| 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" |
| Ilya Biryukov | abc744d | 2019-07-18 15:43:26 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTImporterSharedState.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" |
| Raphael Isemann | ba7bde6 | 2019-10-30 14:50:35 +0100 | [diff] [blame] | 47 | #include "clang/Basic/Builtins.h" |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 48 | #include "clang/Basic/ExceptionSpecificationType.h" |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 49 | #include "clang/Basic/FileManager.h" |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 50 | #include "clang/Basic/IdentifierTable.h" |
| 51 | #include "clang/Basic/LLVM.h" |
| 52 | #include "clang/Basic/LangOptions.h" |
| 53 | #include "clang/Basic/SourceLocation.h" |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 54 | #include "clang/Basic/SourceManager.h" |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 55 | #include "clang/Basic/Specifiers.h" |
| 56 | #include "llvm/ADT/APSInt.h" |
| 57 | #include "llvm/ADT/ArrayRef.h" |
| 58 | #include "llvm/ADT/DenseMap.h" |
| 59 | #include "llvm/ADT/None.h" |
| 60 | #include "llvm/ADT/Optional.h" |
| Balazs Keri | d2c5761 | 2019-07-18 15:23:10 +0000 | [diff] [blame] | 61 | #include "llvm/ADT/ScopeExit.h" |
| Ilya Biryukov | abc744d | 2019-07-18 15:43:26 +0000 | [diff] [blame] | 62 | #include "llvm/ADT/STLExtras.h" |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 63 | #include "llvm/ADT/SmallVector.h" |
| 64 | #include "llvm/Support/Casting.h" |
| 65 | #include "llvm/Support/ErrorHandling.h" |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 66 | #include "llvm/Support/MemoryBuffer.h" |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 67 | #include <algorithm> |
| 68 | #include <cassert> |
| 69 | #include <cstddef> |
| 70 | #include <memory> |
| 71 | #include <type_traits> |
| 72 | #include <utility> |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 73 | |
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 74 | namespace clang { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 75 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 76 | using llvm::make_error; |
| 77 | using llvm::Error; |
| 78 | using llvm::Expected; |
| 79 | using ExpectedType = llvm::Expected<QualType>; |
| 80 | using ExpectedStmt = llvm::Expected<Stmt *>; |
| 81 | using ExpectedExpr = llvm::Expected<Expr *>; |
| 82 | using ExpectedDecl = llvm::Expected<Decl *>; |
| 83 | using ExpectedSLoc = llvm::Expected<SourceLocation>; |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 84 | using ExpectedName = llvm::Expected<DeclarationName>; |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 85 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 86 | std::string ImportError::toString() const { |
| 87 | // FIXME: Improve error texts. |
| 88 | switch (Error) { |
| 89 | case NameConflict: |
| 90 | return "NameConflict"; |
| 91 | case UnsupportedConstruct: |
| 92 | return "UnsupportedConstruct"; |
| 93 | case Unknown: |
| 94 | return "Unknown error"; |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 95 | } |
| Balazs Keri | 2a13d66 | 2018-10-19 15:16:51 +0000 | [diff] [blame] | 96 | llvm_unreachable("Invalid error code."); |
| 97 | return "Invalid error code."; |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 100 | void ImportError::log(raw_ostream &OS) const { |
| 101 | OS << toString(); |
| 102 | } |
| 103 | |
| 104 | std::error_code ImportError::convertToErrorCode() const { |
| 105 | llvm_unreachable("Function not implemented."); |
| 106 | } |
| 107 | |
| 108 | char ImportError::ID; |
| 109 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 110 | template <class T> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 111 | SmallVector<Decl *, 2> |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 112 | getCanonicalForwardRedeclChain(Redeclarable<T>* D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 113 | SmallVector<Decl *, 2> Redecls; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 114 | for (auto *R : D->getFirstDecl()->redecls()) { |
| 115 | if (R != D->getFirstDecl()) |
| 116 | Redecls.push_back(R); |
| 117 | } |
| 118 | Redecls.push_back(D->getFirstDecl()); |
| 119 | std::reverse(Redecls.begin(), Redecls.end()); |
| 120 | return Redecls; |
| 121 | } |
| 122 | |
| 123 | SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D) { |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 124 | if (auto *FD = dyn_cast<FunctionDecl>(D)) |
| 125 | return getCanonicalForwardRedeclChain<FunctionDecl>(FD); |
| 126 | if (auto *VD = dyn_cast<VarDecl>(D)) |
| 127 | return getCanonicalForwardRedeclChain<VarDecl>(VD); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 128 | if (auto *TD = dyn_cast<TagDecl>(D)) |
| 129 | return getCanonicalForwardRedeclChain<TagDecl>(TD); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 130 | llvm_unreachable("Bad declaration kind"); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 133 | void updateFlags(const Decl *From, Decl *To) { |
| 134 | // Check if some flags or attrs are new in 'From' and copy into 'To'. |
| 135 | // FIXME: Other flags or attrs? |
| 136 | if (From->isUsed(false) && !To->isUsed(false)) |
| 137 | To->setIsUsed(); |
| 138 | } |
| 139 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 140 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>, |
| 141 | public DeclVisitor<ASTNodeImporter, ExpectedDecl>, |
| 142 | public StmtVisitor<ASTNodeImporter, ExpectedStmt> { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 143 | ASTImporter &Importer; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 144 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 145 | // Use this instead of Importer.importInto . |
| 146 | template <typename ImportT> |
| 147 | LLVM_NODISCARD Error importInto(ImportT &To, const ImportT &From) { |
| 148 | return Importer.importInto(To, From); |
| 149 | } |
| 150 | |
| 151 | // Use this to import pointers of specific type. |
| 152 | template <typename ImportT> |
| 153 | LLVM_NODISCARD Error importInto(ImportT *&To, ImportT *From) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 154 | auto ToOrErr = Importer.Import(From); |
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 155 | if (ToOrErr) |
| 156 | To = cast_or_null<ImportT>(*ToOrErr); |
| 157 | return ToOrErr.takeError(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | // Call the import function of ASTImporter for a baseclass of type `T` and |
| 161 | // cast the return value to `T`. |
| 162 | template <typename T> |
| 163 | Expected<T *> import(T *From) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 164 | auto ToOrErr = Importer.Import(From); |
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 165 | if (!ToOrErr) |
| 166 | return ToOrErr.takeError(); |
| 167 | return cast_or_null<T>(*ToOrErr); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | template <typename T> |
| 171 | Expected<T *> import(const T *From) { |
| 172 | return import(const_cast<T *>(From)); |
| 173 | } |
| 174 | |
| 175 | // Call the import function of ASTImporter for type `T`. |
| 176 | template <typename T> |
| 177 | Expected<T> import(const T &From) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 178 | return Importer.Import(From); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 181 | // Import an Optional<T> by importing the contained T, if any. |
| 182 | template<typename T> |
| 183 | Expected<Optional<T>> import(Optional<T> From) { |
| 184 | if (!From) |
| 185 | return Optional<T>(); |
| 186 | return import(*From); |
| 187 | } |
| 188 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 189 | // Helper for chaining together multiple imports. If an error is detected, |
| 190 | // subsequent imports will return default constructed nodes, so that failure |
| 191 | // can be detected with a single conditional branch after a sequence of |
| 192 | // imports. |
| 193 | template <typename T> T importChecked(Error &Err, const T &From) { |
| Reid Kleckner | af3e884 | 2020-01-29 14:29:34 -0800 | [diff] [blame] | 194 | // Don't attempt to import nodes if we hit an error earlier. |
| 195 | if (Err) |
| 196 | return T{}; |
| 197 | Expected<T> MaybeVal = import(From); |
| 198 | if (!MaybeVal) { |
| 199 | Err = MaybeVal.takeError(); |
| 200 | return T{}; |
| 201 | } |
| 202 | return *MaybeVal; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| Reid Kleckner | af3e884 | 2020-01-29 14:29:34 -0800 | [diff] [blame] | 205 | // Wrapper for an overload set. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 206 | template <typename ToDeclT> struct CallOverloadedCreateFun { |
| Justin Lebar | ac66c61 | 2020-02-11 10:34:01 -0800 | [diff] [blame] | 207 | template <typename... Args> decltype(auto) operator()(Args &&... args) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 208 | return ToDeclT::Create(std::forward<Args>(args)...); |
| 209 | } |
| 210 | }; |
| 211 | |
| 212 | // Always use these functions to create a Decl during import. There are |
| 213 | // certain tasks which must be done after the Decl was created, e.g. we |
| 214 | // must immediately register that as an imported Decl. The parameter `ToD` |
| 215 | // will be set to the newly created Decl or if had been imported before |
| 216 | // then to the already imported Decl. Returns a bool value set to true if |
| 217 | // the `FromD` had been imported before. |
| 218 | template <typename ToDeclT, typename FromDeclT, typename... Args> |
| 219 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 220 | Args &&... args) { |
| 221 | // There may be several overloads of ToDeclT::Create. We must make sure |
| 222 | // to call the one which would be chosen by the arguments, thus we use a |
| 223 | // wrapper for the overload set. |
| 224 | CallOverloadedCreateFun<ToDeclT> OC; |
| 225 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 226 | std::forward<Args>(args)...); |
| 227 | } |
| 228 | // Use this overload if a special Type is needed to be created. E.g if we |
| 229 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` |
| 230 | // then: |
| 231 | // TypedefNameDecl *ToTypedef; |
| 232 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); |
| 233 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, |
| 234 | typename... Args> |
| 235 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 236 | Args &&... args) { |
| 237 | CallOverloadedCreateFun<NewDeclT> OC; |
| 238 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 239 | std::forward<Args>(args)...); |
| 240 | } |
| 241 | // Use this version if a special create function must be |
| 242 | // used, e.g. CXXRecordDecl::CreateLambda . |
| 243 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, |
| 244 | typename... Args> |
| 245 | LLVM_NODISCARD bool |
| 246 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, |
| 247 | FromDeclT *FromD, Args &&... args) { |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 248 | if (Importer.getImportDeclErrorIfAny(FromD)) { |
| 249 | ToD = nullptr; |
| 250 | return true; // Already imported but with error. |
| 251 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 252 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); |
| 253 | if (ToD) |
| 254 | return true; // Already imported. |
| 255 | ToD = CreateFun(std::forward<Args>(args)...); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 256 | // Keep track of imported Decls. |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 257 | Importer.RegisterImportedDecl(FromD, ToD); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 258 | InitializeImportedDecl(FromD, ToD); |
| 259 | return false; // A new Decl is created. |
| 260 | } |
| 261 | |
| 262 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 263 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; |
| 264 | if (FromD->hasAttrs()) |
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 265 | for (const Attr *FromAttr : FromD->getAttrs()) { |
| 266 | // FIXME: Return of the error here is not possible until store of |
| 267 | // import errors is implemented. |
| 268 | auto ToAttrOrErr = import(FromAttr); |
| 269 | if (ToAttrOrErr) |
| 270 | ToD->addAttr(*ToAttrOrErr); |
| 271 | else |
| 272 | llvm::consumeError(ToAttrOrErr.takeError()); |
| 273 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 274 | if (FromD->isUsed()) |
| 275 | ToD->setIsUsed(); |
| 276 | if (FromD->isImplicit()) |
| 277 | ToD->setImplicit(); |
| 278 | } |
| 279 | |
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 280 | // Check if we have found an existing definition. Returns with that |
| 281 | // definition if yes, otherwise returns null. |
| 282 | Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) { |
| 283 | const FunctionDecl *Definition = nullptr; |
| 284 | if (D->doesThisDeclarationHaveABody() && |
| 285 | FoundFunction->hasBody(Definition)) |
| 286 | return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition)); |
| 287 | return nullptr; |
| 288 | } |
| 289 | |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 290 | void addDeclToContexts(Decl *FromD, Decl *ToD) { |
| 291 | if (Importer.isMinimalImport()) { |
| 292 | // In minimal import case the decl must be added even if it is not |
| 293 | // contained in original context, for LLDB compatibility. |
| 294 | // FIXME: Check if a better solution is possible. |
| 295 | if (!FromD->getDescribedTemplate() && |
| 296 | FromD->getFriendObjectKind() == Decl::FOK_None) |
| 297 | ToD->getLexicalDeclContext()->addDeclInternal(ToD); |
| 298 | return; |
| 299 | } |
| 300 | |
| 301 | DeclContext *FromDC = FromD->getDeclContext(); |
| 302 | DeclContext *FromLexicalDC = FromD->getLexicalDeclContext(); |
| 303 | DeclContext *ToDC = ToD->getDeclContext(); |
| 304 | DeclContext *ToLexicalDC = ToD->getLexicalDeclContext(); |
| 305 | |
| 306 | bool Visible = false; |
| 307 | if (FromDC->containsDeclAndLoad(FromD)) { |
| 308 | ToDC->addDeclInternal(ToD); |
| 309 | Visible = true; |
| 310 | } |
| 311 | if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) { |
| 312 | ToLexicalDC->addDeclInternal(ToD); |
| 313 | Visible = true; |
| 314 | } |
| 315 | |
| 316 | // If the Decl was added to any context, it was made already visible. |
| 317 | // Otherwise it is still possible that it should be visible. |
| 318 | if (!Visible) { |
| 319 | if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) { |
| 320 | auto *ToNamed = cast<NamedDecl>(ToD); |
| 321 | DeclContextLookupResult FromLookup = |
| 322 | FromDC->lookup(FromNamed->getDeclName()); |
| 323 | for (NamedDecl *ND : FromLookup) |
| 324 | if (ND == FromNamed) { |
| 325 | ToDC->makeDeclVisibleInContext(ToNamed); |
| 326 | break; |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 332 | public: |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 333 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} |
| Gabor Marton | 344b099 | 2018-05-16 11:48:11 +0000 | [diff] [blame] | 334 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 335 | using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit; |
| 336 | using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit; |
| 337 | using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 338 | |
| 339 | // Importing types |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 340 | ExpectedType VisitType(const Type *T); |
| 341 | ExpectedType VisitAtomicType(const AtomicType *T); |
| 342 | ExpectedType VisitBuiltinType(const BuiltinType *T); |
| 343 | ExpectedType VisitDecayedType(const DecayedType *T); |
| 344 | ExpectedType VisitComplexType(const ComplexType *T); |
| 345 | ExpectedType VisitPointerType(const PointerType *T); |
| 346 | ExpectedType VisitBlockPointerType(const BlockPointerType *T); |
| 347 | ExpectedType VisitLValueReferenceType(const LValueReferenceType *T); |
| 348 | ExpectedType VisitRValueReferenceType(const RValueReferenceType *T); |
| 349 | ExpectedType VisitMemberPointerType(const MemberPointerType *T); |
| 350 | ExpectedType VisitConstantArrayType(const ConstantArrayType *T); |
| 351 | ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T); |
| 352 | ExpectedType VisitVariableArrayType(const VariableArrayType *T); |
| 353 | ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 354 | // FIXME: DependentSizedExtVectorType |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 355 | ExpectedType VisitVectorType(const VectorType *T); |
| 356 | ExpectedType VisitExtVectorType(const ExtVectorType *T); |
| 357 | ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T); |
| 358 | ExpectedType VisitFunctionProtoType(const FunctionProtoType *T); |
| 359 | ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T); |
| 360 | ExpectedType VisitParenType(const ParenType *T); |
| 361 | ExpectedType VisitTypedefType(const TypedefType *T); |
| 362 | ExpectedType VisitTypeOfExprType(const TypeOfExprType *T); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 363 | // FIXME: DependentTypeOfExprType |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 364 | ExpectedType VisitTypeOfType(const TypeOfType *T); |
| 365 | ExpectedType VisitDecltypeType(const DecltypeType *T); |
| 366 | ExpectedType VisitUnaryTransformType(const UnaryTransformType *T); |
| 367 | ExpectedType VisitAutoType(const AutoType *T); |
| 368 | ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 369 | // FIXME: DependentDecltypeType |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 370 | ExpectedType VisitRecordType(const RecordType *T); |
| 371 | ExpectedType VisitEnumType(const EnumType *T); |
| 372 | ExpectedType VisitAttributedType(const AttributedType *T); |
| 373 | ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T); |
| 374 | ExpectedType VisitSubstTemplateTypeParmType( |
| 375 | const SubstTemplateTypeParmType *T); |
| 376 | ExpectedType VisitTemplateSpecializationType( |
| 377 | const TemplateSpecializationType *T); |
| 378 | ExpectedType VisitElaboratedType(const ElaboratedType *T); |
| 379 | ExpectedType VisitDependentNameType(const DependentNameType *T); |
| 380 | ExpectedType VisitPackExpansionType(const PackExpansionType *T); |
| 381 | ExpectedType VisitDependentTemplateSpecializationType( |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 382 | const DependentTemplateSpecializationType *T); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 383 | ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T); |
| 384 | ExpectedType VisitObjCObjectType(const ObjCObjectType *T); |
| 385 | ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); |
| Rafael Stahl | df55620 | 2018-05-29 08:12:15 +0000 | [diff] [blame] | 386 | |
| 387 | // Importing declarations |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 388 | Error ImportDeclParts( |
| 389 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 390 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc); |
| 391 | Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); |
| 392 | Error ImportDeclarationNameLoc( |
| 393 | const DeclarationNameInfo &From, DeclarationNameInfo &To); |
| 394 | Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); |
| 395 | Error ImportDeclContext( |
| 396 | Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC); |
| 397 | Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 398 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 399 | Expected<CXXCastPath> ImportCastPath(CastExpr *E); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 400 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 401 | using Designator = DesignatedInitExpr::Designator; |
| 402 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 403 | /// What we should import from the definition. |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 404 | enum ImportDefinitionKind { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 405 | /// Import the default subset of the definition, which might be |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 406 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 407 | /// import is not set). |
| 408 | IDK_Default, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 409 | /// Import everything. |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 410 | IDK_Everything, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 411 | /// Import only the bare bones needed to establish a valid |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 412 | /// DeclContext. |
| 413 | IDK_Basic |
| 414 | }; |
| 415 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 416 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 417 | return IDK == IDK_Everything || |
| 418 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 419 | } |
| 420 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 421 | Error ImportInitializer(VarDecl *From, VarDecl *To); |
| 422 | Error ImportDefinition( |
| 423 | RecordDecl *From, RecordDecl *To, |
| 424 | ImportDefinitionKind Kind = IDK_Default); |
| 425 | Error ImportDefinition( |
| 426 | EnumDecl *From, EnumDecl *To, |
| 427 | ImportDefinitionKind Kind = IDK_Default); |
| 428 | Error ImportDefinition( |
| 429 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
| 430 | ImportDefinitionKind Kind = IDK_Default); |
| 431 | Error ImportDefinition( |
| 432 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
| 433 | ImportDefinitionKind Kind = IDK_Default); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 434 | Error ImportTemplateArguments( |
| 435 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 436 | SmallVectorImpl<TemplateArgument> &ToArgs); |
| 437 | Expected<TemplateArgument> |
| 438 | ImportTemplateArgument(const TemplateArgument &From); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 439 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 440 | template <typename InContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 441 | Error ImportTemplateArgumentListInfo( |
| 442 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 443 | |
| 444 | template<typename InContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 445 | Error ImportTemplateArgumentListInfo( |
| 446 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 447 | const InContainerTy &Container, TemplateArgumentListInfo &Result); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 448 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 449 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 450 | using FunctionTemplateAndArgsTy = |
| 451 | std::tuple<FunctionTemplateDecl *, TemplateArgsTy>; |
| 452 | Expected<FunctionTemplateAndArgsTy> |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 453 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 454 | FunctionDecl *FromFD); |
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 455 | Error ImportTemplateParameterLists(const DeclaratorDecl *FromD, |
| 456 | DeclaratorDecl *ToD); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 457 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 458 | Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 459 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 460 | Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD); |
| 461 | |
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 462 | Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam, |
| 463 | ParmVarDecl *ToParam); |
| 464 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 465 | template <typename T> |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 466 | bool hasSameVisibilityContextAndLinkage(T *Found, T *From); |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 467 | |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 468 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 469 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 470 | bool Complain = true); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 471 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 472 | bool Complain = true); |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 473 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 474 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 475 | bool IsStructuralMatch(FunctionTemplateDecl *From, |
| 476 | FunctionTemplateDecl *To); |
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 477 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 478 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 479 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 480 | ExpectedDecl VisitDecl(Decl *D); |
| 481 | ExpectedDecl VisitImportDecl(ImportDecl *D); |
| 482 | ExpectedDecl VisitEmptyDecl(EmptyDecl *D); |
| 483 | ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); |
| 484 | ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); |
| 485 | ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 486 | ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); |
| 487 | ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
| 488 | ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
| 489 | ExpectedDecl VisitTypedefDecl(TypedefDecl *D); |
| 490 | ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D); |
| 491 | ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
| 492 | ExpectedDecl VisitLabelDecl(LabelDecl *D); |
| 493 | ExpectedDecl VisitEnumDecl(EnumDecl *D); |
| 494 | ExpectedDecl VisitRecordDecl(RecordDecl *D); |
| 495 | ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D); |
| 496 | ExpectedDecl VisitFunctionDecl(FunctionDecl *D); |
| 497 | ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D); |
| 498 | ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 499 | ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 500 | ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); |
| 501 | ExpectedDecl VisitFieldDecl(FieldDecl *D); |
| 502 | ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); |
| 503 | ExpectedDecl VisitFriendDecl(FriendDecl *D); |
| 504 | ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 505 | ExpectedDecl VisitVarDecl(VarDecl *D); |
| 506 | ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D); |
| 507 | ExpectedDecl VisitParmVarDecl(ParmVarDecl *D); |
| 508 | ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 509 | ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
| 510 | ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 511 | ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 512 | ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D); |
| 513 | ExpectedDecl VisitUsingDecl(UsingDecl *D); |
| 514 | ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); |
| 515 | ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 516 | ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 517 | ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
| Raphael Isemann | ba7bde6 | 2019-10-30 14:50:35 +0100 | [diff] [blame] | 518 | ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D); |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 519 | ExpectedDecl |
| 520 | VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 521 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 522 | Expected<ObjCTypeParamList *> |
| 523 | ImportObjCTypeParamList(ObjCTypeParamList *list); |
| 524 | |
| 525 | ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 526 | ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 527 | ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 528 | ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 529 | ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
| 530 | ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 531 | ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 532 | ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 533 | ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D); |
| 534 | ExpectedDecl VisitClassTemplateSpecializationDecl( |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 535 | ClassTemplateSpecializationDecl *D); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 536 | ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); |
| 537 | ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
| 538 | ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 539 | |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 540 | // Importing statements |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 541 | ExpectedStmt VisitStmt(Stmt *S); |
| 542 | ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S); |
| 543 | ExpectedStmt VisitDeclStmt(DeclStmt *S); |
| 544 | ExpectedStmt VisitNullStmt(NullStmt *S); |
| 545 | ExpectedStmt VisitCompoundStmt(CompoundStmt *S); |
| 546 | ExpectedStmt VisitCaseStmt(CaseStmt *S); |
| 547 | ExpectedStmt VisitDefaultStmt(DefaultStmt *S); |
| 548 | ExpectedStmt VisitLabelStmt(LabelStmt *S); |
| 549 | ExpectedStmt VisitAttributedStmt(AttributedStmt *S); |
| 550 | ExpectedStmt VisitIfStmt(IfStmt *S); |
| 551 | ExpectedStmt VisitSwitchStmt(SwitchStmt *S); |
| 552 | ExpectedStmt VisitWhileStmt(WhileStmt *S); |
| 553 | ExpectedStmt VisitDoStmt(DoStmt *S); |
| 554 | ExpectedStmt VisitForStmt(ForStmt *S); |
| 555 | ExpectedStmt VisitGotoStmt(GotoStmt *S); |
| 556 | ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 557 | ExpectedStmt VisitContinueStmt(ContinueStmt *S); |
| 558 | ExpectedStmt VisitBreakStmt(BreakStmt *S); |
| 559 | ExpectedStmt VisitReturnStmt(ReturnStmt *S); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 560 | // FIXME: MSAsmStmt |
| 561 | // FIXME: SEHExceptStmt |
| 562 | // FIXME: SEHFinallyStmt |
| 563 | // FIXME: SEHTryStmt |
| 564 | // FIXME: SEHLeaveStmt |
| 565 | // FIXME: CapturedStmt |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 566 | ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S); |
| 567 | ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S); |
| 568 | ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 569 | // FIXME: MSDependentExistsStmt |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 570 | ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 571 | ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 572 | ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 573 | ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 574 | ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 575 | ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 576 | ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 577 | |
| 578 | // Importing expressions |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 579 | ExpectedStmt VisitExpr(Expr *E); |
| 580 | ExpectedStmt VisitVAArgExpr(VAArgExpr *E); |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 581 | ExpectedStmt VisitChooseExpr(ChooseExpr *E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 582 | ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); |
| 583 | ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E); |
| 584 | ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E); |
| 585 | ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); |
| 586 | ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 587 | ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
| 588 | ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E); |
| 589 | ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E); |
| 590 | ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E); |
| Vince Bridgers | 789215d | 2020-04-06 08:22:35 -0500 | [diff] [blame] | 591 | ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 592 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); |
| 593 | ExpectedStmt VisitStringLiteral(StringLiteral *E); |
| 594 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 595 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); |
| 596 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 597 | ExpectedStmt VisitConstantExpr(ConstantExpr *E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 598 | ExpectedStmt VisitParenExpr(ParenExpr *E); |
| 599 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); |
| 600 | ExpectedStmt VisitStmtExpr(StmtExpr *E); |
| 601 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); |
| 602 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
| 603 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); |
| 604 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); |
| 605 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 606 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); |
| 607 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 608 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 609 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
| 610 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 611 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); |
| 612 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 613 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 614 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); |
| 615 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 616 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 617 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 618 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 619 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); |
| 620 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
| 621 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); |
| 622 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); |
| 623 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); |
| 624 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); |
| 625 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); |
| 626 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
| 627 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
| 628 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); |
| 629 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); |
| 630 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
| 631 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
| 632 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); |
| 633 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); |
| 634 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
| 635 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
| 636 | ExpectedStmt VisitMemberExpr(MemberExpr *E); |
| 637 | ExpectedStmt VisitCallExpr(CallExpr *E); |
| 638 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); |
| 639 | ExpectedStmt VisitInitListExpr(InitListExpr *E); |
| 640 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); |
| 641 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); |
| 642 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 643 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
| 644 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 645 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
| 646 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
| 647 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); |
| 648 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 649 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 650 | template<typename IIter, typename OIter> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 651 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
| Justin Lebar | 027eb71 | 2020-02-10 23:23:44 -0800 | [diff] [blame] | 652 | using ItemT = std::remove_reference_t<decltype(*Obegin)>; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 653 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { |
| 654 | Expected<ItemT> ToOrErr = import(*Ibegin); |
| 655 | if (!ToOrErr) |
| 656 | return ToOrErr.takeError(); |
| 657 | *Obegin = *ToOrErr; |
| 658 | } |
| 659 | return Error::success(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 660 | } |
| 661 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 662 | // Import every item from a container structure into an output container. |
| 663 | // If error occurs, stops at first error and returns the error. |
| 664 | // The output container should have space for all needed elements (it is not |
| 665 | // expanded, new items are put into from the beginning). |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 666 | template<typename InContainerTy, typename OutContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 667 | Error ImportContainerChecked( |
| 668 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { |
| 669 | return ImportArrayChecked( |
| 670 | InContainer.begin(), InContainer.end(), OutContainer.begin()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | template<typename InContainerTy, typename OIter> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 674 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 675 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 676 | } |
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 677 | |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 678 | Error ImportOverriddenMethods(CXXMethodDecl *ToMethod, |
| 679 | CXXMethodDecl *FromMethod); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 680 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 681 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( |
| 682 | FunctionDecl *FromFD); |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 683 | |
| 684 | // Returns true if the given function has a placeholder return type and |
| 685 | // that type is declared inside the body of the function. |
| 686 | // E.g. auto f() { struct X{}; return X(); } |
| 687 | bool hasAutoReturnTypeDeclaredInside(FunctionDecl *D); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 688 | }; |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 689 | |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 690 | template <typename InContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 691 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 692 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 693 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 694 | auto ToLAngleLocOrErr = import(FromLAngleLoc); |
| 695 | if (!ToLAngleLocOrErr) |
| 696 | return ToLAngleLocOrErr.takeError(); |
| 697 | auto ToRAngleLocOrErr = import(FromRAngleLoc); |
| 698 | if (!ToRAngleLocOrErr) |
| 699 | return ToRAngleLocOrErr.takeError(); |
| 700 | |
| 701 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); |
| 702 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 703 | return Err; |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 704 | Result = ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 705 | return Error::success(); |
| Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 706 | } |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 707 | |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 708 | template <> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 709 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 710 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 711 | return ImportTemplateArgumentListInfo( |
| 712 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 713 | } |
| 714 | |
| 715 | template <> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 716 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 717 | ASTTemplateArgumentListInfo>( |
| 718 | const ASTTemplateArgumentListInfo &From, |
| 719 | TemplateArgumentListInfo &Result) { |
| 720 | return ImportTemplateArgumentListInfo( |
| 721 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 724 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 725 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 726 | FunctionDecl *FromFD) { |
| 727 | assert(FromFD->getTemplatedKind() == |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 728 | FunctionDecl::TK_FunctionTemplateSpecialization); |
| 729 | |
| 730 | FunctionTemplateAndArgsTy Result; |
| 731 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 732 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 733 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) |
| 734 | return std::move(Err); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 735 | |
| 736 | // Import template arguments. |
| 737 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 738 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 739 | std::get<1>(Result))) |
| 740 | return std::move(Err); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 741 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 742 | return Result; |
| 743 | } |
| 744 | |
| 745 | template <> |
| 746 | Expected<TemplateParameterList *> |
| 747 | ASTNodeImporter::import(TemplateParameterList *From) { |
| 748 | SmallVector<NamedDecl *, 4> To(From->size()); |
| 749 | if (Error Err = ImportContainerChecked(*From, To)) |
| 750 | return std::move(Err); |
| 751 | |
| 752 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); |
| 753 | if (!ToRequiresClause) |
| 754 | return ToRequiresClause.takeError(); |
| 755 | |
| 756 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); |
| 757 | if (!ToTemplateLocOrErr) |
| 758 | return ToTemplateLocOrErr.takeError(); |
| 759 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); |
| 760 | if (!ToLAngleLocOrErr) |
| 761 | return ToLAngleLocOrErr.takeError(); |
| 762 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); |
| 763 | if (!ToRAngleLocOrErr) |
| 764 | return ToRAngleLocOrErr.takeError(); |
| 765 | |
| 766 | return TemplateParameterList::Create( |
| 767 | Importer.getToContext(), |
| 768 | *ToTemplateLocOrErr, |
| 769 | *ToLAngleLocOrErr, |
| 770 | To, |
| 771 | *ToRAngleLocOrErr, |
| 772 | *ToRequiresClause); |
| 773 | } |
| 774 | |
| 775 | template <> |
| 776 | Expected<TemplateArgument> |
| 777 | ASTNodeImporter::import(const TemplateArgument &From) { |
| 778 | switch (From.getKind()) { |
| 779 | case TemplateArgument::Null: |
| 780 | return TemplateArgument(); |
| 781 | |
| 782 | case TemplateArgument::Type: { |
| 783 | ExpectedType ToTypeOrErr = import(From.getAsType()); |
| 784 | if (!ToTypeOrErr) |
| 785 | return ToTypeOrErr.takeError(); |
| 786 | return TemplateArgument(*ToTypeOrErr); |
| 787 | } |
| 788 | |
| 789 | case TemplateArgument::Integral: { |
| 790 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); |
| 791 | if (!ToTypeOrErr) |
| 792 | return ToTypeOrErr.takeError(); |
| 793 | return TemplateArgument(From, *ToTypeOrErr); |
| 794 | } |
| 795 | |
| 796 | case TemplateArgument::Declaration: { |
| 797 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); |
| 798 | if (!ToOrErr) |
| 799 | return ToOrErr.takeError(); |
| 800 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); |
| 801 | if (!ToTypeOrErr) |
| 802 | return ToTypeOrErr.takeError(); |
| 803 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); |
| 804 | } |
| 805 | |
| 806 | case TemplateArgument::NullPtr: { |
| 807 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); |
| 808 | if (!ToTypeOrErr) |
| 809 | return ToTypeOrErr.takeError(); |
| 810 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); |
| 811 | } |
| 812 | |
| 813 | case TemplateArgument::Template: { |
| 814 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); |
| 815 | if (!ToTemplateOrErr) |
| 816 | return ToTemplateOrErr.takeError(); |
| 817 | |
| 818 | return TemplateArgument(*ToTemplateOrErr); |
| 819 | } |
| 820 | |
| 821 | case TemplateArgument::TemplateExpansion: { |
| 822 | Expected<TemplateName> ToTemplateOrErr = |
| 823 | import(From.getAsTemplateOrTemplatePattern()); |
| 824 | if (!ToTemplateOrErr) |
| 825 | return ToTemplateOrErr.takeError(); |
| 826 | |
| 827 | return TemplateArgument( |
| 828 | *ToTemplateOrErr, From.getNumTemplateExpansions()); |
| 829 | } |
| 830 | |
| 831 | case TemplateArgument::Expression: |
| 832 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) |
| 833 | return TemplateArgument(*ToExpr); |
| 834 | else |
| 835 | return ToExpr.takeError(); |
| 836 | |
| 837 | case TemplateArgument::Pack: { |
| 838 | SmallVector<TemplateArgument, 2> ToPack; |
| 839 | ToPack.reserve(From.pack_size()); |
| 840 | if (Error Err = ImportTemplateArguments( |
| 841 | From.pack_begin(), From.pack_size(), ToPack)) |
| 842 | return std::move(Err); |
| 843 | |
| 844 | return TemplateArgument( |
| 845 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | llvm_unreachable("Invalid template argument kind"); |
| 850 | } |
| 851 | |
| 852 | template <> |
| 853 | Expected<TemplateArgumentLoc> |
| 854 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { |
| 855 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); |
| 856 | if (!ArgOrErr) |
| 857 | return ArgOrErr.takeError(); |
| 858 | TemplateArgument Arg = *ArgOrErr; |
| 859 | |
| 860 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 861 | |
| 862 | TemplateArgumentLocInfo ToInfo; |
| 863 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 864 | ExpectedExpr E = import(FromInfo.getAsExpr()); |
| 865 | if (!E) |
| 866 | return E.takeError(); |
| 867 | ToInfo = TemplateArgumentLocInfo(*E); |
| 868 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 869 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) |
| 870 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); |
| 871 | else |
| 872 | return TSIOrErr.takeError(); |
| 873 | } else { |
| 874 | auto ToTemplateQualifierLocOrErr = |
| 875 | import(FromInfo.getTemplateQualifierLoc()); |
| 876 | if (!ToTemplateQualifierLocOrErr) |
| 877 | return ToTemplateQualifierLocOrErr.takeError(); |
| 878 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); |
| 879 | if (!ToTemplateNameLocOrErr) |
| 880 | return ToTemplateNameLocOrErr.takeError(); |
| 881 | auto ToTemplateEllipsisLocOrErr = |
| 882 | import(FromInfo.getTemplateEllipsisLoc()); |
| 883 | if (!ToTemplateEllipsisLocOrErr) |
| 884 | return ToTemplateEllipsisLocOrErr.takeError(); |
| 885 | |
| 886 | ToInfo = TemplateArgumentLocInfo( |
| 887 | *ToTemplateQualifierLocOrErr, |
| 888 | *ToTemplateNameLocOrErr, |
| 889 | *ToTemplateEllipsisLocOrErr); |
| 890 | } |
| 891 | |
| 892 | return TemplateArgumentLoc(Arg, ToInfo); |
| 893 | } |
| 894 | |
| 895 | template <> |
| 896 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { |
| 897 | if (DG.isNull()) |
| 898 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 899 | size_t NumDecls = DG.end() - DG.begin(); |
| 900 | SmallVector<Decl *, 1> ToDecls; |
| 901 | ToDecls.reserve(NumDecls); |
| 902 | for (Decl *FromD : DG) { |
| 903 | if (auto ToDOrErr = import(FromD)) |
| 904 | ToDecls.push_back(*ToDOrErr); |
| 905 | else |
| 906 | return ToDOrErr.takeError(); |
| 907 | } |
| 908 | return DeclGroupRef::Create(Importer.getToContext(), |
| 909 | ToDecls.begin(), |
| 910 | NumDecls); |
| 911 | } |
| 912 | |
| 913 | template <> |
| 914 | Expected<ASTNodeImporter::Designator> |
| 915 | ASTNodeImporter::import(const Designator &D) { |
| 916 | if (D.isFieldDesignator()) { |
| 917 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 918 | |
| 919 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); |
| 920 | if (!ToDotLocOrErr) |
| 921 | return ToDotLocOrErr.takeError(); |
| 922 | |
| 923 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); |
| 924 | if (!ToFieldLocOrErr) |
| 925 | return ToFieldLocOrErr.takeError(); |
| 926 | |
| 927 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); |
| 928 | } |
| 929 | |
| 930 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); |
| 931 | if (!ToLBracketLocOrErr) |
| 932 | return ToLBracketLocOrErr.takeError(); |
| 933 | |
| 934 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); |
| 935 | if (!ToRBracketLocOrErr) |
| 936 | return ToRBracketLocOrErr.takeError(); |
| 937 | |
| 938 | if (D.isArrayDesignator()) |
| 939 | return Designator(D.getFirstExprIndex(), |
| 940 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); |
| 941 | |
| 942 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); |
| 943 | if (!ToEllipsisLocOrErr) |
| 944 | return ToEllipsisLocOrErr.takeError(); |
| 945 | |
| 946 | assert(D.isArrayRangeDesignator()); |
| 947 | return Designator( |
| 948 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, |
| 949 | *ToRBracketLocOrErr); |
| 950 | } |
| 951 | |
| 952 | template <> |
| 953 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { |
| 954 | VarDecl *Var = nullptr; |
| 955 | if (From.capturesVariable()) { |
| 956 | if (auto VarOrErr = import(From.getCapturedVar())) |
| 957 | Var = *VarOrErr; |
| 958 | else |
| 959 | return VarOrErr.takeError(); |
| 960 | } |
| 961 | |
| 962 | auto LocationOrErr = import(From.getLocation()); |
| 963 | if (!LocationOrErr) |
| 964 | return LocationOrErr.takeError(); |
| 965 | |
| 966 | SourceLocation EllipsisLoc; |
| 967 | if (From.isPackExpansion()) |
| 968 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) |
| 969 | return std::move(Err); |
| 970 | |
| 971 | return LambdaCapture( |
| 972 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, |
| 973 | EllipsisLoc); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 974 | } |
| 975 | |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 976 | template <typename T> |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 977 | bool ASTNodeImporter::hasSameVisibilityContextAndLinkage(T *Found, T *From) { |
| 978 | if (Found->getLinkageInternal() != From->getLinkageInternal()) |
| 979 | return false; |
| 980 | |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 981 | if (From->hasExternalFormalLinkage()) |
| 982 | return Found->hasExternalFormalLinkage(); |
| 983 | if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl()) |
| 984 | return false; |
| 985 | if (From->isInAnonymousNamespace()) |
| 986 | return Found->isInAnonymousNamespace(); |
| 987 | else |
| 988 | return !Found->isInAnonymousNamespace() && |
| 989 | !Found->hasExternalFormalLinkage(); |
| 990 | } |
| 991 | |
| 992 | template <> |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 993 | bool ASTNodeImporter::hasSameVisibilityContextAndLinkage(TypedefNameDecl *Found, |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 994 | TypedefNameDecl *From) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 995 | if (Found->getLinkageInternal() != From->getLinkageInternal()) |
| 996 | return false; |
| 997 | |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 998 | if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace()) |
| 999 | return Importer.GetFromTU(Found) == From->getTranslationUnitDecl(); |
| 1000 | return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace(); |
| 1001 | } |
| 1002 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1003 | } // namespace clang |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 1004 | |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1005 | //---------------------------------------------------------------------------- |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1006 | // Import Types |
| 1007 | //---------------------------------------------------------------------------- |
| 1008 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1009 | using namespace clang; |
| 1010 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1011 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1012 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 1013 | << T->getTypeClassName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1014 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1017 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 1018 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); |
| 1019 | if (!UnderlyingTypeOrErr) |
| 1020 | return UnderlyingTypeOrErr.takeError(); |
| Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 1021 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1022 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); |
| Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1025 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1026 | switch (T->getKind()) { |
| Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 1027 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 1028 | case BuiltinType::Id: \ |
| 1029 | return Importer.getToContext().SingletonId; |
| Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 1030 | #include "clang/Basic/OpenCLImageTypes.def" |
| Andrew Savonichev | 3fee351 | 2018-11-08 11:25:41 +0000 | [diff] [blame] | 1031 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
| 1032 | case BuiltinType::Id: \ |
| 1033 | return Importer.getToContext().Id##Ty; |
| 1034 | #include "clang/Basic/OpenCLExtensionTypes.def" |
| Richard Sandiford | eb485fb | 2019-08-09 08:52:54 +0000 | [diff] [blame] | 1035 | #define SVE_TYPE(Name, Id, SingletonId) \ |
| 1036 | case BuiltinType::Id: \ |
| 1037 | return Importer.getToContext().SingletonId; |
| 1038 | #include "clang/Basic/AArch64SVEACLETypes.def" |
| John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 1039 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 1040 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 1041 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 1042 | #include "clang/AST/BuiltinTypes.def" |
| 1043 | |
| 1044 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 1045 | // context supports C++. |
| 1046 | |
| 1047 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 1048 | // context supports ObjC. |
| 1049 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1050 | case BuiltinType::Char_U: |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1051 | // The context we're importing from has an unsigned 'char'. If we're |
| 1052 | // importing into a context with a signed 'char', translate to |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1053 | // 'unsigned char' instead. |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1054 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1055 | return Importer.getToContext().UnsignedCharTy; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1056 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1057 | return Importer.getToContext().CharTy; |
| 1058 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1059 | case BuiltinType::Char_S: |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1060 | // The context we're importing from has an unsigned 'char'. If we're |
| 1061 | // importing into a context with a signed 'char', translate to |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1062 | // 'unsigned char' instead. |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1063 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1064 | return Importer.getToContext().SignedCharTy; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1065 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1066 | return Importer.getToContext().CharTy; |
| 1067 | |
| Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 1068 | case BuiltinType::WChar_S: |
| 1069 | case BuiltinType::WChar_U: |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1070 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 1071 | // wchar_t? |
| 1072 | return Importer.getToContext().WCharTy; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1073 | } |
| David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 1074 | |
| 1075 | llvm_unreachable("Invalid BuiltinType Kind!"); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1078 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 1079 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); |
| 1080 | if (!ToOriginalTypeOrErr) |
| 1081 | return ToOriginalTypeOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1082 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1083 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1086 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
| 1087 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1088 | if (!ToElementTypeOrErr) |
| 1089 | return ToElementTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1090 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1091 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1094 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
| 1095 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1096 | if (!ToPointeeTypeOrErr) |
| 1097 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1098 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1099 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1102 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1103 | // FIXME: Check for blocks support in "to" context. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1104 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1105 | if (!ToPointeeTypeOrErr) |
| 1106 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1107 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1108 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1111 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1112 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1113 | // FIXME: Check for C++ support in "to" context. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1114 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1115 | if (!ToPointeeTypeOrErr) |
| 1116 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1117 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1118 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1119 | } |
| 1120 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1121 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1122 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1123 | // FIXME: Check for C++0x support in "to" context. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1124 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1125 | if (!ToPointeeTypeOrErr) |
| 1126 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1127 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1128 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1131 | ExpectedType |
| 1132 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1133 | // FIXME: Check for C++ support in "to" context. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1134 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1135 | if (!ToPointeeTypeOrErr) |
| 1136 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1137 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1138 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); |
| 1139 | if (!ClassTypeOrErr) |
| 1140 | return ClassTypeOrErr.takeError(); |
| 1141 | |
| 1142 | return Importer.getToContext().getMemberPointerType( |
| 1143 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1146 | ExpectedType |
| 1147 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 1148 | Error Err = Error::success(); |
| 1149 | auto ToElementType = importChecked(Err, T->getElementType()); |
| 1150 | auto ToSizeExpr = importChecked(Err, T->getSizeExpr()); |
| 1151 | if (Err) |
| 1152 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1153 | |
| Richard Smith | 772e266 | 2019-10-04 01:25:59 +0000 | [diff] [blame] | 1154 | return Importer.getToContext().getConstantArrayType( |
| 1155 | ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(), |
| 1156 | T->getIndexTypeCVRQualifiers()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1159 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1160 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1161 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1162 | if (!ToElementTypeOrErr) |
| 1163 | return ToElementTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1164 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1165 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1166 | T->getSizeModifier(), |
| 1167 | T->getIndexTypeCVRQualifiers()); |
| 1168 | } |
| 1169 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1170 | ExpectedType |
| 1171 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 1172 | Error Err = Error::success(); |
| 1173 | QualType ToElementType = importChecked(Err, T->getElementType()); |
| 1174 | Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr()); |
| 1175 | SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange()); |
| 1176 | if (Err) |
| 1177 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1178 | return Importer.getToContext().getVariableArrayType( |
| 1179 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1180 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1183 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1184 | const DependentSizedArrayType *T) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 1185 | Error Err = Error::success(); |
| 1186 | QualType ToElementType = importChecked(Err, T->getElementType()); |
| 1187 | Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr()); |
| 1188 | SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange()); |
| 1189 | if (Err) |
| 1190 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1191 | // SizeExpr may be null if size is not specified directly. |
| 1192 | // For example, 'int a[]'. |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1193 | |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1194 | return Importer.getToContext().getDependentSizedArrayType( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1195 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1196 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1199 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
| 1200 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1201 | if (!ToElementTypeOrErr) |
| 1202 | return ToElementTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1203 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1204 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1205 | T->getNumElements(), |
| Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 1206 | T->getVectorKind()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1209 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
| 1210 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1211 | if (!ToElementTypeOrErr) |
| 1212 | return ToElementTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1213 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1214 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1215 | T->getNumElements()); |
| 1216 | } |
| 1217 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1218 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1219 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1220 | // FIXME: What happens if we're importing a function without a prototype |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1221 | // into C++? Should we make it variadic? |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1222 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1223 | if (!ToReturnTypeOrErr) |
| 1224 | return ToReturnTypeOrErr.takeError(); |
| Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1225 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1226 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, |
| Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1227 | T->getExtInfo()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1230 | ExpectedType |
| 1231 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 1232 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1233 | if (!ToReturnTypeOrErr) |
| 1234 | return ToReturnTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1235 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1236 | // Import argument types |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1237 | SmallVector<QualType, 4> ArgTypes; |
| Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 1238 | for (const auto &A : T->param_types()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1239 | ExpectedType TyOrErr = import(A); |
| 1240 | if (!TyOrErr) |
| 1241 | return TyOrErr.takeError(); |
| 1242 | ArgTypes.push_back(*TyOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1243 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1244 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1245 | // Import exception types |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1246 | SmallVector<QualType, 4> ExceptionTypes; |
| Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 1247 | for (const auto &E : T->exceptions()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1248 | ExpectedType TyOrErr = import(E); |
| 1249 | if (!TyOrErr) |
| 1250 | return TyOrErr.takeError(); |
| 1251 | ExceptionTypes.push_back(*TyOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1252 | } |
| John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 1253 | |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1254 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 1255 | Error Err = Error::success(); |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1256 | FunctionProtoType::ExtProtoInfo ToEPI; |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1257 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 1258 | ToEPI.Variadic = FromEPI.Variadic; |
| 1259 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 1260 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 1261 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1262 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 1263 | ToEPI.ExceptionSpec.NoexceptExpr = |
| 1264 | importChecked(Err, FromEPI.ExceptionSpec.NoexceptExpr); |
| 1265 | ToEPI.ExceptionSpec.SourceDecl = |
| 1266 | importChecked(Err, FromEPI.ExceptionSpec.SourceDecl); |
| 1267 | ToEPI.ExceptionSpec.SourceTemplate = |
| 1268 | importChecked(Err, FromEPI.ExceptionSpec.SourceTemplate); |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1269 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 1270 | |
| 1271 | if (Err) |
| 1272 | return std::move(Err); |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1273 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1274 | return Importer.getToContext().getFunctionType( |
| 1275 | *ToReturnTypeOrErr, ArgTypes, ToEPI); |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1278 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1279 | const UnresolvedUsingType *T) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 1280 | Error Err = Error::success(); |
| 1281 | auto ToD = importChecked(Err, T->getDecl()); |
| 1282 | auto ToPrevD = importChecked(Err, T->getDecl()->getPreviousDecl()); |
| 1283 | if (Err) |
| 1284 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1285 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1286 | return Importer.getToContext().getTypeDeclType( |
| 1287 | ToD, cast_or_null<TypeDecl>(ToPrevD)); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1288 | } |
| 1289 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1290 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 1291 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); |
| 1292 | if (!ToInnerTypeOrErr) |
| 1293 | return ToInnerTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1294 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1295 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); |
| Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 1296 | } |
| 1297 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1298 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
| 1299 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1300 | if (!ToDeclOrErr) |
| 1301 | return ToDeclOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1302 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1303 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1306 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
| 1307 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1308 | if (!ToExprOrErr) |
| 1309 | return ToExprOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1310 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1311 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1314 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
| 1315 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1316 | if (!ToUnderlyingTypeOrErr) |
| 1317 | return ToUnderlyingTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1318 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1319 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1320 | } |
| 1321 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1322 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1323 | // FIXME: Make sure that the "to" context supports C++0x! |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1324 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1325 | if (!ToExprOrErr) |
| 1326 | return ToExprOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1327 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1328 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1329 | if (!ToUnderlyingTypeOrErr) |
| 1330 | return ToUnderlyingTypeOrErr.takeError(); |
| Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 1331 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1332 | return Importer.getToContext().getDecltypeType( |
| 1333 | *ToExprOrErr, *ToUnderlyingTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1334 | } |
| 1335 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1336 | ExpectedType |
| 1337 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 1338 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1339 | if (!ToBaseTypeOrErr) |
| 1340 | return ToBaseTypeOrErr.takeError(); |
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1341 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1342 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1343 | if (!ToUnderlyingTypeOrErr) |
| 1344 | return ToUnderlyingTypeOrErr.takeError(); |
| 1345 | |
| 1346 | return Importer.getToContext().getUnaryTransformType( |
| 1347 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); |
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1350 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
| Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 1351 | // FIXME: Make sure that the "to" context supports C++11! |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1352 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); |
| 1353 | if (!ToDeducedTypeOrErr) |
| 1354 | return ToDeducedTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1355 | |
| Saar Raz | b481f02 | 2020-01-22 02:03:05 +0200 | [diff] [blame] | 1356 | ExpectedDecl ToTypeConstraintConcept = import(T->getTypeConstraintConcept()); |
| 1357 | if (!ToTypeConstraintConcept) |
| 1358 | return ToTypeConstraintConcept.takeError(); |
| 1359 | |
| 1360 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
| 1361 | ArrayRef<TemplateArgument> FromTemplateArgs = T->getTypeConstraintArguments(); |
| 1362 | if (Error Err = ImportTemplateArguments(FromTemplateArgs.data(), |
| 1363 | FromTemplateArgs.size(), |
| 1364 | ToTemplateArgs)) |
| 1365 | return std::move(Err); |
| 1366 | |
| 1367 | return Importer.getToContext().getAutoType( |
| 1368 | *ToDeducedTypeOrErr, T->getKeyword(), /*IsDependent*/false, |
| 1369 | /*IsPack=*/false, cast_or_null<ConceptDecl>(*ToTypeConstraintConcept), |
| 1370 | ToTemplateArgs); |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1373 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1374 | const InjectedClassNameType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1375 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1376 | if (!ToDeclOrErr) |
| 1377 | return ToDeclOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1378 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1379 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); |
| 1380 | if (!ToInjTypeOrErr) |
| 1381 | return ToInjTypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1382 | |
| 1383 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 1384 | // See comments in InjectedClassNameType definition for details |
| 1385 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 1386 | enum { |
| 1387 | TypeAlignmentInBits = 4, |
| 1388 | TypeAlignment = 1 << TypeAlignmentInBits |
| 1389 | }; |
| 1390 | |
| 1391 | return QualType(new (Importer.getToContext(), TypeAlignment) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1392 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1395 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
| 1396 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1397 | if (!ToDeclOrErr) |
| 1398 | return ToDeclOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1399 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1400 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1403 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
| 1404 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1405 | if (!ToDeclOrErr) |
| 1406 | return ToDeclOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1407 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1408 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
| 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 ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 1412 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); |
| 1413 | if (!ToModifiedTypeOrErr) |
| 1414 | return ToModifiedTypeOrErr.takeError(); |
| 1415 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); |
| 1416 | if (!ToEquivalentTypeOrErr) |
| 1417 | return ToEquivalentTypeOrErr.takeError(); |
| Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1418 | |
| 1419 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1420 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); |
| Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1421 | } |
| 1422 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1423 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1424 | const TemplateTypeParmType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1425 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1426 | if (!ToDeclOrErr) |
| 1427 | return ToDeclOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1428 | |
| 1429 | return Importer.getToContext().getTemplateTypeParmType( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1430 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1433 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1434 | const SubstTemplateTypeParmType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1435 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); |
| 1436 | if (!ReplacedOrErr) |
| 1437 | return ReplacedOrErr.takeError(); |
| 1438 | const TemplateTypeParmType *Replaced = |
| 1439 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1440 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1441 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); |
| 1442 | if (!ToReplacementTypeOrErr) |
| 1443 | return ToReplacementTypeOrErr.takeError(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1444 | |
| 1445 | return Importer.getToContext().getSubstTemplateTypeParmType( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1446 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1449 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1450 | const TemplateSpecializationType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1451 | auto ToTemplateOrErr = import(T->getTemplateName()); |
| 1452 | if (!ToTemplateOrErr) |
| 1453 | return ToTemplateOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1454 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1455 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1456 | if (Error Err = ImportTemplateArguments( |
| 1457 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
| 1458 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1459 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1460 | QualType ToCanonType; |
| 1461 | if (!QualType(T, 0).isCanonical()) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1462 | QualType FromCanonType |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1463 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1464 | if (ExpectedType TyOrErr = import(FromCanonType)) |
| 1465 | ToCanonType = *TyOrErr; |
| 1466 | else |
| 1467 | return TyOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1468 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1469 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, |
| David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 1470 | ToTemplateArgs, |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1471 | ToCanonType); |
| 1472 | } |
| 1473 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1474 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1475 | // Note: the qualifier in an ElaboratedType is optional. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1476 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1477 | if (!ToQualifierOrErr) |
| 1478 | return ToQualifierOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1479 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1480 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); |
| 1481 | if (!ToNamedTypeOrErr) |
| 1482 | return ToNamedTypeOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1483 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1484 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); |
| 1485 | if (!ToOwnedTagDeclOrErr) |
| 1486 | return ToOwnedTagDeclOrErr.takeError(); |
| Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1487 | |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1488 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1489 | *ToQualifierOrErr, |
| 1490 | *ToNamedTypeOrErr, |
| 1491 | *ToOwnedTagDeclOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1494 | ExpectedType |
| 1495 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 1496 | ExpectedType ToPatternOrErr = import(T->getPattern()); |
| 1497 | if (!ToPatternOrErr) |
| 1498 | return ToPatternOrErr.takeError(); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1499 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1500 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1501 | T->getNumExpansions()); |
| 1502 | } |
| 1503 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1504 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1505 | const DependentTemplateSpecializationType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1506 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1507 | if (!ToQualifierOrErr) |
| 1508 | return ToQualifierOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1509 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1510 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1511 | |
| 1512 | SmallVector<TemplateArgument, 2> ToPack; |
| 1513 | ToPack.reserve(T->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1514 | if (Error Err = ImportTemplateArguments( |
| 1515 | T->getArgs(), T->getNumArgs(), ToPack)) |
| 1516 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1517 | |
| 1518 | return Importer.getToContext().getDependentTemplateSpecializationType( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1519 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1522 | ExpectedType |
| 1523 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { |
| 1524 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1525 | if (!ToQualifierOrErr) |
| 1526 | return ToQualifierOrErr.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1527 | |
| 1528 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1529 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1530 | QualType Canon; |
| 1531 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { |
| 1532 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) |
| 1533 | Canon = (*TyOrErr).getCanonicalType(); |
| 1534 | else |
| 1535 | return TyOrErr.takeError(); |
| 1536 | } |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1537 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1538 | return Importer.getToContext().getDependentNameType(T->getKeyword(), |
| 1539 | *ToQualifierOrErr, |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1540 | Name, Canon); |
| 1541 | } |
| 1542 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1543 | ExpectedType |
| 1544 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
| 1545 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1546 | if (!ToDeclOrErr) |
| 1547 | return ToDeclOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1548 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1549 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1550 | } |
| 1551 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1552 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
| 1553 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1554 | if (!ToBaseTypeOrErr) |
| 1555 | return ToBaseTypeOrErr.takeError(); |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1556 | |
| Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1557 | SmallVector<QualType, 4> TypeArgs; |
| Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1558 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1559 | if (ExpectedType TyOrErr = import(TypeArg)) |
| 1560 | TypeArgs.push_back(*TyOrErr); |
| 1561 | else |
| 1562 | return TyOrErr.takeError(); |
| Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1563 | } |
| 1564 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1565 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1566 | for (auto *P : T->quals()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1567 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) |
| 1568 | Protocols.push_back(*ProtocolOrErr); |
| 1569 | else |
| 1570 | return ProtocolOrErr.takeError(); |
| 1571 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1572 | } |
| 1573 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1574 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, |
| Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1575 | Protocols, |
| 1576 | T->isKindOfTypeAsWritten()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1579 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1580 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1581 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1582 | if (!ToPointeeTypeOrErr) |
| 1583 | return ToPointeeTypeOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1584 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1585 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1586 | } |
| 1587 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1588 | //---------------------------------------------------------------------------- |
| 1589 | // Import Declarations |
| 1590 | //---------------------------------------------------------------------------- |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1591 | Error ASTNodeImporter::ImportDeclParts( |
| 1592 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 1593 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { |
| Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1594 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. |
| 1595 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 1596 | // FIXME: We could support these constructs by importing a different type of |
| 1597 | // this parameter and by importing the original type of the parameter only |
| 1598 | // after the FunctionDecl is created. See |
| 1599 | // VisitFunctionDecl::UsedDifferentProtoType. |
| Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1600 | DeclContext *OrigDC = D->getDeclContext(); |
| 1601 | FunctionDecl *FunDecl; |
| 1602 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && |
| 1603 | FunDecl->hasBody()) { |
| Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1604 | auto getLeafPointeeType = [](const Type *T) { |
| 1605 | while (T->isPointerType() || T->isArrayType()) { |
| 1606 | T = T->getPointeeOrArrayElementType(); |
| 1607 | } |
| 1608 | return T; |
| 1609 | }; |
| 1610 | for (const ParmVarDecl *P : FunDecl->parameters()) { |
| 1611 | const Type *LeafT = |
| 1612 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); |
| 1613 | auto *RT = dyn_cast<RecordType>(LeafT); |
| 1614 | if (RT && RT->getDecl() == D) { |
| 1615 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 1616 | << D->getDeclKindName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1617 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1618 | } |
| Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1619 | } |
| 1620 | } |
| 1621 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1622 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1623 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 1624 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1625 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1626 | // Import the name of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1627 | if (Error Err = importInto(Name, D->getDeclName())) |
| 1628 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1629 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1630 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1631 | if (Error Err = importInto(Loc, D->getLocation())) |
| 1632 | return Err; |
| 1633 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1634 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
| Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 1635 | if (ToD) |
| 1636 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD)) |
| 1637 | return Err; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1638 | |
| 1639 | return Error::success(); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1640 | } |
| 1641 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1642 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1643 | if (!FromD) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1644 | return Error::success(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1645 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1646 | if (!ToD) |
| 1647 | if (Error Err = importInto(ToD, FromD)) |
| 1648 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1649 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1650 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1651 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { |
| 1652 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && |
| 1653 | !ToRecord->getDefinition()) { |
| 1654 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) |
| 1655 | return Err; |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1656 | } |
| 1657 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1658 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1659 | } |
| 1660 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1661 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1662 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1663 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1664 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) |
| 1665 | return Err; |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1666 | } |
| 1667 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1668 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1669 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1670 | |
| 1671 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1674 | Error |
| 1675 | ASTNodeImporter::ImportDeclarationNameLoc( |
| 1676 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1677 | // NOTE: To.Name and To.Loc are already imported. |
| 1678 | // We only have to import To.LocInfo. |
| 1679 | switch (To.getName().getNameKind()) { |
| 1680 | case DeclarationName::Identifier: |
| 1681 | case DeclarationName::ObjCZeroArgSelector: |
| 1682 | case DeclarationName::ObjCOneArgSelector: |
| 1683 | case DeclarationName::ObjCMultiArgSelector: |
| 1684 | case DeclarationName::CXXUsingDirective: |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1685 | case DeclarationName::CXXDeductionGuideName: |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1686 | return Error::success(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1687 | |
| 1688 | case DeclarationName::CXXOperatorName: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1689 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) |
| 1690 | To.setCXXOperatorNameRange(*ToRangeOrErr); |
| 1691 | else |
| 1692 | return ToRangeOrErr.takeError(); |
| 1693 | return Error::success(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1694 | } |
| 1695 | case DeclarationName::CXXLiteralOperatorName: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1696 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) |
| 1697 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); |
| 1698 | else |
| 1699 | return LocOrErr.takeError(); |
| 1700 | return Error::success(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1701 | } |
| 1702 | case DeclarationName::CXXConstructorName: |
| 1703 | case DeclarationName::CXXDestructorName: |
| 1704 | case DeclarationName::CXXConversionFunctionName: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1705 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) |
| 1706 | To.setNamedTypeInfo(*ToTInfoOrErr); |
| 1707 | else |
| 1708 | return ToTInfoOrErr.takeError(); |
| 1709 | return Error::success(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1710 | } |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1711 | } |
| Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1712 | llvm_unreachable("Unknown name kind."); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1715 | Error |
| 1716 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1717 | if (Importer.isMinimalImport() && !ForceImport) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1718 | auto ToDCOrErr = Importer.ImportContext(FromDC); |
| 1719 | return ToDCOrErr.takeError(); |
| 1720 | } |
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1721 | |
| 1722 | // We use strict error handling in case of records and enums, but not |
| 1723 | // with e.g. namespaces. |
| 1724 | // |
| 1725 | // FIXME Clients of the ASTImporter should be able to choose an |
| 1726 | // appropriate error handling strategy for their needs. For instance, |
| 1727 | // they may not want to mark an entire namespace as erroneous merely |
| 1728 | // because there is an ODR error with two typedefs. As another example, |
| 1729 | // the client may allow EnumConstantDecls with same names but with |
| 1730 | // different values in two distinct translation units. |
| 1731 | bool AccumulateChildErrors = isa<TagDecl>(FromDC); |
| 1732 | |
| 1733 | Error ChildErrors = Error::success(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1734 | for (auto *From : FromDC->decls()) { |
| 1735 | ExpectedDecl ImportedOrErr = import(From); |
| shafik | 6a7df3a | 2019-12-19 11:14:39 -0800 | [diff] [blame] | 1736 | |
| 1737 | // If we are in the process of ImportDefinition(...) for a RecordDecl we |
| 1738 | // want to make sure that we are also completing each FieldDecl. There |
| 1739 | // are currently cases where this does not happen and this is correctness |
| 1740 | // fix since operations such as code generation will expect this to be so. |
| 1741 | if (ImportedOrErr) { |
| 1742 | FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From); |
| Raphael Isemann | 326c39b | 2020-01-24 10:42:26 +0100 | [diff] [blame] | 1743 | Decl *ImportedDecl = *ImportedOrErr; |
| shafik | 6a7df3a | 2019-12-19 11:14:39 -0800 | [diff] [blame] | 1744 | FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl); |
| 1745 | if (FieldFrom && FieldTo) { |
| 1746 | const RecordType *RecordFrom = FieldFrom->getType()->getAs<RecordType>(); |
| 1747 | const RecordType *RecordTo = FieldTo->getType()->getAs<RecordType>(); |
| 1748 | if (RecordFrom && RecordTo) { |
| 1749 | RecordDecl *FromRecordDecl = RecordFrom->getDecl(); |
| 1750 | RecordDecl *ToRecordDecl = RecordTo->getDecl(); |
| 1751 | |
| 1752 | if (FromRecordDecl->isCompleteDefinition() && |
| 1753 | !ToRecordDecl->isCompleteDefinition()) { |
| 1754 | Error Err = ImportDefinition(FromRecordDecl, ToRecordDecl); |
| 1755 | |
| 1756 | if (Err && AccumulateChildErrors) |
| 1757 | ChildErrors = joinErrors(std::move(ChildErrors), std::move(Err)); |
| 1758 | else |
| 1759 | consumeError(std::move(Err)); |
| 1760 | } |
| 1761 | } |
| 1762 | } |
| 1763 | } else { |
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1764 | if (AccumulateChildErrors) |
| 1765 | ChildErrors = |
| 1766 | joinErrors(std::move(ChildErrors), ImportedOrErr.takeError()); |
| 1767 | else |
| 1768 | consumeError(ImportedOrErr.takeError()); |
| 1769 | } |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1770 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1771 | |
| Gabor Marton | 48b16e1 | 2019-07-25 09:07:17 +0000 | [diff] [blame] | 1772 | // We reorder declarations in RecordDecls because they may have another order |
| 1773 | // in the "to" context than they have in the "from" context. This may happen |
| 1774 | // e.g when we import a class like this: |
| 1775 | // struct declToImport { |
| 1776 | // int a = c + b; |
| 1777 | // int b = 1; |
| 1778 | // int c = 2; |
| 1779 | // }; |
| 1780 | // During the import of `a` we import first the dependencies in sequence, |
| 1781 | // thus the order would be `c`, `b`, `a`. We will get the normal order by |
| 1782 | // first removing the already imported members and then adding them in the |
| 1783 | // order as they apper in the "from" context. |
| 1784 | // |
| 1785 | // Keeping field order is vital because it determines structure layout. |
| 1786 | // |
| 1787 | // Here and below, we cannot call field_begin() method and its callers on |
| 1788 | // ToDC if it has an external storage. Calling field_begin() will |
| 1789 | // automatically load all the fields by calling |
| 1790 | // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would |
| 1791 | // call ASTImporter::Import(). This is because the ExternalASTSource |
| 1792 | // interface in LLDB is implemented by the means of the ASTImporter. However, |
| 1793 | // calling an import at this point would result in an uncontrolled import, we |
| 1794 | // must avoid that. |
| 1795 | const auto *FromRD = dyn_cast<RecordDecl>(FromDC); |
| 1796 | if (!FromRD) |
| 1797 | return ChildErrors; |
| 1798 | |
| 1799 | auto ToDCOrErr = Importer.ImportContext(FromDC); |
| 1800 | if (!ToDCOrErr) { |
| 1801 | consumeError(std::move(ChildErrors)); |
| 1802 | return ToDCOrErr.takeError(); |
| 1803 | } |
| 1804 | |
| 1805 | DeclContext *ToDC = *ToDCOrErr; |
| 1806 | // Remove all declarations, which may be in wrong order in the |
| 1807 | // lexical DeclContext and then add them in the proper order. |
| 1808 | for (auto *D : FromRD->decls()) { |
| Balazs Keri | 6e08669 | 2019-09-02 07:17:01 +0000 | [diff] [blame] | 1809 | if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<FriendDecl>(D)) { |
| Gabor Marton | 48b16e1 | 2019-07-25 09:07:17 +0000 | [diff] [blame] | 1810 | assert(D && "DC contains a null decl"); |
| 1811 | Decl *ToD = Importer.GetAlreadyImportedOrNull(D); |
| 1812 | // Remove only the decls which we successfully imported. |
| 1813 | if (ToD) { |
| 1814 | assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD)); |
| 1815 | // Remove the decl from its wrong place in the linked list. |
| 1816 | ToDC->removeDecl(ToD); |
| 1817 | // Add the decl to the end of the linked list. |
| 1818 | // This time it will be at the proper place because the enclosing for |
| 1819 | // loop iterates in the original (good) order of the decls. |
| 1820 | ToDC->addDeclInternal(ToD); |
| 1821 | } |
| 1822 | } |
| 1823 | } |
| 1824 | |
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1825 | return ChildErrors; |
| Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1826 | } |
| 1827 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1828 | Error ASTNodeImporter::ImportDeclContext( |
| 1829 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { |
| 1830 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); |
| 1831 | if (!ToDCOrErr) |
| 1832 | return ToDCOrErr.takeError(); |
| 1833 | ToDC = *ToDCOrErr; |
| 1834 | |
| 1835 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { |
| 1836 | auto ToLexicalDCOrErr = Importer.ImportContext( |
| 1837 | FromD->getLexicalDeclContext()); |
| 1838 | if (!ToLexicalDCOrErr) |
| 1839 | return ToLexicalDCOrErr.takeError(); |
| 1840 | ToLexicalDC = *ToLexicalDCOrErr; |
| 1841 | } else |
| 1842 | ToLexicalDC = ToDC; |
| 1843 | |
| 1844 | return Error::success(); |
| 1845 | } |
| 1846 | |
| 1847 | Error ASTNodeImporter::ImportImplicitMethods( |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1848 | const CXXRecordDecl *From, CXXRecordDecl *To) { |
| 1849 | assert(From->isCompleteDefinition() && To->getDefinition() == To && |
| 1850 | "Import implicit methods to or from non-definition"); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1851 | |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1852 | for (CXXMethodDecl *FromM : From->methods()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1853 | if (FromM->isImplicit()) { |
| 1854 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); |
| 1855 | if (!ToMOrErr) |
| 1856 | return ToMOrErr.takeError(); |
| 1857 | } |
| 1858 | |
| 1859 | return Error::success(); |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1862 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1863 | ASTImporter &Importer) { |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1864 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 1865 | if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef)) |
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 1866 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); |
| 1867 | else |
| 1868 | return ToTypedefOrErr.takeError(); |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1869 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1870 | return Error::success(); |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1871 | } |
| 1872 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1873 | Error ASTNodeImporter::ImportDefinition( |
| 1874 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1875 | auto DefinitionCompleter = [To]() { |
| 1876 | // There are cases in LLDB when we first import a class without its |
| 1877 | // members. The class will have DefinitionData, but no members. Then, |
| 1878 | // importDefinition is called from LLDB, which tries to get the members, so |
| 1879 | // when we get here, the class already has the DefinitionData set, so we |
| 1880 | // must unset the CompleteDefinition here to be able to complete again the |
| 1881 | // definition. |
| 1882 | To->setCompleteDefinition(false); |
| 1883 | To->completeDefinition(); |
| 1884 | }; |
| 1885 | |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1886 | if (To->getDefinition() || To->isBeingDefined()) { |
| Gabor Marton | e73805f | 2019-07-08 12:49:13 +0000 | [diff] [blame] | 1887 | if (Kind == IDK_Everything || |
| 1888 | // In case of lambdas, the class already has a definition ptr set, but |
| 1889 | // the contained decls are not imported yet. Also, isBeingDefined was |
| 1890 | // set in CXXRecordDecl::CreateLambda. We must import the contained |
| 1891 | // decls here and finish the definition. |
| 1892 | (To->isLambda() && shouldForceImportDeclContext(Kind))) { |
| Richard Smith | ebcbd5ba | 2020-06-04 19:15:22 -0700 | [diff] [blame] | 1893 | if (To->isLambda()) { |
| 1894 | auto *FromCXXRD = cast<CXXRecordDecl>(From); |
| 1895 | SmallVector<LambdaCapture, 8> ToCaptures; |
| 1896 | ToCaptures.reserve(FromCXXRD->capture_size()); |
| 1897 | for (const auto &FromCapture : FromCXXRD->captures()) { |
| 1898 | if (auto ToCaptureOrErr = import(FromCapture)) |
| 1899 | ToCaptures.push_back(*ToCaptureOrErr); |
| 1900 | else |
| 1901 | return ToCaptureOrErr.takeError(); |
| 1902 | } |
| 1903 | cast<CXXRecordDecl>(To)->setCaptures(ToCaptures); |
| 1904 | } |
| 1905 | |
| Gabor Marton | e73805f | 2019-07-08 12:49:13 +0000 | [diff] [blame] | 1906 | Error Result = ImportDeclContext(From, /*ForceImport=*/true); |
| 1907 | // Finish the definition of the lambda, set isBeingDefined to false. |
| 1908 | if (To->isLambda()) |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1909 | DefinitionCompleter(); |
| Gabor Marton | e73805f | 2019-07-08 12:49:13 +0000 | [diff] [blame] | 1910 | return Result; |
| 1911 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1912 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1913 | return Error::success(); |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1914 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1915 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1916 | To->startDefinition(); |
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1917 | // Complete the definition even if error is returned. |
| 1918 | // The RecordDecl may be already part of the AST so it is better to |
| 1919 | // have it in complete state even if something is wrong with it. |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1920 | auto DefinitionCompleterScopeExit = |
| 1921 | llvm::make_scope_exit(DefinitionCompleter); |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1922 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1923 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1924 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1925 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1926 | // Add base classes. |
| Gabor Marton | 17d3967 | 2018-11-26 15:54:08 +0000 | [diff] [blame] | 1927 | auto *ToCXX = dyn_cast<CXXRecordDecl>(To); |
| 1928 | auto *FromCXX = dyn_cast<CXXRecordDecl>(From); |
| 1929 | if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) { |
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1930 | |
| 1931 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1932 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 1933 | |
| 1934 | #define FIELD(Name, Width, Merge) \ |
| 1935 | ToData.Name = FromData.Name; |
| 1936 | #include "clang/AST/CXXRecordDeclDefinitionBits.def" |
| Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1937 | |
| Shafik Yaghmour | 16b9073 | 2019-04-26 18:51:28 +0000 | [diff] [blame] | 1938 | // Copy over the data stored in RecordDeclBits |
| 1939 | ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions()); |
| 1940 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1941 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1942 | for (const auto &Base1 : FromCXX->bases()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1943 | ExpectedType TyOrErr = import(Base1.getType()); |
| 1944 | if (!TyOrErr) |
| 1945 | return TyOrErr.takeError(); |
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1946 | |
| 1947 | SourceLocation EllipsisLoc; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1948 | if (Base1.isPackExpansion()) { |
| 1949 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) |
| 1950 | EllipsisLoc = *LocOrErr; |
| 1951 | else |
| 1952 | return LocOrErr.takeError(); |
| 1953 | } |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1954 | |
| 1955 | // Ensure that we have a definition for the base. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1956 | if (Error Err = |
| 1957 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) |
| 1958 | return Err; |
| 1959 | |
| 1960 | auto RangeOrErr = import(Base1.getSourceRange()); |
| 1961 | if (!RangeOrErr) |
| 1962 | return RangeOrErr.takeError(); |
| 1963 | |
| 1964 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); |
| 1965 | if (!TSIOrErr) |
| 1966 | return TSIOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1967 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1968 | Bases.push_back( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1969 | new (Importer.getToContext()) CXXBaseSpecifier( |
| 1970 | *RangeOrErr, |
| 1971 | Base1.isVirtual(), |
| 1972 | Base1.isBaseOfClass(), |
| 1973 | Base1.getAccessSpecifierAsWritten(), |
| 1974 | *TSIOrErr, |
| 1975 | EllipsisLoc)); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1976 | } |
| 1977 | if (!Bases.empty()) |
| Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1978 | ToCXX->setBases(Bases.data(), Bases.size()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1979 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1980 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1981 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1982 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1983 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1984 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1985 | return Error::success(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1986 | } |
| 1987 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1988 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1989 | if (To->getAnyInitializer()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1990 | return Error::success(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1991 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1992 | Expr *FromInit = From->getInit(); |
| 1993 | if (!FromInit) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1994 | return Error::success(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1995 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1996 | ExpectedExpr ToInitOrErr = import(FromInit); |
| 1997 | if (!ToInitOrErr) |
| 1998 | return ToInitOrErr.takeError(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1999 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2000 | To->setInit(*ToInitOrErr); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 2001 | if (From->isInitKnownICE()) { |
| 2002 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); |
| 2003 | Eval->CheckedICE = true; |
| 2004 | Eval->IsICE = From->isInitICE(); |
| 2005 | } |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2006 | |
| 2007 | // FIXME: Other bits to merge? |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2008 | return Error::success(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2009 | } |
| 2010 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2011 | Error ASTNodeImporter::ImportDefinition( |
| 2012 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2013 | if (To->getDefinition() || To->isBeingDefined()) { |
| 2014 | if (Kind == IDK_Everything) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2015 | return ImportDeclContext(From, /*ForceImport=*/true); |
| 2016 | return Error::success(); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2017 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2018 | |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2019 | To->startDefinition(); |
| 2020 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2021 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 2022 | return Err; |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 2023 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2024 | ExpectedType ToTypeOrErr = |
| 2025 | import(Importer.getFromContext().getTypeDeclType(From)); |
| 2026 | if (!ToTypeOrErr) |
| 2027 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2028 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2029 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); |
| 2030 | if (!ToPromotionTypeOrErr) |
| 2031 | return ToPromotionTypeOrErr.takeError(); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2032 | |
| 2033 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2034 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 2035 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2036 | |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2037 | // FIXME: we might need to merge the number of positive or negative bits |
| 2038 | // if the enumerator lists don't match. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2039 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2040 | From->getNumPositiveBits(), |
| 2041 | From->getNumNegativeBits()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2042 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2045 | Error ASTNodeImporter::ImportTemplateArguments( |
| 2046 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 2047 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 2048 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2049 | if (auto ToOrErr = import(FromArgs[I])) |
| 2050 | ToArgs.push_back(*ToOrErr); |
| 2051 | else |
| 2052 | return ToOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 2053 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2054 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2055 | return Error::success(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 2056 | } |
| 2057 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2058 | // FIXME: Do not forget to remove this and use only 'import'. |
| 2059 | Expected<TemplateArgument> |
| 2060 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 2061 | return import(From); |
| 2062 | } |
| 2063 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2064 | template <typename InContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2065 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2066 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 2067 | for (const auto &FromLoc : Container) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2068 | if (auto ToLocOrErr = import(FromLoc)) |
| 2069 | ToTAInfo.addArgument(*ToLocOrErr); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2070 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2071 | return ToLocOrErr.takeError(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2072 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2073 | return Error::success(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2074 | } |
| 2075 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2076 | static StructuralEquivalenceKind |
| 2077 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 2078 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 2079 | : StructuralEquivalenceKind::Default; |
| 2080 | } |
| 2081 | |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2082 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { |
| 2083 | StructuralEquivalenceContext Ctx( |
| 2084 | Importer.getFromContext(), Importer.getToContext(), |
| 2085 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2086 | false, Complain); |
| 2087 | return Ctx.IsEquivalent(From, To); |
| 2088 | } |
| 2089 | |
| 2090 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2091 | RecordDecl *ToRecord, bool Complain) { |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2092 | // Eliminate a potential failure point where we attempt to re-import |
| 2093 | // something we're trying to import while completing ToRecord. |
| 2094 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 2095 | if (ToOrigin) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2096 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2097 | if (ToOriginRecord) |
| 2098 | ToRecord = ToOriginRecord; |
| 2099 | } |
| 2100 | |
| Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 2101 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2102 | ToRecord->getASTContext(), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2103 | Importer.getNonEquivalentDecls(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2104 | getStructuralEquivalenceKind(Importer), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2105 | false, Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2106 | return Ctx.IsEquivalent(FromRecord, ToRecord); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2107 | } |
| 2108 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2109 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 2110 | bool Complain) { |
| 2111 | StructuralEquivalenceContext Ctx( |
| 2112 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2113 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2114 | false, Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2115 | return Ctx.IsEquivalent(FromVar, ToVar); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2116 | } |
| 2117 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2118 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
| Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 2119 | // Eliminate a potential failure point where we attempt to re-import |
| Raphael Isemann | fa26c20 | 2019-04-09 14:18:23 +0000 | [diff] [blame] | 2120 | // something we're trying to import while completing ToEnum. |
| Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 2121 | if (Decl *ToOrigin = Importer.GetOriginalDecl(ToEnum)) |
| 2122 | if (auto *ToOriginEnum = dyn_cast<EnumDecl>(ToOrigin)) |
| 2123 | ToEnum = ToOriginEnum; |
| 2124 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2125 | StructuralEquivalenceContext Ctx( |
| 2126 | Importer.getFromContext(), Importer.getToContext(), |
| 2127 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2128 | return Ctx.IsEquivalent(FromEnum, ToEnum); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2129 | } |
| 2130 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2131 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 2132 | FunctionTemplateDecl *To) { |
| 2133 | StructuralEquivalenceContext Ctx( |
| 2134 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2135 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2136 | false, false); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2137 | return Ctx.IsEquivalent(From, To); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2138 | } |
| 2139 | |
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2140 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 2141 | StructuralEquivalenceContext Ctx( |
| 2142 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2143 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2144 | false, false); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2145 | return Ctx.IsEquivalent(From, To); |
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2146 | } |
| 2147 | |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2148 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2149 | EnumConstantDecl *ToEC) { |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2150 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 2151 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 2152 | |
| 2153 | return FromVal.isSigned() == ToVal.isSigned() && |
| 2154 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 2155 | FromVal == ToVal; |
| 2156 | } |
| 2157 | |
| 2158 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2159 | ClassTemplateDecl *To) { |
| 2160 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2161 | Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2162 | Importer.getNonEquivalentDecls(), |
| 2163 | getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2164 | return Ctx.IsEquivalent(From, To); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2165 | } |
| 2166 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2167 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 2168 | VarTemplateDecl *To) { |
| 2169 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2170 | Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2171 | Importer.getNonEquivalentDecls(), |
| 2172 | getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2173 | return Ctx.IsEquivalent(From, To); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2174 | } |
| 2175 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2176 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 2177 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2178 | << D->getDeclKindName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2179 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2180 | } |
| 2181 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2182 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { |
| 2183 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 2184 | << D->getDeclKindName(); |
| 2185 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| 2186 | } |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2187 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2188 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 2189 | // Import the context of this declaration. |
| 2190 | DeclContext *DC, *LexicalDC; |
| 2191 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 2192 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2193 | |
| 2194 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2195 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2196 | if (!LocOrErr) |
| 2197 | return LocOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2198 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2199 | EmptyDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2200 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2201 | return ToD; |
| 2202 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2203 | ToD->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2204 | LexicalDC->addDeclInternal(ToD); |
| 2205 | return ToD; |
| 2206 | } |
| 2207 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2208 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2209 | TranslationUnitDecl *ToD = |
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2210 | Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2211 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2212 | Importer.MapImported(D, ToD); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2213 | |
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2214 | return ToD; |
| 2215 | } |
| 2216 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2217 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 2218 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2219 | if (!LocOrErr) |
| 2220 | return LocOrErr.takeError(); |
| 2221 | auto ColonLocOrErr = import(D->getColonLoc()); |
| 2222 | if (!ColonLocOrErr) |
| 2223 | return ColonLocOrErr.takeError(); |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2224 | |
| 2225 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2226 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2227 | if (!DCOrErr) |
| 2228 | return DCOrErr.takeError(); |
| 2229 | DeclContext *DC = *DCOrErr; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2230 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2231 | AccessSpecDecl *ToD; |
| 2232 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2233 | DC, *LocOrErr, *ColonLocOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2234 | return ToD; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2235 | |
| 2236 | // Lexical DeclContext and Semantic DeclContext |
| 2237 | // is always the same for the accessSpec. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2238 | ToD->setLexicalDeclContext(DC); |
| 2239 | DC->addDeclInternal(ToD); |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2240 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2241 | return ToD; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2242 | } |
| 2243 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2244 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 2245 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2246 | if (!DCOrErr) |
| 2247 | return DCOrErr.takeError(); |
| 2248 | DeclContext *DC = *DCOrErr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2249 | DeclContext *LexicalDC = DC; |
| 2250 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2251 | Error Err = Error::success(); |
| 2252 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 2253 | auto ToRParenLoc = importChecked(Err, D->getRParenLoc()); |
| 2254 | auto ToAssertExpr = importChecked(Err, D->getAssertExpr()); |
| 2255 | auto ToMessage = importChecked(Err, D->getMessage()); |
| 2256 | if (Err) |
| 2257 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2258 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2259 | StaticAssertDecl *ToD; |
| 2260 | if (GetImportedOrCreateDecl( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2261 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, |
| 2262 | ToRParenLoc, D->isFailed())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2263 | return ToD; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2264 | |
| 2265 | ToD->setLexicalDeclContext(LexicalDC); |
| 2266 | LexicalDC->addDeclInternal(ToD); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2267 | return ToD; |
| 2268 | } |
| 2269 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2270 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2271 | // Import the major distinguishing characteristics of this namespace. |
| 2272 | DeclContext *DC, *LexicalDC; |
| 2273 | DeclarationName Name; |
| 2274 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2275 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2276 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2277 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2278 | if (ToD) |
| 2279 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2280 | |
| 2281 | NamespaceDecl *MergeWithNamespace = nullptr; |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2282 | if (!Name) { |
| 2283 | // This is an anonymous namespace. Adopt an existing anonymous |
| 2284 | // namespace if we can. |
| 2285 | // FIXME: Not testable. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2286 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2287 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 2288 | else |
| 2289 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 2290 | } else { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2291 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2292 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2293 | for (auto *FoundDecl : FoundDecls) { |
| 2294 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2295 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2296 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2297 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2298 | MergeWithNamespace = FoundNS; |
| 2299 | ConflictingDecls.clear(); |
| 2300 | break; |
| 2301 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2302 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2303 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2304 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2305 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2306 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2307 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2308 | Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(), |
| 2309 | ConflictingDecls.size()); |
| 2310 | if (NameOrErr) |
| 2311 | Name = NameOrErr.get(); |
| 2312 | else |
| 2313 | return NameOrErr.takeError(); |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2314 | } |
| 2315 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2316 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2317 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2318 | if (!BeginLocOrErr) |
| 2319 | return BeginLocOrErr.takeError(); |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2320 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 2321 | if (!RBraceLocOrErr) |
| 2322 | return RBraceLocOrErr.takeError(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2323 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2324 | // Create the "to" namespace, if needed. |
| 2325 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 2326 | if (!ToNamespace) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2327 | if (GetImportedOrCreateDecl( |
| 2328 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2329 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2330 | /*PrevDecl=*/nullptr)) |
| 2331 | return ToNamespace; |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2332 | ToNamespace->setRBraceLoc(*RBraceLocOrErr); |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2333 | ToNamespace->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2334 | LexicalDC->addDeclInternal(ToNamespace); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2335 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2336 | // If this is an anonymous namespace, register it as the anonymous |
| 2337 | // namespace within its context. |
| 2338 | if (!Name) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2339 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2340 | TU->setAnonymousNamespace(ToNamespace); |
| 2341 | else |
| 2342 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 2343 | } |
| 2344 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2345 | Importer.MapImported(D, ToNamespace); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2346 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2347 | if (Error Err = ImportDeclContext(D)) |
| 2348 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2349 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2350 | return ToNamespace; |
| 2351 | } |
| 2352 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2353 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2354 | // Import the major distinguishing characteristics of this namespace. |
| 2355 | DeclContext *DC, *LexicalDC; |
| 2356 | DeclarationName Name; |
| 2357 | SourceLocation Loc; |
| 2358 | NamedDecl *LookupD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2359 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 2360 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2361 | if (LookupD) |
| 2362 | return LookupD; |
| 2363 | |
| 2364 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 2365 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2366 | Error Err = Error::success(); |
| 2367 | auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc()); |
| 2368 | auto ToAliasLoc = importChecked(Err, D->getAliasLoc()); |
| 2369 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 2370 | auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc()); |
| 2371 | auto ToNamespace = importChecked(Err, D->getNamespace()); |
| 2372 | if (Err) |
| 2373 | return std::move(Err); |
| 2374 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2375 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2376 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2377 | NamespaceAliasDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2378 | if (GetImportedOrCreateDecl( |
| 2379 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, |
| 2380 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2381 | return ToD; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2382 | |
| 2383 | ToD->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2384 | LexicalDC->addDeclInternal(ToD); |
| 2385 | |
| 2386 | return ToD; |
| 2387 | } |
| 2388 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2389 | ExpectedDecl |
| 2390 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2391 | // Import the major distinguishing characteristics of this typedef. |
| 2392 | DeclContext *DC, *LexicalDC; |
| 2393 | DeclarationName Name; |
| 2394 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2395 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2396 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2397 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2398 | if (ToD) |
| 2399 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2400 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2401 | // If this typedef is not in block scope, determine whether we've |
| 2402 | // seen a typedef with the same name (that we can merge with) or any |
| 2403 | // other entity by that name (which name lookup could conflict with). |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 2404 | // Note: Repeated typedefs are not valid in C99: |
| 2405 | // 'typedef int T; typedef int T;' is invalid |
| 2406 | // We do not care about this now. |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2407 | if (!DC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2408 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2409 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2410 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2411 | for (auto *FoundDecl : FoundDecls) { |
| 2412 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2413 | continue; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2414 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 2415 | if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D)) |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 2416 | continue; |
| 2417 | |
| Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2418 | QualType FromUT = D->getUnderlyingType(); |
| 2419 | QualType FoundUT = FoundTypedef->getUnderlyingType(); |
| 2420 | if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) { |
| 2421 | // If the "From" context has a complete underlying type but we |
| 2422 | // already have a complete underlying type then return with that. |
| 2423 | if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2424 | return Importer.MapImported(D, FoundTypedef); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2425 | // FIXME Handle redecl chain. When you do that make consistent changes |
| 2426 | // in ASTImporterLookupTable too. |
| 2427 | } else { |
| 2428 | ConflictingDecls.push_back(FoundDecl); |
| Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2429 | } |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2430 | } |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2431 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2432 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2433 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2434 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2435 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 2436 | if (NameOrErr) |
| 2437 | Name = NameOrErr.get(); |
| 2438 | else |
| 2439 | return NameOrErr.takeError(); |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2440 | } |
| 2441 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2442 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2443 | Error Err = Error::success(); |
| 2444 | auto ToUnderlyingType = importChecked(Err, D->getUnderlyingType()); |
| 2445 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 2446 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); |
| 2447 | if (Err) |
| 2448 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2449 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2450 | // Create the new typedef node. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2451 | // FIXME: ToUnderlyingType is not used. |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2452 | (void)ToUnderlyingType; |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2453 | TypedefNameDecl *ToTypedef; |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2454 | if (IsAlias) { |
| 2455 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2456 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2457 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2458 | return ToTypedef; |
| 2459 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2460 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2461 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2462 | return ToTypedef; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2463 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2464 | ToTypedef->setAccess(D->getAccess()); |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2465 | ToTypedef->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2466 | |
| 2467 | // Templated declarations should not appear in DeclContext. |
| 2468 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 2469 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 2470 | LexicalDC->addDeclInternal(ToTypedef); |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2471 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2472 | return ToTypedef; |
| 2473 | } |
| 2474 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2475 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2476 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 2477 | } |
| 2478 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2479 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2480 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 2481 | } |
| 2482 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2483 | ExpectedDecl |
| 2484 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2485 | // Import the major distinguishing characteristics of this typedef. |
| 2486 | DeclContext *DC, *LexicalDC; |
| 2487 | DeclarationName Name; |
| 2488 | SourceLocation Loc; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2489 | NamedDecl *FoundD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2490 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
| 2491 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2492 | if (FoundD) |
| 2493 | return FoundD; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2494 | |
| 2495 | // If this typedef is not in block scope, determine whether we've |
| 2496 | // seen a typedef with the same name (that we can merge with) or any |
| 2497 | // other entity by that name (which name lookup could conflict with). |
| 2498 | if (!DC->isFunctionOrMethod()) { |
| 2499 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 2500 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2501 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2502 | for (auto *FoundDecl : FoundDecls) { |
| 2503 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2504 | continue; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2505 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2506 | return Importer.MapImported(D, FoundAlias); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2507 | ConflictingDecls.push_back(FoundDecl); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2508 | } |
| 2509 | |
| 2510 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2511 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2512 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 2513 | if (NameOrErr) |
| 2514 | Name = NameOrErr.get(); |
| 2515 | else |
| 2516 | return NameOrErr.takeError(); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2517 | } |
| 2518 | } |
| 2519 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2520 | Error Err = Error::success(); |
| 2521 | auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters()); |
| 2522 | auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl()); |
| 2523 | if (Err) |
| 2524 | return std::move(Err); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2525 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2526 | TypeAliasTemplateDecl *ToAlias; |
| 2527 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2528 | Name, ToTemplateParameters, ToTemplatedDecl)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2529 | return ToAlias; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2530 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2531 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2532 | |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2533 | ToAlias->setAccess(D->getAccess()); |
| 2534 | ToAlias->setLexicalDeclContext(LexicalDC); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2535 | LexicalDC->addDeclInternal(ToAlias); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2536 | return ToAlias; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2537 | } |
| 2538 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2539 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2540 | // Import the major distinguishing characteristics of this label. |
| 2541 | DeclContext *DC, *LexicalDC; |
| 2542 | DeclarationName Name; |
| 2543 | SourceLocation Loc; |
| 2544 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2545 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2546 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2547 | if (ToD) |
| 2548 | return ToD; |
| 2549 | |
| 2550 | assert(LexicalDC->isFunctionOrMethod()); |
| 2551 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2552 | LabelDecl *ToLabel; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2553 | if (D->isGnuLocal()) { |
| 2554 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2555 | if (!BeginLocOrErr) |
| 2556 | return BeginLocOrErr.takeError(); |
| 2557 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2558 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) |
| 2559 | return ToLabel; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2560 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2561 | } else { |
| 2562 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2563 | Name.getAsIdentifierInfo())) |
| 2564 | return ToLabel; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2565 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2566 | } |
| 2567 | |
| 2568 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); |
| 2569 | if (!ToStmtOrErr) |
| 2570 | return ToStmtOrErr.takeError(); |
| 2571 | |
| 2572 | ToLabel->setStmt(*ToStmtOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2573 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2574 | LexicalDC->addDeclInternal(ToLabel); |
| 2575 | return ToLabel; |
| 2576 | } |
| 2577 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2578 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2579 | // Import the major distinguishing characteristics of this enum. |
| 2580 | DeclContext *DC, *LexicalDC; |
| 2581 | DeclarationName Name; |
| 2582 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2583 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2584 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2585 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2586 | if (ToD) |
| 2587 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2588 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2589 | // Figure out what enum name we're looking for. |
| 2590 | unsigned IDNS = Decl::IDNS_Tag; |
| 2591 | DeclarationName SearchName = Name; |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2592 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2593 | if (Error Err = importInto( |
| 2594 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2595 | return std::move(Err); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2596 | IDNS = Decl::IDNS_Ordinary; |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2597 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2598 | IDNS |= Decl::IDNS_Ordinary; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2599 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2600 | // We may already have an enum of the same name; try to find and match it. |
| Balázs Kéri | d4741c4 | 2020-02-17 14:25:16 +0100 | [diff] [blame] | 2601 | EnumDecl *PrevDecl = nullptr; |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2602 | if (!DC->isFunctionOrMethod() && SearchName) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2603 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2604 | auto FoundDecls = |
| 2605 | Importer.findDeclsInToCtx(DC, SearchName); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2606 | for (auto *FoundDecl : FoundDecls) { |
| 2607 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2608 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2609 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2610 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2611 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2612 | FoundDecl = Tag->getDecl(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2613 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2614 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2615 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 2616 | if (!hasSameVisibilityContextAndLinkage(FoundEnum, D)) |
| Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 2617 | continue; |
| Balázs Kéri | d4741c4 | 2020-02-17 14:25:16 +0100 | [diff] [blame] | 2618 | if (IsStructuralMatch(D, FoundEnum)) { |
| 2619 | EnumDecl *FoundDef = FoundEnum->getDefinition(); |
| 2620 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 2621 | return Importer.MapImported(D, FoundDef); |
| 2622 | PrevDecl = FoundEnum->getMostRecentDecl(); |
| 2623 | break; |
| 2624 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2625 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2626 | } |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2627 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2628 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2629 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2630 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2631 | SearchName, DC, IDNS, ConflictingDecls.data(), |
| 2632 | ConflictingDecls.size()); |
| 2633 | if (NameOrErr) |
| 2634 | Name = NameOrErr.get(); |
| 2635 | else |
| 2636 | return NameOrErr.takeError(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2637 | } |
| 2638 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2639 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2640 | Error Err = Error::success(); |
| 2641 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); |
| 2642 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 2643 | auto ToIntegerType = importChecked(Err, D->getIntegerType()); |
| 2644 | auto ToBraceRange = importChecked(Err, D->getBraceRange()); |
| 2645 | if (Err) |
| 2646 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2647 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2648 | // Create the enum declaration. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2649 | EnumDecl *D2; |
| 2650 | if (GetImportedOrCreateDecl( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2651 | D2, D, Importer.getToContext(), DC, ToBeginLoc, |
| Balázs Kéri | d4741c4 | 2020-02-17 14:25:16 +0100 | [diff] [blame] | 2652 | Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2653 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2654 | return D2; |
| 2655 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2656 | D2->setQualifierInfo(ToQualifierLoc); |
| 2657 | D2->setIntegerType(ToIntegerType); |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2658 | D2->setBraceRange(ToBraceRange); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2659 | D2->setAccess(D->getAccess()); |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2660 | D2->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2661 | LexicalDC->addDeclInternal(D2); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2662 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2663 | // Import the definition |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2664 | if (D->isCompleteDefinition()) |
| 2665 | if (Error Err = ImportDefinition(D, D2)) |
| 2666 | return std::move(Err); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2667 | |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2668 | return D2; |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2669 | } |
| 2670 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2671 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2672 | bool IsFriendTemplate = false; |
| 2673 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2674 | IsFriendTemplate = |
| 2675 | DCXX->getDescribedClassTemplate() && |
| 2676 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != |
| 2677 | Decl::FOK_None; |
| 2678 | } |
| 2679 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2680 | // Import the major distinguishing characteristics of this record. |
| Simon Pilgrim | 4706f3b | 2019-10-15 10:23:05 +0000 | [diff] [blame] | 2681 | DeclContext *DC = nullptr, *LexicalDC = nullptr; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2682 | DeclarationName Name; |
| 2683 | SourceLocation Loc; |
| Simon Pilgrim | 4706f3b | 2019-10-15 10:23:05 +0000 | [diff] [blame] | 2684 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2685 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2686 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2687 | if (ToD) |
| 2688 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2689 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2690 | // Figure out what structure name we're looking for. |
| 2691 | unsigned IDNS = Decl::IDNS_Tag; |
| 2692 | DeclarationName SearchName = Name; |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2693 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2694 | if (Error Err = importInto( |
| 2695 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2696 | return std::move(Err); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2697 | IDNS = Decl::IDNS_Ordinary; |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2698 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2699 | IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2700 | |
| 2701 | // 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] | 2702 | RecordDecl *PrevDecl = nullptr; |
| Gabor Marton | e3e83d7 | 2019-08-30 10:55:41 +0000 | [diff] [blame] | 2703 | if (!DC->isFunctionOrMethod() && !D->isLambda()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2704 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2705 | auto FoundDecls = |
| 2706 | Importer.findDeclsInToCtx(DC, SearchName); |
| Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2707 | if (!FoundDecls.empty()) { |
| Gabor Marton | 41e3892 | 2019-03-05 11:23:24 +0000 | [diff] [blame] | 2708 | // We're going to have to compare D against potentially conflicting Decls, |
| 2709 | // so complete it. |
| Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2710 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2711 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2712 | } |
| 2713 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2714 | for (auto *FoundDecl : FoundDecls) { |
| 2715 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2716 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2717 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2718 | Decl *Found = FoundDecl; |
| 2719 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2720 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2721 | Found = Tag->getDecl(); |
| 2722 | } |
| Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2723 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2724 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2725 | // Do not emit false positive diagnostic in case of unnamed |
| 2726 | // struct/union and in case of anonymous structs. Would be false |
| 2727 | // because there may be several anonymous/unnamed structs in a class. |
| 2728 | // E.g. these are both valid: |
| 2729 | // struct A { // unnamed structs |
| 2730 | // struct { struct A *next; } entry0; |
| 2731 | // struct { struct A *next; } entry1; |
| 2732 | // }; |
| 2733 | // struct X { struct { int a; }; struct { int b; }; }; // anon structs |
| 2734 | if (!SearchName) |
| Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2735 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2736 | continue; |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2737 | |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 2738 | if (!hasSameVisibilityContextAndLinkage(FoundRecord, D)) |
| Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 2739 | continue; |
| 2740 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2741 | if (IsStructuralMatch(D, FoundRecord)) { |
| 2742 | RecordDecl *FoundDef = FoundRecord->getDefinition(); |
| 2743 | if (D->isThisDeclarationADefinition() && FoundDef) { |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2744 | // FIXME: Structural equivalence check should check for same |
| 2745 | // user-defined methods. |
| 2746 | Importer.MapImported(D, FoundDef); |
| 2747 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2748 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); |
| 2749 | assert(FoundCXX && "Record type mismatch"); |
| 2750 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2751 | if (!Importer.isMinimalImport()) |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2752 | // FoundDef may not have every implicit method that D has |
| 2753 | // because implicit methods are created only if they are used. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2754 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) |
| 2755 | return std::move(Err); |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2756 | } |
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2757 | } |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2758 | PrevDecl = FoundRecord->getMostRecentDecl(); |
| 2759 | break; |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2760 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2761 | ConflictingDecls.push_back(FoundDecl); |
| 2762 | } // kind is RecordDecl |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2763 | } // for |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2764 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2765 | if (!ConflictingDecls.empty() && SearchName) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2766 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2767 | SearchName, DC, IDNS, ConflictingDecls.data(), |
| 2768 | ConflictingDecls.size()); |
| 2769 | if (NameOrErr) |
| 2770 | Name = NameOrErr.get(); |
| 2771 | else |
| 2772 | return NameOrErr.takeError(); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2773 | } |
| 2774 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2775 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2776 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2777 | if (!BeginLocOrErr) |
| 2778 | return BeginLocOrErr.takeError(); |
| 2779 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2780 | // Create the record declaration. |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2781 | RecordDecl *D2 = nullptr; |
| 2782 | CXXRecordDecl *D2CXX = nullptr; |
| 2783 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2784 | if (DCXX->isLambda()) { |
| 2785 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); |
| 2786 | if (!TInfoOrErr) |
| 2787 | return TInfoOrErr.takeError(); |
| 2788 | if (GetImportedOrCreateSpecialDecl( |
| 2789 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
| 2790 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), |
| 2791 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2792 | return D2CXX; |
| 2793 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); |
| 2794 | if (!CDeclOrErr) |
| 2795 | return CDeclOrErr.takeError(); |
| Michael Liao | 243ebfb | 2019-10-19 00:15:19 +0000 | [diff] [blame] | 2796 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr, |
| 2797 | DCXX->hasKnownLambdaInternalLinkage()); |
| Richard Smith | 825e3bb | 2020-06-04 19:16:05 -0700 | [diff] [blame] | 2798 | } else if (DCXX->isInjectedClassName()) { |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2799 | // We have to be careful to do a similar dance to the one in |
| 2800 | // Sema::ActOnStartCXXMemberDeclarations |
| 2801 | const bool DelayTypeCreation = true; |
| 2802 | if (GetImportedOrCreateDecl( |
| 2803 | D2CXX, D, Importer.getToContext(), D->getTagKind(), DC, |
| 2804 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
| 2805 | cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation)) |
| 2806 | return D2CXX; |
| 2807 | Importer.getToContext().getTypeDeclType( |
| 2808 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
| 2809 | } else { |
| 2810 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2811 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2812 | Name.getAsIdentifierInfo(), |
| 2813 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2814 | return D2CXX; |
| 2815 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2816 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2817 | D2 = D2CXX; |
| 2818 | D2->setAccess(D->getAccess()); |
| 2819 | D2->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 2820 | addDeclToContexts(D, D2); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2821 | |
| 2822 | if (ClassTemplateDecl *FromDescribed = |
| 2823 | DCXX->getDescribedClassTemplate()) { |
| 2824 | ClassTemplateDecl *ToDescribed; |
| 2825 | if (Error Err = importInto(ToDescribed, FromDescribed)) |
| 2826 | return std::move(Err); |
| 2827 | D2CXX->setDescribedClassTemplate(ToDescribed); |
| 2828 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { |
| 2829 | // In a record describing a template the type should be an |
| 2830 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2831 | // previously set type to the correct value here (ToDescribed is not |
| 2832 | // available at record create). |
| 2833 | // FIXME: The previous type is cleared but not removed from |
| 2834 | // ASTContext's internal storage. |
| 2835 | CXXRecordDecl *Injected = nullptr; |
| 2836 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2837 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2838 | if (Record && Record->isInjectedClassName()) { |
| 2839 | Injected = Record; |
| 2840 | break; |
| Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2841 | } |
| 2842 | } |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2843 | // Create an injected type for the whole redecl chain. |
| 2844 | SmallVector<Decl *, 2> Redecls = |
| 2845 | getCanonicalForwardRedeclChain(D2CXX); |
| 2846 | for (auto *R : Redecls) { |
| 2847 | auto *RI = cast<CXXRecordDecl>(R); |
| 2848 | RI->setTypeForDecl(nullptr); |
| 2849 | // Below we create a new injected type and assign that to the |
| 2850 | // canonical decl, subsequent declarations in the chain will reuse |
| 2851 | // that type. |
| 2852 | Importer.getToContext().getInjectedClassNameType( |
| 2853 | RI, ToDescribed->getInjectedClassNameSpecialization()); |
| 2854 | } |
| 2855 | // Set the new type for the previous injected decl too. |
| 2856 | if (Injected) { |
| 2857 | Injected->setTypeForDecl(nullptr); |
| 2858 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2859 | } |
| 2860 | } |
| 2861 | } else if (MemberSpecializationInfo *MemberInfo = |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2862 | DCXX->getMemberSpecializationInfo()) { |
| 2863 | TemplateSpecializationKind SK = |
| 2864 | MemberInfo->getTemplateSpecializationKind(); |
| 2865 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2866 | |
| 2867 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) |
| 2868 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); |
| 2869 | else |
| 2870 | return ToInstOrErr.takeError(); |
| 2871 | |
| 2872 | if (ExpectedSLoc POIOrErr = |
| 2873 | import(MemberInfo->getPointOfInstantiation())) |
| 2874 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2875 | *POIOrErr); |
| 2876 | else |
| 2877 | return POIOrErr.takeError(); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2878 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2879 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2880 | } else { |
| 2881 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
| 2882 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2883 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2884 | return D2; |
| 2885 | D2->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 2886 | addDeclToContexts(D, D2); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2887 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2888 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2889 | if (auto BraceRangeOrErr = import(D->getBraceRange())) |
| 2890 | D2->setBraceRange(*BraceRangeOrErr); |
| 2891 | else |
| 2892 | return BraceRangeOrErr.takeError(); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2893 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) |
| 2894 | D2->setQualifierInfo(*QualifierLocOrErr); |
| 2895 | else |
| 2896 | return QualifierLocOrErr.takeError(); |
| 2897 | |
| 2898 | if (D->isAnonymousStructOrUnion()) |
| 2899 | D2->setAnonymousStructOrUnion(true); |
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2900 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2901 | if (D->isCompleteDefinition()) |
| 2902 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) |
| 2903 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2904 | |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2905 | return D2; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2906 | } |
| 2907 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2908 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2909 | // Import the major distinguishing characteristics of this enumerator. |
| 2910 | DeclContext *DC, *LexicalDC; |
| 2911 | DeclarationName Name; |
| 2912 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2913 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2914 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2915 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2916 | if (ToD) |
| 2917 | return ToD; |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2918 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2919 | // Determine whether there are any other declarations with the same name and |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2920 | // in the same context. |
| 2921 | if (!LexicalDC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2922 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2923 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2924 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2925 | for (auto *FoundDecl : FoundDecls) { |
| 2926 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2927 | continue; |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2928 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2929 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2930 | if (IsStructuralMatch(D, FoundEnumConstant)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2931 | return Importer.MapImported(D, FoundEnumConstant); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2932 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2933 | } |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2934 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2935 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2936 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2937 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2938 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 2939 | if (NameOrErr) |
| 2940 | Name = NameOrErr.get(); |
| 2941 | else |
| 2942 | return NameOrErr.takeError(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2943 | } |
| 2944 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2945 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2946 | ExpectedType TypeOrErr = import(D->getType()); |
| 2947 | if (!TypeOrErr) |
| 2948 | return TypeOrErr.takeError(); |
| 2949 | |
| 2950 | ExpectedExpr InitOrErr = import(D->getInitExpr()); |
| 2951 | if (!InitOrErr) |
| 2952 | return InitOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2953 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2954 | EnumConstantDecl *ToEnumerator; |
| 2955 | if (GetImportedOrCreateDecl( |
| 2956 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2957 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2958 | return ToEnumerator; |
| 2959 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2960 | ToEnumerator->setAccess(D->getAccess()); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2961 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2962 | LexicalDC->addDeclInternal(ToEnumerator); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2963 | return ToEnumerator; |
| 2964 | } |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2965 | |
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 2966 | Error ASTNodeImporter::ImportTemplateParameterLists(const DeclaratorDecl *FromD, |
| 2967 | DeclaratorDecl *ToD) { |
| 2968 | unsigned int Num = FromD->getNumTemplateParameterLists(); |
| 2969 | if (Num == 0) |
| 2970 | return Error::success(); |
| 2971 | SmallVector<TemplateParameterList *, 2> ToTPLists(Num); |
| 2972 | for (unsigned int I = 0; I < Num; ++I) |
| 2973 | if (Expected<TemplateParameterList *> ToTPListOrErr = |
| 2974 | import(FromD->getTemplateParameterList(I))) |
| 2975 | ToTPLists[I] = *ToTPListOrErr; |
| 2976 | else |
| 2977 | return ToTPListOrErr.takeError(); |
| 2978 | ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists); |
| 2979 | return Error::success(); |
| 2980 | } |
| 2981 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2982 | Error ASTNodeImporter::ImportTemplateInformation( |
| 2983 | FunctionDecl *FromFD, FunctionDecl *ToFD) { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2984 | switch (FromFD->getTemplatedKind()) { |
| 2985 | case FunctionDecl::TK_NonTemplate: |
| 2986 | case FunctionDecl::TK_FunctionTemplate: |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2987 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2988 | |
| 2989 | case FunctionDecl::TK_MemberSpecialization: { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2990 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2991 | |
| 2992 | if (Expected<FunctionDecl *> InstFDOrErr = |
| 2993 | import(FromFD->getInstantiatedFromMemberFunction())) |
| 2994 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); |
| 2995 | else |
| 2996 | return InstFDOrErr.takeError(); |
| 2997 | |
| 2998 | if (ExpectedSLoc POIOrErr = import( |
| 2999 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) |
| 3000 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); |
| 3001 | else |
| 3002 | return POIOrErr.takeError(); |
| 3003 | |
| 3004 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3008 | auto FunctionAndArgsOrErr = |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3009 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3010 | if (!FunctionAndArgsOrErr) |
| 3011 | return FunctionAndArgsOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3012 | |
| 3013 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3014 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3015 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3016 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3017 | TemplateArgumentListInfo ToTAInfo; |
| 3018 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3019 | if (FromTAArgsAsWritten) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3020 | if (Error Err = ImportTemplateArgumentListInfo( |
| 3021 | *FromTAArgsAsWritten, ToTAInfo)) |
| 3022 | return Err; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3023 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3024 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); |
| 3025 | if (!POIOrErr) |
| 3026 | return POIOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3027 | |
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 3028 | if (Error Err = ImportTemplateParameterLists(FromFD, ToFD)) |
| 3029 | return Err; |
| 3030 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3031 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3032 | ToFD->setFunctionTemplateSpecialization( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3033 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, |
| 3034 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); |
| 3035 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 3039 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 3040 | UnresolvedSet<8> TemplDecls; |
| 3041 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 3042 | for (unsigned I = 0; I < NumTemplates; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3043 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = |
| 3044 | import(FromInfo->getTemplate(I))) |
| 3045 | TemplDecls.addDecl(*ToFTDOrErr); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3046 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3047 | return ToFTDOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | // Import TemplateArgumentListInfo. |
| 3051 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3052 | if (Error Err = ImportTemplateArgumentListInfo( |
| 3053 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 3054 | llvm::makeArrayRef( |
| 3055 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), |
| 3056 | ToTAInfo)) |
| 3057 | return Err; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3058 | |
| 3059 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 3060 | TemplDecls, ToTAInfo); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3061 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3062 | } |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3063 | } |
| Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 3064 | llvm_unreachable("All cases should be covered!"); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3065 | } |
| 3066 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3067 | Expected<FunctionDecl *> |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3068 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3069 | auto FunctionAndArgsOrErr = |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3070 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3071 | if (!FunctionAndArgsOrErr) |
| 3072 | return FunctionAndArgsOrErr.takeError(); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3073 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3074 | FunctionTemplateDecl *Template; |
| 3075 | TemplateArgsTy ToTemplArgs; |
| 3076 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3077 | void *InsertPos = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3078 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3079 | return FoundSpec; |
| 3080 | } |
| 3081 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3082 | Error ASTNodeImporter::ImportFunctionDeclBody(FunctionDecl *FromFD, |
| 3083 | FunctionDecl *ToFD) { |
| 3084 | if (Stmt *FromBody = FromFD->getBody()) { |
| 3085 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) |
| 3086 | ToFD->setBody(*ToBodyOrErr); |
| 3087 | else |
| 3088 | return ToBodyOrErr.takeError(); |
| 3089 | } |
| 3090 | return Error::success(); |
| 3091 | } |
| 3092 | |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3093 | // Returns true if the given D has a DeclContext up to the TranslationUnitDecl |
| 3094 | // which is equal to the given DC. |
| Benjamin Kramer | df18650 | 2020-01-14 14:06:12 +0100 | [diff] [blame] | 3095 | static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) { |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3096 | const DeclContext *DCi = D->getDeclContext(); |
| 3097 | while (DCi != D->getTranslationUnitDecl()) { |
| 3098 | if (DCi == DC) |
| 3099 | return true; |
| 3100 | DCi = DCi->getParent(); |
| 3101 | } |
| 3102 | return false; |
| 3103 | } |
| 3104 | |
| 3105 | bool ASTNodeImporter::hasAutoReturnTypeDeclaredInside(FunctionDecl *D) { |
| 3106 | QualType FromTy = D->getType(); |
| 3107 | const FunctionProtoType *FromFPT = FromTy->getAs<FunctionProtoType>(); |
| 3108 | assert(FromFPT && "Must be called on FunctionProtoType"); |
| 3109 | if (AutoType *AutoT = FromFPT->getReturnType()->getContainedAutoType()) { |
| 3110 | QualType DeducedT = AutoT->getDeducedType(); |
| 3111 | if (const RecordType *RecordT = |
| 3112 | DeducedT.isNull() ? nullptr : dyn_cast<RecordType>(DeducedT)) { |
| 3113 | RecordDecl *RD = RecordT->getDecl(); |
| 3114 | assert(RD); |
| 3115 | if (isAncestorDeclContextOf(D, RD)) { |
| 3116 | assert(RD->getLexicalDeclContext() == RD->getDeclContext()); |
| 3117 | return true; |
| 3118 | } |
| 3119 | } |
| 3120 | } |
| 3121 | if (const TypedefType *TypedefT = |
| 3122 | dyn_cast<TypedefType>(FromFPT->getReturnType())) { |
| 3123 | TypedefNameDecl *TD = TypedefT->getDecl(); |
| 3124 | assert(TD); |
| 3125 | if (isAncestorDeclContextOf(D, TD)) { |
| 3126 | assert(TD->getLexicalDeclContext() == TD->getDeclContext()); |
| 3127 | return true; |
| 3128 | } |
| 3129 | } |
| 3130 | return false; |
| 3131 | } |
| 3132 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3133 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3134 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3135 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3136 | auto RedeclIt = Redecls.begin(); |
| 3137 | // Import the first part of the decl chain. I.e. import all previous |
| 3138 | // declarations starting from the canonical decl. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3139 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3140 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3141 | if (!ToRedeclOrErr) |
| 3142 | return ToRedeclOrErr.takeError(); |
| 3143 | } |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3144 | assert(*RedeclIt == D); |
| 3145 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3146 | // Import the major distinguishing characteristics of this function. |
| 3147 | DeclContext *DC, *LexicalDC; |
| 3148 | DeclarationName Name; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3149 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3150 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3151 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3152 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3153 | if (ToD) |
| 3154 | return ToD; |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3155 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3156 | FunctionDecl *FoundByLookup = nullptr; |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3157 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); |
| Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 3158 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3159 | // 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] | 3160 | // existing specialization in the "to" context. The lookup below will not |
| 3161 | // find any specialization, but would find the primary template; thus, we |
| 3162 | // have to skip normal lookup in case of specializations. |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3163 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 3164 | if (D->getTemplatedKind() == |
| 3165 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3166 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); |
| 3167 | if (!FoundFunctionOrErr) |
| 3168 | return FoundFunctionOrErr.takeError(); |
| 3169 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { |
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 3170 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 3171 | return Def; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3172 | FoundByLookup = FoundFunction; |
| 3173 | } |
| 3174 | } |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3175 | // Try to find a function in our own ("to") context with the same name, same |
| 3176 | // type, and in the same context as the function we're importing. |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3177 | else if (!LexicalDC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3178 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3179 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3180 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3181 | for (auto *FoundDecl : FoundDecls) { |
| 3182 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3183 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3184 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3185 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 3186 | if (!hasSameVisibilityContextAndLinkage(FoundFunction, D)) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3187 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3188 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3189 | if (IsStructuralMatch(D, FoundFunction)) { |
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 3190 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 3191 | return Def; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3192 | FoundByLookup = FoundFunction; |
| 3193 | break; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3194 | } |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3195 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 3196 | // Sema::IsOverload out to the AST library. |
| 3197 | |
| 3198 | // Function overloading is okay in C++. |
| 3199 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
| 3200 | continue; |
| 3201 | |
| 3202 | // Complain about inconsistent function types. |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3203 | Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3204 | << Name << D->getType() << FoundFunction->getType(); |
| 3205 | Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here) |
| 3206 | << FoundFunction->getType(); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3207 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3208 | } |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3209 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3210 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3211 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3212 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 3213 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 3214 | if (NameOrErr) |
| 3215 | Name = NameOrErr.get(); |
| 3216 | else |
| 3217 | return NameOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3218 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3219 | } |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3220 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3221 | // We do not allow more than one in-class declaration of a function. This is |
| 3222 | // because AST clients like VTableBuilder asserts on this. VTableBuilder |
| 3223 | // assumes there is only one in-class declaration. Building a redecl |
| 3224 | // chain would result in more than one in-class declaration for |
| 3225 | // overrides (even if they are part of the same redecl chain inside the |
| 3226 | // derived class.) |
| 3227 | if (FoundByLookup) { |
| Mikael Holmen | c1c97aa | 2019-01-29 06:53:31 +0000 | [diff] [blame] | 3228 | if (isa<CXXMethodDecl>(FoundByLookup)) { |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3229 | if (D->getLexicalDeclContext() == D->getDeclContext()) { |
| Balazs Keri | e9719f9 | 2019-08-07 12:40:17 +0000 | [diff] [blame] | 3230 | if (!D->doesThisDeclarationHaveABody()) { |
| 3231 | if (FunctionTemplateDecl *DescribedD = |
| 3232 | D->getDescribedFunctionTemplate()) { |
| 3233 | // Handle a "templated" function together with its described |
| 3234 | // template. This avoids need for a similar check at import of the |
| 3235 | // described template. |
| 3236 | assert(FoundByLookup->getDescribedFunctionTemplate() && |
| 3237 | "Templated function mapped to non-templated?"); |
| 3238 | Importer.MapImported(DescribedD, |
| 3239 | FoundByLookup->getDescribedFunctionTemplate()); |
| 3240 | } |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3241 | return Importer.MapImported(D, FoundByLookup); |
| Balazs Keri | e9719f9 | 2019-08-07 12:40:17 +0000 | [diff] [blame] | 3242 | } else { |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3243 | // Let's continue and build up the redecl chain in this case. |
| 3244 | // FIXME Merge the functions into one decl. |
| 3245 | } |
| 3246 | } |
| 3247 | } |
| 3248 | } |
| 3249 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3250 | DeclarationNameInfo NameInfo(Name, Loc); |
| 3251 | // Import additional name location/type info. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3252 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 3253 | return std::move(Err); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3254 | |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3255 | QualType FromTy = D->getType(); |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3256 | // Set to true if we do not import the type of the function as is. There are |
| 3257 | // cases when the original type would result in an infinite recursion during |
| 3258 | // the import. To avoid an infinite recursion when importing, we create the |
| 3259 | // FunctionDecl with a simplified function type and update it only after the |
| 3260 | // relevant AST nodes are already imported. |
| 3261 | bool UsedDifferentProtoType = false; |
| 3262 | if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) { |
| 3263 | QualType FromReturnTy = FromFPT->getReturnType(); |
| 3264 | // Functions with auto return type may define a struct inside their body |
| 3265 | // and the return type could refer to that struct. |
| 3266 | // E.g.: auto foo() { struct X{}; return X(); } |
| 3267 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 3268 | // with a simplified return type. |
| 3269 | if (hasAutoReturnTypeDeclaredInside(D)) { |
| 3270 | FromReturnTy = Importer.getFromContext().VoidTy; |
| 3271 | UsedDifferentProtoType = true; |
| 3272 | } |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3273 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 3274 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 3275 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 3276 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3277 | // with a simplified function type. |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 3278 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 3279 | FromEPI.ExceptionSpec.SourceTemplate || |
| 3280 | FromEPI.ExceptionSpec.NoexceptExpr) { |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3281 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3282 | FromEPI = DefaultEPI; |
| 3283 | UsedDifferentProtoType = true; |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3284 | } |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3285 | FromTy = Importer.getFromContext().getFunctionType( |
| 3286 | FromReturnTy, FromFPT->getParamTypes(), FromEPI); |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3287 | } |
| 3288 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3289 | Error Err = Error::success(); |
| 3290 | auto T = importChecked(Err, FromTy); |
| 3291 | auto TInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 3292 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 3293 | auto ToEndLoc = importChecked(Err, D->getEndLoc()); |
| 3294 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 3295 | auto TrailingRequiresClause = |
| 3296 | importChecked(Err, D->getTrailingRequiresClause()); |
| 3297 | if (Err) |
| 3298 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3299 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3300 | // Import the function parameters. |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3301 | SmallVector<ParmVarDecl *, 8> Parameters; |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3302 | for (auto P : D->parameters()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3303 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) |
| 3304 | Parameters.push_back(*ToPOrErr); |
| 3305 | else |
| 3306 | return ToPOrErr.takeError(); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3307 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3308 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3309 | // Create the imported function. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3310 | FunctionDecl *ToFunction = nullptr; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3311 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3312 | Expr *ExplicitExpr = nullptr; |
| 3313 | if (FromConstructor->getExplicitSpecifier().getExpr()) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3314 | auto Imp = import(FromConstructor->getExplicitSpecifier().getExpr()); |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3315 | if (!Imp) |
| 3316 | return Imp.takeError(); |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3317 | ExplicitExpr = *Imp; |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3318 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3319 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3320 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3321 | ToInnerLocStart, NameInfo, T, TInfo, |
| 3322 | ExplicitSpecifier( |
| 3323 | ExplicitExpr, |
| 3324 | FromConstructor->getExplicitSpecifier().getKind()), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3325 | D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(), |
| 3326 | InheritedConstructor(), // FIXME: Properly import inherited |
| 3327 | // constructor info |
| 3328 | TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3329 | return ToFunction; |
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3330 | } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { |
| 3331 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3332 | Error Err = Error::success(); |
| 3333 | auto ToOperatorDelete = importChecked( |
| 3334 | Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete())); |
| 3335 | auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg()); |
| 3336 | if (Err) |
| 3337 | return std::move(Err); |
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3338 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3339 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3340 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3341 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3342 | D->isImplicit(), D->getConstexprKind(), TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3343 | return ToFunction; |
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3344 | |
| 3345 | CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction); |
| 3346 | |
| 3347 | ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3348 | } else if (CXXConversionDecl *FromConversion = |
| 3349 | dyn_cast<CXXConversionDecl>(D)) { |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3350 | Expr *ExplicitExpr = nullptr; |
| 3351 | if (FromConversion->getExplicitSpecifier().getExpr()) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3352 | auto Imp = import(FromConversion->getExplicitSpecifier().getExpr()); |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3353 | if (!Imp) |
| 3354 | return Imp.takeError(); |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3355 | ExplicitExpr = *Imp; |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3356 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3357 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 3358 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3359 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3360 | ExplicitSpecifier(ExplicitExpr, |
| 3361 | FromConversion->getExplicitSpecifier().getKind()), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3362 | D->getConstexprKind(), SourceLocation(), TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3363 | return ToFunction; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3364 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3365 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 3366 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3367 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3368 | Method->isInlineSpecified(), D->getConstexprKind(), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3369 | SourceLocation(), TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3370 | return ToFunction; |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3371 | } else { |
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3372 | if (GetImportedOrCreateDecl( |
| 3373 | ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, |
| 3374 | NameInfo, T, TInfo, D->getStorageClass(), D->isInlineSpecified(), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3375 | D->hasWrittenPrototype(), D->getConstexprKind(), |
| 3376 | TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3377 | return ToFunction; |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3378 | } |
| John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3379 | |
| Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3380 | // Connect the redecl chain. |
| 3381 | if (FoundByLookup) { |
| 3382 | auto *Recent = const_cast<FunctionDecl *>( |
| 3383 | FoundByLookup->getMostRecentDecl()); |
| 3384 | ToFunction->setPreviousDecl(Recent); |
| Gabor Marton | ce6b781 | 2019-05-08 15:23:48 +0000 | [diff] [blame] | 3385 | // FIXME Probably we should merge exception specifications. E.g. In the |
| 3386 | // "To" context the existing function may have exception specification with |
| 3387 | // noexcept-unevaluated, while the newly imported function may have an |
| 3388 | // evaluated noexcept. A call to adjustExceptionSpec() on the imported |
| 3389 | // decl and its redeclarations may be required. |
| Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3390 | } |
| 3391 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3392 | ToFunction->setQualifierInfo(ToQualifierLoc); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3393 | ToFunction->setAccess(D->getAccess()); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3394 | ToFunction->setLexicalDeclContext(LexicalDC); |
| John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 3395 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 3396 | ToFunction->setTrivial(D->isTrivial()); |
| 3397 | ToFunction->setPure(D->isPure()); |
| Balazs Keri | b427c06 | 2019-08-13 08:04:06 +0000 | [diff] [blame] | 3398 | ToFunction->setDefaulted(D->isDefaulted()); |
| 3399 | ToFunction->setExplicitlyDefaulted(D->isExplicitlyDefaulted()); |
| 3400 | ToFunction->setDeletedAsWritten(D->isDeletedAsWritten()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3401 | ToFunction->setRangeEnd(ToEndLoc); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3402 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3403 | // Set the parameters. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3404 | for (auto *Param : Parameters) { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3405 | Param->setOwningFunction(ToFunction); |
| 3406 | ToFunction->addDeclInternal(Param); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3407 | } |
| David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 3408 | ToFunction->setParams(Parameters); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3409 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3410 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 3411 | // params it refers to. |
| 3412 | if (TInfo) { |
| 3413 | if (auto ProtoLoc = |
| 3414 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 3415 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 3416 | ProtoLoc.setParam(I, Parameters[I]); |
| 3417 | } |
| 3418 | } |
| 3419 | |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3420 | // Import the describing template function, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3421 | if (FromFT) { |
| 3422 | auto ToFTOrErr = import(FromFT); |
| 3423 | if (!ToFTOrErr) |
| 3424 | return ToFTOrErr.takeError(); |
| 3425 | } |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3426 | |
| Balazs Keri | e13e836 | 2019-08-16 12:10:03 +0000 | [diff] [blame] | 3427 | // Import Ctor initializers. |
| 3428 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 3429 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 3430 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); |
| 3431 | // Import first, then allocate memory and copy if there was no error. |
| 3432 | if (Error Err = ImportContainerChecked( |
| 3433 | FromConstructor->inits(), CtorInitializers)) |
| 3434 | return std::move(Err); |
| 3435 | auto **Memory = |
| 3436 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 3437 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
| 3438 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
| 3439 | ToCtor->setCtorInitializers(Memory); |
| 3440 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 3441 | } |
| 3442 | } |
| 3443 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3444 | if (D->doesThisDeclarationHaveABody()) { |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3445 | Error Err = ImportFunctionDeclBody(D, ToFunction); |
| 3446 | |
| 3447 | if (Err) |
| 3448 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3449 | } |
| 3450 | |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3451 | // Import and set the original type in case we used another type. |
| 3452 | if (UsedDifferentProtoType) { |
| 3453 | if (ExpectedType TyOrErr = import(D->getType())) |
| 3454 | ToFunction->setType(*TyOrErr); |
| 3455 | else |
| 3456 | return TyOrErr.takeError(); |
| 3457 | } |
| 3458 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3459 | // FIXME: Other bits to merge? |
| Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3460 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3461 | // If it is a template, import all related things. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3462 | if (Error Err = ImportTemplateInformation(D, ToFunction)) |
| 3463 | return std::move(Err); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3464 | |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 3465 | addDeclToContexts(D, ToFunction); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3466 | |
| Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3467 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 3468 | if (Error Err = ImportOverriddenMethods(cast<CXXMethodDecl>(ToFunction), |
| 3469 | FromCXXMethod)) |
| 3470 | return std::move(Err); |
| Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3471 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3472 | // Import the rest of the chain. I.e. import all subsequent declarations. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3473 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3474 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3475 | if (!ToRedeclOrErr) |
| 3476 | return ToRedeclOrErr.takeError(); |
| 3477 | } |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3478 | |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3479 | return ToFunction; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3480 | } |
| 3481 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3482 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3483 | return VisitFunctionDecl(D); |
| 3484 | } |
| 3485 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3486 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3487 | return VisitCXXMethodDecl(D); |
| 3488 | } |
| 3489 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3490 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3491 | return VisitCXXMethodDecl(D); |
| 3492 | } |
| 3493 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3494 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3495 | return VisitCXXMethodDecl(D); |
| 3496 | } |
| 3497 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3498 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3499 | // Import the major distinguishing characteristics of a variable. |
| 3500 | DeclContext *DC, *LexicalDC; |
| 3501 | DeclarationName Name; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3502 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3503 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3504 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3505 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3506 | if (ToD) |
| 3507 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3508 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3509 | // Determine whether we've already imported this field. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3510 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3511 | for (auto *FoundDecl : FoundDecls) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3512 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3513 | // For anonymous fields, match up by index. |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3514 | if (!Name && |
| 3515 | ASTImporter::getFieldIndex(D) != |
| 3516 | ASTImporter::getFieldIndex(FoundField)) |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3517 | continue; |
| 3518 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3519 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3520 | FoundField->getType())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3521 | Importer.MapImported(D, FoundField); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3522 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the |
| 3523 | // initializer of a FieldDecl might not had been instantiated in the |
| 3524 | // "To" context. However, the "From" context might instantiated that, |
| 3525 | // thus we have to merge that. |
| 3526 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
| 3527 | // We don't have yet the initializer set. |
| 3528 | if (FoundField->hasInClassInitializer() && |
| 3529 | !FoundField->getInClassInitializer()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3530 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) |
| 3531 | FoundField->setInClassInitializer(*ToInitializerOrErr); |
| 3532 | else { |
| 3533 | // We can't return error here, |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3534 | // since we already mapped D as imported. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3535 | // FIXME: warning message? |
| 3536 | consumeError(ToInitializerOrErr.takeError()); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3537 | return FoundField; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3538 | } |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3539 | } |
| 3540 | } |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3541 | return FoundField; |
| 3542 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3543 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3544 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3545 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3546 | << Name << D->getType() << FoundField->getType(); |
| 3547 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3548 | << FoundField->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3549 | |
| 3550 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3551 | } |
| 3552 | } |
| 3553 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3554 | Error Err = Error::success(); |
| 3555 | auto ToType = importChecked(Err, D->getType()); |
| 3556 | auto ToTInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 3557 | auto ToBitWidth = importChecked(Err, D->getBitWidth()); |
| 3558 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 3559 | auto ToInitializer = importChecked(Err, D->getInClassInitializer()); |
| 3560 | if (Err) |
| 3561 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3562 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3563 | FieldDecl *ToField; |
| 3564 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3565 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3566 | ToType, ToTInfo, ToBitWidth, D->isMutable(), |
| 3567 | D->getInClassInitStyle())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3568 | return ToField; |
| 3569 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3570 | ToField->setAccess(D->getAccess()); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3571 | ToField->setLexicalDeclContext(LexicalDC); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3572 | if (ToInitializer) |
| 3573 | ToField->setInClassInitializer(ToInitializer); |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3574 | ToField->setImplicit(D->isImplicit()); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3575 | LexicalDC->addDeclInternal(ToField); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3576 | return ToField; |
| 3577 | } |
| 3578 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3579 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3580 | // Import the major distinguishing characteristics of a variable. |
| 3581 | DeclContext *DC, *LexicalDC; |
| 3582 | DeclarationName Name; |
| 3583 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3584 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3585 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3586 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3587 | if (ToD) |
| 3588 | return ToD; |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3589 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3590 | // Determine whether we've already imported this field. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3591 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3592 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3593 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3594 | // For anonymous indirect fields, match up by index. |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3595 | if (!Name && |
| 3596 | ASTImporter::getFieldIndex(D) != |
| 3597 | ASTImporter::getFieldIndex(FoundField)) |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3598 | continue; |
| 3599 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3600 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3601 | FoundField->getType(), |
| David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 3602 | !Name.isEmpty())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3603 | Importer.MapImported(D, FoundField); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3604 | return FoundField; |
| 3605 | } |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3606 | |
| 3607 | // If there are more anonymous fields to check, continue. |
| 3608 | if (!Name && I < N-1) |
| 3609 | continue; |
| 3610 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3611 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3612 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3613 | << Name << D->getType() << FoundField->getType(); |
| 3614 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3615 | << FoundField->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3616 | |
| 3617 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3618 | } |
| 3619 | } |
| 3620 | |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3621 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3622 | auto TypeOrErr = import(D->getType()); |
| 3623 | if (!TypeOrErr) |
| 3624 | return TypeOrErr.takeError(); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3625 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3626 | auto **NamedChain = |
| 3627 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3628 | |
| 3629 | unsigned i = 0; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3630 | for (auto *PI : D->chain()) |
| 3631 | if (Expected<NamedDecl *> ToD = import(PI)) |
| 3632 | NamedChain[i++] = *ToD; |
| 3633 | else |
| 3634 | return ToD.takeError(); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3635 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3636 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 3637 | IndirectFieldDecl *ToIndirectField; |
| 3638 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3639 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3640 | // FIXME here we leak `NamedChain` which is allocated before |
| 3641 | return ToIndirectField; |
| Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3642 | |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3643 | ToIndirectField->setAccess(D->getAccess()); |
| 3644 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3645 | LexicalDC->addDeclInternal(ToIndirectField); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3646 | return ToIndirectField; |
| 3647 | } |
| 3648 | |
| Balázs Kéri | 85f5d12 | 2020-07-07 14:21:18 +0200 | [diff] [blame] | 3649 | /// Used as return type of getFriendCountAndPosition. |
| 3650 | struct FriendCountAndPosition { |
| 3651 | /// Number of similar looking friends. |
| 3652 | unsigned int TotalCount; |
| 3653 | /// Index of the specific FriendDecl. |
| 3654 | unsigned int IndexOfDecl; |
| 3655 | }; |
| 3656 | |
| 3657 | template <class T> |
| Benjamin Kramer | b444705 | 2020-07-09 13:48:56 +0200 | [diff] [blame] | 3658 | static FriendCountAndPosition getFriendCountAndPosition( |
| Balázs Kéri | 85f5d12 | 2020-07-07 14:21:18 +0200 | [diff] [blame] | 3659 | const FriendDecl *FD, |
| Benjamin Kramer | b444705 | 2020-07-09 13:48:56 +0200 | [diff] [blame] | 3660 | llvm::function_ref<T(const FriendDecl *)> GetCanTypeOrDecl) { |
| Balázs Kéri | 85f5d12 | 2020-07-07 14:21:18 +0200 | [diff] [blame] | 3661 | unsigned int FriendCount = 0; |
| 3662 | llvm::Optional<unsigned int> FriendPosition; |
| 3663 | const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext()); |
| 3664 | |
| 3665 | T TypeOrDecl = GetCanTypeOrDecl(FD); |
| 3666 | |
| 3667 | for (const FriendDecl *FoundFriend : RD->friends()) { |
| 3668 | if (FoundFriend == FD) { |
| 3669 | FriendPosition = FriendCount; |
| 3670 | ++FriendCount; |
| 3671 | } else if (!FoundFriend->getFriendDecl() == !FD->getFriendDecl() && |
| 3672 | GetCanTypeOrDecl(FoundFriend) == TypeOrDecl) { |
| 3673 | ++FriendCount; |
| 3674 | } |
| 3675 | } |
| 3676 | |
| 3677 | assert(FriendPosition && "Friend decl not found in own parent."); |
| 3678 | |
| 3679 | return {FriendCount, *FriendPosition}; |
| 3680 | } |
| 3681 | |
| Benjamin Kramer | b444705 | 2020-07-09 13:48:56 +0200 | [diff] [blame] | 3682 | static FriendCountAndPosition getFriendCountAndPosition(const FriendDecl *FD) { |
| Balázs Kéri | 85f5d12 | 2020-07-07 14:21:18 +0200 | [diff] [blame] | 3683 | if (FD->getFriendType()) |
| 3684 | return getFriendCountAndPosition<QualType>(FD, [](const FriendDecl *F) { |
| 3685 | if (TypeSourceInfo *TSI = F->getFriendType()) |
| 3686 | return TSI->getType().getCanonicalType(); |
| 3687 | llvm_unreachable("Wrong friend object type."); |
| 3688 | }); |
| 3689 | else |
| 3690 | return getFriendCountAndPosition<Decl *>(FD, [](const FriendDecl *F) { |
| 3691 | if (Decl *D = F->getFriendDecl()) |
| 3692 | return D->getCanonicalDecl(); |
| 3693 | llvm_unreachable("Wrong friend object type."); |
| 3694 | }); |
| 3695 | } |
| 3696 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3697 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3698 | // Import the major distinguishing characteristics of a declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3699 | DeclContext *DC, *LexicalDC; |
| 3700 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 3701 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3702 | |
| 3703 | // Determine whether we've already imported this decl. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3704 | // FriendDecl is not a NamedDecl so we cannot use lookup. |
| Balázs Kéri | 85f5d12 | 2020-07-07 14:21:18 +0200 | [diff] [blame] | 3705 | // We try to maintain order and count of redundant friend declarations. |
| 3706 | const auto *RD = cast<CXXRecordDecl>(DC); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3707 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
| Balázs Kéri | 85f5d12 | 2020-07-07 14:21:18 +0200 | [diff] [blame] | 3708 | SmallVector<FriendDecl *, 2> ImportedEquivalentFriends; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3709 | |
| 3710 | while (ImportedFriend) { |
| Balázs Kéri | 85f5d12 | 2020-07-07 14:21:18 +0200 | [diff] [blame] | 3711 | bool Match = false; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3712 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
| Balázs Kéri | 85f5d12 | 2020-07-07 14:21:18 +0200 | [diff] [blame] | 3713 | Match = |
| 3714 | IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 3715 | /*Complain=*/false); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3716 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| Balázs Kéri | 85f5d12 | 2020-07-07 14:21:18 +0200 | [diff] [blame] | 3717 | Match = Importer.IsStructurallyEquivalent( |
| 3718 | D->getFriendType()->getType(), |
| 3719 | ImportedFriend->getFriendType()->getType(), /*Complain=*/false); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3720 | } |
| Balázs Kéri | 85f5d12 | 2020-07-07 14:21:18 +0200 | [diff] [blame] | 3721 | if (Match) |
| 3722 | ImportedEquivalentFriends.push_back(ImportedFriend); |
| 3723 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3724 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3725 | } |
| Balázs Kéri | 85f5d12 | 2020-07-07 14:21:18 +0200 | [diff] [blame] | 3726 | FriendCountAndPosition CountAndPosition = getFriendCountAndPosition(D); |
| 3727 | |
| 3728 | assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount && |
| 3729 | "Class with non-matching friends is imported, ODR check wrong?"); |
| 3730 | if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount) |
| 3731 | return Importer.MapImported( |
| 3732 | D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3733 | |
| 3734 | // Not found. Create it. |
| Balázs Kéri | 85f5d12 | 2020-07-07 14:21:18 +0200 | [diff] [blame] | 3735 | // The declarations will be put into order later by ImportDeclContext. |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3736 | FriendDecl::FriendUnion ToFU; |
| Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3737 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3738 | NamedDecl *ToFriendD; |
| 3739 | if (Error Err = importInto(ToFriendD, FriendD)) |
| 3740 | return std::move(Err); |
| 3741 | |
| 3742 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && |
| Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3743 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3744 | ToFriendD->setObjectOfFriendDecl(false); |
| 3745 | |
| 3746 | ToFU = ToFriendD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3747 | } else { // The friend is a type, not a decl. |
| 3748 | if (auto TSIOrErr = import(D->getFriendType())) |
| 3749 | ToFU = *TSIOrErr; |
| 3750 | else |
| 3751 | return TSIOrErr.takeError(); |
| 3752 | } |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3753 | |
| 3754 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3755 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3756 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 3757 | if (auto ListOrErr = import(FromTPLists[I])) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3758 | ToTPLists[I] = *ListOrErr; |
| 3759 | else |
| 3760 | return ListOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3761 | } |
| 3762 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3763 | auto LocationOrErr = import(D->getLocation()); |
| 3764 | if (!LocationOrErr) |
| 3765 | return LocationOrErr.takeError(); |
| 3766 | auto FriendLocOrErr = import(D->getFriendLoc()); |
| 3767 | if (!FriendLocOrErr) |
| 3768 | return FriendLocOrErr.takeError(); |
| 3769 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3770 | FriendDecl *FrD; |
| 3771 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3772 | *LocationOrErr, ToFU, |
| 3773 | *FriendLocOrErr, ToTPLists)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3774 | return FrD; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3775 | |
| 3776 | FrD->setAccess(D->getAccess()); |
| 3777 | FrD->setLexicalDeclContext(LexicalDC); |
| 3778 | LexicalDC->addDeclInternal(FrD); |
| 3779 | return FrD; |
| 3780 | } |
| 3781 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3782 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3783 | // Import the major distinguishing characteristics of an ivar. |
| 3784 | DeclContext *DC, *LexicalDC; |
| 3785 | DeclarationName Name; |
| 3786 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3787 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3788 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3789 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3790 | if (ToD) |
| 3791 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3792 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3793 | // Determine whether we've already imported this ivar |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3794 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3795 | for (auto *FoundDecl : FoundDecls) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3796 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3797 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3798 | FoundIvar->getType())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3799 | Importer.MapImported(D, FoundIvar); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3800 | return FoundIvar; |
| 3801 | } |
| 3802 | |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3803 | Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent) |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3804 | << Name << D->getType() << FoundIvar->getType(); |
| 3805 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3806 | << FoundIvar->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3807 | |
| 3808 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3809 | } |
| 3810 | } |
| 3811 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3812 | Error Err = Error::success(); |
| 3813 | auto ToType = importChecked(Err, D->getType()); |
| 3814 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 3815 | auto ToBitWidth = importChecked(Err, D->getBitWidth()); |
| 3816 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 3817 | if (Err) |
| 3818 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3819 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3820 | ObjCIvarDecl *ToIvar; |
| 3821 | if (GetImportedOrCreateDecl( |
| 3822 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3823 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3824 | ToType, ToTypeSourceInfo, |
| 3825 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3826 | return ToIvar; |
| 3827 | |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3828 | ToIvar->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3829 | LexicalDC->addDeclInternal(ToIvar); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3830 | return ToIvar; |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3831 | } |
| 3832 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3833 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3834 | |
| 3835 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 3836 | auto RedeclIt = Redecls.begin(); |
| 3837 | // Import the first part of the decl chain. I.e. import all previous |
| 3838 | // declarations starting from the canonical decl. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3839 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3840 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3841 | if (!RedeclOrErr) |
| 3842 | return RedeclOrErr.takeError(); |
| 3843 | } |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3844 | assert(*RedeclIt == D); |
| 3845 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3846 | // Import the major distinguishing characteristics of a variable. |
| 3847 | DeclContext *DC, *LexicalDC; |
| 3848 | DeclarationName Name; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3849 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3850 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3851 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3852 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3853 | if (ToD) |
| 3854 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3855 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3856 | // Try to find a variable in our own ("to") context with the same name and |
| 3857 | // in the same context as the variable we're importing. |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3858 | VarDecl *FoundByLookup = nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3859 | if (D->isFileVarDecl()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3860 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3861 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3862 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3863 | for (auto *FoundDecl : FoundDecls) { |
| 3864 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3865 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3866 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3867 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 3868 | if (!hasSameVisibilityContextAndLinkage(FoundVar, D)) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3869 | continue; |
| 3870 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| 3871 | FoundVar->getType())) { |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3872 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3873 | // The VarDecl in the "From" context has a definition, but in the |
| 3874 | // "To" context we already have a definition. |
| 3875 | VarDecl *FoundDef = FoundVar->getDefinition(); |
| 3876 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 3877 | // FIXME Check for ODR error if the two definitions have |
| 3878 | // different initializers? |
| 3879 | return Importer.MapImported(D, FoundDef); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3880 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3881 | // The VarDecl in the "From" context has an initializer, but in the |
| 3882 | // "To" context we already have an initializer. |
| 3883 | const VarDecl *FoundDInit = nullptr; |
| 3884 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) |
| 3885 | // FIXME Diagnose ODR error if the two initializers are different? |
| 3886 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); |
| 3887 | |
| 3888 | FoundByLookup = FoundVar; |
| 3889 | break; |
| 3890 | } |
| 3891 | |
| 3892 | const ArrayType *FoundArray |
| 3893 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3894 | const ArrayType *TArray |
| 3895 | = Importer.getToContext().getAsArrayType(D->getType()); |
| 3896 | if (FoundArray && TArray) { |
| 3897 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3898 | isa<ConstantArrayType>(TArray)) { |
| 3899 | // Import the type. |
| 3900 | if (auto TyOrErr = import(D->getType())) |
| 3901 | FoundVar->setType(*TyOrErr); |
| 3902 | else |
| 3903 | return TyOrErr.takeError(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3904 | |
| 3905 | FoundByLookup = FoundVar; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3906 | break; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3907 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3908 | isa<ConstantArrayType>(FoundArray)) { |
| 3909 | FoundByLookup = FoundVar; |
| 3910 | break; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3911 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3912 | } |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3913 | |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3914 | Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3915 | << Name << D->getType() << FoundVar->getType(); |
| 3916 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3917 | << FoundVar->getType(); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3918 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3919 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3920 | } |
| 3921 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3922 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3923 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 3924 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 3925 | if (NameOrErr) |
| 3926 | Name = NameOrErr.get(); |
| 3927 | else |
| 3928 | return NameOrErr.takeError(); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3929 | } |
| 3930 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3931 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3932 | Error Err = Error::success(); |
| 3933 | auto ToType = importChecked(Err, D->getType()); |
| 3934 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 3935 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 3936 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 3937 | if (Err) |
| 3938 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3939 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3940 | // Create the imported variable. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3941 | VarDecl *ToVar; |
| 3942 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3943 | ToInnerLocStart, Loc, |
| 3944 | Name.getAsIdentifierInfo(), |
| 3945 | ToType, ToTypeSourceInfo, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3946 | D->getStorageClass())) |
| 3947 | return ToVar; |
| 3948 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3949 | ToVar->setQualifierInfo(ToQualifierLoc); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3950 | ToVar->setAccess(D->getAccess()); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3951 | ToVar->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3952 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3953 | if (FoundByLookup) { |
| 3954 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); |
| 3955 | ToVar->setPreviousDecl(Recent); |
| 3956 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3957 | |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 3958 | // Import the described template, if any. |
| 3959 | if (D->getDescribedVarTemplate()) { |
| 3960 | auto ToVTOrErr = import(D->getDescribedVarTemplate()); |
| 3961 | if (!ToVTOrErr) |
| 3962 | return ToVTOrErr.takeError(); |
| 3963 | } |
| 3964 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3965 | if (Error Err = ImportInitializer(D, ToVar)) |
| 3966 | return std::move(Err); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3967 | |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3968 | if (D->isConstexpr()) |
| 3969 | ToVar->setConstexpr(true); |
| 3970 | |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 3971 | addDeclToContexts(D, ToVar); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3972 | |
| 3973 | // Import the rest of the chain. I.e. import all subsequent declarations. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3974 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3975 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3976 | if (!RedeclOrErr) |
| 3977 | return RedeclOrErr.takeError(); |
| 3978 | } |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3979 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3980 | return ToVar; |
| 3981 | } |
| 3982 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3983 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3984 | // Parameters are created in the translation unit's context, then moved |
| 3985 | // into the function declaration's context afterward. |
| 3986 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3987 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3988 | Error Err = Error::success(); |
| 3989 | auto ToDeclName = importChecked(Err, D->getDeclName()); |
| 3990 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 3991 | auto ToType = importChecked(Err, D->getType()); |
| 3992 | if (Err) |
| 3993 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3994 | |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3995 | // Create the imported parameter. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3996 | ImplicitParamDecl *ToParm = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3997 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3998 | ToLocation, ToDeclName.getAsIdentifierInfo(), |
| 3999 | ToType, D->getParameterKind())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4000 | return ToParm; |
| 4001 | return ToParm; |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 4002 | } |
| 4003 | |
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 4004 | Error ASTNodeImporter::ImportDefaultArgOfParmVarDecl( |
| 4005 | const ParmVarDecl *FromParam, ParmVarDecl *ToParam) { |
| 4006 | ToParam->setHasInheritedDefaultArg(FromParam->hasInheritedDefaultArg()); |
| 4007 | ToParam->setKNRPromoted(FromParam->isKNRPromoted()); |
| 4008 | |
| 4009 | if (FromParam->hasUninstantiatedDefaultArg()) { |
| 4010 | if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg())) |
| 4011 | ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr); |
| 4012 | else |
| 4013 | return ToDefArgOrErr.takeError(); |
| 4014 | } else if (FromParam->hasUnparsedDefaultArg()) { |
| 4015 | ToParam->setUnparsedDefaultArg(); |
| 4016 | } else if (FromParam->hasDefaultArg()) { |
| 4017 | if (auto ToDefArgOrErr = import(FromParam->getDefaultArg())) |
| 4018 | ToParam->setDefaultArg(*ToDefArgOrErr); |
| 4019 | else |
| 4020 | return ToDefArgOrErr.takeError(); |
| 4021 | } |
| 4022 | |
| 4023 | return Error::success(); |
| 4024 | } |
| 4025 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4026 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 4027 | // Parameters are created in the translation unit's context, then moved |
| 4028 | // into the function declaration's context afterward. |
| 4029 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4030 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4031 | Error Err = Error::success(); |
| 4032 | auto ToDeclName = importChecked(Err, D->getDeclName()); |
| 4033 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 4034 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 4035 | auto ToType = importChecked(Err, D->getType()); |
| 4036 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 4037 | if (Err) |
| 4038 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4039 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4040 | ParmVarDecl *ToParm; |
| 4041 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4042 | ToInnerLocStart, ToLocation, |
| 4043 | ToDeclName.getAsIdentifierInfo(), ToType, |
| 4044 | ToTypeSourceInfo, D->getStorageClass(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4045 | /*DefaultArg*/ nullptr)) |
| 4046 | return ToParm; |
| Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 4047 | |
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 4048 | // Set the default argument. It should be no problem if it was already done. |
| 4049 | // Do not import the default expression before GetImportedOrCreateDecl call |
| 4050 | // to avoid possible infinite import loop because circular dependency. |
| 4051 | if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm)) |
| 4052 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4053 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4054 | if (D->isObjCMethodParameter()) { |
| 4055 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 4056 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 4057 | } else { |
| 4058 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 4059 | D->getFunctionScopeIndex()); |
| 4060 | } |
| 4061 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4062 | return ToParm; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 4063 | } |
| 4064 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4065 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4066 | // Import the major distinguishing characteristics of a method. |
| 4067 | DeclContext *DC, *LexicalDC; |
| 4068 | DeclarationName Name; |
| 4069 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4070 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4071 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4072 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4073 | if (ToD) |
| 4074 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4075 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4076 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4077 | for (auto *FoundDecl : FoundDecls) { |
| 4078 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4079 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 4080 | continue; |
| 4081 | |
| 4082 | // Check return types. |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4083 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 4084 | FoundMethod->getReturnType())) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4085 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent) |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4086 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 4087 | << FoundMethod->getReturnType(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4088 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4089 | diag::note_odr_objc_method_here) |
| 4090 | << D->isInstanceMethod() << Name; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4091 | |
| 4092 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | // Check the number of parameters. |
| 4096 | if (D->param_size() != FoundMethod->param_size()) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4097 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4098 | << D->isInstanceMethod() << Name |
| 4099 | << D->param_size() << FoundMethod->param_size(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4100 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4101 | diag::note_odr_objc_method_here) |
| 4102 | << D->isInstanceMethod() << Name; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4103 | |
| 4104 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4105 | } |
| 4106 | |
| 4107 | // Check parameter types. |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4108 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4109 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 4110 | P != PEnd; ++P, ++FoundP) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4111 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4112 | (*FoundP)->getType())) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4113 | Importer.FromDiag((*P)->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4114 | diag::warn_odr_objc_method_param_type_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4115 | << D->isInstanceMethod() << Name |
| 4116 | << (*P)->getType() << (*FoundP)->getType(); |
| 4117 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 4118 | << (*FoundP)->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4119 | |
| 4120 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4121 | } |
| 4122 | } |
| 4123 | |
| 4124 | // Check variadic/non-variadic. |
| 4125 | // Check the number of parameters. |
| 4126 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4127 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4128 | << D->isInstanceMethod() << Name; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4129 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4130 | diag::note_odr_objc_method_here) |
| 4131 | << D->isInstanceMethod() << Name; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4132 | |
| 4133 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4134 | } |
| 4135 | |
| 4136 | // FIXME: Any other bits we need to merge? |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4137 | return Importer.MapImported(D, FoundMethod); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4138 | } |
| 4139 | } |
| 4140 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4141 | Error Err = Error::success(); |
| 4142 | auto ToEndLoc = importChecked(Err, D->getEndLoc()); |
| 4143 | auto ToReturnType = importChecked(Err, D->getReturnType()); |
| 4144 | auto ToReturnTypeSourceInfo = |
| 4145 | importChecked(Err, D->getReturnTypeSourceInfo()); |
| 4146 | if (Err) |
| 4147 | return std::move(Err); |
| Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 4148 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4149 | ObjCMethodDecl *ToMethod; |
| 4150 | if (GetImportedOrCreateDecl( |
| Adrian Prantl | 2073dd2 | 2019-11-04 14:28:14 -0800 | [diff] [blame] | 4151 | ToMethod, D, Importer.getToContext(), Loc, ToEndLoc, |
| 4152 | Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC, |
| 4153 | D->isInstanceMethod(), D->isVariadic(), D->isPropertyAccessor(), |
| 4154 | D->isSynthesizedAccessorStub(), D->isImplicit(), D->isDefined(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4155 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 4156 | return ToMethod; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4157 | |
| 4158 | // FIXME: When we decide to merge method definitions, we'll need to |
| 4159 | // deal with implicit parameters. |
| 4160 | |
| 4161 | // Import the parameters |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4162 | SmallVector<ParmVarDecl *, 5> ToParams; |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 4163 | for (auto *FromP : D->parameters()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4164 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) |
| 4165 | ToParams.push_back(*ToPOrErr); |
| 4166 | else |
| 4167 | return ToPOrErr.takeError(); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4168 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4169 | |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4170 | // Set the parameters. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4171 | for (auto *ToParam : ToParams) { |
| 4172 | ToParam->setOwningFunction(ToMethod); |
| 4173 | ToMethod->addDeclInternal(ToParam); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4174 | } |
| Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 4175 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4176 | SmallVector<SourceLocation, 12> FromSelLocs; |
| 4177 | D->getSelectorLocs(FromSelLocs); |
| 4178 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); |
| 4179 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) |
| 4180 | return std::move(Err); |
| Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 4181 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4182 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4183 | |
| 4184 | ToMethod->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4185 | LexicalDC->addDeclInternal(ToMethod); |
| Raphael Isemann | 164e0fc | 2019-12-06 18:10:23 +0100 | [diff] [blame] | 4186 | |
| 4187 | // Implicit params are declared when Sema encounters the definition but this |
| 4188 | // never happens when the method is imported. Manually declare the implicit |
| 4189 | // params now that the MethodDecl knows its class interface. |
| 4190 | if (D->getSelfDecl()) |
| 4191 | ToMethod->createImplicitParams(Importer.getToContext(), |
| 4192 | ToMethod->getClassInterface()); |
| 4193 | |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4194 | return ToMethod; |
| 4195 | } |
| 4196 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4197 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4198 | // Import the major distinguishing characteristics of a category. |
| 4199 | DeclContext *DC, *LexicalDC; |
| 4200 | DeclarationName Name; |
| 4201 | SourceLocation Loc; |
| 4202 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4203 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4204 | return std::move(Err); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4205 | if (ToD) |
| 4206 | return ToD; |
| 4207 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4208 | Error Err = Error::success(); |
| 4209 | auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc()); |
| 4210 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 4211 | auto ToColonLoc = importChecked(Err, D->getColonLoc()); |
| 4212 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 4213 | if (Err) |
| 4214 | return std::move(Err); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4215 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4216 | ObjCTypeParamDecl *Result; |
| 4217 | if (GetImportedOrCreateDecl( |
| 4218 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4219 | ToVarianceLoc, D->getIndex(), |
| 4220 | ToLocation, Name.getAsIdentifierInfo(), |
| 4221 | ToColonLoc, ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4222 | return Result; |
| 4223 | |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4224 | Result->setLexicalDeclContext(LexicalDC); |
| 4225 | return Result; |
| 4226 | } |
| 4227 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4228 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4229 | // Import the major distinguishing characteristics of a category. |
| 4230 | DeclContext *DC, *LexicalDC; |
| 4231 | DeclarationName Name; |
| 4232 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4233 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4234 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4235 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4236 | if (ToD) |
| 4237 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4238 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4239 | ObjCInterfaceDecl *ToInterface; |
| 4240 | if (Error Err = importInto(ToInterface, D->getClassInterface())) |
| 4241 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4242 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4243 | // Determine if we've already encountered this category. |
| 4244 | ObjCCategoryDecl *MergeWithCategory |
| 4245 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 4246 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 4247 | if (!ToCategory) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4248 | |
| 4249 | Error Err = Error::success(); |
| 4250 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); |
| 4251 | auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc()); |
| 4252 | auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc()); |
| 4253 | auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc()); |
| 4254 | if (Err) |
| 4255 | return std::move(Err); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4256 | |
| 4257 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4258 | ToAtStartLoc, Loc, |
| 4259 | ToCategoryNameLoc, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4260 | Name.getAsIdentifierInfo(), ToInterface, |
| 4261 | /*TypeParamList=*/nullptr, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4262 | ToIvarLBraceLoc, |
| 4263 | ToIvarRBraceLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4264 | return ToCategory; |
| 4265 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4266 | ToCategory->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4267 | LexicalDC->addDeclInternal(ToCategory); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4268 | // Import the type parameter list after MapImported, to avoid |
| Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4269 | // loops when bringing in their DeclContext. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4270 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) |
| 4271 | ToCategory->setTypeParamList(*PListOrErr); |
| 4272 | else |
| 4273 | return PListOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4274 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4275 | // Import protocols |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4276 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4277 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4278 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 4279 | = D->protocol_loc_begin(); |
| 4280 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 4281 | FromProtoEnd = D->protocol_end(); |
| 4282 | FromProto != FromProtoEnd; |
| 4283 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4284 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4285 | Protocols.push_back(*ToProtoOrErr); |
| 4286 | else |
| 4287 | return ToProtoOrErr.takeError(); |
| 4288 | |
| 4289 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4290 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4291 | else |
| 4292 | return ToProtoLocOrErr.takeError(); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4293 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4294 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4295 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4296 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 4297 | ProtocolLocs.data(), Importer.getToContext()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4298 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4299 | } else { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4300 | Importer.MapImported(D, ToCategory); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4301 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4302 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4303 | // Import all of the members of this category. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4304 | if (Error Err = ImportDeclContext(D)) |
| 4305 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4306 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4307 | // If we have an implementation, import it as well. |
| 4308 | if (D->getImplementation()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4309 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = |
| 4310 | import(D->getImplementation())) |
| 4311 | ToCategory->setImplementation(*ToImplOrErr); |
| 4312 | else |
| 4313 | return ToImplOrErr.takeError(); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4314 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4315 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4316 | return ToCategory; |
| 4317 | } |
| 4318 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4319 | Error ASTNodeImporter::ImportDefinition( |
| 4320 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4321 | if (To->getDefinition()) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4322 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4323 | if (Error Err = ImportDeclContext(From)) |
| 4324 | return Err; |
| 4325 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | // Start the protocol definition |
| 4329 | To->startDefinition(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4330 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4331 | // Import protocols |
| 4332 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4333 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4334 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = |
| 4335 | From->protocol_loc_begin(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4336 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4337 | FromProtoEnd = From->protocol_end(); |
| 4338 | FromProto != FromProtoEnd; |
| 4339 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4340 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4341 | Protocols.push_back(*ToProtoOrErr); |
| 4342 | else |
| 4343 | return ToProtoOrErr.takeError(); |
| 4344 | |
| 4345 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4346 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4347 | else |
| 4348 | return ToProtoLocOrErr.takeError(); |
| 4349 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4350 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4351 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4352 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4353 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4354 | ProtocolLocs.data(), Importer.getToContext()); |
| 4355 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4356 | if (shouldForceImportDeclContext(Kind)) { |
| 4357 | // Import all of the members of this protocol. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4358 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4359 | return Err; |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4360 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4361 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4362 | } |
| 4363 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4364 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4365 | // 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] | 4366 | // from, but this particular declaration is not that definition, import the |
| 4367 | // definition and map to that. |
| 4368 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 4369 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4370 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4371 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4372 | else |
| 4373 | return ImportedDefOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4374 | } |
| 4375 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4376 | // Import the major distinguishing characteristics of a protocol. |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4377 | DeclContext *DC, *LexicalDC; |
| 4378 | DeclarationName Name; |
| 4379 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4380 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4381 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4382 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4383 | if (ToD) |
| 4384 | return ToD; |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4385 | |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4386 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4387 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4388 | for (auto *FoundDecl : FoundDecls) { |
| 4389 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4390 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4391 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4392 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4393 | break; |
| 4394 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4395 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4396 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4397 | if (!ToProto) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4398 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4399 | if (!ToAtBeginLocOrErr) |
| 4400 | return ToAtBeginLocOrErr.takeError(); |
| 4401 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4402 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 4403 | Name.getAsIdentifierInfo(), Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4404 | *ToAtBeginLocOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4405 | /*PrevDecl=*/nullptr)) |
| 4406 | return ToProto; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4407 | ToProto->setLexicalDeclContext(LexicalDC); |
| 4408 | LexicalDC->addDeclInternal(ToProto); |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4409 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4410 | |
| 4411 | Importer.MapImported(D, ToProto); |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4412 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4413 | if (D->isThisDeclarationADefinition()) |
| 4414 | if (Error Err = ImportDefinition(D, ToProto)) |
| 4415 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4416 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4417 | return ToProto; |
| 4418 | } |
| 4419 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4420 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 4421 | DeclContext *DC, *LexicalDC; |
| 4422 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4423 | return std::move(Err); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4424 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4425 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); |
| 4426 | if (!ExternLocOrErr) |
| 4427 | return ExternLocOrErr.takeError(); |
| 4428 | |
| 4429 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); |
| 4430 | if (!LangLocOrErr) |
| 4431 | return LangLocOrErr.takeError(); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4432 | |
| 4433 | bool HasBraces = D->hasBraces(); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4434 | |
| 4435 | LinkageSpecDecl *ToLinkageSpec; |
| 4436 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4437 | *ExternLocOrErr, *LangLocOrErr, |
| 4438 | D->getLanguage(), HasBraces)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4439 | return ToLinkageSpec; |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4440 | |
| 4441 | if (HasBraces) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4442 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 4443 | if (!RBraceLocOrErr) |
| 4444 | return RBraceLocOrErr.takeError(); |
| 4445 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4446 | } |
| 4447 | |
| 4448 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 4449 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 4450 | |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4451 | return ToLinkageSpec; |
| 4452 | } |
| 4453 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4454 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4455 | DeclContext *DC, *LexicalDC; |
| 4456 | DeclarationName Name; |
| 4457 | SourceLocation Loc; |
| 4458 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4459 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4460 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4461 | if (ToD) |
| 4462 | return ToD; |
| 4463 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4464 | Error Err = Error::success(); |
| 4465 | auto ToLoc = importChecked(Err, D->getNameInfo().getLoc()); |
| 4466 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); |
| 4467 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 4468 | if (Err) |
| 4469 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4470 | |
| 4471 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4472 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4473 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4474 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4475 | UsingDecl *ToUsing; |
| 4476 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4477 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4478 | D->hasTypename())) |
| 4479 | return ToUsing; |
| 4480 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4481 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4482 | LexicalDC->addDeclInternal(ToUsing); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4483 | |
| 4484 | if (NamedDecl *FromPattern = |
| 4485 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4486 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) |
| 4487 | Importer.getToContext().setInstantiatedFromUsingDecl( |
| 4488 | ToUsing, *ToPatternOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4489 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4490 | return ToPatternOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4491 | } |
| 4492 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4493 | for (UsingShadowDecl *FromShadow : D->shadows()) { |
| 4494 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) |
| 4495 | ToUsing->addShadowDecl(*ToShadowOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4496 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4497 | // FIXME: We return error here but the definition is already created |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4498 | // and available with lookups. How to fix this?.. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4499 | return ToShadowOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4500 | } |
| 4501 | return ToUsing; |
| 4502 | } |
| 4503 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4504 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4505 | DeclContext *DC, *LexicalDC; |
| 4506 | DeclarationName Name; |
| 4507 | SourceLocation Loc; |
| 4508 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4509 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4510 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4511 | if (ToD) |
| 4512 | return ToD; |
| 4513 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4514 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); |
| 4515 | if (!ToUsingOrErr) |
| 4516 | return ToUsingOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4517 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4518 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); |
| 4519 | if (!ToTargetOrErr) |
| 4520 | return ToTargetOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4521 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4522 | UsingShadowDecl *ToShadow; |
| 4523 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4524 | *ToUsingOrErr, *ToTargetOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4525 | return ToShadow; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4526 | |
| 4527 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 4528 | ToShadow->setAccess(D->getAccess()); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4529 | |
| 4530 | if (UsingShadowDecl *FromPattern = |
| 4531 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4532 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) |
| 4533 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( |
| 4534 | ToShadow, *ToPatternOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4535 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4536 | // FIXME: We return error here but the definition is already created |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4537 | // and available with lookups. How to fix this?.. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4538 | return ToPatternOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4539 | } |
| 4540 | |
| 4541 | LexicalDC->addDeclInternal(ToShadow); |
| 4542 | |
| 4543 | return ToShadow; |
| 4544 | } |
| 4545 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4546 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4547 | DeclContext *DC, *LexicalDC; |
| 4548 | DeclarationName Name; |
| 4549 | SourceLocation Loc; |
| 4550 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4551 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4552 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4553 | if (ToD) |
| 4554 | return ToD; |
| 4555 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4556 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); |
| 4557 | if (!ToComAncestorOrErr) |
| 4558 | return ToComAncestorOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4559 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4560 | Error Err = Error::success(); |
| 4561 | auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace()); |
| 4562 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); |
| 4563 | auto ToNamespaceKeyLocation = |
| 4564 | importChecked(Err, D->getNamespaceKeyLocation()); |
| 4565 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 4566 | auto ToIdentLocation = importChecked(Err, D->getIdentLocation()); |
| 4567 | if (Err) |
| 4568 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4569 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4570 | UsingDirectiveDecl *ToUsingDir; |
| 4571 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4572 | ToUsingLoc, |
| 4573 | ToNamespaceKeyLocation, |
| 4574 | ToQualifierLoc, |
| 4575 | ToIdentLocation, |
| 4576 | ToNominatedNamespace, *ToComAncestorOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4577 | return ToUsingDir; |
| 4578 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4579 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 4580 | LexicalDC->addDeclInternal(ToUsingDir); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4581 | |
| 4582 | return ToUsingDir; |
| 4583 | } |
| 4584 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4585 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4586 | UnresolvedUsingValueDecl *D) { |
| 4587 | DeclContext *DC, *LexicalDC; |
| 4588 | DeclarationName Name; |
| 4589 | SourceLocation Loc; |
| 4590 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4591 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4592 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4593 | if (ToD) |
| 4594 | return ToD; |
| 4595 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4596 | Error Err = Error::success(); |
| 4597 | auto ToLoc = importChecked(Err, D->getNameInfo().getLoc()); |
| 4598 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); |
| 4599 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 4600 | auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc()); |
| 4601 | if (Err) |
| 4602 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4603 | |
| 4604 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4605 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4606 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4607 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4608 | UnresolvedUsingValueDecl *ToUsingValue; |
| 4609 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4610 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| 4611 | ToEllipsisLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4612 | return ToUsingValue; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4613 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4614 | ToUsingValue->setAccess(D->getAccess()); |
| 4615 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 4616 | LexicalDC->addDeclInternal(ToUsingValue); |
| 4617 | |
| 4618 | return ToUsingValue; |
| 4619 | } |
| 4620 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4621 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4622 | UnresolvedUsingTypenameDecl *D) { |
| 4623 | DeclContext *DC, *LexicalDC; |
| 4624 | DeclarationName Name; |
| 4625 | SourceLocation Loc; |
| 4626 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4627 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4628 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4629 | if (ToD) |
| 4630 | return ToD; |
| 4631 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4632 | Error Err = Error::success(); |
| 4633 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); |
| 4634 | auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc()); |
| 4635 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 4636 | auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc()); |
| 4637 | if (Err) |
| 4638 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4639 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4640 | UnresolvedUsingTypenameDecl *ToUsing; |
| 4641 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4642 | ToUsingLoc, ToTypenameLoc, |
| 4643 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4644 | return ToUsing; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4645 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4646 | ToUsing->setAccess(D->getAccess()); |
| 4647 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4648 | LexicalDC->addDeclInternal(ToUsing); |
| 4649 | |
| 4650 | return ToUsing; |
| 4651 | } |
| 4652 | |
| Raphael Isemann | ba7bde6 | 2019-10-30 14:50:35 +0100 | [diff] [blame] | 4653 | ExpectedDecl ASTNodeImporter::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) { |
| 4654 | Decl* ToD = nullptr; |
| 4655 | switch (D->getBuiltinTemplateKind()) { |
| 4656 | case BuiltinTemplateKind::BTK__make_integer_seq: |
| 4657 | ToD = Importer.getToContext().getMakeIntegerSeqDecl(); |
| 4658 | break; |
| 4659 | case BuiltinTemplateKind::BTK__type_pack_element: |
| 4660 | ToD = Importer.getToContext().getTypePackElementDecl(); |
| 4661 | break; |
| 4662 | } |
| 4663 | assert(ToD && "BuiltinTemplateDecl of unsupported kind!"); |
| 4664 | Importer.MapImported(D, ToD); |
| 4665 | return ToD; |
| 4666 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4667 | |
| 4668 | Error ASTNodeImporter::ImportDefinition( |
| 4669 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4670 | if (To->getDefinition()) { |
| 4671 | // Check consistency of superclass. |
| 4672 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 4673 | if (FromSuper) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4674 | if (auto FromSuperOrErr = import(FromSuper)) |
| 4675 | FromSuper = *FromSuperOrErr; |
| 4676 | else |
| 4677 | return FromSuperOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4678 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4679 | |
| 4680 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4681 | if ((bool)FromSuper != (bool)ToSuper || |
| 4682 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4683 | Importer.ToDiag(To->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4684 | diag::warn_odr_objc_superclass_inconsistent) |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4685 | << To->getDeclName(); |
| 4686 | if (ToSuper) |
| 4687 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 4688 | << To->getSuperClass()->getDeclName(); |
| 4689 | else |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4690 | Importer.ToDiag(To->getLocation(), |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4691 | diag::note_odr_objc_missing_superclass); |
| 4692 | if (From->getSuperClass()) |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4693 | Importer.FromDiag(From->getSuperClassLoc(), |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4694 | diag::note_odr_objc_superclass) |
| 4695 | << From->getSuperClass()->getDeclName(); |
| 4696 | else |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4697 | Importer.FromDiag(From->getLocation(), |
| 4698 | diag::note_odr_objc_missing_superclass); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4699 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4700 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4701 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4702 | if (Error Err = ImportDeclContext(From)) |
| 4703 | return Err; |
| 4704 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4705 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4706 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4707 | // Start the definition. |
| 4708 | To->startDefinition(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4709 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4710 | // If this class has a superclass, import it. |
| 4711 | if (From->getSuperClass()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4712 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) |
| 4713 | To->setSuperClass(*SuperTInfoOrErr); |
| 4714 | else |
| 4715 | return SuperTInfoOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4716 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4717 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4718 | // Import protocols |
| 4719 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4720 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4721 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = |
| 4722 | From->protocol_loc_begin(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4723 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4724 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4725 | FromProtoEnd = From->protocol_end(); |
| 4726 | FromProto != FromProtoEnd; |
| 4727 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4728 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4729 | Protocols.push_back(*ToProtoOrErr); |
| 4730 | else |
| 4731 | return ToProtoOrErr.takeError(); |
| 4732 | |
| 4733 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4734 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4735 | else |
| 4736 | return ToProtoLocOrErr.takeError(); |
| 4737 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4738 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4739 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4740 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4741 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4742 | ProtocolLocs.data(), Importer.getToContext()); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4743 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4744 | // Import categories. When the categories themselves are imported, they'll |
| 4745 | // hook themselves into this interface. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4746 | for (auto *Cat : From->known_categories()) { |
| 4747 | auto ToCatOrErr = import(Cat); |
| 4748 | if (!ToCatOrErr) |
| 4749 | return ToCatOrErr.takeError(); |
| 4750 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4751 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4752 | // If we have an @implementation, import it as well. |
| 4753 | if (From->getImplementation()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4754 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = |
| 4755 | import(From->getImplementation())) |
| 4756 | To->setImplementation(*ToImplOrErr); |
| 4757 | else |
| 4758 | return ToImplOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4759 | } |
| 4760 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4761 | if (shouldForceImportDeclContext(Kind)) { |
| 4762 | // Import all of the members of this class. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4763 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4764 | return Err; |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4765 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4766 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4767 | } |
| 4768 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4769 | Expected<ObjCTypeParamList *> |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4770 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 4771 | if (!list) |
| 4772 | return nullptr; |
| 4773 | |
| 4774 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4775 | for (auto *fromTypeParam : *list) { |
| 4776 | if (auto toTypeParamOrErr = import(fromTypeParam)) |
| 4777 | toTypeParams.push_back(*toTypeParamOrErr); |
| 4778 | else |
| 4779 | return toTypeParamOrErr.takeError(); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4780 | } |
| 4781 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4782 | auto LAngleLocOrErr = import(list->getLAngleLoc()); |
| 4783 | if (!LAngleLocOrErr) |
| 4784 | return LAngleLocOrErr.takeError(); |
| 4785 | |
| 4786 | auto RAngleLocOrErr = import(list->getRAngleLoc()); |
| 4787 | if (!RAngleLocOrErr) |
| 4788 | return RAngleLocOrErr.takeError(); |
| 4789 | |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4790 | return ObjCTypeParamList::create(Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4791 | *LAngleLocOrErr, |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4792 | toTypeParams, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4793 | *RAngleLocOrErr); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4794 | } |
| 4795 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4796 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4797 | // If this class has a definition in the translation unit we're coming from, |
| 4798 | // but this particular declaration is not that definition, import the |
| 4799 | // definition and map to that. |
| 4800 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 4801 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4802 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4803 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4804 | else |
| 4805 | return ImportedDefOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4806 | } |
| 4807 | |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4808 | // Import the major distinguishing characteristics of an @interface. |
| 4809 | DeclContext *DC, *LexicalDC; |
| 4810 | DeclarationName Name; |
| 4811 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4812 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4813 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4814 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4815 | if (ToD) |
| 4816 | return ToD; |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4817 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4818 | // Look for an existing interface with the same name. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4819 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4820 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4821 | for (auto *FoundDecl : FoundDecls) { |
| 4822 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4823 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4824 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4825 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4826 | break; |
| 4827 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4828 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4829 | // Create an interface declaration, if one does not already exist. |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4830 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4831 | if (!ToIface) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4832 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4833 | if (!AtBeginLocOrErr) |
| 4834 | return AtBeginLocOrErr.takeError(); |
| 4835 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4836 | if (GetImportedOrCreateDecl( |
| 4837 | ToIface, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4838 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4839 | /*TypeParamList=*/nullptr, |
| 4840 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 4841 | return ToIface; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4842 | ToIface->setLexicalDeclContext(LexicalDC); |
| 4843 | LexicalDC->addDeclInternal(ToIface); |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4844 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4845 | Importer.MapImported(D, ToIface); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4846 | // Import the type parameter list after MapImported, to avoid |
| Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4847 | // loops when bringing in their DeclContext. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4848 | if (auto ToPListOrErr = |
| 4849 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) |
| 4850 | ToIface->setTypeParamList(*ToPListOrErr); |
| 4851 | else |
| 4852 | return ToPListOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4853 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4854 | if (D->isThisDeclarationADefinition()) |
| 4855 | if (Error Err = ImportDefinition(D, ToIface)) |
| 4856 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4857 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4858 | return ToIface; |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4859 | } |
| 4860 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4861 | ExpectedDecl |
| 4862 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 4863 | ObjCCategoryDecl *Category; |
| 4864 | if (Error Err = importInto(Category, D->getCategoryDecl())) |
| 4865 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4866 | |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4867 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4868 | if (!ToImpl) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4869 | DeclContext *DC, *LexicalDC; |
| 4870 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4871 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4872 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4873 | Error Err = Error::success(); |
| 4874 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 4875 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); |
| 4876 | auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc()); |
| 4877 | if (Err) |
| 4878 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4879 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4880 | if (GetImportedOrCreateDecl( |
| 4881 | ToImpl, D, Importer.getToContext(), DC, |
| 4882 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4883 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4884 | return ToImpl; |
| 4885 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4886 | ToImpl->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4887 | LexicalDC->addDeclInternal(ToImpl); |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4888 | Category->setImplementation(ToImpl); |
| 4889 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4890 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4891 | Importer.MapImported(D, ToImpl); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4892 | if (Error Err = ImportDeclContext(D)) |
| 4893 | return std::move(Err); |
| 4894 | |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4895 | return ToImpl; |
| 4896 | } |
| 4897 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4898 | ExpectedDecl |
| 4899 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4900 | // Find the corresponding interface. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4901 | ObjCInterfaceDecl *Iface; |
| 4902 | if (Error Err = importInto(Iface, D->getClassInterface())) |
| 4903 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4904 | |
| 4905 | // Import the superclass, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4906 | ObjCInterfaceDecl *Super; |
| 4907 | if (Error Err = importInto(Super, D->getSuperClass())) |
| 4908 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4909 | |
| 4910 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4911 | if (!Impl) { |
| 4912 | // We haven't imported an implementation yet. Create a new @implementation |
| 4913 | // now. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4914 | DeclContext *DC, *LexicalDC; |
| 4915 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4916 | return std::move(Err); |
| 4917 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4918 | Error Err = Error::success(); |
| 4919 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 4920 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); |
| 4921 | auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc()); |
| 4922 | auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc()); |
| 4923 | auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc()); |
| 4924 | if (Err) |
| 4925 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4926 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4927 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4928 | DC, Iface, Super, |
| 4929 | ToLocation, |
| 4930 | ToAtStartLoc, |
| 4931 | ToSuperClassLoc, |
| 4932 | ToIvarLBraceLoc, |
| 4933 | ToIvarRBraceLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4934 | return Impl; |
| 4935 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4936 | Impl->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4937 | |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4938 | // Associate the implementation with the class it implements. |
| 4939 | Iface->setImplementation(Impl); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4940 | Importer.MapImported(D, Iface->getImplementation()); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4941 | } else { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4942 | Importer.MapImported(D, Iface->getImplementation()); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4943 | |
| 4944 | // Verify that the existing @implementation has the same superclass. |
| 4945 | if ((Super && !Impl->getSuperClass()) || |
| 4946 | (!Super && Impl->getSuperClass()) || |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4947 | (Super && Impl->getSuperClass() && |
| 4948 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4949 | Impl->getSuperClass()))) { |
| 4950 | Importer.ToDiag(Impl->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4951 | diag::warn_odr_objc_superclass_inconsistent) |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4952 | << Iface->getDeclName(); |
| 4953 | // FIXME: It would be nice to have the location of the superclass |
| 4954 | // below. |
| 4955 | if (Impl->getSuperClass()) |
| 4956 | Importer.ToDiag(Impl->getLocation(), |
| 4957 | diag::note_odr_objc_superclass) |
| 4958 | << Impl->getSuperClass()->getDeclName(); |
| 4959 | else |
| 4960 | Importer.ToDiag(Impl->getLocation(), |
| 4961 | diag::note_odr_objc_missing_superclass); |
| 4962 | if (D->getSuperClass()) |
| 4963 | Importer.FromDiag(D->getLocation(), |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4964 | diag::note_odr_objc_superclass) |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4965 | << D->getSuperClass()->getDeclName(); |
| 4966 | else |
| 4967 | Importer.FromDiag(D->getLocation(), |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4968 | diag::note_odr_objc_missing_superclass); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4969 | |
| 4970 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4971 | } |
| 4972 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4973 | |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4974 | // Import all of the members of this @implementation. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4975 | if (Error Err = ImportDeclContext(D)) |
| 4976 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4977 | |
| 4978 | return Impl; |
| 4979 | } |
| 4980 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4981 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4982 | // Import the major distinguishing characteristics of an @property. |
| 4983 | DeclContext *DC, *LexicalDC; |
| 4984 | DeclarationName Name; |
| 4985 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4986 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4987 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4988 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4989 | if (ToD) |
| 4990 | return ToD; |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4991 | |
| 4992 | // Check whether we have already imported this property. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4993 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4994 | for (auto *FoundDecl : FoundDecls) { |
| 4995 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4996 | // Check property types. |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4997 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4998 | FoundProp->getType())) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4999 | Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent) |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 5000 | << Name << D->getType() << FoundProp->getType(); |
| 5001 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 5002 | << FoundProp->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5003 | |
| 5004 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 5005 | } |
| 5006 | |
| 5007 | // FIXME: Check property attributes, getters, setters, etc.? |
| 5008 | |
| 5009 | // Consider these properties to be equivalent. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5010 | Importer.MapImported(D, FoundProp); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 5011 | return FoundProp; |
| 5012 | } |
| 5013 | } |
| 5014 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5015 | Error Err = Error::success(); |
| 5016 | auto ToType = importChecked(Err, D->getType()); |
| 5017 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 5018 | auto ToAtLoc = importChecked(Err, D->getAtLoc()); |
| 5019 | auto ToLParenLoc = importChecked(Err, D->getLParenLoc()); |
| 5020 | if (Err) |
| 5021 | return std::move(Err); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 5022 | |
| 5023 | // Create the new property. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5024 | ObjCPropertyDecl *ToProperty; |
| 5025 | if (GetImportedOrCreateDecl( |
| 5026 | ToProperty, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5027 | Name.getAsIdentifierInfo(), ToAtLoc, |
| 5028 | ToLParenLoc, ToType, |
| 5029 | ToTypeSourceInfo, D->getPropertyImplementation())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5030 | return ToProperty; |
| 5031 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5032 | auto ToGetterName = importChecked(Err, D->getGetterName()); |
| 5033 | auto ToSetterName = importChecked(Err, D->getSetterName()); |
| 5034 | auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc()); |
| 5035 | auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc()); |
| 5036 | auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl()); |
| 5037 | auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl()); |
| 5038 | auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl()); |
| 5039 | if (Err) |
| 5040 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5041 | |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 5042 | ToProperty->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 5043 | LexicalDC->addDeclInternal(ToProperty); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 5044 | |
| 5045 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
| Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 5046 | ToProperty->setPropertyAttributesAsWritten( |
| 5047 | D->getPropertyAttributesAsWritten()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5048 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); |
| 5049 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); |
| 5050 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); |
| 5051 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); |
| 5052 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 5053 | return ToProperty; |
| 5054 | } |
| 5055 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5056 | ExpectedDecl |
| 5057 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 5058 | ObjCPropertyDecl *Property; |
| 5059 | if (Error Err = importInto(Property, D->getPropertyDecl())) |
| 5060 | return std::move(Err); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5061 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5062 | DeclContext *DC, *LexicalDC; |
| 5063 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5064 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5065 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5066 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5067 | |
| 5068 | // Import the ivar (for an @synthesize). |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5069 | ObjCIvarDecl *Ivar = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5070 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) |
| 5071 | return std::move(Err); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5072 | |
| 5073 | ObjCPropertyImplDecl *ToImpl |
| Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 5074 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 5075 | Property->getQueryKind()); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5076 | if (!ToImpl) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5077 | |
| 5078 | Error Err = Error::success(); |
| 5079 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); |
| 5080 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 5081 | auto ToPropertyIvarDeclLoc = |
| 5082 | importChecked(Err, D->getPropertyIvarDeclLoc()); |
| 5083 | if (Err) |
| 5084 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5085 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5086 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5087 | ToBeginLoc, |
| 5088 | ToLocation, Property, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5089 | D->getPropertyImplementation(), Ivar, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5090 | ToPropertyIvarDeclLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5091 | return ToImpl; |
| 5092 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5093 | ToImpl->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 5094 | LexicalDC->addDeclInternal(ToImpl); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5095 | } else { |
| 5096 | // Check that we have the same kind of property implementation (@synthesize |
| 5097 | // vs. @dynamic). |
| 5098 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5099 | Importer.ToDiag(ToImpl->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 5100 | diag::warn_odr_objc_property_impl_kind_inconsistent) |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5101 | << Property->getDeclName() |
| 5102 | << (ToImpl->getPropertyImplementation() |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5103 | == ObjCPropertyImplDecl::Dynamic); |
| 5104 | Importer.FromDiag(D->getLocation(), |
| 5105 | diag::note_odr_objc_property_impl_kind) |
| 5106 | << D->getPropertyDecl()->getDeclName() |
| 5107 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5108 | |
| 5109 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5110 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5111 | |
| 5112 | // For @synthesize, check that we have the same |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5113 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 5114 | Ivar != ToImpl->getPropertyIvarDecl()) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5115 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 5116 | diag::warn_odr_objc_synthesize_ivar_inconsistent) |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5117 | << Property->getDeclName() |
| 5118 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 5119 | << Ivar->getDeclName(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5120 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5121 | diag::note_odr_objc_synthesize_ivar_here) |
| 5122 | << D->getPropertyIvarDecl()->getDeclName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5123 | |
| 5124 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5125 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5126 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5127 | // Merge the existing implementation with the new implementation. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5128 | Importer.MapImported(D, ToImpl); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5129 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5130 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5131 | return ToImpl; |
| 5132 | } |
| 5133 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5134 | ExpectedDecl |
| 5135 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5136 | // For template arguments, we adopt the translation unit as our declaration |
| 5137 | // context. This context will be fixed when the actual template declaration |
| 5138 | // is created. |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5139 | |
| Saar Raz | ff1e0fc | 2020-01-15 02:48:42 +0200 | [diff] [blame] | 5140 | // FIXME: Import default argument and constraint expression. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5141 | |
| 5142 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5143 | if (!BeginLocOrErr) |
| 5144 | return BeginLocOrErr.takeError(); |
| 5145 | |
| 5146 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 5147 | if (!LocationOrErr) |
| 5148 | return LocationOrErr.takeError(); |
| 5149 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5150 | TemplateTypeParmDecl *ToD = nullptr; |
| Saar Raz | ff1e0fc | 2020-01-15 02:48:42 +0200 | [diff] [blame] | 5151 | if (GetImportedOrCreateDecl( |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5152 | ToD, D, Importer.getToContext(), |
| 5153 | Importer.getToContext().getTranslationUnitDecl(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5154 | *BeginLocOrErr, *LocationOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5155 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| Saar Raz | ff1e0fc | 2020-01-15 02:48:42 +0200 | [diff] [blame] | 5156 | D->wasDeclaredWithTypename(), D->isParameterPack(), |
| 5157 | D->hasTypeConstraint())) |
| 5158 | return ToD; |
| 5159 | |
| 5160 | // Import the type-constraint |
| 5161 | if (const TypeConstraint *TC = D->getTypeConstraint()) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5162 | |
| 5163 | Error Err = Error::success(); |
| 5164 | auto ToNNS = importChecked(Err, TC->getNestedNameSpecifierLoc()); |
| 5165 | auto ToName = importChecked(Err, TC->getConceptNameInfo().getName()); |
| 5166 | auto ToNameLoc = importChecked(Err, TC->getConceptNameInfo().getLoc()); |
| 5167 | auto ToFoundDecl = importChecked(Err, TC->getFoundDecl()); |
| 5168 | auto ToNamedConcept = importChecked(Err, TC->getNamedConcept()); |
| 5169 | auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint()); |
| 5170 | if (Err) |
| 5171 | return std::move(Err); |
| Saar Raz | ff1e0fc | 2020-01-15 02:48:42 +0200 | [diff] [blame] | 5172 | |
| 5173 | TemplateArgumentListInfo ToTAInfo; |
| 5174 | const auto *ASTTemplateArgs = TC->getTemplateArgsAsWritten(); |
| 5175 | if (ASTTemplateArgs) |
| 5176 | if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, |
| 5177 | ToTAInfo)) |
| 5178 | return std::move(Err); |
| 5179 | |
| 5180 | ToD->setTypeConstraint(ToNNS, DeclarationNameInfo(ToName, ToNameLoc), |
| 5181 | ToFoundDecl, ToNamedConcept, |
| 5182 | ASTTemplateArgs ? |
| 5183 | ASTTemplateArgumentListInfo::Create(Importer.getToContext(), |
| 5184 | ToTAInfo) : nullptr, |
| 5185 | ToIDC); |
| 5186 | } |
| 5187 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5188 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5189 | } |
| 5190 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5191 | ExpectedDecl |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5192 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5193 | |
| 5194 | Error Err = Error::success(); |
| 5195 | auto ToDeclName = importChecked(Err, D->getDeclName()); |
| 5196 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 5197 | auto ToType = importChecked(Err, D->getType()); |
| 5198 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 5199 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 5200 | if (Err) |
| 5201 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5202 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5203 | // FIXME: Import default argument. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5204 | |
| 5205 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 5206 | (void)GetImportedOrCreateDecl( |
| 5207 | ToD, D, Importer.getToContext(), |
| 5208 | Importer.getToContext().getTranslationUnitDecl(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5209 | ToInnerLocStart, ToLocation, D->getDepth(), |
| 5210 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, |
| 5211 | D->isParameterPack(), ToTypeSourceInfo); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5212 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5213 | } |
| 5214 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5215 | ExpectedDecl |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5216 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 5217 | // Import the name of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5218 | auto NameOrErr = import(D->getDeclName()); |
| 5219 | if (!NameOrErr) |
| 5220 | return NameOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5221 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5222 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5223 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 5224 | if (!LocationOrErr) |
| 5225 | return LocationOrErr.takeError(); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5226 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5227 | // Import template parameters. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5228 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5229 | if (!TemplateParamsOrErr) |
| 5230 | return TemplateParamsOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5231 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5232 | // FIXME: Import default argument. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5233 | |
| 5234 | TemplateTemplateParmDecl *ToD = nullptr; |
| 5235 | (void)GetImportedOrCreateDecl( |
| 5236 | ToD, D, Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5237 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, |
| 5238 | D->getDepth(), D->getPosition(), D->isParameterPack(), |
| 5239 | (*NameOrErr).getAsIdentifierInfo(), |
| 5240 | *TemplateParamsOrErr); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5241 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5242 | } |
| 5243 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5244 | // Returns the definition for a (forward) declaration of a TemplateDecl, if |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5245 | // it has any definition in the redecl chain. |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5246 | template <typename T> static auto getTemplateDefinition(T *D) -> T * { |
| 5247 | assert(D->getTemplatedDecl() && "Should be called on templates only"); |
| 5248 | auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5249 | if (!ToTemplatedDef) |
| 5250 | return nullptr; |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5251 | auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate(); |
| 5252 | return cast_or_null<T>(TemplateWithDef); |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5253 | } |
| 5254 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5255 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5256 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5257 | // Import the major distinguishing characteristics of this class template. |
| 5258 | DeclContext *DC, *LexicalDC; |
| 5259 | DeclarationName Name; |
| 5260 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5261 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5262 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5263 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5264 | if (ToD) |
| 5265 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5266 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5267 | ClassTemplateDecl *FoundByLookup = nullptr; |
| 5268 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5269 | // We may already have a template of the same name; try to find and match it. |
| 5270 | if (!DC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5271 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5272 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5273 | for (auto *FoundDecl : FoundDecls) { |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5274 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary | |
| 5275 | Decl::IDNS_TagFriend)) |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5276 | continue; |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5277 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5278 | Decl *Found = FoundDecl; |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5279 | auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found); |
| 5280 | if (FoundTemplate) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 5281 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D)) |
| Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 5282 | continue; |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5283 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5284 | if (IsStructuralMatch(D, FoundTemplate)) { |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5285 | ClassTemplateDecl *TemplateWithDef = |
| 5286 | getTemplateDefinition(FoundTemplate); |
| Balazs Keri | 2e16060 | 2019-08-12 10:07:38 +0000 | [diff] [blame] | 5287 | if (D->isThisDeclarationADefinition() && TemplateWithDef) |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5288 | return Importer.MapImported(D, TemplateWithDef); |
| Balazs Keri | 2e16060 | 2019-08-12 10:07:38 +0000 | [diff] [blame] | 5289 | if (!FoundByLookup) |
| 5290 | FoundByLookup = FoundTemplate; |
| 5291 | // Search in all matches because there may be multiple decl chains, |
| 5292 | // see ASTTests test ImportExistingFriendClassTemplateDef. |
| 5293 | continue; |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5294 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5295 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5296 | } |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5297 | } |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5298 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5299 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5300 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 5301 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), |
| 5302 | ConflictingDecls.size()); |
| 5303 | if (NameOrErr) |
| 5304 | Name = NameOrErr.get(); |
| 5305 | else |
| 5306 | return NameOrErr.takeError(); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5307 | } |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5308 | } |
| 5309 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5310 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 5311 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5312 | // Create the declaration that is being templated. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5313 | CXXRecordDecl *ToTemplated; |
| 5314 | if (Error Err = importInto(ToTemplated, FromTemplated)) |
| 5315 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5316 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5317 | // Create the class template declaration itself. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5318 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5319 | if (!TemplateParamsOrErr) |
| 5320 | return TemplateParamsOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5321 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5322 | ClassTemplateDecl *D2; |
| 5323 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5324 | *TemplateParamsOrErr, ToTemplated)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5325 | return D2; |
| 5326 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5327 | ToTemplated->setDescribedClassTemplate(D2); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5328 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5329 | D2->setAccess(D->getAccess()); |
| 5330 | D2->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5331 | |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 5332 | addDeclToContexts(D, D2); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5333 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5334 | if (FoundByLookup) { |
| 5335 | auto *Recent = |
| 5336 | const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5337 | |
| 5338 | // It is possible that during the import of the class template definition |
| 5339 | // we start the import of a fwd friend decl of the very same class template |
| 5340 | // and we add the fwd friend decl to the lookup table. But the ToTemplated |
| 5341 | // had been created earlier and by that time the lookup could not find |
| 5342 | // anything existing, so it has no previous decl. Later, (still during the |
| 5343 | // import of the fwd friend decl) we start to import the definition again |
| 5344 | // and this time the lookup finds the previous fwd friend class template. |
| 5345 | // In this case we must set up the previous decl for the templated decl. |
| 5346 | if (!ToTemplated->getPreviousDecl()) { |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5347 | assert(FoundByLookup->getTemplatedDecl() && |
| 5348 | "Found decl must have its templated decl set"); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5349 | CXXRecordDecl *PrevTemplated = |
| 5350 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5351 | if (ToTemplated != PrevTemplated) |
| 5352 | ToTemplated->setPreviousDecl(PrevTemplated); |
| 5353 | } |
| 5354 | |
| 5355 | D2->setPreviousDecl(Recent); |
| 5356 | } |
| 5357 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5358 | if (FromTemplated->isCompleteDefinition() && |
| 5359 | !ToTemplated->isCompleteDefinition()) { |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5360 | // FIXME: Import definition! |
| 5361 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5362 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5363 | return D2; |
| 5364 | } |
| 5365 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5366 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5367 | ClassTemplateSpecializationDecl *D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5368 | ClassTemplateDecl *ClassTemplate; |
| 5369 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) |
| 5370 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5371 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5372 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5373 | DeclContext *DC, *LexicalDC; |
| 5374 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5375 | return std::move(Err); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5376 | |
| 5377 | // Import template arguments. |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5378 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5379 | if (Error Err = ImportTemplateArguments( |
| 5380 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5381 | return std::move(Err); |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5382 | // Try to find an existing specialization with these template arguments and |
| 5383 | // template parameter list. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5384 | void *InsertPos = nullptr; |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5385 | ClassTemplateSpecializationDecl *PrevDecl = nullptr; |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5386 | ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 5387 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5388 | |
| 5389 | // Import template parameters. |
| 5390 | TemplateParameterList *ToTPList = nullptr; |
| 5391 | |
| 5392 | if (PartialSpec) { |
| 5393 | auto ToTPListOrErr = import(PartialSpec->getTemplateParameters()); |
| 5394 | if (!ToTPListOrErr) |
| 5395 | return ToTPListOrErr.takeError(); |
| 5396 | ToTPList = *ToTPListOrErr; |
| 5397 | PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs, |
| 5398 | *ToTPListOrErr, |
| 5399 | InsertPos); |
| 5400 | } else |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5401 | PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5402 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5403 | if (PrevDecl) { |
| 5404 | if (IsStructuralMatch(D, PrevDecl)) { |
| 5405 | if (D->isThisDeclarationADefinition() && PrevDecl->getDefinition()) { |
| 5406 | Importer.MapImported(D, PrevDecl->getDefinition()); |
| 5407 | // Import those default field initializers which have been |
| 5408 | // instantiated in the "From" context, but not in the "To" context. |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5409 | for (auto *FromField : D->fields()) { |
| 5410 | auto ToOrErr = import(FromField); |
| 5411 | if (!ToOrErr) |
| 5412 | return ToOrErr.takeError(); |
| 5413 | } |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5414 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5415 | // Import those methods which have been instantiated in the |
| 5416 | // "From" context, but not in the "To" context. |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5417 | for (CXXMethodDecl *FromM : D->methods()) { |
| 5418 | auto ToOrErr = import(FromM); |
| 5419 | if (!ToOrErr) |
| 5420 | return ToOrErr.takeError(); |
| 5421 | } |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5422 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5423 | // TODO Import instantiated default arguments. |
| 5424 | // TODO Import instantiated exception specifications. |
| 5425 | // |
| 5426 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint |
| 5427 | // what else could be fused during an AST merge. |
| 5428 | return PrevDecl; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5429 | } |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5430 | } else { // ODR violation. |
| 5431 | // FIXME HandleNameConflict |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 5432 | return make_error<ImportError>(ImportError::NameConflict); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5433 | } |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5434 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5435 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5436 | // Import the location of this declaration. |
| 5437 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5438 | if (!BeginLocOrErr) |
| 5439 | return BeginLocOrErr.takeError(); |
| 5440 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); |
| 5441 | if (!IdLocOrErr) |
| 5442 | return IdLocOrErr.takeError(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5443 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5444 | // Create the specialization. |
| 5445 | ClassTemplateSpecializationDecl *D2 = nullptr; |
| 5446 | if (PartialSpec) { |
| 5447 | // Import TemplateArgumentListInfo. |
| 5448 | TemplateArgumentListInfo ToTAInfo; |
| 5449 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 5450 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
| 5451 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5452 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5453 | QualType CanonInjType; |
| 5454 | if (Error Err = importInto( |
| 5455 | CanonInjType, PartialSpec->getInjectedSpecializationType())) |
| 5456 | return std::move(Err); |
| 5457 | CanonInjType = CanonInjType.getCanonicalType(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5458 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5459 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
| 5460 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5461 | *BeginLocOrErr, *IdLocOrErr, ToTPList, ClassTemplate, |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5462 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 5463 | ToTAInfo, CanonInjType, |
| 5464 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) |
| 5465 | return D2; |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5466 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5467 | // Update InsertPos, because preceding import calls may have invalidated |
| 5468 | // it by adding new specializations. |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5469 | auto *PartSpec2 = cast<ClassTemplatePartialSpecializationDecl>(D2); |
| 5470 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList, |
| 5471 | InsertPos)) |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5472 | // Add this partial specialization to the class template. |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5473 | ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5474 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5475 | } else { // Not a partial specialization. |
| 5476 | if (GetImportedOrCreateDecl( |
| 5477 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5478 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, |
| 5479 | PrevDecl)) |
| 5480 | return D2; |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5481 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5482 | // Update InsertPos, because preceding import calls may have invalidated |
| 5483 | // it by adding new specializations. |
| 5484 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) |
| 5485 | // Add this specialization to the class template. |
| 5486 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 5487 | } |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5488 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5489 | D2->setSpecializationKind(D->getSpecializationKind()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5490 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5491 | // Set the context of this specialization/instantiation. |
| 5492 | D2->setLexicalDeclContext(LexicalDC); |
| 5493 | |
| 5494 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 5495 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 5496 | LexicalDC->addDeclInternal(D2); |
| 5497 | } |
| 5498 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 5499 | if (auto BraceRangeOrErr = import(D->getBraceRange())) |
| 5500 | D2->setBraceRange(*BraceRangeOrErr); |
| 5501 | else |
| 5502 | return BraceRangeOrErr.takeError(); |
| 5503 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5504 | // Import the qualifier, if any. |
| 5505 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5506 | D2->setQualifierInfo(*LocOrErr); |
| 5507 | else |
| 5508 | return LocOrErr.takeError(); |
| 5509 | |
| 5510 | if (auto *TSI = D->getTypeAsWritten()) { |
| 5511 | if (auto TInfoOrErr = import(TSI)) |
| 5512 | D2->setTypeAsWritten(*TInfoOrErr); |
| 5513 | else |
| 5514 | return TInfoOrErr.takeError(); |
| 5515 | |
| 5516 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) |
| 5517 | D2->setTemplateKeywordLoc(*LocOrErr); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5518 | else |
| 5519 | return LocOrErr.takeError(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5520 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5521 | if (auto LocOrErr = import(D->getExternLoc())) |
| 5522 | D2->setExternLoc(*LocOrErr); |
| 5523 | else |
| 5524 | return LocOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5525 | } |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5526 | |
| 5527 | if (D->getPointOfInstantiation().isValid()) { |
| 5528 | if (auto POIOrErr = import(D->getPointOfInstantiation())) |
| 5529 | D2->setPointOfInstantiation(*POIOrErr); |
| 5530 | else |
| 5531 | return POIOrErr.takeError(); |
| 5532 | } |
| 5533 | |
| 5534 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 5535 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5536 | if (D->isCompleteDefinition()) |
| 5537 | if (Error Err = ImportDefinition(D, D2)) |
| 5538 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5539 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5540 | return D2; |
| 5541 | } |
| 5542 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5543 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5544 | // Import the major distinguishing characteristics of this variable template. |
| 5545 | DeclContext *DC, *LexicalDC; |
| 5546 | DeclarationName Name; |
| 5547 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5548 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5549 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5550 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5551 | if (ToD) |
| 5552 | return ToD; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5553 | |
| 5554 | // We may already have a template of the same name; try to find and match it. |
| 5555 | assert(!DC->isFunctionOrMethod() && |
| 5556 | "Variable templates cannot be declared at function scope"); |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 5557 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5558 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5559 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 5560 | VarTemplateDecl *FoundByLookup = nullptr; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5561 | for (auto *FoundDecl : FoundDecls) { |
| 5562 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5563 | continue; |
| 5564 | |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 5565 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) { |
| Balázs Kéri | 8d67bcf | 2020-03-09 11:01:48 +0100 | [diff] [blame] | 5566 | // Use the templated decl, some linkage flags are set only there. |
| 5567 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(), |
| 5568 | D->getTemplatedDecl())) |
| 5569 | continue; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5570 | if (IsStructuralMatch(D, FoundTemplate)) { |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 5571 | // The Decl in the "From" context has a definition, but in the |
| 5572 | // "To" context we already have a definition. |
| 5573 | VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate); |
| 5574 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 5575 | // FIXME Check for ODR error if the two definitions have |
| 5576 | // different initializers? |
| 5577 | return Importer.MapImported(D, FoundDef); |
| 5578 | |
| 5579 | FoundByLookup = FoundTemplate; |
| 5580 | break; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5581 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5582 | ConflictingDecls.push_back(FoundDecl); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5583 | } |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5584 | } |
| 5585 | |
| 5586 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5587 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 5588 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), |
| 5589 | ConflictingDecls.size()); |
| 5590 | if (NameOrErr) |
| 5591 | Name = NameOrErr.get(); |
| 5592 | else |
| 5593 | return NameOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5594 | } |
| 5595 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5596 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 5597 | |
| 5598 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5599 | // FIXME: Value not used? |
| 5600 | ExpectedType TypeOrErr = import(DTemplated->getType()); |
| 5601 | if (!TypeOrErr) |
| 5602 | return TypeOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5603 | |
| 5604 | // Create the declaration that is being templated. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5605 | VarDecl *ToTemplated; |
| 5606 | if (Error Err = importInto(ToTemplated, DTemplated)) |
| 5607 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5608 | |
| 5609 | // Create the variable template declaration itself. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5610 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5611 | if (!TemplateParamsOrErr) |
| 5612 | return TemplateParamsOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5613 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5614 | VarTemplateDecl *ToVarTD; |
| 5615 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5616 | Name, *TemplateParamsOrErr, ToTemplated)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5617 | return ToVarTD; |
| 5618 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5619 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5620 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5621 | ToVarTD->setAccess(D->getAccess()); |
| 5622 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 5623 | LexicalDC->addDeclInternal(ToVarTD); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5624 | |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 5625 | if (FoundByLookup) { |
| 5626 | auto *Recent = |
| 5627 | const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5628 | if (!ToTemplated->getPreviousDecl()) { |
| 5629 | auto *PrevTemplated = |
| 5630 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5631 | if (ToTemplated != PrevTemplated) |
| 5632 | ToTemplated->setPreviousDecl(PrevTemplated); |
| 5633 | } |
| 5634 | ToVarTD->setPreviousDecl(Recent); |
| 5635 | } |
| 5636 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5637 | if (DTemplated->isThisDeclarationADefinition() && |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5638 | !ToTemplated->isThisDeclarationADefinition()) { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5639 | // FIXME: Import definition! |
| 5640 | } |
| 5641 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5642 | return ToVarTD; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5643 | } |
| 5644 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5645 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5646 | VarTemplateSpecializationDecl *D) { |
| 5647 | // If this record has a definition in the translation unit we're coming from, |
| 5648 | // but this particular declaration is not that definition, import the |
| 5649 | // definition and map to that. |
| 5650 | VarDecl *Definition = D->getDefinition(); |
| 5651 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5652 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5653 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5654 | else |
| 5655 | return ImportedDefOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5656 | } |
| 5657 | |
| Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 5658 | VarTemplateDecl *VarTemplate = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5659 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) |
| 5660 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5661 | |
| 5662 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5663 | DeclContext *DC, *LexicalDC; |
| 5664 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5665 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5666 | |
| 5667 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5668 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5669 | if (!BeginLocOrErr) |
| 5670 | return BeginLocOrErr.takeError(); |
| 5671 | |
| 5672 | auto IdLocOrErr = import(D->getLocation()); |
| 5673 | if (!IdLocOrErr) |
| 5674 | return IdLocOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5675 | |
| 5676 | // Import template arguments. |
| 5677 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5678 | if (Error Err = ImportTemplateArguments( |
| 5679 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5680 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5681 | |
| 5682 | // Try to find an existing specialization with these template arguments. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5683 | void *InsertPos = nullptr; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5684 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
| Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 5685 | TemplateArgs, InsertPos); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5686 | if (D2) { |
| 5687 | // We already have a variable template specialization with these template |
| 5688 | // arguments. |
| 5689 | |
| 5690 | // FIXME: Check for specialization vs. instantiation errors. |
| 5691 | |
| 5692 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 5693 | if (!D->isThisDeclarationADefinition() || |
| 5694 | IsStructuralMatch(D, FoundDef)) { |
| 5695 | // The record types structurally match, or the "from" translation |
| 5696 | // unit only had a forward declaration anyway; call it the same |
| 5697 | // variable. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5698 | return Importer.MapImported(D, FoundDef); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5699 | } |
| 5700 | } |
| 5701 | } else { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5702 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5703 | QualType T; |
| 5704 | if (Error Err = importInto(T, D->getType())) |
| 5705 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5706 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5707 | auto TInfoOrErr = import(D->getTypeSourceInfo()); |
| 5708 | if (!TInfoOrErr) |
| 5709 | return TInfoOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5710 | |
| 5711 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5712 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5713 | D->getTemplateArgsInfo(), ToTAInfo)) |
| 5714 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5715 | |
| 5716 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5717 | // Create a new specialization. |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5718 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 5719 | // Import TemplateArgumentListInfo |
| 5720 | TemplateArgumentListInfo ArgInfos; |
| 5721 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 5722 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5723 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5724 | *FromTAArgsAsWritten, ArgInfos)) |
| 5725 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5726 | |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5727 | auto ToTPListOrErr = import(FromPartial->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5728 | if (!ToTPListOrErr) |
| 5729 | return ToTPListOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5730 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5731 | PartVarSpecDecl *ToPartial; |
| 5732 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5733 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, |
| 5734 | VarTemplate, T, *TInfoOrErr, |
| 5735 | D->getStorageClass(), TemplateArgs, ArgInfos)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5736 | return ToPartial; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5737 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5738 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( |
| 5739 | FromPartial->getInstantiatedFromMember())) |
| 5740 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); |
| 5741 | else |
| 5742 | return ToInstOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5743 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5744 | if (FromPartial->isMemberSpecialization()) |
| 5745 | ToPartial->setMemberSpecialization(); |
| 5746 | |
| 5747 | D2 = ToPartial; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5748 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5749 | } else { // Full specialization |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5750 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, |
| 5751 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, |
| 5752 | T, *TInfoOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5753 | D->getStorageClass(), TemplateArgs)) |
| 5754 | return D2; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5755 | } |
| 5756 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5757 | if (D->getPointOfInstantiation().isValid()) { |
| 5758 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) |
| 5759 | D2->setPointOfInstantiation(*POIOrErr); |
| 5760 | else |
| 5761 | return POIOrErr.takeError(); |
| 5762 | } |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5763 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5764 | D2->setSpecializationKind(D->getSpecializationKind()); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5765 | D2->setTemplateArgsInfo(ToTAInfo); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5766 | |
| 5767 | // Add this specialization to the class template. |
| 5768 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 5769 | |
| 5770 | // Import the qualifier, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5771 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5772 | D2->setQualifierInfo(*LocOrErr); |
| 5773 | else |
| 5774 | return LocOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5775 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5776 | if (D->isConstexpr()) |
| 5777 | D2->setConstexpr(true); |
| 5778 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5779 | // Add the specialization to this context. |
| 5780 | D2->setLexicalDeclContext(LexicalDC); |
| 5781 | LexicalDC->addDeclInternal(D2); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5782 | |
| 5783 | D2->setAccess(D->getAccess()); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5784 | } |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5785 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5786 | if (Error Err = ImportInitializer(D, D2)) |
| 5787 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5788 | |
| 5789 | return D2; |
| 5790 | } |
| 5791 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5792 | ExpectedDecl |
| 5793 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5794 | DeclContext *DC, *LexicalDC; |
| 5795 | DeclarationName Name; |
| 5796 | SourceLocation Loc; |
| 5797 | NamedDecl *ToD; |
| 5798 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5799 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5800 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5801 | |
| 5802 | if (ToD) |
| 5803 | return ToD; |
| 5804 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5805 | const FunctionTemplateDecl *FoundByLookup = nullptr; |
| 5806 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5807 | // Try to find a function in our own ("to") context with the same name, same |
| 5808 | // type, and in the same context as the function we're importing. |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5809 | // FIXME Split this into a separate function. |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5810 | if (!LexicalDC->isFunctionOrMethod()) { |
| Gabor Marton | e331e63 | 2019-02-18 13:09:27 +0000 | [diff] [blame] | 5811 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5812 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5813 | for (auto *FoundDecl : FoundDecls) { |
| 5814 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5815 | continue; |
| 5816 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5817 | if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 5818 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D)) |
| Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 5819 | continue; |
| 5820 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5821 | FunctionTemplateDecl *TemplateWithDef = |
| 5822 | getTemplateDefinition(FoundTemplate); |
| 5823 | if (D->isThisDeclarationADefinition() && TemplateWithDef) |
| 5824 | return Importer.MapImported(D, TemplateWithDef); |
| 5825 | |
| 5826 | FoundByLookup = FoundTemplate; |
| 5827 | break; |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5828 | // TODO: handle conflicting names |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5829 | } |
| 5830 | } |
| 5831 | } |
| 5832 | } |
| 5833 | |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5834 | auto ParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5835 | if (!ParamsOrErr) |
| 5836 | return ParamsOrErr.takeError(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5837 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5838 | FunctionDecl *TemplatedFD; |
| 5839 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) |
| 5840 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5841 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5842 | FunctionTemplateDecl *ToFunc; |
| 5843 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5844 | *ParamsOrErr, TemplatedFD)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5845 | return ToFunc; |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5846 | |
| 5847 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5848 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5849 | ToFunc->setAccess(D->getAccess()); |
| 5850 | ToFunc->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5851 | LexicalDC->addDeclInternal(ToFunc); |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5852 | |
| 5853 | if (FoundByLookup) { |
| 5854 | auto *Recent = |
| 5855 | const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5856 | if (!TemplatedFD->getPreviousDecl()) { |
| 5857 | assert(FoundByLookup->getTemplatedDecl() && |
| 5858 | "Found decl must have its templated decl set"); |
| 5859 | auto *PrevTemplated = |
| 5860 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5861 | if (TemplatedFD != PrevTemplated) |
| 5862 | TemplatedFD->setPreviousDecl(PrevTemplated); |
| 5863 | } |
| 5864 | ToFunc->setPreviousDecl(Recent); |
| 5865 | } |
| 5866 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5867 | return ToFunc; |
| 5868 | } |
| 5869 | |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5870 | //---------------------------------------------------------------------------- |
| 5871 | // Import Statements |
| 5872 | //---------------------------------------------------------------------------- |
| 5873 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5874 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5875 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) |
| 5876 | << S->getStmtClassName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5877 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5878 | } |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5879 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5880 | |
| 5881 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 5882 | if (Importer.returnWithErrorInTest()) |
| 5883 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5884 | SmallVector<IdentifierInfo *, 4> Names; |
| 5885 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 5886 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
| Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5887 | // ToII is nullptr when no symbolic name is given for output operand |
| 5888 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5889 | Names.push_back(ToII); |
| 5890 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5891 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5892 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 5893 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
| Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5894 | // ToII is nullptr when no symbolic name is given for input operand |
| 5895 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5896 | Names.push_back(ToII); |
| 5897 | } |
| 5898 | |
| 5899 | SmallVector<StringLiteral *, 4> Clobbers; |
| 5900 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5901 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) |
| 5902 | Clobbers.push_back(*ClobberOrErr); |
| 5903 | else |
| 5904 | return ClobberOrErr.takeError(); |
| 5905 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5906 | } |
| 5907 | |
| 5908 | SmallVector<StringLiteral *, 4> Constraints; |
| 5909 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5910 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) |
| 5911 | Constraints.push_back(*OutputOrErr); |
| 5912 | else |
| 5913 | return OutputOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5914 | } |
| 5915 | |
| 5916 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5917 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) |
| 5918 | Constraints.push_back(*InputOrErr); |
| 5919 | else |
| 5920 | return InputOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5921 | } |
| 5922 | |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5923 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() + |
| 5924 | S->getNumLabels()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5925 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) |
| 5926 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5927 | |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5928 | if (Error Err = |
| 5929 | ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
| 5930 | return std::move(Err); |
| 5931 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5932 | if (Error Err = ImportArrayChecked( |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5933 | S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs())) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5934 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5935 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5936 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); |
| 5937 | if (!AsmLocOrErr) |
| 5938 | return AsmLocOrErr.takeError(); |
| 5939 | auto AsmStrOrErr = import(S->getAsmString()); |
| 5940 | if (!AsmStrOrErr) |
| 5941 | return AsmStrOrErr.takeError(); |
| 5942 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); |
| 5943 | if (!RParenLocOrErr) |
| 5944 | return RParenLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5945 | |
| 5946 | return new (Importer.getToContext()) GCCAsmStmt( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5947 | Importer.getToContext(), |
| 5948 | *AsmLocOrErr, |
| 5949 | S->isSimple(), |
| 5950 | S->isVolatile(), |
| 5951 | S->getNumOutputs(), |
| 5952 | S->getNumInputs(), |
| 5953 | Names.data(), |
| 5954 | Constraints.data(), |
| 5955 | Exprs.data(), |
| 5956 | *AsmStrOrErr, |
| 5957 | S->getNumClobbers(), |
| 5958 | Clobbers.data(), |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5959 | S->getNumLabels(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5960 | *RParenLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5961 | } |
| 5962 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5963 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5964 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5965 | Error Err = Error::success(); |
| 5966 | auto ToDG = importChecked(Err, S->getDeclGroup()); |
| 5967 | auto ToBeginLoc = importChecked(Err, S->getBeginLoc()); |
| 5968 | auto ToEndLoc = importChecked(Err, S->getEndLoc()); |
| 5969 | if (Err) |
| 5970 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5971 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5972 | } |
| 5973 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5974 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5975 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); |
| 5976 | if (!ToSemiLocOrErr) |
| 5977 | return ToSemiLocOrErr.takeError(); |
| 5978 | return new (Importer.getToContext()) NullStmt( |
| 5979 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5980 | } |
| 5981 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5982 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5983 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5984 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5985 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) |
| 5986 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5987 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5988 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); |
| 5989 | if (!ToLBracLocOrErr) |
| 5990 | return ToLBracLocOrErr.takeError(); |
| 5991 | |
| 5992 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); |
| 5993 | if (!ToRBracLocOrErr) |
| 5994 | return ToRBracLocOrErr.takeError(); |
| 5995 | |
| 5996 | return CompoundStmt::Create( |
| 5997 | Importer.getToContext(), ToStmts, |
| 5998 | *ToLBracLocOrErr, *ToRBracLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5999 | } |
| 6000 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6001 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6002 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6003 | Error Err = Error::success(); |
| 6004 | auto ToLHS = importChecked(Err, S->getLHS()); |
| 6005 | auto ToRHS = importChecked(Err, S->getRHS()); |
| 6006 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); |
| 6007 | auto ToCaseLoc = importChecked(Err, S->getCaseLoc()); |
| 6008 | auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc()); |
| 6009 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); |
| 6010 | if (Err) |
| 6011 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6012 | |
| Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 6013 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, |
| 6014 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
| Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 6015 | ToStmt->setSubStmt(ToSubStmt); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6016 | |
| Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 6017 | return ToStmt; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6018 | } |
| 6019 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6020 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6021 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6022 | Error Err = Error::success(); |
| 6023 | auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc()); |
| 6024 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); |
| 6025 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); |
| 6026 | if (Err) |
| 6027 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6028 | |
| 6029 | return new (Importer.getToContext()) DefaultStmt( |
| 6030 | ToDefaultLoc, ToColonLoc, ToSubStmt); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6031 | } |
| 6032 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6033 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6034 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6035 | Error Err = Error::success(); |
| 6036 | auto ToIdentLoc = importChecked(Err, S->getIdentLoc()); |
| 6037 | auto ToLabelDecl = importChecked(Err, S->getDecl()); |
| 6038 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); |
| 6039 | if (Err) |
| 6040 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6041 | |
| 6042 | return new (Importer.getToContext()) LabelStmt( |
| 6043 | ToIdentLoc, ToLabelDecl, ToSubStmt); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6044 | } |
| 6045 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6046 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 6047 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); |
| 6048 | if (!ToAttrLocOrErr) |
| 6049 | return ToAttrLocOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6050 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 6051 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6052 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) |
| 6053 | return std::move(Err); |
| 6054 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 6055 | if (!ToSubStmtOrErr) |
| 6056 | return ToSubStmtOrErr.takeError(); |
| 6057 | |
| 6058 | return AttributedStmt::Create( |
| 6059 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6060 | } |
| 6061 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6062 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6063 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6064 | Error Err = Error::success(); |
| 6065 | auto ToIfLoc = importChecked(Err, S->getIfLoc()); |
| 6066 | auto ToInit = importChecked(Err, S->getInit()); |
| 6067 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); |
| 6068 | auto ToCond = importChecked(Err, S->getCond()); |
| 6069 | auto ToThen = importChecked(Err, S->getThen()); |
| 6070 | auto ToElseLoc = importChecked(Err, S->getElseLoc()); |
| 6071 | auto ToElse = importChecked(Err, S->getElse()); |
| 6072 | if (Err) |
| 6073 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6074 | |
| Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 6075 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), |
| 6076 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, |
| 6077 | ToElse); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6078 | } |
| 6079 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6080 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6081 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6082 | Error Err = Error::success(); |
| 6083 | auto ToInit = importChecked(Err, S->getInit()); |
| 6084 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); |
| 6085 | auto ToCond = importChecked(Err, S->getCond()); |
| 6086 | auto ToBody = importChecked(Err, S->getBody()); |
| 6087 | auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc()); |
| 6088 | if (Err) |
| 6089 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6090 | |
| Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 6091 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, |
| 6092 | ToConditionVariable, ToCond); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6093 | ToStmt->setBody(ToBody); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6094 | ToStmt->setSwitchLoc(ToSwitchLoc); |
| 6095 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6096 | // Now we have to re-chain the cases. |
| 6097 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 6098 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 6099 | SC = SC->getNextSwitchCase()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6100 | Expected<SwitchCase *> ToSCOrErr = import(SC); |
| 6101 | if (!ToSCOrErr) |
| 6102 | return ToSCOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6103 | if (LastChainedSwitchCase) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6104 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6105 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6106 | ToStmt->setSwitchCaseList(*ToSCOrErr); |
| 6107 | LastChainedSwitchCase = *ToSCOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6108 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6109 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6110 | return ToStmt; |
| 6111 | } |
| 6112 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6113 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6114 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6115 | Error Err = Error::success(); |
| 6116 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); |
| 6117 | auto ToCond = importChecked(Err, S->getCond()); |
| 6118 | auto ToBody = importChecked(Err, S->getBody()); |
| 6119 | auto ToWhileLoc = importChecked(Err, S->getWhileLoc()); |
| 6120 | if (Err) |
| 6121 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6122 | |
| Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 6123 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, |
| 6124 | ToBody, ToWhileLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6125 | } |
| 6126 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6127 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6128 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6129 | Error Err = Error::success(); |
| 6130 | auto ToBody = importChecked(Err, S->getBody()); |
| 6131 | auto ToCond = importChecked(Err, S->getCond()); |
| 6132 | auto ToDoLoc = importChecked(Err, S->getDoLoc()); |
| 6133 | auto ToWhileLoc = importChecked(Err, S->getWhileLoc()); |
| 6134 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); |
| 6135 | if (Err) |
| 6136 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6137 | |
| 6138 | return new (Importer.getToContext()) DoStmt( |
| 6139 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6140 | } |
| 6141 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6142 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6143 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6144 | Error Err = Error::success(); |
| 6145 | auto ToInit = importChecked(Err, S->getInit()); |
| 6146 | auto ToCond = importChecked(Err, S->getCond()); |
| 6147 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); |
| 6148 | auto ToInc = importChecked(Err, S->getInc()); |
| 6149 | auto ToBody = importChecked(Err, S->getBody()); |
| 6150 | auto ToForLoc = importChecked(Err, S->getForLoc()); |
| 6151 | auto ToLParenLoc = importChecked(Err, S->getLParenLoc()); |
| 6152 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); |
| 6153 | if (Err) |
| 6154 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6155 | |
| 6156 | return new (Importer.getToContext()) ForStmt( |
| 6157 | Importer.getToContext(), |
| 6158 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, |
| 6159 | ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6160 | } |
| 6161 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6162 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6163 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6164 | Error Err = Error::success(); |
| 6165 | auto ToLabel = importChecked(Err, S->getLabel()); |
| 6166 | auto ToGotoLoc = importChecked(Err, S->getGotoLoc()); |
| 6167 | auto ToLabelLoc = importChecked(Err, S->getLabelLoc()); |
| 6168 | if (Err) |
| 6169 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6170 | |
| 6171 | return new (Importer.getToContext()) GotoStmt( |
| 6172 | ToLabel, ToGotoLoc, ToLabelLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6173 | } |
| 6174 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6175 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6176 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6177 | Error Err = Error::success(); |
| 6178 | auto ToGotoLoc = importChecked(Err, S->getGotoLoc()); |
| 6179 | auto ToStarLoc = importChecked(Err, S->getStarLoc()); |
| 6180 | auto ToTarget = importChecked(Err, S->getTarget()); |
| 6181 | if (Err) |
| 6182 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6183 | |
| 6184 | return new (Importer.getToContext()) IndirectGotoStmt( |
| 6185 | ToGotoLoc, ToStarLoc, ToTarget); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6186 | } |
| 6187 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6188 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 6189 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); |
| 6190 | if (!ToContinueLocOrErr) |
| 6191 | return ToContinueLocOrErr.takeError(); |
| 6192 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6193 | } |
| 6194 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6195 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 6196 | auto ToBreakLocOrErr = import(S->getBreakLoc()); |
| 6197 | if (!ToBreakLocOrErr) |
| 6198 | return ToBreakLocOrErr.takeError(); |
| 6199 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6200 | } |
| 6201 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6202 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6203 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6204 | Error Err = Error::success(); |
| 6205 | auto ToReturnLoc = importChecked(Err, S->getReturnLoc()); |
| 6206 | auto ToRetValue = importChecked(Err, S->getRetValue()); |
| 6207 | auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate()); |
| 6208 | if (Err) |
| 6209 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6210 | |
| Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 6211 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, |
| 6212 | ToNRVOCandidate); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6213 | } |
| 6214 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6215 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6216 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6217 | Error Err = Error::success(); |
| 6218 | auto ToCatchLoc = importChecked(Err, S->getCatchLoc()); |
| 6219 | auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl()); |
| 6220 | auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock()); |
| 6221 | if (Err) |
| 6222 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6223 | |
| 6224 | return new (Importer.getToContext()) CXXCatchStmt ( |
| 6225 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6226 | } |
| 6227 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6228 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 6229 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); |
| 6230 | if (!ToTryLocOrErr) |
| 6231 | return ToTryLocOrErr.takeError(); |
| 6232 | |
| 6233 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); |
| 6234 | if (!ToTryBlockOrErr) |
| 6235 | return ToTryBlockOrErr.takeError(); |
| 6236 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6237 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 6238 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 6239 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6240 | if (auto ToHandlerOrErr = import(FromHandler)) |
| 6241 | ToHandlers[HI] = *ToHandlerOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6242 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6243 | return ToHandlerOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6244 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6245 | |
| 6246 | return CXXTryStmt::Create( |
| 6247 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6248 | } |
| 6249 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6250 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6251 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6252 | Error Err = Error::success(); |
| 6253 | auto ToInit = importChecked(Err, S->getInit()); |
| 6254 | auto ToRangeStmt = importChecked(Err, S->getRangeStmt()); |
| 6255 | auto ToBeginStmt = importChecked(Err, S->getBeginStmt()); |
| 6256 | auto ToEndStmt = importChecked(Err, S->getEndStmt()); |
| 6257 | auto ToCond = importChecked(Err, S->getCond()); |
| 6258 | auto ToInc = importChecked(Err, S->getInc()); |
| 6259 | auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt()); |
| 6260 | auto ToBody = importChecked(Err, S->getBody()); |
| 6261 | auto ToForLoc = importChecked(Err, S->getForLoc()); |
| 6262 | auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc()); |
| 6263 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); |
| 6264 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); |
| 6265 | if (Err) |
| 6266 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6267 | |
| 6268 | return new (Importer.getToContext()) CXXForRangeStmt( |
| 6269 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 6270 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6271 | } |
| 6272 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6273 | ExpectedStmt |
| 6274 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6275 | Error Err = Error::success(); |
| 6276 | auto ToElement = importChecked(Err, S->getElement()); |
| 6277 | auto ToCollection = importChecked(Err, S->getCollection()); |
| 6278 | auto ToBody = importChecked(Err, S->getBody()); |
| 6279 | auto ToForLoc = importChecked(Err, S->getForLoc()); |
| 6280 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); |
| 6281 | if (Err) |
| 6282 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6283 | |
| 6284 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, |
| 6285 | ToCollection, |
| 6286 | ToBody, |
| 6287 | ToForLoc, |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6288 | ToRParenLoc); |
| 6289 | } |
| 6290 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6291 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6292 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6293 | Error Err = Error::success(); |
| 6294 | auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc()); |
| 6295 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); |
| 6296 | auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl()); |
| 6297 | auto ToCatchBody = importChecked(Err, S->getCatchBody()); |
| 6298 | if (Err) |
| 6299 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6300 | |
| 6301 | return new (Importer.getToContext()) ObjCAtCatchStmt ( |
| 6302 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6303 | } |
| 6304 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6305 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 6306 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); |
| 6307 | if (!ToAtFinallyLocOrErr) |
| 6308 | return ToAtFinallyLocOrErr.takeError(); |
| 6309 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); |
| 6310 | if (!ToAtFinallyStmtOrErr) |
| 6311 | return ToAtFinallyStmtOrErr.takeError(); |
| 6312 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, |
| 6313 | *ToAtFinallyStmtOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6314 | } |
| 6315 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6316 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6317 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6318 | Error Err = Error::success(); |
| 6319 | auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc()); |
| 6320 | auto ToTryBody = importChecked(Err, S->getTryBody()); |
| 6321 | auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt()); |
| 6322 | if (Err) |
| 6323 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6324 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6325 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 6326 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 6327 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6328 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) |
| 6329 | ToCatchStmts[CI] = *ToCatchStmtOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6330 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6331 | return ToCatchStmtOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6332 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6333 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6334 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6335 | ToAtTryLoc, ToTryBody, |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6336 | ToCatchStmts.begin(), ToCatchStmts.size(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6337 | ToFinallyStmt); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6338 | } |
| 6339 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6340 | ExpectedStmt |
| 6341 | ASTNodeImporter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6342 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6343 | Error Err = Error::success(); |
| 6344 | auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc()); |
| 6345 | auto ToSynchExpr = importChecked(Err, S->getSynchExpr()); |
| 6346 | auto ToSynchBody = importChecked(Err, S->getSynchBody()); |
| 6347 | if (Err) |
| 6348 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6349 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6350 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 6351 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 6352 | } |
| 6353 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6354 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 6355 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); |
| 6356 | if (!ToThrowLocOrErr) |
| 6357 | return ToThrowLocOrErr.takeError(); |
| 6358 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); |
| 6359 | if (!ToThrowExprOrErr) |
| 6360 | return ToThrowExprOrErr.takeError(); |
| 6361 | return new (Importer.getToContext()) ObjCAtThrowStmt( |
| 6362 | *ToThrowLocOrErr, *ToThrowExprOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6363 | } |
| 6364 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6365 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( |
| 6366 | ObjCAutoreleasePoolStmt *S) { |
| 6367 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); |
| 6368 | if (!ToAtLocOrErr) |
| 6369 | return ToAtLocOrErr.takeError(); |
| 6370 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 6371 | if (!ToSubStmtOrErr) |
| 6372 | return ToSubStmtOrErr.takeError(); |
| 6373 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, |
| 6374 | *ToSubStmtOrErr); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6375 | } |
| 6376 | |
| 6377 | //---------------------------------------------------------------------------- |
| 6378 | // Import Expressions |
| 6379 | //---------------------------------------------------------------------------- |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6380 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6381 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) |
| 6382 | << E->getStmtClassName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6383 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6384 | } |
| 6385 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6386 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6387 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6388 | Error Err = Error::success(); |
| 6389 | auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); |
| 6390 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 6391 | auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo()); |
| 6392 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 6393 | auto ToType = importChecked(Err, E->getType()); |
| 6394 | if (Err) |
| 6395 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6396 | |
| 6397 | return new (Importer.getToContext()) VAArgExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6398 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, |
| 6399 | E->isMicrosoftABI()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6400 | } |
| 6401 | |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6402 | ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) { |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6403 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6404 | Error Err = Error::success(); |
| 6405 | auto ToCond = importChecked(Err, E->getCond()); |
| 6406 | auto ToLHS = importChecked(Err, E->getLHS()); |
| 6407 | auto ToRHS = importChecked(Err, E->getRHS()); |
| 6408 | auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); |
| 6409 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 6410 | auto ToType = importChecked(Err, E->getType()); |
| 6411 | if (Err) |
| 6412 | return std::move(Err); |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6413 | |
| 6414 | ExprValueKind VK = E->getValueKind(); |
| 6415 | ExprObjectKind OK = E->getObjectKind(); |
| 6416 | |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6417 | // The value of CondIsTrue only matters if the value is not |
| 6418 | // condition-dependent. |
| 6419 | bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue(); |
| 6420 | |
| 6421 | return new (Importer.getToContext()) |
| 6422 | ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK, |
| Haojian Wu | 876bb86 | 2020-03-17 08:33:37 +0100 | [diff] [blame] | 6423 | ToRParenLoc, CondIsTrue); |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6424 | } |
| 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 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 6427 | ExpectedType TypeOrErr = import(E->getType()); |
| 6428 | if (!TypeOrErr) |
| 6429 | return TypeOrErr.takeError(); |
| 6430 | |
| 6431 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); |
| 6432 | if (!BeginLocOrErr) |
| 6433 | return BeginLocOrErr.takeError(); |
| 6434 | |
| 6435 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6436 | } |
| 6437 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6438 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6439 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6440 | Error Err = Error::success(); |
| 6441 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 6442 | auto ToType = importChecked(Err, E->getType()); |
| 6443 | auto ToFunctionName = importChecked(Err, E->getFunctionName()); |
| 6444 | if (Err) |
| 6445 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6446 | |
| Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 6447 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, |
| 6448 | E->getIdentKind(), ToFunctionName); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6449 | } |
| 6450 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6451 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6452 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6453 | Error Err = Error::success(); |
| 6454 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 6455 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); |
| 6456 | auto ToDecl = importChecked(Err, E->getDecl()); |
| 6457 | auto ToLocation = importChecked(Err, E->getLocation()); |
| 6458 | auto ToType = importChecked(Err, E->getType()); |
| 6459 | if (Err) |
| 6460 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6461 | |
| 6462 | NamedDecl *ToFoundD = nullptr; |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6463 | if (E->getDecl() != E->getFoundDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6464 | auto FoundDOrErr = import(E->getFoundDecl()); |
| 6465 | if (!FoundDOrErr) |
| 6466 | return FoundDOrErr.takeError(); |
| 6467 | ToFoundD = *FoundDOrErr; |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6468 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6469 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6470 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6471 | TemplateArgumentListInfo *ToResInfo = nullptr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6472 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6473 | if (Error Err = |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 6474 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6475 | E->template_arguments(), ToTAInfo)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6476 | return std::move(Err); |
| 6477 | ToResInfo = &ToTAInfo; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6478 | } |
| 6479 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6480 | auto *ToE = DeclRefExpr::Create( |
| 6481 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, |
| 6482 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, |
| Richard Smith | 715f7a1 | 2019-06-11 17:50:32 +0000 | [diff] [blame] | 6483 | E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse()); |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 6484 | if (E->hadMultipleCandidates()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6485 | ToE->setHadMultipleCandidates(true); |
| 6486 | return ToE; |
| Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 6487 | } |
| 6488 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6489 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 6490 | ExpectedType TypeOrErr = import(E->getType()); |
| 6491 | if (!TypeOrErr) |
| 6492 | return TypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6493 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6494 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6495 | } |
| 6496 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6497 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 6498 | ExpectedExpr ToInitOrErr = import(E->getInit()); |
| 6499 | if (!ToInitOrErr) |
| 6500 | return ToInitOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6501 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6502 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); |
| 6503 | if (!ToEqualOrColonLocOrErr) |
| 6504 | return ToEqualOrColonLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6505 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6506 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6507 | // List elements from the second, the first is Init itself |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6508 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { |
| 6509 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) |
| 6510 | ToIndexExprs[I - 1] = *ToArgOrErr; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6511 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6512 | return ToArgOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6513 | } |
| 6514 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6515 | SmallVector<Designator, 4> ToDesignators(E->size()); |
| 6516 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) |
| 6517 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6518 | |
| 6519 | return DesignatedInitExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6520 | Importer.getToContext(), ToDesignators, |
| 6521 | ToIndexExprs, *ToEqualOrColonLocOrErr, |
| 6522 | E->usesGNUSyntax(), *ToInitOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6523 | } |
| 6524 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6525 | ExpectedStmt |
| 6526 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 6527 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6528 | if (!ToTypeOrErr) |
| 6529 | return ToTypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6530 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6531 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6532 | if (!ToLocationOrErr) |
| 6533 | return ToLocationOrErr.takeError(); |
| 6534 | |
| 6535 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( |
| 6536 | *ToTypeOrErr, *ToLocationOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6537 | } |
| 6538 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6539 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 6540 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6541 | if (!ToTypeOrErr) |
| 6542 | return ToTypeOrErr.takeError(); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6543 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6544 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6545 | if (!ToLocationOrErr) |
| 6546 | return ToLocationOrErr.takeError(); |
| 6547 | |
| 6548 | return IntegerLiteral::Create( |
| 6549 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6550 | } |
| 6551 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6552 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6553 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 6554 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6555 | if (!ToTypeOrErr) |
| 6556 | return ToTypeOrErr.takeError(); |
| 6557 | |
| 6558 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6559 | if (!ToLocationOrErr) |
| 6560 | return ToLocationOrErr.takeError(); |
| 6561 | |
| 6562 | return FloatingLiteral::Create( |
| 6563 | Importer.getToContext(), E->getValue(), E->isExact(), |
| 6564 | *ToTypeOrErr, *ToLocationOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6565 | } |
| 6566 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6567 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 6568 | auto ToTypeOrErr = import(E->getType()); |
| 6569 | if (!ToTypeOrErr) |
| 6570 | return ToTypeOrErr.takeError(); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6571 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6572 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6573 | if (!ToSubExprOrErr) |
| 6574 | return ToSubExprOrErr.takeError(); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6575 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6576 | return new (Importer.getToContext()) ImaginaryLiteral( |
| 6577 | *ToSubExprOrErr, *ToTypeOrErr); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6578 | } |
| 6579 | |
| Vince Bridgers | 789215d | 2020-04-06 08:22:35 -0500 | [diff] [blame] | 6580 | ExpectedStmt ASTNodeImporter::VisitFixedPointLiteral(FixedPointLiteral *E) { |
| 6581 | auto ToTypeOrErr = import(E->getType()); |
| 6582 | if (!ToTypeOrErr) |
| 6583 | return ToTypeOrErr.takeError(); |
| 6584 | |
| 6585 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6586 | if (!ToLocationOrErr) |
| 6587 | return ToLocationOrErr.takeError(); |
| 6588 | |
| 6589 | return new (Importer.getToContext()) FixedPointLiteral( |
| 6590 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr, |
| 6591 | Importer.getToContext().getFixedPointScale(*ToTypeOrErr)); |
| 6592 | } |
| 6593 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6594 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 6595 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6596 | if (!ToTypeOrErr) |
| 6597 | return ToTypeOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6598 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6599 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6600 | if (!ToLocationOrErr) |
| 6601 | return ToLocationOrErr.takeError(); |
| 6602 | |
| 6603 | return new (Importer.getToContext()) CharacterLiteral( |
| 6604 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); |
| Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 6605 | } |
| 6606 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6607 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 6608 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6609 | if (!ToTypeOrErr) |
| 6610 | return ToTypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6611 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6612 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); |
| 6613 | if (Error Err = ImportArrayChecked( |
| 6614 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) |
| 6615 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6616 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6617 | return StringLiteral::Create( |
| 6618 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), |
| 6619 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6620 | } |
| 6621 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6622 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6623 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6624 | Error Err = Error::success(); |
| 6625 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); |
| 6626 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); |
| 6627 | auto ToType = importChecked(Err, E->getType()); |
| 6628 | auto ToInitializer = importChecked(Err, E->getInitializer()); |
| 6629 | if (Err) |
| 6630 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6631 | |
| 6632 | return new (Importer.getToContext()) CompoundLiteralExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6633 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), |
| 6634 | ToInitializer, E->isFileScope()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6635 | } |
| 6636 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6637 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6638 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6639 | Error Err = Error::success(); |
| 6640 | auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); |
| 6641 | auto ToType = importChecked(Err, E->getType()); |
| 6642 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 6643 | if (Err) |
| 6644 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6645 | |
| 6646 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); |
| 6647 | if (Error Err = ImportArrayChecked( |
| 6648 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 6649 | ToExprs.begin())) |
| 6650 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6651 | |
| 6652 | return new (Importer.getToContext()) AtomicExpr( |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6653 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6654 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6655 | } |
| 6656 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6657 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6658 | Error Err = Error::success(); |
| 6659 | auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc()); |
| 6660 | auto ToLabelLoc = importChecked(Err, E->getLabelLoc()); |
| 6661 | auto ToLabel = importChecked(Err, E->getLabel()); |
| 6662 | auto ToType = importChecked(Err, E->getType()); |
| 6663 | if (Err) |
| 6664 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6665 | |
| 6666 | return new (Importer.getToContext()) AddrLabelExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6667 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6668 | } |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6669 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6670 | Error Err = Error::success(); |
| 6671 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 6672 | if (Err) |
| 6673 | return std::move(Err); |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6674 | |
| Gauthier Harnisch | 83c7b61 | 2019-06-15 10:24:47 +0000 | [diff] [blame] | 6675 | // TODO : Handle APValue::ValueKind that require importing. |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6676 | |
| Gauthier Harnisch | 83c7b61 | 2019-06-15 10:24:47 +0000 | [diff] [blame] | 6677 | APValue::ValueKind Kind = E->getResultAPValueKind(); |
| 6678 | if (Kind == APValue::Int || Kind == APValue::Float || |
| 6679 | Kind == APValue::FixedPoint || Kind == APValue::ComplexFloat || |
| 6680 | Kind == APValue::ComplexInt) |
| 6681 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, |
| 6682 | E->getAPValueResult()); |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 6683 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr); |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6684 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6685 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6686 | Error Err = Error::success(); |
| 6687 | auto ToLParen = importChecked(Err, E->getLParen()); |
| 6688 | auto ToRParen = importChecked(Err, E->getRParen()); |
| 6689 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 6690 | if (Err) |
| 6691 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6692 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6693 | return new (Importer.getToContext()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6694 | ParenExpr(ToLParen, ToRParen, ToSubExpr); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6695 | } |
| 6696 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6697 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 6698 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); |
| 6699 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) |
| 6700 | return std::move(Err); |
| 6701 | |
| 6702 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); |
| 6703 | if (!ToLParenLocOrErr) |
| 6704 | return ToLParenLocOrErr.takeError(); |
| 6705 | |
| 6706 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); |
| 6707 | if (!ToRParenLocOrErr) |
| 6708 | return ToRParenLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6709 | |
| Bruno Ricci | f49e1ca | 2018-11-20 16:20:40 +0000 | [diff] [blame] | 6710 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, |
| 6711 | ToExprs, *ToRParenLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6712 | } |
| 6713 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6714 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6715 | Error Err = Error::success(); |
| 6716 | auto ToSubStmt = importChecked(Err, E->getSubStmt()); |
| 6717 | auto ToType = importChecked(Err, E->getType()); |
| 6718 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); |
| 6719 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 6720 | if (Err) |
| 6721 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6722 | |
| Richard Smith | 5c845c1 | 2020-03-09 17:34:33 -0700 | [diff] [blame] | 6723 | return new (Importer.getToContext()) |
| 6724 | StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc, |
| 6725 | E->getTemplateDepth()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6726 | } |
| 6727 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6728 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6729 | Error Err = Error::success(); |
| 6730 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 6731 | auto ToType = importChecked(Err, E->getType()); |
| 6732 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 6733 | if (Err) |
| 6734 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6735 | |
| Melanie Blower | f5360d4 | 2020-05-01 10:32:06 -0700 | [diff] [blame] | 6736 | return UnaryOperator::Create( |
| 6737 | Importer.getToContext(), ToSubExpr, E->getOpcode(), ToType, |
| 6738 | E->getValueKind(), E->getObjectKind(), ToOperatorLoc, E->canOverflow(), |
| Melanie Blower | f4aaed3 | 2020-06-26 09:23:45 -0700 | [diff] [blame] | 6739 | E->getFPOptionsOverride()); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6740 | } |
| 6741 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6742 | ExpectedStmt |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6743 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6744 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
| 6745 | Error Err = Error::success(); |
| 6746 | auto ToType = importChecked(Err, E->getType()); |
| 6747 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 6748 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 6749 | if (Err) |
| 6750 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6751 | |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6752 | if (E->isArgumentType()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6753 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = |
| 6754 | import(E->getArgumentTypeInfo()); |
| 6755 | if (!ToArgumentTypeInfoOrErr) |
| 6756 | return ToArgumentTypeInfoOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6757 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6758 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6759 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, |
| 6760 | ToRParenLoc); |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6761 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6762 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6763 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); |
| 6764 | if (!ToArgumentExprOrErr) |
| 6765 | return ToArgumentExprOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6766 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6767 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6768 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6769 | } |
| 6770 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6771 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6772 | Error Err = Error::success(); |
| 6773 | auto ToLHS = importChecked(Err, E->getLHS()); |
| 6774 | auto ToRHS = importChecked(Err, E->getRHS()); |
| 6775 | auto ToType = importChecked(Err, E->getType()); |
| 6776 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 6777 | if (Err) |
| 6778 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6779 | |
| Benjamin Kramer | 3ee1ec0 | 2020-04-16 11:45:02 +0200 | [diff] [blame] | 6780 | return BinaryOperator::Create( |
| 6781 | Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType, |
| 6782 | E->getValueKind(), E->getObjectKind(), ToOperatorLoc, |
| 6783 | E->getFPFeatures(Importer.getFromContext().getLangOpts())); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6784 | } |
| 6785 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6786 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6787 | Error Err = Error::success(); |
| 6788 | auto ToCond = importChecked(Err, E->getCond()); |
| 6789 | auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc()); |
| 6790 | auto ToLHS = importChecked(Err, E->getLHS()); |
| 6791 | auto ToColonLoc = importChecked(Err, E->getColonLoc()); |
| 6792 | auto ToRHS = importChecked(Err, E->getRHS()); |
| 6793 | auto ToType = importChecked(Err, E->getType()); |
| 6794 | if (Err) |
| 6795 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6796 | |
| 6797 | return new (Importer.getToContext()) ConditionalOperator( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6798 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, |
| 6799 | E->getValueKind(), E->getObjectKind()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6800 | } |
| 6801 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6802 | ExpectedStmt |
| 6803 | ASTNodeImporter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) { |
| 6804 | Error Err = Error::success(); |
| 6805 | auto ToCommon = importChecked(Err, E->getCommon()); |
| 6806 | auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue()); |
| 6807 | auto ToCond = importChecked(Err, E->getCond()); |
| 6808 | auto ToTrueExpr = importChecked(Err, E->getTrueExpr()); |
| 6809 | auto ToFalseExpr = importChecked(Err, E->getFalseExpr()); |
| 6810 | auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc()); |
| 6811 | auto ToColonLoc = importChecked(Err, E->getColonLoc()); |
| 6812 | auto ToType = importChecked(Err, E->getType()); |
| 6813 | if (Err) |
| 6814 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6815 | |
| 6816 | return new (Importer.getToContext()) BinaryConditionalOperator( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6817 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, |
| 6818 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), |
| 6819 | E->getObjectKind()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6820 | } |
| 6821 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6822 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6823 | Error Err = Error::success(); |
| 6824 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 6825 | auto ToQueriedTypeSourceInfo = |
| 6826 | importChecked(Err, E->getQueriedTypeSourceInfo()); |
| 6827 | auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression()); |
| 6828 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); |
| 6829 | auto ToType = importChecked(Err, E->getType()); |
| 6830 | if (Err) |
| 6831 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6832 | |
| 6833 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6834 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), |
| 6835 | ToDimensionExpression, ToEndLoc, ToType); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6836 | } |
| 6837 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6838 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6839 | Error Err = Error::success(); |
| 6840 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 6841 | auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression()); |
| 6842 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); |
| 6843 | auto ToType = importChecked(Err, E->getType()); |
| 6844 | if (Err) |
| 6845 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6846 | |
| 6847 | return new (Importer.getToContext()) ExpressionTraitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6848 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), |
| 6849 | ToEndLoc, ToType); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6850 | } |
| 6851 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6852 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6853 | Error Err = Error::success(); |
| 6854 | auto ToLocation = importChecked(Err, E->getLocation()); |
| 6855 | auto ToType = importChecked(Err, E->getType()); |
| 6856 | auto ToSourceExpr = importChecked(Err, E->getSourceExpr()); |
| 6857 | if (Err) |
| 6858 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6859 | |
| 6860 | return new (Importer.getToContext()) OpaqueValueExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6861 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6862 | } |
| 6863 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6864 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6865 | Error Err = Error::success(); |
| 6866 | auto ToLHS = importChecked(Err, E->getLHS()); |
| 6867 | auto ToRHS = importChecked(Err, E->getRHS()); |
| 6868 | auto ToType = importChecked(Err, E->getType()); |
| 6869 | auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc()); |
| 6870 | if (Err) |
| 6871 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6872 | |
| 6873 | return new (Importer.getToContext()) ArraySubscriptExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6874 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), |
| 6875 | ToRBracketLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6876 | } |
| 6877 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6878 | ExpectedStmt |
| 6879 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6880 | Error Err = Error::success(); |
| 6881 | auto ToLHS = importChecked(Err, E->getLHS()); |
| 6882 | auto ToRHS = importChecked(Err, E->getRHS()); |
| 6883 | auto ToType = importChecked(Err, E->getType()); |
| 6884 | auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType()); |
| 6885 | auto ToComputationResultType = |
| 6886 | importChecked(Err, E->getComputationResultType()); |
| 6887 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 6888 | if (Err) |
| 6889 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6890 | |
| Melanie Blower | 2ba4e3a | 2020-04-10 13:34:46 -0700 | [diff] [blame] | 6891 | return CompoundAssignOperator::Create( |
| 6892 | Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType, |
| 6893 | E->getValueKind(), E->getObjectKind(), ToOperatorLoc, |
| Benjamin Kramer | 3ee1ec0 | 2020-04-16 11:45:02 +0200 | [diff] [blame] | 6894 | E->getFPFeatures(Importer.getFromContext().getLangOpts()), |
| Gabor Marton | e033ec2 | 2020-04-16 15:48:13 +0200 | [diff] [blame] | 6895 | ToComputationLHSType, ToComputationResultType); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6896 | } |
| 6897 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6898 | Expected<CXXCastPath> |
| 6899 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { |
| 6900 | CXXCastPath Path; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6901 | 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] | 6902 | if (auto SpecOrErr = import(*I)) |
| 6903 | Path.push_back(*SpecOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6904 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6905 | return SpecOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6906 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6907 | return Path; |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6908 | } |
| 6909 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6910 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 6911 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6912 | if (!ToTypeOrErr) |
| 6913 | return ToTypeOrErr.takeError(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6914 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6915 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6916 | if (!ToSubExprOrErr) |
| 6917 | return ToSubExprOrErr.takeError(); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6918 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6919 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6920 | if (!ToBasePathOrErr) |
| 6921 | return ToBasePathOrErr.takeError(); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6922 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6923 | return ImplicitCastExpr::Create( |
| 6924 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, |
| 6925 | &(*ToBasePathOrErr), E->getValueKind()); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6926 | } |
| 6927 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6928 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6929 | Error Err = Error::success(); |
| 6930 | auto ToType = importChecked(Err, E->getType()); |
| 6931 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 6932 | auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten()); |
| 6933 | if (Err) |
| 6934 | return std::move(Err); |
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6935 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6936 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6937 | if (!ToBasePathOrErr) |
| 6938 | return ToBasePathOrErr.takeError(); |
| 6939 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6940 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6941 | switch (E->getStmtClass()) { |
| 6942 | case Stmt::CStyleCastExprClass: { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6943 | auto *CCE = cast<CStyleCastExpr>(E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6944 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); |
| 6945 | if (!ToLParenLocOrErr) |
| 6946 | return ToLParenLocOrErr.takeError(); |
| 6947 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); |
| 6948 | if (!ToRParenLocOrErr) |
| 6949 | return ToRParenLocOrErr.takeError(); |
| 6950 | return CStyleCastExpr::Create( |
| 6951 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), |
| 6952 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, |
| 6953 | *ToRParenLocOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6954 | } |
| 6955 | |
| 6956 | case Stmt::CXXFunctionalCastExprClass: { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6957 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6958 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); |
| 6959 | if (!ToLParenLocOrErr) |
| 6960 | return ToLParenLocOrErr.takeError(); |
| 6961 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); |
| 6962 | if (!ToRParenLocOrErr) |
| 6963 | return ToRParenLocOrErr.takeError(); |
| 6964 | return CXXFunctionalCastExpr::Create( |
| 6965 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, |
| 6966 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, |
| 6967 | *ToRParenLocOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6968 | } |
| 6969 | |
| 6970 | case Stmt::ObjCBridgedCastExprClass: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6971 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
| 6972 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); |
| 6973 | if (!ToLParenLocOrErr) |
| 6974 | return ToLParenLocOrErr.takeError(); |
| 6975 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); |
| 6976 | if (!ToBridgeKeywordLocOrErr) |
| 6977 | return ToBridgeKeywordLocOrErr.takeError(); |
| 6978 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 6979 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), |
| 6980 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6981 | } |
| 6982 | default: |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6983 | llvm_unreachable("Cast expression of unsupported type!"); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6984 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6985 | } |
| 6986 | } |
| 6987 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6988 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { |
| 6989 | SmallVector<OffsetOfNode, 4> ToNodes; |
| 6990 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { |
| 6991 | const OffsetOfNode &FromNode = E->getComponent(I); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6992 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6993 | SourceLocation ToBeginLoc, ToEndLoc; |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6994 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6995 | if (FromNode.getKind() != OffsetOfNode::Base) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6996 | Error Err = Error::success(); |
| 6997 | ToBeginLoc = importChecked(Err, FromNode.getBeginLoc()); |
| 6998 | ToEndLoc = importChecked(Err, FromNode.getEndLoc()); |
| 6999 | if (Err) |
| 7000 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7001 | } |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7002 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7003 | switch (FromNode.getKind()) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7004 | case OffsetOfNode::Array: |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7005 | ToNodes.push_back( |
| 7006 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7007 | break; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7008 | case OffsetOfNode::Base: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7009 | auto ToBSOrErr = import(FromNode.getBase()); |
| 7010 | if (!ToBSOrErr) |
| 7011 | return ToBSOrErr.takeError(); |
| 7012 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7013 | break; |
| 7014 | } |
| 7015 | case OffsetOfNode::Field: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7016 | auto ToFieldOrErr = import(FromNode.getField()); |
| 7017 | if (!ToFieldOrErr) |
| 7018 | return ToFieldOrErr.takeError(); |
| 7019 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7020 | break; |
| 7021 | } |
| 7022 | case OffsetOfNode::Identifier: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7023 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); |
| 7024 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7025 | break; |
| 7026 | } |
| 7027 | } |
| 7028 | } |
| 7029 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7030 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); |
| 7031 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { |
| 7032 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); |
| 7033 | if (!ToIndexExprOrErr) |
| 7034 | return ToIndexExprOrErr.takeError(); |
| 7035 | ToExprs[I] = *ToIndexExprOrErr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7036 | } |
| 7037 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7038 | Error Err = Error::success(); |
| 7039 | auto ToType = importChecked(Err, E->getType()); |
| 7040 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); |
| 7041 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7042 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7043 | if (Err) |
| 7044 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7045 | |
| 7046 | return OffsetOfExpr::Create( |
| 7047 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, |
| 7048 | ToExprs, ToRParenLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7049 | } |
| 7050 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7051 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7052 | Error Err = Error::success(); |
| 7053 | auto ToType = importChecked(Err, E->getType()); |
| 7054 | auto ToOperand = importChecked(Err, E->getOperand()); |
| 7055 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 7056 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); |
| 7057 | if (Err) |
| 7058 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7059 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7060 | CanThrowResult ToCanThrow; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7061 | if (E->isValueDependent()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7062 | ToCanThrow = CT_Dependent; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7063 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7064 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7065 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7066 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 7067 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7068 | } |
| 7069 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7070 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7071 | Error Err = Error::success(); |
| 7072 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 7073 | auto ToType = importChecked(Err, E->getType()); |
| 7074 | auto ToThrowLoc = importChecked(Err, E->getThrowLoc()); |
| 7075 | if (Err) |
| 7076 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7077 | |
| 7078 | return new (Importer.getToContext()) CXXThrowExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7079 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7080 | } |
| 7081 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7082 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 7083 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); |
| 7084 | if (!ToUsedLocOrErr) |
| 7085 | return ToUsedLocOrErr.takeError(); |
| 7086 | |
| 7087 | auto ToParamOrErr = import(E->getParam()); |
| 7088 | if (!ToParamOrErr) |
| 7089 | return ToParamOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7090 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7091 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); |
| 7092 | if (!UsedContextOrErr) |
| 7093 | return UsedContextOrErr.takeError(); |
| 7094 | |
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 7095 | // Import the default arg if it was not imported yet. |
| 7096 | // This is needed because it can happen that during the import of the |
| 7097 | // default expression (from VisitParmVarDecl) the same ParmVarDecl is |
| 7098 | // encountered here. The default argument for a ParmVarDecl is set in the |
| 7099 | // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here, |
| 7100 | // see VisitParmVarDecl). |
| 7101 | ParmVarDecl *ToParam = *ToParamOrErr; |
| 7102 | if (!ToParam->getDefaultArg()) { |
| 7103 | Optional<ParmVarDecl *> FromParam = Importer.getImportedFromDecl(ToParam); |
| 7104 | assert(FromParam && "ParmVarDecl was not imported?"); |
| 7105 | |
| 7106 | if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam)) |
| 7107 | return std::move(Err); |
| 7108 | } |
| 7109 | |
| 7110 | return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr, |
| 7111 | *ToParamOrErr, *UsedContextOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7112 | } |
| 7113 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7114 | ExpectedStmt |
| 7115 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7116 | Error Err = Error::success(); |
| 7117 | auto ToType = importChecked(Err, E->getType()); |
| 7118 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); |
| 7119 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7120 | if (Err) |
| 7121 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7122 | |
| 7123 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7124 | ToType, ToTypeSourceInfo, ToRParenLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7125 | } |
| 7126 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7127 | ExpectedStmt |
| 7128 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 7129 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7130 | if (!ToSubExprOrErr) |
| 7131 | return ToSubExprOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7132 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7133 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); |
| 7134 | if (!ToDtorOrErr) |
| 7135 | return ToDtorOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7136 | |
| 7137 | ASTContext &ToCtx = Importer.getToContext(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7138 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); |
| 7139 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7140 | } |
| 7141 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7142 | ExpectedStmt |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7143 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7144 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { |
| 7145 | Error Err = Error::success(); |
| 7146 | auto ToConstructor = importChecked(Err, E->getConstructor()); |
| 7147 | auto ToType = importChecked(Err, E->getType()); |
| 7148 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); |
| 7149 | auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange()); |
| 7150 | if (Err) |
| 7151 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7152 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7153 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); |
| 7154 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7155 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7156 | |
| Bruno Ricci | ddb8f6b | 2018-12-22 14:39:30 +0000 | [diff] [blame] | 7157 | return CXXTemporaryObjectExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7158 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, |
| 7159 | ToParenOrBraceRange, E->hadMultipleCandidates(), |
| 7160 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 7161 | E->requiresZeroInitialization()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7162 | } |
| 7163 | |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7164 | ExpectedDecl ASTNodeImporter::VisitLifetimeExtendedTemporaryDecl( |
| 7165 | LifetimeExtendedTemporaryDecl *D) { |
| 7166 | DeclContext *DC, *LexicalDC; |
| 7167 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 7168 | return std::move(Err); |
| 7169 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7170 | Error Err = Error::success(); |
| 7171 | auto Temporary = importChecked(Err, D->getTemporaryExpr()); |
| 7172 | auto ExtendingDecl = importChecked(Err, D->getExtendingDecl()); |
| 7173 | if (Err) |
| 7174 | return std::move(Err); |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7175 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
| 7176 | |
| 7177 | LifetimeExtendedTemporaryDecl *To; |
| 7178 | if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl, |
| 7179 | D->getManglingNumber())) |
| 7180 | return To; |
| 7181 | |
| 7182 | To->setLexicalDeclContext(LexicalDC); |
| 7183 | LexicalDC->addDeclInternal(To); |
| 7184 | return To; |
| 7185 | } |
| 7186 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7187 | ExpectedStmt |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7188 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7189 | Error Err = Error::success(); |
| 7190 | auto ToType = importChecked(Err, E->getType()); |
| 7191 | Expr *ToTemporaryExpr = importChecked( |
| 7192 | Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr()); |
| 7193 | auto ToMaterializedDecl = |
| 7194 | importChecked(Err, E->getLifetimeExtendedTemporaryDecl()); |
| 7195 | if (Err) |
| 7196 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7197 | |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7198 | if (!ToTemporaryExpr) |
| 7199 | ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7200 | |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7201 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
| 7202 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference(), |
| 7203 | ToMaterializedDecl); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7204 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7205 | return ToMTE; |
| 7206 | } |
| 7207 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7208 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7209 | Error Err = Error::success(); |
| 7210 | auto ToType = importChecked(Err, E->getType()); |
| 7211 | auto ToPattern = importChecked(Err, E->getPattern()); |
| 7212 | auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc()); |
| 7213 | if (Err) |
| 7214 | return std::move(Err); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7215 | |
| 7216 | return new (Importer.getToContext()) PackExpansionExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7217 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7218 | } |
| 7219 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7220 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7221 | Error Err = Error::success(); |
| 7222 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7223 | auto ToPack = importChecked(Err, E->getPack()); |
| 7224 | auto ToPackLoc = importChecked(Err, E->getPackLoc()); |
| 7225 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7226 | if (Err) |
| 7227 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7228 | |
| 7229 | Optional<unsigned> Length; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7230 | if (!E->isValueDependent()) |
| 7231 | Length = E->getPackLength(); |
| 7232 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7233 | SmallVector<TemplateArgument, 8> ToPartialArguments; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7234 | if (E->isPartiallySubstituted()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7235 | if (Error Err = ImportTemplateArguments( |
| 7236 | E->getPartialArguments().data(), |
| 7237 | E->getPartialArguments().size(), |
| 7238 | ToPartialArguments)) |
| 7239 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7240 | } |
| 7241 | |
| 7242 | return SizeOfPackExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7243 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, |
| 7244 | Length, ToPartialArguments); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7245 | } |
| 7246 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7247 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7248 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7249 | Error Err = Error::success(); |
| 7250 | auto ToOperatorNew = importChecked(Err, E->getOperatorNew()); |
| 7251 | auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete()); |
| 7252 | auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens()); |
| 7253 | auto ToArraySize = importChecked(Err, E->getArraySize()); |
| 7254 | auto ToInitializer = importChecked(Err, E->getInitializer()); |
| 7255 | auto ToType = importChecked(Err, E->getType()); |
| 7256 | auto ToAllocatedTypeSourceInfo = |
| 7257 | importChecked(Err, E->getAllocatedTypeSourceInfo()); |
| 7258 | auto ToSourceRange = importChecked(Err, E->getSourceRange()); |
| 7259 | auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange()); |
| 7260 | if (Err) |
| 7261 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7262 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7263 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); |
| 7264 | if (Error Err = |
| 7265 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) |
| 7266 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7267 | |
| Bruno Ricci | 9b6dfac | 2019-01-07 15:04:45 +0000 | [diff] [blame] | 7268 | return CXXNewExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7269 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, |
| 7270 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), |
| 7271 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), |
| 7272 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, |
| 7273 | ToDirectInitRange); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7274 | } |
| 7275 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7276 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7277 | Error Err = Error::success(); |
| 7278 | auto ToType = importChecked(Err, E->getType()); |
| 7279 | auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete()); |
| 7280 | auto ToArgument = importChecked(Err, E->getArgument()); |
| 7281 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 7282 | if (Err) |
| 7283 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7284 | |
| 7285 | return new (Importer.getToContext()) CXXDeleteExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7286 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), |
| 7287 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, |
| 7288 | ToBeginLoc); |
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 7289 | } |
| 7290 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7291 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7292 | Error Err = Error::success(); |
| 7293 | auto ToType = importChecked(Err, E->getType()); |
| 7294 | auto ToLocation = importChecked(Err, E->getLocation()); |
| 7295 | auto ToConstructor = importChecked(Err, E->getConstructor()); |
| 7296 | auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange()); |
| 7297 | if (Err) |
| 7298 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7299 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7300 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7301 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7302 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7303 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7304 | return CXXConstructExpr::Create( |
| 7305 | Importer.getToContext(), ToType, ToLocation, ToConstructor, |
| 7306 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), |
| 7307 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 7308 | E->requiresZeroInitialization(), E->getConstructionKind(), |
| 7309 | ToParenOrBraceRange); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7310 | } |
| 7311 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7312 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { |
| 7313 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7314 | if (!ToSubExprOrErr) |
| 7315 | return ToSubExprOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7316 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7317 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); |
| 7318 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) |
| 7319 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7320 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7321 | return ExprWithCleanups::Create( |
| 7322 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), |
| 7323 | ToObjects); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7324 | } |
| 7325 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7326 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7327 | Error Err = Error::success(); |
| 7328 | auto ToCallee = importChecked(Err, E->getCallee()); |
| 7329 | auto ToType = importChecked(Err, E->getType()); |
| 7330 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7331 | if (Err) |
| 7332 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7333 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7334 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7335 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7336 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7337 | |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7338 | return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, |
| 7339 | ToType, E->getValueKind(), ToRParenLoc); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7340 | } |
| 7341 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7342 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 7343 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7344 | if (!ToTypeOrErr) |
| 7345 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7346 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7347 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7348 | if (!ToLocationOrErr) |
| 7349 | return ToLocationOrErr.takeError(); |
| 7350 | |
| 7351 | return new (Importer.getToContext()) CXXThisExpr( |
| 7352 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7353 | } |
| 7354 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7355 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 7356 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7357 | if (!ToTypeOrErr) |
| 7358 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7359 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7360 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7361 | if (!ToLocationOrErr) |
| 7362 | return ToLocationOrErr.takeError(); |
| 7363 | |
| 7364 | return new (Importer.getToContext()) CXXBoolLiteralExpr( |
| 7365 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7366 | } |
| 7367 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7368 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7369 | Error Err = Error::success(); |
| 7370 | auto ToBase = importChecked(Err, E->getBase()); |
| 7371 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7372 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 7373 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); |
| 7374 | auto ToMemberDecl = importChecked(Err, E->getMemberDecl()); |
| 7375 | auto ToType = importChecked(Err, E->getType()); |
| 7376 | auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl()); |
| 7377 | auto ToName = importChecked(Err, E->getMemberNameInfo().getName()); |
| 7378 | auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc()); |
| 7379 | if (Err) |
| 7380 | return std::move(Err); |
| Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 7381 | |
| 7382 | DeclAccessPair ToFoundDecl = |
| 7383 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7384 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7385 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7386 | |
| Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7387 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7388 | if (E->hasExplicitTemplateArgs()) { |
| Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7389 | if (Error Err = |
| 7390 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 7391 | E->template_arguments(), ToTAInfo)) |
| 7392 | return std::move(Err); |
| 7393 | ResInfo = &ToTAInfo; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7394 | } |
| 7395 | |
| Richard Smith | 1bbad59 | 2019-06-11 17:50:36 +0000 | [diff] [blame] | 7396 | return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(), |
| 7397 | ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7398 | ToMemberDecl, ToFoundDecl, ToMemberNameInfo, |
| 7399 | ResInfo, ToType, E->getValueKind(), |
| 7400 | E->getObjectKind(), E->isNonOdrUse()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7401 | } |
| 7402 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7403 | ExpectedStmt |
| 7404 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7405 | Error Err = Error::success(); |
| 7406 | auto ToBase = importChecked(Err, E->getBase()); |
| 7407 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7408 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 7409 | auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo()); |
| 7410 | auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc()); |
| 7411 | auto ToTildeLoc = importChecked(Err, E->getTildeLoc()); |
| 7412 | if (Err) |
| 7413 | return std::move(Err); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7414 | |
| 7415 | PseudoDestructorTypeStorage Storage; |
| 7416 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 7417 | IdentifierInfo *ToII = Importer.Import(FromII); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7418 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); |
| 7419 | if (!ToDestroyedTypeLocOrErr) |
| 7420 | return ToDestroyedTypeLocOrErr.takeError(); |
| 7421 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7422 | } else { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7423 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) |
| 7424 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); |
| 7425 | else |
| 7426 | return ToTIOrErr.takeError(); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7427 | } |
| 7428 | |
| 7429 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7430 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7431 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7432 | } |
| 7433 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7434 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7435 | CXXDependentScopeMemberExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7436 | Error Err = Error::success(); |
| 7437 | auto ToType = importChecked(Err, E->getType()); |
| 7438 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7439 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 7440 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); |
| 7441 | auto ToFirstQualifierFoundInScope = |
| 7442 | importChecked(Err, E->getFirstQualifierFoundInScope()); |
| 7443 | if (Err) |
| 7444 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7445 | |
| 7446 | Expr *ToBase = nullptr; |
| 7447 | if (!E->isImplicitAccess()) { |
| 7448 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7449 | ToBase = *ToBaseOrErr; |
| 7450 | else |
| 7451 | return ToBaseOrErr.takeError(); |
| 7452 | } |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7453 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7454 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7455 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7456 | if (E->hasExplicitTemplateArgs()) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7457 | if (Error Err = |
| 7458 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 7459 | E->template_arguments(), ToTAInfo)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7460 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7461 | ResInfo = &ToTAInfo; |
| 7462 | } |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7463 | auto ToMember = importChecked(Err, E->getMember()); |
| 7464 | auto ToMemberLoc = importChecked(Err, E->getMemberLoc()); |
| 7465 | if (Err) |
| 7466 | return std::move(Err); |
| 7467 | DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7468 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7469 | // Import additional name location/type info. |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7470 | if (Error Err = |
| 7471 | ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7472 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7473 | |
| 7474 | return CXXDependentScopeMemberExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7475 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, |
| 7476 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, |
| 7477 | ToMemberNameInfo, ResInfo); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7478 | } |
| 7479 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7480 | ExpectedStmt |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7481 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7482 | Error Err = Error::success(); |
| 7483 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 7484 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); |
| 7485 | auto ToDeclName = importChecked(Err, E->getDeclName()); |
| 7486 | auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc()); |
| 7487 | auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc()); |
| 7488 | auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc()); |
| 7489 | if (Err) |
| 7490 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7491 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7492 | DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7493 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7494 | return std::move(Err); |
| 7495 | |
| 7496 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7497 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7498 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7499 | if (Error Err = |
| 7500 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7501 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7502 | ResInfo = &ToTAInfo; |
| 7503 | } |
| 7504 | |
| 7505 | return DependentScopeDeclRefExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7506 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, |
| 7507 | ToNameInfo, ResInfo); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7508 | } |
| 7509 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7510 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 7511 | CXXUnresolvedConstructExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7512 | Error Err = Error::success(); |
| 7513 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); |
| 7514 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7515 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); |
| 7516 | if (Err) |
| 7517 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7518 | |
| 7519 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); |
| 7520 | if (Error Err = |
| 7521 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) |
| 7522 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7523 | |
| 7524 | return CXXUnresolvedConstructExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7525 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, |
| 7526 | llvm::makeArrayRef(ToArgs), ToRParenLoc); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7527 | } |
| 7528 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7529 | ExpectedStmt |
| 7530 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
| 7531 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); |
| 7532 | if (!ToNamingClassOrErr) |
| 7533 | return ToNamingClassOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7534 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7535 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); |
| 7536 | if (!ToQualifierLocOrErr) |
| 7537 | return ToQualifierLocOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7538 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7539 | Error Err = Error::success(); |
| 7540 | auto ToName = importChecked(Err, E->getName()); |
| 7541 | auto ToNameLoc = importChecked(Err, E->getNameLoc()); |
| 7542 | if (Err) |
| 7543 | return std::move(Err); |
| 7544 | DeclarationNameInfo ToNameInfo(ToName, ToNameLoc); |
| 7545 | |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7546 | // Import additional name location/type info. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7547 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7548 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7549 | |
| 7550 | UnresolvedSet<8> ToDecls; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7551 | for (auto *D : E->decls()) |
| 7552 | if (auto ToDOrErr = import(D)) |
| 7553 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7554 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7555 | return ToDOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7556 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7557 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7558 | TemplateArgumentListInfo ToTAInfo; |
| 7559 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7560 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7561 | ToTAInfo)) |
| 7562 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7563 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7564 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); |
| 7565 | if (!ToTemplateKeywordLocOrErr) |
| 7566 | return ToTemplateKeywordLocOrErr.takeError(); |
| 7567 | |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7568 | return UnresolvedLookupExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7569 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7570 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, |
| 7571 | ToDecls.begin(), ToDecls.end()); |
| 7572 | } |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7573 | |
| 7574 | return UnresolvedLookupExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7575 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7576 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), |
| 7577 | ToDecls.end()); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7578 | } |
| 7579 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7580 | ExpectedStmt |
| 7581 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7582 | Error Err = Error::success(); |
| 7583 | auto ToType = importChecked(Err, E->getType()); |
| 7584 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7585 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 7586 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); |
| 7587 | auto ToName = importChecked(Err, E->getName()); |
| 7588 | auto ToNameLoc = importChecked(Err, E->getNameLoc()); |
| 7589 | if (Err) |
| 7590 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7591 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7592 | DeclarationNameInfo ToNameInfo(ToName, ToNameLoc); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7593 | // Import additional name location/type info. |
| 7594 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7595 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7596 | |
| 7597 | UnresolvedSet<8> ToDecls; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7598 | for (Decl *D : E->decls()) |
| 7599 | if (auto ToDOrErr = import(D)) |
| 7600 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7601 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7602 | return ToDOrErr.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7603 | |
| 7604 | TemplateArgumentListInfo ToTAInfo; |
| 7605 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7606 | if (E->hasExplicitTemplateArgs()) { |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7607 | TemplateArgumentListInfo FromTAInfo; |
| 7608 | E->copyTemplateArgumentsInto(FromTAInfo); |
| 7609 | if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7610 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7611 | ResInfo = &ToTAInfo; |
| 7612 | } |
| 7613 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7614 | Expr *ToBase = nullptr; |
| 7615 | if (!E->isImplicitAccess()) { |
| 7616 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7617 | ToBase = *ToBaseOrErr; |
| 7618 | else |
| 7619 | return ToBaseOrErr.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7620 | } |
| 7621 | |
| 7622 | return UnresolvedMemberExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7623 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, |
| 7624 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7625 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7626 | } |
| 7627 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7628 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7629 | Error Err = Error::success(); |
| 7630 | auto ToCallee = importChecked(Err, E->getCallee()); |
| 7631 | auto ToType = importChecked(Err, E->getType()); |
| 7632 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7633 | if (Err) |
| 7634 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7635 | |
| 7636 | unsigned NumArgs = E->getNumArgs(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7637 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 7638 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7639 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7640 | |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7641 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7642 | return CXXOperatorCallExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7643 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, |
| Eric Fiselier | 5cdc2cd | 2018-12-12 21:50:55 +0000 | [diff] [blame] | 7644 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), |
| 7645 | OCE->getADLCallKind()); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7646 | } |
| 7647 | |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7648 | return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType, |
| 7649 | E->getValueKind(), ToRParenLoc, /*MinNumArgs=*/0, |
| 7650 | E->getADLCallKind()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7651 | } |
| 7652 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7653 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { |
| 7654 | CXXRecordDecl *FromClass = E->getLambdaClass(); |
| 7655 | auto ToClassOrErr = import(FromClass); |
| 7656 | if (!ToClassOrErr) |
| 7657 | return ToClassOrErr.takeError(); |
| 7658 | CXXRecordDecl *ToClass = *ToClassOrErr; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7659 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7660 | auto ToCallOpOrErr = import(E->getCallOperator()); |
| 7661 | if (!ToCallOpOrErr) |
| 7662 | return ToCallOpOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7663 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7664 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); |
| 7665 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) |
| 7666 | return std::move(Err); |
| 7667 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7668 | Error Err = Error::success(); |
| 7669 | auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange()); |
| 7670 | auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc()); |
| 7671 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); |
| 7672 | if (Err) |
| 7673 | return std::move(Err); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7674 | |
| Richard Smith | ebcbd5ba | 2020-06-04 19:15:22 -0700 | [diff] [blame] | 7675 | return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange, |
| 7676 | E->getCaptureDefault(), ToCaptureDefaultLoc, |
| 7677 | E->hasExplicitParameters(), |
| 7678 | E->hasExplicitResultType(), ToCaptureInits, |
| 7679 | ToEndLoc, E->containsUnexpandedParameterPack()); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7680 | } |
| 7681 | |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7682 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7683 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7684 | Error Err = Error::success(); |
| 7685 | auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc()); |
| 7686 | auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc()); |
| 7687 | auto ToType = importChecked(Err, E->getType()); |
| 7688 | if (Err) |
| 7689 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7690 | |
| 7691 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); |
| 7692 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) |
| 7693 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7694 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7695 | ASTContext &ToCtx = Importer.getToContext(); |
| 7696 | InitListExpr *To = new (ToCtx) InitListExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7697 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); |
| 7698 | To->setType(ToType); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7699 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7700 | if (E->hasArrayFiller()) { |
| 7701 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) |
| 7702 | To->setArrayFiller(*ToFillerOrErr); |
| 7703 | else |
| 7704 | return ToFillerOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7705 | } |
| 7706 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7707 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { |
| 7708 | if (auto ToFDOrErr = import(FromFD)) |
| 7709 | To->setInitializedFieldInUnion(*ToFDOrErr); |
| 7710 | else |
| 7711 | return ToFDOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7712 | } |
| 7713 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7714 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { |
| 7715 | if (auto ToSyntFormOrErr = import(SyntForm)) |
| 7716 | To->setSyntacticForm(*ToSyntFormOrErr); |
| 7717 | else |
| 7718 | return ToSyntFormOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7719 | } |
| 7720 | |
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7721 | // Copy InitListExprBitfields, which are not handled in the ctor of |
| 7722 | // InitListExpr. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7723 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7724 | |
| 7725 | return To; |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7726 | } |
| 7727 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7728 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7729 | CXXStdInitializerListExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7730 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7731 | if (!ToTypeOrErr) |
| 7732 | return ToTypeOrErr.takeError(); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7733 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7734 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7735 | if (!ToSubExprOrErr) |
| 7736 | return ToSubExprOrErr.takeError(); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7737 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7738 | return new (Importer.getToContext()) CXXStdInitializerListExpr( |
| 7739 | *ToTypeOrErr, *ToSubExprOrErr); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7740 | } |
| 7741 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7742 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7743 | CXXInheritedCtorInitExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7744 | Error Err = Error::success(); |
| 7745 | auto ToLocation = importChecked(Err, E->getLocation()); |
| 7746 | auto ToType = importChecked(Err, E->getType()); |
| 7747 | auto ToConstructor = importChecked(Err, E->getConstructor()); |
| 7748 | if (Err) |
| 7749 | return std::move(Err); |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7750 | |
| 7751 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7752 | ToLocation, ToType, ToConstructor, E->constructsVBase(), |
| 7753 | E->inheritedFromVBase()); |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7754 | } |
| 7755 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7756 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7757 | Error Err = Error::success(); |
| 7758 | auto ToType = importChecked(Err, E->getType()); |
| 7759 | auto ToCommonExpr = importChecked(Err, E->getCommonExpr()); |
| 7760 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 7761 | if (Err) |
| 7762 | return std::move(Err); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7763 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7764 | return new (Importer.getToContext()) ArrayInitLoopExpr( |
| 7765 | ToType, ToCommonExpr, ToSubExpr); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7766 | } |
| 7767 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7768 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 7769 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7770 | if (!ToTypeOrErr) |
| 7771 | return ToTypeOrErr.takeError(); |
| 7772 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7773 | } |
| 7774 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7775 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7776 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); |
| 7777 | if (!ToBeginLocOrErr) |
| 7778 | return ToBeginLocOrErr.takeError(); |
| 7779 | |
| 7780 | auto ToFieldOrErr = import(E->getField()); |
| 7781 | if (!ToFieldOrErr) |
| 7782 | return ToFieldOrErr.takeError(); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7783 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7784 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); |
| 7785 | if (!UsedContextOrErr) |
| 7786 | return UsedContextOrErr.takeError(); |
| 7787 | |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7788 | return CXXDefaultInitExpr::Create( |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7789 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr, *UsedContextOrErr); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7790 | } |
| 7791 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7792 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7793 | Error Err = Error::success(); |
| 7794 | auto ToType = importChecked(Err, E->getType()); |
| 7795 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 7796 | auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten()); |
| 7797 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7798 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7799 | auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets()); |
| 7800 | if (Err) |
| 7801 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7802 | |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7803 | ExprValueKind VK = E->getValueKind(); |
| 7804 | CastKind CK = E->getCastKind(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7805 | auto ToBasePathOrErr = ImportCastPath(E); |
| 7806 | if (!ToBasePathOrErr) |
| 7807 | return ToBasePathOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7808 | |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7809 | if (isa<CXXStaticCastExpr>(E)) { |
| 7810 | return CXXStaticCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7811 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7812 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7813 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 7814 | return CXXDynamicCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7815 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7816 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7817 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 7818 | return CXXReinterpretCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7819 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7820 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 7821 | } else if (isa<CXXConstCastExpr>(E)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7822 | return CXXConstCastExpr::Create( |
| 7823 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, |
| 7824 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7825 | } else { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7826 | llvm_unreachable("Unknown cast type"); |
| 7827 | return make_error<ImportError>(); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7828 | } |
| 7829 | } |
| 7830 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7831 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7832 | SubstNonTypeTemplateParmExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7833 | Error Err = Error::success(); |
| 7834 | auto ToType = importChecked(Err, E->getType()); |
| 7835 | auto ToExprLoc = importChecked(Err, E->getExprLoc()); |
| 7836 | auto ToParameter = importChecked(Err, E->getParameter()); |
| 7837 | auto ToReplacement = importChecked(Err, E->getReplacement()); |
| 7838 | if (Err) |
| 7839 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7840 | |
| 7841 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7842 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7843 | } |
| 7844 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7845 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7846 | Error Err = Error::success(); |
| 7847 | auto ToType = importChecked(Err, E->getType()); |
| 7848 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 7849 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); |
| 7850 | if (Err) |
| 7851 | return std::move(Err); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7852 | |
| 7853 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7854 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) |
| 7855 | return std::move(Err); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7856 | |
| 7857 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 7858 | // Value is always false. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7859 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7860 | |
| 7861 | return TypeTraitExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7862 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, |
| 7863 | ToEndLoc, ToValue); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7864 | } |
| 7865 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7866 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 7867 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7868 | if (!ToTypeOrErr) |
| 7869 | return ToTypeOrErr.takeError(); |
| 7870 | |
| 7871 | auto ToSourceRangeOrErr = import(E->getSourceRange()); |
| 7872 | if (!ToSourceRangeOrErr) |
| 7873 | return ToSourceRangeOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7874 | |
| 7875 | if (E->isTypeOperand()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7876 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) |
| 7877 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7878 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); |
| 7879 | else |
| 7880 | return ToTSIOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7881 | } |
| 7882 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7883 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); |
| 7884 | if (!ToExprOperandOrErr) |
| 7885 | return ToExprOperandOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7886 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7887 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7888 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7889 | } |
| 7890 | |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7891 | Error ASTNodeImporter::ImportOverriddenMethods(CXXMethodDecl *ToMethod, |
| 7892 | CXXMethodDecl *FromMethod) { |
| 7893 | Error ImportErrors = Error::success(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7894 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { |
| 7895 | if (auto ImportedOrErr = import(FromOverriddenMethod)) |
| 7896 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( |
| 7897 | (*ImportedOrErr)->getCanonicalDecl())); |
| 7898 | else |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7899 | ImportErrors = |
| 7900 | joinErrors(std::move(ImportErrors), ImportedOrErr.takeError()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7901 | } |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7902 | return ImportErrors; |
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7903 | } |
| 7904 | |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7905 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7906 | ASTContext &FromContext, FileManager &FromFileManager, |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7907 | bool MinimalImport, |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7908 | std::shared_ptr<ASTImporterSharedState> SharedState) |
| 7909 | : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext), |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7910 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 7911 | Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) { |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7912 | |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7913 | // Create a default state without the lookup table: LLDB case. |
| 7914 | if (!SharedState) { |
| 7915 | this->SharedState = std::make_shared<ASTImporterSharedState>(); |
| 7916 | } |
| 7917 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7918 | ImportedDecls[FromContext.getTranslationUnitDecl()] = |
| 7919 | ToContext.getTranslationUnitDecl(); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7920 | } |
| 7921 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7922 | ASTImporter::~ASTImporter() = default; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7923 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7924 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { |
| 7925 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && |
| 7926 | "Try to get field index for non-field."); |
| 7927 | |
| 7928 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 7929 | if (!Owner) |
| 7930 | return None; |
| 7931 | |
| 7932 | unsigned Index = 0; |
| 7933 | for (const auto *D : Owner->decls()) { |
| 7934 | if (D == F) |
| 7935 | return Index; |
| 7936 | |
| 7937 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 7938 | ++Index; |
| 7939 | } |
| 7940 | |
| 7941 | llvm_unreachable("Field was not found in its parent context."); |
| 7942 | |
| 7943 | return None; |
| 7944 | } |
| 7945 | |
| 7946 | ASTImporter::FoundDeclsTy |
| 7947 | ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) { |
| 7948 | // We search in the redecl context because of transparent contexts. |
| 7949 | // E.g. a simple C language enum is a transparent context: |
| 7950 | // enum E { A, B }; |
| 7951 | // Now if we had a global variable in the TU |
| 7952 | // int A; |
| 7953 | // then the enum constant 'A' and the variable 'A' violates ODR. |
| 7954 | // We can diagnose this only if we search in the redecl context. |
| 7955 | DeclContext *ReDC = DC->getRedeclContext(); |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7956 | if (SharedState->getLookupTable()) { |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7957 | ASTImporterLookupTable::LookupResult LookupResult = |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7958 | SharedState->getLookupTable()->lookup(ReDC, Name); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7959 | return FoundDeclsTy(LookupResult.begin(), LookupResult.end()); |
| 7960 | } else { |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 7961 | DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name); |
| 7962 | FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end()); |
| 7963 | // We must search by the slow case of localUncachedLookup because that is |
| 7964 | // working even if there is no LookupPtr for the DC. We could use |
| 7965 | // DC::buildLookup() to create the LookupPtr, but that would load external |
| 7966 | // decls again, we must avoid that case. |
| 7967 | // Also, even if we had the LookupPtr, we must find Decls which are not |
| 7968 | // in the LookupPtr, so we need the slow case. |
| 7969 | // These cases are handled in ASTImporterLookupTable, but we cannot use |
| 7970 | // that with LLDB since that traverses through the AST which initiates the |
| 7971 | // load of external decls again via DC::decls(). And again, we must avoid |
| 7972 | // loading external decls during the import. |
| 7973 | if (Result.empty()) |
| 7974 | ReDC->localUncachedLookup(Name, Result); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7975 | return Result; |
| 7976 | } |
| 7977 | } |
| 7978 | |
| 7979 | void ASTImporter::AddToLookupTable(Decl *ToD) { |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7980 | SharedState->addDeclToLookup(ToD); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7981 | } |
| 7982 | |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7983 | Expected<Decl *> ASTImporter::ImportImpl(Decl *FromD) { |
| 7984 | // Import the decl using ASTNodeImporter. |
| 7985 | ASTNodeImporter Importer(*this); |
| 7986 | return Importer.Visit(FromD); |
| 7987 | } |
| 7988 | |
| 7989 | void ASTImporter::RegisterImportedDecl(Decl *FromD, Decl *ToD) { |
| 7990 | MapImported(FromD, ToD); |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7991 | } |
| 7992 | |
| Akira Hatanaka | 40568fe | 2020-03-10 14:06:25 -0700 | [diff] [blame] | 7993 | llvm::Expected<ExprWithCleanups::CleanupObject> |
| 7994 | ASTImporter::Import(ExprWithCleanups::CleanupObject From) { |
| 7995 | if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) { |
| 7996 | if (Expected<Expr *> R = Import(CLE)) |
| 7997 | return ExprWithCleanups::CleanupObject(cast<CompoundLiteralExpr>(*R)); |
| 7998 | } |
| 7999 | |
| 8000 | // FIXME: Handle BlockDecl when we implement importing BlockExpr in |
| 8001 | // ASTNodeImporter. |
| 8002 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| 8003 | } |
| 8004 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8005 | Expected<QualType> ASTImporter::Import(QualType FromT) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8006 | if (FromT.isNull()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8007 | return QualType{}; |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 8008 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8009 | const Type *FromTy = FromT.getTypePtr(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8010 | |
| 8011 | // Check whether we've already imported this type. |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 8012 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8013 | = ImportedTypes.find(FromTy); |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 8014 | if (Pos != ImportedTypes.end()) |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 8015 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8016 | |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 8017 | // Import the type |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8018 | ASTNodeImporter Importer(*this); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8019 | ExpectedType ToTOrErr = Importer.Visit(FromTy); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8020 | if (!ToTOrErr) |
| 8021 | return ToTOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8022 | |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 8023 | // Record the imported type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8024 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8025 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8026 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8027 | } |
| 8028 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8029 | Expected<TypeSourceInfo *> ASTImporter::Import(TypeSourceInfo *FromTSI) { |
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 8030 | if (!FromTSI) |
| 8031 | return FromTSI; |
| 8032 | |
| 8033 | // FIXME: For now we just create a "trivial" type source info based |
| Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 8034 | // 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] | 8035 | ExpectedType TOrErr = Import(FromTSI->getType()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8036 | if (!TOrErr) |
| 8037 | return TOrErr.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8038 | ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8039 | if (!BeginLocOrErr) |
| 8040 | return BeginLocOrErr.takeError(); |
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 8041 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8042 | return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr); |
| 8043 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8044 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8045 | Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) { |
| Balázs Kéri | b17f292 | 2020-02-28 08:32:32 +0100 | [diff] [blame] | 8046 | Attr *ToAttr = nullptr; |
| 8047 | SourceRange ToRange; |
| 8048 | if (Error Err = importInto(ToRange, FromAttr->getRange())) |
| 8049 | return std::move(Err); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8050 | |
| Balázs Kéri | b17f292 | 2020-02-28 08:32:32 +0100 | [diff] [blame] | 8051 | // FIXME: Is there some kind of AttrVisitor to use here? |
| 8052 | switch (FromAttr->getKind()) { |
| 8053 | case attr::Aligned: { |
| 8054 | auto *From = cast<AlignedAttr>(FromAttr); |
| 8055 | AlignedAttr *To; |
| 8056 | auto CreateAlign = [&](bool IsAlignmentExpr, void *Alignment) { |
| 8057 | return AlignedAttr::Create(ToContext, IsAlignmentExpr, Alignment, ToRange, |
| 8058 | From->getSyntax(), |
| 8059 | From->getSemanticSpelling()); |
| 8060 | }; |
| 8061 | if (From->isAlignmentExpr()) { |
| 8062 | if (auto ToEOrErr = Import(From->getAlignmentExpr())) |
| 8063 | To = CreateAlign(true, *ToEOrErr); |
| 8064 | else |
| 8065 | return ToEOrErr.takeError(); |
| 8066 | } else { |
| 8067 | if (auto ToTOrErr = Import(From->getAlignmentType())) |
| 8068 | To = CreateAlign(false, *ToTOrErr); |
| 8069 | else |
| 8070 | return ToTOrErr.takeError(); |
| 8071 | } |
| 8072 | To->setInherited(From->isInherited()); |
| 8073 | To->setPackExpansion(From->isPackExpansion()); |
| 8074 | To->setImplicit(From->isImplicit()); |
| 8075 | ToAttr = To; |
| 8076 | break; |
| 8077 | } |
| 8078 | default: |
| 8079 | // FIXME: 'clone' copies every member but some of them should be imported. |
| 8080 | // Handle other Attrs that have parameters that should be imported. |
| 8081 | ToAttr = FromAttr->clone(ToContext); |
| 8082 | ToAttr->setRange(ToRange); |
| 8083 | break; |
| 8084 | } |
| 8085 | assert(ToAttr && "Attribute should be created."); |
| 8086 | |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8087 | return ToAttr; |
| Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8088 | } |
| Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 8089 | |
| Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 8090 | Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { |
| 8091 | auto Pos = ImportedDecls.find(FromD); |
| 8092 | if (Pos != ImportedDecls.end()) |
| 8093 | return Pos->second; |
| 8094 | else |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 8095 | return nullptr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 8096 | } |
| 8097 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 8098 | TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) { |
| 8099 | auto FromDPos = ImportedFromDecls.find(ToD); |
| 8100 | if (FromDPos == ImportedFromDecls.end()) |
| 8101 | return nullptr; |
| 8102 | return FromDPos->second->getTranslationUnitDecl(); |
| 8103 | } |
| 8104 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8105 | Expected<Decl *> ASTImporter::Import(Decl *FromD) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8106 | if (!FromD) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8107 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8108 | |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8109 | // Push FromD to the stack, and remove that when we return. |
| 8110 | ImportPath.push(FromD); |
| 8111 | auto ImportPathBuilder = |
| 8112 | llvm::make_scope_exit([this]() { ImportPath.pop(); }); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8113 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8114 | // Check whether there was a previous failed import. |
| 8115 | // If yes return the existing error. |
| 8116 | if (auto Error = getImportDeclErrorIfAny(FromD)) |
| 8117 | return make_error<ImportError>(*Error); |
| 8118 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8119 | // Check whether we've already imported this declaration. |
| 8120 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 8121 | if (ToD) { |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8122 | // Already imported (possibly from another TU) and with an error. |
| 8123 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { |
| 8124 | setImportDeclError(FromD, *Error); |
| 8125 | return make_error<ImportError>(*Error); |
| 8126 | } |
| 8127 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8128 | // If FromD has some updated flags after last import, apply it |
| 8129 | updateFlags(FromD, ToD); |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8130 | // If we encounter a cycle during an import then we save the relevant part |
| 8131 | // of the import path associated to the Decl. |
| 8132 | if (ImportPath.hasCycleAtBack()) |
| 8133 | SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack()); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8134 | return ToD; |
| 8135 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8136 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8137 | // Import the declaration. |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 8138 | ExpectedDecl ToDOrErr = ImportImpl(FromD); |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8139 | if (!ToDOrErr) { |
| 8140 | // Failed to import. |
| 8141 | |
| 8142 | auto Pos = ImportedDecls.find(FromD); |
| 8143 | if (Pos != ImportedDecls.end()) { |
| 8144 | // Import failed after the object was created. |
| 8145 | // Remove all references to it. |
| 8146 | auto *ToD = Pos->second; |
| 8147 | ImportedDecls.erase(Pos); |
| 8148 | |
| 8149 | // ImportedDecls and ImportedFromDecls are not symmetric. It may happen |
| 8150 | // (e.g. with namespaces) that several decls from the 'from' context are |
| 8151 | // mapped to the same decl in the 'to' context. If we removed entries |
| 8152 | // from the LookupTable here then we may end up removing them multiple |
| 8153 | // times. |
| 8154 | |
| 8155 | // The Lookuptable contains decls only which are in the 'to' context. |
| 8156 | // Remove from the Lookuptable only if it is *imported* into the 'to' |
| 8157 | // context (and do not remove it if it was added during the initial |
| 8158 | // traverse of the 'to' context). |
| 8159 | auto PosF = ImportedFromDecls.find(ToD); |
| 8160 | if (PosF != ImportedFromDecls.end()) { |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8161 | SharedState->removeDeclFromLookup(ToD); |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8162 | ImportedFromDecls.erase(PosF); |
| 8163 | } |
| 8164 | |
| 8165 | // FIXME: AST may contain remaining references to the failed object. |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8166 | // However, the ImportDeclErrors in the shared state contains all the |
| 8167 | // failed objects together with their error. |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8168 | } |
| 8169 | |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8170 | // Error encountered for the first time. |
| 8171 | // After takeError the error is not usable any more in ToDOrErr. |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8172 | // Get a copy of the error object (any more simple solution for this?). |
| 8173 | ImportError ErrOut; |
| 8174 | handleAllErrors(ToDOrErr.takeError(), |
| 8175 | [&ErrOut](const ImportError &E) { ErrOut = E; }); |
| 8176 | setImportDeclError(FromD, ErrOut); |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8177 | // Set the error for the mapped to Decl, which is in the "to" context. |
| 8178 | if (Pos != ImportedDecls.end()) |
| 8179 | SharedState->setImportDeclError(Pos->second, ErrOut); |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8180 | |
| 8181 | // Set the error for all nodes which have been created before we |
| 8182 | // recognized the error. |
| 8183 | for (const auto &Path : SavedImportPaths[FromD]) |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8184 | for (Decl *FromDi : Path) { |
| 8185 | setImportDeclError(FromDi, ErrOut); |
| 8186 | //FIXME Should we remove these Decls from ImportedDecls? |
| 8187 | // Set the error for the mapped to Decl, which is in the "to" context. |
| 8188 | auto Ii = ImportedDecls.find(FromDi); |
| 8189 | if (Ii != ImportedDecls.end()) |
| 8190 | SharedState->setImportDeclError(Ii->second, ErrOut); |
| 8191 | // FIXME Should we remove these Decls from the LookupTable, |
| 8192 | // and from ImportedFromDecls? |
| 8193 | } |
| Jaroslav Sevcik | 4481eef | 2020-01-22 15:19:44 +0100 | [diff] [blame] | 8194 | SavedImportPaths.erase(FromD); |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8195 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8196 | // Do not return ToDOrErr, error was taken out of it. |
| 8197 | return make_error<ImportError>(ErrOut); |
| 8198 | } |
| 8199 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8200 | ToD = *ToDOrErr; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8201 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8202 | // FIXME: Handle the "already imported with error" case. We can get here |
| 8203 | // nullptr only if GetImportedOrCreateDecl returned nullptr (after a |
| 8204 | // previously failed create was requested). |
| 8205 | // Later GetImportedOrCreateDecl can be updated to return the error. |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 8206 | if (!ToD) { |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8207 | auto Err = getImportDeclErrorIfAny(FromD); |
| 8208 | assert(Err); |
| 8209 | return make_error<ImportError>(*Err); |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 8210 | } |
| 8211 | |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8212 | // We could import from the current TU without error. But previously we |
| 8213 | // already had imported a Decl as `ToD` from another TU (with another |
| 8214 | // ASTImporter object) and with an error. |
| 8215 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { |
| 8216 | setImportDeclError(FromD, *Error); |
| 8217 | return make_error<ImportError>(*Error); |
| 8218 | } |
| 8219 | |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 8220 | // Make sure that ImportImpl registered the imported decl. |
| 8221 | assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?"); |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8222 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8223 | // Notify subclasses. |
| 8224 | Imported(FromD, ToD); |
| 8225 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 8226 | updateFlags(FromD, ToD); |
| Jaroslav Sevcik | 4481eef | 2020-01-22 15:19:44 +0100 | [diff] [blame] | 8227 | SavedImportPaths.erase(FromD); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8228 | return ToDOrErr; |
| 8229 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8230 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8231 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8232 | if (!FromDC) |
| 8233 | return FromDC; |
| 8234 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8235 | ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC)); |
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8236 | if (!ToDCOrErr) |
| 8237 | return ToDCOrErr.takeError(); |
| 8238 | auto *ToDC = cast<DeclContext>(*ToDCOrErr); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8239 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8240 | // 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] | 8241 | // need it to have a definition. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8242 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 8243 | auto *FromRecord = cast<RecordDecl>(FromDC); |
| shafik | def7c7f | 2020-04-23 15:16:34 -0700 | [diff] [blame] | 8244 | if (ToRecord->isCompleteDefinition()) |
| 8245 | return ToDC; |
| 8246 | |
| 8247 | // If FromRecord is not defined we need to force it to be. |
| 8248 | // Simply calling CompleteDecl(...) for a RecordDecl will break some cases |
| 8249 | // it will start the definition but we never finish it. |
| 8250 | // If there are base classes they won't be imported and we will |
| 8251 | // be missing anything that we inherit from those bases. |
| 8252 | if (FromRecord->getASTContext().getExternalSource() && |
| 8253 | !FromRecord->isCompleteDefinition()) |
| 8254 | FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord); |
| 8255 | |
| 8256 | if (FromRecord->isCompleteDefinition()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8257 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8258 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) |
| 8259 | return std::move(Err); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8260 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 8261 | auto *FromEnum = cast<EnumDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8262 | if (ToEnum->isCompleteDefinition()) { |
| 8263 | // Do nothing. |
| 8264 | } else if (FromEnum->isCompleteDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8265 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8266 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) |
| 8267 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8268 | } else { |
| 8269 | CompleteDecl(ToEnum); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8270 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8271 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 8272 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8273 | if (ToClass->getDefinition()) { |
| 8274 | // Do nothing. |
| 8275 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8276 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8277 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) |
| 8278 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8279 | } else { |
| 8280 | CompleteDecl(ToClass); |
| 8281 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8282 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 8283 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8284 | if (ToProto->getDefinition()) { |
| 8285 | // Do nothing. |
| 8286 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8287 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8288 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) |
| 8289 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8290 | } else { |
| 8291 | CompleteDecl(ToProto); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8292 | } |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 8293 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8294 | |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 8295 | return ToDC; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8296 | } |
| 8297 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8298 | Expected<Expr *> ASTImporter::Import(Expr *FromE) { |
| 8299 | if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE))) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8300 | return cast_or_null<Expr>(*ToSOrErr); |
| 8301 | else |
| 8302 | return ToSOrErr.takeError(); |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8303 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8304 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8305 | Expected<Stmt *> ASTImporter::Import(Stmt *FromS) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8306 | if (!FromS) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8307 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8308 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8309 | // Check whether we've already imported this statement. |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 8310 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 8311 | if (Pos != ImportedStmts.end()) |
| 8312 | return Pos->second; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8313 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8314 | // Import the statement. |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 8315 | ASTNodeImporter Importer(*this); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8316 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8317 | if (!ToSOrErr) |
| 8318 | return ToSOrErr; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8319 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8320 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { |
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 8321 | auto *FromE = cast<Expr>(FromS); |
| 8322 | // Copy ExprBitfields, which may not be handled in Expr subclasses |
| 8323 | // constructors. |
| 8324 | ToE->setValueKind(FromE->getValueKind()); |
| 8325 | ToE->setObjectKind(FromE->getObjectKind()); |
| Ilya Biryukov | ec3060c | 2020-03-02 16:07:09 +0100 | [diff] [blame] | 8326 | ToE->setDependence(FromE->getDependence()); |
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 8327 | } |
| 8328 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8329 | // Record the imported statement object. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8330 | ImportedStmts[FromS] = *ToSOrErr; |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8331 | return ToSOrErr; |
| 8332 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8333 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8334 | Expected<NestedNameSpecifier *> |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8335 | ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8336 | if (!FromNNS) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8337 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8338 | |
| Simon Pilgrim | 130df2c | 2019-07-15 13:00:43 +0000 | [diff] [blame] | 8339 | NestedNameSpecifier *Prefix = nullptr; |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8340 | if (Error Err = importInto(Prefix, FromNNS->getPrefix())) |
| 8341 | return std::move(Err); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8342 | |
| 8343 | switch (FromNNS->getKind()) { |
| 8344 | case NestedNameSpecifier::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8345 | assert(FromNNS->getAsIdentifier() && "NNS should contain identifier."); |
| 8346 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8347 | Import(FromNNS->getAsIdentifier())); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8348 | |
| 8349 | case NestedNameSpecifier::Namespace: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8350 | if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8351 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8352 | cast<NamespaceDecl>(*NSOrErr)); |
| 8353 | } else |
| 8354 | return NSOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8355 | |
| 8356 | case NestedNameSpecifier::NamespaceAlias: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8357 | if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8358 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8359 | cast<NamespaceAliasDecl>(*NSADOrErr)); |
| 8360 | else |
| 8361 | return NSADOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8362 | |
| 8363 | case NestedNameSpecifier::Global: |
| 8364 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 8365 | |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8366 | case NestedNameSpecifier::Super: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8367 | if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8368 | return NestedNameSpecifier::SuperSpecifier(ToContext, |
| 8369 | cast<CXXRecordDecl>(*RDOrErr)); |
| 8370 | else |
| 8371 | return RDOrErr.takeError(); |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8372 | |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8373 | case NestedNameSpecifier::TypeSpec: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8374 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 8375 | if (Expected<QualType> TyOrErr = |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8376 | Import(QualType(FromNNS->getAsType(), 0u))) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8377 | bool TSTemplate = |
| 8378 | FromNNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate; |
| 8379 | return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate, |
| 8380 | TyOrErr->getTypePtr()); |
| 8381 | } else { |
| 8382 | return TyOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8383 | } |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8384 | } |
| 8385 | |
| 8386 | llvm_unreachable("Invalid nested name specifier kind"); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8387 | } |
| 8388 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8389 | Expected<NestedNameSpecifierLoc> |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8390 | ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8391 | // Copied from NestedNameSpecifier mostly. |
| 8392 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 8393 | NestedNameSpecifierLoc NNS = FromNNS; |
| 8394 | |
| 8395 | // Push each of the nested-name-specifiers's onto a stack for |
| 8396 | // serialization in reverse order. |
| 8397 | while (NNS) { |
| 8398 | NestedNames.push_back(NNS); |
| 8399 | NNS = NNS.getPrefix(); |
| 8400 | } |
| 8401 | |
| 8402 | NestedNameSpecifierLocBuilder Builder; |
| 8403 | |
| 8404 | while (!NestedNames.empty()) { |
| 8405 | NNS = NestedNames.pop_back_val(); |
| Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 8406 | NestedNameSpecifier *Spec = nullptr; |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8407 | if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier())) |
| 8408 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8409 | |
| 8410 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8411 | |
| 8412 | SourceLocation ToLocalBeginLoc, ToLocalEndLoc; |
| 8413 | if (Kind != NestedNameSpecifier::Super) { |
| 8414 | if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc())) |
| 8415 | return std::move(Err); |
| 8416 | |
| 8417 | if (Kind != NestedNameSpecifier::Global) |
| 8418 | if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc())) |
| 8419 | return std::move(Err); |
| 8420 | } |
| 8421 | |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8422 | switch (Kind) { |
| 8423 | case NestedNameSpecifier::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8424 | Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc, |
| 8425 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8426 | break; |
| 8427 | |
| 8428 | case NestedNameSpecifier::Namespace: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8429 | Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc, |
| 8430 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8431 | break; |
| 8432 | |
| 8433 | case NestedNameSpecifier::NamespaceAlias: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8434 | Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(), |
| 8435 | ToLocalBeginLoc, ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8436 | break; |
| 8437 | |
| 8438 | case NestedNameSpecifier::TypeSpec: |
| 8439 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8440 | SourceLocation ToTLoc; |
| 8441 | if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc())) |
| 8442 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8443 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8444 | QualType(Spec->getAsType(), 0), ToTLoc); |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 8445 | if (Kind == NestedNameSpecifier::TypeSpecWithTemplate) |
| 8446 | // ToLocalBeginLoc is here the location of the 'template' keyword. |
| 8447 | Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(), |
| 8448 | ToLocalEndLoc); |
| 8449 | else |
| 8450 | // No location for 'template' keyword here. |
| 8451 | Builder.Extend(getToContext(), SourceLocation{}, TSI->getTypeLoc(), |
| 8452 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8453 | break; |
| 8454 | } |
| 8455 | |
| 8456 | case NestedNameSpecifier::Global: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8457 | Builder.MakeGlobal(getToContext(), ToLocalBeginLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8458 | break; |
| 8459 | |
| 8460 | case NestedNameSpecifier::Super: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8461 | auto ToSourceRangeOrErr = Import(NNS.getSourceRange()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8462 | if (!ToSourceRangeOrErr) |
| 8463 | return ToSourceRangeOrErr.takeError(); |
| 8464 | |
| 8465 | Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(), |
| 8466 | ToSourceRangeOrErr->getBegin(), |
| 8467 | ToSourceRangeOrErr->getEnd()); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8468 | } |
| 8469 | } |
| 8470 | } |
| 8471 | |
| 8472 | return Builder.getWithLocInContext(getToContext()); |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 8473 | } |
| 8474 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8475 | Expected<TemplateName> ASTImporter::Import(TemplateName From) { |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8476 | switch (From.getKind()) { |
| 8477 | case TemplateName::Template: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8478 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8479 | return TemplateName(cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8480 | else |
| 8481 | return ToTemplateOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8482 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8483 | case TemplateName::OverloadedTemplate: { |
| 8484 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 8485 | UnresolvedSet<2> ToTemplates; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8486 | for (auto *I : *FromStorage) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8487 | if (auto ToOrErr = Import(I)) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8488 | ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr)); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8489 | else |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8490 | return ToOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8491 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8492 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8493 | ToTemplates.end()); |
| 8494 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8495 | |
| Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8496 | case TemplateName::AssumedTemplate: { |
| 8497 | AssumedTemplateStorage *FromStorage = From.getAsAssumedTemplateName(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8498 | auto DeclNameOrErr = Import(FromStorage->getDeclName()); |
| Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8499 | if (!DeclNameOrErr) |
| 8500 | return DeclNameOrErr.takeError(); |
| 8501 | return ToContext.getAssumedTemplateName(*DeclNameOrErr); |
| 8502 | } |
| 8503 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8504 | case TemplateName::QualifiedTemplate: { |
| 8505 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8506 | auto QualifierOrErr = Import(QTN->getQualifier()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8507 | if (!QualifierOrErr) |
| 8508 | return QualifierOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8509 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8510 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8511 | return ToContext.getQualifiedTemplateName( |
| 8512 | *QualifierOrErr, QTN->hasTemplateKeyword(), |
| 8513 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8514 | else |
| 8515 | return ToTemplateOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8516 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8517 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8518 | case TemplateName::DependentTemplate: { |
| 8519 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8520 | auto QualifierOrErr = Import(DTN->getQualifier()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8521 | if (!QualifierOrErr) |
| 8522 | return QualifierOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8523 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8524 | if (DTN->isIdentifier()) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8525 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8526 | Import(DTN->getIdentifier())); |
| 8527 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8528 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8529 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
| 8530 | DTN->getOperator()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8531 | } |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8532 | |
| 8533 | case TemplateName::SubstTemplateTemplateParm: { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8534 | SubstTemplateTemplateParmStorage *Subst = |
| 8535 | From.getAsSubstTemplateTemplateParm(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8536 | ExpectedDecl ParamOrErr = Import(Subst->getParameter()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8537 | if (!ParamOrErr) |
| 8538 | return ParamOrErr.takeError(); |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8539 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8540 | auto ReplacementOrErr = Import(Subst->getReplacement()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8541 | if (!ReplacementOrErr) |
| 8542 | return ReplacementOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8543 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8544 | return ToContext.getSubstTemplateTemplateParm( |
| 8545 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ReplacementOrErr); |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8546 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8547 | |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8548 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 8549 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 8550 | = From.getAsSubstTemplateTemplateParmPack(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8551 | ExpectedDecl ParamOrErr = Import(SubstPack->getParameterPack()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8552 | if (!ParamOrErr) |
| 8553 | return ParamOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8554 | |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8555 | ASTNodeImporter Importer(*this); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8556 | auto ArgPackOrErr = |
| 8557 | Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 8558 | if (!ArgPackOrErr) |
| 8559 | return ArgPackOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8560 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8561 | return ToContext.getSubstTemplateTemplateParmPack( |
| 8562 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ArgPackOrErr); |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8563 | } |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8564 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8565 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8566 | llvm_unreachable("Invalid template name kind"); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8567 | } |
| 8568 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8569 | Expected<SourceLocation> ASTImporter::Import(SourceLocation FromLoc) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8570 | if (FromLoc.isInvalid()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8571 | return SourceLocation{}; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8572 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8573 | SourceManager &FromSM = FromContext.getSourceManager(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8574 | bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8575 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8576 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8577 | Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8578 | if (!ToFileIDOrErr) |
| 8579 | return ToFileIDOrErr.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8580 | SourceManager &ToSM = ToContext.getSourceManager(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8581 | return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second); |
| 8582 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8583 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8584 | Expected<SourceRange> ASTImporter::Import(SourceRange FromRange) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8585 | SourceLocation ToBegin, ToEnd; |
| 8586 | if (Error Err = importInto(ToBegin, FromRange.getBegin())) |
| 8587 | return std::move(Err); |
| 8588 | if (Error Err = importInto(ToEnd, FromRange.getEnd())) |
| 8589 | return std::move(Err); |
| 8590 | |
| 8591 | return SourceRange(ToBegin, ToEnd); |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8592 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8593 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8594 | Expected<FileID> ASTImporter::Import(FileID FromID, bool IsBuiltin) { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8595 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8596 | if (Pos != ImportedFileIDs.end()) |
| 8597 | return Pos->second; |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8598 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8599 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 8600 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8601 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8602 | |
| 8603 | // Map the FromID to the "to" source manager. |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8604 | FileID ToID; |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8605 | if (FromSLoc.isExpansion()) { |
| 8606 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8607 | ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8608 | if (!ToSpLoc) |
| 8609 | return ToSpLoc.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8610 | ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8611 | if (!ToExLocS) |
| 8612 | return ToExLocS.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8613 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 8614 | SourceLocation MLoc; |
| 8615 | if (FromEx.isMacroArgExpansion()) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8616 | MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, TokenLen); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8617 | } else { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8618 | if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8619 | MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, TokenLen, |
| 8620 | FromEx.isExpansionTokenRange()); |
| 8621 | else |
| 8622 | return ToExLocE.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8623 | } |
| 8624 | ToID = ToSM.getFileID(MLoc); |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8625 | } else { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8626 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8627 | |
| Raphael Isemann | 9f1e81f | 2020-04-27 10:06:56 +0200 | [diff] [blame] | 8628 | if (!IsBuiltin && !Cache->BufferOverridden) { |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8629 | // Include location of this file. |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8630 | ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8631 | if (!ToIncludeLoc) |
| 8632 | return ToIncludeLoc.takeError(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8633 | |
| Raphael Isemann | a37734f | 2020-02-17 19:43:33 +0100 | [diff] [blame] | 8634 | // Every FileID that is not the main FileID needs to have a valid include |
| 8635 | // location so that the include chain points to the main FileID. When |
| 8636 | // importing the main FileID (which has no include location), we need to |
| 8637 | // create a fake include location in the main file to keep this property |
| 8638 | // intact. |
| 8639 | SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc; |
| 8640 | if (FromID == FromSM.getMainFileID()) |
| 8641 | ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID()); |
| 8642 | |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8643 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 8644 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 8645 | // disk again |
| 8646 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 8647 | // than mmap the files several times. |
| Harlan Haskins | 8d323d1 | 2019-08-01 21:31:56 +0000 | [diff] [blame] | 8648 | auto Entry = |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8649 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 8650 | // FIXME: The filename may be a virtual name that does probably not |
| 8651 | // point to a valid file and we get no Entry here. In this case try with |
| 8652 | // the memory buffer below. |
| 8653 | if (Entry) |
| Raphael Isemann | a37734f | 2020-02-17 19:43:33 +0100 | [diff] [blame] | 8654 | ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc, |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8655 | FromSLoc.getFile().getFileCharacteristic()); |
| 8656 | } |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8657 | } |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8658 | |
| 8659 | if (ToID.isInvalid() || IsBuiltin) { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8660 | // FIXME: We want to re-use the existing MemoryBuffer! |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8661 | bool Invalid = true; |
| Duncan P. N. Exon Smith | f584819 | 2019-08-26 20:32:05 +0000 | [diff] [blame] | 8662 | const llvm::MemoryBuffer *FromBuf = |
| 8663 | Cache->getBuffer(FromContext.getDiagnostics(), |
| 8664 | FromSM.getFileManager(), SourceLocation{}, &Invalid); |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8665 | if (!FromBuf || Invalid) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8666 | // FIXME: Use a new error kind? |
| 8667 | return llvm::make_error<ImportError>(ImportError::Unknown); |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8668 | |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8669 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 8670 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 8671 | FromBuf->getBufferIdentifier()); |
| 8672 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 8673 | FromSLoc.getFile().getFileCharacteristic()); |
| 8674 | } |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8675 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8676 | |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8677 | assert(ToID.isValid() && "Unexpected invalid fileID was created."); |
| 8678 | |
| Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 8679 | ImportedFileIDs[FromID] = ToID; |
| Balazs Keri | d22f877 | 2019-07-24 10:16:37 +0000 | [diff] [blame] | 8680 | |
| 8681 | if (FileIDImportHandler) |
| 8682 | FileIDImportHandler(ToID, FromID); |
| 8683 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8684 | return ToID; |
| 8685 | } |
| 8686 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8687 | Expected<CXXCtorInitializer *> ASTImporter::Import(CXXCtorInitializer *From) { |
| 8688 | ExpectedExpr ToExprOrErr = Import(From->getInit()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8689 | if (!ToExprOrErr) |
| 8690 | return ToExprOrErr.takeError(); |
| 8691 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8692 | auto LParenLocOrErr = Import(From->getLParenLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8693 | if (!LParenLocOrErr) |
| 8694 | return LParenLocOrErr.takeError(); |
| 8695 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8696 | auto RParenLocOrErr = Import(From->getRParenLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8697 | if (!RParenLocOrErr) |
| 8698 | return RParenLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8699 | |
| 8700 | if (From->isBaseInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8701 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8702 | if (!ToTInfoOrErr) |
| 8703 | return ToTInfoOrErr.takeError(); |
| 8704 | |
| 8705 | SourceLocation EllipsisLoc; |
| 8706 | if (From->isPackExpansion()) |
| 8707 | if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc())) |
| 8708 | return std::move(Err); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8709 | |
| 8710 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8711 | ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr, |
| 8712 | *ToExprOrErr, *RParenLocOrErr, EllipsisLoc); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8713 | } else if (From->isMemberInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8714 | ExpectedDecl ToFieldOrErr = Import(From->getMember()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8715 | if (!ToFieldOrErr) |
| 8716 | return ToFieldOrErr.takeError(); |
| 8717 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8718 | auto MemberLocOrErr = Import(From->getMemberLocation()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8719 | if (!MemberLocOrErr) |
| 8720 | return MemberLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8721 | |
| 8722 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8723 | ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr, |
| 8724 | *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8725 | } else if (From->isIndirectMemberInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8726 | ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8727 | if (!ToIFieldOrErr) |
| 8728 | return ToIFieldOrErr.takeError(); |
| 8729 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8730 | auto MemberLocOrErr = Import(From->getMemberLocation()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8731 | if (!MemberLocOrErr) |
| 8732 | return MemberLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8733 | |
| 8734 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8735 | ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr), |
| 8736 | *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8737 | } else if (From->isDelegatingInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8738 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8739 | if (!ToTInfoOrErr) |
| 8740 | return ToTInfoOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8741 | |
| 8742 | return new (ToContext) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8743 | CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr, |
| 8744 | *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8745 | } else { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8746 | // FIXME: assert? |
| 8747 | return make_error<ImportError>(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8748 | } |
| Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8749 | } |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8750 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8751 | Expected<CXXBaseSpecifier *> |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8752 | ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8753 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 8754 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 8755 | return Pos->second; |
| 8756 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8757 | Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8758 | if (!ToSourceRange) |
| 8759 | return ToSourceRange.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8760 | Expected<TypeSourceInfo *> ToTSI = Import(BaseSpec->getTypeSourceInfo()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8761 | if (!ToTSI) |
| 8762 | return ToTSI.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8763 | ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8764 | if (!ToEllipsisLoc) |
| 8765 | return ToEllipsisLoc.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8766 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8767 | *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 8768 | BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8769 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 8770 | return Imported; |
| 8771 | } |
| 8772 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8773 | Error ASTImporter::ImportDefinition(Decl *From) { |
| 8774 | ExpectedDecl ToOrErr = Import(From); |
| 8775 | if (!ToOrErr) |
| 8776 | return ToOrErr.takeError(); |
| 8777 | Decl *To = *ToOrErr; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8778 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8779 | auto *FromDC = cast<DeclContext>(From); |
| 8780 | ASTNodeImporter Importer(*this); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8781 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8782 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
| 8783 | if (!ToRecord->getDefinition()) { |
| 8784 | return Importer.ImportDefinition( |
| 8785 | cast<RecordDecl>(FromDC), ToRecord, |
| 8786 | ASTNodeImporter::IDK_Everything); |
| Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8787 | } |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8788 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8789 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8790 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
| 8791 | if (!ToEnum->getDefinition()) { |
| 8792 | return Importer.ImportDefinition( |
| 8793 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); |
| 8794 | } |
| 8795 | } |
| 8796 | |
| 8797 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
| 8798 | if (!ToIFace->getDefinition()) { |
| 8799 | return Importer.ImportDefinition( |
| 8800 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
| 8801 | ASTNodeImporter::IDK_Everything); |
| 8802 | } |
| 8803 | } |
| 8804 | |
| 8805 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
| 8806 | if (!ToProto->getDefinition()) { |
| 8807 | return Importer.ImportDefinition( |
| 8808 | cast<ObjCProtocolDecl>(FromDC), ToProto, |
| 8809 | ASTNodeImporter::IDK_Everything); |
| 8810 | } |
| 8811 | } |
| 8812 | |
| 8813 | return Importer.ImportDeclContext(FromDC, true); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8814 | } |
| 8815 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8816 | Expected<DeclarationName> ASTImporter::Import(DeclarationName FromName) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8817 | if (!FromName) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8818 | return DeclarationName{}; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8819 | |
| 8820 | switch (FromName.getNameKind()) { |
| 8821 | case DeclarationName::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8822 | return DeclarationName(Import(FromName.getAsIdentifierInfo())); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8823 | |
| 8824 | case DeclarationName::ObjCZeroArgSelector: |
| 8825 | case DeclarationName::ObjCOneArgSelector: |
| 8826 | case DeclarationName::ObjCMultiArgSelector: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8827 | if (auto ToSelOrErr = Import(FromName.getObjCSelector())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8828 | return DeclarationName(*ToSelOrErr); |
| 8829 | else |
| 8830 | return ToSelOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8831 | |
| 8832 | case DeclarationName::CXXConstructorName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8833 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8834 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 8835 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8836 | else |
| 8837 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8838 | } |
| 8839 | |
| 8840 | case DeclarationName::CXXDestructorName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8841 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8842 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 8843 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8844 | else |
| 8845 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8846 | } |
| 8847 | |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8848 | case DeclarationName::CXXDeductionGuideName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8849 | if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8850 | return ToContext.DeclarationNames.getCXXDeductionGuideName( |
| 8851 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8852 | else |
| 8853 | return ToTemplateOrErr.takeError(); |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8854 | } |
| 8855 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8856 | case DeclarationName::CXXConversionFunctionName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8857 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8858 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 8859 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8860 | else |
| 8861 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8862 | } |
| 8863 | |
| 8864 | case DeclarationName::CXXOperatorName: |
| 8865 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 8866 | FromName.getCXXOverloadedOperator()); |
| 8867 | |
| 8868 | case DeclarationName::CXXLiteralOperatorName: |
| 8869 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8870 | Import(FromName.getCXXLiteralIdentifier())); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8871 | |
| 8872 | case DeclarationName::CXXUsingDirective: |
| 8873 | // FIXME: STATICS! |
| 8874 | return DeclarationName::getUsingDirectiveName(); |
| 8875 | } |
| 8876 | |
| David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 8877 | llvm_unreachable("Invalid DeclarationName Kind!"); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8878 | } |
| 8879 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8880 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8881 | if (!FromId) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8882 | return nullptr; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8883 | |
| Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 8884 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 8885 | |
| 8886 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 8887 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 8888 | |
| 8889 | return ToId; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8890 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8891 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8892 | Expected<Selector> ASTImporter::Import(Selector FromSel) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8893 | if (FromSel.isNull()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8894 | return Selector{}; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8895 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8896 | SmallVector<IdentifierInfo *, 4> Idents; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8897 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 8898 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 8899 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 8900 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 8901 | } |
| 8902 | |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 8903 | Expected<DeclarationName> ASTImporter::HandleNameConflict(DeclarationName Name, |
| 8904 | DeclContext *DC, |
| 8905 | unsigned IDNS, |
| 8906 | NamedDecl **Decls, |
| 8907 | unsigned NumDecls) { |
| 8908 | if (ODRHandling == ODRHandlingType::Conservative) |
| 8909 | // Report error at any name conflict. |
| 8910 | return make_error<ImportError>(ImportError::NameConflict); |
| 8911 | else |
| 8912 | // Allow to create the new Decl with the same name. |
| 8913 | return Name; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8914 | } |
| 8915 | |
| 8916 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
| Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8917 | if (LastDiagFromFrom) |
| 8918 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8919 | FromContext.getDiagnostics()); |
| 8920 | LastDiagFromFrom = false; |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8921 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8922 | } |
| 8923 | |
| 8924 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
| Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8925 | if (!LastDiagFromFrom) |
| 8926 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8927 | ToContext.getDiagnostics()); |
| 8928 | LastDiagFromFrom = true; |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8929 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8930 | } |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8931 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8932 | void ASTImporter::CompleteDecl (Decl *D) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8933 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8934 | if (!ID->getDefinition()) |
| 8935 | ID->startDefinition(); |
| 8936 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8937 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8938 | if (!PD->getDefinition()) |
| 8939 | PD->startDefinition(); |
| 8940 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8941 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8942 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 8943 | TD->startDefinition(); |
| 8944 | TD->setCompleteDefinition(true); |
| 8945 | } |
| 8946 | } |
| 8947 | else { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8948 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8949 | } |
| 8950 | } |
| 8951 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8952 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 8953 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 8954 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 8955 | "Try to import an already imported Decl"); |
| 8956 | if (Pos != ImportedDecls.end()) |
| 8957 | return Pos->second; |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8958 | ImportedDecls[From] = To; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 8959 | // This mapping should be maintained only in this function. Therefore do not |
| 8960 | // check for additional consistency. |
| 8961 | ImportedFromDecls[To] = From; |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8962 | AddToLookupTable(To); |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8963 | return To; |
| Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 8964 | } |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8965 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8966 | llvm::Optional<ImportError> |
| 8967 | ASTImporter::getImportDeclErrorIfAny(Decl *FromD) const { |
| 8968 | auto Pos = ImportDeclErrors.find(FromD); |
| 8969 | if (Pos != ImportDeclErrors.end()) |
| 8970 | return Pos->second; |
| 8971 | else |
| 8972 | return Optional<ImportError>(); |
| 8973 | } |
| 8974 | |
| 8975 | void ASTImporter::setImportDeclError(Decl *From, ImportError Error) { |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8976 | auto InsertRes = ImportDeclErrors.insert({From, Error}); |
| Benjamin Kramer | 4f76936 | 2019-07-01 14:33:26 +0000 | [diff] [blame] | 8977 | (void)InsertRes; |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8978 | // Either we set the error for the first time, or we already had set one and |
| 8979 | // now we want to set the same error. |
| 8980 | assert(InsertRes.second || InsertRes.first->second.Error == Error.Error); |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8981 | } |
| 8982 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8983 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 8984 | bool Complain) { |
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8985 | llvm::DenseMap<const Type *, const Type *>::iterator Pos = |
| 8986 | ImportedTypes.find(From.getTypePtr()); |
| 8987 | if (Pos != ImportedTypes.end()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8988 | if (ExpectedType ToFromOrErr = Import(From)) { |
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8989 | if (ToContext.hasSameType(*ToFromOrErr, To)) |
| 8990 | return true; |
| 8991 | } else { |
| 8992 | llvm::consumeError(ToFromOrErr.takeError()); |
| 8993 | } |
| 8994 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 8995 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8996 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8997 | getStructuralEquivalenceKind(*this), false, |
| 8998 | Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 8999 | return Ctx.IsEquivalent(From, To); |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 9000 | } |