| 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))) { |
| 1893 | Error Result = ImportDeclContext(From, /*ForceImport=*/true); |
| 1894 | // Finish the definition of the lambda, set isBeingDefined to false. |
| 1895 | if (To->isLambda()) |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1896 | DefinitionCompleter(); |
| Gabor Marton | e73805f | 2019-07-08 12:49:13 +0000 | [diff] [blame] | 1897 | return Result; |
| 1898 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1899 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1900 | return Error::success(); |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1901 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1902 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1903 | To->startDefinition(); |
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1904 | // Complete the definition even if error is returned. |
| 1905 | // The RecordDecl may be already part of the AST so it is better to |
| 1906 | // have it in complete state even if something is wrong with it. |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1907 | auto DefinitionCompleterScopeExit = |
| 1908 | llvm::make_scope_exit(DefinitionCompleter); |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1909 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1910 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1911 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1912 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1913 | // Add base classes. |
| Gabor Marton | 17d3967 | 2018-11-26 15:54:08 +0000 | [diff] [blame] | 1914 | auto *ToCXX = dyn_cast<CXXRecordDecl>(To); |
| 1915 | auto *FromCXX = dyn_cast<CXXRecordDecl>(From); |
| 1916 | if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) { |
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1917 | |
| 1918 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1919 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 1920 | |
| 1921 | #define FIELD(Name, Width, Merge) \ |
| 1922 | ToData.Name = FromData.Name; |
| 1923 | #include "clang/AST/CXXRecordDeclDefinitionBits.def" |
| Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1924 | |
| Shafik Yaghmour | 16b9073 | 2019-04-26 18:51:28 +0000 | [diff] [blame] | 1925 | // Copy over the data stored in RecordDeclBits |
| 1926 | ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions()); |
| 1927 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1928 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1929 | for (const auto &Base1 : FromCXX->bases()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1930 | ExpectedType TyOrErr = import(Base1.getType()); |
| 1931 | if (!TyOrErr) |
| 1932 | return TyOrErr.takeError(); |
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1933 | |
| 1934 | SourceLocation EllipsisLoc; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1935 | if (Base1.isPackExpansion()) { |
| 1936 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) |
| 1937 | EllipsisLoc = *LocOrErr; |
| 1938 | else |
| 1939 | return LocOrErr.takeError(); |
| 1940 | } |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1941 | |
| 1942 | // Ensure that we have a definition for the base. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1943 | if (Error Err = |
| 1944 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) |
| 1945 | return Err; |
| 1946 | |
| 1947 | auto RangeOrErr = import(Base1.getSourceRange()); |
| 1948 | if (!RangeOrErr) |
| 1949 | return RangeOrErr.takeError(); |
| 1950 | |
| 1951 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); |
| 1952 | if (!TSIOrErr) |
| 1953 | return TSIOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1954 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1955 | Bases.push_back( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1956 | new (Importer.getToContext()) CXXBaseSpecifier( |
| 1957 | *RangeOrErr, |
| 1958 | Base1.isVirtual(), |
| 1959 | Base1.isBaseOfClass(), |
| 1960 | Base1.getAccessSpecifierAsWritten(), |
| 1961 | *TSIOrErr, |
| 1962 | EllipsisLoc)); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1963 | } |
| 1964 | if (!Bases.empty()) |
| Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1965 | ToCXX->setBases(Bases.data(), Bases.size()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1966 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1967 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1968 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1969 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1970 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1971 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1972 | return Error::success(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1973 | } |
| 1974 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1975 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1976 | if (To->getAnyInitializer()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1977 | return Error::success(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1978 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1979 | Expr *FromInit = From->getInit(); |
| 1980 | if (!FromInit) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1981 | return Error::success(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1982 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1983 | ExpectedExpr ToInitOrErr = import(FromInit); |
| 1984 | if (!ToInitOrErr) |
| 1985 | return ToInitOrErr.takeError(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1986 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1987 | To->setInit(*ToInitOrErr); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1988 | if (From->isInitKnownICE()) { |
| 1989 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); |
| 1990 | Eval->CheckedICE = true; |
| 1991 | Eval->IsICE = From->isInitICE(); |
| 1992 | } |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1993 | |
| 1994 | // FIXME: Other bits to merge? |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1995 | return Error::success(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1998 | Error ASTNodeImporter::ImportDefinition( |
| 1999 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2000 | if (To->getDefinition() || To->isBeingDefined()) { |
| 2001 | if (Kind == IDK_Everything) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2002 | return ImportDeclContext(From, /*ForceImport=*/true); |
| 2003 | return Error::success(); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2004 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2005 | |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2006 | To->startDefinition(); |
| 2007 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2008 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 2009 | return Err; |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 2010 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2011 | ExpectedType ToTypeOrErr = |
| 2012 | import(Importer.getFromContext().getTypeDeclType(From)); |
| 2013 | if (!ToTypeOrErr) |
| 2014 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2015 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2016 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); |
| 2017 | if (!ToPromotionTypeOrErr) |
| 2018 | return ToPromotionTypeOrErr.takeError(); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2019 | |
| 2020 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2021 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 2022 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2023 | |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2024 | // FIXME: we might need to merge the number of positive or negative bits |
| 2025 | // if the enumerator lists don't match. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2026 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2027 | From->getNumPositiveBits(), |
| 2028 | From->getNumNegativeBits()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2029 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2030 | } |
| 2031 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2032 | Error ASTNodeImporter::ImportTemplateArguments( |
| 2033 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 2034 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 2035 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2036 | if (auto ToOrErr = import(FromArgs[I])) |
| 2037 | ToArgs.push_back(*ToOrErr); |
| 2038 | else |
| 2039 | return ToOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 2040 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2041 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2042 | return Error::success(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 2043 | } |
| 2044 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2045 | // FIXME: Do not forget to remove this and use only 'import'. |
| 2046 | Expected<TemplateArgument> |
| 2047 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 2048 | return import(From); |
| 2049 | } |
| 2050 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2051 | template <typename InContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2052 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2053 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 2054 | for (const auto &FromLoc : Container) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2055 | if (auto ToLocOrErr = import(FromLoc)) |
| 2056 | ToTAInfo.addArgument(*ToLocOrErr); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2057 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2058 | return ToLocOrErr.takeError(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2059 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2060 | return Error::success(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2063 | static StructuralEquivalenceKind |
| 2064 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 2065 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 2066 | : StructuralEquivalenceKind::Default; |
| 2067 | } |
| 2068 | |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2069 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { |
| 2070 | StructuralEquivalenceContext Ctx( |
| 2071 | Importer.getFromContext(), Importer.getToContext(), |
| 2072 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2073 | false, Complain); |
| 2074 | return Ctx.IsEquivalent(From, To); |
| 2075 | } |
| 2076 | |
| 2077 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2078 | RecordDecl *ToRecord, bool Complain) { |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2079 | // Eliminate a potential failure point where we attempt to re-import |
| 2080 | // something we're trying to import while completing ToRecord. |
| 2081 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 2082 | if (ToOrigin) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2083 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2084 | if (ToOriginRecord) |
| 2085 | ToRecord = ToOriginRecord; |
| 2086 | } |
| 2087 | |
| Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 2088 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2089 | ToRecord->getASTContext(), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2090 | Importer.getNonEquivalentDecls(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2091 | getStructuralEquivalenceKind(Importer), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2092 | false, Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2093 | return Ctx.IsEquivalent(FromRecord, ToRecord); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2094 | } |
| 2095 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2096 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 2097 | bool Complain) { |
| 2098 | StructuralEquivalenceContext Ctx( |
| 2099 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2100 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2101 | false, Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2102 | return Ctx.IsEquivalent(FromVar, ToVar); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2103 | } |
| 2104 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2105 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
| Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 2106 | // Eliminate a potential failure point where we attempt to re-import |
| Raphael Isemann | fa26c20 | 2019-04-09 14:18:23 +0000 | [diff] [blame] | 2107 | // something we're trying to import while completing ToEnum. |
| Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 2108 | if (Decl *ToOrigin = Importer.GetOriginalDecl(ToEnum)) |
| 2109 | if (auto *ToOriginEnum = dyn_cast<EnumDecl>(ToOrigin)) |
| 2110 | ToEnum = ToOriginEnum; |
| 2111 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2112 | StructuralEquivalenceContext Ctx( |
| 2113 | Importer.getFromContext(), Importer.getToContext(), |
| 2114 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2115 | return Ctx.IsEquivalent(FromEnum, ToEnum); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2116 | } |
| 2117 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2118 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 2119 | FunctionTemplateDecl *To) { |
| 2120 | StructuralEquivalenceContext Ctx( |
| 2121 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2122 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2123 | false, false); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2124 | return Ctx.IsEquivalent(From, To); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2125 | } |
| 2126 | |
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2127 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 2128 | StructuralEquivalenceContext Ctx( |
| 2129 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2130 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2131 | false, false); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2132 | return Ctx.IsEquivalent(From, To); |
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2133 | } |
| 2134 | |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2135 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2136 | EnumConstantDecl *ToEC) { |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2137 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 2138 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 2139 | |
| 2140 | return FromVal.isSigned() == ToVal.isSigned() && |
| 2141 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 2142 | FromVal == ToVal; |
| 2143 | } |
| 2144 | |
| 2145 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2146 | ClassTemplateDecl *To) { |
| 2147 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2148 | Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2149 | Importer.getNonEquivalentDecls(), |
| 2150 | getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2151 | return Ctx.IsEquivalent(From, To); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2152 | } |
| 2153 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2154 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 2155 | VarTemplateDecl *To) { |
| 2156 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2157 | Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2158 | Importer.getNonEquivalentDecls(), |
| 2159 | getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2160 | return Ctx.IsEquivalent(From, To); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2161 | } |
| 2162 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2163 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 2164 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2165 | << D->getDeclKindName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2166 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2167 | } |
| 2168 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2169 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { |
| 2170 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 2171 | << D->getDeclKindName(); |
| 2172 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| 2173 | } |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2174 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2175 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 2176 | // Import the context of this declaration. |
| 2177 | DeclContext *DC, *LexicalDC; |
| 2178 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 2179 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2180 | |
| 2181 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2182 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2183 | if (!LocOrErr) |
| 2184 | return LocOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2185 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2186 | EmptyDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2187 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2188 | return ToD; |
| 2189 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2190 | ToD->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2191 | LexicalDC->addDeclInternal(ToD); |
| 2192 | return ToD; |
| 2193 | } |
| 2194 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2195 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2196 | TranslationUnitDecl *ToD = |
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2197 | Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2198 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2199 | Importer.MapImported(D, ToD); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2200 | |
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2201 | return ToD; |
| 2202 | } |
| 2203 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2204 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 2205 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2206 | if (!LocOrErr) |
| 2207 | return LocOrErr.takeError(); |
| 2208 | auto ColonLocOrErr = import(D->getColonLoc()); |
| 2209 | if (!ColonLocOrErr) |
| 2210 | return ColonLocOrErr.takeError(); |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2211 | |
| 2212 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2213 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2214 | if (!DCOrErr) |
| 2215 | return DCOrErr.takeError(); |
| 2216 | DeclContext *DC = *DCOrErr; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2217 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2218 | AccessSpecDecl *ToD; |
| 2219 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2220 | DC, *LocOrErr, *ColonLocOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2221 | return ToD; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2222 | |
| 2223 | // Lexical DeclContext and Semantic DeclContext |
| 2224 | // is always the same for the accessSpec. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2225 | ToD->setLexicalDeclContext(DC); |
| 2226 | DC->addDeclInternal(ToD); |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2227 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2228 | return ToD; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2229 | } |
| 2230 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2231 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 2232 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2233 | if (!DCOrErr) |
| 2234 | return DCOrErr.takeError(); |
| 2235 | DeclContext *DC = *DCOrErr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2236 | DeclContext *LexicalDC = DC; |
| 2237 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2238 | Error Err = Error::success(); |
| 2239 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 2240 | auto ToRParenLoc = importChecked(Err, D->getRParenLoc()); |
| 2241 | auto ToAssertExpr = importChecked(Err, D->getAssertExpr()); |
| 2242 | auto ToMessage = importChecked(Err, D->getMessage()); |
| 2243 | if (Err) |
| 2244 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2245 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2246 | StaticAssertDecl *ToD; |
| 2247 | if (GetImportedOrCreateDecl( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2248 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, |
| 2249 | ToRParenLoc, D->isFailed())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2250 | return ToD; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2251 | |
| 2252 | ToD->setLexicalDeclContext(LexicalDC); |
| 2253 | LexicalDC->addDeclInternal(ToD); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2254 | return ToD; |
| 2255 | } |
| 2256 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2257 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2258 | // Import the major distinguishing characteristics of this namespace. |
| 2259 | DeclContext *DC, *LexicalDC; |
| 2260 | DeclarationName Name; |
| 2261 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2262 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2263 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2264 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2265 | if (ToD) |
| 2266 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2267 | |
| 2268 | NamespaceDecl *MergeWithNamespace = nullptr; |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2269 | if (!Name) { |
| 2270 | // This is an anonymous namespace. Adopt an existing anonymous |
| 2271 | // namespace if we can. |
| 2272 | // FIXME: Not testable. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2273 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2274 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 2275 | else |
| 2276 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 2277 | } else { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2278 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2279 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2280 | for (auto *FoundDecl : FoundDecls) { |
| 2281 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2282 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2283 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2284 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2285 | MergeWithNamespace = FoundNS; |
| 2286 | ConflictingDecls.clear(); |
| 2287 | break; |
| 2288 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2289 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2290 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2291 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2292 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2293 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2294 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2295 | Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(), |
| 2296 | ConflictingDecls.size()); |
| 2297 | if (NameOrErr) |
| 2298 | Name = NameOrErr.get(); |
| 2299 | else |
| 2300 | return NameOrErr.takeError(); |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2301 | } |
| 2302 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2303 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2304 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2305 | if (!BeginLocOrErr) |
| 2306 | return BeginLocOrErr.takeError(); |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2307 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 2308 | if (!RBraceLocOrErr) |
| 2309 | return RBraceLocOrErr.takeError(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2310 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2311 | // Create the "to" namespace, if needed. |
| 2312 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 2313 | if (!ToNamespace) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2314 | if (GetImportedOrCreateDecl( |
| 2315 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2316 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2317 | /*PrevDecl=*/nullptr)) |
| 2318 | return ToNamespace; |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2319 | ToNamespace->setRBraceLoc(*RBraceLocOrErr); |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2320 | ToNamespace->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2321 | LexicalDC->addDeclInternal(ToNamespace); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2322 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2323 | // If this is an anonymous namespace, register it as the anonymous |
| 2324 | // namespace within its context. |
| 2325 | if (!Name) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2326 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2327 | TU->setAnonymousNamespace(ToNamespace); |
| 2328 | else |
| 2329 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 2330 | } |
| 2331 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2332 | Importer.MapImported(D, ToNamespace); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2333 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2334 | if (Error Err = ImportDeclContext(D)) |
| 2335 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2336 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2337 | return ToNamespace; |
| 2338 | } |
| 2339 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2340 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2341 | // Import the major distinguishing characteristics of this namespace. |
| 2342 | DeclContext *DC, *LexicalDC; |
| 2343 | DeclarationName Name; |
| 2344 | SourceLocation Loc; |
| 2345 | NamedDecl *LookupD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2346 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 2347 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2348 | if (LookupD) |
| 2349 | return LookupD; |
| 2350 | |
| 2351 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 2352 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2353 | Error Err = Error::success(); |
| 2354 | auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc()); |
| 2355 | auto ToAliasLoc = importChecked(Err, D->getAliasLoc()); |
| 2356 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 2357 | auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc()); |
| 2358 | auto ToNamespace = importChecked(Err, D->getNamespace()); |
| 2359 | if (Err) |
| 2360 | return std::move(Err); |
| 2361 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2362 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2363 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2364 | NamespaceAliasDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2365 | if (GetImportedOrCreateDecl( |
| 2366 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, |
| 2367 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2368 | return ToD; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2369 | |
| 2370 | ToD->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2371 | LexicalDC->addDeclInternal(ToD); |
| 2372 | |
| 2373 | return ToD; |
| 2374 | } |
| 2375 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2376 | ExpectedDecl |
| 2377 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2378 | // Import the major distinguishing characteristics of this typedef. |
| 2379 | DeclContext *DC, *LexicalDC; |
| 2380 | DeclarationName Name; |
| 2381 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2382 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2383 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2384 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2385 | if (ToD) |
| 2386 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2387 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2388 | // If this typedef is not in block scope, determine whether we've |
| 2389 | // seen a typedef with the same name (that we can merge with) or any |
| 2390 | // other entity by that name (which name lookup could conflict with). |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 2391 | // Note: Repeated typedefs are not valid in C99: |
| 2392 | // 'typedef int T; typedef int T;' is invalid |
| 2393 | // We do not care about this now. |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2394 | if (!DC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2395 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2396 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2397 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2398 | for (auto *FoundDecl : FoundDecls) { |
| 2399 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2400 | continue; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2401 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 2402 | if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D)) |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 2403 | continue; |
| 2404 | |
| Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2405 | QualType FromUT = D->getUnderlyingType(); |
| 2406 | QualType FoundUT = FoundTypedef->getUnderlyingType(); |
| 2407 | if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) { |
| 2408 | // If the "From" context has a complete underlying type but we |
| 2409 | // already have a complete underlying type then return with that. |
| 2410 | if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2411 | return Importer.MapImported(D, FoundTypedef); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2412 | // FIXME Handle redecl chain. When you do that make consistent changes |
| 2413 | // in ASTImporterLookupTable too. |
| 2414 | } else { |
| 2415 | ConflictingDecls.push_back(FoundDecl); |
| Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2416 | } |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2417 | } |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2418 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2419 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2420 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2421 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2422 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 2423 | if (NameOrErr) |
| 2424 | Name = NameOrErr.get(); |
| 2425 | else |
| 2426 | return NameOrErr.takeError(); |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2427 | } |
| 2428 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2429 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2430 | Error Err = Error::success(); |
| 2431 | auto ToUnderlyingType = importChecked(Err, D->getUnderlyingType()); |
| 2432 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 2433 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); |
| 2434 | if (Err) |
| 2435 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2436 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2437 | // Create the new typedef node. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2438 | // FIXME: ToUnderlyingType is not used. |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2439 | (void)ToUnderlyingType; |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2440 | TypedefNameDecl *ToTypedef; |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2441 | if (IsAlias) { |
| 2442 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2443 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2444 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2445 | return ToTypedef; |
| 2446 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2447 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2448 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2449 | return ToTypedef; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2450 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2451 | ToTypedef->setAccess(D->getAccess()); |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2452 | ToTypedef->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2453 | |
| 2454 | // Templated declarations should not appear in DeclContext. |
| 2455 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 2456 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 2457 | LexicalDC->addDeclInternal(ToTypedef); |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2458 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2459 | return ToTypedef; |
| 2460 | } |
| 2461 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2462 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2463 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 2464 | } |
| 2465 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2466 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2467 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 2468 | } |
| 2469 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2470 | ExpectedDecl |
| 2471 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2472 | // Import the major distinguishing characteristics of this typedef. |
| 2473 | DeclContext *DC, *LexicalDC; |
| 2474 | DeclarationName Name; |
| 2475 | SourceLocation Loc; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2476 | NamedDecl *FoundD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2477 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
| 2478 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2479 | if (FoundD) |
| 2480 | return FoundD; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2481 | |
| 2482 | // If this typedef is not in block scope, determine whether we've |
| 2483 | // seen a typedef with the same name (that we can merge with) or any |
| 2484 | // other entity by that name (which name lookup could conflict with). |
| 2485 | if (!DC->isFunctionOrMethod()) { |
| 2486 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 2487 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2488 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2489 | for (auto *FoundDecl : FoundDecls) { |
| 2490 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2491 | continue; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2492 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2493 | return Importer.MapImported(D, FoundAlias); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2494 | ConflictingDecls.push_back(FoundDecl); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2498 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2499 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 2500 | if (NameOrErr) |
| 2501 | Name = NameOrErr.get(); |
| 2502 | else |
| 2503 | return NameOrErr.takeError(); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2504 | } |
| 2505 | } |
| 2506 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2507 | Error Err = Error::success(); |
| 2508 | auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters()); |
| 2509 | auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl()); |
| 2510 | if (Err) |
| 2511 | return std::move(Err); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2512 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2513 | TypeAliasTemplateDecl *ToAlias; |
| 2514 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2515 | Name, ToTemplateParameters, ToTemplatedDecl)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2516 | return ToAlias; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2517 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2518 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2519 | |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2520 | ToAlias->setAccess(D->getAccess()); |
| 2521 | ToAlias->setLexicalDeclContext(LexicalDC); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2522 | LexicalDC->addDeclInternal(ToAlias); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2523 | return ToAlias; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2524 | } |
| 2525 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2526 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2527 | // Import the major distinguishing characteristics of this label. |
| 2528 | DeclContext *DC, *LexicalDC; |
| 2529 | DeclarationName Name; |
| 2530 | SourceLocation Loc; |
| 2531 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2532 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2533 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2534 | if (ToD) |
| 2535 | return ToD; |
| 2536 | |
| 2537 | assert(LexicalDC->isFunctionOrMethod()); |
| 2538 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2539 | LabelDecl *ToLabel; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2540 | if (D->isGnuLocal()) { |
| 2541 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2542 | if (!BeginLocOrErr) |
| 2543 | return BeginLocOrErr.takeError(); |
| 2544 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2545 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) |
| 2546 | return ToLabel; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2547 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2548 | } else { |
| 2549 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2550 | Name.getAsIdentifierInfo())) |
| 2551 | return ToLabel; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2552 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); |
| 2556 | if (!ToStmtOrErr) |
| 2557 | return ToStmtOrErr.takeError(); |
| 2558 | |
| 2559 | ToLabel->setStmt(*ToStmtOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2560 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2561 | LexicalDC->addDeclInternal(ToLabel); |
| 2562 | return ToLabel; |
| 2563 | } |
| 2564 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2565 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2566 | // Import the major distinguishing characteristics of this enum. |
| 2567 | DeclContext *DC, *LexicalDC; |
| 2568 | DeclarationName Name; |
| 2569 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2570 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2571 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2572 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2573 | if (ToD) |
| 2574 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2575 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2576 | // Figure out what enum name we're looking for. |
| 2577 | unsigned IDNS = Decl::IDNS_Tag; |
| 2578 | DeclarationName SearchName = Name; |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2579 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2580 | if (Error Err = importInto( |
| 2581 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2582 | return std::move(Err); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2583 | IDNS = Decl::IDNS_Ordinary; |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2584 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2585 | IDNS |= Decl::IDNS_Ordinary; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2586 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2587 | // 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] | 2588 | EnumDecl *PrevDecl = nullptr; |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2589 | if (!DC->isFunctionOrMethod() && SearchName) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2590 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2591 | auto FoundDecls = |
| 2592 | Importer.findDeclsInToCtx(DC, SearchName); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2593 | for (auto *FoundDecl : FoundDecls) { |
| 2594 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2595 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2596 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2597 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2598 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2599 | FoundDecl = Tag->getDecl(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2600 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2601 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2602 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 2603 | if (!hasSameVisibilityContextAndLinkage(FoundEnum, D)) |
| Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 2604 | continue; |
| Balázs Kéri | d4741c4 | 2020-02-17 14:25:16 +0100 | [diff] [blame] | 2605 | if (IsStructuralMatch(D, FoundEnum)) { |
| 2606 | EnumDecl *FoundDef = FoundEnum->getDefinition(); |
| 2607 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 2608 | return Importer.MapImported(D, FoundDef); |
| 2609 | PrevDecl = FoundEnum->getMostRecentDecl(); |
| 2610 | break; |
| 2611 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2612 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2613 | } |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2614 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2615 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2616 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2617 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2618 | SearchName, DC, IDNS, ConflictingDecls.data(), |
| 2619 | ConflictingDecls.size()); |
| 2620 | if (NameOrErr) |
| 2621 | Name = NameOrErr.get(); |
| 2622 | else |
| 2623 | return NameOrErr.takeError(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2624 | } |
| 2625 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2626 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2627 | Error Err = Error::success(); |
| 2628 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); |
| 2629 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 2630 | auto ToIntegerType = importChecked(Err, D->getIntegerType()); |
| 2631 | auto ToBraceRange = importChecked(Err, D->getBraceRange()); |
| 2632 | if (Err) |
| 2633 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2634 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2635 | // Create the enum declaration. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2636 | EnumDecl *D2; |
| 2637 | if (GetImportedOrCreateDecl( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2638 | D2, D, Importer.getToContext(), DC, ToBeginLoc, |
| Balázs Kéri | d4741c4 | 2020-02-17 14:25:16 +0100 | [diff] [blame] | 2639 | Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2640 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2641 | return D2; |
| 2642 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2643 | D2->setQualifierInfo(ToQualifierLoc); |
| 2644 | D2->setIntegerType(ToIntegerType); |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2645 | D2->setBraceRange(ToBraceRange); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2646 | D2->setAccess(D->getAccess()); |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2647 | D2->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2648 | LexicalDC->addDeclInternal(D2); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2649 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2650 | // Import the definition |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2651 | if (D->isCompleteDefinition()) |
| 2652 | if (Error Err = ImportDefinition(D, D2)) |
| 2653 | return std::move(Err); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2654 | |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2655 | return D2; |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2656 | } |
| 2657 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2658 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2659 | bool IsFriendTemplate = false; |
| 2660 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2661 | IsFriendTemplate = |
| 2662 | DCXX->getDescribedClassTemplate() && |
| 2663 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != |
| 2664 | Decl::FOK_None; |
| 2665 | } |
| 2666 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2667 | // Import the major distinguishing characteristics of this record. |
| Simon Pilgrim | 4706f3b | 2019-10-15 10:23:05 +0000 | [diff] [blame] | 2668 | DeclContext *DC = nullptr, *LexicalDC = nullptr; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2669 | DeclarationName Name; |
| 2670 | SourceLocation Loc; |
| Simon Pilgrim | 4706f3b | 2019-10-15 10:23:05 +0000 | [diff] [blame] | 2671 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2672 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2673 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2674 | if (ToD) |
| 2675 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2676 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2677 | // Figure out what structure name we're looking for. |
| 2678 | unsigned IDNS = Decl::IDNS_Tag; |
| 2679 | DeclarationName SearchName = Name; |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2680 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2681 | if (Error Err = importInto( |
| 2682 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2683 | return std::move(Err); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2684 | IDNS = Decl::IDNS_Ordinary; |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2685 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2686 | IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2687 | |
| 2688 | // 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] | 2689 | RecordDecl *PrevDecl = nullptr; |
| Gabor Marton | e3e83d7 | 2019-08-30 10:55:41 +0000 | [diff] [blame] | 2690 | if (!DC->isFunctionOrMethod() && !D->isLambda()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2691 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2692 | auto FoundDecls = |
| 2693 | Importer.findDeclsInToCtx(DC, SearchName); |
| Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2694 | if (!FoundDecls.empty()) { |
| Gabor Marton | 41e3892 | 2019-03-05 11:23:24 +0000 | [diff] [blame] | 2695 | // We're going to have to compare D against potentially conflicting Decls, |
| 2696 | // so complete it. |
| Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2697 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2698 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2699 | } |
| 2700 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2701 | for (auto *FoundDecl : FoundDecls) { |
| 2702 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2703 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2704 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2705 | Decl *Found = FoundDecl; |
| 2706 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2707 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2708 | Found = Tag->getDecl(); |
| 2709 | } |
| Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2710 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2711 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2712 | // Do not emit false positive diagnostic in case of unnamed |
| 2713 | // struct/union and in case of anonymous structs. Would be false |
| 2714 | // because there may be several anonymous/unnamed structs in a class. |
| 2715 | // E.g. these are both valid: |
| 2716 | // struct A { // unnamed structs |
| 2717 | // struct { struct A *next; } entry0; |
| 2718 | // struct { struct A *next; } entry1; |
| 2719 | // }; |
| 2720 | // struct X { struct { int a; }; struct { int b; }; }; // anon structs |
| 2721 | if (!SearchName) |
| Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2722 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2723 | continue; |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2724 | |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 2725 | if (!hasSameVisibilityContextAndLinkage(FoundRecord, D)) |
| Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 2726 | continue; |
| 2727 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2728 | if (IsStructuralMatch(D, FoundRecord)) { |
| 2729 | RecordDecl *FoundDef = FoundRecord->getDefinition(); |
| 2730 | if (D->isThisDeclarationADefinition() && FoundDef) { |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2731 | // FIXME: Structural equivalence check should check for same |
| 2732 | // user-defined methods. |
| 2733 | Importer.MapImported(D, FoundDef); |
| 2734 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2735 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); |
| 2736 | assert(FoundCXX && "Record type mismatch"); |
| 2737 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2738 | if (!Importer.isMinimalImport()) |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2739 | // FoundDef may not have every implicit method that D has |
| 2740 | // because implicit methods are created only if they are used. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2741 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) |
| 2742 | return std::move(Err); |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2743 | } |
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2744 | } |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2745 | PrevDecl = FoundRecord->getMostRecentDecl(); |
| 2746 | break; |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2747 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2748 | ConflictingDecls.push_back(FoundDecl); |
| 2749 | } // kind is RecordDecl |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2750 | } // for |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2751 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2752 | if (!ConflictingDecls.empty() && SearchName) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2753 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2754 | SearchName, DC, IDNS, ConflictingDecls.data(), |
| 2755 | ConflictingDecls.size()); |
| 2756 | if (NameOrErr) |
| 2757 | Name = NameOrErr.get(); |
| 2758 | else |
| 2759 | return NameOrErr.takeError(); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2760 | } |
| 2761 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2762 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2763 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2764 | if (!BeginLocOrErr) |
| 2765 | return BeginLocOrErr.takeError(); |
| 2766 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2767 | // Create the record declaration. |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2768 | RecordDecl *D2 = nullptr; |
| 2769 | CXXRecordDecl *D2CXX = nullptr; |
| 2770 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2771 | if (DCXX->isLambda()) { |
| 2772 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); |
| 2773 | if (!TInfoOrErr) |
| 2774 | return TInfoOrErr.takeError(); |
| 2775 | if (GetImportedOrCreateSpecialDecl( |
| 2776 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
| 2777 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), |
| 2778 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2779 | return D2CXX; |
| 2780 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); |
| 2781 | if (!CDeclOrErr) |
| 2782 | return CDeclOrErr.takeError(); |
| Michael Liao | 243ebfb | 2019-10-19 00:15:19 +0000 | [diff] [blame] | 2783 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr, |
| 2784 | DCXX->hasKnownLambdaInternalLinkage()); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2785 | } else if (DCXX->isInjectedClassName()) { |
| 2786 | // We have to be careful to do a similar dance to the one in |
| 2787 | // Sema::ActOnStartCXXMemberDeclarations |
| 2788 | const bool DelayTypeCreation = true; |
| 2789 | if (GetImportedOrCreateDecl( |
| 2790 | D2CXX, D, Importer.getToContext(), D->getTagKind(), DC, |
| 2791 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
| 2792 | cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation)) |
| 2793 | return D2CXX; |
| 2794 | Importer.getToContext().getTypeDeclType( |
| 2795 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
| 2796 | } else { |
| 2797 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2798 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2799 | Name.getAsIdentifierInfo(), |
| 2800 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2801 | return D2CXX; |
| 2802 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2803 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2804 | D2 = D2CXX; |
| 2805 | D2->setAccess(D->getAccess()); |
| 2806 | D2->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 2807 | addDeclToContexts(D, D2); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2808 | |
| 2809 | if (ClassTemplateDecl *FromDescribed = |
| 2810 | DCXX->getDescribedClassTemplate()) { |
| 2811 | ClassTemplateDecl *ToDescribed; |
| 2812 | if (Error Err = importInto(ToDescribed, FromDescribed)) |
| 2813 | return std::move(Err); |
| 2814 | D2CXX->setDescribedClassTemplate(ToDescribed); |
| 2815 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { |
| 2816 | // In a record describing a template the type should be an |
| 2817 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2818 | // previously set type to the correct value here (ToDescribed is not |
| 2819 | // available at record create). |
| 2820 | // FIXME: The previous type is cleared but not removed from |
| 2821 | // ASTContext's internal storage. |
| 2822 | CXXRecordDecl *Injected = nullptr; |
| 2823 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2824 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2825 | if (Record && Record->isInjectedClassName()) { |
| 2826 | Injected = Record; |
| 2827 | break; |
| Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2828 | } |
| 2829 | } |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2830 | // Create an injected type for the whole redecl chain. |
| 2831 | SmallVector<Decl *, 2> Redecls = |
| 2832 | getCanonicalForwardRedeclChain(D2CXX); |
| 2833 | for (auto *R : Redecls) { |
| 2834 | auto *RI = cast<CXXRecordDecl>(R); |
| 2835 | RI->setTypeForDecl(nullptr); |
| 2836 | // Below we create a new injected type and assign that to the |
| 2837 | // canonical decl, subsequent declarations in the chain will reuse |
| 2838 | // that type. |
| 2839 | Importer.getToContext().getInjectedClassNameType( |
| 2840 | RI, ToDescribed->getInjectedClassNameSpecialization()); |
| 2841 | } |
| 2842 | // Set the new type for the previous injected decl too. |
| 2843 | if (Injected) { |
| 2844 | Injected->setTypeForDecl(nullptr); |
| 2845 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2846 | } |
| 2847 | } |
| 2848 | } else if (MemberSpecializationInfo *MemberInfo = |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2849 | DCXX->getMemberSpecializationInfo()) { |
| 2850 | TemplateSpecializationKind SK = |
| 2851 | MemberInfo->getTemplateSpecializationKind(); |
| 2852 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2853 | |
| 2854 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) |
| 2855 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); |
| 2856 | else |
| 2857 | return ToInstOrErr.takeError(); |
| 2858 | |
| 2859 | if (ExpectedSLoc POIOrErr = |
| 2860 | import(MemberInfo->getPointOfInstantiation())) |
| 2861 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2862 | *POIOrErr); |
| 2863 | else |
| 2864 | return POIOrErr.takeError(); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2865 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2866 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2867 | } else { |
| 2868 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
| 2869 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2870 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2871 | return D2; |
| 2872 | D2->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 2873 | addDeclToContexts(D, D2); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2874 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2875 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2876 | if (auto BraceRangeOrErr = import(D->getBraceRange())) |
| 2877 | D2->setBraceRange(*BraceRangeOrErr); |
| 2878 | else |
| 2879 | return BraceRangeOrErr.takeError(); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2880 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) |
| 2881 | D2->setQualifierInfo(*QualifierLocOrErr); |
| 2882 | else |
| 2883 | return QualifierLocOrErr.takeError(); |
| 2884 | |
| 2885 | if (D->isAnonymousStructOrUnion()) |
| 2886 | D2->setAnonymousStructOrUnion(true); |
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2887 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2888 | if (D->isCompleteDefinition()) |
| 2889 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) |
| 2890 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2891 | |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2892 | return D2; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2893 | } |
| 2894 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2895 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2896 | // Import the major distinguishing characteristics of this enumerator. |
| 2897 | DeclContext *DC, *LexicalDC; |
| 2898 | DeclarationName Name; |
| 2899 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2900 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2901 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2902 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2903 | if (ToD) |
| 2904 | return ToD; |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2905 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2906 | // Determine whether there are any other declarations with the same name and |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2907 | // in the same context. |
| 2908 | if (!LexicalDC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2909 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2910 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2911 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2912 | for (auto *FoundDecl : FoundDecls) { |
| 2913 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2914 | continue; |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2915 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2916 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2917 | if (IsStructuralMatch(D, FoundEnumConstant)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2918 | return Importer.MapImported(D, FoundEnumConstant); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2919 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2920 | } |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2921 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2922 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2923 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2924 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2925 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 2926 | if (NameOrErr) |
| 2927 | Name = NameOrErr.get(); |
| 2928 | else |
| 2929 | return NameOrErr.takeError(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2930 | } |
| 2931 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2932 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2933 | ExpectedType TypeOrErr = import(D->getType()); |
| 2934 | if (!TypeOrErr) |
| 2935 | return TypeOrErr.takeError(); |
| 2936 | |
| 2937 | ExpectedExpr InitOrErr = import(D->getInitExpr()); |
| 2938 | if (!InitOrErr) |
| 2939 | return InitOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2940 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2941 | EnumConstantDecl *ToEnumerator; |
| 2942 | if (GetImportedOrCreateDecl( |
| 2943 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2944 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2945 | return ToEnumerator; |
| 2946 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2947 | ToEnumerator->setAccess(D->getAccess()); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2948 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2949 | LexicalDC->addDeclInternal(ToEnumerator); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2950 | return ToEnumerator; |
| 2951 | } |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2952 | |
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 2953 | Error ASTNodeImporter::ImportTemplateParameterLists(const DeclaratorDecl *FromD, |
| 2954 | DeclaratorDecl *ToD) { |
| 2955 | unsigned int Num = FromD->getNumTemplateParameterLists(); |
| 2956 | if (Num == 0) |
| 2957 | return Error::success(); |
| 2958 | SmallVector<TemplateParameterList *, 2> ToTPLists(Num); |
| 2959 | for (unsigned int I = 0; I < Num; ++I) |
| 2960 | if (Expected<TemplateParameterList *> ToTPListOrErr = |
| 2961 | import(FromD->getTemplateParameterList(I))) |
| 2962 | ToTPLists[I] = *ToTPListOrErr; |
| 2963 | else |
| 2964 | return ToTPListOrErr.takeError(); |
| 2965 | ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists); |
| 2966 | return Error::success(); |
| 2967 | } |
| 2968 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2969 | Error ASTNodeImporter::ImportTemplateInformation( |
| 2970 | FunctionDecl *FromFD, FunctionDecl *ToFD) { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2971 | switch (FromFD->getTemplatedKind()) { |
| 2972 | case FunctionDecl::TK_NonTemplate: |
| 2973 | case FunctionDecl::TK_FunctionTemplate: |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2974 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2975 | |
| 2976 | case FunctionDecl::TK_MemberSpecialization: { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2977 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2978 | |
| 2979 | if (Expected<FunctionDecl *> InstFDOrErr = |
| 2980 | import(FromFD->getInstantiatedFromMemberFunction())) |
| 2981 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); |
| 2982 | else |
| 2983 | return InstFDOrErr.takeError(); |
| 2984 | |
| 2985 | if (ExpectedSLoc POIOrErr = import( |
| 2986 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) |
| 2987 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); |
| 2988 | else |
| 2989 | return POIOrErr.takeError(); |
| 2990 | |
| 2991 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2992 | } |
| 2993 | |
| 2994 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2995 | auto FunctionAndArgsOrErr = |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2996 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2997 | if (!FunctionAndArgsOrErr) |
| 2998 | return FunctionAndArgsOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2999 | |
| 3000 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3001 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3002 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3003 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3004 | TemplateArgumentListInfo ToTAInfo; |
| 3005 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3006 | if (FromTAArgsAsWritten) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3007 | if (Error Err = ImportTemplateArgumentListInfo( |
| 3008 | *FromTAArgsAsWritten, ToTAInfo)) |
| 3009 | return Err; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3010 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3011 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); |
| 3012 | if (!POIOrErr) |
| 3013 | return POIOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3014 | |
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 3015 | if (Error Err = ImportTemplateParameterLists(FromFD, ToFD)) |
| 3016 | return Err; |
| 3017 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3018 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3019 | ToFD->setFunctionTemplateSpecialization( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3020 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, |
| 3021 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); |
| 3022 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3023 | } |
| 3024 | |
| 3025 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 3026 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 3027 | UnresolvedSet<8> TemplDecls; |
| 3028 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 3029 | for (unsigned I = 0; I < NumTemplates; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3030 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = |
| 3031 | import(FromInfo->getTemplate(I))) |
| 3032 | TemplDecls.addDecl(*ToFTDOrErr); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3033 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3034 | return ToFTDOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | // Import TemplateArgumentListInfo. |
| 3038 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3039 | if (Error Err = ImportTemplateArgumentListInfo( |
| 3040 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 3041 | llvm::makeArrayRef( |
| 3042 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), |
| 3043 | ToTAInfo)) |
| 3044 | return Err; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3045 | |
| 3046 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 3047 | TemplDecls, ToTAInfo); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3048 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3049 | } |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3050 | } |
| Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 3051 | llvm_unreachable("All cases should be covered!"); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3052 | } |
| 3053 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3054 | Expected<FunctionDecl *> |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3055 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3056 | auto FunctionAndArgsOrErr = |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3057 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3058 | if (!FunctionAndArgsOrErr) |
| 3059 | return FunctionAndArgsOrErr.takeError(); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3060 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3061 | FunctionTemplateDecl *Template; |
| 3062 | TemplateArgsTy ToTemplArgs; |
| 3063 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3064 | void *InsertPos = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3065 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3066 | return FoundSpec; |
| 3067 | } |
| 3068 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3069 | Error ASTNodeImporter::ImportFunctionDeclBody(FunctionDecl *FromFD, |
| 3070 | FunctionDecl *ToFD) { |
| 3071 | if (Stmt *FromBody = FromFD->getBody()) { |
| 3072 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) |
| 3073 | ToFD->setBody(*ToBodyOrErr); |
| 3074 | else |
| 3075 | return ToBodyOrErr.takeError(); |
| 3076 | } |
| 3077 | return Error::success(); |
| 3078 | } |
| 3079 | |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3080 | // Returns true if the given D has a DeclContext up to the TranslationUnitDecl |
| 3081 | // which is equal to the given DC. |
| Benjamin Kramer | df18650 | 2020-01-14 14:06:12 +0100 | [diff] [blame] | 3082 | static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) { |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3083 | const DeclContext *DCi = D->getDeclContext(); |
| 3084 | while (DCi != D->getTranslationUnitDecl()) { |
| 3085 | if (DCi == DC) |
| 3086 | return true; |
| 3087 | DCi = DCi->getParent(); |
| 3088 | } |
| 3089 | return false; |
| 3090 | } |
| 3091 | |
| 3092 | bool ASTNodeImporter::hasAutoReturnTypeDeclaredInside(FunctionDecl *D) { |
| 3093 | QualType FromTy = D->getType(); |
| 3094 | const FunctionProtoType *FromFPT = FromTy->getAs<FunctionProtoType>(); |
| 3095 | assert(FromFPT && "Must be called on FunctionProtoType"); |
| 3096 | if (AutoType *AutoT = FromFPT->getReturnType()->getContainedAutoType()) { |
| 3097 | QualType DeducedT = AutoT->getDeducedType(); |
| 3098 | if (const RecordType *RecordT = |
| 3099 | DeducedT.isNull() ? nullptr : dyn_cast<RecordType>(DeducedT)) { |
| 3100 | RecordDecl *RD = RecordT->getDecl(); |
| 3101 | assert(RD); |
| 3102 | if (isAncestorDeclContextOf(D, RD)) { |
| 3103 | assert(RD->getLexicalDeclContext() == RD->getDeclContext()); |
| 3104 | return true; |
| 3105 | } |
| 3106 | } |
| 3107 | } |
| 3108 | if (const TypedefType *TypedefT = |
| 3109 | dyn_cast<TypedefType>(FromFPT->getReturnType())) { |
| 3110 | TypedefNameDecl *TD = TypedefT->getDecl(); |
| 3111 | assert(TD); |
| 3112 | if (isAncestorDeclContextOf(D, TD)) { |
| 3113 | assert(TD->getLexicalDeclContext() == TD->getDeclContext()); |
| 3114 | return true; |
| 3115 | } |
| 3116 | } |
| 3117 | return false; |
| 3118 | } |
| 3119 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3120 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3121 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3122 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3123 | auto RedeclIt = Redecls.begin(); |
| 3124 | // Import the first part of the decl chain. I.e. import all previous |
| 3125 | // declarations starting from the canonical decl. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3126 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3127 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3128 | if (!ToRedeclOrErr) |
| 3129 | return ToRedeclOrErr.takeError(); |
| 3130 | } |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3131 | assert(*RedeclIt == D); |
| 3132 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3133 | // Import the major distinguishing characteristics of this function. |
| 3134 | DeclContext *DC, *LexicalDC; |
| 3135 | DeclarationName Name; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3136 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3137 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3138 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3139 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3140 | if (ToD) |
| 3141 | return ToD; |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3142 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3143 | FunctionDecl *FoundByLookup = nullptr; |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3144 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); |
| Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 3145 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3146 | // 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] | 3147 | // existing specialization in the "to" context. The lookup below will not |
| 3148 | // find any specialization, but would find the primary template; thus, we |
| 3149 | // have to skip normal lookup in case of specializations. |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3150 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 3151 | if (D->getTemplatedKind() == |
| 3152 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3153 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); |
| 3154 | if (!FoundFunctionOrErr) |
| 3155 | return FoundFunctionOrErr.takeError(); |
| 3156 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { |
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 3157 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 3158 | return Def; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3159 | FoundByLookup = FoundFunction; |
| 3160 | } |
| 3161 | } |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3162 | // Try to find a function in our own ("to") context with the same name, same |
| 3163 | // type, and in the same context as the function we're importing. |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3164 | else if (!LexicalDC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3165 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3166 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3167 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3168 | for (auto *FoundDecl : FoundDecls) { |
| 3169 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3170 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3171 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3172 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 3173 | if (!hasSameVisibilityContextAndLinkage(FoundFunction, D)) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3174 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3175 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3176 | if (IsStructuralMatch(D, FoundFunction)) { |
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 3177 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 3178 | return Def; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3179 | FoundByLookup = FoundFunction; |
| 3180 | break; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3181 | } |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3182 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 3183 | // Sema::IsOverload out to the AST library. |
| 3184 | |
| 3185 | // Function overloading is okay in C++. |
| 3186 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
| 3187 | continue; |
| 3188 | |
| 3189 | // Complain about inconsistent function types. |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3190 | Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3191 | << Name << D->getType() << FoundFunction->getType(); |
| 3192 | Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here) |
| 3193 | << FoundFunction->getType(); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3194 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3195 | } |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3196 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3197 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3198 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3199 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 3200 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 3201 | if (NameOrErr) |
| 3202 | Name = NameOrErr.get(); |
| 3203 | else |
| 3204 | return NameOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3205 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3206 | } |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3207 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3208 | // We do not allow more than one in-class declaration of a function. This is |
| 3209 | // because AST clients like VTableBuilder asserts on this. VTableBuilder |
| 3210 | // assumes there is only one in-class declaration. Building a redecl |
| 3211 | // chain would result in more than one in-class declaration for |
| 3212 | // overrides (even if they are part of the same redecl chain inside the |
| 3213 | // derived class.) |
| 3214 | if (FoundByLookup) { |
| Mikael Holmen | c1c97aa | 2019-01-29 06:53:31 +0000 | [diff] [blame] | 3215 | if (isa<CXXMethodDecl>(FoundByLookup)) { |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3216 | if (D->getLexicalDeclContext() == D->getDeclContext()) { |
| Balazs Keri | e9719f9 | 2019-08-07 12:40:17 +0000 | [diff] [blame] | 3217 | if (!D->doesThisDeclarationHaveABody()) { |
| 3218 | if (FunctionTemplateDecl *DescribedD = |
| 3219 | D->getDescribedFunctionTemplate()) { |
| 3220 | // Handle a "templated" function together with its described |
| 3221 | // template. This avoids need for a similar check at import of the |
| 3222 | // described template. |
| 3223 | assert(FoundByLookup->getDescribedFunctionTemplate() && |
| 3224 | "Templated function mapped to non-templated?"); |
| 3225 | Importer.MapImported(DescribedD, |
| 3226 | FoundByLookup->getDescribedFunctionTemplate()); |
| 3227 | } |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3228 | return Importer.MapImported(D, FoundByLookup); |
| Balazs Keri | e9719f9 | 2019-08-07 12:40:17 +0000 | [diff] [blame] | 3229 | } else { |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3230 | // Let's continue and build up the redecl chain in this case. |
| 3231 | // FIXME Merge the functions into one decl. |
| 3232 | } |
| 3233 | } |
| 3234 | } |
| 3235 | } |
| 3236 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3237 | DeclarationNameInfo NameInfo(Name, Loc); |
| 3238 | // Import additional name location/type info. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3239 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 3240 | return std::move(Err); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3241 | |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3242 | QualType FromTy = D->getType(); |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3243 | // Set to true if we do not import the type of the function as is. There are |
| 3244 | // cases when the original type would result in an infinite recursion during |
| 3245 | // the import. To avoid an infinite recursion when importing, we create the |
| 3246 | // FunctionDecl with a simplified function type and update it only after the |
| 3247 | // relevant AST nodes are already imported. |
| 3248 | bool UsedDifferentProtoType = false; |
| 3249 | if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) { |
| 3250 | QualType FromReturnTy = FromFPT->getReturnType(); |
| 3251 | // Functions with auto return type may define a struct inside their body |
| 3252 | // and the return type could refer to that struct. |
| 3253 | // E.g.: auto foo() { struct X{}; return X(); } |
| 3254 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 3255 | // with a simplified return type. |
| 3256 | if (hasAutoReturnTypeDeclaredInside(D)) { |
| 3257 | FromReturnTy = Importer.getFromContext().VoidTy; |
| 3258 | UsedDifferentProtoType = true; |
| 3259 | } |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3260 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 3261 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 3262 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 3263 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3264 | // with a simplified function type. |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 3265 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 3266 | FromEPI.ExceptionSpec.SourceTemplate || |
| 3267 | FromEPI.ExceptionSpec.NoexceptExpr) { |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3268 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3269 | FromEPI = DefaultEPI; |
| 3270 | UsedDifferentProtoType = true; |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3271 | } |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3272 | FromTy = Importer.getFromContext().getFunctionType( |
| 3273 | FromReturnTy, FromFPT->getParamTypes(), FromEPI); |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3274 | } |
| 3275 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3276 | Error Err = Error::success(); |
| 3277 | auto T = importChecked(Err, FromTy); |
| 3278 | auto TInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 3279 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 3280 | auto ToEndLoc = importChecked(Err, D->getEndLoc()); |
| 3281 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 3282 | auto TrailingRequiresClause = |
| 3283 | importChecked(Err, D->getTrailingRequiresClause()); |
| 3284 | if (Err) |
| 3285 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3286 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3287 | // Import the function parameters. |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3288 | SmallVector<ParmVarDecl *, 8> Parameters; |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3289 | for (auto P : D->parameters()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3290 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) |
| 3291 | Parameters.push_back(*ToPOrErr); |
| 3292 | else |
| 3293 | return ToPOrErr.takeError(); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3294 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3295 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3296 | // Create the imported function. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3297 | FunctionDecl *ToFunction = nullptr; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3298 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3299 | Expr *ExplicitExpr = nullptr; |
| 3300 | if (FromConstructor->getExplicitSpecifier().getExpr()) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3301 | auto Imp = import(FromConstructor->getExplicitSpecifier().getExpr()); |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3302 | if (!Imp) |
| 3303 | return Imp.takeError(); |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3304 | ExplicitExpr = *Imp; |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3305 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3306 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3307 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3308 | ToInnerLocStart, NameInfo, T, TInfo, |
| 3309 | ExplicitSpecifier( |
| 3310 | ExplicitExpr, |
| 3311 | FromConstructor->getExplicitSpecifier().getKind()), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3312 | D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(), |
| 3313 | InheritedConstructor(), // FIXME: Properly import inherited |
| 3314 | // constructor info |
| 3315 | TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3316 | return ToFunction; |
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3317 | } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { |
| 3318 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3319 | Error Err = Error::success(); |
| 3320 | auto ToOperatorDelete = importChecked( |
| 3321 | Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete())); |
| 3322 | auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg()); |
| 3323 | if (Err) |
| 3324 | return std::move(Err); |
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3325 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3326 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3327 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3328 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3329 | D->isImplicit(), D->getConstexprKind(), TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3330 | return ToFunction; |
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3331 | |
| 3332 | CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction); |
| 3333 | |
| 3334 | ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3335 | } else if (CXXConversionDecl *FromConversion = |
| 3336 | dyn_cast<CXXConversionDecl>(D)) { |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3337 | Expr *ExplicitExpr = nullptr; |
| 3338 | if (FromConversion->getExplicitSpecifier().getExpr()) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3339 | auto Imp = import(FromConversion->getExplicitSpecifier().getExpr()); |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3340 | if (!Imp) |
| 3341 | return Imp.takeError(); |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3342 | ExplicitExpr = *Imp; |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3343 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3344 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 3345 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3346 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3347 | ExplicitSpecifier(ExplicitExpr, |
| 3348 | FromConversion->getExplicitSpecifier().getKind()), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3349 | D->getConstexprKind(), SourceLocation(), TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3350 | return ToFunction; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3351 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3352 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 3353 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3354 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3355 | Method->isInlineSpecified(), D->getConstexprKind(), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3356 | SourceLocation(), TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3357 | return ToFunction; |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3358 | } else { |
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3359 | if (GetImportedOrCreateDecl( |
| 3360 | ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, |
| 3361 | NameInfo, T, TInfo, D->getStorageClass(), D->isInlineSpecified(), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3362 | D->hasWrittenPrototype(), D->getConstexprKind(), |
| 3363 | TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3364 | return ToFunction; |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3365 | } |
| John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3366 | |
| Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3367 | // Connect the redecl chain. |
| 3368 | if (FoundByLookup) { |
| 3369 | auto *Recent = const_cast<FunctionDecl *>( |
| 3370 | FoundByLookup->getMostRecentDecl()); |
| 3371 | ToFunction->setPreviousDecl(Recent); |
| Gabor Marton | ce6b781 | 2019-05-08 15:23:48 +0000 | [diff] [blame] | 3372 | // FIXME Probably we should merge exception specifications. E.g. In the |
| 3373 | // "To" context the existing function may have exception specification with |
| 3374 | // noexcept-unevaluated, while the newly imported function may have an |
| 3375 | // evaluated noexcept. A call to adjustExceptionSpec() on the imported |
| 3376 | // decl and its redeclarations may be required. |
| Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3377 | } |
| 3378 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3379 | ToFunction->setQualifierInfo(ToQualifierLoc); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3380 | ToFunction->setAccess(D->getAccess()); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3381 | ToFunction->setLexicalDeclContext(LexicalDC); |
| John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 3382 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 3383 | ToFunction->setTrivial(D->isTrivial()); |
| 3384 | ToFunction->setPure(D->isPure()); |
| Balazs Keri | b427c06 | 2019-08-13 08:04:06 +0000 | [diff] [blame] | 3385 | ToFunction->setDefaulted(D->isDefaulted()); |
| 3386 | ToFunction->setExplicitlyDefaulted(D->isExplicitlyDefaulted()); |
| 3387 | ToFunction->setDeletedAsWritten(D->isDeletedAsWritten()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3388 | ToFunction->setRangeEnd(ToEndLoc); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3389 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3390 | // Set the parameters. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3391 | for (auto *Param : Parameters) { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3392 | Param->setOwningFunction(ToFunction); |
| 3393 | ToFunction->addDeclInternal(Param); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3394 | } |
| David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 3395 | ToFunction->setParams(Parameters); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3396 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3397 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 3398 | // params it refers to. |
| 3399 | if (TInfo) { |
| 3400 | if (auto ProtoLoc = |
| 3401 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 3402 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 3403 | ProtoLoc.setParam(I, Parameters[I]); |
| 3404 | } |
| 3405 | } |
| 3406 | |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3407 | // Import the describing template function, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3408 | if (FromFT) { |
| 3409 | auto ToFTOrErr = import(FromFT); |
| 3410 | if (!ToFTOrErr) |
| 3411 | return ToFTOrErr.takeError(); |
| 3412 | } |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3413 | |
| Balazs Keri | e13e836 | 2019-08-16 12:10:03 +0000 | [diff] [blame] | 3414 | // Import Ctor initializers. |
| 3415 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 3416 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 3417 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); |
| 3418 | // Import first, then allocate memory and copy if there was no error. |
| 3419 | if (Error Err = ImportContainerChecked( |
| 3420 | FromConstructor->inits(), CtorInitializers)) |
| 3421 | return std::move(Err); |
| 3422 | auto **Memory = |
| 3423 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 3424 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
| 3425 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
| 3426 | ToCtor->setCtorInitializers(Memory); |
| 3427 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 3428 | } |
| 3429 | } |
| 3430 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3431 | if (D->doesThisDeclarationHaveABody()) { |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3432 | Error Err = ImportFunctionDeclBody(D, ToFunction); |
| 3433 | |
| 3434 | if (Err) |
| 3435 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3436 | } |
| 3437 | |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3438 | // Import and set the original type in case we used another type. |
| 3439 | if (UsedDifferentProtoType) { |
| 3440 | if (ExpectedType TyOrErr = import(D->getType())) |
| 3441 | ToFunction->setType(*TyOrErr); |
| 3442 | else |
| 3443 | return TyOrErr.takeError(); |
| 3444 | } |
| 3445 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3446 | // FIXME: Other bits to merge? |
| Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3447 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3448 | // If it is a template, import all related things. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3449 | if (Error Err = ImportTemplateInformation(D, ToFunction)) |
| 3450 | return std::move(Err); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3451 | |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 3452 | addDeclToContexts(D, ToFunction); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3453 | |
| Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3454 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 3455 | if (Error Err = ImportOverriddenMethods(cast<CXXMethodDecl>(ToFunction), |
| 3456 | FromCXXMethod)) |
| 3457 | return std::move(Err); |
| Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3458 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3459 | // Import the rest of the chain. I.e. import all subsequent declarations. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3460 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3461 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3462 | if (!ToRedeclOrErr) |
| 3463 | return ToRedeclOrErr.takeError(); |
| 3464 | } |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3465 | |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3466 | return ToFunction; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3467 | } |
| 3468 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3469 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3470 | return VisitFunctionDecl(D); |
| 3471 | } |
| 3472 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3473 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3474 | return VisitCXXMethodDecl(D); |
| 3475 | } |
| 3476 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3477 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3478 | return VisitCXXMethodDecl(D); |
| 3479 | } |
| 3480 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3481 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3482 | return VisitCXXMethodDecl(D); |
| 3483 | } |
| 3484 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3485 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3486 | // Import the major distinguishing characteristics of a variable. |
| 3487 | DeclContext *DC, *LexicalDC; |
| 3488 | DeclarationName Name; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3489 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3490 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3491 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3492 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3493 | if (ToD) |
| 3494 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3495 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3496 | // Determine whether we've already imported this field. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3497 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3498 | for (auto *FoundDecl : FoundDecls) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3499 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3500 | // For anonymous fields, match up by index. |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3501 | if (!Name && |
| 3502 | ASTImporter::getFieldIndex(D) != |
| 3503 | ASTImporter::getFieldIndex(FoundField)) |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3504 | continue; |
| 3505 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3506 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3507 | FoundField->getType())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3508 | Importer.MapImported(D, FoundField); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3509 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the |
| 3510 | // initializer of a FieldDecl might not had been instantiated in the |
| 3511 | // "To" context. However, the "From" context might instantiated that, |
| 3512 | // thus we have to merge that. |
| 3513 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
| 3514 | // We don't have yet the initializer set. |
| 3515 | if (FoundField->hasInClassInitializer() && |
| 3516 | !FoundField->getInClassInitializer()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3517 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) |
| 3518 | FoundField->setInClassInitializer(*ToInitializerOrErr); |
| 3519 | else { |
| 3520 | // We can't return error here, |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3521 | // since we already mapped D as imported. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3522 | // FIXME: warning message? |
| 3523 | consumeError(ToInitializerOrErr.takeError()); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3524 | return FoundField; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3525 | } |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3526 | } |
| 3527 | } |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3528 | return FoundField; |
| 3529 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3530 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3531 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3532 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3533 | << Name << D->getType() << FoundField->getType(); |
| 3534 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3535 | << FoundField->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3536 | |
| 3537 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3538 | } |
| 3539 | } |
| 3540 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3541 | Error Err = Error::success(); |
| 3542 | auto ToType = importChecked(Err, D->getType()); |
| 3543 | auto ToTInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 3544 | auto ToBitWidth = importChecked(Err, D->getBitWidth()); |
| 3545 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 3546 | auto ToInitializer = importChecked(Err, D->getInClassInitializer()); |
| 3547 | if (Err) |
| 3548 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3549 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3550 | FieldDecl *ToField; |
| 3551 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3552 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3553 | ToType, ToTInfo, ToBitWidth, D->isMutable(), |
| 3554 | D->getInClassInitStyle())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3555 | return ToField; |
| 3556 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3557 | ToField->setAccess(D->getAccess()); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3558 | ToField->setLexicalDeclContext(LexicalDC); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3559 | if (ToInitializer) |
| 3560 | ToField->setInClassInitializer(ToInitializer); |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3561 | ToField->setImplicit(D->isImplicit()); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3562 | LexicalDC->addDeclInternal(ToField); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3563 | return ToField; |
| 3564 | } |
| 3565 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3566 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3567 | // Import the major distinguishing characteristics of a variable. |
| 3568 | DeclContext *DC, *LexicalDC; |
| 3569 | DeclarationName Name; |
| 3570 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3571 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3572 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3573 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3574 | if (ToD) |
| 3575 | return ToD; |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3576 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3577 | // Determine whether we've already imported this field. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3578 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3579 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3580 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3581 | // For anonymous indirect fields, match up by index. |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3582 | if (!Name && |
| 3583 | ASTImporter::getFieldIndex(D) != |
| 3584 | ASTImporter::getFieldIndex(FoundField)) |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3585 | continue; |
| 3586 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3587 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3588 | FoundField->getType(), |
| David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 3589 | !Name.isEmpty())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3590 | Importer.MapImported(D, FoundField); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3591 | return FoundField; |
| 3592 | } |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3593 | |
| 3594 | // If there are more anonymous fields to check, continue. |
| 3595 | if (!Name && I < N-1) |
| 3596 | continue; |
| 3597 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3598 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3599 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3600 | << Name << D->getType() << FoundField->getType(); |
| 3601 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3602 | << FoundField->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3603 | |
| 3604 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3605 | } |
| 3606 | } |
| 3607 | |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3608 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3609 | auto TypeOrErr = import(D->getType()); |
| 3610 | if (!TypeOrErr) |
| 3611 | return TypeOrErr.takeError(); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3612 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3613 | auto **NamedChain = |
| 3614 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3615 | |
| 3616 | unsigned i = 0; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3617 | for (auto *PI : D->chain()) |
| 3618 | if (Expected<NamedDecl *> ToD = import(PI)) |
| 3619 | NamedChain[i++] = *ToD; |
| 3620 | else |
| 3621 | return ToD.takeError(); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3622 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3623 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 3624 | IndirectFieldDecl *ToIndirectField; |
| 3625 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3626 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3627 | // FIXME here we leak `NamedChain` which is allocated before |
| 3628 | return ToIndirectField; |
| Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3629 | |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3630 | ToIndirectField->setAccess(D->getAccess()); |
| 3631 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3632 | LexicalDC->addDeclInternal(ToIndirectField); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3633 | return ToIndirectField; |
| 3634 | } |
| 3635 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3636 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3637 | // Import the major distinguishing characteristics of a declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3638 | DeclContext *DC, *LexicalDC; |
| 3639 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 3640 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3641 | |
| 3642 | // Determine whether we've already imported this decl. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3643 | // FriendDecl is not a NamedDecl so we cannot use lookup. |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3644 | auto *RD = cast<CXXRecordDecl>(DC); |
| 3645 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3646 | |
| 3647 | while (ImportedFriend) { |
| 3648 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3649 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 3650 | /*Complain=*/false)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3651 | return Importer.MapImported(D, ImportedFriend); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3652 | |
| 3653 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 3654 | if (Importer.IsStructurallyEquivalent( |
| 3655 | D->getFriendType()->getType(), |
| 3656 | ImportedFriend->getFriendType()->getType(), true)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3657 | return Importer.MapImported(D, ImportedFriend); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3658 | } |
| 3659 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3660 | } |
| 3661 | |
| 3662 | // Not found. Create it. |
| 3663 | FriendDecl::FriendUnion ToFU; |
| Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3664 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3665 | NamedDecl *ToFriendD; |
| 3666 | if (Error Err = importInto(ToFriendD, FriendD)) |
| 3667 | return std::move(Err); |
| 3668 | |
| 3669 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && |
| Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3670 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3671 | ToFriendD->setObjectOfFriendDecl(false); |
| 3672 | |
| 3673 | ToFU = ToFriendD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3674 | } else { // The friend is a type, not a decl. |
| 3675 | if (auto TSIOrErr = import(D->getFriendType())) |
| 3676 | ToFU = *TSIOrErr; |
| 3677 | else |
| 3678 | return TSIOrErr.takeError(); |
| 3679 | } |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3680 | |
| 3681 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3682 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3683 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 3684 | if (auto ListOrErr = import(FromTPLists[I])) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3685 | ToTPLists[I] = *ListOrErr; |
| 3686 | else |
| 3687 | return ListOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3688 | } |
| 3689 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3690 | auto LocationOrErr = import(D->getLocation()); |
| 3691 | if (!LocationOrErr) |
| 3692 | return LocationOrErr.takeError(); |
| 3693 | auto FriendLocOrErr = import(D->getFriendLoc()); |
| 3694 | if (!FriendLocOrErr) |
| 3695 | return FriendLocOrErr.takeError(); |
| 3696 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3697 | FriendDecl *FrD; |
| 3698 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3699 | *LocationOrErr, ToFU, |
| 3700 | *FriendLocOrErr, ToTPLists)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3701 | return FrD; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3702 | |
| 3703 | FrD->setAccess(D->getAccess()); |
| 3704 | FrD->setLexicalDeclContext(LexicalDC); |
| 3705 | LexicalDC->addDeclInternal(FrD); |
| 3706 | return FrD; |
| 3707 | } |
| 3708 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3709 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3710 | // Import the major distinguishing characteristics of an ivar. |
| 3711 | DeclContext *DC, *LexicalDC; |
| 3712 | DeclarationName Name; |
| 3713 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3714 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3715 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3716 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3717 | if (ToD) |
| 3718 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3719 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3720 | // Determine whether we've already imported this ivar |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3721 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3722 | for (auto *FoundDecl : FoundDecls) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3723 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3724 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3725 | FoundIvar->getType())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3726 | Importer.MapImported(D, FoundIvar); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3727 | return FoundIvar; |
| 3728 | } |
| 3729 | |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3730 | Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent) |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3731 | << Name << D->getType() << FoundIvar->getType(); |
| 3732 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3733 | << FoundIvar->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3734 | |
| 3735 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3736 | } |
| 3737 | } |
| 3738 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3739 | Error Err = Error::success(); |
| 3740 | auto ToType = importChecked(Err, D->getType()); |
| 3741 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 3742 | auto ToBitWidth = importChecked(Err, D->getBitWidth()); |
| 3743 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 3744 | if (Err) |
| 3745 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3746 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3747 | ObjCIvarDecl *ToIvar; |
| 3748 | if (GetImportedOrCreateDecl( |
| 3749 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3750 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3751 | ToType, ToTypeSourceInfo, |
| 3752 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3753 | return ToIvar; |
| 3754 | |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3755 | ToIvar->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3756 | LexicalDC->addDeclInternal(ToIvar); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3757 | return ToIvar; |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3758 | } |
| 3759 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3760 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3761 | |
| 3762 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 3763 | auto RedeclIt = Redecls.begin(); |
| 3764 | // Import the first part of the decl chain. I.e. import all previous |
| 3765 | // declarations starting from the canonical decl. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3766 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3767 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3768 | if (!RedeclOrErr) |
| 3769 | return RedeclOrErr.takeError(); |
| 3770 | } |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3771 | assert(*RedeclIt == D); |
| 3772 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3773 | // Import the major distinguishing characteristics of a variable. |
| 3774 | DeclContext *DC, *LexicalDC; |
| 3775 | DeclarationName Name; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3776 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3777 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3778 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3779 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3780 | if (ToD) |
| 3781 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3782 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3783 | // Try to find a variable in our own ("to") context with the same name and |
| 3784 | // in the same context as the variable we're importing. |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3785 | VarDecl *FoundByLookup = nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3786 | if (D->isFileVarDecl()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3787 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3788 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3789 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3790 | for (auto *FoundDecl : FoundDecls) { |
| 3791 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3792 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3793 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3794 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 3795 | if (!hasSameVisibilityContextAndLinkage(FoundVar, D)) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3796 | continue; |
| 3797 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| 3798 | FoundVar->getType())) { |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3799 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3800 | // The VarDecl in the "From" context has a definition, but in the |
| 3801 | // "To" context we already have a definition. |
| 3802 | VarDecl *FoundDef = FoundVar->getDefinition(); |
| 3803 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 3804 | // FIXME Check for ODR error if the two definitions have |
| 3805 | // different initializers? |
| 3806 | return Importer.MapImported(D, FoundDef); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3807 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3808 | // The VarDecl in the "From" context has an initializer, but in the |
| 3809 | // "To" context we already have an initializer. |
| 3810 | const VarDecl *FoundDInit = nullptr; |
| 3811 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) |
| 3812 | // FIXME Diagnose ODR error if the two initializers are different? |
| 3813 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); |
| 3814 | |
| 3815 | FoundByLookup = FoundVar; |
| 3816 | break; |
| 3817 | } |
| 3818 | |
| 3819 | const ArrayType *FoundArray |
| 3820 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3821 | const ArrayType *TArray |
| 3822 | = Importer.getToContext().getAsArrayType(D->getType()); |
| 3823 | if (FoundArray && TArray) { |
| 3824 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3825 | isa<ConstantArrayType>(TArray)) { |
| 3826 | // Import the type. |
| 3827 | if (auto TyOrErr = import(D->getType())) |
| 3828 | FoundVar->setType(*TyOrErr); |
| 3829 | else |
| 3830 | return TyOrErr.takeError(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3831 | |
| 3832 | FoundByLookup = FoundVar; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3833 | break; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3834 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3835 | isa<ConstantArrayType>(FoundArray)) { |
| 3836 | FoundByLookup = FoundVar; |
| 3837 | break; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3838 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3839 | } |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3840 | |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3841 | Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3842 | << Name << D->getType() << FoundVar->getType(); |
| 3843 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3844 | << FoundVar->getType(); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3845 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3846 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3847 | } |
| 3848 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3849 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3850 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 3851 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 3852 | if (NameOrErr) |
| 3853 | Name = NameOrErr.get(); |
| 3854 | else |
| 3855 | return NameOrErr.takeError(); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3856 | } |
| 3857 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3858 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3859 | Error Err = Error::success(); |
| 3860 | auto ToType = importChecked(Err, D->getType()); |
| 3861 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 3862 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 3863 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 3864 | if (Err) |
| 3865 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3866 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3867 | // Create the imported variable. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3868 | VarDecl *ToVar; |
| 3869 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3870 | ToInnerLocStart, Loc, |
| 3871 | Name.getAsIdentifierInfo(), |
| 3872 | ToType, ToTypeSourceInfo, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3873 | D->getStorageClass())) |
| 3874 | return ToVar; |
| 3875 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3876 | ToVar->setQualifierInfo(ToQualifierLoc); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3877 | ToVar->setAccess(D->getAccess()); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3878 | ToVar->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3879 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3880 | if (FoundByLookup) { |
| 3881 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); |
| 3882 | ToVar->setPreviousDecl(Recent); |
| 3883 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3884 | |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 3885 | // Import the described template, if any. |
| 3886 | if (D->getDescribedVarTemplate()) { |
| 3887 | auto ToVTOrErr = import(D->getDescribedVarTemplate()); |
| 3888 | if (!ToVTOrErr) |
| 3889 | return ToVTOrErr.takeError(); |
| 3890 | } |
| 3891 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3892 | if (Error Err = ImportInitializer(D, ToVar)) |
| 3893 | return std::move(Err); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3894 | |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3895 | if (D->isConstexpr()) |
| 3896 | ToVar->setConstexpr(true); |
| 3897 | |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 3898 | addDeclToContexts(D, ToVar); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3899 | |
| 3900 | // Import the rest of the chain. I.e. import all subsequent declarations. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3901 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3902 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3903 | if (!RedeclOrErr) |
| 3904 | return RedeclOrErr.takeError(); |
| 3905 | } |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3906 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3907 | return ToVar; |
| 3908 | } |
| 3909 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3910 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3911 | // Parameters are created in the translation unit's context, then moved |
| 3912 | // into the function declaration's context afterward. |
| 3913 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3914 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3915 | Error Err = Error::success(); |
| 3916 | auto ToDeclName = importChecked(Err, D->getDeclName()); |
| 3917 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 3918 | auto ToType = importChecked(Err, D->getType()); |
| 3919 | if (Err) |
| 3920 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3921 | |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3922 | // Create the imported parameter. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3923 | ImplicitParamDecl *ToParm = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3924 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3925 | ToLocation, ToDeclName.getAsIdentifierInfo(), |
| 3926 | ToType, D->getParameterKind())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3927 | return ToParm; |
| 3928 | return ToParm; |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3929 | } |
| 3930 | |
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 3931 | Error ASTNodeImporter::ImportDefaultArgOfParmVarDecl( |
| 3932 | const ParmVarDecl *FromParam, ParmVarDecl *ToParam) { |
| 3933 | ToParam->setHasInheritedDefaultArg(FromParam->hasInheritedDefaultArg()); |
| 3934 | ToParam->setKNRPromoted(FromParam->isKNRPromoted()); |
| 3935 | |
| 3936 | if (FromParam->hasUninstantiatedDefaultArg()) { |
| 3937 | if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg())) |
| 3938 | ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr); |
| 3939 | else |
| 3940 | return ToDefArgOrErr.takeError(); |
| 3941 | } else if (FromParam->hasUnparsedDefaultArg()) { |
| 3942 | ToParam->setUnparsedDefaultArg(); |
| 3943 | } else if (FromParam->hasDefaultArg()) { |
| 3944 | if (auto ToDefArgOrErr = import(FromParam->getDefaultArg())) |
| 3945 | ToParam->setDefaultArg(*ToDefArgOrErr); |
| 3946 | else |
| 3947 | return ToDefArgOrErr.takeError(); |
| 3948 | } |
| 3949 | |
| 3950 | return Error::success(); |
| 3951 | } |
| 3952 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3953 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3954 | // Parameters are created in the translation unit's context, then moved |
| 3955 | // into the function declaration's context afterward. |
| 3956 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3957 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3958 | Error Err = Error::success(); |
| 3959 | auto ToDeclName = importChecked(Err, D->getDeclName()); |
| 3960 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 3961 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 3962 | auto ToType = importChecked(Err, D->getType()); |
| 3963 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 3964 | if (Err) |
| 3965 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3966 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3967 | ParmVarDecl *ToParm; |
| 3968 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3969 | ToInnerLocStart, ToLocation, |
| 3970 | ToDeclName.getAsIdentifierInfo(), ToType, |
| 3971 | ToTypeSourceInfo, D->getStorageClass(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3972 | /*DefaultArg*/ nullptr)) |
| 3973 | return ToParm; |
| Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3974 | |
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 3975 | // Set the default argument. It should be no problem if it was already done. |
| 3976 | // Do not import the default expression before GetImportedOrCreateDecl call |
| 3977 | // to avoid possible infinite import loop because circular dependency. |
| 3978 | if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm)) |
| 3979 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3980 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3981 | if (D->isObjCMethodParameter()) { |
| 3982 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3983 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3984 | } else { |
| 3985 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3986 | D->getFunctionScopeIndex()); |
| 3987 | } |
| 3988 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3989 | return ToParm; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3990 | } |
| 3991 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3992 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3993 | // Import the major distinguishing characteristics of a method. |
| 3994 | DeclContext *DC, *LexicalDC; |
| 3995 | DeclarationName Name; |
| 3996 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3997 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3998 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3999 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4000 | if (ToD) |
| 4001 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4002 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4003 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4004 | for (auto *FoundDecl : FoundDecls) { |
| 4005 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4006 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 4007 | continue; |
| 4008 | |
| 4009 | // Check return types. |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4010 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 4011 | FoundMethod->getReturnType())) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4012 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent) |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4013 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 4014 | << FoundMethod->getReturnType(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4015 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4016 | diag::note_odr_objc_method_here) |
| 4017 | << D->isInstanceMethod() << Name; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4018 | |
| 4019 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4020 | } |
| 4021 | |
| 4022 | // Check the number of parameters. |
| 4023 | if (D->param_size() != FoundMethod->param_size()) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4024 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4025 | << D->isInstanceMethod() << Name |
| 4026 | << D->param_size() << FoundMethod->param_size(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4027 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4028 | diag::note_odr_objc_method_here) |
| 4029 | << D->isInstanceMethod() << Name; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4030 | |
| 4031 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4032 | } |
| 4033 | |
| 4034 | // Check parameter types. |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4035 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4036 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 4037 | P != PEnd; ++P, ++FoundP) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4038 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4039 | (*FoundP)->getType())) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4040 | Importer.FromDiag((*P)->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4041 | diag::warn_odr_objc_method_param_type_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4042 | << D->isInstanceMethod() << Name |
| 4043 | << (*P)->getType() << (*FoundP)->getType(); |
| 4044 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 4045 | << (*FoundP)->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4046 | |
| 4047 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4048 | } |
| 4049 | } |
| 4050 | |
| 4051 | // Check variadic/non-variadic. |
| 4052 | // Check the number of parameters. |
| 4053 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4054 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4055 | << D->isInstanceMethod() << Name; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4056 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4057 | diag::note_odr_objc_method_here) |
| 4058 | << D->isInstanceMethod() << Name; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4059 | |
| 4060 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4061 | } |
| 4062 | |
| 4063 | // FIXME: Any other bits we need to merge? |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4064 | return Importer.MapImported(D, FoundMethod); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4065 | } |
| 4066 | } |
| 4067 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4068 | Error Err = Error::success(); |
| 4069 | auto ToEndLoc = importChecked(Err, D->getEndLoc()); |
| 4070 | auto ToReturnType = importChecked(Err, D->getReturnType()); |
| 4071 | auto ToReturnTypeSourceInfo = |
| 4072 | importChecked(Err, D->getReturnTypeSourceInfo()); |
| 4073 | if (Err) |
| 4074 | return std::move(Err); |
| Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 4075 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4076 | ObjCMethodDecl *ToMethod; |
| 4077 | if (GetImportedOrCreateDecl( |
| Adrian Prantl | 2073dd2 | 2019-11-04 14:28:14 -0800 | [diff] [blame] | 4078 | ToMethod, D, Importer.getToContext(), Loc, ToEndLoc, |
| 4079 | Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC, |
| 4080 | D->isInstanceMethod(), D->isVariadic(), D->isPropertyAccessor(), |
| 4081 | D->isSynthesizedAccessorStub(), D->isImplicit(), D->isDefined(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4082 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 4083 | return ToMethod; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4084 | |
| 4085 | // FIXME: When we decide to merge method definitions, we'll need to |
| 4086 | // deal with implicit parameters. |
| 4087 | |
| 4088 | // Import the parameters |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4089 | SmallVector<ParmVarDecl *, 5> ToParams; |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 4090 | for (auto *FromP : D->parameters()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4091 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) |
| 4092 | ToParams.push_back(*ToPOrErr); |
| 4093 | else |
| 4094 | return ToPOrErr.takeError(); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4095 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4096 | |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4097 | // Set the parameters. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4098 | for (auto *ToParam : ToParams) { |
| 4099 | ToParam->setOwningFunction(ToMethod); |
| 4100 | ToMethod->addDeclInternal(ToParam); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4101 | } |
| Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 4102 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4103 | SmallVector<SourceLocation, 12> FromSelLocs; |
| 4104 | D->getSelectorLocs(FromSelLocs); |
| 4105 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); |
| 4106 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) |
| 4107 | return std::move(Err); |
| Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 4108 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4109 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4110 | |
| 4111 | ToMethod->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4112 | LexicalDC->addDeclInternal(ToMethod); |
| Raphael Isemann | 164e0fc | 2019-12-06 18:10:23 +0100 | [diff] [blame] | 4113 | |
| 4114 | // Implicit params are declared when Sema encounters the definition but this |
| 4115 | // never happens when the method is imported. Manually declare the implicit |
| 4116 | // params now that the MethodDecl knows its class interface. |
| 4117 | if (D->getSelfDecl()) |
| 4118 | ToMethod->createImplicitParams(Importer.getToContext(), |
| 4119 | ToMethod->getClassInterface()); |
| 4120 | |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4121 | return ToMethod; |
| 4122 | } |
| 4123 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4124 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4125 | // Import the major distinguishing characteristics of a category. |
| 4126 | DeclContext *DC, *LexicalDC; |
| 4127 | DeclarationName Name; |
| 4128 | SourceLocation Loc; |
| 4129 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4130 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4131 | return std::move(Err); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4132 | if (ToD) |
| 4133 | return ToD; |
| 4134 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4135 | Error Err = Error::success(); |
| 4136 | auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc()); |
| 4137 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 4138 | auto ToColonLoc = importChecked(Err, D->getColonLoc()); |
| 4139 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 4140 | if (Err) |
| 4141 | return std::move(Err); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4142 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4143 | ObjCTypeParamDecl *Result; |
| 4144 | if (GetImportedOrCreateDecl( |
| 4145 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4146 | ToVarianceLoc, D->getIndex(), |
| 4147 | ToLocation, Name.getAsIdentifierInfo(), |
| 4148 | ToColonLoc, ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4149 | return Result; |
| 4150 | |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4151 | Result->setLexicalDeclContext(LexicalDC); |
| 4152 | return Result; |
| 4153 | } |
| 4154 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4155 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4156 | // Import the major distinguishing characteristics of a category. |
| 4157 | DeclContext *DC, *LexicalDC; |
| 4158 | DeclarationName Name; |
| 4159 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4160 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4161 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4162 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4163 | if (ToD) |
| 4164 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4165 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4166 | ObjCInterfaceDecl *ToInterface; |
| 4167 | if (Error Err = importInto(ToInterface, D->getClassInterface())) |
| 4168 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4169 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4170 | // Determine if we've already encountered this category. |
| 4171 | ObjCCategoryDecl *MergeWithCategory |
| 4172 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 4173 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 4174 | if (!ToCategory) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4175 | |
| 4176 | Error Err = Error::success(); |
| 4177 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); |
| 4178 | auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc()); |
| 4179 | auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc()); |
| 4180 | auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc()); |
| 4181 | if (Err) |
| 4182 | return std::move(Err); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4183 | |
| 4184 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4185 | ToAtStartLoc, Loc, |
| 4186 | ToCategoryNameLoc, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4187 | Name.getAsIdentifierInfo(), ToInterface, |
| 4188 | /*TypeParamList=*/nullptr, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4189 | ToIvarLBraceLoc, |
| 4190 | ToIvarRBraceLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4191 | return ToCategory; |
| 4192 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4193 | ToCategory->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4194 | LexicalDC->addDeclInternal(ToCategory); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4195 | // Import the type parameter list after MapImported, to avoid |
| Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4196 | // loops when bringing in their DeclContext. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4197 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) |
| 4198 | ToCategory->setTypeParamList(*PListOrErr); |
| 4199 | else |
| 4200 | return PListOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4201 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4202 | // Import protocols |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4203 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4204 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4205 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 4206 | = D->protocol_loc_begin(); |
| 4207 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 4208 | FromProtoEnd = D->protocol_end(); |
| 4209 | FromProto != FromProtoEnd; |
| 4210 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4211 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4212 | Protocols.push_back(*ToProtoOrErr); |
| 4213 | else |
| 4214 | return ToProtoOrErr.takeError(); |
| 4215 | |
| 4216 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4217 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4218 | else |
| 4219 | return ToProtoLocOrErr.takeError(); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4220 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4221 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4222 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4223 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 4224 | ProtocolLocs.data(), Importer.getToContext()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4225 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4226 | } else { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4227 | Importer.MapImported(D, ToCategory); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4228 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4229 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4230 | // Import all of the members of this category. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4231 | if (Error Err = ImportDeclContext(D)) |
| 4232 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4233 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4234 | // If we have an implementation, import it as well. |
| 4235 | if (D->getImplementation()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4236 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = |
| 4237 | import(D->getImplementation())) |
| 4238 | ToCategory->setImplementation(*ToImplOrErr); |
| 4239 | else |
| 4240 | return ToImplOrErr.takeError(); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4241 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4242 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4243 | return ToCategory; |
| 4244 | } |
| 4245 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4246 | Error ASTNodeImporter::ImportDefinition( |
| 4247 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4248 | if (To->getDefinition()) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4249 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4250 | if (Error Err = ImportDeclContext(From)) |
| 4251 | return Err; |
| 4252 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | // Start the protocol definition |
| 4256 | To->startDefinition(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4257 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4258 | // Import protocols |
| 4259 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4260 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4261 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = |
| 4262 | From->protocol_loc_begin(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4263 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4264 | FromProtoEnd = From->protocol_end(); |
| 4265 | FromProto != FromProtoEnd; |
| 4266 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4267 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4268 | Protocols.push_back(*ToProtoOrErr); |
| 4269 | else |
| 4270 | return ToProtoOrErr.takeError(); |
| 4271 | |
| 4272 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4273 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4274 | else |
| 4275 | return ToProtoLocOrErr.takeError(); |
| 4276 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4277 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4278 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4279 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4280 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4281 | ProtocolLocs.data(), Importer.getToContext()); |
| 4282 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4283 | if (shouldForceImportDeclContext(Kind)) { |
| 4284 | // Import all of the members of this protocol. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4285 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4286 | return Err; |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4287 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4288 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4289 | } |
| 4290 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4291 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4292 | // 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] | 4293 | // from, but this particular declaration is not that definition, import the |
| 4294 | // definition and map to that. |
| 4295 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 4296 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4297 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4298 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4299 | else |
| 4300 | return ImportedDefOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4301 | } |
| 4302 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4303 | // Import the major distinguishing characteristics of a protocol. |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4304 | DeclContext *DC, *LexicalDC; |
| 4305 | DeclarationName Name; |
| 4306 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4307 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4308 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4309 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4310 | if (ToD) |
| 4311 | return ToD; |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4312 | |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4313 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4314 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4315 | for (auto *FoundDecl : FoundDecls) { |
| 4316 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4317 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4318 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4319 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4320 | break; |
| 4321 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4322 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4323 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4324 | if (!ToProto) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4325 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4326 | if (!ToAtBeginLocOrErr) |
| 4327 | return ToAtBeginLocOrErr.takeError(); |
| 4328 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4329 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 4330 | Name.getAsIdentifierInfo(), Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4331 | *ToAtBeginLocOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4332 | /*PrevDecl=*/nullptr)) |
| 4333 | return ToProto; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4334 | ToProto->setLexicalDeclContext(LexicalDC); |
| 4335 | LexicalDC->addDeclInternal(ToProto); |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4336 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4337 | |
| 4338 | Importer.MapImported(D, ToProto); |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4339 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4340 | if (D->isThisDeclarationADefinition()) |
| 4341 | if (Error Err = ImportDefinition(D, ToProto)) |
| 4342 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4343 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4344 | return ToProto; |
| 4345 | } |
| 4346 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4347 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 4348 | DeclContext *DC, *LexicalDC; |
| 4349 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4350 | return std::move(Err); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4351 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4352 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); |
| 4353 | if (!ExternLocOrErr) |
| 4354 | return ExternLocOrErr.takeError(); |
| 4355 | |
| 4356 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); |
| 4357 | if (!LangLocOrErr) |
| 4358 | return LangLocOrErr.takeError(); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4359 | |
| 4360 | bool HasBraces = D->hasBraces(); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4361 | |
| 4362 | LinkageSpecDecl *ToLinkageSpec; |
| 4363 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4364 | *ExternLocOrErr, *LangLocOrErr, |
| 4365 | D->getLanguage(), HasBraces)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4366 | return ToLinkageSpec; |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4367 | |
| 4368 | if (HasBraces) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4369 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 4370 | if (!RBraceLocOrErr) |
| 4371 | return RBraceLocOrErr.takeError(); |
| 4372 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4373 | } |
| 4374 | |
| 4375 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 4376 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 4377 | |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4378 | return ToLinkageSpec; |
| 4379 | } |
| 4380 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4381 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4382 | DeclContext *DC, *LexicalDC; |
| 4383 | DeclarationName Name; |
| 4384 | SourceLocation Loc; |
| 4385 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4386 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4387 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4388 | if (ToD) |
| 4389 | return ToD; |
| 4390 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4391 | Error Err = Error::success(); |
| 4392 | auto ToLoc = importChecked(Err, D->getNameInfo().getLoc()); |
| 4393 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); |
| 4394 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 4395 | if (Err) |
| 4396 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4397 | |
| 4398 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4399 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4400 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4401 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4402 | UsingDecl *ToUsing; |
| 4403 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4404 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4405 | D->hasTypename())) |
| 4406 | return ToUsing; |
| 4407 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4408 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4409 | LexicalDC->addDeclInternal(ToUsing); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4410 | |
| 4411 | if (NamedDecl *FromPattern = |
| 4412 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4413 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) |
| 4414 | Importer.getToContext().setInstantiatedFromUsingDecl( |
| 4415 | ToUsing, *ToPatternOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4416 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4417 | return ToPatternOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4418 | } |
| 4419 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4420 | for (UsingShadowDecl *FromShadow : D->shadows()) { |
| 4421 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) |
| 4422 | ToUsing->addShadowDecl(*ToShadowOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4423 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4424 | // FIXME: We return error here but the definition is already created |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4425 | // and available with lookups. How to fix this?.. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4426 | return ToShadowOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4427 | } |
| 4428 | return ToUsing; |
| 4429 | } |
| 4430 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4431 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4432 | DeclContext *DC, *LexicalDC; |
| 4433 | DeclarationName Name; |
| 4434 | SourceLocation Loc; |
| 4435 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4436 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4437 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4438 | if (ToD) |
| 4439 | return ToD; |
| 4440 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4441 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); |
| 4442 | if (!ToUsingOrErr) |
| 4443 | return ToUsingOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4444 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4445 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); |
| 4446 | if (!ToTargetOrErr) |
| 4447 | return ToTargetOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4448 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4449 | UsingShadowDecl *ToShadow; |
| 4450 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4451 | *ToUsingOrErr, *ToTargetOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4452 | return ToShadow; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4453 | |
| 4454 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 4455 | ToShadow->setAccess(D->getAccess()); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4456 | |
| 4457 | if (UsingShadowDecl *FromPattern = |
| 4458 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4459 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) |
| 4460 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( |
| 4461 | ToShadow, *ToPatternOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4462 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4463 | // FIXME: We return error here but the definition is already created |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4464 | // and available with lookups. How to fix this?.. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4465 | return ToPatternOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4466 | } |
| 4467 | |
| 4468 | LexicalDC->addDeclInternal(ToShadow); |
| 4469 | |
| 4470 | return ToShadow; |
| 4471 | } |
| 4472 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4473 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4474 | DeclContext *DC, *LexicalDC; |
| 4475 | DeclarationName Name; |
| 4476 | SourceLocation Loc; |
| 4477 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4478 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4479 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4480 | if (ToD) |
| 4481 | return ToD; |
| 4482 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4483 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); |
| 4484 | if (!ToComAncestorOrErr) |
| 4485 | return ToComAncestorOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4486 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4487 | Error Err = Error::success(); |
| 4488 | auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace()); |
| 4489 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); |
| 4490 | auto ToNamespaceKeyLocation = |
| 4491 | importChecked(Err, D->getNamespaceKeyLocation()); |
| 4492 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 4493 | auto ToIdentLocation = importChecked(Err, D->getIdentLocation()); |
| 4494 | if (Err) |
| 4495 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4496 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4497 | UsingDirectiveDecl *ToUsingDir; |
| 4498 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4499 | ToUsingLoc, |
| 4500 | ToNamespaceKeyLocation, |
| 4501 | ToQualifierLoc, |
| 4502 | ToIdentLocation, |
| 4503 | ToNominatedNamespace, *ToComAncestorOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4504 | return ToUsingDir; |
| 4505 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4506 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 4507 | LexicalDC->addDeclInternal(ToUsingDir); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4508 | |
| 4509 | return ToUsingDir; |
| 4510 | } |
| 4511 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4512 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4513 | UnresolvedUsingValueDecl *D) { |
| 4514 | DeclContext *DC, *LexicalDC; |
| 4515 | DeclarationName Name; |
| 4516 | SourceLocation Loc; |
| 4517 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4518 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4519 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4520 | if (ToD) |
| 4521 | return ToD; |
| 4522 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4523 | Error Err = Error::success(); |
| 4524 | auto ToLoc = importChecked(Err, D->getNameInfo().getLoc()); |
| 4525 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); |
| 4526 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 4527 | auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc()); |
| 4528 | if (Err) |
| 4529 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4530 | |
| 4531 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4532 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4533 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4534 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4535 | UnresolvedUsingValueDecl *ToUsingValue; |
| 4536 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4537 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| 4538 | ToEllipsisLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4539 | return ToUsingValue; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4540 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4541 | ToUsingValue->setAccess(D->getAccess()); |
| 4542 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 4543 | LexicalDC->addDeclInternal(ToUsingValue); |
| 4544 | |
| 4545 | return ToUsingValue; |
| 4546 | } |
| 4547 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4548 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4549 | UnresolvedUsingTypenameDecl *D) { |
| 4550 | DeclContext *DC, *LexicalDC; |
| 4551 | DeclarationName Name; |
| 4552 | SourceLocation Loc; |
| 4553 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4554 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4555 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4556 | if (ToD) |
| 4557 | return ToD; |
| 4558 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4559 | Error Err = Error::success(); |
| 4560 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); |
| 4561 | auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc()); |
| 4562 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 4563 | auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc()); |
| 4564 | if (Err) |
| 4565 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4566 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4567 | UnresolvedUsingTypenameDecl *ToUsing; |
| 4568 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4569 | ToUsingLoc, ToTypenameLoc, |
| 4570 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4571 | return ToUsing; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4572 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4573 | ToUsing->setAccess(D->getAccess()); |
| 4574 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4575 | LexicalDC->addDeclInternal(ToUsing); |
| 4576 | |
| 4577 | return ToUsing; |
| 4578 | } |
| 4579 | |
| Raphael Isemann | ba7bde6 | 2019-10-30 14:50:35 +0100 | [diff] [blame] | 4580 | ExpectedDecl ASTNodeImporter::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) { |
| 4581 | Decl* ToD = nullptr; |
| 4582 | switch (D->getBuiltinTemplateKind()) { |
| 4583 | case BuiltinTemplateKind::BTK__make_integer_seq: |
| 4584 | ToD = Importer.getToContext().getMakeIntegerSeqDecl(); |
| 4585 | break; |
| 4586 | case BuiltinTemplateKind::BTK__type_pack_element: |
| 4587 | ToD = Importer.getToContext().getTypePackElementDecl(); |
| 4588 | break; |
| 4589 | } |
| 4590 | assert(ToD && "BuiltinTemplateDecl of unsupported kind!"); |
| 4591 | Importer.MapImported(D, ToD); |
| 4592 | return ToD; |
| 4593 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4594 | |
| 4595 | Error ASTNodeImporter::ImportDefinition( |
| 4596 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4597 | if (To->getDefinition()) { |
| 4598 | // Check consistency of superclass. |
| 4599 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 4600 | if (FromSuper) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4601 | if (auto FromSuperOrErr = import(FromSuper)) |
| 4602 | FromSuper = *FromSuperOrErr; |
| 4603 | else |
| 4604 | return FromSuperOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4605 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4606 | |
| 4607 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4608 | if ((bool)FromSuper != (bool)ToSuper || |
| 4609 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4610 | Importer.ToDiag(To->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4611 | diag::warn_odr_objc_superclass_inconsistent) |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4612 | << To->getDeclName(); |
| 4613 | if (ToSuper) |
| 4614 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 4615 | << To->getSuperClass()->getDeclName(); |
| 4616 | else |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4617 | Importer.ToDiag(To->getLocation(), |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4618 | diag::note_odr_objc_missing_superclass); |
| 4619 | if (From->getSuperClass()) |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4620 | Importer.FromDiag(From->getSuperClassLoc(), |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4621 | diag::note_odr_objc_superclass) |
| 4622 | << From->getSuperClass()->getDeclName(); |
| 4623 | else |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4624 | Importer.FromDiag(From->getLocation(), |
| 4625 | diag::note_odr_objc_missing_superclass); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4626 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4627 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4628 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4629 | if (Error Err = ImportDeclContext(From)) |
| 4630 | return Err; |
| 4631 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4632 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4633 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4634 | // Start the definition. |
| 4635 | To->startDefinition(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4636 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4637 | // If this class has a superclass, import it. |
| 4638 | if (From->getSuperClass()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4639 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) |
| 4640 | To->setSuperClass(*SuperTInfoOrErr); |
| 4641 | else |
| 4642 | return SuperTInfoOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4643 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4644 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4645 | // Import protocols |
| 4646 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4647 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4648 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = |
| 4649 | From->protocol_loc_begin(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4650 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4651 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4652 | FromProtoEnd = From->protocol_end(); |
| 4653 | FromProto != FromProtoEnd; |
| 4654 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4655 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4656 | Protocols.push_back(*ToProtoOrErr); |
| 4657 | else |
| 4658 | return ToProtoOrErr.takeError(); |
| 4659 | |
| 4660 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4661 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4662 | else |
| 4663 | return ToProtoLocOrErr.takeError(); |
| 4664 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4665 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4666 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4667 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4668 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4669 | ProtocolLocs.data(), Importer.getToContext()); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4670 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4671 | // Import categories. When the categories themselves are imported, they'll |
| 4672 | // hook themselves into this interface. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4673 | for (auto *Cat : From->known_categories()) { |
| 4674 | auto ToCatOrErr = import(Cat); |
| 4675 | if (!ToCatOrErr) |
| 4676 | return ToCatOrErr.takeError(); |
| 4677 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4678 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4679 | // If we have an @implementation, import it as well. |
| 4680 | if (From->getImplementation()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4681 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = |
| 4682 | import(From->getImplementation())) |
| 4683 | To->setImplementation(*ToImplOrErr); |
| 4684 | else |
| 4685 | return ToImplOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4686 | } |
| 4687 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4688 | if (shouldForceImportDeclContext(Kind)) { |
| 4689 | // Import all of the members of this class. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4690 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4691 | return Err; |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4692 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4693 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4694 | } |
| 4695 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4696 | Expected<ObjCTypeParamList *> |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4697 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 4698 | if (!list) |
| 4699 | return nullptr; |
| 4700 | |
| 4701 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4702 | for (auto *fromTypeParam : *list) { |
| 4703 | if (auto toTypeParamOrErr = import(fromTypeParam)) |
| 4704 | toTypeParams.push_back(*toTypeParamOrErr); |
| 4705 | else |
| 4706 | return toTypeParamOrErr.takeError(); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4707 | } |
| 4708 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4709 | auto LAngleLocOrErr = import(list->getLAngleLoc()); |
| 4710 | if (!LAngleLocOrErr) |
| 4711 | return LAngleLocOrErr.takeError(); |
| 4712 | |
| 4713 | auto RAngleLocOrErr = import(list->getRAngleLoc()); |
| 4714 | if (!RAngleLocOrErr) |
| 4715 | return RAngleLocOrErr.takeError(); |
| 4716 | |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4717 | return ObjCTypeParamList::create(Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4718 | *LAngleLocOrErr, |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4719 | toTypeParams, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4720 | *RAngleLocOrErr); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4721 | } |
| 4722 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4723 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4724 | // If this class has a definition in the translation unit we're coming from, |
| 4725 | // but this particular declaration is not that definition, import the |
| 4726 | // definition and map to that. |
| 4727 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 4728 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4729 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4730 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4731 | else |
| 4732 | return ImportedDefOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4733 | } |
| 4734 | |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4735 | // Import the major distinguishing characteristics of an @interface. |
| 4736 | DeclContext *DC, *LexicalDC; |
| 4737 | DeclarationName Name; |
| 4738 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4739 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4740 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4741 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4742 | if (ToD) |
| 4743 | return ToD; |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4744 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4745 | // Look for an existing interface with the same name. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4746 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4747 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4748 | for (auto *FoundDecl : FoundDecls) { |
| 4749 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4750 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4751 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4752 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4753 | break; |
| 4754 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4755 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4756 | // Create an interface declaration, if one does not already exist. |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4757 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4758 | if (!ToIface) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4759 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4760 | if (!AtBeginLocOrErr) |
| 4761 | return AtBeginLocOrErr.takeError(); |
| 4762 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4763 | if (GetImportedOrCreateDecl( |
| 4764 | ToIface, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4765 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4766 | /*TypeParamList=*/nullptr, |
| 4767 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 4768 | return ToIface; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4769 | ToIface->setLexicalDeclContext(LexicalDC); |
| 4770 | LexicalDC->addDeclInternal(ToIface); |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4771 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4772 | Importer.MapImported(D, ToIface); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4773 | // Import the type parameter list after MapImported, to avoid |
| Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4774 | // loops when bringing in their DeclContext. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4775 | if (auto ToPListOrErr = |
| 4776 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) |
| 4777 | ToIface->setTypeParamList(*ToPListOrErr); |
| 4778 | else |
| 4779 | return ToPListOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4780 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4781 | if (D->isThisDeclarationADefinition()) |
| 4782 | if (Error Err = ImportDefinition(D, ToIface)) |
| 4783 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4784 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4785 | return ToIface; |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4786 | } |
| 4787 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4788 | ExpectedDecl |
| 4789 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 4790 | ObjCCategoryDecl *Category; |
| 4791 | if (Error Err = importInto(Category, D->getCategoryDecl())) |
| 4792 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4793 | |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4794 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4795 | if (!ToImpl) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4796 | DeclContext *DC, *LexicalDC; |
| 4797 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4798 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4799 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4800 | Error Err = Error::success(); |
| 4801 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 4802 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); |
| 4803 | auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc()); |
| 4804 | if (Err) |
| 4805 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4806 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4807 | if (GetImportedOrCreateDecl( |
| 4808 | ToImpl, D, Importer.getToContext(), DC, |
| 4809 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4810 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4811 | return ToImpl; |
| 4812 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4813 | ToImpl->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4814 | LexicalDC->addDeclInternal(ToImpl); |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4815 | Category->setImplementation(ToImpl); |
| 4816 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4817 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4818 | Importer.MapImported(D, ToImpl); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4819 | if (Error Err = ImportDeclContext(D)) |
| 4820 | return std::move(Err); |
| 4821 | |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4822 | return ToImpl; |
| 4823 | } |
| 4824 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4825 | ExpectedDecl |
| 4826 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4827 | // Find the corresponding interface. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4828 | ObjCInterfaceDecl *Iface; |
| 4829 | if (Error Err = importInto(Iface, D->getClassInterface())) |
| 4830 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4831 | |
| 4832 | // Import the superclass, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4833 | ObjCInterfaceDecl *Super; |
| 4834 | if (Error Err = importInto(Super, D->getSuperClass())) |
| 4835 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4836 | |
| 4837 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4838 | if (!Impl) { |
| 4839 | // We haven't imported an implementation yet. Create a new @implementation |
| 4840 | // now. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4841 | DeclContext *DC, *LexicalDC; |
| 4842 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4843 | return std::move(Err); |
| 4844 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4845 | Error Err = Error::success(); |
| 4846 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 4847 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); |
| 4848 | auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc()); |
| 4849 | auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc()); |
| 4850 | auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc()); |
| 4851 | if (Err) |
| 4852 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4853 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4854 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4855 | DC, Iface, Super, |
| 4856 | ToLocation, |
| 4857 | ToAtStartLoc, |
| 4858 | ToSuperClassLoc, |
| 4859 | ToIvarLBraceLoc, |
| 4860 | ToIvarRBraceLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4861 | return Impl; |
| 4862 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4863 | Impl->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4864 | |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4865 | // Associate the implementation with the class it implements. |
| 4866 | Iface->setImplementation(Impl); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4867 | Importer.MapImported(D, Iface->getImplementation()); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4868 | } else { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4869 | Importer.MapImported(D, Iface->getImplementation()); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4870 | |
| 4871 | // Verify that the existing @implementation has the same superclass. |
| 4872 | if ((Super && !Impl->getSuperClass()) || |
| 4873 | (!Super && Impl->getSuperClass()) || |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4874 | (Super && Impl->getSuperClass() && |
| 4875 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4876 | Impl->getSuperClass()))) { |
| 4877 | Importer.ToDiag(Impl->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4878 | diag::warn_odr_objc_superclass_inconsistent) |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4879 | << Iface->getDeclName(); |
| 4880 | // FIXME: It would be nice to have the location of the superclass |
| 4881 | // below. |
| 4882 | if (Impl->getSuperClass()) |
| 4883 | Importer.ToDiag(Impl->getLocation(), |
| 4884 | diag::note_odr_objc_superclass) |
| 4885 | << Impl->getSuperClass()->getDeclName(); |
| 4886 | else |
| 4887 | Importer.ToDiag(Impl->getLocation(), |
| 4888 | diag::note_odr_objc_missing_superclass); |
| 4889 | if (D->getSuperClass()) |
| 4890 | Importer.FromDiag(D->getLocation(), |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4891 | diag::note_odr_objc_superclass) |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4892 | << D->getSuperClass()->getDeclName(); |
| 4893 | else |
| 4894 | Importer.FromDiag(D->getLocation(), |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4895 | diag::note_odr_objc_missing_superclass); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4896 | |
| 4897 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4898 | } |
| 4899 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4900 | |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4901 | // Import all of the members of this @implementation. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4902 | if (Error Err = ImportDeclContext(D)) |
| 4903 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4904 | |
| 4905 | return Impl; |
| 4906 | } |
| 4907 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4908 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4909 | // Import the major distinguishing characteristics of an @property. |
| 4910 | DeclContext *DC, *LexicalDC; |
| 4911 | DeclarationName Name; |
| 4912 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4913 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4914 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4915 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4916 | if (ToD) |
| 4917 | return ToD; |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4918 | |
| 4919 | // Check whether we have already imported this property. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4920 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4921 | for (auto *FoundDecl : FoundDecls) { |
| 4922 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4923 | // Check property types. |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4924 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4925 | FoundProp->getType())) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4926 | Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent) |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4927 | << Name << D->getType() << FoundProp->getType(); |
| 4928 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4929 | << FoundProp->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4930 | |
| 4931 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4932 | } |
| 4933 | |
| 4934 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4935 | |
| 4936 | // Consider these properties to be equivalent. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4937 | Importer.MapImported(D, FoundProp); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4938 | return FoundProp; |
| 4939 | } |
| 4940 | } |
| 4941 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4942 | Error Err = Error::success(); |
| 4943 | auto ToType = importChecked(Err, D->getType()); |
| 4944 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 4945 | auto ToAtLoc = importChecked(Err, D->getAtLoc()); |
| 4946 | auto ToLParenLoc = importChecked(Err, D->getLParenLoc()); |
| 4947 | if (Err) |
| 4948 | return std::move(Err); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4949 | |
| 4950 | // Create the new property. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4951 | ObjCPropertyDecl *ToProperty; |
| 4952 | if (GetImportedOrCreateDecl( |
| 4953 | ToProperty, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4954 | Name.getAsIdentifierInfo(), ToAtLoc, |
| 4955 | ToLParenLoc, ToType, |
| 4956 | ToTypeSourceInfo, D->getPropertyImplementation())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4957 | return ToProperty; |
| 4958 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4959 | auto ToGetterName = importChecked(Err, D->getGetterName()); |
| 4960 | auto ToSetterName = importChecked(Err, D->getSetterName()); |
| 4961 | auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc()); |
| 4962 | auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc()); |
| 4963 | auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl()); |
| 4964 | auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl()); |
| 4965 | auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl()); |
| 4966 | if (Err) |
| 4967 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4968 | |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4969 | ToProperty->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4970 | LexicalDC->addDeclInternal(ToProperty); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4971 | |
| 4972 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
| Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4973 | ToProperty->setPropertyAttributesAsWritten( |
| 4974 | D->getPropertyAttributesAsWritten()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4975 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); |
| 4976 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); |
| 4977 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); |
| 4978 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); |
| 4979 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4980 | return ToProperty; |
| 4981 | } |
| 4982 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4983 | ExpectedDecl |
| 4984 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 4985 | ObjCPropertyDecl *Property; |
| 4986 | if (Error Err = importInto(Property, D->getPropertyDecl())) |
| 4987 | return std::move(Err); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4988 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4989 | DeclContext *DC, *LexicalDC; |
| 4990 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4991 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4992 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4993 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4994 | |
| 4995 | // Import the ivar (for an @synthesize). |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4996 | ObjCIvarDecl *Ivar = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4997 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) |
| 4998 | return std::move(Err); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4999 | |
| 5000 | ObjCPropertyImplDecl *ToImpl |
| Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 5001 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 5002 | Property->getQueryKind()); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5003 | if (!ToImpl) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5004 | |
| 5005 | Error Err = Error::success(); |
| 5006 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); |
| 5007 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 5008 | auto ToPropertyIvarDeclLoc = |
| 5009 | importChecked(Err, D->getPropertyIvarDeclLoc()); |
| 5010 | if (Err) |
| 5011 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5012 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5013 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5014 | ToBeginLoc, |
| 5015 | ToLocation, Property, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5016 | D->getPropertyImplementation(), Ivar, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5017 | ToPropertyIvarDeclLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5018 | return ToImpl; |
| 5019 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5020 | ToImpl->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 5021 | LexicalDC->addDeclInternal(ToImpl); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5022 | } else { |
| 5023 | // Check that we have the same kind of property implementation (@synthesize |
| 5024 | // vs. @dynamic). |
| 5025 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5026 | Importer.ToDiag(ToImpl->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 5027 | diag::warn_odr_objc_property_impl_kind_inconsistent) |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5028 | << Property->getDeclName() |
| 5029 | << (ToImpl->getPropertyImplementation() |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5030 | == ObjCPropertyImplDecl::Dynamic); |
| 5031 | Importer.FromDiag(D->getLocation(), |
| 5032 | diag::note_odr_objc_property_impl_kind) |
| 5033 | << D->getPropertyDecl()->getDeclName() |
| 5034 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5035 | |
| 5036 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5037 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5038 | |
| 5039 | // For @synthesize, check that we have the same |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5040 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 5041 | Ivar != ToImpl->getPropertyIvarDecl()) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5042 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 5043 | diag::warn_odr_objc_synthesize_ivar_inconsistent) |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5044 | << Property->getDeclName() |
| 5045 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 5046 | << Ivar->getDeclName(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5047 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5048 | diag::note_odr_objc_synthesize_ivar_here) |
| 5049 | << D->getPropertyIvarDecl()->getDeclName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5050 | |
| 5051 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5052 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5053 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5054 | // Merge the existing implementation with the new implementation. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5055 | Importer.MapImported(D, ToImpl); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5056 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5057 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5058 | return ToImpl; |
| 5059 | } |
| 5060 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5061 | ExpectedDecl |
| 5062 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5063 | // For template arguments, we adopt the translation unit as our declaration |
| 5064 | // context. This context will be fixed when the actual template declaration |
| 5065 | // is created. |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5066 | |
| Saar Raz | ff1e0fc | 2020-01-15 02:48:42 +0200 | [diff] [blame] | 5067 | // FIXME: Import default argument and constraint expression. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5068 | |
| 5069 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5070 | if (!BeginLocOrErr) |
| 5071 | return BeginLocOrErr.takeError(); |
| 5072 | |
| 5073 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 5074 | if (!LocationOrErr) |
| 5075 | return LocationOrErr.takeError(); |
| 5076 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5077 | TemplateTypeParmDecl *ToD = nullptr; |
| Saar Raz | ff1e0fc | 2020-01-15 02:48:42 +0200 | [diff] [blame] | 5078 | if (GetImportedOrCreateDecl( |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5079 | ToD, D, Importer.getToContext(), |
| 5080 | Importer.getToContext().getTranslationUnitDecl(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5081 | *BeginLocOrErr, *LocationOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5082 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| Saar Raz | ff1e0fc | 2020-01-15 02:48:42 +0200 | [diff] [blame] | 5083 | D->wasDeclaredWithTypename(), D->isParameterPack(), |
| 5084 | D->hasTypeConstraint())) |
| 5085 | return ToD; |
| 5086 | |
| 5087 | // Import the type-constraint |
| 5088 | if (const TypeConstraint *TC = D->getTypeConstraint()) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5089 | |
| 5090 | Error Err = Error::success(); |
| 5091 | auto ToNNS = importChecked(Err, TC->getNestedNameSpecifierLoc()); |
| 5092 | auto ToName = importChecked(Err, TC->getConceptNameInfo().getName()); |
| 5093 | auto ToNameLoc = importChecked(Err, TC->getConceptNameInfo().getLoc()); |
| 5094 | auto ToFoundDecl = importChecked(Err, TC->getFoundDecl()); |
| 5095 | auto ToNamedConcept = importChecked(Err, TC->getNamedConcept()); |
| 5096 | auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint()); |
| 5097 | if (Err) |
| 5098 | return std::move(Err); |
| Saar Raz | ff1e0fc | 2020-01-15 02:48:42 +0200 | [diff] [blame] | 5099 | |
| 5100 | TemplateArgumentListInfo ToTAInfo; |
| 5101 | const auto *ASTTemplateArgs = TC->getTemplateArgsAsWritten(); |
| 5102 | if (ASTTemplateArgs) |
| 5103 | if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, |
| 5104 | ToTAInfo)) |
| 5105 | return std::move(Err); |
| 5106 | |
| 5107 | ToD->setTypeConstraint(ToNNS, DeclarationNameInfo(ToName, ToNameLoc), |
| 5108 | ToFoundDecl, ToNamedConcept, |
| 5109 | ASTTemplateArgs ? |
| 5110 | ASTTemplateArgumentListInfo::Create(Importer.getToContext(), |
| 5111 | ToTAInfo) : nullptr, |
| 5112 | ToIDC); |
| 5113 | } |
| 5114 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5115 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5116 | } |
| 5117 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5118 | ExpectedDecl |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5119 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5120 | |
| 5121 | Error Err = Error::success(); |
| 5122 | auto ToDeclName = importChecked(Err, D->getDeclName()); |
| 5123 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 5124 | auto ToType = importChecked(Err, D->getType()); |
| 5125 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 5126 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 5127 | if (Err) |
| 5128 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5129 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5130 | // FIXME: Import default argument. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5131 | |
| 5132 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 5133 | (void)GetImportedOrCreateDecl( |
| 5134 | ToD, D, Importer.getToContext(), |
| 5135 | Importer.getToContext().getTranslationUnitDecl(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5136 | ToInnerLocStart, ToLocation, D->getDepth(), |
| 5137 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, |
| 5138 | D->isParameterPack(), ToTypeSourceInfo); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5139 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5140 | } |
| 5141 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5142 | ExpectedDecl |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5143 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 5144 | // Import the name of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5145 | auto NameOrErr = import(D->getDeclName()); |
| 5146 | if (!NameOrErr) |
| 5147 | return NameOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5148 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5149 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5150 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 5151 | if (!LocationOrErr) |
| 5152 | return LocationOrErr.takeError(); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5153 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5154 | // Import template parameters. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5155 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5156 | if (!TemplateParamsOrErr) |
| 5157 | return TemplateParamsOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5158 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5159 | // FIXME: Import default argument. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5160 | |
| 5161 | TemplateTemplateParmDecl *ToD = nullptr; |
| 5162 | (void)GetImportedOrCreateDecl( |
| 5163 | ToD, D, Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5164 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, |
| 5165 | D->getDepth(), D->getPosition(), D->isParameterPack(), |
| 5166 | (*NameOrErr).getAsIdentifierInfo(), |
| 5167 | *TemplateParamsOrErr); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5168 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5169 | } |
| 5170 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5171 | // Returns the definition for a (forward) declaration of a TemplateDecl, if |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5172 | // it has any definition in the redecl chain. |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5173 | template <typename T> static auto getTemplateDefinition(T *D) -> T * { |
| 5174 | assert(D->getTemplatedDecl() && "Should be called on templates only"); |
| 5175 | auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5176 | if (!ToTemplatedDef) |
| 5177 | return nullptr; |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5178 | auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate(); |
| 5179 | return cast_or_null<T>(TemplateWithDef); |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5180 | } |
| 5181 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5182 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5183 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5184 | // Import the major distinguishing characteristics of this class template. |
| 5185 | DeclContext *DC, *LexicalDC; |
| 5186 | DeclarationName Name; |
| 5187 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5188 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5189 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5190 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5191 | if (ToD) |
| 5192 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5193 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5194 | ClassTemplateDecl *FoundByLookup = nullptr; |
| 5195 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5196 | // We may already have a template of the same name; try to find and match it. |
| 5197 | if (!DC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5198 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5199 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5200 | for (auto *FoundDecl : FoundDecls) { |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5201 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary | |
| 5202 | Decl::IDNS_TagFriend)) |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5203 | continue; |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5204 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5205 | Decl *Found = FoundDecl; |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5206 | auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found); |
| 5207 | if (FoundTemplate) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 5208 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D)) |
| Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 5209 | continue; |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5210 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5211 | if (IsStructuralMatch(D, FoundTemplate)) { |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5212 | ClassTemplateDecl *TemplateWithDef = |
| 5213 | getTemplateDefinition(FoundTemplate); |
| Balazs Keri | 2e16060 | 2019-08-12 10:07:38 +0000 | [diff] [blame] | 5214 | if (D->isThisDeclarationADefinition() && TemplateWithDef) |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5215 | return Importer.MapImported(D, TemplateWithDef); |
| Balazs Keri | 2e16060 | 2019-08-12 10:07:38 +0000 | [diff] [blame] | 5216 | if (!FoundByLookup) |
| 5217 | FoundByLookup = FoundTemplate; |
| 5218 | // Search in all matches because there may be multiple decl chains, |
| 5219 | // see ASTTests test ImportExistingFriendClassTemplateDef. |
| 5220 | continue; |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5221 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5222 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5223 | } |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5224 | } |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5225 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5226 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5227 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 5228 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), |
| 5229 | ConflictingDecls.size()); |
| 5230 | if (NameOrErr) |
| 5231 | Name = NameOrErr.get(); |
| 5232 | else |
| 5233 | return NameOrErr.takeError(); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5234 | } |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5235 | } |
| 5236 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5237 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 5238 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5239 | // Create the declaration that is being templated. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5240 | CXXRecordDecl *ToTemplated; |
| 5241 | if (Error Err = importInto(ToTemplated, FromTemplated)) |
| 5242 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5243 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5244 | // Create the class template declaration itself. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5245 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5246 | if (!TemplateParamsOrErr) |
| 5247 | return TemplateParamsOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5248 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5249 | ClassTemplateDecl *D2; |
| 5250 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5251 | *TemplateParamsOrErr, ToTemplated)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5252 | return D2; |
| 5253 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5254 | ToTemplated->setDescribedClassTemplate(D2); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5255 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5256 | D2->setAccess(D->getAccess()); |
| 5257 | D2->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5258 | |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 5259 | addDeclToContexts(D, D2); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5260 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5261 | if (FoundByLookup) { |
| 5262 | auto *Recent = |
| 5263 | const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5264 | |
| 5265 | // It is possible that during the import of the class template definition |
| 5266 | // we start the import of a fwd friend decl of the very same class template |
| 5267 | // and we add the fwd friend decl to the lookup table. But the ToTemplated |
| 5268 | // had been created earlier and by that time the lookup could not find |
| 5269 | // anything existing, so it has no previous decl. Later, (still during the |
| 5270 | // import of the fwd friend decl) we start to import the definition again |
| 5271 | // and this time the lookup finds the previous fwd friend class template. |
| 5272 | // In this case we must set up the previous decl for the templated decl. |
| 5273 | if (!ToTemplated->getPreviousDecl()) { |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5274 | assert(FoundByLookup->getTemplatedDecl() && |
| 5275 | "Found decl must have its templated decl set"); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5276 | CXXRecordDecl *PrevTemplated = |
| 5277 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5278 | if (ToTemplated != PrevTemplated) |
| 5279 | ToTemplated->setPreviousDecl(PrevTemplated); |
| 5280 | } |
| 5281 | |
| 5282 | D2->setPreviousDecl(Recent); |
| 5283 | } |
| 5284 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5285 | if (FromTemplated->isCompleteDefinition() && |
| 5286 | !ToTemplated->isCompleteDefinition()) { |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5287 | // FIXME: Import definition! |
| 5288 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5289 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5290 | return D2; |
| 5291 | } |
| 5292 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5293 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5294 | ClassTemplateSpecializationDecl *D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5295 | ClassTemplateDecl *ClassTemplate; |
| 5296 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) |
| 5297 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5298 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5299 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5300 | DeclContext *DC, *LexicalDC; |
| 5301 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5302 | return std::move(Err); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5303 | |
| 5304 | // Import template arguments. |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5305 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5306 | if (Error Err = ImportTemplateArguments( |
| 5307 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5308 | return std::move(Err); |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5309 | // Try to find an existing specialization with these template arguments and |
| 5310 | // template parameter list. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5311 | void *InsertPos = nullptr; |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5312 | ClassTemplateSpecializationDecl *PrevDecl = nullptr; |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5313 | ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 5314 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5315 | |
| 5316 | // Import template parameters. |
| 5317 | TemplateParameterList *ToTPList = nullptr; |
| 5318 | |
| 5319 | if (PartialSpec) { |
| 5320 | auto ToTPListOrErr = import(PartialSpec->getTemplateParameters()); |
| 5321 | if (!ToTPListOrErr) |
| 5322 | return ToTPListOrErr.takeError(); |
| 5323 | ToTPList = *ToTPListOrErr; |
| 5324 | PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs, |
| 5325 | *ToTPListOrErr, |
| 5326 | InsertPos); |
| 5327 | } else |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5328 | PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5329 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5330 | if (PrevDecl) { |
| 5331 | if (IsStructuralMatch(D, PrevDecl)) { |
| 5332 | if (D->isThisDeclarationADefinition() && PrevDecl->getDefinition()) { |
| 5333 | Importer.MapImported(D, PrevDecl->getDefinition()); |
| 5334 | // Import those default field initializers which have been |
| 5335 | // instantiated in the "From" context, but not in the "To" context. |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5336 | for (auto *FromField : D->fields()) { |
| 5337 | auto ToOrErr = import(FromField); |
| 5338 | if (!ToOrErr) |
| 5339 | return ToOrErr.takeError(); |
| 5340 | } |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5341 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5342 | // Import those methods which have been instantiated in the |
| 5343 | // "From" context, but not in the "To" context. |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5344 | for (CXXMethodDecl *FromM : D->methods()) { |
| 5345 | auto ToOrErr = import(FromM); |
| 5346 | if (!ToOrErr) |
| 5347 | return ToOrErr.takeError(); |
| 5348 | } |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5349 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5350 | // TODO Import instantiated default arguments. |
| 5351 | // TODO Import instantiated exception specifications. |
| 5352 | // |
| 5353 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint |
| 5354 | // what else could be fused during an AST merge. |
| 5355 | return PrevDecl; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5356 | } |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5357 | } else { // ODR violation. |
| 5358 | // FIXME HandleNameConflict |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 5359 | return make_error<ImportError>(ImportError::NameConflict); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5360 | } |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5361 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5362 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5363 | // Import the location of this declaration. |
| 5364 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5365 | if (!BeginLocOrErr) |
| 5366 | return BeginLocOrErr.takeError(); |
| 5367 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); |
| 5368 | if (!IdLocOrErr) |
| 5369 | return IdLocOrErr.takeError(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5370 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5371 | // Create the specialization. |
| 5372 | ClassTemplateSpecializationDecl *D2 = nullptr; |
| 5373 | if (PartialSpec) { |
| 5374 | // Import TemplateArgumentListInfo. |
| 5375 | TemplateArgumentListInfo ToTAInfo; |
| 5376 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 5377 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
| 5378 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5379 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5380 | QualType CanonInjType; |
| 5381 | if (Error Err = importInto( |
| 5382 | CanonInjType, PartialSpec->getInjectedSpecializationType())) |
| 5383 | return std::move(Err); |
| 5384 | CanonInjType = CanonInjType.getCanonicalType(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5385 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5386 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
| 5387 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5388 | *BeginLocOrErr, *IdLocOrErr, ToTPList, ClassTemplate, |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5389 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 5390 | ToTAInfo, CanonInjType, |
| 5391 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) |
| 5392 | return D2; |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5393 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5394 | // Update InsertPos, because preceding import calls may have invalidated |
| 5395 | // it by adding new specializations. |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5396 | auto *PartSpec2 = cast<ClassTemplatePartialSpecializationDecl>(D2); |
| 5397 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList, |
| 5398 | InsertPos)) |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5399 | // Add this partial specialization to the class template. |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5400 | ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5401 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5402 | } else { // Not a partial specialization. |
| 5403 | if (GetImportedOrCreateDecl( |
| 5404 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5405 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, |
| 5406 | PrevDecl)) |
| 5407 | return D2; |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5408 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5409 | // Update InsertPos, because preceding import calls may have invalidated |
| 5410 | // it by adding new specializations. |
| 5411 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) |
| 5412 | // Add this specialization to the class template. |
| 5413 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 5414 | } |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5415 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5416 | D2->setSpecializationKind(D->getSpecializationKind()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5417 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5418 | // Set the context of this specialization/instantiation. |
| 5419 | D2->setLexicalDeclContext(LexicalDC); |
| 5420 | |
| 5421 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 5422 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 5423 | LexicalDC->addDeclInternal(D2); |
| 5424 | } |
| 5425 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 5426 | if (auto BraceRangeOrErr = import(D->getBraceRange())) |
| 5427 | D2->setBraceRange(*BraceRangeOrErr); |
| 5428 | else |
| 5429 | return BraceRangeOrErr.takeError(); |
| 5430 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5431 | // Import the qualifier, if any. |
| 5432 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5433 | D2->setQualifierInfo(*LocOrErr); |
| 5434 | else |
| 5435 | return LocOrErr.takeError(); |
| 5436 | |
| 5437 | if (auto *TSI = D->getTypeAsWritten()) { |
| 5438 | if (auto TInfoOrErr = import(TSI)) |
| 5439 | D2->setTypeAsWritten(*TInfoOrErr); |
| 5440 | else |
| 5441 | return TInfoOrErr.takeError(); |
| 5442 | |
| 5443 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) |
| 5444 | D2->setTemplateKeywordLoc(*LocOrErr); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5445 | else |
| 5446 | return LocOrErr.takeError(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5447 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5448 | if (auto LocOrErr = import(D->getExternLoc())) |
| 5449 | D2->setExternLoc(*LocOrErr); |
| 5450 | else |
| 5451 | return LocOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5452 | } |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5453 | |
| 5454 | if (D->getPointOfInstantiation().isValid()) { |
| 5455 | if (auto POIOrErr = import(D->getPointOfInstantiation())) |
| 5456 | D2->setPointOfInstantiation(*POIOrErr); |
| 5457 | else |
| 5458 | return POIOrErr.takeError(); |
| 5459 | } |
| 5460 | |
| 5461 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 5462 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5463 | if (D->isCompleteDefinition()) |
| 5464 | if (Error Err = ImportDefinition(D, D2)) |
| 5465 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5466 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5467 | return D2; |
| 5468 | } |
| 5469 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5470 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5471 | // Import the major distinguishing characteristics of this variable template. |
| 5472 | DeclContext *DC, *LexicalDC; |
| 5473 | DeclarationName Name; |
| 5474 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5475 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5476 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5477 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5478 | if (ToD) |
| 5479 | return ToD; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5480 | |
| 5481 | // We may already have a template of the same name; try to find and match it. |
| 5482 | assert(!DC->isFunctionOrMethod() && |
| 5483 | "Variable templates cannot be declared at function scope"); |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 5484 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5485 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5486 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 5487 | VarTemplateDecl *FoundByLookup = nullptr; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5488 | for (auto *FoundDecl : FoundDecls) { |
| 5489 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5490 | continue; |
| 5491 | |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 5492 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) { |
| Balázs Kéri | 8d67bcf | 2020-03-09 11:01:48 +0100 | [diff] [blame] | 5493 | // Use the templated decl, some linkage flags are set only there. |
| 5494 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(), |
| 5495 | D->getTemplatedDecl())) |
| 5496 | continue; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5497 | if (IsStructuralMatch(D, FoundTemplate)) { |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 5498 | // The Decl in the "From" context has a definition, but in the |
| 5499 | // "To" context we already have a definition. |
| 5500 | VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate); |
| 5501 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 5502 | // FIXME Check for ODR error if the two definitions have |
| 5503 | // different initializers? |
| 5504 | return Importer.MapImported(D, FoundDef); |
| 5505 | |
| 5506 | FoundByLookup = FoundTemplate; |
| 5507 | break; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5508 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5509 | ConflictingDecls.push_back(FoundDecl); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5510 | } |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5511 | } |
| 5512 | |
| 5513 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5514 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 5515 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), |
| 5516 | ConflictingDecls.size()); |
| 5517 | if (NameOrErr) |
| 5518 | Name = NameOrErr.get(); |
| 5519 | else |
| 5520 | return NameOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5521 | } |
| 5522 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5523 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 5524 | |
| 5525 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5526 | // FIXME: Value not used? |
| 5527 | ExpectedType TypeOrErr = import(DTemplated->getType()); |
| 5528 | if (!TypeOrErr) |
| 5529 | return TypeOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5530 | |
| 5531 | // Create the declaration that is being templated. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5532 | VarDecl *ToTemplated; |
| 5533 | if (Error Err = importInto(ToTemplated, DTemplated)) |
| 5534 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5535 | |
| 5536 | // Create the variable template declaration itself. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5537 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5538 | if (!TemplateParamsOrErr) |
| 5539 | return TemplateParamsOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5540 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5541 | VarTemplateDecl *ToVarTD; |
| 5542 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5543 | Name, *TemplateParamsOrErr, ToTemplated)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5544 | return ToVarTD; |
| 5545 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5546 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5547 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5548 | ToVarTD->setAccess(D->getAccess()); |
| 5549 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 5550 | LexicalDC->addDeclInternal(ToVarTD); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5551 | |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 5552 | if (FoundByLookup) { |
| 5553 | auto *Recent = |
| 5554 | const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5555 | if (!ToTemplated->getPreviousDecl()) { |
| 5556 | auto *PrevTemplated = |
| 5557 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5558 | if (ToTemplated != PrevTemplated) |
| 5559 | ToTemplated->setPreviousDecl(PrevTemplated); |
| 5560 | } |
| 5561 | ToVarTD->setPreviousDecl(Recent); |
| 5562 | } |
| 5563 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5564 | if (DTemplated->isThisDeclarationADefinition() && |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5565 | !ToTemplated->isThisDeclarationADefinition()) { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5566 | // FIXME: Import definition! |
| 5567 | } |
| 5568 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5569 | return ToVarTD; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5570 | } |
| 5571 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5572 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5573 | VarTemplateSpecializationDecl *D) { |
| 5574 | // If this record has a definition in the translation unit we're coming from, |
| 5575 | // but this particular declaration is not that definition, import the |
| 5576 | // definition and map to that. |
| 5577 | VarDecl *Definition = D->getDefinition(); |
| 5578 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5579 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5580 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5581 | else |
| 5582 | return ImportedDefOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5583 | } |
| 5584 | |
| Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 5585 | VarTemplateDecl *VarTemplate = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5586 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) |
| 5587 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5588 | |
| 5589 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5590 | DeclContext *DC, *LexicalDC; |
| 5591 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5592 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5593 | |
| 5594 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5595 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5596 | if (!BeginLocOrErr) |
| 5597 | return BeginLocOrErr.takeError(); |
| 5598 | |
| 5599 | auto IdLocOrErr = import(D->getLocation()); |
| 5600 | if (!IdLocOrErr) |
| 5601 | return IdLocOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5602 | |
| 5603 | // Import template arguments. |
| 5604 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5605 | if (Error Err = ImportTemplateArguments( |
| 5606 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5607 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5608 | |
| 5609 | // Try to find an existing specialization with these template arguments. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5610 | void *InsertPos = nullptr; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5611 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
| Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 5612 | TemplateArgs, InsertPos); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5613 | if (D2) { |
| 5614 | // We already have a variable template specialization with these template |
| 5615 | // arguments. |
| 5616 | |
| 5617 | // FIXME: Check for specialization vs. instantiation errors. |
| 5618 | |
| 5619 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 5620 | if (!D->isThisDeclarationADefinition() || |
| 5621 | IsStructuralMatch(D, FoundDef)) { |
| 5622 | // The record types structurally match, or the "from" translation |
| 5623 | // unit only had a forward declaration anyway; call it the same |
| 5624 | // variable. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5625 | return Importer.MapImported(D, FoundDef); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5626 | } |
| 5627 | } |
| 5628 | } else { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5629 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5630 | QualType T; |
| 5631 | if (Error Err = importInto(T, D->getType())) |
| 5632 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5633 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5634 | auto TInfoOrErr = import(D->getTypeSourceInfo()); |
| 5635 | if (!TInfoOrErr) |
| 5636 | return TInfoOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5637 | |
| 5638 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5639 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5640 | D->getTemplateArgsInfo(), ToTAInfo)) |
| 5641 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5642 | |
| 5643 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5644 | // Create a new specialization. |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5645 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 5646 | // Import TemplateArgumentListInfo |
| 5647 | TemplateArgumentListInfo ArgInfos; |
| 5648 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 5649 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5650 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5651 | *FromTAArgsAsWritten, ArgInfos)) |
| 5652 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5653 | |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5654 | auto ToTPListOrErr = import(FromPartial->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5655 | if (!ToTPListOrErr) |
| 5656 | return ToTPListOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5657 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5658 | PartVarSpecDecl *ToPartial; |
| 5659 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5660 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, |
| 5661 | VarTemplate, T, *TInfoOrErr, |
| 5662 | D->getStorageClass(), TemplateArgs, ArgInfos)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5663 | return ToPartial; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5664 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5665 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( |
| 5666 | FromPartial->getInstantiatedFromMember())) |
| 5667 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); |
| 5668 | else |
| 5669 | return ToInstOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5670 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5671 | if (FromPartial->isMemberSpecialization()) |
| 5672 | ToPartial->setMemberSpecialization(); |
| 5673 | |
| 5674 | D2 = ToPartial; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5675 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5676 | } else { // Full specialization |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5677 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, |
| 5678 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, |
| 5679 | T, *TInfoOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5680 | D->getStorageClass(), TemplateArgs)) |
| 5681 | return D2; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5682 | } |
| 5683 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5684 | if (D->getPointOfInstantiation().isValid()) { |
| 5685 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) |
| 5686 | D2->setPointOfInstantiation(*POIOrErr); |
| 5687 | else |
| 5688 | return POIOrErr.takeError(); |
| 5689 | } |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5690 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5691 | D2->setSpecializationKind(D->getSpecializationKind()); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5692 | D2->setTemplateArgsInfo(ToTAInfo); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5693 | |
| 5694 | // Add this specialization to the class template. |
| 5695 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 5696 | |
| 5697 | // Import the qualifier, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5698 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5699 | D2->setQualifierInfo(*LocOrErr); |
| 5700 | else |
| 5701 | return LocOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5702 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5703 | if (D->isConstexpr()) |
| 5704 | D2->setConstexpr(true); |
| 5705 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5706 | // Add the specialization to this context. |
| 5707 | D2->setLexicalDeclContext(LexicalDC); |
| 5708 | LexicalDC->addDeclInternal(D2); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5709 | |
| 5710 | D2->setAccess(D->getAccess()); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5711 | } |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5712 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5713 | if (Error Err = ImportInitializer(D, D2)) |
| 5714 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5715 | |
| 5716 | return D2; |
| 5717 | } |
| 5718 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5719 | ExpectedDecl |
| 5720 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5721 | DeclContext *DC, *LexicalDC; |
| 5722 | DeclarationName Name; |
| 5723 | SourceLocation Loc; |
| 5724 | NamedDecl *ToD; |
| 5725 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5726 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5727 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5728 | |
| 5729 | if (ToD) |
| 5730 | return ToD; |
| 5731 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5732 | const FunctionTemplateDecl *FoundByLookup = nullptr; |
| 5733 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5734 | // Try to find a function in our own ("to") context with the same name, same |
| 5735 | // type, and in the same context as the function we're importing. |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5736 | // FIXME Split this into a separate function. |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5737 | if (!LexicalDC->isFunctionOrMethod()) { |
| Gabor Marton | e331e63 | 2019-02-18 13:09:27 +0000 | [diff] [blame] | 5738 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5739 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5740 | for (auto *FoundDecl : FoundDecls) { |
| 5741 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5742 | continue; |
| 5743 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5744 | if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 5745 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D)) |
| Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 5746 | continue; |
| 5747 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5748 | FunctionTemplateDecl *TemplateWithDef = |
| 5749 | getTemplateDefinition(FoundTemplate); |
| 5750 | if (D->isThisDeclarationADefinition() && TemplateWithDef) |
| 5751 | return Importer.MapImported(D, TemplateWithDef); |
| 5752 | |
| 5753 | FoundByLookup = FoundTemplate; |
| 5754 | break; |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5755 | // TODO: handle conflicting names |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5756 | } |
| 5757 | } |
| 5758 | } |
| 5759 | } |
| 5760 | |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5761 | auto ParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5762 | if (!ParamsOrErr) |
| 5763 | return ParamsOrErr.takeError(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5764 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5765 | FunctionDecl *TemplatedFD; |
| 5766 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) |
| 5767 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5768 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5769 | FunctionTemplateDecl *ToFunc; |
| 5770 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5771 | *ParamsOrErr, TemplatedFD)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5772 | return ToFunc; |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5773 | |
| 5774 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5775 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5776 | ToFunc->setAccess(D->getAccess()); |
| 5777 | ToFunc->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5778 | LexicalDC->addDeclInternal(ToFunc); |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5779 | |
| 5780 | if (FoundByLookup) { |
| 5781 | auto *Recent = |
| 5782 | const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5783 | if (!TemplatedFD->getPreviousDecl()) { |
| 5784 | assert(FoundByLookup->getTemplatedDecl() && |
| 5785 | "Found decl must have its templated decl set"); |
| 5786 | auto *PrevTemplated = |
| 5787 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5788 | if (TemplatedFD != PrevTemplated) |
| 5789 | TemplatedFD->setPreviousDecl(PrevTemplated); |
| 5790 | } |
| 5791 | ToFunc->setPreviousDecl(Recent); |
| 5792 | } |
| 5793 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5794 | return ToFunc; |
| 5795 | } |
| 5796 | |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5797 | //---------------------------------------------------------------------------- |
| 5798 | // Import Statements |
| 5799 | //---------------------------------------------------------------------------- |
| 5800 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5801 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5802 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) |
| 5803 | << S->getStmtClassName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5804 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5805 | } |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5806 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5807 | |
| 5808 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 5809 | if (Importer.returnWithErrorInTest()) |
| 5810 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5811 | SmallVector<IdentifierInfo *, 4> Names; |
| 5812 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 5813 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
| Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5814 | // ToII is nullptr when no symbolic name is given for output operand |
| 5815 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5816 | Names.push_back(ToII); |
| 5817 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5818 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5819 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 5820 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
| Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5821 | // ToII is nullptr when no symbolic name is given for input operand |
| 5822 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5823 | Names.push_back(ToII); |
| 5824 | } |
| 5825 | |
| 5826 | SmallVector<StringLiteral *, 4> Clobbers; |
| 5827 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5828 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) |
| 5829 | Clobbers.push_back(*ClobberOrErr); |
| 5830 | else |
| 5831 | return ClobberOrErr.takeError(); |
| 5832 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5833 | } |
| 5834 | |
| 5835 | SmallVector<StringLiteral *, 4> Constraints; |
| 5836 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5837 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) |
| 5838 | Constraints.push_back(*OutputOrErr); |
| 5839 | else |
| 5840 | return OutputOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5841 | } |
| 5842 | |
| 5843 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5844 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) |
| 5845 | Constraints.push_back(*InputOrErr); |
| 5846 | else |
| 5847 | return InputOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5848 | } |
| 5849 | |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5850 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() + |
| 5851 | S->getNumLabels()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5852 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) |
| 5853 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5854 | |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5855 | if (Error Err = |
| 5856 | ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
| 5857 | return std::move(Err); |
| 5858 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5859 | if (Error Err = ImportArrayChecked( |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5860 | S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs())) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5861 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5862 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5863 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); |
| 5864 | if (!AsmLocOrErr) |
| 5865 | return AsmLocOrErr.takeError(); |
| 5866 | auto AsmStrOrErr = import(S->getAsmString()); |
| 5867 | if (!AsmStrOrErr) |
| 5868 | return AsmStrOrErr.takeError(); |
| 5869 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); |
| 5870 | if (!RParenLocOrErr) |
| 5871 | return RParenLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5872 | |
| 5873 | return new (Importer.getToContext()) GCCAsmStmt( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5874 | Importer.getToContext(), |
| 5875 | *AsmLocOrErr, |
| 5876 | S->isSimple(), |
| 5877 | S->isVolatile(), |
| 5878 | S->getNumOutputs(), |
| 5879 | S->getNumInputs(), |
| 5880 | Names.data(), |
| 5881 | Constraints.data(), |
| 5882 | Exprs.data(), |
| 5883 | *AsmStrOrErr, |
| 5884 | S->getNumClobbers(), |
| 5885 | Clobbers.data(), |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5886 | S->getNumLabels(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5887 | *RParenLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5888 | } |
| 5889 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5890 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5891 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5892 | Error Err = Error::success(); |
| 5893 | auto ToDG = importChecked(Err, S->getDeclGroup()); |
| 5894 | auto ToBeginLoc = importChecked(Err, S->getBeginLoc()); |
| 5895 | auto ToEndLoc = importChecked(Err, S->getEndLoc()); |
| 5896 | if (Err) |
| 5897 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5898 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5899 | } |
| 5900 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5901 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5902 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); |
| 5903 | if (!ToSemiLocOrErr) |
| 5904 | return ToSemiLocOrErr.takeError(); |
| 5905 | return new (Importer.getToContext()) NullStmt( |
| 5906 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5907 | } |
| 5908 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5909 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5910 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5911 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5912 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) |
| 5913 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5914 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5915 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); |
| 5916 | if (!ToLBracLocOrErr) |
| 5917 | return ToLBracLocOrErr.takeError(); |
| 5918 | |
| 5919 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); |
| 5920 | if (!ToRBracLocOrErr) |
| 5921 | return ToRBracLocOrErr.takeError(); |
| 5922 | |
| 5923 | return CompoundStmt::Create( |
| 5924 | Importer.getToContext(), ToStmts, |
| 5925 | *ToLBracLocOrErr, *ToRBracLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5926 | } |
| 5927 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5928 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5929 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5930 | Error Err = Error::success(); |
| 5931 | auto ToLHS = importChecked(Err, S->getLHS()); |
| 5932 | auto ToRHS = importChecked(Err, S->getRHS()); |
| 5933 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); |
| 5934 | auto ToCaseLoc = importChecked(Err, S->getCaseLoc()); |
| 5935 | auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc()); |
| 5936 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); |
| 5937 | if (Err) |
| 5938 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5939 | |
| Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 5940 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, |
| 5941 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
| Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5942 | ToStmt->setSubStmt(ToSubStmt); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5943 | |
| Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5944 | return ToStmt; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5945 | } |
| 5946 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5947 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5948 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5949 | Error Err = Error::success(); |
| 5950 | auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc()); |
| 5951 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); |
| 5952 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); |
| 5953 | if (Err) |
| 5954 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5955 | |
| 5956 | return new (Importer.getToContext()) DefaultStmt( |
| 5957 | ToDefaultLoc, ToColonLoc, ToSubStmt); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5958 | } |
| 5959 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5960 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5961 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5962 | Error Err = Error::success(); |
| 5963 | auto ToIdentLoc = importChecked(Err, S->getIdentLoc()); |
| 5964 | auto ToLabelDecl = importChecked(Err, S->getDecl()); |
| 5965 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); |
| 5966 | if (Err) |
| 5967 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5968 | |
| 5969 | return new (Importer.getToContext()) LabelStmt( |
| 5970 | ToIdentLoc, ToLabelDecl, ToSubStmt); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5971 | } |
| 5972 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5973 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 5974 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); |
| 5975 | if (!ToAttrLocOrErr) |
| 5976 | return ToAttrLocOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5977 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 5978 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5979 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) |
| 5980 | return std::move(Err); |
| 5981 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 5982 | if (!ToSubStmtOrErr) |
| 5983 | return ToSubStmtOrErr.takeError(); |
| 5984 | |
| 5985 | return AttributedStmt::Create( |
| 5986 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5987 | } |
| 5988 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5989 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5990 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5991 | Error Err = Error::success(); |
| 5992 | auto ToIfLoc = importChecked(Err, S->getIfLoc()); |
| 5993 | auto ToInit = importChecked(Err, S->getInit()); |
| 5994 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); |
| 5995 | auto ToCond = importChecked(Err, S->getCond()); |
| 5996 | auto ToThen = importChecked(Err, S->getThen()); |
| 5997 | auto ToElseLoc = importChecked(Err, S->getElseLoc()); |
| 5998 | auto ToElse = importChecked(Err, S->getElse()); |
| 5999 | if (Err) |
| 6000 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6001 | |
| Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 6002 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), |
| 6003 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, |
| 6004 | ToElse); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6005 | } |
| 6006 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6007 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6008 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6009 | Error Err = Error::success(); |
| 6010 | auto ToInit = importChecked(Err, S->getInit()); |
| 6011 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); |
| 6012 | auto ToCond = importChecked(Err, S->getCond()); |
| 6013 | auto ToBody = importChecked(Err, S->getBody()); |
| 6014 | auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc()); |
| 6015 | if (Err) |
| 6016 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6017 | |
| Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 6018 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, |
| 6019 | ToConditionVariable, ToCond); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6020 | ToStmt->setBody(ToBody); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6021 | ToStmt->setSwitchLoc(ToSwitchLoc); |
| 6022 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6023 | // Now we have to re-chain the cases. |
| 6024 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 6025 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 6026 | SC = SC->getNextSwitchCase()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6027 | Expected<SwitchCase *> ToSCOrErr = import(SC); |
| 6028 | if (!ToSCOrErr) |
| 6029 | return ToSCOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6030 | if (LastChainedSwitchCase) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6031 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6032 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6033 | ToStmt->setSwitchCaseList(*ToSCOrErr); |
| 6034 | LastChainedSwitchCase = *ToSCOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6035 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6036 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6037 | return ToStmt; |
| 6038 | } |
| 6039 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6040 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6041 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6042 | Error Err = Error::success(); |
| 6043 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); |
| 6044 | auto ToCond = importChecked(Err, S->getCond()); |
| 6045 | auto ToBody = importChecked(Err, S->getBody()); |
| 6046 | auto ToWhileLoc = importChecked(Err, S->getWhileLoc()); |
| 6047 | if (Err) |
| 6048 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6049 | |
| Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 6050 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, |
| 6051 | ToBody, ToWhileLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6052 | } |
| 6053 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6054 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6055 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6056 | Error Err = Error::success(); |
| 6057 | auto ToBody = importChecked(Err, S->getBody()); |
| 6058 | auto ToCond = importChecked(Err, S->getCond()); |
| 6059 | auto ToDoLoc = importChecked(Err, S->getDoLoc()); |
| 6060 | auto ToWhileLoc = importChecked(Err, S->getWhileLoc()); |
| 6061 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); |
| 6062 | if (Err) |
| 6063 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6064 | |
| 6065 | return new (Importer.getToContext()) DoStmt( |
| 6066 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6067 | } |
| 6068 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6069 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6070 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6071 | Error Err = Error::success(); |
| 6072 | auto ToInit = importChecked(Err, S->getInit()); |
| 6073 | auto ToCond = importChecked(Err, S->getCond()); |
| 6074 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); |
| 6075 | auto ToInc = importChecked(Err, S->getInc()); |
| 6076 | auto ToBody = importChecked(Err, S->getBody()); |
| 6077 | auto ToForLoc = importChecked(Err, S->getForLoc()); |
| 6078 | auto ToLParenLoc = importChecked(Err, S->getLParenLoc()); |
| 6079 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); |
| 6080 | if (Err) |
| 6081 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6082 | |
| 6083 | return new (Importer.getToContext()) ForStmt( |
| 6084 | Importer.getToContext(), |
| 6085 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, |
| 6086 | ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6087 | } |
| 6088 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6089 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6090 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6091 | Error Err = Error::success(); |
| 6092 | auto ToLabel = importChecked(Err, S->getLabel()); |
| 6093 | auto ToGotoLoc = importChecked(Err, S->getGotoLoc()); |
| 6094 | auto ToLabelLoc = importChecked(Err, S->getLabelLoc()); |
| 6095 | if (Err) |
| 6096 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6097 | |
| 6098 | return new (Importer.getToContext()) GotoStmt( |
| 6099 | ToLabel, ToGotoLoc, ToLabelLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6100 | } |
| 6101 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6102 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6103 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6104 | Error Err = Error::success(); |
| 6105 | auto ToGotoLoc = importChecked(Err, S->getGotoLoc()); |
| 6106 | auto ToStarLoc = importChecked(Err, S->getStarLoc()); |
| 6107 | auto ToTarget = importChecked(Err, S->getTarget()); |
| 6108 | if (Err) |
| 6109 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6110 | |
| 6111 | return new (Importer.getToContext()) IndirectGotoStmt( |
| 6112 | ToGotoLoc, ToStarLoc, ToTarget); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6113 | } |
| 6114 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6115 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 6116 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); |
| 6117 | if (!ToContinueLocOrErr) |
| 6118 | return ToContinueLocOrErr.takeError(); |
| 6119 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6120 | } |
| 6121 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6122 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 6123 | auto ToBreakLocOrErr = import(S->getBreakLoc()); |
| 6124 | if (!ToBreakLocOrErr) |
| 6125 | return ToBreakLocOrErr.takeError(); |
| 6126 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6127 | } |
| 6128 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6129 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6130 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6131 | Error Err = Error::success(); |
| 6132 | auto ToReturnLoc = importChecked(Err, S->getReturnLoc()); |
| 6133 | auto ToRetValue = importChecked(Err, S->getRetValue()); |
| 6134 | auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate()); |
| 6135 | if (Err) |
| 6136 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6137 | |
| Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 6138 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, |
| 6139 | ToNRVOCandidate); |
| 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::VisitCXXCatchStmt(CXXCatchStmt *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 ToCatchLoc = importChecked(Err, S->getCatchLoc()); |
| 6146 | auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl()); |
| 6147 | auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock()); |
| 6148 | if (Err) |
| 6149 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6150 | |
| 6151 | return new (Importer.getToContext()) CXXCatchStmt ( |
| 6152 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6153 | } |
| 6154 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6155 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 6156 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); |
| 6157 | if (!ToTryLocOrErr) |
| 6158 | return ToTryLocOrErr.takeError(); |
| 6159 | |
| 6160 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); |
| 6161 | if (!ToTryBlockOrErr) |
| 6162 | return ToTryBlockOrErr.takeError(); |
| 6163 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6164 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 6165 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 6166 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6167 | if (auto ToHandlerOrErr = import(FromHandler)) |
| 6168 | ToHandlers[HI] = *ToHandlerOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6169 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6170 | return ToHandlerOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6171 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6172 | |
| 6173 | return CXXTryStmt::Create( |
| 6174 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6175 | } |
| 6176 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6177 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6178 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6179 | Error Err = Error::success(); |
| 6180 | auto ToInit = importChecked(Err, S->getInit()); |
| 6181 | auto ToRangeStmt = importChecked(Err, S->getRangeStmt()); |
| 6182 | auto ToBeginStmt = importChecked(Err, S->getBeginStmt()); |
| 6183 | auto ToEndStmt = importChecked(Err, S->getEndStmt()); |
| 6184 | auto ToCond = importChecked(Err, S->getCond()); |
| 6185 | auto ToInc = importChecked(Err, S->getInc()); |
| 6186 | auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt()); |
| 6187 | auto ToBody = importChecked(Err, S->getBody()); |
| 6188 | auto ToForLoc = importChecked(Err, S->getForLoc()); |
| 6189 | auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc()); |
| 6190 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); |
| 6191 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); |
| 6192 | if (Err) |
| 6193 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6194 | |
| 6195 | return new (Importer.getToContext()) CXXForRangeStmt( |
| 6196 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 6197 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6198 | } |
| 6199 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6200 | ExpectedStmt |
| 6201 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6202 | Error Err = Error::success(); |
| 6203 | auto ToElement = importChecked(Err, S->getElement()); |
| 6204 | auto ToCollection = importChecked(Err, S->getCollection()); |
| 6205 | auto ToBody = importChecked(Err, S->getBody()); |
| 6206 | auto ToForLoc = importChecked(Err, S->getForLoc()); |
| 6207 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); |
| 6208 | if (Err) |
| 6209 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6210 | |
| 6211 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, |
| 6212 | ToCollection, |
| 6213 | ToBody, |
| 6214 | ToForLoc, |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6215 | ToRParenLoc); |
| 6216 | } |
| 6217 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6218 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6219 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6220 | Error Err = Error::success(); |
| 6221 | auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc()); |
| 6222 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); |
| 6223 | auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl()); |
| 6224 | auto ToCatchBody = importChecked(Err, S->getCatchBody()); |
| 6225 | if (Err) |
| 6226 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6227 | |
| 6228 | return new (Importer.getToContext()) ObjCAtCatchStmt ( |
| 6229 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6230 | } |
| 6231 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6232 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 6233 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); |
| 6234 | if (!ToAtFinallyLocOrErr) |
| 6235 | return ToAtFinallyLocOrErr.takeError(); |
| 6236 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); |
| 6237 | if (!ToAtFinallyStmtOrErr) |
| 6238 | return ToAtFinallyStmtOrErr.takeError(); |
| 6239 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, |
| 6240 | *ToAtFinallyStmtOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6241 | } |
| 6242 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6243 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6244 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6245 | Error Err = Error::success(); |
| 6246 | auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc()); |
| 6247 | auto ToTryBody = importChecked(Err, S->getTryBody()); |
| 6248 | auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt()); |
| 6249 | if (Err) |
| 6250 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6251 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6252 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 6253 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 6254 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6255 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) |
| 6256 | ToCatchStmts[CI] = *ToCatchStmtOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6257 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6258 | return ToCatchStmtOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6259 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6260 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6261 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6262 | ToAtTryLoc, ToTryBody, |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6263 | ToCatchStmts.begin(), ToCatchStmts.size(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6264 | ToFinallyStmt); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6265 | } |
| 6266 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6267 | ExpectedStmt |
| 6268 | ASTNodeImporter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6269 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6270 | Error Err = Error::success(); |
| 6271 | auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc()); |
| 6272 | auto ToSynchExpr = importChecked(Err, S->getSynchExpr()); |
| 6273 | auto ToSynchBody = importChecked(Err, S->getSynchBody()); |
| 6274 | if (Err) |
| 6275 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6276 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6277 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 6278 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 6279 | } |
| 6280 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6281 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 6282 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); |
| 6283 | if (!ToThrowLocOrErr) |
| 6284 | return ToThrowLocOrErr.takeError(); |
| 6285 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); |
| 6286 | if (!ToThrowExprOrErr) |
| 6287 | return ToThrowExprOrErr.takeError(); |
| 6288 | return new (Importer.getToContext()) ObjCAtThrowStmt( |
| 6289 | *ToThrowLocOrErr, *ToThrowExprOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6290 | } |
| 6291 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6292 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( |
| 6293 | ObjCAutoreleasePoolStmt *S) { |
| 6294 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); |
| 6295 | if (!ToAtLocOrErr) |
| 6296 | return ToAtLocOrErr.takeError(); |
| 6297 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 6298 | if (!ToSubStmtOrErr) |
| 6299 | return ToSubStmtOrErr.takeError(); |
| 6300 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, |
| 6301 | *ToSubStmtOrErr); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6302 | } |
| 6303 | |
| 6304 | //---------------------------------------------------------------------------- |
| 6305 | // Import Expressions |
| 6306 | //---------------------------------------------------------------------------- |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6307 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6308 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) |
| 6309 | << E->getStmtClassName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6310 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6311 | } |
| 6312 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6313 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6314 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6315 | Error Err = Error::success(); |
| 6316 | auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); |
| 6317 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 6318 | auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo()); |
| 6319 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 6320 | auto ToType = importChecked(Err, E->getType()); |
| 6321 | if (Err) |
| 6322 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6323 | |
| 6324 | return new (Importer.getToContext()) VAArgExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6325 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, |
| 6326 | E->isMicrosoftABI()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6327 | } |
| 6328 | |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6329 | ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) { |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6330 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6331 | Error Err = Error::success(); |
| 6332 | auto ToCond = importChecked(Err, E->getCond()); |
| 6333 | auto ToLHS = importChecked(Err, E->getLHS()); |
| 6334 | auto ToRHS = importChecked(Err, E->getRHS()); |
| 6335 | auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); |
| 6336 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 6337 | auto ToType = importChecked(Err, E->getType()); |
| 6338 | if (Err) |
| 6339 | return std::move(Err); |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6340 | |
| 6341 | ExprValueKind VK = E->getValueKind(); |
| 6342 | ExprObjectKind OK = E->getObjectKind(); |
| 6343 | |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6344 | // The value of CondIsTrue only matters if the value is not |
| 6345 | // condition-dependent. |
| 6346 | bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue(); |
| 6347 | |
| 6348 | return new (Importer.getToContext()) |
| 6349 | ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK, |
| Haojian Wu | 876bb86 | 2020-03-17 08:33:37 +0100 | [diff] [blame] | 6350 | ToRParenLoc, CondIsTrue); |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6351 | } |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6352 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6353 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 6354 | ExpectedType TypeOrErr = import(E->getType()); |
| 6355 | if (!TypeOrErr) |
| 6356 | return TypeOrErr.takeError(); |
| 6357 | |
| 6358 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); |
| 6359 | if (!BeginLocOrErr) |
| 6360 | return BeginLocOrErr.takeError(); |
| 6361 | |
| 6362 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6363 | } |
| 6364 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6365 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6366 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6367 | Error Err = Error::success(); |
| 6368 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 6369 | auto ToType = importChecked(Err, E->getType()); |
| 6370 | auto ToFunctionName = importChecked(Err, E->getFunctionName()); |
| 6371 | if (Err) |
| 6372 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6373 | |
| Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 6374 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, |
| 6375 | E->getIdentKind(), ToFunctionName); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6376 | } |
| 6377 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6378 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6379 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6380 | Error Err = Error::success(); |
| 6381 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 6382 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); |
| 6383 | auto ToDecl = importChecked(Err, E->getDecl()); |
| 6384 | auto ToLocation = importChecked(Err, E->getLocation()); |
| 6385 | auto ToType = importChecked(Err, E->getType()); |
| 6386 | if (Err) |
| 6387 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6388 | |
| 6389 | NamedDecl *ToFoundD = nullptr; |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6390 | if (E->getDecl() != E->getFoundDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6391 | auto FoundDOrErr = import(E->getFoundDecl()); |
| 6392 | if (!FoundDOrErr) |
| 6393 | return FoundDOrErr.takeError(); |
| 6394 | ToFoundD = *FoundDOrErr; |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6395 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6396 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6397 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6398 | TemplateArgumentListInfo *ToResInfo = nullptr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6399 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6400 | if (Error Err = |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 6401 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6402 | E->template_arguments(), ToTAInfo)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6403 | return std::move(Err); |
| 6404 | ToResInfo = &ToTAInfo; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6405 | } |
| 6406 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6407 | auto *ToE = DeclRefExpr::Create( |
| 6408 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, |
| 6409 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, |
| Richard Smith | 715f7a1 | 2019-06-11 17:50:32 +0000 | [diff] [blame] | 6410 | E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse()); |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 6411 | if (E->hadMultipleCandidates()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6412 | ToE->setHadMultipleCandidates(true); |
| 6413 | return ToE; |
| Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 6414 | } |
| 6415 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6416 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 6417 | ExpectedType TypeOrErr = import(E->getType()); |
| 6418 | if (!TypeOrErr) |
| 6419 | return TypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6420 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6421 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6422 | } |
| 6423 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6424 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 6425 | ExpectedExpr ToInitOrErr = import(E->getInit()); |
| 6426 | if (!ToInitOrErr) |
| 6427 | return ToInitOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6428 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6429 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); |
| 6430 | if (!ToEqualOrColonLocOrErr) |
| 6431 | return ToEqualOrColonLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6432 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6433 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6434 | // List elements from the second, the first is Init itself |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6435 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { |
| 6436 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) |
| 6437 | ToIndexExprs[I - 1] = *ToArgOrErr; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6438 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6439 | return ToArgOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6440 | } |
| 6441 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6442 | SmallVector<Designator, 4> ToDesignators(E->size()); |
| 6443 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) |
| 6444 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6445 | |
| 6446 | return DesignatedInitExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6447 | Importer.getToContext(), ToDesignators, |
| 6448 | ToIndexExprs, *ToEqualOrColonLocOrErr, |
| 6449 | E->usesGNUSyntax(), *ToInitOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6450 | } |
| 6451 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6452 | ExpectedStmt |
| 6453 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 6454 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6455 | if (!ToTypeOrErr) |
| 6456 | return ToTypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6457 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6458 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6459 | if (!ToLocationOrErr) |
| 6460 | return ToLocationOrErr.takeError(); |
| 6461 | |
| 6462 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( |
| 6463 | *ToTypeOrErr, *ToLocationOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6464 | } |
| 6465 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6466 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 6467 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6468 | if (!ToTypeOrErr) |
| 6469 | return ToTypeOrErr.takeError(); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6470 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6471 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6472 | if (!ToLocationOrErr) |
| 6473 | return ToLocationOrErr.takeError(); |
| 6474 | |
| 6475 | return IntegerLiteral::Create( |
| 6476 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6477 | } |
| 6478 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6479 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6480 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 6481 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6482 | if (!ToTypeOrErr) |
| 6483 | return ToTypeOrErr.takeError(); |
| 6484 | |
| 6485 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6486 | if (!ToLocationOrErr) |
| 6487 | return ToLocationOrErr.takeError(); |
| 6488 | |
| 6489 | return FloatingLiteral::Create( |
| 6490 | Importer.getToContext(), E->getValue(), E->isExact(), |
| 6491 | *ToTypeOrErr, *ToLocationOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6492 | } |
| 6493 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6494 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 6495 | auto ToTypeOrErr = import(E->getType()); |
| 6496 | if (!ToTypeOrErr) |
| 6497 | return ToTypeOrErr.takeError(); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6498 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6499 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6500 | if (!ToSubExprOrErr) |
| 6501 | return ToSubExprOrErr.takeError(); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6502 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6503 | return new (Importer.getToContext()) ImaginaryLiteral( |
| 6504 | *ToSubExprOrErr, *ToTypeOrErr); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6505 | } |
| 6506 | |
| Vince Bridgers | 789215d | 2020-04-06 08:22:35 -0500 | [diff] [blame] | 6507 | ExpectedStmt ASTNodeImporter::VisitFixedPointLiteral(FixedPointLiteral *E) { |
| 6508 | auto ToTypeOrErr = import(E->getType()); |
| 6509 | if (!ToTypeOrErr) |
| 6510 | return ToTypeOrErr.takeError(); |
| 6511 | |
| 6512 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6513 | if (!ToLocationOrErr) |
| 6514 | return ToLocationOrErr.takeError(); |
| 6515 | |
| 6516 | return new (Importer.getToContext()) FixedPointLiteral( |
| 6517 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr, |
| 6518 | Importer.getToContext().getFixedPointScale(*ToTypeOrErr)); |
| 6519 | } |
| 6520 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6521 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 6522 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6523 | if (!ToTypeOrErr) |
| 6524 | return ToTypeOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6525 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6526 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6527 | if (!ToLocationOrErr) |
| 6528 | return ToLocationOrErr.takeError(); |
| 6529 | |
| 6530 | return new (Importer.getToContext()) CharacterLiteral( |
| 6531 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); |
| Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 6532 | } |
| 6533 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6534 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 6535 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6536 | if (!ToTypeOrErr) |
| 6537 | return ToTypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6538 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6539 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); |
| 6540 | if (Error Err = ImportArrayChecked( |
| 6541 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) |
| 6542 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6543 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6544 | return StringLiteral::Create( |
| 6545 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), |
| 6546 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6547 | } |
| 6548 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6549 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6550 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6551 | Error Err = Error::success(); |
| 6552 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); |
| 6553 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); |
| 6554 | auto ToType = importChecked(Err, E->getType()); |
| 6555 | auto ToInitializer = importChecked(Err, E->getInitializer()); |
| 6556 | if (Err) |
| 6557 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6558 | |
| 6559 | return new (Importer.getToContext()) CompoundLiteralExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6560 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), |
| 6561 | ToInitializer, E->isFileScope()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6562 | } |
| 6563 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6564 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6565 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6566 | Error Err = Error::success(); |
| 6567 | auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); |
| 6568 | auto ToType = importChecked(Err, E->getType()); |
| 6569 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 6570 | if (Err) |
| 6571 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6572 | |
| 6573 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); |
| 6574 | if (Error Err = ImportArrayChecked( |
| 6575 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 6576 | ToExprs.begin())) |
| 6577 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6578 | |
| 6579 | return new (Importer.getToContext()) AtomicExpr( |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6580 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6581 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6582 | } |
| 6583 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6584 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6585 | Error Err = Error::success(); |
| 6586 | auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc()); |
| 6587 | auto ToLabelLoc = importChecked(Err, E->getLabelLoc()); |
| 6588 | auto ToLabel = importChecked(Err, E->getLabel()); |
| 6589 | auto ToType = importChecked(Err, E->getType()); |
| 6590 | if (Err) |
| 6591 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6592 | |
| 6593 | return new (Importer.getToContext()) AddrLabelExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6594 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6595 | } |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6596 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6597 | Error Err = Error::success(); |
| 6598 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 6599 | if (Err) |
| 6600 | return std::move(Err); |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6601 | |
| Gauthier Harnisch | 83c7b61 | 2019-06-15 10:24:47 +0000 | [diff] [blame] | 6602 | // TODO : Handle APValue::ValueKind that require importing. |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6603 | |
| Gauthier Harnisch | 83c7b61 | 2019-06-15 10:24:47 +0000 | [diff] [blame] | 6604 | APValue::ValueKind Kind = E->getResultAPValueKind(); |
| 6605 | if (Kind == APValue::Int || Kind == APValue::Float || |
| 6606 | Kind == APValue::FixedPoint || Kind == APValue::ComplexFloat || |
| 6607 | Kind == APValue::ComplexInt) |
| 6608 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, |
| 6609 | E->getAPValueResult()); |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 6610 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr); |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6611 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6612 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6613 | Error Err = Error::success(); |
| 6614 | auto ToLParen = importChecked(Err, E->getLParen()); |
| 6615 | auto ToRParen = importChecked(Err, E->getRParen()); |
| 6616 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 6617 | if (Err) |
| 6618 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6619 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6620 | return new (Importer.getToContext()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6621 | ParenExpr(ToLParen, ToRParen, ToSubExpr); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6622 | } |
| 6623 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6624 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 6625 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); |
| 6626 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) |
| 6627 | return std::move(Err); |
| 6628 | |
| 6629 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); |
| 6630 | if (!ToLParenLocOrErr) |
| 6631 | return ToLParenLocOrErr.takeError(); |
| 6632 | |
| 6633 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); |
| 6634 | if (!ToRParenLocOrErr) |
| 6635 | return ToRParenLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6636 | |
| Bruno Ricci | f49e1ca | 2018-11-20 16:20:40 +0000 | [diff] [blame] | 6637 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, |
| 6638 | ToExprs, *ToRParenLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6639 | } |
| 6640 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6641 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6642 | Error Err = Error::success(); |
| 6643 | auto ToSubStmt = importChecked(Err, E->getSubStmt()); |
| 6644 | auto ToType = importChecked(Err, E->getType()); |
| 6645 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); |
| 6646 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 6647 | if (Err) |
| 6648 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6649 | |
| Richard Smith | 5c845c1 | 2020-03-09 17:34:33 -0700 | [diff] [blame] | 6650 | return new (Importer.getToContext()) |
| 6651 | StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc, |
| 6652 | E->getTemplateDepth()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6653 | } |
| 6654 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6655 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6656 | Error Err = Error::success(); |
| 6657 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 6658 | auto ToType = importChecked(Err, E->getType()); |
| 6659 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 6660 | if (Err) |
| 6661 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6662 | |
| Melanie Blower | f5360d4 | 2020-05-01 10:32:06 -0700 | [diff] [blame^] | 6663 | return UnaryOperator::Create( |
| 6664 | Importer.getToContext(), ToSubExpr, E->getOpcode(), ToType, |
| 6665 | E->getValueKind(), E->getObjectKind(), ToOperatorLoc, E->canOverflow(), |
| 6666 | E->getFPFeatures(Importer.getFromContext().getLangOpts())); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6667 | } |
| 6668 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6669 | ExpectedStmt |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6670 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6671 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
| 6672 | Error Err = Error::success(); |
| 6673 | auto ToType = importChecked(Err, E->getType()); |
| 6674 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 6675 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 6676 | if (Err) |
| 6677 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6678 | |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6679 | if (E->isArgumentType()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6680 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = |
| 6681 | import(E->getArgumentTypeInfo()); |
| 6682 | if (!ToArgumentTypeInfoOrErr) |
| 6683 | return ToArgumentTypeInfoOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6684 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6685 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6686 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, |
| 6687 | ToRParenLoc); |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6688 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6689 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6690 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); |
| 6691 | if (!ToArgumentExprOrErr) |
| 6692 | return ToArgumentExprOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6693 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6694 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6695 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6696 | } |
| 6697 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6698 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6699 | Error Err = Error::success(); |
| 6700 | auto ToLHS = importChecked(Err, E->getLHS()); |
| 6701 | auto ToRHS = importChecked(Err, E->getRHS()); |
| 6702 | auto ToType = importChecked(Err, E->getType()); |
| 6703 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 6704 | if (Err) |
| 6705 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6706 | |
| Benjamin Kramer | 3ee1ec0 | 2020-04-16 11:45:02 +0200 | [diff] [blame] | 6707 | return BinaryOperator::Create( |
| 6708 | Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType, |
| 6709 | E->getValueKind(), E->getObjectKind(), ToOperatorLoc, |
| 6710 | E->getFPFeatures(Importer.getFromContext().getLangOpts())); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6711 | } |
| 6712 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6713 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6714 | Error Err = Error::success(); |
| 6715 | auto ToCond = importChecked(Err, E->getCond()); |
| 6716 | auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc()); |
| 6717 | auto ToLHS = importChecked(Err, E->getLHS()); |
| 6718 | auto ToColonLoc = importChecked(Err, E->getColonLoc()); |
| 6719 | auto ToRHS = importChecked(Err, E->getRHS()); |
| 6720 | auto ToType = importChecked(Err, E->getType()); |
| 6721 | if (Err) |
| 6722 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6723 | |
| 6724 | return new (Importer.getToContext()) ConditionalOperator( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6725 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, |
| 6726 | E->getValueKind(), E->getObjectKind()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6727 | } |
| 6728 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6729 | ExpectedStmt |
| 6730 | ASTNodeImporter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) { |
| 6731 | Error Err = Error::success(); |
| 6732 | auto ToCommon = importChecked(Err, E->getCommon()); |
| 6733 | auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue()); |
| 6734 | auto ToCond = importChecked(Err, E->getCond()); |
| 6735 | auto ToTrueExpr = importChecked(Err, E->getTrueExpr()); |
| 6736 | auto ToFalseExpr = importChecked(Err, E->getFalseExpr()); |
| 6737 | auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc()); |
| 6738 | auto ToColonLoc = importChecked(Err, E->getColonLoc()); |
| 6739 | auto ToType = importChecked(Err, E->getType()); |
| 6740 | if (Err) |
| 6741 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6742 | |
| 6743 | return new (Importer.getToContext()) BinaryConditionalOperator( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6744 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, |
| 6745 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), |
| 6746 | E->getObjectKind()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6747 | } |
| 6748 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6749 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6750 | Error Err = Error::success(); |
| 6751 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 6752 | auto ToQueriedTypeSourceInfo = |
| 6753 | importChecked(Err, E->getQueriedTypeSourceInfo()); |
| 6754 | auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression()); |
| 6755 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); |
| 6756 | auto ToType = importChecked(Err, E->getType()); |
| 6757 | if (Err) |
| 6758 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6759 | |
| 6760 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6761 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), |
| 6762 | ToDimensionExpression, ToEndLoc, ToType); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6763 | } |
| 6764 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6765 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6766 | Error Err = Error::success(); |
| 6767 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 6768 | auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression()); |
| 6769 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); |
| 6770 | auto ToType = importChecked(Err, E->getType()); |
| 6771 | if (Err) |
| 6772 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6773 | |
| 6774 | return new (Importer.getToContext()) ExpressionTraitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6775 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), |
| 6776 | ToEndLoc, ToType); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6777 | } |
| 6778 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6779 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6780 | Error Err = Error::success(); |
| 6781 | auto ToLocation = importChecked(Err, E->getLocation()); |
| 6782 | auto ToType = importChecked(Err, E->getType()); |
| 6783 | auto ToSourceExpr = importChecked(Err, E->getSourceExpr()); |
| 6784 | if (Err) |
| 6785 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6786 | |
| 6787 | return new (Importer.getToContext()) OpaqueValueExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6788 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6789 | } |
| 6790 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6791 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6792 | Error Err = Error::success(); |
| 6793 | auto ToLHS = importChecked(Err, E->getLHS()); |
| 6794 | auto ToRHS = importChecked(Err, E->getRHS()); |
| 6795 | auto ToType = importChecked(Err, E->getType()); |
| 6796 | auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc()); |
| 6797 | if (Err) |
| 6798 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6799 | |
| 6800 | return new (Importer.getToContext()) ArraySubscriptExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6801 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), |
| 6802 | ToRBracketLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6803 | } |
| 6804 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6805 | ExpectedStmt |
| 6806 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6807 | Error Err = Error::success(); |
| 6808 | auto ToLHS = importChecked(Err, E->getLHS()); |
| 6809 | auto ToRHS = importChecked(Err, E->getRHS()); |
| 6810 | auto ToType = importChecked(Err, E->getType()); |
| 6811 | auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType()); |
| 6812 | auto ToComputationResultType = |
| 6813 | importChecked(Err, E->getComputationResultType()); |
| 6814 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 6815 | if (Err) |
| 6816 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6817 | |
| Melanie Blower | 2ba4e3a | 2020-04-10 13:34:46 -0700 | [diff] [blame] | 6818 | return CompoundAssignOperator::Create( |
| 6819 | Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType, |
| 6820 | E->getValueKind(), E->getObjectKind(), ToOperatorLoc, |
| Benjamin Kramer | 3ee1ec0 | 2020-04-16 11:45:02 +0200 | [diff] [blame] | 6821 | E->getFPFeatures(Importer.getFromContext().getLangOpts()), |
| Gabor Marton | e033ec2 | 2020-04-16 15:48:13 +0200 | [diff] [blame] | 6822 | ToComputationLHSType, ToComputationResultType); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6823 | } |
| 6824 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6825 | Expected<CXXCastPath> |
| 6826 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { |
| 6827 | CXXCastPath Path; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6828 | 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] | 6829 | if (auto SpecOrErr = import(*I)) |
| 6830 | Path.push_back(*SpecOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6831 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6832 | return SpecOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6833 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6834 | return Path; |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6835 | } |
| 6836 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6837 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 6838 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6839 | if (!ToTypeOrErr) |
| 6840 | return ToTypeOrErr.takeError(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6841 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6842 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6843 | if (!ToSubExprOrErr) |
| 6844 | return ToSubExprOrErr.takeError(); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6845 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6846 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6847 | if (!ToBasePathOrErr) |
| 6848 | return ToBasePathOrErr.takeError(); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6849 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6850 | return ImplicitCastExpr::Create( |
| 6851 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, |
| 6852 | &(*ToBasePathOrErr), E->getValueKind()); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6853 | } |
| 6854 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6855 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6856 | Error Err = Error::success(); |
| 6857 | auto ToType = importChecked(Err, E->getType()); |
| 6858 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 6859 | auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten()); |
| 6860 | if (Err) |
| 6861 | return std::move(Err); |
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6862 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6863 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6864 | if (!ToBasePathOrErr) |
| 6865 | return ToBasePathOrErr.takeError(); |
| 6866 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6867 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6868 | switch (E->getStmtClass()) { |
| 6869 | case Stmt::CStyleCastExprClass: { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6870 | auto *CCE = cast<CStyleCastExpr>(E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6871 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); |
| 6872 | if (!ToLParenLocOrErr) |
| 6873 | return ToLParenLocOrErr.takeError(); |
| 6874 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); |
| 6875 | if (!ToRParenLocOrErr) |
| 6876 | return ToRParenLocOrErr.takeError(); |
| 6877 | return CStyleCastExpr::Create( |
| 6878 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), |
| 6879 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, |
| 6880 | *ToRParenLocOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6881 | } |
| 6882 | |
| 6883 | case Stmt::CXXFunctionalCastExprClass: { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6884 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6885 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); |
| 6886 | if (!ToLParenLocOrErr) |
| 6887 | return ToLParenLocOrErr.takeError(); |
| 6888 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); |
| 6889 | if (!ToRParenLocOrErr) |
| 6890 | return ToRParenLocOrErr.takeError(); |
| 6891 | return CXXFunctionalCastExpr::Create( |
| 6892 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, |
| 6893 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, |
| 6894 | *ToRParenLocOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6895 | } |
| 6896 | |
| 6897 | case Stmt::ObjCBridgedCastExprClass: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6898 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
| 6899 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); |
| 6900 | if (!ToLParenLocOrErr) |
| 6901 | return ToLParenLocOrErr.takeError(); |
| 6902 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); |
| 6903 | if (!ToBridgeKeywordLocOrErr) |
| 6904 | return ToBridgeKeywordLocOrErr.takeError(); |
| 6905 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 6906 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), |
| 6907 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6908 | } |
| 6909 | default: |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6910 | llvm_unreachable("Cast expression of unsupported type!"); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6911 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6912 | } |
| 6913 | } |
| 6914 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6915 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { |
| 6916 | SmallVector<OffsetOfNode, 4> ToNodes; |
| 6917 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { |
| 6918 | const OffsetOfNode &FromNode = E->getComponent(I); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6919 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6920 | SourceLocation ToBeginLoc, ToEndLoc; |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6921 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6922 | if (FromNode.getKind() != OffsetOfNode::Base) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6923 | Error Err = Error::success(); |
| 6924 | ToBeginLoc = importChecked(Err, FromNode.getBeginLoc()); |
| 6925 | ToEndLoc = importChecked(Err, FromNode.getEndLoc()); |
| 6926 | if (Err) |
| 6927 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6928 | } |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6929 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6930 | switch (FromNode.getKind()) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6931 | case OffsetOfNode::Array: |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6932 | ToNodes.push_back( |
| 6933 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6934 | break; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6935 | case OffsetOfNode::Base: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6936 | auto ToBSOrErr = import(FromNode.getBase()); |
| 6937 | if (!ToBSOrErr) |
| 6938 | return ToBSOrErr.takeError(); |
| 6939 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6940 | break; |
| 6941 | } |
| 6942 | case OffsetOfNode::Field: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6943 | auto ToFieldOrErr = import(FromNode.getField()); |
| 6944 | if (!ToFieldOrErr) |
| 6945 | return ToFieldOrErr.takeError(); |
| 6946 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6947 | break; |
| 6948 | } |
| 6949 | case OffsetOfNode::Identifier: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6950 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); |
| 6951 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6952 | break; |
| 6953 | } |
| 6954 | } |
| 6955 | } |
| 6956 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6957 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); |
| 6958 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { |
| 6959 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); |
| 6960 | if (!ToIndexExprOrErr) |
| 6961 | return ToIndexExprOrErr.takeError(); |
| 6962 | ToExprs[I] = *ToIndexExprOrErr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6963 | } |
| 6964 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6965 | Error Err = Error::success(); |
| 6966 | auto ToType = importChecked(Err, E->getType()); |
| 6967 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); |
| 6968 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 6969 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 6970 | if (Err) |
| 6971 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6972 | |
| 6973 | return OffsetOfExpr::Create( |
| 6974 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, |
| 6975 | ToExprs, ToRParenLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6976 | } |
| 6977 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6978 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6979 | Error Err = Error::success(); |
| 6980 | auto ToType = importChecked(Err, E->getType()); |
| 6981 | auto ToOperand = importChecked(Err, E->getOperand()); |
| 6982 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 6983 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); |
| 6984 | if (Err) |
| 6985 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6986 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6987 | CanThrowResult ToCanThrow; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6988 | if (E->isValueDependent()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6989 | ToCanThrow = CT_Dependent; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6990 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6991 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; |
| 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 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 6994 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6995 | } |
| 6996 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6997 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6998 | Error Err = Error::success(); |
| 6999 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 7000 | auto ToType = importChecked(Err, E->getType()); |
| 7001 | auto ToThrowLoc = importChecked(Err, E->getThrowLoc()); |
| 7002 | if (Err) |
| 7003 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7004 | |
| 7005 | return new (Importer.getToContext()) CXXThrowExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7006 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7007 | } |
| 7008 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7009 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 7010 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); |
| 7011 | if (!ToUsedLocOrErr) |
| 7012 | return ToUsedLocOrErr.takeError(); |
| 7013 | |
| 7014 | auto ToParamOrErr = import(E->getParam()); |
| 7015 | if (!ToParamOrErr) |
| 7016 | return ToParamOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7017 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7018 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); |
| 7019 | if (!UsedContextOrErr) |
| 7020 | return UsedContextOrErr.takeError(); |
| 7021 | |
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 7022 | // Import the default arg if it was not imported yet. |
| 7023 | // This is needed because it can happen that during the import of the |
| 7024 | // default expression (from VisitParmVarDecl) the same ParmVarDecl is |
| 7025 | // encountered here. The default argument for a ParmVarDecl is set in the |
| 7026 | // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here, |
| 7027 | // see VisitParmVarDecl). |
| 7028 | ParmVarDecl *ToParam = *ToParamOrErr; |
| 7029 | if (!ToParam->getDefaultArg()) { |
| 7030 | Optional<ParmVarDecl *> FromParam = Importer.getImportedFromDecl(ToParam); |
| 7031 | assert(FromParam && "ParmVarDecl was not imported?"); |
| 7032 | |
| 7033 | if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam)) |
| 7034 | return std::move(Err); |
| 7035 | } |
| 7036 | |
| 7037 | return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr, |
| 7038 | *ToParamOrErr, *UsedContextOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7039 | } |
| 7040 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7041 | ExpectedStmt |
| 7042 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7043 | Error Err = Error::success(); |
| 7044 | auto ToType = importChecked(Err, E->getType()); |
| 7045 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); |
| 7046 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7047 | if (Err) |
| 7048 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7049 | |
| 7050 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7051 | ToType, ToTypeSourceInfo, ToRParenLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7052 | } |
| 7053 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7054 | ExpectedStmt |
| 7055 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 7056 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7057 | if (!ToSubExprOrErr) |
| 7058 | return ToSubExprOrErr.takeError(); |
| 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 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); |
| 7061 | if (!ToDtorOrErr) |
| 7062 | return ToDtorOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7063 | |
| 7064 | ASTContext &ToCtx = Importer.getToContext(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7065 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); |
| 7066 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7067 | } |
| 7068 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7069 | ExpectedStmt |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7070 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7071 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { |
| 7072 | Error Err = Error::success(); |
| 7073 | auto ToConstructor = importChecked(Err, E->getConstructor()); |
| 7074 | auto ToType = importChecked(Err, E->getType()); |
| 7075 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); |
| 7076 | auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange()); |
| 7077 | if (Err) |
| 7078 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7079 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7080 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); |
| 7081 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7082 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7083 | |
| Bruno Ricci | ddb8f6b | 2018-12-22 14:39:30 +0000 | [diff] [blame] | 7084 | return CXXTemporaryObjectExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7085 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, |
| 7086 | ToParenOrBraceRange, E->hadMultipleCandidates(), |
| 7087 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 7088 | E->requiresZeroInitialization()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7089 | } |
| 7090 | |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7091 | ExpectedDecl ASTNodeImporter::VisitLifetimeExtendedTemporaryDecl( |
| 7092 | LifetimeExtendedTemporaryDecl *D) { |
| 7093 | DeclContext *DC, *LexicalDC; |
| 7094 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 7095 | return std::move(Err); |
| 7096 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7097 | Error Err = Error::success(); |
| 7098 | auto Temporary = importChecked(Err, D->getTemporaryExpr()); |
| 7099 | auto ExtendingDecl = importChecked(Err, D->getExtendingDecl()); |
| 7100 | if (Err) |
| 7101 | return std::move(Err); |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7102 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
| 7103 | |
| 7104 | LifetimeExtendedTemporaryDecl *To; |
| 7105 | if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl, |
| 7106 | D->getManglingNumber())) |
| 7107 | return To; |
| 7108 | |
| 7109 | To->setLexicalDeclContext(LexicalDC); |
| 7110 | LexicalDC->addDeclInternal(To); |
| 7111 | return To; |
| 7112 | } |
| 7113 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7114 | ExpectedStmt |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7115 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *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 | Expr *ToTemporaryExpr = importChecked( |
| 7119 | Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr()); |
| 7120 | auto ToMaterializedDecl = |
| 7121 | importChecked(Err, E->getLifetimeExtendedTemporaryDecl()); |
| 7122 | if (Err) |
| 7123 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7124 | |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7125 | if (!ToTemporaryExpr) |
| 7126 | ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7127 | |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7128 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
| 7129 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference(), |
| 7130 | ToMaterializedDecl); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7131 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7132 | return ToMTE; |
| 7133 | } |
| 7134 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7135 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7136 | Error Err = Error::success(); |
| 7137 | auto ToType = importChecked(Err, E->getType()); |
| 7138 | auto ToPattern = importChecked(Err, E->getPattern()); |
| 7139 | auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc()); |
| 7140 | if (Err) |
| 7141 | return std::move(Err); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7142 | |
| 7143 | return new (Importer.getToContext()) PackExpansionExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7144 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7145 | } |
| 7146 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7147 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7148 | Error Err = Error::success(); |
| 7149 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7150 | auto ToPack = importChecked(Err, E->getPack()); |
| 7151 | auto ToPackLoc = importChecked(Err, E->getPackLoc()); |
| 7152 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7153 | if (Err) |
| 7154 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7155 | |
| 7156 | Optional<unsigned> Length; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7157 | if (!E->isValueDependent()) |
| 7158 | Length = E->getPackLength(); |
| 7159 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7160 | SmallVector<TemplateArgument, 8> ToPartialArguments; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7161 | if (E->isPartiallySubstituted()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7162 | if (Error Err = ImportTemplateArguments( |
| 7163 | E->getPartialArguments().data(), |
| 7164 | E->getPartialArguments().size(), |
| 7165 | ToPartialArguments)) |
| 7166 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7167 | } |
| 7168 | |
| 7169 | return SizeOfPackExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7170 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, |
| 7171 | Length, ToPartialArguments); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7172 | } |
| 7173 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7174 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7175 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7176 | Error Err = Error::success(); |
| 7177 | auto ToOperatorNew = importChecked(Err, E->getOperatorNew()); |
| 7178 | auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete()); |
| 7179 | auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens()); |
| 7180 | auto ToArraySize = importChecked(Err, E->getArraySize()); |
| 7181 | auto ToInitializer = importChecked(Err, E->getInitializer()); |
| 7182 | auto ToType = importChecked(Err, E->getType()); |
| 7183 | auto ToAllocatedTypeSourceInfo = |
| 7184 | importChecked(Err, E->getAllocatedTypeSourceInfo()); |
| 7185 | auto ToSourceRange = importChecked(Err, E->getSourceRange()); |
| 7186 | auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange()); |
| 7187 | if (Err) |
| 7188 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7189 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7190 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); |
| 7191 | if (Error Err = |
| 7192 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) |
| 7193 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7194 | |
| Bruno Ricci | 9b6dfac | 2019-01-07 15:04:45 +0000 | [diff] [blame] | 7195 | return CXXNewExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7196 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, |
| 7197 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), |
| 7198 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), |
| 7199 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, |
| 7200 | ToDirectInitRange); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7201 | } |
| 7202 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7203 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7204 | Error Err = Error::success(); |
| 7205 | auto ToType = importChecked(Err, E->getType()); |
| 7206 | auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete()); |
| 7207 | auto ToArgument = importChecked(Err, E->getArgument()); |
| 7208 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 7209 | if (Err) |
| 7210 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7211 | |
| 7212 | return new (Importer.getToContext()) CXXDeleteExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7213 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), |
| 7214 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, |
| 7215 | ToBeginLoc); |
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 7216 | } |
| 7217 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7218 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7219 | Error Err = Error::success(); |
| 7220 | auto ToType = importChecked(Err, E->getType()); |
| 7221 | auto ToLocation = importChecked(Err, E->getLocation()); |
| 7222 | auto ToConstructor = importChecked(Err, E->getConstructor()); |
| 7223 | auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange()); |
| 7224 | if (Err) |
| 7225 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7226 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7227 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7228 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7229 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7230 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7231 | return CXXConstructExpr::Create( |
| 7232 | Importer.getToContext(), ToType, ToLocation, ToConstructor, |
| 7233 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), |
| 7234 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 7235 | E->requiresZeroInitialization(), E->getConstructionKind(), |
| 7236 | ToParenOrBraceRange); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7237 | } |
| 7238 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7239 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { |
| 7240 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7241 | if (!ToSubExprOrErr) |
| 7242 | return ToSubExprOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7243 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7244 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); |
| 7245 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) |
| 7246 | return std::move(Err); |
| 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 | return ExprWithCleanups::Create( |
| 7249 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), |
| 7250 | ToObjects); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7251 | } |
| 7252 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7253 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7254 | Error Err = Error::success(); |
| 7255 | auto ToCallee = importChecked(Err, E->getCallee()); |
| 7256 | auto ToType = importChecked(Err, E->getType()); |
| 7257 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7258 | if (Err) |
| 7259 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7260 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7261 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7262 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7263 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7264 | |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7265 | return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, |
| 7266 | ToType, E->getValueKind(), ToRParenLoc); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7267 | } |
| 7268 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7269 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 7270 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7271 | if (!ToTypeOrErr) |
| 7272 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7273 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7274 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7275 | if (!ToLocationOrErr) |
| 7276 | return ToLocationOrErr.takeError(); |
| 7277 | |
| 7278 | return new (Importer.getToContext()) CXXThisExpr( |
| 7279 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7280 | } |
| 7281 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7282 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 7283 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7284 | if (!ToTypeOrErr) |
| 7285 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7286 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7287 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7288 | if (!ToLocationOrErr) |
| 7289 | return ToLocationOrErr.takeError(); |
| 7290 | |
| 7291 | return new (Importer.getToContext()) CXXBoolLiteralExpr( |
| 7292 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7293 | } |
| 7294 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7295 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7296 | Error Err = Error::success(); |
| 7297 | auto ToBase = importChecked(Err, E->getBase()); |
| 7298 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7299 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 7300 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); |
| 7301 | auto ToMemberDecl = importChecked(Err, E->getMemberDecl()); |
| 7302 | auto ToType = importChecked(Err, E->getType()); |
| 7303 | auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl()); |
| 7304 | auto ToName = importChecked(Err, E->getMemberNameInfo().getName()); |
| 7305 | auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc()); |
| 7306 | if (Err) |
| 7307 | return std::move(Err); |
| Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 7308 | |
| 7309 | DeclAccessPair ToFoundDecl = |
| 7310 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7311 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7312 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7313 | |
| Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7314 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7315 | if (E->hasExplicitTemplateArgs()) { |
| Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7316 | if (Error Err = |
| 7317 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 7318 | E->template_arguments(), ToTAInfo)) |
| 7319 | return std::move(Err); |
| 7320 | ResInfo = &ToTAInfo; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7321 | } |
| 7322 | |
| Richard Smith | 1bbad59 | 2019-06-11 17:50:36 +0000 | [diff] [blame] | 7323 | return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(), |
| 7324 | ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7325 | ToMemberDecl, ToFoundDecl, ToMemberNameInfo, |
| 7326 | ResInfo, ToType, E->getValueKind(), |
| 7327 | E->getObjectKind(), E->isNonOdrUse()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7328 | } |
| 7329 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7330 | ExpectedStmt |
| 7331 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7332 | Error Err = Error::success(); |
| 7333 | auto ToBase = importChecked(Err, E->getBase()); |
| 7334 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7335 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 7336 | auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo()); |
| 7337 | auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc()); |
| 7338 | auto ToTildeLoc = importChecked(Err, E->getTildeLoc()); |
| 7339 | if (Err) |
| 7340 | return std::move(Err); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7341 | |
| 7342 | PseudoDestructorTypeStorage Storage; |
| 7343 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 7344 | IdentifierInfo *ToII = Importer.Import(FromII); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7345 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); |
| 7346 | if (!ToDestroyedTypeLocOrErr) |
| 7347 | return ToDestroyedTypeLocOrErr.takeError(); |
| 7348 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7349 | } else { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7350 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) |
| 7351 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); |
| 7352 | else |
| 7353 | return ToTIOrErr.takeError(); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7354 | } |
| 7355 | |
| 7356 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7357 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7358 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7359 | } |
| 7360 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7361 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7362 | CXXDependentScopeMemberExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7363 | Error Err = Error::success(); |
| 7364 | auto ToType = importChecked(Err, E->getType()); |
| 7365 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7366 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 7367 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); |
| 7368 | auto ToFirstQualifierFoundInScope = |
| 7369 | importChecked(Err, E->getFirstQualifierFoundInScope()); |
| 7370 | if (Err) |
| 7371 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7372 | |
| 7373 | Expr *ToBase = nullptr; |
| 7374 | if (!E->isImplicitAccess()) { |
| 7375 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7376 | ToBase = *ToBaseOrErr; |
| 7377 | else |
| 7378 | return ToBaseOrErr.takeError(); |
| 7379 | } |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7380 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7381 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7382 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7383 | if (E->hasExplicitTemplateArgs()) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7384 | if (Error Err = |
| 7385 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 7386 | E->template_arguments(), ToTAInfo)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7387 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7388 | ResInfo = &ToTAInfo; |
| 7389 | } |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7390 | auto ToMember = importChecked(Err, E->getMember()); |
| 7391 | auto ToMemberLoc = importChecked(Err, E->getMemberLoc()); |
| 7392 | if (Err) |
| 7393 | return std::move(Err); |
| 7394 | DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7395 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7396 | // Import additional name location/type info. |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7397 | if (Error Err = |
| 7398 | ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7399 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7400 | |
| 7401 | return CXXDependentScopeMemberExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7402 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, |
| 7403 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, |
| 7404 | ToMemberNameInfo, ResInfo); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7405 | } |
| 7406 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7407 | ExpectedStmt |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7408 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7409 | Error Err = Error::success(); |
| 7410 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 7411 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); |
| 7412 | auto ToDeclName = importChecked(Err, E->getDeclName()); |
| 7413 | auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc()); |
| 7414 | auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc()); |
| 7415 | auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc()); |
| 7416 | if (Err) |
| 7417 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7418 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7419 | DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7420 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7421 | return std::move(Err); |
| 7422 | |
| 7423 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7424 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7425 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7426 | if (Error Err = |
| 7427 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7428 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7429 | ResInfo = &ToTAInfo; |
| 7430 | } |
| 7431 | |
| 7432 | return DependentScopeDeclRefExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7433 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, |
| 7434 | ToNameInfo, ResInfo); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7435 | } |
| 7436 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7437 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 7438 | CXXUnresolvedConstructExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7439 | Error Err = Error::success(); |
| 7440 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); |
| 7441 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7442 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); |
| 7443 | if (Err) |
| 7444 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7445 | |
| 7446 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); |
| 7447 | if (Error Err = |
| 7448 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) |
| 7449 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7450 | |
| 7451 | return CXXUnresolvedConstructExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7452 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, |
| 7453 | llvm::makeArrayRef(ToArgs), ToRParenLoc); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7454 | } |
| 7455 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7456 | ExpectedStmt |
| 7457 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
| 7458 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); |
| 7459 | if (!ToNamingClassOrErr) |
| 7460 | return ToNamingClassOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7461 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7462 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); |
| 7463 | if (!ToQualifierLocOrErr) |
| 7464 | return ToQualifierLocOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7465 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7466 | Error Err = Error::success(); |
| 7467 | auto ToName = importChecked(Err, E->getName()); |
| 7468 | auto ToNameLoc = importChecked(Err, E->getNameLoc()); |
| 7469 | if (Err) |
| 7470 | return std::move(Err); |
| 7471 | DeclarationNameInfo ToNameInfo(ToName, ToNameLoc); |
| 7472 | |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7473 | // Import additional name location/type info. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7474 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7475 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7476 | |
| 7477 | UnresolvedSet<8> ToDecls; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7478 | for (auto *D : E->decls()) |
| 7479 | if (auto ToDOrErr = import(D)) |
| 7480 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7481 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7482 | return ToDOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7483 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7484 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7485 | TemplateArgumentListInfo ToTAInfo; |
| 7486 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7487 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7488 | ToTAInfo)) |
| 7489 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7490 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7491 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); |
| 7492 | if (!ToTemplateKeywordLocOrErr) |
| 7493 | return ToTemplateKeywordLocOrErr.takeError(); |
| 7494 | |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7495 | return UnresolvedLookupExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7496 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7497 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, |
| 7498 | ToDecls.begin(), ToDecls.end()); |
| 7499 | } |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7500 | |
| 7501 | return UnresolvedLookupExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7502 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7503 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), |
| 7504 | ToDecls.end()); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7505 | } |
| 7506 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7507 | ExpectedStmt |
| 7508 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7509 | Error Err = Error::success(); |
| 7510 | auto ToType = importChecked(Err, E->getType()); |
| 7511 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7512 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 7513 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); |
| 7514 | auto ToName = importChecked(Err, E->getName()); |
| 7515 | auto ToNameLoc = importChecked(Err, E->getNameLoc()); |
| 7516 | if (Err) |
| 7517 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7518 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7519 | DeclarationNameInfo ToNameInfo(ToName, ToNameLoc); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7520 | // Import additional name location/type info. |
| 7521 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7522 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7523 | |
| 7524 | UnresolvedSet<8> ToDecls; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7525 | for (Decl *D : E->decls()) |
| 7526 | if (auto ToDOrErr = import(D)) |
| 7527 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7528 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7529 | return ToDOrErr.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7530 | |
| 7531 | TemplateArgumentListInfo ToTAInfo; |
| 7532 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7533 | if (E->hasExplicitTemplateArgs()) { |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7534 | TemplateArgumentListInfo FromTAInfo; |
| 7535 | E->copyTemplateArgumentsInto(FromTAInfo); |
| 7536 | if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7537 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7538 | ResInfo = &ToTAInfo; |
| 7539 | } |
| 7540 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7541 | Expr *ToBase = nullptr; |
| 7542 | if (!E->isImplicitAccess()) { |
| 7543 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7544 | ToBase = *ToBaseOrErr; |
| 7545 | else |
| 7546 | return ToBaseOrErr.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7547 | } |
| 7548 | |
| 7549 | return UnresolvedMemberExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7550 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, |
| 7551 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7552 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7553 | } |
| 7554 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7555 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7556 | Error Err = Error::success(); |
| 7557 | auto ToCallee = importChecked(Err, E->getCallee()); |
| 7558 | auto ToType = importChecked(Err, E->getType()); |
| 7559 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7560 | if (Err) |
| 7561 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7562 | |
| 7563 | unsigned NumArgs = E->getNumArgs(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7564 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 7565 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7566 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7567 | |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7568 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7569 | return CXXOperatorCallExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7570 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, |
| Eric Fiselier | 5cdc2cd | 2018-12-12 21:50:55 +0000 | [diff] [blame] | 7571 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), |
| 7572 | OCE->getADLCallKind()); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7573 | } |
| 7574 | |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7575 | return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType, |
| 7576 | E->getValueKind(), ToRParenLoc, /*MinNumArgs=*/0, |
| 7577 | E->getADLCallKind()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7578 | } |
| 7579 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7580 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { |
| 7581 | CXXRecordDecl *FromClass = E->getLambdaClass(); |
| 7582 | auto ToClassOrErr = import(FromClass); |
| 7583 | if (!ToClassOrErr) |
| 7584 | return ToClassOrErr.takeError(); |
| 7585 | CXXRecordDecl *ToClass = *ToClassOrErr; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7586 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7587 | auto ToCallOpOrErr = import(E->getCallOperator()); |
| 7588 | if (!ToCallOpOrErr) |
| 7589 | return ToCallOpOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7590 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7591 | SmallVector<LambdaCapture, 8> ToCaptures; |
| 7592 | ToCaptures.reserve(E->capture_size()); |
| 7593 | for (const auto &FromCapture : E->captures()) { |
| 7594 | if (auto ToCaptureOrErr = import(FromCapture)) |
| 7595 | ToCaptures.push_back(*ToCaptureOrErr); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7596 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7597 | return ToCaptureOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7598 | } |
| 7599 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7600 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); |
| 7601 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) |
| 7602 | return std::move(Err); |
| 7603 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7604 | Error Err = Error::success(); |
| 7605 | auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange()); |
| 7606 | auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc()); |
| 7607 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); |
| 7608 | if (Err) |
| 7609 | return std::move(Err); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7610 | |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7611 | return LambdaExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7612 | Importer.getToContext(), ToClass, ToIntroducerRange, |
| 7613 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, |
| 7614 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, |
| 7615 | ToEndLoc, E->containsUnexpandedParameterPack()); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7616 | } |
| 7617 | |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7618 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7619 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7620 | Error Err = Error::success(); |
| 7621 | auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc()); |
| 7622 | auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc()); |
| 7623 | auto ToType = importChecked(Err, E->getType()); |
| 7624 | if (Err) |
| 7625 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7626 | |
| 7627 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); |
| 7628 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) |
| 7629 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7630 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7631 | ASTContext &ToCtx = Importer.getToContext(); |
| 7632 | InitListExpr *To = new (ToCtx) InitListExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7633 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); |
| 7634 | To->setType(ToType); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7635 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7636 | if (E->hasArrayFiller()) { |
| 7637 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) |
| 7638 | To->setArrayFiller(*ToFillerOrErr); |
| 7639 | else |
| 7640 | return ToFillerOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7641 | } |
| 7642 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7643 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { |
| 7644 | if (auto ToFDOrErr = import(FromFD)) |
| 7645 | To->setInitializedFieldInUnion(*ToFDOrErr); |
| 7646 | else |
| 7647 | return ToFDOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7648 | } |
| 7649 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7650 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { |
| 7651 | if (auto ToSyntFormOrErr = import(SyntForm)) |
| 7652 | To->setSyntacticForm(*ToSyntFormOrErr); |
| 7653 | else |
| 7654 | return ToSyntFormOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7655 | } |
| 7656 | |
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7657 | // Copy InitListExprBitfields, which are not handled in the ctor of |
| 7658 | // InitListExpr. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7659 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7660 | |
| 7661 | return To; |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7662 | } |
| 7663 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7664 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7665 | CXXStdInitializerListExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7666 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7667 | if (!ToTypeOrErr) |
| 7668 | return ToTypeOrErr.takeError(); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7669 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7670 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7671 | if (!ToSubExprOrErr) |
| 7672 | return ToSubExprOrErr.takeError(); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7673 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7674 | return new (Importer.getToContext()) CXXStdInitializerListExpr( |
| 7675 | *ToTypeOrErr, *ToSubExprOrErr); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7676 | } |
| 7677 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7678 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7679 | CXXInheritedCtorInitExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7680 | Error Err = Error::success(); |
| 7681 | auto ToLocation = importChecked(Err, E->getLocation()); |
| 7682 | auto ToType = importChecked(Err, E->getType()); |
| 7683 | auto ToConstructor = importChecked(Err, E->getConstructor()); |
| 7684 | if (Err) |
| 7685 | return std::move(Err); |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7686 | |
| 7687 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7688 | ToLocation, ToType, ToConstructor, E->constructsVBase(), |
| 7689 | E->inheritedFromVBase()); |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7690 | } |
| 7691 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7692 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7693 | Error Err = Error::success(); |
| 7694 | auto ToType = importChecked(Err, E->getType()); |
| 7695 | auto ToCommonExpr = importChecked(Err, E->getCommonExpr()); |
| 7696 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 7697 | if (Err) |
| 7698 | return std::move(Err); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7699 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7700 | return new (Importer.getToContext()) ArrayInitLoopExpr( |
| 7701 | ToType, ToCommonExpr, ToSubExpr); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7702 | } |
| 7703 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7704 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 7705 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7706 | if (!ToTypeOrErr) |
| 7707 | return ToTypeOrErr.takeError(); |
| 7708 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7709 | } |
| 7710 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7711 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7712 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); |
| 7713 | if (!ToBeginLocOrErr) |
| 7714 | return ToBeginLocOrErr.takeError(); |
| 7715 | |
| 7716 | auto ToFieldOrErr = import(E->getField()); |
| 7717 | if (!ToFieldOrErr) |
| 7718 | return ToFieldOrErr.takeError(); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7719 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7720 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); |
| 7721 | if (!UsedContextOrErr) |
| 7722 | return UsedContextOrErr.takeError(); |
| 7723 | |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7724 | return CXXDefaultInitExpr::Create( |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7725 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr, *UsedContextOrErr); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7726 | } |
| 7727 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7728 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7729 | Error Err = Error::success(); |
| 7730 | auto ToType = importChecked(Err, E->getType()); |
| 7731 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 7732 | auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten()); |
| 7733 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7734 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7735 | auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets()); |
| 7736 | if (Err) |
| 7737 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7738 | |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7739 | ExprValueKind VK = E->getValueKind(); |
| 7740 | CastKind CK = E->getCastKind(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7741 | auto ToBasePathOrErr = ImportCastPath(E); |
| 7742 | if (!ToBasePathOrErr) |
| 7743 | return ToBasePathOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7744 | |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7745 | if (isa<CXXStaticCastExpr>(E)) { |
| 7746 | return CXXStaticCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7747 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7748 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7749 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 7750 | return CXXDynamicCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7751 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7752 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7753 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 7754 | return CXXReinterpretCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7755 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7756 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 7757 | } else if (isa<CXXConstCastExpr>(E)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7758 | return CXXConstCastExpr::Create( |
| 7759 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, |
| 7760 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7761 | } else { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7762 | llvm_unreachable("Unknown cast type"); |
| 7763 | return make_error<ImportError>(); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7764 | } |
| 7765 | } |
| 7766 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7767 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7768 | SubstNonTypeTemplateParmExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7769 | Error Err = Error::success(); |
| 7770 | auto ToType = importChecked(Err, E->getType()); |
| 7771 | auto ToExprLoc = importChecked(Err, E->getExprLoc()); |
| 7772 | auto ToParameter = importChecked(Err, E->getParameter()); |
| 7773 | auto ToReplacement = importChecked(Err, E->getReplacement()); |
| 7774 | if (Err) |
| 7775 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7776 | |
| 7777 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7778 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7779 | } |
| 7780 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7781 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7782 | Error Err = Error::success(); |
| 7783 | auto ToType = importChecked(Err, E->getType()); |
| 7784 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 7785 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); |
| 7786 | if (Err) |
| 7787 | return std::move(Err); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7788 | |
| 7789 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7790 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) |
| 7791 | return std::move(Err); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7792 | |
| 7793 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 7794 | // Value is always false. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7795 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7796 | |
| 7797 | return TypeTraitExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7798 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, |
| 7799 | ToEndLoc, ToValue); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7800 | } |
| 7801 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7802 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 7803 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7804 | if (!ToTypeOrErr) |
| 7805 | return ToTypeOrErr.takeError(); |
| 7806 | |
| 7807 | auto ToSourceRangeOrErr = import(E->getSourceRange()); |
| 7808 | if (!ToSourceRangeOrErr) |
| 7809 | return ToSourceRangeOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7810 | |
| 7811 | if (E->isTypeOperand()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7812 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) |
| 7813 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7814 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); |
| 7815 | else |
| 7816 | return ToTSIOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7817 | } |
| 7818 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7819 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); |
| 7820 | if (!ToExprOperandOrErr) |
| 7821 | return ToExprOperandOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7822 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7823 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7824 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7825 | } |
| 7826 | |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7827 | Error ASTNodeImporter::ImportOverriddenMethods(CXXMethodDecl *ToMethod, |
| 7828 | CXXMethodDecl *FromMethod) { |
| 7829 | Error ImportErrors = Error::success(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7830 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { |
| 7831 | if (auto ImportedOrErr = import(FromOverriddenMethod)) |
| 7832 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( |
| 7833 | (*ImportedOrErr)->getCanonicalDecl())); |
| 7834 | else |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7835 | ImportErrors = |
| 7836 | joinErrors(std::move(ImportErrors), ImportedOrErr.takeError()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7837 | } |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7838 | return ImportErrors; |
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7839 | } |
| 7840 | |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7841 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7842 | ASTContext &FromContext, FileManager &FromFileManager, |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7843 | bool MinimalImport, |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7844 | std::shared_ptr<ASTImporterSharedState> SharedState) |
| 7845 | : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext), |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7846 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 7847 | Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) { |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7848 | |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7849 | // Create a default state without the lookup table: LLDB case. |
| 7850 | if (!SharedState) { |
| 7851 | this->SharedState = std::make_shared<ASTImporterSharedState>(); |
| 7852 | } |
| 7853 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7854 | ImportedDecls[FromContext.getTranslationUnitDecl()] = |
| 7855 | ToContext.getTranslationUnitDecl(); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7856 | } |
| 7857 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7858 | ASTImporter::~ASTImporter() = default; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7859 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7860 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { |
| 7861 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && |
| 7862 | "Try to get field index for non-field."); |
| 7863 | |
| 7864 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 7865 | if (!Owner) |
| 7866 | return None; |
| 7867 | |
| 7868 | unsigned Index = 0; |
| 7869 | for (const auto *D : Owner->decls()) { |
| 7870 | if (D == F) |
| 7871 | return Index; |
| 7872 | |
| 7873 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 7874 | ++Index; |
| 7875 | } |
| 7876 | |
| 7877 | llvm_unreachable("Field was not found in its parent context."); |
| 7878 | |
| 7879 | return None; |
| 7880 | } |
| 7881 | |
| 7882 | ASTImporter::FoundDeclsTy |
| 7883 | ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) { |
| 7884 | // We search in the redecl context because of transparent contexts. |
| 7885 | // E.g. a simple C language enum is a transparent context: |
| 7886 | // enum E { A, B }; |
| 7887 | // Now if we had a global variable in the TU |
| 7888 | // int A; |
| 7889 | // then the enum constant 'A' and the variable 'A' violates ODR. |
| 7890 | // We can diagnose this only if we search in the redecl context. |
| 7891 | DeclContext *ReDC = DC->getRedeclContext(); |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7892 | if (SharedState->getLookupTable()) { |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7893 | ASTImporterLookupTable::LookupResult LookupResult = |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7894 | SharedState->getLookupTable()->lookup(ReDC, Name); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7895 | return FoundDeclsTy(LookupResult.begin(), LookupResult.end()); |
| 7896 | } else { |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 7897 | DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name); |
| 7898 | FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end()); |
| 7899 | // We must search by the slow case of localUncachedLookup because that is |
| 7900 | // working even if there is no LookupPtr for the DC. We could use |
| 7901 | // DC::buildLookup() to create the LookupPtr, but that would load external |
| 7902 | // decls again, we must avoid that case. |
| 7903 | // Also, even if we had the LookupPtr, we must find Decls which are not |
| 7904 | // in the LookupPtr, so we need the slow case. |
| 7905 | // These cases are handled in ASTImporterLookupTable, but we cannot use |
| 7906 | // that with LLDB since that traverses through the AST which initiates the |
| 7907 | // load of external decls again via DC::decls(). And again, we must avoid |
| 7908 | // loading external decls during the import. |
| 7909 | if (Result.empty()) |
| 7910 | ReDC->localUncachedLookup(Name, Result); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7911 | return Result; |
| 7912 | } |
| 7913 | } |
| 7914 | |
| 7915 | void ASTImporter::AddToLookupTable(Decl *ToD) { |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7916 | SharedState->addDeclToLookup(ToD); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7917 | } |
| 7918 | |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7919 | Expected<Decl *> ASTImporter::ImportImpl(Decl *FromD) { |
| 7920 | // Import the decl using ASTNodeImporter. |
| 7921 | ASTNodeImporter Importer(*this); |
| 7922 | return Importer.Visit(FromD); |
| 7923 | } |
| 7924 | |
| 7925 | void ASTImporter::RegisterImportedDecl(Decl *FromD, Decl *ToD) { |
| 7926 | MapImported(FromD, ToD); |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7927 | } |
| 7928 | |
| Akira Hatanaka | 40568fe | 2020-03-10 14:06:25 -0700 | [diff] [blame] | 7929 | llvm::Expected<ExprWithCleanups::CleanupObject> |
| 7930 | ASTImporter::Import(ExprWithCleanups::CleanupObject From) { |
| 7931 | if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) { |
| 7932 | if (Expected<Expr *> R = Import(CLE)) |
| 7933 | return ExprWithCleanups::CleanupObject(cast<CompoundLiteralExpr>(*R)); |
| 7934 | } |
| 7935 | |
| 7936 | // FIXME: Handle BlockDecl when we implement importing BlockExpr in |
| 7937 | // ASTNodeImporter. |
| 7938 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| 7939 | } |
| 7940 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7941 | Expected<QualType> ASTImporter::Import(QualType FromT) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7942 | if (FromT.isNull()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7943 | return QualType{}; |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7944 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7945 | const Type *FromTy = FromT.getTypePtr(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7946 | |
| 7947 | // Check whether we've already imported this type. |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7948 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7949 | = ImportedTypes.find(FromTy); |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7950 | if (Pos != ImportedTypes.end()) |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7951 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7952 | |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7953 | // Import the type |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7954 | ASTNodeImporter Importer(*this); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7955 | ExpectedType ToTOrErr = Importer.Visit(FromTy); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7956 | if (!ToTOrErr) |
| 7957 | return ToTOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7958 | |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7959 | // Record the imported type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7960 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7961 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7962 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7963 | } |
| 7964 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7965 | Expected<TypeSourceInfo *> ASTImporter::Import(TypeSourceInfo *FromTSI) { |
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7966 | if (!FromTSI) |
| 7967 | return FromTSI; |
| 7968 | |
| 7969 | // FIXME: For now we just create a "trivial" type source info based |
| Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 7970 | // 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] | 7971 | ExpectedType TOrErr = Import(FromTSI->getType()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7972 | if (!TOrErr) |
| 7973 | return TOrErr.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7974 | ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7975 | if (!BeginLocOrErr) |
| 7976 | return BeginLocOrErr.takeError(); |
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7977 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7978 | return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr); |
| 7979 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7980 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7981 | Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) { |
| Balázs Kéri | b17f292 | 2020-02-28 08:32:32 +0100 | [diff] [blame] | 7982 | Attr *ToAttr = nullptr; |
| 7983 | SourceRange ToRange; |
| 7984 | if (Error Err = importInto(ToRange, FromAttr->getRange())) |
| 7985 | return std::move(Err); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7986 | |
| Balázs Kéri | b17f292 | 2020-02-28 08:32:32 +0100 | [diff] [blame] | 7987 | // FIXME: Is there some kind of AttrVisitor to use here? |
| 7988 | switch (FromAttr->getKind()) { |
| 7989 | case attr::Aligned: { |
| 7990 | auto *From = cast<AlignedAttr>(FromAttr); |
| 7991 | AlignedAttr *To; |
| 7992 | auto CreateAlign = [&](bool IsAlignmentExpr, void *Alignment) { |
| 7993 | return AlignedAttr::Create(ToContext, IsAlignmentExpr, Alignment, ToRange, |
| 7994 | From->getSyntax(), |
| 7995 | From->getSemanticSpelling()); |
| 7996 | }; |
| 7997 | if (From->isAlignmentExpr()) { |
| 7998 | if (auto ToEOrErr = Import(From->getAlignmentExpr())) |
| 7999 | To = CreateAlign(true, *ToEOrErr); |
| 8000 | else |
| 8001 | return ToEOrErr.takeError(); |
| 8002 | } else { |
| 8003 | if (auto ToTOrErr = Import(From->getAlignmentType())) |
| 8004 | To = CreateAlign(false, *ToTOrErr); |
| 8005 | else |
| 8006 | return ToTOrErr.takeError(); |
| 8007 | } |
| 8008 | To->setInherited(From->isInherited()); |
| 8009 | To->setPackExpansion(From->isPackExpansion()); |
| 8010 | To->setImplicit(From->isImplicit()); |
| 8011 | ToAttr = To; |
| 8012 | break; |
| 8013 | } |
| 8014 | default: |
| 8015 | // FIXME: 'clone' copies every member but some of them should be imported. |
| 8016 | // Handle other Attrs that have parameters that should be imported. |
| 8017 | ToAttr = FromAttr->clone(ToContext); |
| 8018 | ToAttr->setRange(ToRange); |
| 8019 | break; |
| 8020 | } |
| 8021 | assert(ToAttr && "Attribute should be created."); |
| 8022 | |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8023 | return ToAttr; |
| Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8024 | } |
| Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 8025 | |
| Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 8026 | Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { |
| 8027 | auto Pos = ImportedDecls.find(FromD); |
| 8028 | if (Pos != ImportedDecls.end()) |
| 8029 | return Pos->second; |
| 8030 | else |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 8031 | return nullptr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 8032 | } |
| 8033 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 8034 | TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) { |
| 8035 | auto FromDPos = ImportedFromDecls.find(ToD); |
| 8036 | if (FromDPos == ImportedFromDecls.end()) |
| 8037 | return nullptr; |
| 8038 | return FromDPos->second->getTranslationUnitDecl(); |
| 8039 | } |
| 8040 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8041 | Expected<Decl *> ASTImporter::Import(Decl *FromD) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8042 | if (!FromD) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8043 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8044 | |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8045 | // Push FromD to the stack, and remove that when we return. |
| 8046 | ImportPath.push(FromD); |
| 8047 | auto ImportPathBuilder = |
| 8048 | llvm::make_scope_exit([this]() { ImportPath.pop(); }); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8049 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8050 | // Check whether there was a previous failed import. |
| 8051 | // If yes return the existing error. |
| 8052 | if (auto Error = getImportDeclErrorIfAny(FromD)) |
| 8053 | return make_error<ImportError>(*Error); |
| 8054 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8055 | // Check whether we've already imported this declaration. |
| 8056 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 8057 | if (ToD) { |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8058 | // Already imported (possibly from another TU) and with an error. |
| 8059 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { |
| 8060 | setImportDeclError(FromD, *Error); |
| 8061 | return make_error<ImportError>(*Error); |
| 8062 | } |
| 8063 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8064 | // If FromD has some updated flags after last import, apply it |
| 8065 | updateFlags(FromD, ToD); |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8066 | // If we encounter a cycle during an import then we save the relevant part |
| 8067 | // of the import path associated to the Decl. |
| 8068 | if (ImportPath.hasCycleAtBack()) |
| 8069 | SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack()); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8070 | return ToD; |
| 8071 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8072 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8073 | // Import the declaration. |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 8074 | ExpectedDecl ToDOrErr = ImportImpl(FromD); |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8075 | if (!ToDOrErr) { |
| 8076 | // Failed to import. |
| 8077 | |
| 8078 | auto Pos = ImportedDecls.find(FromD); |
| 8079 | if (Pos != ImportedDecls.end()) { |
| 8080 | // Import failed after the object was created. |
| 8081 | // Remove all references to it. |
| 8082 | auto *ToD = Pos->second; |
| 8083 | ImportedDecls.erase(Pos); |
| 8084 | |
| 8085 | // ImportedDecls and ImportedFromDecls are not symmetric. It may happen |
| 8086 | // (e.g. with namespaces) that several decls from the 'from' context are |
| 8087 | // mapped to the same decl in the 'to' context. If we removed entries |
| 8088 | // from the LookupTable here then we may end up removing them multiple |
| 8089 | // times. |
| 8090 | |
| 8091 | // The Lookuptable contains decls only which are in the 'to' context. |
| 8092 | // Remove from the Lookuptable only if it is *imported* into the 'to' |
| 8093 | // context (and do not remove it if it was added during the initial |
| 8094 | // traverse of the 'to' context). |
| 8095 | auto PosF = ImportedFromDecls.find(ToD); |
| 8096 | if (PosF != ImportedFromDecls.end()) { |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8097 | SharedState->removeDeclFromLookup(ToD); |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8098 | ImportedFromDecls.erase(PosF); |
| 8099 | } |
| 8100 | |
| 8101 | // FIXME: AST may contain remaining references to the failed object. |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8102 | // However, the ImportDeclErrors in the shared state contains all the |
| 8103 | // failed objects together with their error. |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8104 | } |
| 8105 | |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8106 | // Error encountered for the first time. |
| 8107 | // After takeError the error is not usable any more in ToDOrErr. |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8108 | // Get a copy of the error object (any more simple solution for this?). |
| 8109 | ImportError ErrOut; |
| 8110 | handleAllErrors(ToDOrErr.takeError(), |
| 8111 | [&ErrOut](const ImportError &E) { ErrOut = E; }); |
| 8112 | setImportDeclError(FromD, ErrOut); |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8113 | // Set the error for the mapped to Decl, which is in the "to" context. |
| 8114 | if (Pos != ImportedDecls.end()) |
| 8115 | SharedState->setImportDeclError(Pos->second, ErrOut); |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8116 | |
| 8117 | // Set the error for all nodes which have been created before we |
| 8118 | // recognized the error. |
| 8119 | for (const auto &Path : SavedImportPaths[FromD]) |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8120 | for (Decl *FromDi : Path) { |
| 8121 | setImportDeclError(FromDi, ErrOut); |
| 8122 | //FIXME Should we remove these Decls from ImportedDecls? |
| 8123 | // Set the error for the mapped to Decl, which is in the "to" context. |
| 8124 | auto Ii = ImportedDecls.find(FromDi); |
| 8125 | if (Ii != ImportedDecls.end()) |
| 8126 | SharedState->setImportDeclError(Ii->second, ErrOut); |
| 8127 | // FIXME Should we remove these Decls from the LookupTable, |
| 8128 | // and from ImportedFromDecls? |
| 8129 | } |
| Jaroslav Sevcik | 4481eef | 2020-01-22 15:19:44 +0100 | [diff] [blame] | 8130 | SavedImportPaths.erase(FromD); |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8131 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8132 | // Do not return ToDOrErr, error was taken out of it. |
| 8133 | return make_error<ImportError>(ErrOut); |
| 8134 | } |
| 8135 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8136 | ToD = *ToDOrErr; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8137 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8138 | // FIXME: Handle the "already imported with error" case. We can get here |
| 8139 | // nullptr only if GetImportedOrCreateDecl returned nullptr (after a |
| 8140 | // previously failed create was requested). |
| 8141 | // Later GetImportedOrCreateDecl can be updated to return the error. |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 8142 | if (!ToD) { |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8143 | auto Err = getImportDeclErrorIfAny(FromD); |
| 8144 | assert(Err); |
| 8145 | return make_error<ImportError>(*Err); |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 8146 | } |
| 8147 | |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8148 | // We could import from the current TU without error. But previously we |
| 8149 | // already had imported a Decl as `ToD` from another TU (with another |
| 8150 | // ASTImporter object) and with an error. |
| 8151 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { |
| 8152 | setImportDeclError(FromD, *Error); |
| 8153 | return make_error<ImportError>(*Error); |
| 8154 | } |
| 8155 | |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 8156 | // Make sure that ImportImpl registered the imported decl. |
| 8157 | assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?"); |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8158 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8159 | // Notify subclasses. |
| 8160 | Imported(FromD, ToD); |
| 8161 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 8162 | updateFlags(FromD, ToD); |
| Jaroslav Sevcik | 4481eef | 2020-01-22 15:19:44 +0100 | [diff] [blame] | 8163 | SavedImportPaths.erase(FromD); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8164 | return ToDOrErr; |
| 8165 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8166 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8167 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8168 | if (!FromDC) |
| 8169 | return FromDC; |
| 8170 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8171 | ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC)); |
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8172 | if (!ToDCOrErr) |
| 8173 | return ToDCOrErr.takeError(); |
| 8174 | auto *ToDC = cast<DeclContext>(*ToDCOrErr); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8175 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8176 | // 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] | 8177 | // need it to have a definition. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8178 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 8179 | auto *FromRecord = cast<RecordDecl>(FromDC); |
| shafik | def7c7f | 2020-04-23 15:16:34 -0700 | [diff] [blame] | 8180 | if (ToRecord->isCompleteDefinition()) |
| 8181 | return ToDC; |
| 8182 | |
| 8183 | // If FromRecord is not defined we need to force it to be. |
| 8184 | // Simply calling CompleteDecl(...) for a RecordDecl will break some cases |
| 8185 | // it will start the definition but we never finish it. |
| 8186 | // If there are base classes they won't be imported and we will |
| 8187 | // be missing anything that we inherit from those bases. |
| 8188 | if (FromRecord->getASTContext().getExternalSource() && |
| 8189 | !FromRecord->isCompleteDefinition()) |
| 8190 | FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord); |
| 8191 | |
| 8192 | if (FromRecord->isCompleteDefinition()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8193 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8194 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) |
| 8195 | return std::move(Err); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8196 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 8197 | auto *FromEnum = cast<EnumDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8198 | if (ToEnum->isCompleteDefinition()) { |
| 8199 | // Do nothing. |
| 8200 | } else if (FromEnum->isCompleteDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8201 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8202 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) |
| 8203 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8204 | } else { |
| 8205 | CompleteDecl(ToEnum); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8206 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8207 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 8208 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8209 | if (ToClass->getDefinition()) { |
| 8210 | // Do nothing. |
| 8211 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8212 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8213 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) |
| 8214 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8215 | } else { |
| 8216 | CompleteDecl(ToClass); |
| 8217 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8218 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 8219 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8220 | if (ToProto->getDefinition()) { |
| 8221 | // Do nothing. |
| 8222 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8223 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8224 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) |
| 8225 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8226 | } else { |
| 8227 | CompleteDecl(ToProto); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8228 | } |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 8229 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8230 | |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 8231 | return ToDC; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8232 | } |
| 8233 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8234 | Expected<Expr *> ASTImporter::Import(Expr *FromE) { |
| 8235 | if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE))) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8236 | return cast_or_null<Expr>(*ToSOrErr); |
| 8237 | else |
| 8238 | return ToSOrErr.takeError(); |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8239 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8240 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8241 | Expected<Stmt *> ASTImporter::Import(Stmt *FromS) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8242 | if (!FromS) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8243 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8244 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8245 | // Check whether we've already imported this statement. |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 8246 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 8247 | if (Pos != ImportedStmts.end()) |
| 8248 | return Pos->second; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8249 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8250 | // Import the statement. |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 8251 | ASTNodeImporter Importer(*this); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8252 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8253 | if (!ToSOrErr) |
| 8254 | return ToSOrErr; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8255 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8256 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { |
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 8257 | auto *FromE = cast<Expr>(FromS); |
| 8258 | // Copy ExprBitfields, which may not be handled in Expr subclasses |
| 8259 | // constructors. |
| 8260 | ToE->setValueKind(FromE->getValueKind()); |
| 8261 | ToE->setObjectKind(FromE->getObjectKind()); |
| Ilya Biryukov | ec3060c | 2020-03-02 16:07:09 +0100 | [diff] [blame] | 8262 | ToE->setDependence(FromE->getDependence()); |
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 8263 | } |
| 8264 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8265 | // Record the imported statement object. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8266 | ImportedStmts[FromS] = *ToSOrErr; |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8267 | return ToSOrErr; |
| 8268 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8269 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8270 | Expected<NestedNameSpecifier *> |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8271 | ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8272 | if (!FromNNS) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8273 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8274 | |
| Simon Pilgrim | 130df2c | 2019-07-15 13:00:43 +0000 | [diff] [blame] | 8275 | NestedNameSpecifier *Prefix = nullptr; |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8276 | if (Error Err = importInto(Prefix, FromNNS->getPrefix())) |
| 8277 | return std::move(Err); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8278 | |
| 8279 | switch (FromNNS->getKind()) { |
| 8280 | case NestedNameSpecifier::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8281 | assert(FromNNS->getAsIdentifier() && "NNS should contain identifier."); |
| 8282 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8283 | Import(FromNNS->getAsIdentifier())); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8284 | |
| 8285 | case NestedNameSpecifier::Namespace: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8286 | if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8287 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8288 | cast<NamespaceDecl>(*NSOrErr)); |
| 8289 | } else |
| 8290 | return NSOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8291 | |
| 8292 | case NestedNameSpecifier::NamespaceAlias: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8293 | if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8294 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8295 | cast<NamespaceAliasDecl>(*NSADOrErr)); |
| 8296 | else |
| 8297 | return NSADOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8298 | |
| 8299 | case NestedNameSpecifier::Global: |
| 8300 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 8301 | |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8302 | case NestedNameSpecifier::Super: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8303 | if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8304 | return NestedNameSpecifier::SuperSpecifier(ToContext, |
| 8305 | cast<CXXRecordDecl>(*RDOrErr)); |
| 8306 | else |
| 8307 | return RDOrErr.takeError(); |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8308 | |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8309 | case NestedNameSpecifier::TypeSpec: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8310 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 8311 | if (Expected<QualType> TyOrErr = |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8312 | Import(QualType(FromNNS->getAsType(), 0u))) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8313 | bool TSTemplate = |
| 8314 | FromNNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate; |
| 8315 | return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate, |
| 8316 | TyOrErr->getTypePtr()); |
| 8317 | } else { |
| 8318 | return TyOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8319 | } |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8320 | } |
| 8321 | |
| 8322 | llvm_unreachable("Invalid nested name specifier kind"); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8323 | } |
| 8324 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8325 | Expected<NestedNameSpecifierLoc> |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8326 | ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8327 | // Copied from NestedNameSpecifier mostly. |
| 8328 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 8329 | NestedNameSpecifierLoc NNS = FromNNS; |
| 8330 | |
| 8331 | // Push each of the nested-name-specifiers's onto a stack for |
| 8332 | // serialization in reverse order. |
| 8333 | while (NNS) { |
| 8334 | NestedNames.push_back(NNS); |
| 8335 | NNS = NNS.getPrefix(); |
| 8336 | } |
| 8337 | |
| 8338 | NestedNameSpecifierLocBuilder Builder; |
| 8339 | |
| 8340 | while (!NestedNames.empty()) { |
| 8341 | NNS = NestedNames.pop_back_val(); |
| Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 8342 | NestedNameSpecifier *Spec = nullptr; |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8343 | if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier())) |
| 8344 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8345 | |
| 8346 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8347 | |
| 8348 | SourceLocation ToLocalBeginLoc, ToLocalEndLoc; |
| 8349 | if (Kind != NestedNameSpecifier::Super) { |
| 8350 | if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc())) |
| 8351 | return std::move(Err); |
| 8352 | |
| 8353 | if (Kind != NestedNameSpecifier::Global) |
| 8354 | if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc())) |
| 8355 | return std::move(Err); |
| 8356 | } |
| 8357 | |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8358 | switch (Kind) { |
| 8359 | case NestedNameSpecifier::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8360 | Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc, |
| 8361 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8362 | break; |
| 8363 | |
| 8364 | case NestedNameSpecifier::Namespace: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8365 | Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc, |
| 8366 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8367 | break; |
| 8368 | |
| 8369 | case NestedNameSpecifier::NamespaceAlias: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8370 | Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(), |
| 8371 | ToLocalBeginLoc, ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8372 | break; |
| 8373 | |
| 8374 | case NestedNameSpecifier::TypeSpec: |
| 8375 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8376 | SourceLocation ToTLoc; |
| 8377 | if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc())) |
| 8378 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8379 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8380 | QualType(Spec->getAsType(), 0), ToTLoc); |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 8381 | if (Kind == NestedNameSpecifier::TypeSpecWithTemplate) |
| 8382 | // ToLocalBeginLoc is here the location of the 'template' keyword. |
| 8383 | Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(), |
| 8384 | ToLocalEndLoc); |
| 8385 | else |
| 8386 | // No location for 'template' keyword here. |
| 8387 | Builder.Extend(getToContext(), SourceLocation{}, TSI->getTypeLoc(), |
| 8388 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8389 | break; |
| 8390 | } |
| 8391 | |
| 8392 | case NestedNameSpecifier::Global: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8393 | Builder.MakeGlobal(getToContext(), ToLocalBeginLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8394 | break; |
| 8395 | |
| 8396 | case NestedNameSpecifier::Super: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8397 | auto ToSourceRangeOrErr = Import(NNS.getSourceRange()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8398 | if (!ToSourceRangeOrErr) |
| 8399 | return ToSourceRangeOrErr.takeError(); |
| 8400 | |
| 8401 | Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(), |
| 8402 | ToSourceRangeOrErr->getBegin(), |
| 8403 | ToSourceRangeOrErr->getEnd()); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8404 | } |
| 8405 | } |
| 8406 | } |
| 8407 | |
| 8408 | return Builder.getWithLocInContext(getToContext()); |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 8409 | } |
| 8410 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8411 | Expected<TemplateName> ASTImporter::Import(TemplateName From) { |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8412 | switch (From.getKind()) { |
| 8413 | case TemplateName::Template: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8414 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8415 | return TemplateName(cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8416 | else |
| 8417 | return ToTemplateOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8418 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8419 | case TemplateName::OverloadedTemplate: { |
| 8420 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 8421 | UnresolvedSet<2> ToTemplates; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8422 | for (auto *I : *FromStorage) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8423 | if (auto ToOrErr = Import(I)) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8424 | ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr)); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8425 | else |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8426 | return ToOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8427 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8428 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8429 | ToTemplates.end()); |
| 8430 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8431 | |
| Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8432 | case TemplateName::AssumedTemplate: { |
| 8433 | AssumedTemplateStorage *FromStorage = From.getAsAssumedTemplateName(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8434 | auto DeclNameOrErr = Import(FromStorage->getDeclName()); |
| Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8435 | if (!DeclNameOrErr) |
| 8436 | return DeclNameOrErr.takeError(); |
| 8437 | return ToContext.getAssumedTemplateName(*DeclNameOrErr); |
| 8438 | } |
| 8439 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8440 | case TemplateName::QualifiedTemplate: { |
| 8441 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8442 | auto QualifierOrErr = Import(QTN->getQualifier()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8443 | if (!QualifierOrErr) |
| 8444 | return QualifierOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8445 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8446 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8447 | return ToContext.getQualifiedTemplateName( |
| 8448 | *QualifierOrErr, QTN->hasTemplateKeyword(), |
| 8449 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8450 | else |
| 8451 | return ToTemplateOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8452 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8453 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8454 | case TemplateName::DependentTemplate: { |
| 8455 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8456 | auto QualifierOrErr = Import(DTN->getQualifier()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8457 | if (!QualifierOrErr) |
| 8458 | return QualifierOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8459 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8460 | if (DTN->isIdentifier()) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8461 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8462 | Import(DTN->getIdentifier())); |
| 8463 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8464 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8465 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
| 8466 | DTN->getOperator()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8467 | } |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8468 | |
| 8469 | case TemplateName::SubstTemplateTemplateParm: { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8470 | SubstTemplateTemplateParmStorage *Subst = |
| 8471 | From.getAsSubstTemplateTemplateParm(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8472 | ExpectedDecl ParamOrErr = Import(Subst->getParameter()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8473 | if (!ParamOrErr) |
| 8474 | return ParamOrErr.takeError(); |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8475 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8476 | auto ReplacementOrErr = Import(Subst->getReplacement()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8477 | if (!ReplacementOrErr) |
| 8478 | return ReplacementOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8479 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8480 | return ToContext.getSubstTemplateTemplateParm( |
| 8481 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ReplacementOrErr); |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8482 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8483 | |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8484 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 8485 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 8486 | = From.getAsSubstTemplateTemplateParmPack(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8487 | ExpectedDecl ParamOrErr = Import(SubstPack->getParameterPack()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8488 | if (!ParamOrErr) |
| 8489 | return ParamOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8490 | |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8491 | ASTNodeImporter Importer(*this); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8492 | auto ArgPackOrErr = |
| 8493 | Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 8494 | if (!ArgPackOrErr) |
| 8495 | return ArgPackOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8496 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8497 | return ToContext.getSubstTemplateTemplateParmPack( |
| 8498 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ArgPackOrErr); |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8499 | } |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8500 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8501 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8502 | llvm_unreachable("Invalid template name kind"); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8503 | } |
| 8504 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8505 | Expected<SourceLocation> ASTImporter::Import(SourceLocation FromLoc) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8506 | if (FromLoc.isInvalid()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8507 | return SourceLocation{}; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8508 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8509 | SourceManager &FromSM = FromContext.getSourceManager(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8510 | bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8511 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8512 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8513 | Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8514 | if (!ToFileIDOrErr) |
| 8515 | return ToFileIDOrErr.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8516 | SourceManager &ToSM = ToContext.getSourceManager(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8517 | return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second); |
| 8518 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8519 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8520 | Expected<SourceRange> ASTImporter::Import(SourceRange FromRange) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8521 | SourceLocation ToBegin, ToEnd; |
| 8522 | if (Error Err = importInto(ToBegin, FromRange.getBegin())) |
| 8523 | return std::move(Err); |
| 8524 | if (Error Err = importInto(ToEnd, FromRange.getEnd())) |
| 8525 | return std::move(Err); |
| 8526 | |
| 8527 | return SourceRange(ToBegin, ToEnd); |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8528 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8529 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8530 | Expected<FileID> ASTImporter::Import(FileID FromID, bool IsBuiltin) { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8531 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8532 | if (Pos != ImportedFileIDs.end()) |
| 8533 | return Pos->second; |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8534 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8535 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 8536 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8537 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8538 | |
| 8539 | // Map the FromID to the "to" source manager. |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8540 | FileID ToID; |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8541 | if (FromSLoc.isExpansion()) { |
| 8542 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8543 | ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8544 | if (!ToSpLoc) |
| 8545 | return ToSpLoc.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8546 | ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8547 | if (!ToExLocS) |
| 8548 | return ToExLocS.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8549 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 8550 | SourceLocation MLoc; |
| 8551 | if (FromEx.isMacroArgExpansion()) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8552 | MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, TokenLen); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8553 | } else { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8554 | if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8555 | MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, TokenLen, |
| 8556 | FromEx.isExpansionTokenRange()); |
| 8557 | else |
| 8558 | return ToExLocE.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8559 | } |
| 8560 | ToID = ToSM.getFileID(MLoc); |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8561 | } else { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8562 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8563 | |
| Raphael Isemann | 9f1e81f | 2020-04-27 10:06:56 +0200 | [diff] [blame] | 8564 | if (!IsBuiltin && !Cache->BufferOverridden) { |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8565 | // Include location of this file. |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8566 | ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8567 | if (!ToIncludeLoc) |
| 8568 | return ToIncludeLoc.takeError(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8569 | |
| Raphael Isemann | a37734f | 2020-02-17 19:43:33 +0100 | [diff] [blame] | 8570 | // Every FileID that is not the main FileID needs to have a valid include |
| 8571 | // location so that the include chain points to the main FileID. When |
| 8572 | // importing the main FileID (which has no include location), we need to |
| 8573 | // create a fake include location in the main file to keep this property |
| 8574 | // intact. |
| 8575 | SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc; |
| 8576 | if (FromID == FromSM.getMainFileID()) |
| 8577 | ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID()); |
| 8578 | |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8579 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 8580 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 8581 | // disk again |
| 8582 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 8583 | // than mmap the files several times. |
| Harlan Haskins | 8d323d1 | 2019-08-01 21:31:56 +0000 | [diff] [blame] | 8584 | auto Entry = |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8585 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 8586 | // FIXME: The filename may be a virtual name that does probably not |
| 8587 | // point to a valid file and we get no Entry here. In this case try with |
| 8588 | // the memory buffer below. |
| 8589 | if (Entry) |
| Raphael Isemann | a37734f | 2020-02-17 19:43:33 +0100 | [diff] [blame] | 8590 | ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc, |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8591 | FromSLoc.getFile().getFileCharacteristic()); |
| 8592 | } |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8593 | } |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8594 | |
| 8595 | if (ToID.isInvalid() || IsBuiltin) { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8596 | // FIXME: We want to re-use the existing MemoryBuffer! |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8597 | bool Invalid = true; |
| Duncan P. N. Exon Smith | f584819 | 2019-08-26 20:32:05 +0000 | [diff] [blame] | 8598 | const llvm::MemoryBuffer *FromBuf = |
| 8599 | Cache->getBuffer(FromContext.getDiagnostics(), |
| 8600 | FromSM.getFileManager(), SourceLocation{}, &Invalid); |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8601 | if (!FromBuf || Invalid) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8602 | // FIXME: Use a new error kind? |
| 8603 | return llvm::make_error<ImportError>(ImportError::Unknown); |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8604 | |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8605 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 8606 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 8607 | FromBuf->getBufferIdentifier()); |
| 8608 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 8609 | FromSLoc.getFile().getFileCharacteristic()); |
| 8610 | } |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8611 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8612 | |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8613 | assert(ToID.isValid() && "Unexpected invalid fileID was created."); |
| 8614 | |
| Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 8615 | ImportedFileIDs[FromID] = ToID; |
| Balazs Keri | d22f877 | 2019-07-24 10:16:37 +0000 | [diff] [blame] | 8616 | |
| 8617 | if (FileIDImportHandler) |
| 8618 | FileIDImportHandler(ToID, FromID); |
| 8619 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8620 | return ToID; |
| 8621 | } |
| 8622 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8623 | Expected<CXXCtorInitializer *> ASTImporter::Import(CXXCtorInitializer *From) { |
| 8624 | ExpectedExpr ToExprOrErr = Import(From->getInit()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8625 | if (!ToExprOrErr) |
| 8626 | return ToExprOrErr.takeError(); |
| 8627 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8628 | auto LParenLocOrErr = Import(From->getLParenLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8629 | if (!LParenLocOrErr) |
| 8630 | return LParenLocOrErr.takeError(); |
| 8631 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8632 | auto RParenLocOrErr = Import(From->getRParenLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8633 | if (!RParenLocOrErr) |
| 8634 | return RParenLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8635 | |
| 8636 | if (From->isBaseInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8637 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8638 | if (!ToTInfoOrErr) |
| 8639 | return ToTInfoOrErr.takeError(); |
| 8640 | |
| 8641 | SourceLocation EllipsisLoc; |
| 8642 | if (From->isPackExpansion()) |
| 8643 | if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc())) |
| 8644 | return std::move(Err); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8645 | |
| 8646 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8647 | ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr, |
| 8648 | *ToExprOrErr, *RParenLocOrErr, EllipsisLoc); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8649 | } else if (From->isMemberInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8650 | ExpectedDecl ToFieldOrErr = Import(From->getMember()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8651 | if (!ToFieldOrErr) |
| 8652 | return ToFieldOrErr.takeError(); |
| 8653 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8654 | auto MemberLocOrErr = Import(From->getMemberLocation()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8655 | if (!MemberLocOrErr) |
| 8656 | return MemberLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8657 | |
| 8658 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8659 | ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr, |
| 8660 | *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8661 | } else if (From->isIndirectMemberInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8662 | ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8663 | if (!ToIFieldOrErr) |
| 8664 | return ToIFieldOrErr.takeError(); |
| 8665 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8666 | auto MemberLocOrErr = Import(From->getMemberLocation()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8667 | if (!MemberLocOrErr) |
| 8668 | return MemberLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8669 | |
| 8670 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8671 | ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr), |
| 8672 | *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8673 | } else if (From->isDelegatingInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8674 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8675 | if (!ToTInfoOrErr) |
| 8676 | return ToTInfoOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8677 | |
| 8678 | return new (ToContext) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8679 | CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr, |
| 8680 | *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8681 | } else { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8682 | // FIXME: assert? |
| 8683 | return make_error<ImportError>(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8684 | } |
| Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8685 | } |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8686 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8687 | Expected<CXXBaseSpecifier *> |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8688 | ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8689 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 8690 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 8691 | return Pos->second; |
| 8692 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8693 | Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8694 | if (!ToSourceRange) |
| 8695 | return ToSourceRange.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8696 | Expected<TypeSourceInfo *> ToTSI = Import(BaseSpec->getTypeSourceInfo()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8697 | if (!ToTSI) |
| 8698 | return ToTSI.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8699 | ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8700 | if (!ToEllipsisLoc) |
| 8701 | return ToEllipsisLoc.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8702 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8703 | *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 8704 | BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8705 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 8706 | return Imported; |
| 8707 | } |
| 8708 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8709 | Error ASTImporter::ImportDefinition(Decl *From) { |
| 8710 | ExpectedDecl ToOrErr = Import(From); |
| 8711 | if (!ToOrErr) |
| 8712 | return ToOrErr.takeError(); |
| 8713 | Decl *To = *ToOrErr; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8714 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8715 | auto *FromDC = cast<DeclContext>(From); |
| 8716 | ASTNodeImporter Importer(*this); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8717 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8718 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
| 8719 | if (!ToRecord->getDefinition()) { |
| 8720 | return Importer.ImportDefinition( |
| 8721 | cast<RecordDecl>(FromDC), ToRecord, |
| 8722 | ASTNodeImporter::IDK_Everything); |
| Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8723 | } |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8724 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8725 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8726 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
| 8727 | if (!ToEnum->getDefinition()) { |
| 8728 | return Importer.ImportDefinition( |
| 8729 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); |
| 8730 | } |
| 8731 | } |
| 8732 | |
| 8733 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
| 8734 | if (!ToIFace->getDefinition()) { |
| 8735 | return Importer.ImportDefinition( |
| 8736 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
| 8737 | ASTNodeImporter::IDK_Everything); |
| 8738 | } |
| 8739 | } |
| 8740 | |
| 8741 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
| 8742 | if (!ToProto->getDefinition()) { |
| 8743 | return Importer.ImportDefinition( |
| 8744 | cast<ObjCProtocolDecl>(FromDC), ToProto, |
| 8745 | ASTNodeImporter::IDK_Everything); |
| 8746 | } |
| 8747 | } |
| 8748 | |
| 8749 | return Importer.ImportDeclContext(FromDC, true); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8750 | } |
| 8751 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8752 | Expected<DeclarationName> ASTImporter::Import(DeclarationName FromName) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8753 | if (!FromName) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8754 | return DeclarationName{}; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8755 | |
| 8756 | switch (FromName.getNameKind()) { |
| 8757 | case DeclarationName::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8758 | return DeclarationName(Import(FromName.getAsIdentifierInfo())); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8759 | |
| 8760 | case DeclarationName::ObjCZeroArgSelector: |
| 8761 | case DeclarationName::ObjCOneArgSelector: |
| 8762 | case DeclarationName::ObjCMultiArgSelector: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8763 | if (auto ToSelOrErr = Import(FromName.getObjCSelector())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8764 | return DeclarationName(*ToSelOrErr); |
| 8765 | else |
| 8766 | return ToSelOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8767 | |
| 8768 | case DeclarationName::CXXConstructorName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8769 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8770 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 8771 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8772 | else |
| 8773 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8774 | } |
| 8775 | |
| 8776 | case DeclarationName::CXXDestructorName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8777 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8778 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 8779 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8780 | else |
| 8781 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8782 | } |
| 8783 | |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8784 | case DeclarationName::CXXDeductionGuideName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8785 | if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8786 | return ToContext.DeclarationNames.getCXXDeductionGuideName( |
| 8787 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8788 | else |
| 8789 | return ToTemplateOrErr.takeError(); |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8790 | } |
| 8791 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8792 | case DeclarationName::CXXConversionFunctionName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8793 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8794 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 8795 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8796 | else |
| 8797 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8798 | } |
| 8799 | |
| 8800 | case DeclarationName::CXXOperatorName: |
| 8801 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 8802 | FromName.getCXXOverloadedOperator()); |
| 8803 | |
| 8804 | case DeclarationName::CXXLiteralOperatorName: |
| 8805 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8806 | Import(FromName.getCXXLiteralIdentifier())); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8807 | |
| 8808 | case DeclarationName::CXXUsingDirective: |
| 8809 | // FIXME: STATICS! |
| 8810 | return DeclarationName::getUsingDirectiveName(); |
| 8811 | } |
| 8812 | |
| David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 8813 | llvm_unreachable("Invalid DeclarationName Kind!"); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8814 | } |
| 8815 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8816 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8817 | if (!FromId) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8818 | return nullptr; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8819 | |
| Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 8820 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 8821 | |
| 8822 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 8823 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 8824 | |
| 8825 | return ToId; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8826 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8827 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8828 | Expected<Selector> ASTImporter::Import(Selector FromSel) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8829 | if (FromSel.isNull()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8830 | return Selector{}; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8831 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8832 | SmallVector<IdentifierInfo *, 4> Idents; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8833 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 8834 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 8835 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 8836 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 8837 | } |
| 8838 | |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 8839 | Expected<DeclarationName> ASTImporter::HandleNameConflict(DeclarationName Name, |
| 8840 | DeclContext *DC, |
| 8841 | unsigned IDNS, |
| 8842 | NamedDecl **Decls, |
| 8843 | unsigned NumDecls) { |
| 8844 | if (ODRHandling == ODRHandlingType::Conservative) |
| 8845 | // Report error at any name conflict. |
| 8846 | return make_error<ImportError>(ImportError::NameConflict); |
| 8847 | else |
| 8848 | // Allow to create the new Decl with the same name. |
| 8849 | return Name; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8850 | } |
| 8851 | |
| 8852 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
| Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8853 | if (LastDiagFromFrom) |
| 8854 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8855 | FromContext.getDiagnostics()); |
| 8856 | LastDiagFromFrom = false; |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8857 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8858 | } |
| 8859 | |
| 8860 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
| Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8861 | if (!LastDiagFromFrom) |
| 8862 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8863 | ToContext.getDiagnostics()); |
| 8864 | LastDiagFromFrom = true; |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8865 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8866 | } |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8867 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8868 | void ASTImporter::CompleteDecl (Decl *D) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8869 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8870 | if (!ID->getDefinition()) |
| 8871 | ID->startDefinition(); |
| 8872 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8873 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8874 | if (!PD->getDefinition()) |
| 8875 | PD->startDefinition(); |
| 8876 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8877 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8878 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 8879 | TD->startDefinition(); |
| 8880 | TD->setCompleteDefinition(true); |
| 8881 | } |
| 8882 | } |
| 8883 | else { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8884 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8885 | } |
| 8886 | } |
| 8887 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8888 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 8889 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 8890 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 8891 | "Try to import an already imported Decl"); |
| 8892 | if (Pos != ImportedDecls.end()) |
| 8893 | return Pos->second; |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8894 | ImportedDecls[From] = To; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 8895 | // This mapping should be maintained only in this function. Therefore do not |
| 8896 | // check for additional consistency. |
| 8897 | ImportedFromDecls[To] = From; |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8898 | AddToLookupTable(To); |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8899 | return To; |
| Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 8900 | } |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8901 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8902 | llvm::Optional<ImportError> |
| 8903 | ASTImporter::getImportDeclErrorIfAny(Decl *FromD) const { |
| 8904 | auto Pos = ImportDeclErrors.find(FromD); |
| 8905 | if (Pos != ImportDeclErrors.end()) |
| 8906 | return Pos->second; |
| 8907 | else |
| 8908 | return Optional<ImportError>(); |
| 8909 | } |
| 8910 | |
| 8911 | void ASTImporter::setImportDeclError(Decl *From, ImportError Error) { |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8912 | auto InsertRes = ImportDeclErrors.insert({From, Error}); |
| Benjamin Kramer | 4f76936 | 2019-07-01 14:33:26 +0000 | [diff] [blame] | 8913 | (void)InsertRes; |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8914 | // Either we set the error for the first time, or we already had set one and |
| 8915 | // now we want to set the same error. |
| 8916 | assert(InsertRes.second || InsertRes.first->second.Error == Error.Error); |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8917 | } |
| 8918 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8919 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 8920 | bool Complain) { |
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8921 | llvm::DenseMap<const Type *, const Type *>::iterator Pos = |
| 8922 | ImportedTypes.find(From.getTypePtr()); |
| 8923 | if (Pos != ImportedTypes.end()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8924 | if (ExpectedType ToFromOrErr = Import(From)) { |
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8925 | if (ToContext.hasSameType(*ToFromOrErr, To)) |
| 8926 | return true; |
| 8927 | } else { |
| 8928 | llvm::consumeError(ToFromOrErr.takeError()); |
| 8929 | } |
| 8930 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 8931 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8932 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8933 | getStructuralEquivalenceKind(*this), false, |
| 8934 | Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 8935 | return Ctx.IsEquivalent(From, To); |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8936 | } |