| 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); |
| 591 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); |
| 592 | ExpectedStmt VisitStringLiteral(StringLiteral *E); |
| 593 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 594 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); |
| 595 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 596 | ExpectedStmt VisitConstantExpr(ConstantExpr *E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 597 | ExpectedStmt VisitParenExpr(ParenExpr *E); |
| 598 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); |
| 599 | ExpectedStmt VisitStmtExpr(StmtExpr *E); |
| 600 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); |
| 601 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
| 602 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); |
| 603 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); |
| 604 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 605 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); |
| 606 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 607 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 608 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
| 609 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 610 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); |
| 611 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 612 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 613 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); |
| 614 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 615 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 616 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 617 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 618 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); |
| 619 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
| 620 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); |
| 621 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); |
| 622 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); |
| 623 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); |
| 624 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); |
| 625 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
| 626 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
| 627 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); |
| 628 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); |
| 629 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
| 630 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
| 631 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); |
| 632 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); |
| 633 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
| 634 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
| 635 | ExpectedStmt VisitMemberExpr(MemberExpr *E); |
| 636 | ExpectedStmt VisitCallExpr(CallExpr *E); |
| 637 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); |
| 638 | ExpectedStmt VisitInitListExpr(InitListExpr *E); |
| 639 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); |
| 640 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); |
| 641 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 642 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
| 643 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 644 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
| 645 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
| 646 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); |
| 647 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 648 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 649 | template<typename IIter, typename OIter> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 650 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
| Justin Lebar | 027eb71 | 2020-02-10 23:23:44 -0800 | [diff] [blame] | 651 | using ItemT = std::remove_reference_t<decltype(*Obegin)>; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 652 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { |
| 653 | Expected<ItemT> ToOrErr = import(*Ibegin); |
| 654 | if (!ToOrErr) |
| 655 | return ToOrErr.takeError(); |
| 656 | *Obegin = *ToOrErr; |
| 657 | } |
| 658 | return Error::success(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 659 | } |
| 660 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 661 | // Import every item from a container structure into an output container. |
| 662 | // If error occurs, stops at first error and returns the error. |
| 663 | // The output container should have space for all needed elements (it is not |
| 664 | // expanded, new items are put into from the beginning). |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 665 | template<typename InContainerTy, typename OutContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 666 | Error ImportContainerChecked( |
| 667 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { |
| 668 | return ImportArrayChecked( |
| 669 | InContainer.begin(), InContainer.end(), OutContainer.begin()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | template<typename InContainerTy, typename OIter> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 673 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 674 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 675 | } |
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 676 | |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 677 | Error ImportOverriddenMethods(CXXMethodDecl *ToMethod, |
| 678 | CXXMethodDecl *FromMethod); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 679 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 680 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( |
| 681 | FunctionDecl *FromFD); |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 682 | |
| 683 | // Returns true if the given function has a placeholder return type and |
| 684 | // that type is declared inside the body of the function. |
| 685 | // E.g. auto f() { struct X{}; return X(); } |
| 686 | bool hasAutoReturnTypeDeclaredInside(FunctionDecl *D); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 687 | }; |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 688 | |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 689 | template <typename InContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 690 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 691 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 692 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 693 | auto ToLAngleLocOrErr = import(FromLAngleLoc); |
| 694 | if (!ToLAngleLocOrErr) |
| 695 | return ToLAngleLocOrErr.takeError(); |
| 696 | auto ToRAngleLocOrErr = import(FromRAngleLoc); |
| 697 | if (!ToRAngleLocOrErr) |
| 698 | return ToRAngleLocOrErr.takeError(); |
| 699 | |
| 700 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); |
| 701 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 702 | return Err; |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 703 | Result = ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 704 | return Error::success(); |
| Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 705 | } |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 706 | |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 707 | template <> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 708 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 709 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 710 | return ImportTemplateArgumentListInfo( |
| 711 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 712 | } |
| 713 | |
| 714 | template <> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 715 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 716 | ASTTemplateArgumentListInfo>( |
| 717 | const ASTTemplateArgumentListInfo &From, |
| 718 | TemplateArgumentListInfo &Result) { |
| 719 | return ImportTemplateArgumentListInfo( |
| 720 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 721 | } |
| 722 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 723 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 724 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 725 | FunctionDecl *FromFD) { |
| 726 | assert(FromFD->getTemplatedKind() == |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 727 | FunctionDecl::TK_FunctionTemplateSpecialization); |
| 728 | |
| 729 | FunctionTemplateAndArgsTy Result; |
| 730 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 731 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 732 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) |
| 733 | return std::move(Err); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 734 | |
| 735 | // Import template arguments. |
| 736 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 737 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 738 | std::get<1>(Result))) |
| 739 | return std::move(Err); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 740 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 741 | return Result; |
| 742 | } |
| 743 | |
| 744 | template <> |
| 745 | Expected<TemplateParameterList *> |
| 746 | ASTNodeImporter::import(TemplateParameterList *From) { |
| 747 | SmallVector<NamedDecl *, 4> To(From->size()); |
| 748 | if (Error Err = ImportContainerChecked(*From, To)) |
| 749 | return std::move(Err); |
| 750 | |
| 751 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); |
| 752 | if (!ToRequiresClause) |
| 753 | return ToRequiresClause.takeError(); |
| 754 | |
| 755 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); |
| 756 | if (!ToTemplateLocOrErr) |
| 757 | return ToTemplateLocOrErr.takeError(); |
| 758 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); |
| 759 | if (!ToLAngleLocOrErr) |
| 760 | return ToLAngleLocOrErr.takeError(); |
| 761 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); |
| 762 | if (!ToRAngleLocOrErr) |
| 763 | return ToRAngleLocOrErr.takeError(); |
| 764 | |
| 765 | return TemplateParameterList::Create( |
| 766 | Importer.getToContext(), |
| 767 | *ToTemplateLocOrErr, |
| 768 | *ToLAngleLocOrErr, |
| 769 | To, |
| 770 | *ToRAngleLocOrErr, |
| 771 | *ToRequiresClause); |
| 772 | } |
| 773 | |
| 774 | template <> |
| 775 | Expected<TemplateArgument> |
| 776 | ASTNodeImporter::import(const TemplateArgument &From) { |
| 777 | switch (From.getKind()) { |
| 778 | case TemplateArgument::Null: |
| 779 | return TemplateArgument(); |
| 780 | |
| 781 | case TemplateArgument::Type: { |
| 782 | ExpectedType ToTypeOrErr = import(From.getAsType()); |
| 783 | if (!ToTypeOrErr) |
| 784 | return ToTypeOrErr.takeError(); |
| 785 | return TemplateArgument(*ToTypeOrErr); |
| 786 | } |
| 787 | |
| 788 | case TemplateArgument::Integral: { |
| 789 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); |
| 790 | if (!ToTypeOrErr) |
| 791 | return ToTypeOrErr.takeError(); |
| 792 | return TemplateArgument(From, *ToTypeOrErr); |
| 793 | } |
| 794 | |
| 795 | case TemplateArgument::Declaration: { |
| 796 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); |
| 797 | if (!ToOrErr) |
| 798 | return ToOrErr.takeError(); |
| 799 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); |
| 800 | if (!ToTypeOrErr) |
| 801 | return ToTypeOrErr.takeError(); |
| 802 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); |
| 803 | } |
| 804 | |
| 805 | case TemplateArgument::NullPtr: { |
| 806 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); |
| 807 | if (!ToTypeOrErr) |
| 808 | return ToTypeOrErr.takeError(); |
| 809 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); |
| 810 | } |
| 811 | |
| 812 | case TemplateArgument::Template: { |
| 813 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); |
| 814 | if (!ToTemplateOrErr) |
| 815 | return ToTemplateOrErr.takeError(); |
| 816 | |
| 817 | return TemplateArgument(*ToTemplateOrErr); |
| 818 | } |
| 819 | |
| 820 | case TemplateArgument::TemplateExpansion: { |
| 821 | Expected<TemplateName> ToTemplateOrErr = |
| 822 | import(From.getAsTemplateOrTemplatePattern()); |
| 823 | if (!ToTemplateOrErr) |
| 824 | return ToTemplateOrErr.takeError(); |
| 825 | |
| 826 | return TemplateArgument( |
| 827 | *ToTemplateOrErr, From.getNumTemplateExpansions()); |
| 828 | } |
| 829 | |
| 830 | case TemplateArgument::Expression: |
| 831 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) |
| 832 | return TemplateArgument(*ToExpr); |
| 833 | else |
| 834 | return ToExpr.takeError(); |
| 835 | |
| 836 | case TemplateArgument::Pack: { |
| 837 | SmallVector<TemplateArgument, 2> ToPack; |
| 838 | ToPack.reserve(From.pack_size()); |
| 839 | if (Error Err = ImportTemplateArguments( |
| 840 | From.pack_begin(), From.pack_size(), ToPack)) |
| 841 | return std::move(Err); |
| 842 | |
| 843 | return TemplateArgument( |
| 844 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | llvm_unreachable("Invalid template argument kind"); |
| 849 | } |
| 850 | |
| 851 | template <> |
| 852 | Expected<TemplateArgumentLoc> |
| 853 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { |
| 854 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); |
| 855 | if (!ArgOrErr) |
| 856 | return ArgOrErr.takeError(); |
| 857 | TemplateArgument Arg = *ArgOrErr; |
| 858 | |
| 859 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 860 | |
| 861 | TemplateArgumentLocInfo ToInfo; |
| 862 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 863 | ExpectedExpr E = import(FromInfo.getAsExpr()); |
| 864 | if (!E) |
| 865 | return E.takeError(); |
| 866 | ToInfo = TemplateArgumentLocInfo(*E); |
| 867 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 868 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) |
| 869 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); |
| 870 | else |
| 871 | return TSIOrErr.takeError(); |
| 872 | } else { |
| 873 | auto ToTemplateQualifierLocOrErr = |
| 874 | import(FromInfo.getTemplateQualifierLoc()); |
| 875 | if (!ToTemplateQualifierLocOrErr) |
| 876 | return ToTemplateQualifierLocOrErr.takeError(); |
| 877 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); |
| 878 | if (!ToTemplateNameLocOrErr) |
| 879 | return ToTemplateNameLocOrErr.takeError(); |
| 880 | auto ToTemplateEllipsisLocOrErr = |
| 881 | import(FromInfo.getTemplateEllipsisLoc()); |
| 882 | if (!ToTemplateEllipsisLocOrErr) |
| 883 | return ToTemplateEllipsisLocOrErr.takeError(); |
| 884 | |
| 885 | ToInfo = TemplateArgumentLocInfo( |
| 886 | *ToTemplateQualifierLocOrErr, |
| 887 | *ToTemplateNameLocOrErr, |
| 888 | *ToTemplateEllipsisLocOrErr); |
| 889 | } |
| 890 | |
| 891 | return TemplateArgumentLoc(Arg, ToInfo); |
| 892 | } |
| 893 | |
| 894 | template <> |
| 895 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { |
| 896 | if (DG.isNull()) |
| 897 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 898 | size_t NumDecls = DG.end() - DG.begin(); |
| 899 | SmallVector<Decl *, 1> ToDecls; |
| 900 | ToDecls.reserve(NumDecls); |
| 901 | for (Decl *FromD : DG) { |
| 902 | if (auto ToDOrErr = import(FromD)) |
| 903 | ToDecls.push_back(*ToDOrErr); |
| 904 | else |
| 905 | return ToDOrErr.takeError(); |
| 906 | } |
| 907 | return DeclGroupRef::Create(Importer.getToContext(), |
| 908 | ToDecls.begin(), |
| 909 | NumDecls); |
| 910 | } |
| 911 | |
| 912 | template <> |
| 913 | Expected<ASTNodeImporter::Designator> |
| 914 | ASTNodeImporter::import(const Designator &D) { |
| 915 | if (D.isFieldDesignator()) { |
| 916 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 917 | |
| 918 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); |
| 919 | if (!ToDotLocOrErr) |
| 920 | return ToDotLocOrErr.takeError(); |
| 921 | |
| 922 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); |
| 923 | if (!ToFieldLocOrErr) |
| 924 | return ToFieldLocOrErr.takeError(); |
| 925 | |
| 926 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); |
| 927 | } |
| 928 | |
| 929 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); |
| 930 | if (!ToLBracketLocOrErr) |
| 931 | return ToLBracketLocOrErr.takeError(); |
| 932 | |
| 933 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); |
| 934 | if (!ToRBracketLocOrErr) |
| 935 | return ToRBracketLocOrErr.takeError(); |
| 936 | |
| 937 | if (D.isArrayDesignator()) |
| 938 | return Designator(D.getFirstExprIndex(), |
| 939 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); |
| 940 | |
| 941 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); |
| 942 | if (!ToEllipsisLocOrErr) |
| 943 | return ToEllipsisLocOrErr.takeError(); |
| 944 | |
| 945 | assert(D.isArrayRangeDesignator()); |
| 946 | return Designator( |
| 947 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, |
| 948 | *ToRBracketLocOrErr); |
| 949 | } |
| 950 | |
| 951 | template <> |
| 952 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { |
| 953 | VarDecl *Var = nullptr; |
| 954 | if (From.capturesVariable()) { |
| 955 | if (auto VarOrErr = import(From.getCapturedVar())) |
| 956 | Var = *VarOrErr; |
| 957 | else |
| 958 | return VarOrErr.takeError(); |
| 959 | } |
| 960 | |
| 961 | auto LocationOrErr = import(From.getLocation()); |
| 962 | if (!LocationOrErr) |
| 963 | return LocationOrErr.takeError(); |
| 964 | |
| 965 | SourceLocation EllipsisLoc; |
| 966 | if (From.isPackExpansion()) |
| 967 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) |
| 968 | return std::move(Err); |
| 969 | |
| 970 | return LambdaCapture( |
| 971 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, |
| 972 | EllipsisLoc); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 973 | } |
| 974 | |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 975 | template <typename T> |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 976 | bool ASTNodeImporter::hasSameVisibilityContextAndLinkage(T *Found, T *From) { |
| 977 | if (Found->getLinkageInternal() != From->getLinkageInternal()) |
| 978 | return false; |
| 979 | |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 980 | if (From->hasExternalFormalLinkage()) |
| 981 | return Found->hasExternalFormalLinkage(); |
| 982 | if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl()) |
| 983 | return false; |
| 984 | if (From->isInAnonymousNamespace()) |
| 985 | return Found->isInAnonymousNamespace(); |
| 986 | else |
| 987 | return !Found->isInAnonymousNamespace() && |
| 988 | !Found->hasExternalFormalLinkage(); |
| 989 | } |
| 990 | |
| 991 | template <> |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 992 | bool ASTNodeImporter::hasSameVisibilityContextAndLinkage(TypedefNameDecl *Found, |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 993 | TypedefNameDecl *From) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 994 | if (Found->getLinkageInternal() != From->getLinkageInternal()) |
| 995 | return false; |
| 996 | |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 997 | if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace()) |
| 998 | return Importer.GetFromTU(Found) == From->getTranslationUnitDecl(); |
| 999 | return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace(); |
| 1000 | } |
| 1001 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1002 | } // namespace clang |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 1003 | |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1004 | //---------------------------------------------------------------------------- |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1005 | // Import Types |
| 1006 | //---------------------------------------------------------------------------- |
| 1007 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1008 | using namespace clang; |
| 1009 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1010 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1011 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 1012 | << T->getTypeClassName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1013 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1016 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 1017 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); |
| 1018 | if (!UnderlyingTypeOrErr) |
| 1019 | return UnderlyingTypeOrErr.takeError(); |
| Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 1020 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1021 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); |
| Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1024 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1025 | switch (T->getKind()) { |
| Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 1026 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 1027 | case BuiltinType::Id: \ |
| 1028 | return Importer.getToContext().SingletonId; |
| Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 1029 | #include "clang/Basic/OpenCLImageTypes.def" |
| Andrew Savonichev | 3fee351 | 2018-11-08 11:25:41 +0000 | [diff] [blame] | 1030 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
| 1031 | case BuiltinType::Id: \ |
| 1032 | return Importer.getToContext().Id##Ty; |
| 1033 | #include "clang/Basic/OpenCLExtensionTypes.def" |
| Richard Sandiford | eb485fb | 2019-08-09 08:52:54 +0000 | [diff] [blame] | 1034 | #define SVE_TYPE(Name, Id, SingletonId) \ |
| 1035 | case BuiltinType::Id: \ |
| 1036 | return Importer.getToContext().SingletonId; |
| 1037 | #include "clang/Basic/AArch64SVEACLETypes.def" |
| John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 1038 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 1039 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 1040 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 1041 | #include "clang/AST/BuiltinTypes.def" |
| 1042 | |
| 1043 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 1044 | // context supports C++. |
| 1045 | |
| 1046 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 1047 | // context supports ObjC. |
| 1048 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1049 | case BuiltinType::Char_U: |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1050 | // The context we're importing from has an unsigned 'char'. If we're |
| 1051 | // importing into a context with a signed 'char', translate to |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1052 | // 'unsigned char' instead. |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1053 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1054 | return Importer.getToContext().UnsignedCharTy; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1055 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1056 | return Importer.getToContext().CharTy; |
| 1057 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1058 | case BuiltinType::Char_S: |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1059 | // The context we're importing from has an unsigned 'char'. If we're |
| 1060 | // importing into a context with a signed 'char', translate to |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1061 | // 'unsigned char' instead. |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1062 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1063 | return Importer.getToContext().SignedCharTy; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1064 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1065 | return Importer.getToContext().CharTy; |
| 1066 | |
| Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 1067 | case BuiltinType::WChar_S: |
| 1068 | case BuiltinType::WChar_U: |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1069 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 1070 | // wchar_t? |
| 1071 | return Importer.getToContext().WCharTy; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1072 | } |
| David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 1073 | |
| 1074 | llvm_unreachable("Invalid BuiltinType Kind!"); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1077 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 1078 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); |
| 1079 | if (!ToOriginalTypeOrErr) |
| 1080 | return ToOriginalTypeOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1081 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1082 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1083 | } |
| 1084 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1085 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
| 1086 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1087 | if (!ToElementTypeOrErr) |
| 1088 | return ToElementTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1089 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1090 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1093 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
| 1094 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1095 | if (!ToPointeeTypeOrErr) |
| 1096 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1097 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1098 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1101 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1102 | // FIXME: Check for blocks support in "to" context. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1103 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1104 | if (!ToPointeeTypeOrErr) |
| 1105 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1106 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1107 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1110 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1111 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1112 | // FIXME: Check for C++ support in "to" context. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1113 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1114 | if (!ToPointeeTypeOrErr) |
| 1115 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1116 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1117 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1120 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1121 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1122 | // FIXME: Check for C++0x support in "to" context. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1123 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1124 | if (!ToPointeeTypeOrErr) |
| 1125 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1126 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1127 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1130 | ExpectedType |
| 1131 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1132 | // FIXME: Check for C++ support in "to" context. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1133 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1134 | if (!ToPointeeTypeOrErr) |
| 1135 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1136 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1137 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); |
| 1138 | if (!ClassTypeOrErr) |
| 1139 | return ClassTypeOrErr.takeError(); |
| 1140 | |
| 1141 | return Importer.getToContext().getMemberPointerType( |
| 1142 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1145 | ExpectedType |
| 1146 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 1147 | Error Err = Error::success(); |
| 1148 | auto ToElementType = importChecked(Err, T->getElementType()); |
| 1149 | auto ToSizeExpr = importChecked(Err, T->getSizeExpr()); |
| 1150 | if (Err) |
| 1151 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1152 | |
| Richard Smith | 772e266 | 2019-10-04 01:25:59 +0000 | [diff] [blame] | 1153 | return Importer.getToContext().getConstantArrayType( |
| 1154 | ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(), |
| 1155 | T->getIndexTypeCVRQualifiers()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1158 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1159 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1160 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1161 | if (!ToElementTypeOrErr) |
| 1162 | return ToElementTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1163 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1164 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1165 | T->getSizeModifier(), |
| 1166 | T->getIndexTypeCVRQualifiers()); |
| 1167 | } |
| 1168 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1169 | ExpectedType |
| 1170 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 1171 | Error Err = Error::success(); |
| 1172 | QualType ToElementType = importChecked(Err, T->getElementType()); |
| 1173 | Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr()); |
| 1174 | SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange()); |
| 1175 | if (Err) |
| 1176 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1177 | return Importer.getToContext().getVariableArrayType( |
| 1178 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1179 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1182 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1183 | const DependentSizedArrayType *T) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 1184 | Error Err = Error::success(); |
| 1185 | QualType ToElementType = importChecked(Err, T->getElementType()); |
| 1186 | Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr()); |
| 1187 | SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange()); |
| 1188 | if (Err) |
| 1189 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1190 | // SizeExpr may be null if size is not specified directly. |
| 1191 | // For example, 'int a[]'. |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1192 | |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1193 | return Importer.getToContext().getDependentSizedArrayType( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1194 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1195 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1198 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
| 1199 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1200 | if (!ToElementTypeOrErr) |
| 1201 | return ToElementTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1202 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1203 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1204 | T->getNumElements(), |
| Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 1205 | T->getVectorKind()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1208 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
| 1209 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1210 | if (!ToElementTypeOrErr) |
| 1211 | return ToElementTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1212 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1213 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1214 | T->getNumElements()); |
| 1215 | } |
| 1216 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1217 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1218 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1219 | // FIXME: What happens if we're importing a function without a prototype |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1220 | // into C++? Should we make it variadic? |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1221 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1222 | if (!ToReturnTypeOrErr) |
| 1223 | return ToReturnTypeOrErr.takeError(); |
| Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1224 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1225 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, |
| Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1226 | T->getExtInfo()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1229 | ExpectedType |
| 1230 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 1231 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1232 | if (!ToReturnTypeOrErr) |
| 1233 | return ToReturnTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1234 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1235 | // Import argument types |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1236 | SmallVector<QualType, 4> ArgTypes; |
| Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 1237 | for (const auto &A : T->param_types()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1238 | ExpectedType TyOrErr = import(A); |
| 1239 | if (!TyOrErr) |
| 1240 | return TyOrErr.takeError(); |
| 1241 | ArgTypes.push_back(*TyOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1242 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1243 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1244 | // Import exception types |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1245 | SmallVector<QualType, 4> ExceptionTypes; |
| Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 1246 | for (const auto &E : T->exceptions()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1247 | ExpectedType TyOrErr = import(E); |
| 1248 | if (!TyOrErr) |
| 1249 | return TyOrErr.takeError(); |
| 1250 | ExceptionTypes.push_back(*TyOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1251 | } |
| John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 1252 | |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1253 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 1254 | Error Err = Error::success(); |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1255 | FunctionProtoType::ExtProtoInfo ToEPI; |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1256 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 1257 | ToEPI.Variadic = FromEPI.Variadic; |
| 1258 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 1259 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 1260 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1261 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 1262 | ToEPI.ExceptionSpec.NoexceptExpr = |
| 1263 | importChecked(Err, FromEPI.ExceptionSpec.NoexceptExpr); |
| 1264 | ToEPI.ExceptionSpec.SourceDecl = |
| 1265 | importChecked(Err, FromEPI.ExceptionSpec.SourceDecl); |
| 1266 | ToEPI.ExceptionSpec.SourceTemplate = |
| 1267 | importChecked(Err, FromEPI.ExceptionSpec.SourceTemplate); |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1268 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 1269 | |
| 1270 | if (Err) |
| 1271 | return std::move(Err); |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1272 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1273 | return Importer.getToContext().getFunctionType( |
| 1274 | *ToReturnTypeOrErr, ArgTypes, ToEPI); |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1277 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1278 | const UnresolvedUsingType *T) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 1279 | Error Err = Error::success(); |
| 1280 | auto ToD = importChecked(Err, T->getDecl()); |
| 1281 | auto ToPrevD = importChecked(Err, T->getDecl()->getPreviousDecl()); |
| 1282 | if (Err) |
| 1283 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1284 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1285 | return Importer.getToContext().getTypeDeclType( |
| 1286 | ToD, cast_or_null<TypeDecl>(ToPrevD)); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1287 | } |
| 1288 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1289 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 1290 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); |
| 1291 | if (!ToInnerTypeOrErr) |
| 1292 | return ToInnerTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1293 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1294 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); |
| Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1297 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
| 1298 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1299 | if (!ToDeclOrErr) |
| 1300 | return ToDeclOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1301 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1302 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1305 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
| 1306 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1307 | if (!ToExprOrErr) |
| 1308 | return ToExprOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1309 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1310 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1311 | } |
| 1312 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1313 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
| 1314 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1315 | if (!ToUnderlyingTypeOrErr) |
| 1316 | return ToUnderlyingTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1317 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1318 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1321 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1322 | // FIXME: Make sure that the "to" context supports C++0x! |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1323 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1324 | if (!ToExprOrErr) |
| 1325 | return ToExprOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1326 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1327 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1328 | if (!ToUnderlyingTypeOrErr) |
| 1329 | return ToUnderlyingTypeOrErr.takeError(); |
| Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 1330 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1331 | return Importer.getToContext().getDecltypeType( |
| 1332 | *ToExprOrErr, *ToUnderlyingTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1335 | ExpectedType |
| 1336 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 1337 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1338 | if (!ToBaseTypeOrErr) |
| 1339 | return ToBaseTypeOrErr.takeError(); |
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1340 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1341 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1342 | if (!ToUnderlyingTypeOrErr) |
| 1343 | return ToUnderlyingTypeOrErr.takeError(); |
| 1344 | |
| 1345 | return Importer.getToContext().getUnaryTransformType( |
| 1346 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); |
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1349 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
| Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 1350 | // FIXME: Make sure that the "to" context supports C++11! |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1351 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); |
| 1352 | if (!ToDeducedTypeOrErr) |
| 1353 | return ToDeducedTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1354 | |
| Saar Raz | b481f02 | 2020-01-22 02:03:05 +0200 | [diff] [blame] | 1355 | ExpectedDecl ToTypeConstraintConcept = import(T->getTypeConstraintConcept()); |
| 1356 | if (!ToTypeConstraintConcept) |
| 1357 | return ToTypeConstraintConcept.takeError(); |
| 1358 | |
| 1359 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
| 1360 | ArrayRef<TemplateArgument> FromTemplateArgs = T->getTypeConstraintArguments(); |
| 1361 | if (Error Err = ImportTemplateArguments(FromTemplateArgs.data(), |
| 1362 | FromTemplateArgs.size(), |
| 1363 | ToTemplateArgs)) |
| 1364 | return std::move(Err); |
| 1365 | |
| 1366 | return Importer.getToContext().getAutoType( |
| 1367 | *ToDeducedTypeOrErr, T->getKeyword(), /*IsDependent*/false, |
| 1368 | /*IsPack=*/false, cast_or_null<ConceptDecl>(*ToTypeConstraintConcept), |
| 1369 | ToTemplateArgs); |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1372 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1373 | const InjectedClassNameType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1374 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1375 | if (!ToDeclOrErr) |
| 1376 | return ToDeclOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1377 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1378 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); |
| 1379 | if (!ToInjTypeOrErr) |
| 1380 | return ToInjTypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1381 | |
| 1382 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 1383 | // See comments in InjectedClassNameType definition for details |
| 1384 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 1385 | enum { |
| 1386 | TypeAlignmentInBits = 4, |
| 1387 | TypeAlignment = 1 << TypeAlignmentInBits |
| 1388 | }; |
| 1389 | |
| 1390 | return QualType(new (Importer.getToContext(), TypeAlignment) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1391 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1392 | } |
| 1393 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1394 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
| 1395 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1396 | if (!ToDeclOrErr) |
| 1397 | return ToDeclOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1398 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1399 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1400 | } |
| 1401 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1402 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
| 1403 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1404 | if (!ToDeclOrErr) |
| 1405 | return ToDeclOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1406 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1407 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1408 | } |
| 1409 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1410 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 1411 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); |
| 1412 | if (!ToModifiedTypeOrErr) |
| 1413 | return ToModifiedTypeOrErr.takeError(); |
| 1414 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); |
| 1415 | if (!ToEquivalentTypeOrErr) |
| 1416 | return ToEquivalentTypeOrErr.takeError(); |
| Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1417 | |
| 1418 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1419 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); |
| Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1420 | } |
| 1421 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1422 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1423 | const TemplateTypeParmType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1424 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1425 | if (!ToDeclOrErr) |
| 1426 | return ToDeclOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1427 | |
| 1428 | return Importer.getToContext().getTemplateTypeParmType( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1429 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1432 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1433 | const SubstTemplateTypeParmType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1434 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); |
| 1435 | if (!ReplacedOrErr) |
| 1436 | return ReplacedOrErr.takeError(); |
| 1437 | const TemplateTypeParmType *Replaced = |
| 1438 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1439 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1440 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); |
| 1441 | if (!ToReplacementTypeOrErr) |
| 1442 | return ToReplacementTypeOrErr.takeError(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1443 | |
| 1444 | return Importer.getToContext().getSubstTemplateTypeParmType( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1445 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1446 | } |
| 1447 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1448 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1449 | const TemplateSpecializationType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1450 | auto ToTemplateOrErr = import(T->getTemplateName()); |
| 1451 | if (!ToTemplateOrErr) |
| 1452 | return ToTemplateOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1453 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1454 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1455 | if (Error Err = ImportTemplateArguments( |
| 1456 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
| 1457 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1458 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1459 | QualType ToCanonType; |
| 1460 | if (!QualType(T, 0).isCanonical()) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1461 | QualType FromCanonType |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1462 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1463 | if (ExpectedType TyOrErr = import(FromCanonType)) |
| 1464 | ToCanonType = *TyOrErr; |
| 1465 | else |
| 1466 | return TyOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1467 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1468 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, |
| David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 1469 | ToTemplateArgs, |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1470 | ToCanonType); |
| 1471 | } |
| 1472 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1473 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1474 | // Note: the qualifier in an ElaboratedType is optional. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1475 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1476 | if (!ToQualifierOrErr) |
| 1477 | return ToQualifierOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1478 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1479 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); |
| 1480 | if (!ToNamedTypeOrErr) |
| 1481 | return ToNamedTypeOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1482 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1483 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); |
| 1484 | if (!ToOwnedTagDeclOrErr) |
| 1485 | return ToOwnedTagDeclOrErr.takeError(); |
| Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1486 | |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1487 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1488 | *ToQualifierOrErr, |
| 1489 | *ToNamedTypeOrErr, |
| 1490 | *ToOwnedTagDeclOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1493 | ExpectedType |
| 1494 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 1495 | ExpectedType ToPatternOrErr = import(T->getPattern()); |
| 1496 | if (!ToPatternOrErr) |
| 1497 | return ToPatternOrErr.takeError(); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1498 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1499 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1500 | T->getNumExpansions()); |
| 1501 | } |
| 1502 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1503 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1504 | const DependentTemplateSpecializationType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1505 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1506 | if (!ToQualifierOrErr) |
| 1507 | return ToQualifierOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1508 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1509 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1510 | |
| 1511 | SmallVector<TemplateArgument, 2> ToPack; |
| 1512 | ToPack.reserve(T->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1513 | if (Error Err = ImportTemplateArguments( |
| 1514 | T->getArgs(), T->getNumArgs(), ToPack)) |
| 1515 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1516 | |
| 1517 | return Importer.getToContext().getDependentTemplateSpecializationType( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1518 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1521 | ExpectedType |
| 1522 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { |
| 1523 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1524 | if (!ToQualifierOrErr) |
| 1525 | return ToQualifierOrErr.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1526 | |
| 1527 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1528 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1529 | QualType Canon; |
| 1530 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { |
| 1531 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) |
| 1532 | Canon = (*TyOrErr).getCanonicalType(); |
| 1533 | else |
| 1534 | return TyOrErr.takeError(); |
| 1535 | } |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1536 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1537 | return Importer.getToContext().getDependentNameType(T->getKeyword(), |
| 1538 | *ToQualifierOrErr, |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1539 | Name, Canon); |
| 1540 | } |
| 1541 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1542 | ExpectedType |
| 1543 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
| 1544 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1545 | if (!ToDeclOrErr) |
| 1546 | return ToDeclOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1547 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1548 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1551 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
| 1552 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1553 | if (!ToBaseTypeOrErr) |
| 1554 | return ToBaseTypeOrErr.takeError(); |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1555 | |
| Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1556 | SmallVector<QualType, 4> TypeArgs; |
| Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1557 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1558 | if (ExpectedType TyOrErr = import(TypeArg)) |
| 1559 | TypeArgs.push_back(*TyOrErr); |
| 1560 | else |
| 1561 | return TyOrErr.takeError(); |
| Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1562 | } |
| 1563 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1564 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1565 | for (auto *P : T->quals()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1566 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) |
| 1567 | Protocols.push_back(*ProtocolOrErr); |
| 1568 | else |
| 1569 | return ProtocolOrErr.takeError(); |
| 1570 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1573 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, |
| Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1574 | Protocols, |
| 1575 | T->isKindOfTypeAsWritten()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1576 | } |
| 1577 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1578 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1579 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1580 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1581 | if (!ToPointeeTypeOrErr) |
| 1582 | return ToPointeeTypeOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1583 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1584 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1587 | //---------------------------------------------------------------------------- |
| 1588 | // Import Declarations |
| 1589 | //---------------------------------------------------------------------------- |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1590 | Error ASTNodeImporter::ImportDeclParts( |
| 1591 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 1592 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { |
| Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1593 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. |
| 1594 | // 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] | 1595 | // FIXME: We could support these constructs by importing a different type of |
| 1596 | // this parameter and by importing the original type of the parameter only |
| 1597 | // after the FunctionDecl is created. See |
| 1598 | // VisitFunctionDecl::UsedDifferentProtoType. |
| Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1599 | DeclContext *OrigDC = D->getDeclContext(); |
| 1600 | FunctionDecl *FunDecl; |
| 1601 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && |
| 1602 | FunDecl->hasBody()) { |
| Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1603 | auto getLeafPointeeType = [](const Type *T) { |
| 1604 | while (T->isPointerType() || T->isArrayType()) { |
| 1605 | T = T->getPointeeOrArrayElementType(); |
| 1606 | } |
| 1607 | return T; |
| 1608 | }; |
| 1609 | for (const ParmVarDecl *P : FunDecl->parameters()) { |
| 1610 | const Type *LeafT = |
| 1611 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); |
| 1612 | auto *RT = dyn_cast<RecordType>(LeafT); |
| 1613 | if (RT && RT->getDecl() == D) { |
| 1614 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 1615 | << D->getDeclKindName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1616 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1617 | } |
| Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1618 | } |
| 1619 | } |
| 1620 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1621 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1622 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 1623 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1624 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1625 | // Import the name of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1626 | if (Error Err = importInto(Name, D->getDeclName())) |
| 1627 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1628 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1629 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1630 | if (Error Err = importInto(Loc, D->getLocation())) |
| 1631 | return Err; |
| 1632 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1633 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
| Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 1634 | if (ToD) |
| 1635 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD)) |
| 1636 | return Err; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1637 | |
| 1638 | return Error::success(); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1639 | } |
| 1640 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1641 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1642 | if (!FromD) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1643 | return Error::success(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1644 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1645 | if (!ToD) |
| 1646 | if (Error Err = importInto(ToD, FromD)) |
| 1647 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1648 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1649 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1650 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { |
| 1651 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && |
| 1652 | !ToRecord->getDefinition()) { |
| 1653 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) |
| 1654 | return Err; |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1655 | } |
| 1656 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1657 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1660 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1661 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1662 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1663 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) |
| 1664 | return Err; |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1665 | } |
| 1666 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1667 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1668 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1669 | |
| 1670 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1671 | } |
| 1672 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1673 | Error |
| 1674 | ASTNodeImporter::ImportDeclarationNameLoc( |
| 1675 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1676 | // NOTE: To.Name and To.Loc are already imported. |
| 1677 | // We only have to import To.LocInfo. |
| 1678 | switch (To.getName().getNameKind()) { |
| 1679 | case DeclarationName::Identifier: |
| 1680 | case DeclarationName::ObjCZeroArgSelector: |
| 1681 | case DeclarationName::ObjCOneArgSelector: |
| 1682 | case DeclarationName::ObjCMultiArgSelector: |
| 1683 | case DeclarationName::CXXUsingDirective: |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1684 | case DeclarationName::CXXDeductionGuideName: |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1685 | return Error::success(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1686 | |
| 1687 | case DeclarationName::CXXOperatorName: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1688 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) |
| 1689 | To.setCXXOperatorNameRange(*ToRangeOrErr); |
| 1690 | else |
| 1691 | return ToRangeOrErr.takeError(); |
| 1692 | return Error::success(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1693 | } |
| 1694 | case DeclarationName::CXXLiteralOperatorName: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1695 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) |
| 1696 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); |
| 1697 | else |
| 1698 | return LocOrErr.takeError(); |
| 1699 | return Error::success(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1700 | } |
| 1701 | case DeclarationName::CXXConstructorName: |
| 1702 | case DeclarationName::CXXDestructorName: |
| 1703 | case DeclarationName::CXXConversionFunctionName: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1704 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) |
| 1705 | To.setNamedTypeInfo(*ToTInfoOrErr); |
| 1706 | else |
| 1707 | return ToTInfoOrErr.takeError(); |
| 1708 | return Error::success(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1709 | } |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1710 | } |
| Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1711 | llvm_unreachable("Unknown name kind."); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1712 | } |
| 1713 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1714 | Error |
| 1715 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1716 | if (Importer.isMinimalImport() && !ForceImport) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1717 | auto ToDCOrErr = Importer.ImportContext(FromDC); |
| 1718 | return ToDCOrErr.takeError(); |
| 1719 | } |
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1720 | |
| 1721 | // We use strict error handling in case of records and enums, but not |
| 1722 | // with e.g. namespaces. |
| 1723 | // |
| 1724 | // FIXME Clients of the ASTImporter should be able to choose an |
| 1725 | // appropriate error handling strategy for their needs. For instance, |
| 1726 | // they may not want to mark an entire namespace as erroneous merely |
| 1727 | // because there is an ODR error with two typedefs. As another example, |
| 1728 | // the client may allow EnumConstantDecls with same names but with |
| 1729 | // different values in two distinct translation units. |
| 1730 | bool AccumulateChildErrors = isa<TagDecl>(FromDC); |
| 1731 | |
| 1732 | Error ChildErrors = Error::success(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1733 | for (auto *From : FromDC->decls()) { |
| 1734 | ExpectedDecl ImportedOrErr = import(From); |
| shafik | 6a7df3a | 2019-12-19 11:14:39 -0800 | [diff] [blame] | 1735 | |
| 1736 | // If we are in the process of ImportDefinition(...) for a RecordDecl we |
| 1737 | // want to make sure that we are also completing each FieldDecl. There |
| 1738 | // are currently cases where this does not happen and this is correctness |
| 1739 | // fix since operations such as code generation will expect this to be so. |
| 1740 | if (ImportedOrErr) { |
| 1741 | FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From); |
| Raphael Isemann | 326c39b | 2020-01-24 10:42:26 +0100 | [diff] [blame] | 1742 | Decl *ImportedDecl = *ImportedOrErr; |
| shafik | 6a7df3a | 2019-12-19 11:14:39 -0800 | [diff] [blame] | 1743 | FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl); |
| 1744 | if (FieldFrom && FieldTo) { |
| 1745 | const RecordType *RecordFrom = FieldFrom->getType()->getAs<RecordType>(); |
| 1746 | const RecordType *RecordTo = FieldTo->getType()->getAs<RecordType>(); |
| 1747 | if (RecordFrom && RecordTo) { |
| 1748 | RecordDecl *FromRecordDecl = RecordFrom->getDecl(); |
| 1749 | RecordDecl *ToRecordDecl = RecordTo->getDecl(); |
| 1750 | |
| 1751 | if (FromRecordDecl->isCompleteDefinition() && |
| 1752 | !ToRecordDecl->isCompleteDefinition()) { |
| 1753 | Error Err = ImportDefinition(FromRecordDecl, ToRecordDecl); |
| 1754 | |
| 1755 | if (Err && AccumulateChildErrors) |
| 1756 | ChildErrors = joinErrors(std::move(ChildErrors), std::move(Err)); |
| 1757 | else |
| 1758 | consumeError(std::move(Err)); |
| 1759 | } |
| 1760 | } |
| 1761 | } |
| 1762 | } else { |
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1763 | if (AccumulateChildErrors) |
| 1764 | ChildErrors = |
| 1765 | joinErrors(std::move(ChildErrors), ImportedOrErr.takeError()); |
| 1766 | else |
| 1767 | consumeError(ImportedOrErr.takeError()); |
| 1768 | } |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1769 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1770 | |
| Gabor Marton | 48b16e1 | 2019-07-25 09:07:17 +0000 | [diff] [blame] | 1771 | // We reorder declarations in RecordDecls because they may have another order |
| 1772 | // in the "to" context than they have in the "from" context. This may happen |
| 1773 | // e.g when we import a class like this: |
| 1774 | // struct declToImport { |
| 1775 | // int a = c + b; |
| 1776 | // int b = 1; |
| 1777 | // int c = 2; |
| 1778 | // }; |
| 1779 | // During the import of `a` we import first the dependencies in sequence, |
| 1780 | // thus the order would be `c`, `b`, `a`. We will get the normal order by |
| 1781 | // first removing the already imported members and then adding them in the |
| 1782 | // order as they apper in the "from" context. |
| 1783 | // |
| 1784 | // Keeping field order is vital because it determines structure layout. |
| 1785 | // |
| 1786 | // Here and below, we cannot call field_begin() method and its callers on |
| 1787 | // ToDC if it has an external storage. Calling field_begin() will |
| 1788 | // automatically load all the fields by calling |
| 1789 | // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would |
| 1790 | // call ASTImporter::Import(). This is because the ExternalASTSource |
| 1791 | // interface in LLDB is implemented by the means of the ASTImporter. However, |
| 1792 | // calling an import at this point would result in an uncontrolled import, we |
| 1793 | // must avoid that. |
| 1794 | const auto *FromRD = dyn_cast<RecordDecl>(FromDC); |
| 1795 | if (!FromRD) |
| 1796 | return ChildErrors; |
| 1797 | |
| 1798 | auto ToDCOrErr = Importer.ImportContext(FromDC); |
| 1799 | if (!ToDCOrErr) { |
| 1800 | consumeError(std::move(ChildErrors)); |
| 1801 | return ToDCOrErr.takeError(); |
| 1802 | } |
| 1803 | |
| 1804 | DeclContext *ToDC = *ToDCOrErr; |
| 1805 | // Remove all declarations, which may be in wrong order in the |
| 1806 | // lexical DeclContext and then add them in the proper order. |
| 1807 | for (auto *D : FromRD->decls()) { |
| Balazs Keri | 6e08669 | 2019-09-02 07:17:01 +0000 | [diff] [blame] | 1808 | if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<FriendDecl>(D)) { |
| Gabor Marton | 48b16e1 | 2019-07-25 09:07:17 +0000 | [diff] [blame] | 1809 | assert(D && "DC contains a null decl"); |
| 1810 | Decl *ToD = Importer.GetAlreadyImportedOrNull(D); |
| 1811 | // Remove only the decls which we successfully imported. |
| 1812 | if (ToD) { |
| 1813 | assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD)); |
| 1814 | // Remove the decl from its wrong place in the linked list. |
| 1815 | ToDC->removeDecl(ToD); |
| 1816 | // Add the decl to the end of the linked list. |
| 1817 | // This time it will be at the proper place because the enclosing for |
| 1818 | // loop iterates in the original (good) order of the decls. |
| 1819 | ToDC->addDeclInternal(ToD); |
| 1820 | } |
| 1821 | } |
| 1822 | } |
| 1823 | |
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1824 | return ChildErrors; |
| Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1825 | } |
| 1826 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1827 | Error ASTNodeImporter::ImportDeclContext( |
| 1828 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { |
| 1829 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); |
| 1830 | if (!ToDCOrErr) |
| 1831 | return ToDCOrErr.takeError(); |
| 1832 | ToDC = *ToDCOrErr; |
| 1833 | |
| 1834 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { |
| 1835 | auto ToLexicalDCOrErr = Importer.ImportContext( |
| 1836 | FromD->getLexicalDeclContext()); |
| 1837 | if (!ToLexicalDCOrErr) |
| 1838 | return ToLexicalDCOrErr.takeError(); |
| 1839 | ToLexicalDC = *ToLexicalDCOrErr; |
| 1840 | } else |
| 1841 | ToLexicalDC = ToDC; |
| 1842 | |
| 1843 | return Error::success(); |
| 1844 | } |
| 1845 | |
| 1846 | Error ASTNodeImporter::ImportImplicitMethods( |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1847 | const CXXRecordDecl *From, CXXRecordDecl *To) { |
| 1848 | assert(From->isCompleteDefinition() && To->getDefinition() == To && |
| 1849 | "Import implicit methods to or from non-definition"); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1850 | |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1851 | for (CXXMethodDecl *FromM : From->methods()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1852 | if (FromM->isImplicit()) { |
| 1853 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); |
| 1854 | if (!ToMOrErr) |
| 1855 | return ToMOrErr.takeError(); |
| 1856 | } |
| 1857 | |
| 1858 | return Error::success(); |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1861 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1862 | ASTImporter &Importer) { |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1863 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 1864 | if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef)) |
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 1865 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); |
| 1866 | else |
| 1867 | return ToTypedefOrErr.takeError(); |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1868 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1869 | return Error::success(); |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1870 | } |
| 1871 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1872 | Error ASTNodeImporter::ImportDefinition( |
| 1873 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1874 | auto DefinitionCompleter = [To]() { |
| 1875 | // There are cases in LLDB when we first import a class without its |
| 1876 | // members. The class will have DefinitionData, but no members. Then, |
| 1877 | // importDefinition is called from LLDB, which tries to get the members, so |
| 1878 | // when we get here, the class already has the DefinitionData set, so we |
| 1879 | // must unset the CompleteDefinition here to be able to complete again the |
| 1880 | // definition. |
| 1881 | To->setCompleteDefinition(false); |
| 1882 | To->completeDefinition(); |
| 1883 | }; |
| 1884 | |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1885 | if (To->getDefinition() || To->isBeingDefined()) { |
| Gabor Marton | e73805f | 2019-07-08 12:49:13 +0000 | [diff] [blame] | 1886 | if (Kind == IDK_Everything || |
| 1887 | // In case of lambdas, the class already has a definition ptr set, but |
| 1888 | // the contained decls are not imported yet. Also, isBeingDefined was |
| 1889 | // set in CXXRecordDecl::CreateLambda. We must import the contained |
| 1890 | // decls here and finish the definition. |
| 1891 | (To->isLambda() && shouldForceImportDeclContext(Kind))) { |
| 1892 | Error Result = ImportDeclContext(From, /*ForceImport=*/true); |
| 1893 | // Finish the definition of the lambda, set isBeingDefined to false. |
| 1894 | if (To->isLambda()) |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1895 | DefinitionCompleter(); |
| Gabor Marton | e73805f | 2019-07-08 12:49:13 +0000 | [diff] [blame] | 1896 | return Result; |
| 1897 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1898 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1899 | return Error::success(); |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1900 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1901 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1902 | To->startDefinition(); |
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1903 | // Complete the definition even if error is returned. |
| 1904 | // The RecordDecl may be already part of the AST so it is better to |
| 1905 | // have it in complete state even if something is wrong with it. |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1906 | auto DefinitionCompleterScopeExit = |
| 1907 | llvm::make_scope_exit(DefinitionCompleter); |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1908 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1909 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1910 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1911 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1912 | // Add base classes. |
| Gabor Marton | 17d3967 | 2018-11-26 15:54:08 +0000 | [diff] [blame] | 1913 | auto *ToCXX = dyn_cast<CXXRecordDecl>(To); |
| 1914 | auto *FromCXX = dyn_cast<CXXRecordDecl>(From); |
| 1915 | if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) { |
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1916 | |
| 1917 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1918 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 1919 | |
| 1920 | #define FIELD(Name, Width, Merge) \ |
| 1921 | ToData.Name = FromData.Name; |
| 1922 | #include "clang/AST/CXXRecordDeclDefinitionBits.def" |
| Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1923 | |
| Shafik Yaghmour | 16b9073 | 2019-04-26 18:51:28 +0000 | [diff] [blame] | 1924 | // Copy over the data stored in RecordDeclBits |
| 1925 | ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions()); |
| 1926 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1927 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1928 | for (const auto &Base1 : FromCXX->bases()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1929 | ExpectedType TyOrErr = import(Base1.getType()); |
| 1930 | if (!TyOrErr) |
| 1931 | return TyOrErr.takeError(); |
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1932 | |
| 1933 | SourceLocation EllipsisLoc; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1934 | if (Base1.isPackExpansion()) { |
| 1935 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) |
| 1936 | EllipsisLoc = *LocOrErr; |
| 1937 | else |
| 1938 | return LocOrErr.takeError(); |
| 1939 | } |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1940 | |
| 1941 | // Ensure that we have a definition for the base. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1942 | if (Error Err = |
| 1943 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) |
| 1944 | return Err; |
| 1945 | |
| 1946 | auto RangeOrErr = import(Base1.getSourceRange()); |
| 1947 | if (!RangeOrErr) |
| 1948 | return RangeOrErr.takeError(); |
| 1949 | |
| 1950 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); |
| 1951 | if (!TSIOrErr) |
| 1952 | return TSIOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1953 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1954 | Bases.push_back( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1955 | new (Importer.getToContext()) CXXBaseSpecifier( |
| 1956 | *RangeOrErr, |
| 1957 | Base1.isVirtual(), |
| 1958 | Base1.isBaseOfClass(), |
| 1959 | Base1.getAccessSpecifierAsWritten(), |
| 1960 | *TSIOrErr, |
| 1961 | EllipsisLoc)); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1962 | } |
| 1963 | if (!Bases.empty()) |
| Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1964 | ToCXX->setBases(Bases.data(), Bases.size()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1965 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1966 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1967 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1968 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1969 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1970 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1971 | return Error::success(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1972 | } |
| 1973 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1974 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1975 | if (To->getAnyInitializer()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1976 | return Error::success(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1977 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1978 | Expr *FromInit = From->getInit(); |
| 1979 | if (!FromInit) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1980 | return Error::success(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1981 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1982 | ExpectedExpr ToInitOrErr = import(FromInit); |
| 1983 | if (!ToInitOrErr) |
| 1984 | return ToInitOrErr.takeError(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1985 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1986 | To->setInit(*ToInitOrErr); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1987 | if (From->isInitKnownICE()) { |
| 1988 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); |
| 1989 | Eval->CheckedICE = true; |
| 1990 | Eval->IsICE = From->isInitICE(); |
| 1991 | } |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1992 | |
| 1993 | // FIXME: Other bits to merge? |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1994 | return Error::success(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1995 | } |
| 1996 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1997 | Error ASTNodeImporter::ImportDefinition( |
| 1998 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1999 | if (To->getDefinition() || To->isBeingDefined()) { |
| 2000 | if (Kind == IDK_Everything) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2001 | return ImportDeclContext(From, /*ForceImport=*/true); |
| 2002 | return Error::success(); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2003 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2004 | |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2005 | To->startDefinition(); |
| 2006 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2007 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 2008 | return Err; |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 2009 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2010 | ExpectedType ToTypeOrErr = |
| 2011 | import(Importer.getFromContext().getTypeDeclType(From)); |
| 2012 | if (!ToTypeOrErr) |
| 2013 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2014 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2015 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); |
| 2016 | if (!ToPromotionTypeOrErr) |
| 2017 | return ToPromotionTypeOrErr.takeError(); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2018 | |
| 2019 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2020 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 2021 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2022 | |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2023 | // FIXME: we might need to merge the number of positive or negative bits |
| 2024 | // if the enumerator lists don't match. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2025 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2026 | From->getNumPositiveBits(), |
| 2027 | From->getNumNegativeBits()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2028 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2029 | } |
| 2030 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2031 | Error ASTNodeImporter::ImportTemplateArguments( |
| 2032 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 2033 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 2034 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2035 | if (auto ToOrErr = import(FromArgs[I])) |
| 2036 | ToArgs.push_back(*ToOrErr); |
| 2037 | else |
| 2038 | return ToOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 2039 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2040 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2041 | return Error::success(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 2042 | } |
| 2043 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2044 | // FIXME: Do not forget to remove this and use only 'import'. |
| 2045 | Expected<TemplateArgument> |
| 2046 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 2047 | return import(From); |
| 2048 | } |
| 2049 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2050 | template <typename InContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2051 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2052 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 2053 | for (const auto &FromLoc : Container) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2054 | if (auto ToLocOrErr = import(FromLoc)) |
| 2055 | ToTAInfo.addArgument(*ToLocOrErr); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2056 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2057 | return ToLocOrErr.takeError(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2058 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2059 | return Error::success(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2060 | } |
| 2061 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2062 | static StructuralEquivalenceKind |
| 2063 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 2064 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 2065 | : StructuralEquivalenceKind::Default; |
| 2066 | } |
| 2067 | |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2068 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { |
| 2069 | StructuralEquivalenceContext Ctx( |
| 2070 | Importer.getFromContext(), Importer.getToContext(), |
| 2071 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2072 | false, Complain); |
| 2073 | return Ctx.IsEquivalent(From, To); |
| 2074 | } |
| 2075 | |
| 2076 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2077 | RecordDecl *ToRecord, bool Complain) { |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2078 | // Eliminate a potential failure point where we attempt to re-import |
| 2079 | // something we're trying to import while completing ToRecord. |
| 2080 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 2081 | if (ToOrigin) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2082 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2083 | if (ToOriginRecord) |
| 2084 | ToRecord = ToOriginRecord; |
| 2085 | } |
| 2086 | |
| Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 2087 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2088 | ToRecord->getASTContext(), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2089 | Importer.getNonEquivalentDecls(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2090 | getStructuralEquivalenceKind(Importer), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2091 | false, Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2092 | return Ctx.IsEquivalent(FromRecord, ToRecord); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2093 | } |
| 2094 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2095 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 2096 | bool Complain) { |
| 2097 | StructuralEquivalenceContext Ctx( |
| 2098 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2099 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2100 | false, Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2101 | return Ctx.IsEquivalent(FromVar, ToVar); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2102 | } |
| 2103 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2104 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
| Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 2105 | // Eliminate a potential failure point where we attempt to re-import |
| Raphael Isemann | fa26c20 | 2019-04-09 14:18:23 +0000 | [diff] [blame] | 2106 | // something we're trying to import while completing ToEnum. |
| Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 2107 | if (Decl *ToOrigin = Importer.GetOriginalDecl(ToEnum)) |
| 2108 | if (auto *ToOriginEnum = dyn_cast<EnumDecl>(ToOrigin)) |
| 2109 | ToEnum = ToOriginEnum; |
| 2110 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2111 | StructuralEquivalenceContext Ctx( |
| 2112 | Importer.getFromContext(), Importer.getToContext(), |
| 2113 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2114 | return Ctx.IsEquivalent(FromEnum, ToEnum); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2115 | } |
| 2116 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2117 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 2118 | FunctionTemplateDecl *To) { |
| 2119 | StructuralEquivalenceContext Ctx( |
| 2120 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2121 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2122 | false, false); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2123 | return Ctx.IsEquivalent(From, To); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2124 | } |
| 2125 | |
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2126 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 2127 | StructuralEquivalenceContext Ctx( |
| 2128 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2129 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2130 | false, false); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2131 | return Ctx.IsEquivalent(From, To); |
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2132 | } |
| 2133 | |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2134 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2135 | EnumConstantDecl *ToEC) { |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2136 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 2137 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 2138 | |
| 2139 | return FromVal.isSigned() == ToVal.isSigned() && |
| 2140 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 2141 | FromVal == ToVal; |
| 2142 | } |
| 2143 | |
| 2144 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2145 | ClassTemplateDecl *To) { |
| 2146 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2147 | Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2148 | Importer.getNonEquivalentDecls(), |
| 2149 | getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2150 | return Ctx.IsEquivalent(From, To); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2151 | } |
| 2152 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2153 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 2154 | VarTemplateDecl *To) { |
| 2155 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2156 | Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2157 | Importer.getNonEquivalentDecls(), |
| 2158 | getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2159 | return Ctx.IsEquivalent(From, To); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2160 | } |
| 2161 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2162 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 2163 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2164 | << D->getDeclKindName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2165 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2166 | } |
| 2167 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2168 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { |
| 2169 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 2170 | << D->getDeclKindName(); |
| 2171 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| 2172 | } |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2173 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2174 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 2175 | // Import the context of this declaration. |
| 2176 | DeclContext *DC, *LexicalDC; |
| 2177 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 2178 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2179 | |
| 2180 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2181 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2182 | if (!LocOrErr) |
| 2183 | return LocOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2184 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2185 | EmptyDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2186 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2187 | return ToD; |
| 2188 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2189 | ToD->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2190 | LexicalDC->addDeclInternal(ToD); |
| 2191 | return ToD; |
| 2192 | } |
| 2193 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2194 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2195 | TranslationUnitDecl *ToD = |
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2196 | Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2197 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2198 | Importer.MapImported(D, ToD); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2199 | |
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2200 | return ToD; |
| 2201 | } |
| 2202 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2203 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 2204 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2205 | if (!LocOrErr) |
| 2206 | return LocOrErr.takeError(); |
| 2207 | auto ColonLocOrErr = import(D->getColonLoc()); |
| 2208 | if (!ColonLocOrErr) |
| 2209 | return ColonLocOrErr.takeError(); |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2210 | |
| 2211 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2212 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2213 | if (!DCOrErr) |
| 2214 | return DCOrErr.takeError(); |
| 2215 | DeclContext *DC = *DCOrErr; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2216 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2217 | AccessSpecDecl *ToD; |
| 2218 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2219 | DC, *LocOrErr, *ColonLocOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2220 | return ToD; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2221 | |
| 2222 | // Lexical DeclContext and Semantic DeclContext |
| 2223 | // is always the same for the accessSpec. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2224 | ToD->setLexicalDeclContext(DC); |
| 2225 | DC->addDeclInternal(ToD); |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2226 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2227 | return ToD; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2228 | } |
| 2229 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2230 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 2231 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2232 | if (!DCOrErr) |
| 2233 | return DCOrErr.takeError(); |
| 2234 | DeclContext *DC = *DCOrErr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2235 | DeclContext *LexicalDC = DC; |
| 2236 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2237 | Error Err = Error::success(); |
| 2238 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 2239 | auto ToRParenLoc = importChecked(Err, D->getRParenLoc()); |
| 2240 | auto ToAssertExpr = importChecked(Err, D->getAssertExpr()); |
| 2241 | auto ToMessage = importChecked(Err, D->getMessage()); |
| 2242 | if (Err) |
| 2243 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2244 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2245 | StaticAssertDecl *ToD; |
| 2246 | if (GetImportedOrCreateDecl( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2247 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, |
| 2248 | ToRParenLoc, D->isFailed())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2249 | return ToD; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2250 | |
| 2251 | ToD->setLexicalDeclContext(LexicalDC); |
| 2252 | LexicalDC->addDeclInternal(ToD); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2253 | return ToD; |
| 2254 | } |
| 2255 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2256 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2257 | // Import the major distinguishing characteristics of this namespace. |
| 2258 | DeclContext *DC, *LexicalDC; |
| 2259 | DeclarationName Name; |
| 2260 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2261 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2262 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2263 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2264 | if (ToD) |
| 2265 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2266 | |
| 2267 | NamespaceDecl *MergeWithNamespace = nullptr; |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2268 | if (!Name) { |
| 2269 | // This is an anonymous namespace. Adopt an existing anonymous |
| 2270 | // namespace if we can. |
| 2271 | // FIXME: Not testable. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2272 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2273 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 2274 | else |
| 2275 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 2276 | } else { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2277 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2278 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2279 | for (auto *FoundDecl : FoundDecls) { |
| 2280 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2281 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2282 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2283 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2284 | MergeWithNamespace = FoundNS; |
| 2285 | ConflictingDecls.clear(); |
| 2286 | break; |
| 2287 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2288 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2289 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2290 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2291 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2292 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2293 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2294 | Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(), |
| 2295 | ConflictingDecls.size()); |
| 2296 | if (NameOrErr) |
| 2297 | Name = NameOrErr.get(); |
| 2298 | else |
| 2299 | return NameOrErr.takeError(); |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2300 | } |
| 2301 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2302 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2303 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2304 | if (!BeginLocOrErr) |
| 2305 | return BeginLocOrErr.takeError(); |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2306 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 2307 | if (!RBraceLocOrErr) |
| 2308 | return RBraceLocOrErr.takeError(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2309 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2310 | // Create the "to" namespace, if needed. |
| 2311 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 2312 | if (!ToNamespace) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2313 | if (GetImportedOrCreateDecl( |
| 2314 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2315 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2316 | /*PrevDecl=*/nullptr)) |
| 2317 | return ToNamespace; |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2318 | ToNamespace->setRBraceLoc(*RBraceLocOrErr); |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2319 | ToNamespace->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2320 | LexicalDC->addDeclInternal(ToNamespace); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2321 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2322 | // If this is an anonymous namespace, register it as the anonymous |
| 2323 | // namespace within its context. |
| 2324 | if (!Name) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2325 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2326 | TU->setAnonymousNamespace(ToNamespace); |
| 2327 | else |
| 2328 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 2329 | } |
| 2330 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2331 | Importer.MapImported(D, ToNamespace); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2332 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2333 | if (Error Err = ImportDeclContext(D)) |
| 2334 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2335 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2336 | return ToNamespace; |
| 2337 | } |
| 2338 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2339 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2340 | // Import the major distinguishing characteristics of this namespace. |
| 2341 | DeclContext *DC, *LexicalDC; |
| 2342 | DeclarationName Name; |
| 2343 | SourceLocation Loc; |
| 2344 | NamedDecl *LookupD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2345 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 2346 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2347 | if (LookupD) |
| 2348 | return LookupD; |
| 2349 | |
| 2350 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 2351 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2352 | Error Err = Error::success(); |
| 2353 | auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc()); |
| 2354 | auto ToAliasLoc = importChecked(Err, D->getAliasLoc()); |
| 2355 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 2356 | auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc()); |
| 2357 | auto ToNamespace = importChecked(Err, D->getNamespace()); |
| 2358 | if (Err) |
| 2359 | return std::move(Err); |
| 2360 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2361 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2362 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2363 | NamespaceAliasDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2364 | if (GetImportedOrCreateDecl( |
| 2365 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, |
| 2366 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2367 | return ToD; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2368 | |
| 2369 | ToD->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2370 | LexicalDC->addDeclInternal(ToD); |
| 2371 | |
| 2372 | return ToD; |
| 2373 | } |
| 2374 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2375 | ExpectedDecl |
| 2376 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2377 | // Import the major distinguishing characteristics of this typedef. |
| 2378 | DeclContext *DC, *LexicalDC; |
| 2379 | DeclarationName Name; |
| 2380 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2381 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2382 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2383 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2384 | if (ToD) |
| 2385 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2386 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2387 | // If this typedef is not in block scope, determine whether we've |
| 2388 | // seen a typedef with the same name (that we can merge with) or any |
| 2389 | // other entity by that name (which name lookup could conflict with). |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 2390 | // Note: Repeated typedefs are not valid in C99: |
| 2391 | // 'typedef int T; typedef int T;' is invalid |
| 2392 | // We do not care about this now. |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2393 | if (!DC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2394 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2395 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2396 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2397 | for (auto *FoundDecl : FoundDecls) { |
| 2398 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2399 | continue; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2400 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 2401 | if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D)) |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 2402 | continue; |
| 2403 | |
| Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2404 | QualType FromUT = D->getUnderlyingType(); |
| 2405 | QualType FoundUT = FoundTypedef->getUnderlyingType(); |
| 2406 | if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) { |
| 2407 | // If the "From" context has a complete underlying type but we |
| 2408 | // already have a complete underlying type then return with that. |
| 2409 | if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2410 | return Importer.MapImported(D, FoundTypedef); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2411 | // FIXME Handle redecl chain. When you do that make consistent changes |
| 2412 | // in ASTImporterLookupTable too. |
| 2413 | } else { |
| 2414 | ConflictingDecls.push_back(FoundDecl); |
| Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2415 | } |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2416 | } |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2417 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2418 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2419 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2420 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2421 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 2422 | if (NameOrErr) |
| 2423 | Name = NameOrErr.get(); |
| 2424 | else |
| 2425 | return NameOrErr.takeError(); |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2426 | } |
| 2427 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2428 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2429 | Error Err = Error::success(); |
| 2430 | auto ToUnderlyingType = importChecked(Err, D->getUnderlyingType()); |
| 2431 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 2432 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); |
| 2433 | if (Err) |
| 2434 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2435 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2436 | // Create the new typedef node. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2437 | // FIXME: ToUnderlyingType is not used. |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2438 | (void)ToUnderlyingType; |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2439 | TypedefNameDecl *ToTypedef; |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2440 | if (IsAlias) { |
| 2441 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2442 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2443 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2444 | return ToTypedef; |
| 2445 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2446 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2447 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2448 | return ToTypedef; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2449 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2450 | ToTypedef->setAccess(D->getAccess()); |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2451 | ToTypedef->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2452 | |
| 2453 | // Templated declarations should not appear in DeclContext. |
| 2454 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 2455 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 2456 | LexicalDC->addDeclInternal(ToTypedef); |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2457 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2458 | return ToTypedef; |
| 2459 | } |
| 2460 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2461 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2462 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 2463 | } |
| 2464 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2465 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2466 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 2467 | } |
| 2468 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2469 | ExpectedDecl |
| 2470 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2471 | // Import the major distinguishing characteristics of this typedef. |
| 2472 | DeclContext *DC, *LexicalDC; |
| 2473 | DeclarationName Name; |
| 2474 | SourceLocation Loc; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2475 | NamedDecl *FoundD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2476 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
| 2477 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2478 | if (FoundD) |
| 2479 | return FoundD; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2480 | |
| 2481 | // If this typedef is not in block scope, determine whether we've |
| 2482 | // seen a typedef with the same name (that we can merge with) or any |
| 2483 | // other entity by that name (which name lookup could conflict with). |
| 2484 | if (!DC->isFunctionOrMethod()) { |
| 2485 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 2486 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2487 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2488 | for (auto *FoundDecl : FoundDecls) { |
| 2489 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2490 | continue; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2491 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2492 | return Importer.MapImported(D, FoundAlias); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2493 | ConflictingDecls.push_back(FoundDecl); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2494 | } |
| 2495 | |
| 2496 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2497 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2498 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 2499 | if (NameOrErr) |
| 2500 | Name = NameOrErr.get(); |
| 2501 | else |
| 2502 | return NameOrErr.takeError(); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2503 | } |
| 2504 | } |
| 2505 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2506 | Error Err = Error::success(); |
| 2507 | auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters()); |
| 2508 | auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl()); |
| 2509 | if (Err) |
| 2510 | return std::move(Err); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2511 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2512 | TypeAliasTemplateDecl *ToAlias; |
| 2513 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2514 | Name, ToTemplateParameters, ToTemplatedDecl)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2515 | return ToAlias; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2516 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2517 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2518 | |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2519 | ToAlias->setAccess(D->getAccess()); |
| 2520 | ToAlias->setLexicalDeclContext(LexicalDC); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2521 | LexicalDC->addDeclInternal(ToAlias); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2522 | return ToAlias; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2523 | } |
| 2524 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2525 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2526 | // Import the major distinguishing characteristics of this label. |
| 2527 | DeclContext *DC, *LexicalDC; |
| 2528 | DeclarationName Name; |
| 2529 | SourceLocation Loc; |
| 2530 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2531 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2532 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2533 | if (ToD) |
| 2534 | return ToD; |
| 2535 | |
| 2536 | assert(LexicalDC->isFunctionOrMethod()); |
| 2537 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2538 | LabelDecl *ToLabel; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2539 | if (D->isGnuLocal()) { |
| 2540 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2541 | if (!BeginLocOrErr) |
| 2542 | return BeginLocOrErr.takeError(); |
| 2543 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2544 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) |
| 2545 | return ToLabel; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2546 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2547 | } else { |
| 2548 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2549 | Name.getAsIdentifierInfo())) |
| 2550 | return ToLabel; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2551 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); |
| 2555 | if (!ToStmtOrErr) |
| 2556 | return ToStmtOrErr.takeError(); |
| 2557 | |
| 2558 | ToLabel->setStmt(*ToStmtOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2559 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2560 | LexicalDC->addDeclInternal(ToLabel); |
| 2561 | return ToLabel; |
| 2562 | } |
| 2563 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2564 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2565 | // Import the major distinguishing characteristics of this enum. |
| 2566 | DeclContext *DC, *LexicalDC; |
| 2567 | DeclarationName Name; |
| 2568 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2569 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2570 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2571 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2572 | if (ToD) |
| 2573 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2574 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2575 | // Figure out what enum name we're looking for. |
| 2576 | unsigned IDNS = Decl::IDNS_Tag; |
| 2577 | DeclarationName SearchName = Name; |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2578 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2579 | if (Error Err = importInto( |
| 2580 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2581 | return std::move(Err); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2582 | IDNS = Decl::IDNS_Ordinary; |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2583 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2584 | IDNS |= Decl::IDNS_Ordinary; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2585 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2586 | // 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] | 2587 | EnumDecl *PrevDecl = nullptr; |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2588 | if (!DC->isFunctionOrMethod() && SearchName) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2589 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2590 | auto FoundDecls = |
| 2591 | Importer.findDeclsInToCtx(DC, SearchName); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2592 | for (auto *FoundDecl : FoundDecls) { |
| 2593 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2594 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2595 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2596 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2597 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2598 | FoundDecl = Tag->getDecl(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2599 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2600 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2601 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 2602 | if (!hasSameVisibilityContextAndLinkage(FoundEnum, D)) |
| Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 2603 | continue; |
| Balázs Kéri | d4741c4 | 2020-02-17 14:25:16 +0100 | [diff] [blame] | 2604 | if (IsStructuralMatch(D, FoundEnum)) { |
| 2605 | EnumDecl *FoundDef = FoundEnum->getDefinition(); |
| 2606 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 2607 | return Importer.MapImported(D, FoundDef); |
| 2608 | PrevDecl = FoundEnum->getMostRecentDecl(); |
| 2609 | break; |
| 2610 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2611 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2612 | } |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2613 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2614 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2615 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2616 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2617 | SearchName, DC, IDNS, ConflictingDecls.data(), |
| 2618 | ConflictingDecls.size()); |
| 2619 | if (NameOrErr) |
| 2620 | Name = NameOrErr.get(); |
| 2621 | else |
| 2622 | return NameOrErr.takeError(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2623 | } |
| 2624 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2625 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 2626 | Error Err = Error::success(); |
| 2627 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); |
| 2628 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 2629 | auto ToIntegerType = importChecked(Err, D->getIntegerType()); |
| 2630 | auto ToBraceRange = importChecked(Err, D->getBraceRange()); |
| 2631 | if (Err) |
| 2632 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2633 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2634 | // Create the enum declaration. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2635 | EnumDecl *D2; |
| 2636 | if (GetImportedOrCreateDecl( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2637 | D2, D, Importer.getToContext(), DC, ToBeginLoc, |
| Balázs Kéri | d4741c4 | 2020-02-17 14:25:16 +0100 | [diff] [blame] | 2638 | Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2639 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2640 | return D2; |
| 2641 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2642 | D2->setQualifierInfo(ToQualifierLoc); |
| 2643 | D2->setIntegerType(ToIntegerType); |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2644 | D2->setBraceRange(ToBraceRange); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2645 | D2->setAccess(D->getAccess()); |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2646 | D2->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2647 | LexicalDC->addDeclInternal(D2); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2648 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2649 | // Import the definition |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2650 | if (D->isCompleteDefinition()) |
| 2651 | if (Error Err = ImportDefinition(D, D2)) |
| 2652 | return std::move(Err); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2653 | |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2654 | return D2; |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2655 | } |
| 2656 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2657 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2658 | bool IsFriendTemplate = false; |
| 2659 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2660 | IsFriendTemplate = |
| 2661 | DCXX->getDescribedClassTemplate() && |
| 2662 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != |
| 2663 | Decl::FOK_None; |
| 2664 | } |
| 2665 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2666 | // Import the major distinguishing characteristics of this record. |
| Simon Pilgrim | 4706f3b | 2019-10-15 10:23:05 +0000 | [diff] [blame] | 2667 | DeclContext *DC = nullptr, *LexicalDC = nullptr; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2668 | DeclarationName Name; |
| 2669 | SourceLocation Loc; |
| Simon Pilgrim | 4706f3b | 2019-10-15 10:23:05 +0000 | [diff] [blame] | 2670 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2671 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2672 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2673 | if (ToD) |
| 2674 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2675 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2676 | // Figure out what structure name we're looking for. |
| 2677 | unsigned IDNS = Decl::IDNS_Tag; |
| 2678 | DeclarationName SearchName = Name; |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2679 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2680 | if (Error Err = importInto( |
| 2681 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2682 | return std::move(Err); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2683 | IDNS = Decl::IDNS_Ordinary; |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2684 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2685 | IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2686 | |
| 2687 | // 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] | 2688 | RecordDecl *PrevDecl = nullptr; |
| Gabor Marton | e3e83d7 | 2019-08-30 10:55:41 +0000 | [diff] [blame] | 2689 | if (!DC->isFunctionOrMethod() && !D->isLambda()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2690 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2691 | auto FoundDecls = |
| 2692 | Importer.findDeclsInToCtx(DC, SearchName); |
| Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2693 | if (!FoundDecls.empty()) { |
| Gabor Marton | 41e3892 | 2019-03-05 11:23:24 +0000 | [diff] [blame] | 2694 | // We're going to have to compare D against potentially conflicting Decls, |
| 2695 | // so complete it. |
| Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2696 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2697 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2698 | } |
| 2699 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2700 | for (auto *FoundDecl : FoundDecls) { |
| 2701 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2702 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2703 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2704 | Decl *Found = FoundDecl; |
| 2705 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2706 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2707 | Found = Tag->getDecl(); |
| 2708 | } |
| Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2709 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2710 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2711 | // Do not emit false positive diagnostic in case of unnamed |
| 2712 | // struct/union and in case of anonymous structs. Would be false |
| 2713 | // because there may be several anonymous/unnamed structs in a class. |
| 2714 | // E.g. these are both valid: |
| 2715 | // struct A { // unnamed structs |
| 2716 | // struct { struct A *next; } entry0; |
| 2717 | // struct { struct A *next; } entry1; |
| 2718 | // }; |
| 2719 | // struct X { struct { int a; }; struct { int b; }; }; // anon structs |
| 2720 | if (!SearchName) |
| Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2721 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2722 | continue; |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2723 | |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 2724 | if (!hasSameVisibilityContextAndLinkage(FoundRecord, D)) |
| Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 2725 | continue; |
| 2726 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2727 | if (IsStructuralMatch(D, FoundRecord)) { |
| 2728 | RecordDecl *FoundDef = FoundRecord->getDefinition(); |
| 2729 | if (D->isThisDeclarationADefinition() && FoundDef) { |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2730 | // FIXME: Structural equivalence check should check for same |
| 2731 | // user-defined methods. |
| 2732 | Importer.MapImported(D, FoundDef); |
| 2733 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2734 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); |
| 2735 | assert(FoundCXX && "Record type mismatch"); |
| 2736 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2737 | if (!Importer.isMinimalImport()) |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2738 | // FoundDef may not have every implicit method that D has |
| 2739 | // because implicit methods are created only if they are used. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2740 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) |
| 2741 | return std::move(Err); |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2742 | } |
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2743 | } |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2744 | PrevDecl = FoundRecord->getMostRecentDecl(); |
| 2745 | break; |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2746 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2747 | ConflictingDecls.push_back(FoundDecl); |
| 2748 | } // kind is RecordDecl |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2749 | } // for |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2750 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2751 | if (!ConflictingDecls.empty() && SearchName) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2752 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2753 | SearchName, DC, IDNS, ConflictingDecls.data(), |
| 2754 | ConflictingDecls.size()); |
| 2755 | if (NameOrErr) |
| 2756 | Name = NameOrErr.get(); |
| 2757 | else |
| 2758 | return NameOrErr.takeError(); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2759 | } |
| 2760 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2761 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2762 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2763 | if (!BeginLocOrErr) |
| 2764 | return BeginLocOrErr.takeError(); |
| 2765 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2766 | // Create the record declaration. |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2767 | RecordDecl *D2 = nullptr; |
| 2768 | CXXRecordDecl *D2CXX = nullptr; |
| 2769 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2770 | if (DCXX->isLambda()) { |
| 2771 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); |
| 2772 | if (!TInfoOrErr) |
| 2773 | return TInfoOrErr.takeError(); |
| 2774 | if (GetImportedOrCreateSpecialDecl( |
| 2775 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
| 2776 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), |
| 2777 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2778 | return D2CXX; |
| 2779 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); |
| 2780 | if (!CDeclOrErr) |
| 2781 | return CDeclOrErr.takeError(); |
| Michael Liao | 243ebfb | 2019-10-19 00:15:19 +0000 | [diff] [blame] | 2782 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr, |
| 2783 | DCXX->hasKnownLambdaInternalLinkage()); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2784 | } else if (DCXX->isInjectedClassName()) { |
| 2785 | // We have to be careful to do a similar dance to the one in |
| 2786 | // Sema::ActOnStartCXXMemberDeclarations |
| 2787 | const bool DelayTypeCreation = true; |
| 2788 | if (GetImportedOrCreateDecl( |
| 2789 | D2CXX, D, Importer.getToContext(), D->getTagKind(), DC, |
| 2790 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
| 2791 | cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation)) |
| 2792 | return D2CXX; |
| 2793 | Importer.getToContext().getTypeDeclType( |
| 2794 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
| 2795 | } else { |
| 2796 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2797 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2798 | Name.getAsIdentifierInfo(), |
| 2799 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2800 | return D2CXX; |
| 2801 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2802 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2803 | D2 = D2CXX; |
| 2804 | D2->setAccess(D->getAccess()); |
| 2805 | D2->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 2806 | addDeclToContexts(D, D2); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2807 | |
| 2808 | if (ClassTemplateDecl *FromDescribed = |
| 2809 | DCXX->getDescribedClassTemplate()) { |
| 2810 | ClassTemplateDecl *ToDescribed; |
| 2811 | if (Error Err = importInto(ToDescribed, FromDescribed)) |
| 2812 | return std::move(Err); |
| 2813 | D2CXX->setDescribedClassTemplate(ToDescribed); |
| 2814 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { |
| 2815 | // In a record describing a template the type should be an |
| 2816 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2817 | // previously set type to the correct value here (ToDescribed is not |
| 2818 | // available at record create). |
| 2819 | // FIXME: The previous type is cleared but not removed from |
| 2820 | // ASTContext's internal storage. |
| 2821 | CXXRecordDecl *Injected = nullptr; |
| 2822 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2823 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2824 | if (Record && Record->isInjectedClassName()) { |
| 2825 | Injected = Record; |
| 2826 | break; |
| Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2827 | } |
| 2828 | } |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2829 | // Create an injected type for the whole redecl chain. |
| 2830 | SmallVector<Decl *, 2> Redecls = |
| 2831 | getCanonicalForwardRedeclChain(D2CXX); |
| 2832 | for (auto *R : Redecls) { |
| 2833 | auto *RI = cast<CXXRecordDecl>(R); |
| 2834 | RI->setTypeForDecl(nullptr); |
| 2835 | // Below we create a new injected type and assign that to the |
| 2836 | // canonical decl, subsequent declarations in the chain will reuse |
| 2837 | // that type. |
| 2838 | Importer.getToContext().getInjectedClassNameType( |
| 2839 | RI, ToDescribed->getInjectedClassNameSpecialization()); |
| 2840 | } |
| 2841 | // Set the new type for the previous injected decl too. |
| 2842 | if (Injected) { |
| 2843 | Injected->setTypeForDecl(nullptr); |
| 2844 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2845 | } |
| 2846 | } |
| 2847 | } else if (MemberSpecializationInfo *MemberInfo = |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2848 | DCXX->getMemberSpecializationInfo()) { |
| 2849 | TemplateSpecializationKind SK = |
| 2850 | MemberInfo->getTemplateSpecializationKind(); |
| 2851 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2852 | |
| 2853 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) |
| 2854 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); |
| 2855 | else |
| 2856 | return ToInstOrErr.takeError(); |
| 2857 | |
| 2858 | if (ExpectedSLoc POIOrErr = |
| 2859 | import(MemberInfo->getPointOfInstantiation())) |
| 2860 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2861 | *POIOrErr); |
| 2862 | else |
| 2863 | return POIOrErr.takeError(); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2864 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2865 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2866 | } else { |
| 2867 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
| 2868 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2869 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2870 | return D2; |
| 2871 | D2->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 2872 | addDeclToContexts(D, D2); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2873 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2874 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2875 | if (auto BraceRangeOrErr = import(D->getBraceRange())) |
| 2876 | D2->setBraceRange(*BraceRangeOrErr); |
| 2877 | else |
| 2878 | return BraceRangeOrErr.takeError(); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2879 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) |
| 2880 | D2->setQualifierInfo(*QualifierLocOrErr); |
| 2881 | else |
| 2882 | return QualifierLocOrErr.takeError(); |
| 2883 | |
| 2884 | if (D->isAnonymousStructOrUnion()) |
| 2885 | D2->setAnonymousStructOrUnion(true); |
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2886 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2887 | if (D->isCompleteDefinition()) |
| 2888 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) |
| 2889 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2890 | |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2891 | return D2; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2892 | } |
| 2893 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2894 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2895 | // Import the major distinguishing characteristics of this enumerator. |
| 2896 | DeclContext *DC, *LexicalDC; |
| 2897 | DeclarationName Name; |
| 2898 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2899 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2900 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2901 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2902 | if (ToD) |
| 2903 | return ToD; |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2904 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2905 | // Determine whether there are any other declarations with the same name and |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2906 | // in the same context. |
| 2907 | if (!LexicalDC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2908 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2909 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2910 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2911 | for (auto *FoundDecl : FoundDecls) { |
| 2912 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2913 | continue; |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2914 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2915 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2916 | if (IsStructuralMatch(D, FoundEnumConstant)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2917 | return Importer.MapImported(D, FoundEnumConstant); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2918 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2919 | } |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2920 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2921 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2922 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2923 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2924 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 2925 | if (NameOrErr) |
| 2926 | Name = NameOrErr.get(); |
| 2927 | else |
| 2928 | return NameOrErr.takeError(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2929 | } |
| 2930 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2931 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2932 | ExpectedType TypeOrErr = import(D->getType()); |
| 2933 | if (!TypeOrErr) |
| 2934 | return TypeOrErr.takeError(); |
| 2935 | |
| 2936 | ExpectedExpr InitOrErr = import(D->getInitExpr()); |
| 2937 | if (!InitOrErr) |
| 2938 | return InitOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2939 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2940 | EnumConstantDecl *ToEnumerator; |
| 2941 | if (GetImportedOrCreateDecl( |
| 2942 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2943 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2944 | return ToEnumerator; |
| 2945 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2946 | ToEnumerator->setAccess(D->getAccess()); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2947 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2948 | LexicalDC->addDeclInternal(ToEnumerator); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2949 | return ToEnumerator; |
| 2950 | } |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2951 | |
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 2952 | Error ASTNodeImporter::ImportTemplateParameterLists(const DeclaratorDecl *FromD, |
| 2953 | DeclaratorDecl *ToD) { |
| 2954 | unsigned int Num = FromD->getNumTemplateParameterLists(); |
| 2955 | if (Num == 0) |
| 2956 | return Error::success(); |
| 2957 | SmallVector<TemplateParameterList *, 2> ToTPLists(Num); |
| 2958 | for (unsigned int I = 0; I < Num; ++I) |
| 2959 | if (Expected<TemplateParameterList *> ToTPListOrErr = |
| 2960 | import(FromD->getTemplateParameterList(I))) |
| 2961 | ToTPLists[I] = *ToTPListOrErr; |
| 2962 | else |
| 2963 | return ToTPListOrErr.takeError(); |
| 2964 | ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists); |
| 2965 | return Error::success(); |
| 2966 | } |
| 2967 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2968 | Error ASTNodeImporter::ImportTemplateInformation( |
| 2969 | FunctionDecl *FromFD, FunctionDecl *ToFD) { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2970 | switch (FromFD->getTemplatedKind()) { |
| 2971 | case FunctionDecl::TK_NonTemplate: |
| 2972 | case FunctionDecl::TK_FunctionTemplate: |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2973 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2974 | |
| 2975 | case FunctionDecl::TK_MemberSpecialization: { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2976 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2977 | |
| 2978 | if (Expected<FunctionDecl *> InstFDOrErr = |
| 2979 | import(FromFD->getInstantiatedFromMemberFunction())) |
| 2980 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); |
| 2981 | else |
| 2982 | return InstFDOrErr.takeError(); |
| 2983 | |
| 2984 | if (ExpectedSLoc POIOrErr = import( |
| 2985 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) |
| 2986 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); |
| 2987 | else |
| 2988 | return POIOrErr.takeError(); |
| 2989 | |
| 2990 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2991 | } |
| 2992 | |
| 2993 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2994 | auto FunctionAndArgsOrErr = |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2995 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2996 | if (!FunctionAndArgsOrErr) |
| 2997 | return FunctionAndArgsOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2998 | |
| 2999 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3000 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3001 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3002 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3003 | TemplateArgumentListInfo ToTAInfo; |
| 3004 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3005 | if (FromTAArgsAsWritten) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3006 | if (Error Err = ImportTemplateArgumentListInfo( |
| 3007 | *FromTAArgsAsWritten, ToTAInfo)) |
| 3008 | return Err; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3009 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3010 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); |
| 3011 | if (!POIOrErr) |
| 3012 | return POIOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3013 | |
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 3014 | if (Error Err = ImportTemplateParameterLists(FromFD, ToFD)) |
| 3015 | return Err; |
| 3016 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3017 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3018 | ToFD->setFunctionTemplateSpecialization( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3019 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, |
| 3020 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); |
| 3021 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3022 | } |
| 3023 | |
| 3024 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 3025 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 3026 | UnresolvedSet<8> TemplDecls; |
| 3027 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 3028 | for (unsigned I = 0; I < NumTemplates; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3029 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = |
| 3030 | import(FromInfo->getTemplate(I))) |
| 3031 | TemplDecls.addDecl(*ToFTDOrErr); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3032 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3033 | return ToFTDOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3034 | } |
| 3035 | |
| 3036 | // Import TemplateArgumentListInfo. |
| 3037 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3038 | if (Error Err = ImportTemplateArgumentListInfo( |
| 3039 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 3040 | llvm::makeArrayRef( |
| 3041 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), |
| 3042 | ToTAInfo)) |
| 3043 | return Err; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3044 | |
| 3045 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 3046 | TemplDecls, ToTAInfo); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3047 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3048 | } |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3049 | } |
| Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 3050 | llvm_unreachable("All cases should be covered!"); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3051 | } |
| 3052 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3053 | Expected<FunctionDecl *> |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3054 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3055 | auto FunctionAndArgsOrErr = |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3056 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3057 | if (!FunctionAndArgsOrErr) |
| 3058 | return FunctionAndArgsOrErr.takeError(); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3059 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3060 | FunctionTemplateDecl *Template; |
| 3061 | TemplateArgsTy ToTemplArgs; |
| 3062 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3063 | void *InsertPos = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3064 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3065 | return FoundSpec; |
| 3066 | } |
| 3067 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3068 | Error ASTNodeImporter::ImportFunctionDeclBody(FunctionDecl *FromFD, |
| 3069 | FunctionDecl *ToFD) { |
| 3070 | if (Stmt *FromBody = FromFD->getBody()) { |
| 3071 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) |
| 3072 | ToFD->setBody(*ToBodyOrErr); |
| 3073 | else |
| 3074 | return ToBodyOrErr.takeError(); |
| 3075 | } |
| 3076 | return Error::success(); |
| 3077 | } |
| 3078 | |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3079 | // Returns true if the given D has a DeclContext up to the TranslationUnitDecl |
| 3080 | // which is equal to the given DC. |
| Benjamin Kramer | df18650 | 2020-01-14 14:06:12 +0100 | [diff] [blame] | 3081 | static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) { |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3082 | const DeclContext *DCi = D->getDeclContext(); |
| 3083 | while (DCi != D->getTranslationUnitDecl()) { |
| 3084 | if (DCi == DC) |
| 3085 | return true; |
| 3086 | DCi = DCi->getParent(); |
| 3087 | } |
| 3088 | return false; |
| 3089 | } |
| 3090 | |
| 3091 | bool ASTNodeImporter::hasAutoReturnTypeDeclaredInside(FunctionDecl *D) { |
| 3092 | QualType FromTy = D->getType(); |
| 3093 | const FunctionProtoType *FromFPT = FromTy->getAs<FunctionProtoType>(); |
| 3094 | assert(FromFPT && "Must be called on FunctionProtoType"); |
| 3095 | if (AutoType *AutoT = FromFPT->getReturnType()->getContainedAutoType()) { |
| 3096 | QualType DeducedT = AutoT->getDeducedType(); |
| 3097 | if (const RecordType *RecordT = |
| 3098 | DeducedT.isNull() ? nullptr : dyn_cast<RecordType>(DeducedT)) { |
| 3099 | RecordDecl *RD = RecordT->getDecl(); |
| 3100 | assert(RD); |
| 3101 | if (isAncestorDeclContextOf(D, RD)) { |
| 3102 | assert(RD->getLexicalDeclContext() == RD->getDeclContext()); |
| 3103 | return true; |
| 3104 | } |
| 3105 | } |
| 3106 | } |
| 3107 | if (const TypedefType *TypedefT = |
| 3108 | dyn_cast<TypedefType>(FromFPT->getReturnType())) { |
| 3109 | TypedefNameDecl *TD = TypedefT->getDecl(); |
| 3110 | assert(TD); |
| 3111 | if (isAncestorDeclContextOf(D, TD)) { |
| 3112 | assert(TD->getLexicalDeclContext() == TD->getDeclContext()); |
| 3113 | return true; |
| 3114 | } |
| 3115 | } |
| 3116 | return false; |
| 3117 | } |
| 3118 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3119 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3120 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3121 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3122 | auto RedeclIt = Redecls.begin(); |
| 3123 | // Import the first part of the decl chain. I.e. import all previous |
| 3124 | // declarations starting from the canonical decl. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3125 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3126 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3127 | if (!ToRedeclOrErr) |
| 3128 | return ToRedeclOrErr.takeError(); |
| 3129 | } |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3130 | assert(*RedeclIt == D); |
| 3131 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3132 | // Import the major distinguishing characteristics of this function. |
| 3133 | DeclContext *DC, *LexicalDC; |
| 3134 | DeclarationName Name; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3135 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3136 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3137 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3138 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3139 | if (ToD) |
| 3140 | return ToD; |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3141 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3142 | FunctionDecl *FoundByLookup = nullptr; |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3143 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); |
| Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 3144 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3145 | // 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] | 3146 | // existing specialization in the "to" context. The lookup below will not |
| 3147 | // find any specialization, but would find the primary template; thus, we |
| 3148 | // have to skip normal lookup in case of specializations. |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3149 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 3150 | if (D->getTemplatedKind() == |
| 3151 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3152 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); |
| 3153 | if (!FoundFunctionOrErr) |
| 3154 | return FoundFunctionOrErr.takeError(); |
| 3155 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { |
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 3156 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 3157 | return Def; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3158 | FoundByLookup = FoundFunction; |
| 3159 | } |
| 3160 | } |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3161 | // Try to find a function in our own ("to") context with the same name, same |
| 3162 | // type, and in the same context as the function we're importing. |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3163 | else if (!LexicalDC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3164 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3165 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3166 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3167 | for (auto *FoundDecl : FoundDecls) { |
| 3168 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3169 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3170 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3171 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 3172 | if (!hasSameVisibilityContextAndLinkage(FoundFunction, D)) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3173 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3174 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3175 | if (IsStructuralMatch(D, FoundFunction)) { |
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 3176 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 3177 | return Def; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3178 | FoundByLookup = FoundFunction; |
| 3179 | break; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3180 | } |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3181 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 3182 | // Sema::IsOverload out to the AST library. |
| 3183 | |
| 3184 | // Function overloading is okay in C++. |
| 3185 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
| 3186 | continue; |
| 3187 | |
| 3188 | // Complain about inconsistent function types. |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3189 | Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3190 | << Name << D->getType() << FoundFunction->getType(); |
| 3191 | Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here) |
| 3192 | << FoundFunction->getType(); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3193 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3194 | } |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3195 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3196 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3197 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3198 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 3199 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 3200 | if (NameOrErr) |
| 3201 | Name = NameOrErr.get(); |
| 3202 | else |
| 3203 | return NameOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3204 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3205 | } |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3206 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3207 | // We do not allow more than one in-class declaration of a function. This is |
| 3208 | // because AST clients like VTableBuilder asserts on this. VTableBuilder |
| 3209 | // assumes there is only one in-class declaration. Building a redecl |
| 3210 | // chain would result in more than one in-class declaration for |
| 3211 | // overrides (even if they are part of the same redecl chain inside the |
| 3212 | // derived class.) |
| 3213 | if (FoundByLookup) { |
| Mikael Holmen | c1c97aa | 2019-01-29 06:53:31 +0000 | [diff] [blame] | 3214 | if (isa<CXXMethodDecl>(FoundByLookup)) { |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3215 | if (D->getLexicalDeclContext() == D->getDeclContext()) { |
| Balazs Keri | e9719f9 | 2019-08-07 12:40:17 +0000 | [diff] [blame] | 3216 | if (!D->doesThisDeclarationHaveABody()) { |
| 3217 | if (FunctionTemplateDecl *DescribedD = |
| 3218 | D->getDescribedFunctionTemplate()) { |
| 3219 | // Handle a "templated" function together with its described |
| 3220 | // template. This avoids need for a similar check at import of the |
| 3221 | // described template. |
| 3222 | assert(FoundByLookup->getDescribedFunctionTemplate() && |
| 3223 | "Templated function mapped to non-templated?"); |
| 3224 | Importer.MapImported(DescribedD, |
| 3225 | FoundByLookup->getDescribedFunctionTemplate()); |
| 3226 | } |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3227 | return Importer.MapImported(D, FoundByLookup); |
| Balazs Keri | e9719f9 | 2019-08-07 12:40:17 +0000 | [diff] [blame] | 3228 | } else { |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3229 | // Let's continue and build up the redecl chain in this case. |
| 3230 | // FIXME Merge the functions into one decl. |
| 3231 | } |
| 3232 | } |
| 3233 | } |
| 3234 | } |
| 3235 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3236 | DeclarationNameInfo NameInfo(Name, Loc); |
| 3237 | // Import additional name location/type info. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3238 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 3239 | return std::move(Err); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3240 | |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3241 | QualType FromTy = D->getType(); |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3242 | // Set to true if we do not import the type of the function as is. There are |
| 3243 | // cases when the original type would result in an infinite recursion during |
| 3244 | // the import. To avoid an infinite recursion when importing, we create the |
| 3245 | // FunctionDecl with a simplified function type and update it only after the |
| 3246 | // relevant AST nodes are already imported. |
| 3247 | bool UsedDifferentProtoType = false; |
| 3248 | if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) { |
| 3249 | QualType FromReturnTy = FromFPT->getReturnType(); |
| 3250 | // Functions with auto return type may define a struct inside their body |
| 3251 | // and the return type could refer to that struct. |
| 3252 | // E.g.: auto foo() { struct X{}; return X(); } |
| 3253 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 3254 | // with a simplified return type. |
| 3255 | if (hasAutoReturnTypeDeclaredInside(D)) { |
| 3256 | FromReturnTy = Importer.getFromContext().VoidTy; |
| 3257 | UsedDifferentProtoType = true; |
| 3258 | } |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3259 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 3260 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 3261 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 3262 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3263 | // with a simplified function type. |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 3264 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 3265 | FromEPI.ExceptionSpec.SourceTemplate || |
| 3266 | FromEPI.ExceptionSpec.NoexceptExpr) { |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3267 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3268 | FromEPI = DefaultEPI; |
| 3269 | UsedDifferentProtoType = true; |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3270 | } |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3271 | FromTy = Importer.getFromContext().getFunctionType( |
| 3272 | FromReturnTy, FromFPT->getParamTypes(), FromEPI); |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3273 | } |
| 3274 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3275 | Error Err = Error::success(); |
| 3276 | auto T = importChecked(Err, FromTy); |
| 3277 | auto TInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 3278 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 3279 | auto ToEndLoc = importChecked(Err, D->getEndLoc()); |
| 3280 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 3281 | auto TrailingRequiresClause = |
| 3282 | importChecked(Err, D->getTrailingRequiresClause()); |
| 3283 | if (Err) |
| 3284 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3285 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3286 | // Import the function parameters. |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3287 | SmallVector<ParmVarDecl *, 8> Parameters; |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3288 | for (auto P : D->parameters()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3289 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) |
| 3290 | Parameters.push_back(*ToPOrErr); |
| 3291 | else |
| 3292 | return ToPOrErr.takeError(); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3293 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3294 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3295 | // Create the imported function. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3296 | FunctionDecl *ToFunction = nullptr; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3297 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3298 | Expr *ExplicitExpr = nullptr; |
| 3299 | if (FromConstructor->getExplicitSpecifier().getExpr()) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3300 | auto Imp = import(FromConstructor->getExplicitSpecifier().getExpr()); |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3301 | if (!Imp) |
| 3302 | return Imp.takeError(); |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3303 | ExplicitExpr = *Imp; |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3304 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3305 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3306 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3307 | ToInnerLocStart, NameInfo, T, TInfo, |
| 3308 | ExplicitSpecifier( |
| 3309 | ExplicitExpr, |
| 3310 | FromConstructor->getExplicitSpecifier().getKind()), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3311 | D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(), |
| 3312 | InheritedConstructor(), // FIXME: Properly import inherited |
| 3313 | // constructor info |
| 3314 | TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3315 | return ToFunction; |
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3316 | } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { |
| 3317 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3318 | Error Err = Error::success(); |
| 3319 | auto ToOperatorDelete = importChecked( |
| 3320 | Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete())); |
| 3321 | auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg()); |
| 3322 | if (Err) |
| 3323 | return std::move(Err); |
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3324 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3325 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3326 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3327 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3328 | D->isImplicit(), D->getConstexprKind(), TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3329 | return ToFunction; |
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3330 | |
| 3331 | CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction); |
| 3332 | |
| 3333 | ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3334 | } else if (CXXConversionDecl *FromConversion = |
| 3335 | dyn_cast<CXXConversionDecl>(D)) { |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3336 | Expr *ExplicitExpr = nullptr; |
| 3337 | if (FromConversion->getExplicitSpecifier().getExpr()) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3338 | auto Imp = import(FromConversion->getExplicitSpecifier().getExpr()); |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3339 | if (!Imp) |
| 3340 | return Imp.takeError(); |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3341 | ExplicitExpr = *Imp; |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3342 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3343 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 3344 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3345 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3346 | ExplicitSpecifier(ExplicitExpr, |
| 3347 | FromConversion->getExplicitSpecifier().getKind()), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3348 | D->getConstexprKind(), SourceLocation(), TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3349 | return ToFunction; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3350 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3351 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 3352 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3353 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3354 | Method->isInlineSpecified(), D->getConstexprKind(), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3355 | SourceLocation(), TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3356 | return ToFunction; |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3357 | } else { |
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3358 | if (GetImportedOrCreateDecl( |
| 3359 | ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, |
| 3360 | NameInfo, T, TInfo, D->getStorageClass(), D->isInlineSpecified(), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3361 | D->hasWrittenPrototype(), D->getConstexprKind(), |
| 3362 | TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3363 | return ToFunction; |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3364 | } |
| John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3365 | |
| Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3366 | // Connect the redecl chain. |
| 3367 | if (FoundByLookup) { |
| 3368 | auto *Recent = const_cast<FunctionDecl *>( |
| 3369 | FoundByLookup->getMostRecentDecl()); |
| 3370 | ToFunction->setPreviousDecl(Recent); |
| Gabor Marton | ce6b781 | 2019-05-08 15:23:48 +0000 | [diff] [blame] | 3371 | // FIXME Probably we should merge exception specifications. E.g. In the |
| 3372 | // "To" context the existing function may have exception specification with |
| 3373 | // noexcept-unevaluated, while the newly imported function may have an |
| 3374 | // evaluated noexcept. A call to adjustExceptionSpec() on the imported |
| 3375 | // decl and its redeclarations may be required. |
| Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3376 | } |
| 3377 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3378 | ToFunction->setQualifierInfo(ToQualifierLoc); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3379 | ToFunction->setAccess(D->getAccess()); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3380 | ToFunction->setLexicalDeclContext(LexicalDC); |
| John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 3381 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 3382 | ToFunction->setTrivial(D->isTrivial()); |
| 3383 | ToFunction->setPure(D->isPure()); |
| Balazs Keri | b427c06 | 2019-08-13 08:04:06 +0000 | [diff] [blame] | 3384 | ToFunction->setDefaulted(D->isDefaulted()); |
| 3385 | ToFunction->setExplicitlyDefaulted(D->isExplicitlyDefaulted()); |
| 3386 | ToFunction->setDeletedAsWritten(D->isDeletedAsWritten()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3387 | ToFunction->setRangeEnd(ToEndLoc); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3388 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3389 | // Set the parameters. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3390 | for (auto *Param : Parameters) { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3391 | Param->setOwningFunction(ToFunction); |
| 3392 | ToFunction->addDeclInternal(Param); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3393 | } |
| David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 3394 | ToFunction->setParams(Parameters); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3395 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3396 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 3397 | // params it refers to. |
| 3398 | if (TInfo) { |
| 3399 | if (auto ProtoLoc = |
| 3400 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 3401 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 3402 | ProtoLoc.setParam(I, Parameters[I]); |
| 3403 | } |
| 3404 | } |
| 3405 | |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3406 | // Import the describing template function, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3407 | if (FromFT) { |
| 3408 | auto ToFTOrErr = import(FromFT); |
| 3409 | if (!ToFTOrErr) |
| 3410 | return ToFTOrErr.takeError(); |
| 3411 | } |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3412 | |
| Balazs Keri | e13e836 | 2019-08-16 12:10:03 +0000 | [diff] [blame] | 3413 | // Import Ctor initializers. |
| 3414 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 3415 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 3416 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); |
| 3417 | // Import first, then allocate memory and copy if there was no error. |
| 3418 | if (Error Err = ImportContainerChecked( |
| 3419 | FromConstructor->inits(), CtorInitializers)) |
| 3420 | return std::move(Err); |
| 3421 | auto **Memory = |
| 3422 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 3423 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
| 3424 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
| 3425 | ToCtor->setCtorInitializers(Memory); |
| 3426 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 3427 | } |
| 3428 | } |
| 3429 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3430 | if (D->doesThisDeclarationHaveABody()) { |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3431 | Error Err = ImportFunctionDeclBody(D, ToFunction); |
| 3432 | |
| 3433 | if (Err) |
| 3434 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3435 | } |
| 3436 | |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3437 | // Import and set the original type in case we used another type. |
| 3438 | if (UsedDifferentProtoType) { |
| 3439 | if (ExpectedType TyOrErr = import(D->getType())) |
| 3440 | ToFunction->setType(*TyOrErr); |
| 3441 | else |
| 3442 | return TyOrErr.takeError(); |
| 3443 | } |
| 3444 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3445 | // FIXME: Other bits to merge? |
| Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3446 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3447 | // If it is a template, import all related things. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3448 | if (Error Err = ImportTemplateInformation(D, ToFunction)) |
| 3449 | return std::move(Err); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3450 | |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 3451 | addDeclToContexts(D, ToFunction); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3452 | |
| Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3453 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 3454 | if (Error Err = ImportOverriddenMethods(cast<CXXMethodDecl>(ToFunction), |
| 3455 | FromCXXMethod)) |
| 3456 | return std::move(Err); |
| Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3457 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3458 | // Import the rest of the chain. I.e. import all subsequent declarations. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3459 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3460 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3461 | if (!ToRedeclOrErr) |
| 3462 | return ToRedeclOrErr.takeError(); |
| 3463 | } |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3464 | |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3465 | return ToFunction; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3466 | } |
| 3467 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3468 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3469 | return VisitFunctionDecl(D); |
| 3470 | } |
| 3471 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3472 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3473 | return VisitCXXMethodDecl(D); |
| 3474 | } |
| 3475 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3476 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3477 | return VisitCXXMethodDecl(D); |
| 3478 | } |
| 3479 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3480 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3481 | return VisitCXXMethodDecl(D); |
| 3482 | } |
| 3483 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3484 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3485 | // Import the major distinguishing characteristics of a variable. |
| 3486 | DeclContext *DC, *LexicalDC; |
| 3487 | DeclarationName Name; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3488 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3489 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3490 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3491 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3492 | if (ToD) |
| 3493 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3494 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3495 | // Determine whether we've already imported this field. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3496 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3497 | for (auto *FoundDecl : FoundDecls) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3498 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3499 | // For anonymous fields, match up by index. |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3500 | if (!Name && |
| 3501 | ASTImporter::getFieldIndex(D) != |
| 3502 | ASTImporter::getFieldIndex(FoundField)) |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3503 | continue; |
| 3504 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3505 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3506 | FoundField->getType())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3507 | Importer.MapImported(D, FoundField); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3508 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the |
| 3509 | // initializer of a FieldDecl might not had been instantiated in the |
| 3510 | // "To" context. However, the "From" context might instantiated that, |
| 3511 | // thus we have to merge that. |
| 3512 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
| 3513 | // We don't have yet the initializer set. |
| 3514 | if (FoundField->hasInClassInitializer() && |
| 3515 | !FoundField->getInClassInitializer()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3516 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) |
| 3517 | FoundField->setInClassInitializer(*ToInitializerOrErr); |
| 3518 | else { |
| 3519 | // We can't return error here, |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3520 | // since we already mapped D as imported. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3521 | // FIXME: warning message? |
| 3522 | consumeError(ToInitializerOrErr.takeError()); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3523 | return FoundField; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3524 | } |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3525 | } |
| 3526 | } |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3527 | return FoundField; |
| 3528 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3529 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3530 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3531 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3532 | << Name << D->getType() << FoundField->getType(); |
| 3533 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3534 | << FoundField->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3535 | |
| 3536 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3537 | } |
| 3538 | } |
| 3539 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3540 | Error Err = Error::success(); |
| 3541 | auto ToType = importChecked(Err, D->getType()); |
| 3542 | auto ToTInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 3543 | auto ToBitWidth = importChecked(Err, D->getBitWidth()); |
| 3544 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 3545 | auto ToInitializer = importChecked(Err, D->getInClassInitializer()); |
| 3546 | if (Err) |
| 3547 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3548 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3549 | FieldDecl *ToField; |
| 3550 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3551 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3552 | ToType, ToTInfo, ToBitWidth, D->isMutable(), |
| 3553 | D->getInClassInitStyle())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3554 | return ToField; |
| 3555 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3556 | ToField->setAccess(D->getAccess()); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3557 | ToField->setLexicalDeclContext(LexicalDC); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3558 | if (ToInitializer) |
| 3559 | ToField->setInClassInitializer(ToInitializer); |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3560 | ToField->setImplicit(D->isImplicit()); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3561 | LexicalDC->addDeclInternal(ToField); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3562 | return ToField; |
| 3563 | } |
| 3564 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3565 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3566 | // Import the major distinguishing characteristics of a variable. |
| 3567 | DeclContext *DC, *LexicalDC; |
| 3568 | DeclarationName Name; |
| 3569 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3570 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3571 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3572 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3573 | if (ToD) |
| 3574 | return ToD; |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3575 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3576 | // Determine whether we've already imported this field. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3577 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3578 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3579 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3580 | // For anonymous indirect fields, match up by index. |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3581 | if (!Name && |
| 3582 | ASTImporter::getFieldIndex(D) != |
| 3583 | ASTImporter::getFieldIndex(FoundField)) |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3584 | continue; |
| 3585 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3586 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3587 | FoundField->getType(), |
| David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 3588 | !Name.isEmpty())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3589 | Importer.MapImported(D, FoundField); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3590 | return FoundField; |
| 3591 | } |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3592 | |
| 3593 | // If there are more anonymous fields to check, continue. |
| 3594 | if (!Name && I < N-1) |
| 3595 | continue; |
| 3596 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3597 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3598 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3599 | << Name << D->getType() << FoundField->getType(); |
| 3600 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3601 | << FoundField->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3602 | |
| 3603 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3604 | } |
| 3605 | } |
| 3606 | |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3607 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3608 | auto TypeOrErr = import(D->getType()); |
| 3609 | if (!TypeOrErr) |
| 3610 | return TypeOrErr.takeError(); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3611 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3612 | auto **NamedChain = |
| 3613 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3614 | |
| 3615 | unsigned i = 0; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3616 | for (auto *PI : D->chain()) |
| 3617 | if (Expected<NamedDecl *> ToD = import(PI)) |
| 3618 | NamedChain[i++] = *ToD; |
| 3619 | else |
| 3620 | return ToD.takeError(); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3621 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3622 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 3623 | IndirectFieldDecl *ToIndirectField; |
| 3624 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3625 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3626 | // FIXME here we leak `NamedChain` which is allocated before |
| 3627 | return ToIndirectField; |
| Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3628 | |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3629 | ToIndirectField->setAccess(D->getAccess()); |
| 3630 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3631 | LexicalDC->addDeclInternal(ToIndirectField); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3632 | return ToIndirectField; |
| 3633 | } |
| 3634 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3635 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3636 | // Import the major distinguishing characteristics of a declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3637 | DeclContext *DC, *LexicalDC; |
| 3638 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 3639 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3640 | |
| 3641 | // Determine whether we've already imported this decl. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3642 | // FriendDecl is not a NamedDecl so we cannot use lookup. |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3643 | auto *RD = cast<CXXRecordDecl>(DC); |
| 3644 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3645 | |
| 3646 | while (ImportedFriend) { |
| 3647 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3648 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 3649 | /*Complain=*/false)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3650 | return Importer.MapImported(D, ImportedFriend); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3651 | |
| 3652 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 3653 | if (Importer.IsStructurallyEquivalent( |
| 3654 | D->getFriendType()->getType(), |
| 3655 | ImportedFriend->getFriendType()->getType(), true)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3656 | return Importer.MapImported(D, ImportedFriend); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3657 | } |
| 3658 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3659 | } |
| 3660 | |
| 3661 | // Not found. Create it. |
| 3662 | FriendDecl::FriendUnion ToFU; |
| Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3663 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3664 | NamedDecl *ToFriendD; |
| 3665 | if (Error Err = importInto(ToFriendD, FriendD)) |
| 3666 | return std::move(Err); |
| 3667 | |
| 3668 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && |
| Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3669 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3670 | ToFriendD->setObjectOfFriendDecl(false); |
| 3671 | |
| 3672 | ToFU = ToFriendD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3673 | } else { // The friend is a type, not a decl. |
| 3674 | if (auto TSIOrErr = import(D->getFriendType())) |
| 3675 | ToFU = *TSIOrErr; |
| 3676 | else |
| 3677 | return TSIOrErr.takeError(); |
| 3678 | } |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3679 | |
| 3680 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3681 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3682 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 3683 | if (auto ListOrErr = import(FromTPLists[I])) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3684 | ToTPLists[I] = *ListOrErr; |
| 3685 | else |
| 3686 | return ListOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3687 | } |
| 3688 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3689 | auto LocationOrErr = import(D->getLocation()); |
| 3690 | if (!LocationOrErr) |
| 3691 | return LocationOrErr.takeError(); |
| 3692 | auto FriendLocOrErr = import(D->getFriendLoc()); |
| 3693 | if (!FriendLocOrErr) |
| 3694 | return FriendLocOrErr.takeError(); |
| 3695 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3696 | FriendDecl *FrD; |
| 3697 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3698 | *LocationOrErr, ToFU, |
| 3699 | *FriendLocOrErr, ToTPLists)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3700 | return FrD; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3701 | |
| 3702 | FrD->setAccess(D->getAccess()); |
| 3703 | FrD->setLexicalDeclContext(LexicalDC); |
| 3704 | LexicalDC->addDeclInternal(FrD); |
| 3705 | return FrD; |
| 3706 | } |
| 3707 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3708 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3709 | // Import the major distinguishing characteristics of an ivar. |
| 3710 | DeclContext *DC, *LexicalDC; |
| 3711 | DeclarationName Name; |
| 3712 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3713 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3714 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3715 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3716 | if (ToD) |
| 3717 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3718 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3719 | // Determine whether we've already imported this ivar |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3720 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3721 | for (auto *FoundDecl : FoundDecls) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3722 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3723 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3724 | FoundIvar->getType())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3725 | Importer.MapImported(D, FoundIvar); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3726 | return FoundIvar; |
| 3727 | } |
| 3728 | |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3729 | Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent) |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3730 | << Name << D->getType() << FoundIvar->getType(); |
| 3731 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3732 | << FoundIvar->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3733 | |
| 3734 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3735 | } |
| 3736 | } |
| 3737 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3738 | Error Err = Error::success(); |
| 3739 | auto ToType = importChecked(Err, D->getType()); |
| 3740 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 3741 | auto ToBitWidth = importChecked(Err, D->getBitWidth()); |
| 3742 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 3743 | if (Err) |
| 3744 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3745 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3746 | ObjCIvarDecl *ToIvar; |
| 3747 | if (GetImportedOrCreateDecl( |
| 3748 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3749 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3750 | ToType, ToTypeSourceInfo, |
| 3751 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3752 | return ToIvar; |
| 3753 | |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3754 | ToIvar->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3755 | LexicalDC->addDeclInternal(ToIvar); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3756 | return ToIvar; |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3757 | } |
| 3758 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3759 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3760 | |
| 3761 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 3762 | auto RedeclIt = Redecls.begin(); |
| 3763 | // Import the first part of the decl chain. I.e. import all previous |
| 3764 | // declarations starting from the canonical decl. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3765 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3766 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3767 | if (!RedeclOrErr) |
| 3768 | return RedeclOrErr.takeError(); |
| 3769 | } |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3770 | assert(*RedeclIt == D); |
| 3771 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3772 | // Import the major distinguishing characteristics of a variable. |
| 3773 | DeclContext *DC, *LexicalDC; |
| 3774 | DeclarationName Name; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3775 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3776 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3777 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3778 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3779 | if (ToD) |
| 3780 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3781 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3782 | // Try to find a variable in our own ("to") context with the same name and |
| 3783 | // in the same context as the variable we're importing. |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3784 | VarDecl *FoundByLookup = nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3785 | if (D->isFileVarDecl()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3786 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3787 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3788 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3789 | for (auto *FoundDecl : FoundDecls) { |
| 3790 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3791 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3792 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3793 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 3794 | if (!hasSameVisibilityContextAndLinkage(FoundVar, D)) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3795 | continue; |
| 3796 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| 3797 | FoundVar->getType())) { |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3798 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3799 | // The VarDecl in the "From" context has a definition, but in the |
| 3800 | // "To" context we already have a definition. |
| 3801 | VarDecl *FoundDef = FoundVar->getDefinition(); |
| 3802 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 3803 | // FIXME Check for ODR error if the two definitions have |
| 3804 | // different initializers? |
| 3805 | return Importer.MapImported(D, FoundDef); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3806 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3807 | // The VarDecl in the "From" context has an initializer, but in the |
| 3808 | // "To" context we already have an initializer. |
| 3809 | const VarDecl *FoundDInit = nullptr; |
| 3810 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) |
| 3811 | // FIXME Diagnose ODR error if the two initializers are different? |
| 3812 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); |
| 3813 | |
| 3814 | FoundByLookup = FoundVar; |
| 3815 | break; |
| 3816 | } |
| 3817 | |
| 3818 | const ArrayType *FoundArray |
| 3819 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3820 | const ArrayType *TArray |
| 3821 | = Importer.getToContext().getAsArrayType(D->getType()); |
| 3822 | if (FoundArray && TArray) { |
| 3823 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3824 | isa<ConstantArrayType>(TArray)) { |
| 3825 | // Import the type. |
| 3826 | if (auto TyOrErr = import(D->getType())) |
| 3827 | FoundVar->setType(*TyOrErr); |
| 3828 | else |
| 3829 | return TyOrErr.takeError(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3830 | |
| 3831 | FoundByLookup = FoundVar; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3832 | break; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3833 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3834 | isa<ConstantArrayType>(FoundArray)) { |
| 3835 | FoundByLookup = FoundVar; |
| 3836 | break; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3837 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3838 | } |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3839 | |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3840 | Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3841 | << Name << D->getType() << FoundVar->getType(); |
| 3842 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3843 | << FoundVar->getType(); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3844 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3845 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3846 | } |
| 3847 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3848 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3849 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 3850 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 3851 | if (NameOrErr) |
| 3852 | Name = NameOrErr.get(); |
| 3853 | else |
| 3854 | return NameOrErr.takeError(); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3855 | } |
| 3856 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3857 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3858 | Error Err = Error::success(); |
| 3859 | auto ToType = importChecked(Err, D->getType()); |
| 3860 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 3861 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 3862 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 3863 | if (Err) |
| 3864 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3865 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3866 | // Create the imported variable. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3867 | VarDecl *ToVar; |
| 3868 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3869 | ToInnerLocStart, Loc, |
| 3870 | Name.getAsIdentifierInfo(), |
| 3871 | ToType, ToTypeSourceInfo, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3872 | D->getStorageClass())) |
| 3873 | return ToVar; |
| 3874 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3875 | ToVar->setQualifierInfo(ToQualifierLoc); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3876 | ToVar->setAccess(D->getAccess()); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3877 | ToVar->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3878 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3879 | if (FoundByLookup) { |
| 3880 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); |
| 3881 | ToVar->setPreviousDecl(Recent); |
| 3882 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3883 | |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 3884 | // Import the described template, if any. |
| 3885 | if (D->getDescribedVarTemplate()) { |
| 3886 | auto ToVTOrErr = import(D->getDescribedVarTemplate()); |
| 3887 | if (!ToVTOrErr) |
| 3888 | return ToVTOrErr.takeError(); |
| 3889 | } |
| 3890 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3891 | if (Error Err = ImportInitializer(D, ToVar)) |
| 3892 | return std::move(Err); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3893 | |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3894 | if (D->isConstexpr()) |
| 3895 | ToVar->setConstexpr(true); |
| 3896 | |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 3897 | addDeclToContexts(D, ToVar); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3898 | |
| 3899 | // Import the rest of the chain. I.e. import all subsequent declarations. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3900 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3901 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3902 | if (!RedeclOrErr) |
| 3903 | return RedeclOrErr.takeError(); |
| 3904 | } |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3905 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3906 | return ToVar; |
| 3907 | } |
| 3908 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3909 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3910 | // Parameters are created in the translation unit's context, then moved |
| 3911 | // into the function declaration's context afterward. |
| 3912 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3913 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3914 | Error Err = Error::success(); |
| 3915 | auto ToDeclName = importChecked(Err, D->getDeclName()); |
| 3916 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 3917 | auto ToType = importChecked(Err, D->getType()); |
| 3918 | if (Err) |
| 3919 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3920 | |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3921 | // Create the imported parameter. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3922 | ImplicitParamDecl *ToParm = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3923 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3924 | ToLocation, ToDeclName.getAsIdentifierInfo(), |
| 3925 | ToType, D->getParameterKind())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3926 | return ToParm; |
| 3927 | return ToParm; |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3928 | } |
| 3929 | |
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 3930 | Error ASTNodeImporter::ImportDefaultArgOfParmVarDecl( |
| 3931 | const ParmVarDecl *FromParam, ParmVarDecl *ToParam) { |
| 3932 | ToParam->setHasInheritedDefaultArg(FromParam->hasInheritedDefaultArg()); |
| 3933 | ToParam->setKNRPromoted(FromParam->isKNRPromoted()); |
| 3934 | |
| 3935 | if (FromParam->hasUninstantiatedDefaultArg()) { |
| 3936 | if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg())) |
| 3937 | ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr); |
| 3938 | else |
| 3939 | return ToDefArgOrErr.takeError(); |
| 3940 | } else if (FromParam->hasUnparsedDefaultArg()) { |
| 3941 | ToParam->setUnparsedDefaultArg(); |
| 3942 | } else if (FromParam->hasDefaultArg()) { |
| 3943 | if (auto ToDefArgOrErr = import(FromParam->getDefaultArg())) |
| 3944 | ToParam->setDefaultArg(*ToDefArgOrErr); |
| 3945 | else |
| 3946 | return ToDefArgOrErr.takeError(); |
| 3947 | } |
| 3948 | |
| 3949 | return Error::success(); |
| 3950 | } |
| 3951 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3952 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3953 | // Parameters are created in the translation unit's context, then moved |
| 3954 | // into the function declaration's context afterward. |
| 3955 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3956 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 3957 | Error Err = Error::success(); |
| 3958 | auto ToDeclName = importChecked(Err, D->getDeclName()); |
| 3959 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 3960 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 3961 | auto ToType = importChecked(Err, D->getType()); |
| 3962 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 3963 | if (Err) |
| 3964 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3965 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3966 | ParmVarDecl *ToParm; |
| 3967 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3968 | ToInnerLocStart, ToLocation, |
| 3969 | ToDeclName.getAsIdentifierInfo(), ToType, |
| 3970 | ToTypeSourceInfo, D->getStorageClass(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3971 | /*DefaultArg*/ nullptr)) |
| 3972 | return ToParm; |
| Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3973 | |
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 3974 | // Set the default argument. It should be no problem if it was already done. |
| 3975 | // Do not import the default expression before GetImportedOrCreateDecl call |
| 3976 | // to avoid possible infinite import loop because circular dependency. |
| 3977 | if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm)) |
| 3978 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3979 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3980 | if (D->isObjCMethodParameter()) { |
| 3981 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3982 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3983 | } else { |
| 3984 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3985 | D->getFunctionScopeIndex()); |
| 3986 | } |
| 3987 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3988 | return ToParm; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3989 | } |
| 3990 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3991 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3992 | // Import the major distinguishing characteristics of a method. |
| 3993 | DeclContext *DC, *LexicalDC; |
| 3994 | DeclarationName Name; |
| 3995 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3996 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3997 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3998 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3999 | if (ToD) |
| 4000 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4001 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4002 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4003 | for (auto *FoundDecl : FoundDecls) { |
| 4004 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4005 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 4006 | continue; |
| 4007 | |
| 4008 | // Check return types. |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4009 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 4010 | FoundMethod->getReturnType())) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4011 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent) |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4012 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 4013 | << FoundMethod->getReturnType(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4014 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4015 | diag::note_odr_objc_method_here) |
| 4016 | << D->isInstanceMethod() << Name; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4017 | |
| 4018 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4019 | } |
| 4020 | |
| 4021 | // Check the number of parameters. |
| 4022 | if (D->param_size() != FoundMethod->param_size()) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4023 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4024 | << D->isInstanceMethod() << Name |
| 4025 | << D->param_size() << FoundMethod->param_size(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4026 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4027 | diag::note_odr_objc_method_here) |
| 4028 | << D->isInstanceMethod() << Name; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4029 | |
| 4030 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4031 | } |
| 4032 | |
| 4033 | // Check parameter types. |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4034 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4035 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 4036 | P != PEnd; ++P, ++FoundP) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4037 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4038 | (*FoundP)->getType())) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4039 | Importer.FromDiag((*P)->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4040 | diag::warn_odr_objc_method_param_type_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4041 | << D->isInstanceMethod() << Name |
| 4042 | << (*P)->getType() << (*FoundP)->getType(); |
| 4043 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 4044 | << (*FoundP)->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4045 | |
| 4046 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4047 | } |
| 4048 | } |
| 4049 | |
| 4050 | // Check variadic/non-variadic. |
| 4051 | // Check the number of parameters. |
| 4052 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4053 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4054 | << D->isInstanceMethod() << Name; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4055 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4056 | diag::note_odr_objc_method_here) |
| 4057 | << D->isInstanceMethod() << Name; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4058 | |
| 4059 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | // FIXME: Any other bits we need to merge? |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4063 | return Importer.MapImported(D, FoundMethod); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4064 | } |
| 4065 | } |
| 4066 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4067 | Error Err = Error::success(); |
| 4068 | auto ToEndLoc = importChecked(Err, D->getEndLoc()); |
| 4069 | auto ToReturnType = importChecked(Err, D->getReturnType()); |
| 4070 | auto ToReturnTypeSourceInfo = |
| 4071 | importChecked(Err, D->getReturnTypeSourceInfo()); |
| 4072 | if (Err) |
| 4073 | return std::move(Err); |
| Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 4074 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4075 | ObjCMethodDecl *ToMethod; |
| 4076 | if (GetImportedOrCreateDecl( |
| Adrian Prantl | 2073dd2 | 2019-11-04 14:28:14 -0800 | [diff] [blame] | 4077 | ToMethod, D, Importer.getToContext(), Loc, ToEndLoc, |
| 4078 | Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC, |
| 4079 | D->isInstanceMethod(), D->isVariadic(), D->isPropertyAccessor(), |
| 4080 | D->isSynthesizedAccessorStub(), D->isImplicit(), D->isDefined(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4081 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 4082 | return ToMethod; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4083 | |
| 4084 | // FIXME: When we decide to merge method definitions, we'll need to |
| 4085 | // deal with implicit parameters. |
| 4086 | |
| 4087 | // Import the parameters |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4088 | SmallVector<ParmVarDecl *, 5> ToParams; |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 4089 | for (auto *FromP : D->parameters()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4090 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) |
| 4091 | ToParams.push_back(*ToPOrErr); |
| 4092 | else |
| 4093 | return ToPOrErr.takeError(); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4094 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4095 | |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4096 | // Set the parameters. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4097 | for (auto *ToParam : ToParams) { |
| 4098 | ToParam->setOwningFunction(ToMethod); |
| 4099 | ToMethod->addDeclInternal(ToParam); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4100 | } |
| Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 4101 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4102 | SmallVector<SourceLocation, 12> FromSelLocs; |
| 4103 | D->getSelectorLocs(FromSelLocs); |
| 4104 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); |
| 4105 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) |
| 4106 | return std::move(Err); |
| Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 4107 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4108 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4109 | |
| 4110 | ToMethod->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4111 | LexicalDC->addDeclInternal(ToMethod); |
| Raphael Isemann | 164e0fc | 2019-12-06 18:10:23 +0100 | [diff] [blame] | 4112 | |
| 4113 | // Implicit params are declared when Sema encounters the definition but this |
| 4114 | // never happens when the method is imported. Manually declare the implicit |
| 4115 | // params now that the MethodDecl knows its class interface. |
| 4116 | if (D->getSelfDecl()) |
| 4117 | ToMethod->createImplicitParams(Importer.getToContext(), |
| 4118 | ToMethod->getClassInterface()); |
| 4119 | |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4120 | return ToMethod; |
| 4121 | } |
| 4122 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4123 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4124 | // Import the major distinguishing characteristics of a category. |
| 4125 | DeclContext *DC, *LexicalDC; |
| 4126 | DeclarationName Name; |
| 4127 | SourceLocation Loc; |
| 4128 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4129 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4130 | return std::move(Err); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4131 | if (ToD) |
| 4132 | return ToD; |
| 4133 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4134 | Error Err = Error::success(); |
| 4135 | auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc()); |
| 4136 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 4137 | auto ToColonLoc = importChecked(Err, D->getColonLoc()); |
| 4138 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 4139 | if (Err) |
| 4140 | return std::move(Err); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4141 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4142 | ObjCTypeParamDecl *Result; |
| 4143 | if (GetImportedOrCreateDecl( |
| 4144 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4145 | ToVarianceLoc, D->getIndex(), |
| 4146 | ToLocation, Name.getAsIdentifierInfo(), |
| 4147 | ToColonLoc, ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4148 | return Result; |
| 4149 | |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4150 | Result->setLexicalDeclContext(LexicalDC); |
| 4151 | return Result; |
| 4152 | } |
| 4153 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4154 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4155 | // Import the major distinguishing characteristics of a category. |
| 4156 | DeclContext *DC, *LexicalDC; |
| 4157 | DeclarationName Name; |
| 4158 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4159 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4160 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4161 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4162 | if (ToD) |
| 4163 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4164 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4165 | ObjCInterfaceDecl *ToInterface; |
| 4166 | if (Error Err = importInto(ToInterface, D->getClassInterface())) |
| 4167 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4168 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4169 | // Determine if we've already encountered this category. |
| 4170 | ObjCCategoryDecl *MergeWithCategory |
| 4171 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 4172 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 4173 | if (!ToCategory) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4174 | |
| 4175 | Error Err = Error::success(); |
| 4176 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); |
| 4177 | auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc()); |
| 4178 | auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc()); |
| 4179 | auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc()); |
| 4180 | if (Err) |
| 4181 | return std::move(Err); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4182 | |
| 4183 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4184 | ToAtStartLoc, Loc, |
| 4185 | ToCategoryNameLoc, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4186 | Name.getAsIdentifierInfo(), ToInterface, |
| 4187 | /*TypeParamList=*/nullptr, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4188 | ToIvarLBraceLoc, |
| 4189 | ToIvarRBraceLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4190 | return ToCategory; |
| 4191 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4192 | ToCategory->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4193 | LexicalDC->addDeclInternal(ToCategory); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4194 | // Import the type parameter list after MapImported, to avoid |
| Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4195 | // loops when bringing in their DeclContext. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4196 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) |
| 4197 | ToCategory->setTypeParamList(*PListOrErr); |
| 4198 | else |
| 4199 | return PListOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4200 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4201 | // Import protocols |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4202 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4203 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4204 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 4205 | = D->protocol_loc_begin(); |
| 4206 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 4207 | FromProtoEnd = D->protocol_end(); |
| 4208 | FromProto != FromProtoEnd; |
| 4209 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4210 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4211 | Protocols.push_back(*ToProtoOrErr); |
| 4212 | else |
| 4213 | return ToProtoOrErr.takeError(); |
| 4214 | |
| 4215 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4216 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4217 | else |
| 4218 | return ToProtoLocOrErr.takeError(); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4219 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4220 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4221 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4222 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 4223 | ProtocolLocs.data(), Importer.getToContext()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4224 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4225 | } else { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4226 | Importer.MapImported(D, ToCategory); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4227 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4228 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4229 | // Import all of the members of this category. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4230 | if (Error Err = ImportDeclContext(D)) |
| 4231 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4232 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4233 | // If we have an implementation, import it as well. |
| 4234 | if (D->getImplementation()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4235 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = |
| 4236 | import(D->getImplementation())) |
| 4237 | ToCategory->setImplementation(*ToImplOrErr); |
| 4238 | else |
| 4239 | return ToImplOrErr.takeError(); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4240 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4241 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4242 | return ToCategory; |
| 4243 | } |
| 4244 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4245 | Error ASTNodeImporter::ImportDefinition( |
| 4246 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4247 | if (To->getDefinition()) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4248 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4249 | if (Error Err = ImportDeclContext(From)) |
| 4250 | return Err; |
| 4251 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4252 | } |
| 4253 | |
| 4254 | // Start the protocol definition |
| 4255 | To->startDefinition(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4256 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4257 | // Import protocols |
| 4258 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4259 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4260 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = |
| 4261 | From->protocol_loc_begin(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4262 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4263 | FromProtoEnd = From->protocol_end(); |
| 4264 | FromProto != FromProtoEnd; |
| 4265 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4266 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4267 | Protocols.push_back(*ToProtoOrErr); |
| 4268 | else |
| 4269 | return ToProtoOrErr.takeError(); |
| 4270 | |
| 4271 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4272 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4273 | else |
| 4274 | return ToProtoLocOrErr.takeError(); |
| 4275 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4276 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4277 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4278 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4279 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4280 | ProtocolLocs.data(), Importer.getToContext()); |
| 4281 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4282 | if (shouldForceImportDeclContext(Kind)) { |
| 4283 | // Import all of the members of this protocol. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4284 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4285 | return Err; |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4286 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4287 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4288 | } |
| 4289 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4290 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4291 | // 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] | 4292 | // from, but this particular declaration is not that definition, import the |
| 4293 | // definition and map to that. |
| 4294 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 4295 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4296 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4297 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4298 | else |
| 4299 | return ImportedDefOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4300 | } |
| 4301 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4302 | // Import the major distinguishing characteristics of a protocol. |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4303 | DeclContext *DC, *LexicalDC; |
| 4304 | DeclarationName Name; |
| 4305 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4306 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4307 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4308 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4309 | if (ToD) |
| 4310 | return ToD; |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4311 | |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4312 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4313 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4314 | for (auto *FoundDecl : FoundDecls) { |
| 4315 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4316 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4317 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4318 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4319 | break; |
| 4320 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4321 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4322 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4323 | if (!ToProto) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4324 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4325 | if (!ToAtBeginLocOrErr) |
| 4326 | return ToAtBeginLocOrErr.takeError(); |
| 4327 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4328 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 4329 | Name.getAsIdentifierInfo(), Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4330 | *ToAtBeginLocOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4331 | /*PrevDecl=*/nullptr)) |
| 4332 | return ToProto; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4333 | ToProto->setLexicalDeclContext(LexicalDC); |
| 4334 | LexicalDC->addDeclInternal(ToProto); |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4335 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4336 | |
| 4337 | Importer.MapImported(D, ToProto); |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4338 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4339 | if (D->isThisDeclarationADefinition()) |
| 4340 | if (Error Err = ImportDefinition(D, ToProto)) |
| 4341 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4342 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4343 | return ToProto; |
| 4344 | } |
| 4345 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4346 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 4347 | DeclContext *DC, *LexicalDC; |
| 4348 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4349 | return std::move(Err); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4350 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4351 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); |
| 4352 | if (!ExternLocOrErr) |
| 4353 | return ExternLocOrErr.takeError(); |
| 4354 | |
| 4355 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); |
| 4356 | if (!LangLocOrErr) |
| 4357 | return LangLocOrErr.takeError(); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4358 | |
| 4359 | bool HasBraces = D->hasBraces(); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4360 | |
| 4361 | LinkageSpecDecl *ToLinkageSpec; |
| 4362 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4363 | *ExternLocOrErr, *LangLocOrErr, |
| 4364 | D->getLanguage(), HasBraces)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4365 | return ToLinkageSpec; |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4366 | |
| 4367 | if (HasBraces) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4368 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 4369 | if (!RBraceLocOrErr) |
| 4370 | return RBraceLocOrErr.takeError(); |
| 4371 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4372 | } |
| 4373 | |
| 4374 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 4375 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 4376 | |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4377 | return ToLinkageSpec; |
| 4378 | } |
| 4379 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4380 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4381 | DeclContext *DC, *LexicalDC; |
| 4382 | DeclarationName Name; |
| 4383 | SourceLocation Loc; |
| 4384 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4385 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4386 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4387 | if (ToD) |
| 4388 | return ToD; |
| 4389 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4390 | Error Err = Error::success(); |
| 4391 | auto ToLoc = importChecked(Err, D->getNameInfo().getLoc()); |
| 4392 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); |
| 4393 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 4394 | if (Err) |
| 4395 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4396 | |
| 4397 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4398 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4399 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4400 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4401 | UsingDecl *ToUsing; |
| 4402 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4403 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4404 | D->hasTypename())) |
| 4405 | return ToUsing; |
| 4406 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4407 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4408 | LexicalDC->addDeclInternal(ToUsing); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4409 | |
| 4410 | if (NamedDecl *FromPattern = |
| 4411 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4412 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) |
| 4413 | Importer.getToContext().setInstantiatedFromUsingDecl( |
| 4414 | ToUsing, *ToPatternOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4415 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4416 | return ToPatternOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4417 | } |
| 4418 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4419 | for (UsingShadowDecl *FromShadow : D->shadows()) { |
| 4420 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) |
| 4421 | ToUsing->addShadowDecl(*ToShadowOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4422 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4423 | // FIXME: We return error here but the definition is already created |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4424 | // and available with lookups. How to fix this?.. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4425 | return ToShadowOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4426 | } |
| 4427 | return ToUsing; |
| 4428 | } |
| 4429 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4430 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4431 | DeclContext *DC, *LexicalDC; |
| 4432 | DeclarationName Name; |
| 4433 | SourceLocation Loc; |
| 4434 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4435 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4436 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4437 | if (ToD) |
| 4438 | return ToD; |
| 4439 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4440 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); |
| 4441 | if (!ToUsingOrErr) |
| 4442 | return ToUsingOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4443 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4444 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); |
| 4445 | if (!ToTargetOrErr) |
| 4446 | return ToTargetOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4447 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4448 | UsingShadowDecl *ToShadow; |
| 4449 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4450 | *ToUsingOrErr, *ToTargetOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4451 | return ToShadow; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4452 | |
| 4453 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 4454 | ToShadow->setAccess(D->getAccess()); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4455 | |
| 4456 | if (UsingShadowDecl *FromPattern = |
| 4457 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4458 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) |
| 4459 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( |
| 4460 | ToShadow, *ToPatternOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4461 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4462 | // FIXME: We return error here but the definition is already created |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4463 | // and available with lookups. How to fix this?.. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4464 | return ToPatternOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4465 | } |
| 4466 | |
| 4467 | LexicalDC->addDeclInternal(ToShadow); |
| 4468 | |
| 4469 | return ToShadow; |
| 4470 | } |
| 4471 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4472 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4473 | DeclContext *DC, *LexicalDC; |
| 4474 | DeclarationName Name; |
| 4475 | SourceLocation Loc; |
| 4476 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4477 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4478 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4479 | if (ToD) |
| 4480 | return ToD; |
| 4481 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4482 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); |
| 4483 | if (!ToComAncestorOrErr) |
| 4484 | return ToComAncestorOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4485 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4486 | Error Err = Error::success(); |
| 4487 | auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace()); |
| 4488 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); |
| 4489 | auto ToNamespaceKeyLocation = |
| 4490 | importChecked(Err, D->getNamespaceKeyLocation()); |
| 4491 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 4492 | auto ToIdentLocation = importChecked(Err, D->getIdentLocation()); |
| 4493 | if (Err) |
| 4494 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4495 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4496 | UsingDirectiveDecl *ToUsingDir; |
| 4497 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4498 | ToUsingLoc, |
| 4499 | ToNamespaceKeyLocation, |
| 4500 | ToQualifierLoc, |
| 4501 | ToIdentLocation, |
| 4502 | ToNominatedNamespace, *ToComAncestorOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4503 | return ToUsingDir; |
| 4504 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4505 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 4506 | LexicalDC->addDeclInternal(ToUsingDir); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4507 | |
| 4508 | return ToUsingDir; |
| 4509 | } |
| 4510 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4511 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4512 | UnresolvedUsingValueDecl *D) { |
| 4513 | DeclContext *DC, *LexicalDC; |
| 4514 | DeclarationName Name; |
| 4515 | SourceLocation Loc; |
| 4516 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4517 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4518 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4519 | if (ToD) |
| 4520 | return ToD; |
| 4521 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4522 | Error Err = Error::success(); |
| 4523 | auto ToLoc = importChecked(Err, D->getNameInfo().getLoc()); |
| 4524 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); |
| 4525 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 4526 | auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc()); |
| 4527 | if (Err) |
| 4528 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4529 | |
| 4530 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4531 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4532 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4533 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4534 | UnresolvedUsingValueDecl *ToUsingValue; |
| 4535 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4536 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| 4537 | ToEllipsisLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4538 | return ToUsingValue; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4539 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4540 | ToUsingValue->setAccess(D->getAccess()); |
| 4541 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 4542 | LexicalDC->addDeclInternal(ToUsingValue); |
| 4543 | |
| 4544 | return ToUsingValue; |
| 4545 | } |
| 4546 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4547 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4548 | UnresolvedUsingTypenameDecl *D) { |
| 4549 | DeclContext *DC, *LexicalDC; |
| 4550 | DeclarationName Name; |
| 4551 | SourceLocation Loc; |
| 4552 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4553 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4554 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4555 | if (ToD) |
| 4556 | return ToD; |
| 4557 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4558 | Error Err = Error::success(); |
| 4559 | auto ToUsingLoc = importChecked(Err, D->getUsingLoc()); |
| 4560 | auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc()); |
| 4561 | auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc()); |
| 4562 | auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc()); |
| 4563 | if (Err) |
| 4564 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4565 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4566 | UnresolvedUsingTypenameDecl *ToUsing; |
| 4567 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4568 | ToUsingLoc, ToTypenameLoc, |
| 4569 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4570 | return ToUsing; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4571 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4572 | ToUsing->setAccess(D->getAccess()); |
| 4573 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4574 | LexicalDC->addDeclInternal(ToUsing); |
| 4575 | |
| 4576 | return ToUsing; |
| 4577 | } |
| 4578 | |
| Raphael Isemann | ba7bde6 | 2019-10-30 14:50:35 +0100 | [diff] [blame] | 4579 | ExpectedDecl ASTNodeImporter::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) { |
| 4580 | Decl* ToD = nullptr; |
| 4581 | switch (D->getBuiltinTemplateKind()) { |
| 4582 | case BuiltinTemplateKind::BTK__make_integer_seq: |
| 4583 | ToD = Importer.getToContext().getMakeIntegerSeqDecl(); |
| 4584 | break; |
| 4585 | case BuiltinTemplateKind::BTK__type_pack_element: |
| 4586 | ToD = Importer.getToContext().getTypePackElementDecl(); |
| 4587 | break; |
| 4588 | } |
| 4589 | assert(ToD && "BuiltinTemplateDecl of unsupported kind!"); |
| 4590 | Importer.MapImported(D, ToD); |
| 4591 | return ToD; |
| 4592 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4593 | |
| 4594 | Error ASTNodeImporter::ImportDefinition( |
| 4595 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4596 | if (To->getDefinition()) { |
| 4597 | // Check consistency of superclass. |
| 4598 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 4599 | if (FromSuper) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4600 | if (auto FromSuperOrErr = import(FromSuper)) |
| 4601 | FromSuper = *FromSuperOrErr; |
| 4602 | else |
| 4603 | return FromSuperOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4604 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4605 | |
| 4606 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4607 | if ((bool)FromSuper != (bool)ToSuper || |
| 4608 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4609 | Importer.ToDiag(To->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4610 | diag::warn_odr_objc_superclass_inconsistent) |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4611 | << To->getDeclName(); |
| 4612 | if (ToSuper) |
| 4613 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 4614 | << To->getSuperClass()->getDeclName(); |
| 4615 | else |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4616 | Importer.ToDiag(To->getLocation(), |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4617 | diag::note_odr_objc_missing_superclass); |
| 4618 | if (From->getSuperClass()) |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4619 | Importer.FromDiag(From->getSuperClassLoc(), |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4620 | diag::note_odr_objc_superclass) |
| 4621 | << From->getSuperClass()->getDeclName(); |
| 4622 | else |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4623 | Importer.FromDiag(From->getLocation(), |
| 4624 | diag::note_odr_objc_missing_superclass); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4625 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4626 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4627 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4628 | if (Error Err = ImportDeclContext(From)) |
| 4629 | return Err; |
| 4630 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4631 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4632 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4633 | // Start the definition. |
| 4634 | To->startDefinition(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4635 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4636 | // If this class has a superclass, import it. |
| 4637 | if (From->getSuperClass()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4638 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) |
| 4639 | To->setSuperClass(*SuperTInfoOrErr); |
| 4640 | else |
| 4641 | return SuperTInfoOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4642 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4643 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4644 | // Import protocols |
| 4645 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4646 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4647 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = |
| 4648 | From->protocol_loc_begin(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4649 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4650 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4651 | FromProtoEnd = From->protocol_end(); |
| 4652 | FromProto != FromProtoEnd; |
| 4653 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4654 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4655 | Protocols.push_back(*ToProtoOrErr); |
| 4656 | else |
| 4657 | return ToProtoOrErr.takeError(); |
| 4658 | |
| 4659 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4660 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4661 | else |
| 4662 | return ToProtoLocOrErr.takeError(); |
| 4663 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4664 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4665 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4666 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4667 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4668 | ProtocolLocs.data(), Importer.getToContext()); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4669 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4670 | // Import categories. When the categories themselves are imported, they'll |
| 4671 | // hook themselves into this interface. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4672 | for (auto *Cat : From->known_categories()) { |
| 4673 | auto ToCatOrErr = import(Cat); |
| 4674 | if (!ToCatOrErr) |
| 4675 | return ToCatOrErr.takeError(); |
| 4676 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4677 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4678 | // If we have an @implementation, import it as well. |
| 4679 | if (From->getImplementation()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4680 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = |
| 4681 | import(From->getImplementation())) |
| 4682 | To->setImplementation(*ToImplOrErr); |
| 4683 | else |
| 4684 | return ToImplOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4685 | } |
| 4686 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4687 | if (shouldForceImportDeclContext(Kind)) { |
| 4688 | // Import all of the members of this class. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4689 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4690 | return Err; |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4691 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4692 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4693 | } |
| 4694 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4695 | Expected<ObjCTypeParamList *> |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4696 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 4697 | if (!list) |
| 4698 | return nullptr; |
| 4699 | |
| 4700 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4701 | for (auto *fromTypeParam : *list) { |
| 4702 | if (auto toTypeParamOrErr = import(fromTypeParam)) |
| 4703 | toTypeParams.push_back(*toTypeParamOrErr); |
| 4704 | else |
| 4705 | return toTypeParamOrErr.takeError(); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4706 | } |
| 4707 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4708 | auto LAngleLocOrErr = import(list->getLAngleLoc()); |
| 4709 | if (!LAngleLocOrErr) |
| 4710 | return LAngleLocOrErr.takeError(); |
| 4711 | |
| 4712 | auto RAngleLocOrErr = import(list->getRAngleLoc()); |
| 4713 | if (!RAngleLocOrErr) |
| 4714 | return RAngleLocOrErr.takeError(); |
| 4715 | |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4716 | return ObjCTypeParamList::create(Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4717 | *LAngleLocOrErr, |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4718 | toTypeParams, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4719 | *RAngleLocOrErr); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4720 | } |
| 4721 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4722 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4723 | // If this class has a definition in the translation unit we're coming from, |
| 4724 | // but this particular declaration is not that definition, import the |
| 4725 | // definition and map to that. |
| 4726 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 4727 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4728 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4729 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4730 | else |
| 4731 | return ImportedDefOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4732 | } |
| 4733 | |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4734 | // Import the major distinguishing characteristics of an @interface. |
| 4735 | DeclContext *DC, *LexicalDC; |
| 4736 | DeclarationName Name; |
| 4737 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4738 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4739 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4740 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4741 | if (ToD) |
| 4742 | return ToD; |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4743 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4744 | // Look for an existing interface with the same name. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4745 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4746 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4747 | for (auto *FoundDecl : FoundDecls) { |
| 4748 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4749 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4750 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4751 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4752 | break; |
| 4753 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4754 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4755 | // Create an interface declaration, if one does not already exist. |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4756 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4757 | if (!ToIface) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4758 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4759 | if (!AtBeginLocOrErr) |
| 4760 | return AtBeginLocOrErr.takeError(); |
| 4761 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4762 | if (GetImportedOrCreateDecl( |
| 4763 | ToIface, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4764 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4765 | /*TypeParamList=*/nullptr, |
| 4766 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 4767 | return ToIface; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4768 | ToIface->setLexicalDeclContext(LexicalDC); |
| 4769 | LexicalDC->addDeclInternal(ToIface); |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4770 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4771 | Importer.MapImported(D, ToIface); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4772 | // Import the type parameter list after MapImported, to avoid |
| Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4773 | // loops when bringing in their DeclContext. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4774 | if (auto ToPListOrErr = |
| 4775 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) |
| 4776 | ToIface->setTypeParamList(*ToPListOrErr); |
| 4777 | else |
| 4778 | return ToPListOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4779 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4780 | if (D->isThisDeclarationADefinition()) |
| 4781 | if (Error Err = ImportDefinition(D, ToIface)) |
| 4782 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4783 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4784 | return ToIface; |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4785 | } |
| 4786 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4787 | ExpectedDecl |
| 4788 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 4789 | ObjCCategoryDecl *Category; |
| 4790 | if (Error Err = importInto(Category, D->getCategoryDecl())) |
| 4791 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4792 | |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4793 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4794 | if (!ToImpl) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4795 | DeclContext *DC, *LexicalDC; |
| 4796 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4797 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4798 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4799 | Error Err = Error::success(); |
| 4800 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 4801 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); |
| 4802 | auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc()); |
| 4803 | if (Err) |
| 4804 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4805 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4806 | if (GetImportedOrCreateDecl( |
| 4807 | ToImpl, D, Importer.getToContext(), DC, |
| 4808 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4809 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4810 | return ToImpl; |
| 4811 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4812 | ToImpl->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4813 | LexicalDC->addDeclInternal(ToImpl); |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4814 | Category->setImplementation(ToImpl); |
| 4815 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4816 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4817 | Importer.MapImported(D, ToImpl); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4818 | if (Error Err = ImportDeclContext(D)) |
| 4819 | return std::move(Err); |
| 4820 | |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4821 | return ToImpl; |
| 4822 | } |
| 4823 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4824 | ExpectedDecl |
| 4825 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4826 | // Find the corresponding interface. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4827 | ObjCInterfaceDecl *Iface; |
| 4828 | if (Error Err = importInto(Iface, D->getClassInterface())) |
| 4829 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4830 | |
| 4831 | // Import the superclass, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4832 | ObjCInterfaceDecl *Super; |
| 4833 | if (Error Err = importInto(Super, D->getSuperClass())) |
| 4834 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4835 | |
| 4836 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4837 | if (!Impl) { |
| 4838 | // We haven't imported an implementation yet. Create a new @implementation |
| 4839 | // now. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4840 | DeclContext *DC, *LexicalDC; |
| 4841 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4842 | return std::move(Err); |
| 4843 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4844 | Error Err = Error::success(); |
| 4845 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 4846 | auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc()); |
| 4847 | auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc()); |
| 4848 | auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc()); |
| 4849 | auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc()); |
| 4850 | if (Err) |
| 4851 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4852 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4853 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4854 | DC, Iface, Super, |
| 4855 | ToLocation, |
| 4856 | ToAtStartLoc, |
| 4857 | ToSuperClassLoc, |
| 4858 | ToIvarLBraceLoc, |
| 4859 | ToIvarRBraceLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4860 | return Impl; |
| 4861 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4862 | Impl->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4863 | |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4864 | // Associate the implementation with the class it implements. |
| 4865 | Iface->setImplementation(Impl); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4866 | Importer.MapImported(D, Iface->getImplementation()); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4867 | } else { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4868 | Importer.MapImported(D, Iface->getImplementation()); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4869 | |
| 4870 | // Verify that the existing @implementation has the same superclass. |
| 4871 | if ((Super && !Impl->getSuperClass()) || |
| 4872 | (!Super && Impl->getSuperClass()) || |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4873 | (Super && Impl->getSuperClass() && |
| 4874 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4875 | Impl->getSuperClass()))) { |
| 4876 | Importer.ToDiag(Impl->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4877 | diag::warn_odr_objc_superclass_inconsistent) |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4878 | << Iface->getDeclName(); |
| 4879 | // FIXME: It would be nice to have the location of the superclass |
| 4880 | // below. |
| 4881 | if (Impl->getSuperClass()) |
| 4882 | Importer.ToDiag(Impl->getLocation(), |
| 4883 | diag::note_odr_objc_superclass) |
| 4884 | << Impl->getSuperClass()->getDeclName(); |
| 4885 | else |
| 4886 | Importer.ToDiag(Impl->getLocation(), |
| 4887 | diag::note_odr_objc_missing_superclass); |
| 4888 | if (D->getSuperClass()) |
| 4889 | Importer.FromDiag(D->getLocation(), |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4890 | diag::note_odr_objc_superclass) |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4891 | << D->getSuperClass()->getDeclName(); |
| 4892 | else |
| 4893 | Importer.FromDiag(D->getLocation(), |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4894 | diag::note_odr_objc_missing_superclass); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4895 | |
| 4896 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4897 | } |
| 4898 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4899 | |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4900 | // Import all of the members of this @implementation. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4901 | if (Error Err = ImportDeclContext(D)) |
| 4902 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4903 | |
| 4904 | return Impl; |
| 4905 | } |
| 4906 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4907 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4908 | // Import the major distinguishing characteristics of an @property. |
| 4909 | DeclContext *DC, *LexicalDC; |
| 4910 | DeclarationName Name; |
| 4911 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4912 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4913 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4914 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4915 | if (ToD) |
| 4916 | return ToD; |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4917 | |
| 4918 | // Check whether we have already imported this property. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4919 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4920 | for (auto *FoundDecl : FoundDecls) { |
| 4921 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4922 | // Check property types. |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4923 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4924 | FoundProp->getType())) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4925 | Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent) |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4926 | << Name << D->getType() << FoundProp->getType(); |
| 4927 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4928 | << FoundProp->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4929 | |
| 4930 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4931 | } |
| 4932 | |
| 4933 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4934 | |
| 4935 | // Consider these properties to be equivalent. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4936 | Importer.MapImported(D, FoundProp); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4937 | return FoundProp; |
| 4938 | } |
| 4939 | } |
| 4940 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4941 | Error Err = Error::success(); |
| 4942 | auto ToType = importChecked(Err, D->getType()); |
| 4943 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 4944 | auto ToAtLoc = importChecked(Err, D->getAtLoc()); |
| 4945 | auto ToLParenLoc = importChecked(Err, D->getLParenLoc()); |
| 4946 | if (Err) |
| 4947 | return std::move(Err); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4948 | |
| 4949 | // Create the new property. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4950 | ObjCPropertyDecl *ToProperty; |
| 4951 | if (GetImportedOrCreateDecl( |
| 4952 | ToProperty, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4953 | Name.getAsIdentifierInfo(), ToAtLoc, |
| 4954 | ToLParenLoc, ToType, |
| 4955 | ToTypeSourceInfo, D->getPropertyImplementation())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4956 | return ToProperty; |
| 4957 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 4958 | auto ToGetterName = importChecked(Err, D->getGetterName()); |
| 4959 | auto ToSetterName = importChecked(Err, D->getSetterName()); |
| 4960 | auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc()); |
| 4961 | auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc()); |
| 4962 | auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl()); |
| 4963 | auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl()); |
| 4964 | auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl()); |
| 4965 | if (Err) |
| 4966 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4967 | |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4968 | ToProperty->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4969 | LexicalDC->addDeclInternal(ToProperty); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4970 | |
| 4971 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
| Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4972 | ToProperty->setPropertyAttributesAsWritten( |
| 4973 | D->getPropertyAttributesAsWritten()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4974 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); |
| 4975 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); |
| 4976 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); |
| 4977 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); |
| 4978 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4979 | return ToProperty; |
| 4980 | } |
| 4981 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4982 | ExpectedDecl |
| 4983 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 4984 | ObjCPropertyDecl *Property; |
| 4985 | if (Error Err = importInto(Property, D->getPropertyDecl())) |
| 4986 | return std::move(Err); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4987 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4988 | DeclContext *DC, *LexicalDC; |
| 4989 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4990 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4991 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4992 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4993 | |
| 4994 | // Import the ivar (for an @synthesize). |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4995 | ObjCIvarDecl *Ivar = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4996 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) |
| 4997 | return std::move(Err); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4998 | |
| 4999 | ObjCPropertyImplDecl *ToImpl |
| Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 5000 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 5001 | Property->getQueryKind()); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5002 | if (!ToImpl) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5003 | |
| 5004 | Error Err = Error::success(); |
| 5005 | auto ToBeginLoc = importChecked(Err, D->getBeginLoc()); |
| 5006 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 5007 | auto ToPropertyIvarDeclLoc = |
| 5008 | importChecked(Err, D->getPropertyIvarDeclLoc()); |
| 5009 | if (Err) |
| 5010 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5011 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5012 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5013 | ToBeginLoc, |
| 5014 | ToLocation, Property, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5015 | D->getPropertyImplementation(), Ivar, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5016 | ToPropertyIvarDeclLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5017 | return ToImpl; |
| 5018 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5019 | ToImpl->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 5020 | LexicalDC->addDeclInternal(ToImpl); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5021 | } else { |
| 5022 | // Check that we have the same kind of property implementation (@synthesize |
| 5023 | // vs. @dynamic). |
| 5024 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5025 | Importer.ToDiag(ToImpl->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 5026 | diag::warn_odr_objc_property_impl_kind_inconsistent) |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5027 | << Property->getDeclName() |
| 5028 | << (ToImpl->getPropertyImplementation() |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5029 | == ObjCPropertyImplDecl::Dynamic); |
| 5030 | Importer.FromDiag(D->getLocation(), |
| 5031 | diag::note_odr_objc_property_impl_kind) |
| 5032 | << D->getPropertyDecl()->getDeclName() |
| 5033 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5034 | |
| 5035 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5036 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5037 | |
| 5038 | // For @synthesize, check that we have the same |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5039 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 5040 | Ivar != ToImpl->getPropertyIvarDecl()) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5041 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 5042 | diag::warn_odr_objc_synthesize_ivar_inconsistent) |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5043 | << Property->getDeclName() |
| 5044 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 5045 | << Ivar->getDeclName(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5046 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5047 | diag::note_odr_objc_synthesize_ivar_here) |
| 5048 | << D->getPropertyIvarDecl()->getDeclName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5049 | |
| 5050 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5051 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5052 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5053 | // Merge the existing implementation with the new implementation. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5054 | Importer.MapImported(D, ToImpl); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5055 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5056 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5057 | return ToImpl; |
| 5058 | } |
| 5059 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5060 | ExpectedDecl |
| 5061 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5062 | // For template arguments, we adopt the translation unit as our declaration |
| 5063 | // context. This context will be fixed when the actual template declaration |
| 5064 | // is created. |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5065 | |
| Saar Raz | ff1e0fc | 2020-01-15 02:48:42 +0200 | [diff] [blame] | 5066 | // FIXME: Import default argument and constraint expression. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5067 | |
| 5068 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5069 | if (!BeginLocOrErr) |
| 5070 | return BeginLocOrErr.takeError(); |
| 5071 | |
| 5072 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 5073 | if (!LocationOrErr) |
| 5074 | return LocationOrErr.takeError(); |
| 5075 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5076 | TemplateTypeParmDecl *ToD = nullptr; |
| Saar Raz | ff1e0fc | 2020-01-15 02:48:42 +0200 | [diff] [blame] | 5077 | if (GetImportedOrCreateDecl( |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5078 | ToD, D, Importer.getToContext(), |
| 5079 | Importer.getToContext().getTranslationUnitDecl(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5080 | *BeginLocOrErr, *LocationOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5081 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| Saar Raz | ff1e0fc | 2020-01-15 02:48:42 +0200 | [diff] [blame] | 5082 | D->wasDeclaredWithTypename(), D->isParameterPack(), |
| 5083 | D->hasTypeConstraint())) |
| 5084 | return ToD; |
| 5085 | |
| 5086 | // Import the type-constraint |
| 5087 | if (const TypeConstraint *TC = D->getTypeConstraint()) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5088 | |
| 5089 | Error Err = Error::success(); |
| 5090 | auto ToNNS = importChecked(Err, TC->getNestedNameSpecifierLoc()); |
| 5091 | auto ToName = importChecked(Err, TC->getConceptNameInfo().getName()); |
| 5092 | auto ToNameLoc = importChecked(Err, TC->getConceptNameInfo().getLoc()); |
| 5093 | auto ToFoundDecl = importChecked(Err, TC->getFoundDecl()); |
| 5094 | auto ToNamedConcept = importChecked(Err, TC->getNamedConcept()); |
| 5095 | auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint()); |
| 5096 | if (Err) |
| 5097 | return std::move(Err); |
| Saar Raz | ff1e0fc | 2020-01-15 02:48:42 +0200 | [diff] [blame] | 5098 | |
| 5099 | TemplateArgumentListInfo ToTAInfo; |
| 5100 | const auto *ASTTemplateArgs = TC->getTemplateArgsAsWritten(); |
| 5101 | if (ASTTemplateArgs) |
| 5102 | if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, |
| 5103 | ToTAInfo)) |
| 5104 | return std::move(Err); |
| 5105 | |
| 5106 | ToD->setTypeConstraint(ToNNS, DeclarationNameInfo(ToName, ToNameLoc), |
| 5107 | ToFoundDecl, ToNamedConcept, |
| 5108 | ASTTemplateArgs ? |
| 5109 | ASTTemplateArgumentListInfo::Create(Importer.getToContext(), |
| 5110 | ToTAInfo) : nullptr, |
| 5111 | ToIDC); |
| 5112 | } |
| 5113 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5114 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5115 | } |
| 5116 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5117 | ExpectedDecl |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5118 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5119 | |
| 5120 | Error Err = Error::success(); |
| 5121 | auto ToDeclName = importChecked(Err, D->getDeclName()); |
| 5122 | auto ToLocation = importChecked(Err, D->getLocation()); |
| 5123 | auto ToType = importChecked(Err, D->getType()); |
| 5124 | auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo()); |
| 5125 | auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart()); |
| 5126 | if (Err) |
| 5127 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5128 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5129 | // FIXME: Import default argument. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5130 | |
| 5131 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 5132 | (void)GetImportedOrCreateDecl( |
| 5133 | ToD, D, Importer.getToContext(), |
| 5134 | Importer.getToContext().getTranslationUnitDecl(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5135 | ToInnerLocStart, ToLocation, D->getDepth(), |
| 5136 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, |
| 5137 | D->isParameterPack(), ToTypeSourceInfo); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5138 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5139 | } |
| 5140 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5141 | ExpectedDecl |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5142 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 5143 | // Import the name of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5144 | auto NameOrErr = import(D->getDeclName()); |
| 5145 | if (!NameOrErr) |
| 5146 | return NameOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5147 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5148 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5149 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 5150 | if (!LocationOrErr) |
| 5151 | return LocationOrErr.takeError(); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5152 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5153 | // Import template parameters. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5154 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5155 | if (!TemplateParamsOrErr) |
| 5156 | return TemplateParamsOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5157 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5158 | // FIXME: Import default argument. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5159 | |
| 5160 | TemplateTemplateParmDecl *ToD = nullptr; |
| 5161 | (void)GetImportedOrCreateDecl( |
| 5162 | ToD, D, Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5163 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, |
| 5164 | D->getDepth(), D->getPosition(), D->isParameterPack(), |
| 5165 | (*NameOrErr).getAsIdentifierInfo(), |
| 5166 | *TemplateParamsOrErr); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5167 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5168 | } |
| 5169 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5170 | // Returns the definition for a (forward) declaration of a TemplateDecl, if |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5171 | // it has any definition in the redecl chain. |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5172 | template <typename T> static auto getTemplateDefinition(T *D) -> T * { |
| 5173 | assert(D->getTemplatedDecl() && "Should be called on templates only"); |
| 5174 | auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5175 | if (!ToTemplatedDef) |
| 5176 | return nullptr; |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5177 | auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate(); |
| 5178 | return cast_or_null<T>(TemplateWithDef); |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5179 | } |
| 5180 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5181 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5182 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5183 | // Import the major distinguishing characteristics of this class template. |
| 5184 | DeclContext *DC, *LexicalDC; |
| 5185 | DeclarationName Name; |
| 5186 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5187 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5188 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5189 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5190 | if (ToD) |
| 5191 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5192 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5193 | ClassTemplateDecl *FoundByLookup = nullptr; |
| 5194 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5195 | // We may already have a template of the same name; try to find and match it. |
| 5196 | if (!DC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5197 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5198 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5199 | for (auto *FoundDecl : FoundDecls) { |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5200 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary | |
| 5201 | Decl::IDNS_TagFriend)) |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5202 | continue; |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5203 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5204 | Decl *Found = FoundDecl; |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5205 | auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found); |
| 5206 | if (FoundTemplate) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 5207 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D)) |
| Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 5208 | continue; |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5209 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5210 | if (IsStructuralMatch(D, FoundTemplate)) { |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5211 | ClassTemplateDecl *TemplateWithDef = |
| 5212 | getTemplateDefinition(FoundTemplate); |
| Balazs Keri | 2e16060 | 2019-08-12 10:07:38 +0000 | [diff] [blame] | 5213 | if (D->isThisDeclarationADefinition() && TemplateWithDef) |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5214 | return Importer.MapImported(D, TemplateWithDef); |
| Balazs Keri | 2e16060 | 2019-08-12 10:07:38 +0000 | [diff] [blame] | 5215 | if (!FoundByLookup) |
| 5216 | FoundByLookup = FoundTemplate; |
| 5217 | // Search in all matches because there may be multiple decl chains, |
| 5218 | // see ASTTests test ImportExistingFriendClassTemplateDef. |
| 5219 | continue; |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5220 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5221 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5222 | } |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5223 | } |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5224 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5225 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5226 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 5227 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), |
| 5228 | ConflictingDecls.size()); |
| 5229 | if (NameOrErr) |
| 5230 | Name = NameOrErr.get(); |
| 5231 | else |
| 5232 | return NameOrErr.takeError(); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5233 | } |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5234 | } |
| 5235 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5236 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 5237 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5238 | // Create the declaration that is being templated. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5239 | CXXRecordDecl *ToTemplated; |
| 5240 | if (Error Err = importInto(ToTemplated, FromTemplated)) |
| 5241 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5242 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5243 | // Create the class template declaration itself. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5244 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5245 | if (!TemplateParamsOrErr) |
| 5246 | return TemplateParamsOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5247 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5248 | ClassTemplateDecl *D2; |
| 5249 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5250 | *TemplateParamsOrErr, ToTemplated)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5251 | return D2; |
| 5252 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5253 | ToTemplated->setDescribedClassTemplate(D2); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5254 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5255 | D2->setAccess(D->getAccess()); |
| 5256 | D2->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5257 | |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 5258 | addDeclToContexts(D, D2); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5259 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5260 | if (FoundByLookup) { |
| 5261 | auto *Recent = |
| 5262 | const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5263 | |
| 5264 | // It is possible that during the import of the class template definition |
| 5265 | // we start the import of a fwd friend decl of the very same class template |
| 5266 | // and we add the fwd friend decl to the lookup table. But the ToTemplated |
| 5267 | // had been created earlier and by that time the lookup could not find |
| 5268 | // anything existing, so it has no previous decl. Later, (still during the |
| 5269 | // import of the fwd friend decl) we start to import the definition again |
| 5270 | // and this time the lookup finds the previous fwd friend class template. |
| 5271 | // In this case we must set up the previous decl for the templated decl. |
| 5272 | if (!ToTemplated->getPreviousDecl()) { |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5273 | assert(FoundByLookup->getTemplatedDecl() && |
| 5274 | "Found decl must have its templated decl set"); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5275 | CXXRecordDecl *PrevTemplated = |
| 5276 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5277 | if (ToTemplated != PrevTemplated) |
| 5278 | ToTemplated->setPreviousDecl(PrevTemplated); |
| 5279 | } |
| 5280 | |
| 5281 | D2->setPreviousDecl(Recent); |
| 5282 | } |
| 5283 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5284 | if (FromTemplated->isCompleteDefinition() && |
| 5285 | !ToTemplated->isCompleteDefinition()) { |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5286 | // FIXME: Import definition! |
| 5287 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5288 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5289 | return D2; |
| 5290 | } |
| 5291 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5292 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5293 | ClassTemplateSpecializationDecl *D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5294 | ClassTemplateDecl *ClassTemplate; |
| 5295 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) |
| 5296 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5297 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5298 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5299 | DeclContext *DC, *LexicalDC; |
| 5300 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5301 | return std::move(Err); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5302 | |
| 5303 | // Import template arguments. |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5304 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5305 | if (Error Err = ImportTemplateArguments( |
| 5306 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5307 | return std::move(Err); |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5308 | // Try to find an existing specialization with these template arguments and |
| 5309 | // template parameter list. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5310 | void *InsertPos = nullptr; |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5311 | ClassTemplateSpecializationDecl *PrevDecl = nullptr; |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5312 | ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 5313 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5314 | |
| 5315 | // Import template parameters. |
| 5316 | TemplateParameterList *ToTPList = nullptr; |
| 5317 | |
| 5318 | if (PartialSpec) { |
| 5319 | auto ToTPListOrErr = import(PartialSpec->getTemplateParameters()); |
| 5320 | if (!ToTPListOrErr) |
| 5321 | return ToTPListOrErr.takeError(); |
| 5322 | ToTPList = *ToTPListOrErr; |
| 5323 | PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs, |
| 5324 | *ToTPListOrErr, |
| 5325 | InsertPos); |
| 5326 | } else |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5327 | PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5328 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5329 | if (PrevDecl) { |
| 5330 | if (IsStructuralMatch(D, PrevDecl)) { |
| 5331 | if (D->isThisDeclarationADefinition() && PrevDecl->getDefinition()) { |
| 5332 | Importer.MapImported(D, PrevDecl->getDefinition()); |
| 5333 | // Import those default field initializers which have been |
| 5334 | // instantiated in the "From" context, but not in the "To" context. |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5335 | for (auto *FromField : D->fields()) { |
| 5336 | auto ToOrErr = import(FromField); |
| 5337 | if (!ToOrErr) |
| 5338 | return ToOrErr.takeError(); |
| 5339 | } |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5340 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5341 | // Import those methods which have been instantiated in the |
| 5342 | // "From" context, but not in the "To" context. |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5343 | for (CXXMethodDecl *FromM : D->methods()) { |
| 5344 | auto ToOrErr = import(FromM); |
| 5345 | if (!ToOrErr) |
| 5346 | return ToOrErr.takeError(); |
| 5347 | } |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5348 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5349 | // TODO Import instantiated default arguments. |
| 5350 | // TODO Import instantiated exception specifications. |
| 5351 | // |
| 5352 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint |
| 5353 | // what else could be fused during an AST merge. |
| 5354 | return PrevDecl; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5355 | } |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5356 | } else { // ODR violation. |
| 5357 | // FIXME HandleNameConflict |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 5358 | return make_error<ImportError>(ImportError::NameConflict); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5359 | } |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5360 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5361 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5362 | // Import the location of this declaration. |
| 5363 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5364 | if (!BeginLocOrErr) |
| 5365 | return BeginLocOrErr.takeError(); |
| 5366 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); |
| 5367 | if (!IdLocOrErr) |
| 5368 | return IdLocOrErr.takeError(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5369 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5370 | // Create the specialization. |
| 5371 | ClassTemplateSpecializationDecl *D2 = nullptr; |
| 5372 | if (PartialSpec) { |
| 5373 | // Import TemplateArgumentListInfo. |
| 5374 | TemplateArgumentListInfo ToTAInfo; |
| 5375 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 5376 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
| 5377 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5378 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5379 | QualType CanonInjType; |
| 5380 | if (Error Err = importInto( |
| 5381 | CanonInjType, PartialSpec->getInjectedSpecializationType())) |
| 5382 | return std::move(Err); |
| 5383 | CanonInjType = CanonInjType.getCanonicalType(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5384 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5385 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
| 5386 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5387 | *BeginLocOrErr, *IdLocOrErr, ToTPList, ClassTemplate, |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5388 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 5389 | ToTAInfo, CanonInjType, |
| 5390 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) |
| 5391 | return D2; |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5392 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5393 | // Update InsertPos, because preceding import calls may have invalidated |
| 5394 | // it by adding new specializations. |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5395 | auto *PartSpec2 = cast<ClassTemplatePartialSpecializationDecl>(D2); |
| 5396 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList, |
| 5397 | InsertPos)) |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5398 | // Add this partial specialization to the class template. |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5399 | ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5400 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5401 | } else { // Not a partial specialization. |
| 5402 | if (GetImportedOrCreateDecl( |
| 5403 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5404 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, |
| 5405 | PrevDecl)) |
| 5406 | return D2; |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5407 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5408 | // Update InsertPos, because preceding import calls may have invalidated |
| 5409 | // it by adding new specializations. |
| 5410 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) |
| 5411 | // Add this specialization to the class template. |
| 5412 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 5413 | } |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5414 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5415 | D2->setSpecializationKind(D->getSpecializationKind()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5416 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5417 | // Set the context of this specialization/instantiation. |
| 5418 | D2->setLexicalDeclContext(LexicalDC); |
| 5419 | |
| 5420 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 5421 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 5422 | LexicalDC->addDeclInternal(D2); |
| 5423 | } |
| 5424 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 5425 | if (auto BraceRangeOrErr = import(D->getBraceRange())) |
| 5426 | D2->setBraceRange(*BraceRangeOrErr); |
| 5427 | else |
| 5428 | return BraceRangeOrErr.takeError(); |
| 5429 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5430 | // Import the qualifier, if any. |
| 5431 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5432 | D2->setQualifierInfo(*LocOrErr); |
| 5433 | else |
| 5434 | return LocOrErr.takeError(); |
| 5435 | |
| 5436 | if (auto *TSI = D->getTypeAsWritten()) { |
| 5437 | if (auto TInfoOrErr = import(TSI)) |
| 5438 | D2->setTypeAsWritten(*TInfoOrErr); |
| 5439 | else |
| 5440 | return TInfoOrErr.takeError(); |
| 5441 | |
| 5442 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) |
| 5443 | D2->setTemplateKeywordLoc(*LocOrErr); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5444 | else |
| 5445 | return LocOrErr.takeError(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5446 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5447 | if (auto LocOrErr = import(D->getExternLoc())) |
| 5448 | D2->setExternLoc(*LocOrErr); |
| 5449 | else |
| 5450 | return LocOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5451 | } |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5452 | |
| 5453 | if (D->getPointOfInstantiation().isValid()) { |
| 5454 | if (auto POIOrErr = import(D->getPointOfInstantiation())) |
| 5455 | D2->setPointOfInstantiation(*POIOrErr); |
| 5456 | else |
| 5457 | return POIOrErr.takeError(); |
| 5458 | } |
| 5459 | |
| 5460 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 5461 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5462 | if (D->isCompleteDefinition()) |
| 5463 | if (Error Err = ImportDefinition(D, D2)) |
| 5464 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5465 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5466 | return D2; |
| 5467 | } |
| 5468 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5469 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5470 | // Import the major distinguishing characteristics of this variable template. |
| 5471 | DeclContext *DC, *LexicalDC; |
| 5472 | DeclarationName Name; |
| 5473 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5474 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5475 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5476 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5477 | if (ToD) |
| 5478 | return ToD; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5479 | |
| 5480 | // We may already have a template of the same name; try to find and match it. |
| 5481 | assert(!DC->isFunctionOrMethod() && |
| 5482 | "Variable templates cannot be declared at function scope"); |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 5483 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5484 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5485 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 5486 | VarTemplateDecl *FoundByLookup = nullptr; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5487 | for (auto *FoundDecl : FoundDecls) { |
| 5488 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5489 | continue; |
| 5490 | |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 5491 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) { |
| Balázs Kéri | 8d67bcf | 2020-03-09 11:01:48 +0100 | [diff] [blame] | 5492 | // Use the templated decl, some linkage flags are set only there. |
| 5493 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(), |
| 5494 | D->getTemplatedDecl())) |
| 5495 | continue; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5496 | if (IsStructuralMatch(D, FoundTemplate)) { |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 5497 | // The Decl in the "From" context has a definition, but in the |
| 5498 | // "To" context we already have a definition. |
| 5499 | VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate); |
| 5500 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 5501 | // FIXME Check for ODR error if the two definitions have |
| 5502 | // different initializers? |
| 5503 | return Importer.MapImported(D, FoundDef); |
| 5504 | |
| 5505 | FoundByLookup = FoundTemplate; |
| 5506 | break; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5507 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5508 | ConflictingDecls.push_back(FoundDecl); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5509 | } |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5510 | } |
| 5511 | |
| 5512 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5513 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 5514 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), |
| 5515 | ConflictingDecls.size()); |
| 5516 | if (NameOrErr) |
| 5517 | Name = NameOrErr.get(); |
| 5518 | else |
| 5519 | return NameOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5520 | } |
| 5521 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5522 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 5523 | |
| 5524 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5525 | // FIXME: Value not used? |
| 5526 | ExpectedType TypeOrErr = import(DTemplated->getType()); |
| 5527 | if (!TypeOrErr) |
| 5528 | return TypeOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5529 | |
| 5530 | // Create the declaration that is being templated. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5531 | VarDecl *ToTemplated; |
| 5532 | if (Error Err = importInto(ToTemplated, DTemplated)) |
| 5533 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5534 | |
| 5535 | // Create the variable template declaration itself. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5536 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5537 | if (!TemplateParamsOrErr) |
| 5538 | return TemplateParamsOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5539 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5540 | VarTemplateDecl *ToVarTD; |
| 5541 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5542 | Name, *TemplateParamsOrErr, ToTemplated)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5543 | return ToVarTD; |
| 5544 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5545 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5546 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5547 | ToVarTD->setAccess(D->getAccess()); |
| 5548 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 5549 | LexicalDC->addDeclInternal(ToVarTD); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5550 | |
| Balázs Kéri | 7b6168e | 2020-02-25 14:47:38 +0100 | [diff] [blame] | 5551 | if (FoundByLookup) { |
| 5552 | auto *Recent = |
| 5553 | const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5554 | if (!ToTemplated->getPreviousDecl()) { |
| 5555 | auto *PrevTemplated = |
| 5556 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5557 | if (ToTemplated != PrevTemplated) |
| 5558 | ToTemplated->setPreviousDecl(PrevTemplated); |
| 5559 | } |
| 5560 | ToVarTD->setPreviousDecl(Recent); |
| 5561 | } |
| 5562 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5563 | if (DTemplated->isThisDeclarationADefinition() && |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5564 | !ToTemplated->isThisDeclarationADefinition()) { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5565 | // FIXME: Import definition! |
| 5566 | } |
| 5567 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5568 | return ToVarTD; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5569 | } |
| 5570 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5571 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5572 | VarTemplateSpecializationDecl *D) { |
| 5573 | // If this record has a definition in the translation unit we're coming from, |
| 5574 | // but this particular declaration is not that definition, import the |
| 5575 | // definition and map to that. |
| 5576 | VarDecl *Definition = D->getDefinition(); |
| 5577 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5578 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5579 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5580 | else |
| 5581 | return ImportedDefOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5582 | } |
| 5583 | |
| Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 5584 | VarTemplateDecl *VarTemplate = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5585 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) |
| 5586 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5587 | |
| 5588 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5589 | DeclContext *DC, *LexicalDC; |
| 5590 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5591 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5592 | |
| 5593 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5594 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5595 | if (!BeginLocOrErr) |
| 5596 | return BeginLocOrErr.takeError(); |
| 5597 | |
| 5598 | auto IdLocOrErr = import(D->getLocation()); |
| 5599 | if (!IdLocOrErr) |
| 5600 | return IdLocOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5601 | |
| 5602 | // Import template arguments. |
| 5603 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5604 | if (Error Err = ImportTemplateArguments( |
| 5605 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5606 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5607 | |
| 5608 | // Try to find an existing specialization with these template arguments. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5609 | void *InsertPos = nullptr; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5610 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
| Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 5611 | TemplateArgs, InsertPos); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5612 | if (D2) { |
| 5613 | // We already have a variable template specialization with these template |
| 5614 | // arguments. |
| 5615 | |
| 5616 | // FIXME: Check for specialization vs. instantiation errors. |
| 5617 | |
| 5618 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 5619 | if (!D->isThisDeclarationADefinition() || |
| 5620 | IsStructuralMatch(D, FoundDef)) { |
| 5621 | // The record types structurally match, or the "from" translation |
| 5622 | // unit only had a forward declaration anyway; call it the same |
| 5623 | // variable. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5624 | return Importer.MapImported(D, FoundDef); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5625 | } |
| 5626 | } |
| 5627 | } else { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5628 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5629 | QualType T; |
| 5630 | if (Error Err = importInto(T, D->getType())) |
| 5631 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5632 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5633 | auto TInfoOrErr = import(D->getTypeSourceInfo()); |
| 5634 | if (!TInfoOrErr) |
| 5635 | return TInfoOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5636 | |
| 5637 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5638 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5639 | D->getTemplateArgsInfo(), ToTAInfo)) |
| 5640 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5641 | |
| 5642 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5643 | // Create a new specialization. |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5644 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 5645 | // Import TemplateArgumentListInfo |
| 5646 | TemplateArgumentListInfo ArgInfos; |
| 5647 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 5648 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5649 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5650 | *FromTAArgsAsWritten, ArgInfos)) |
| 5651 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5652 | |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5653 | auto ToTPListOrErr = import(FromPartial->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5654 | if (!ToTPListOrErr) |
| 5655 | return ToTPListOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5656 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5657 | PartVarSpecDecl *ToPartial; |
| 5658 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5659 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, |
| 5660 | VarTemplate, T, *TInfoOrErr, |
| 5661 | D->getStorageClass(), TemplateArgs, ArgInfos)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5662 | return ToPartial; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5663 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5664 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( |
| 5665 | FromPartial->getInstantiatedFromMember())) |
| 5666 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); |
| 5667 | else |
| 5668 | return ToInstOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5669 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5670 | if (FromPartial->isMemberSpecialization()) |
| 5671 | ToPartial->setMemberSpecialization(); |
| 5672 | |
| 5673 | D2 = ToPartial; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5674 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5675 | } else { // Full specialization |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5676 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, |
| 5677 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, |
| 5678 | T, *TInfoOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5679 | D->getStorageClass(), TemplateArgs)) |
| 5680 | return D2; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5681 | } |
| 5682 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5683 | if (D->getPointOfInstantiation().isValid()) { |
| 5684 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) |
| 5685 | D2->setPointOfInstantiation(*POIOrErr); |
| 5686 | else |
| 5687 | return POIOrErr.takeError(); |
| 5688 | } |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5689 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5690 | D2->setSpecializationKind(D->getSpecializationKind()); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5691 | D2->setTemplateArgsInfo(ToTAInfo); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5692 | |
| 5693 | // Add this specialization to the class template. |
| 5694 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 5695 | |
| 5696 | // Import the qualifier, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5697 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5698 | D2->setQualifierInfo(*LocOrErr); |
| 5699 | else |
| 5700 | return LocOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5701 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5702 | if (D->isConstexpr()) |
| 5703 | D2->setConstexpr(true); |
| 5704 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5705 | // Add the specialization to this context. |
| 5706 | D2->setLexicalDeclContext(LexicalDC); |
| 5707 | LexicalDC->addDeclInternal(D2); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5708 | |
| 5709 | D2->setAccess(D->getAccess()); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5710 | } |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5711 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5712 | if (Error Err = ImportInitializer(D, D2)) |
| 5713 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5714 | |
| 5715 | return D2; |
| 5716 | } |
| 5717 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5718 | ExpectedDecl |
| 5719 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5720 | DeclContext *DC, *LexicalDC; |
| 5721 | DeclarationName Name; |
| 5722 | SourceLocation Loc; |
| 5723 | NamedDecl *ToD; |
| 5724 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5725 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5726 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5727 | |
| 5728 | if (ToD) |
| 5729 | return ToD; |
| 5730 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5731 | const FunctionTemplateDecl *FoundByLookup = nullptr; |
| 5732 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5733 | // Try to find a function in our own ("to") context with the same name, same |
| 5734 | // type, and in the same context as the function we're importing. |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5735 | // FIXME Split this into a separate function. |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5736 | if (!LexicalDC->isFunctionOrMethod()) { |
| Gabor Marton | e331e63 | 2019-02-18 13:09:27 +0000 | [diff] [blame] | 5737 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5738 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5739 | for (auto *FoundDecl : FoundDecls) { |
| 5740 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5741 | continue; |
| 5742 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5743 | if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
| shafik | bf3f427 | 2020-02-20 12:28:46 -0800 | [diff] [blame] | 5744 | if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D)) |
| Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 5745 | continue; |
| 5746 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5747 | FunctionTemplateDecl *TemplateWithDef = |
| 5748 | getTemplateDefinition(FoundTemplate); |
| 5749 | if (D->isThisDeclarationADefinition() && TemplateWithDef) |
| 5750 | return Importer.MapImported(D, TemplateWithDef); |
| 5751 | |
| 5752 | FoundByLookup = FoundTemplate; |
| 5753 | break; |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5754 | // TODO: handle conflicting names |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5755 | } |
| 5756 | } |
| 5757 | } |
| 5758 | } |
| 5759 | |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5760 | auto ParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5761 | if (!ParamsOrErr) |
| 5762 | return ParamsOrErr.takeError(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5763 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5764 | FunctionDecl *TemplatedFD; |
| 5765 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) |
| 5766 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5767 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5768 | FunctionTemplateDecl *ToFunc; |
| 5769 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5770 | *ParamsOrErr, TemplatedFD)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5771 | return ToFunc; |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5772 | |
| 5773 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5774 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5775 | ToFunc->setAccess(D->getAccess()); |
| 5776 | ToFunc->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5777 | LexicalDC->addDeclInternal(ToFunc); |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5778 | |
| 5779 | if (FoundByLookup) { |
| 5780 | auto *Recent = |
| 5781 | const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5782 | if (!TemplatedFD->getPreviousDecl()) { |
| 5783 | assert(FoundByLookup->getTemplatedDecl() && |
| 5784 | "Found decl must have its templated decl set"); |
| 5785 | auto *PrevTemplated = |
| 5786 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5787 | if (TemplatedFD != PrevTemplated) |
| 5788 | TemplatedFD->setPreviousDecl(PrevTemplated); |
| 5789 | } |
| 5790 | ToFunc->setPreviousDecl(Recent); |
| 5791 | } |
| 5792 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5793 | return ToFunc; |
| 5794 | } |
| 5795 | |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5796 | //---------------------------------------------------------------------------- |
| 5797 | // Import Statements |
| 5798 | //---------------------------------------------------------------------------- |
| 5799 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5800 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5801 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) |
| 5802 | << S->getStmtClassName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5803 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5804 | } |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5805 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5806 | |
| 5807 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 5808 | if (Importer.returnWithErrorInTest()) |
| 5809 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5810 | SmallVector<IdentifierInfo *, 4> Names; |
| 5811 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 5812 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
| Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5813 | // ToII is nullptr when no symbolic name is given for output operand |
| 5814 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5815 | Names.push_back(ToII); |
| 5816 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5817 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5818 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 5819 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
| Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5820 | // ToII is nullptr when no symbolic name is given for input operand |
| 5821 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5822 | Names.push_back(ToII); |
| 5823 | } |
| 5824 | |
| 5825 | SmallVector<StringLiteral *, 4> Clobbers; |
| 5826 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5827 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) |
| 5828 | Clobbers.push_back(*ClobberOrErr); |
| 5829 | else |
| 5830 | return ClobberOrErr.takeError(); |
| 5831 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5832 | } |
| 5833 | |
| 5834 | SmallVector<StringLiteral *, 4> Constraints; |
| 5835 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5836 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) |
| 5837 | Constraints.push_back(*OutputOrErr); |
| 5838 | else |
| 5839 | return OutputOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5840 | } |
| 5841 | |
| 5842 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5843 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) |
| 5844 | Constraints.push_back(*InputOrErr); |
| 5845 | else |
| 5846 | return InputOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5847 | } |
| 5848 | |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5849 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() + |
| 5850 | S->getNumLabels()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5851 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) |
| 5852 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5853 | |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5854 | if (Error Err = |
| 5855 | ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
| 5856 | return std::move(Err); |
| 5857 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5858 | if (Error Err = ImportArrayChecked( |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5859 | S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs())) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5860 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5861 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5862 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); |
| 5863 | if (!AsmLocOrErr) |
| 5864 | return AsmLocOrErr.takeError(); |
| 5865 | auto AsmStrOrErr = import(S->getAsmString()); |
| 5866 | if (!AsmStrOrErr) |
| 5867 | return AsmStrOrErr.takeError(); |
| 5868 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); |
| 5869 | if (!RParenLocOrErr) |
| 5870 | return RParenLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5871 | |
| 5872 | return new (Importer.getToContext()) GCCAsmStmt( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5873 | Importer.getToContext(), |
| 5874 | *AsmLocOrErr, |
| 5875 | S->isSimple(), |
| 5876 | S->isVolatile(), |
| 5877 | S->getNumOutputs(), |
| 5878 | S->getNumInputs(), |
| 5879 | Names.data(), |
| 5880 | Constraints.data(), |
| 5881 | Exprs.data(), |
| 5882 | *AsmStrOrErr, |
| 5883 | S->getNumClobbers(), |
| 5884 | Clobbers.data(), |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5885 | S->getNumLabels(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5886 | *RParenLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5887 | } |
| 5888 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5889 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5890 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5891 | Error Err = Error::success(); |
| 5892 | auto ToDG = importChecked(Err, S->getDeclGroup()); |
| 5893 | auto ToBeginLoc = importChecked(Err, S->getBeginLoc()); |
| 5894 | auto ToEndLoc = importChecked(Err, S->getEndLoc()); |
| 5895 | if (Err) |
| 5896 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5897 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5898 | } |
| 5899 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5900 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5901 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); |
| 5902 | if (!ToSemiLocOrErr) |
| 5903 | return ToSemiLocOrErr.takeError(); |
| 5904 | return new (Importer.getToContext()) NullStmt( |
| 5905 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5906 | } |
| 5907 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5908 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5909 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5910 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5911 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) |
| 5912 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5913 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5914 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); |
| 5915 | if (!ToLBracLocOrErr) |
| 5916 | return ToLBracLocOrErr.takeError(); |
| 5917 | |
| 5918 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); |
| 5919 | if (!ToRBracLocOrErr) |
| 5920 | return ToRBracLocOrErr.takeError(); |
| 5921 | |
| 5922 | return CompoundStmt::Create( |
| 5923 | Importer.getToContext(), ToStmts, |
| 5924 | *ToLBracLocOrErr, *ToRBracLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5925 | } |
| 5926 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5927 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5928 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5929 | Error Err = Error::success(); |
| 5930 | auto ToLHS = importChecked(Err, S->getLHS()); |
| 5931 | auto ToRHS = importChecked(Err, S->getRHS()); |
| 5932 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); |
| 5933 | auto ToCaseLoc = importChecked(Err, S->getCaseLoc()); |
| 5934 | auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc()); |
| 5935 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); |
| 5936 | if (Err) |
| 5937 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5938 | |
| Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 5939 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, |
| 5940 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
| Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5941 | ToStmt->setSubStmt(ToSubStmt); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5942 | |
| Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5943 | return ToStmt; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5944 | } |
| 5945 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5946 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5947 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5948 | Error Err = Error::success(); |
| 5949 | auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc()); |
| 5950 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); |
| 5951 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); |
| 5952 | if (Err) |
| 5953 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5954 | |
| 5955 | return new (Importer.getToContext()) DefaultStmt( |
| 5956 | ToDefaultLoc, ToColonLoc, ToSubStmt); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5957 | } |
| 5958 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5959 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5960 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5961 | Error Err = Error::success(); |
| 5962 | auto ToIdentLoc = importChecked(Err, S->getIdentLoc()); |
| 5963 | auto ToLabelDecl = importChecked(Err, S->getDecl()); |
| 5964 | auto ToSubStmt = importChecked(Err, S->getSubStmt()); |
| 5965 | if (Err) |
| 5966 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5967 | |
| 5968 | return new (Importer.getToContext()) LabelStmt( |
| 5969 | ToIdentLoc, ToLabelDecl, ToSubStmt); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5970 | } |
| 5971 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5972 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 5973 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); |
| 5974 | if (!ToAttrLocOrErr) |
| 5975 | return ToAttrLocOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5976 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 5977 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5978 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) |
| 5979 | return std::move(Err); |
| 5980 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 5981 | if (!ToSubStmtOrErr) |
| 5982 | return ToSubStmtOrErr.takeError(); |
| 5983 | |
| 5984 | return AttributedStmt::Create( |
| 5985 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5986 | } |
| 5987 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5988 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5989 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 5990 | Error Err = Error::success(); |
| 5991 | auto ToIfLoc = importChecked(Err, S->getIfLoc()); |
| 5992 | auto ToInit = importChecked(Err, S->getInit()); |
| 5993 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); |
| 5994 | auto ToCond = importChecked(Err, S->getCond()); |
| 5995 | auto ToThen = importChecked(Err, S->getThen()); |
| 5996 | auto ToElseLoc = importChecked(Err, S->getElseLoc()); |
| 5997 | auto ToElse = importChecked(Err, S->getElse()); |
| 5998 | if (Err) |
| 5999 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6000 | |
| Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 6001 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), |
| 6002 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, |
| 6003 | ToElse); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6004 | } |
| 6005 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6006 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6007 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6008 | Error Err = Error::success(); |
| 6009 | auto ToInit = importChecked(Err, S->getInit()); |
| 6010 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); |
| 6011 | auto ToCond = importChecked(Err, S->getCond()); |
| 6012 | auto ToBody = importChecked(Err, S->getBody()); |
| 6013 | auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc()); |
| 6014 | if (Err) |
| 6015 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6016 | |
| Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 6017 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, |
| 6018 | ToConditionVariable, ToCond); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6019 | ToStmt->setBody(ToBody); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6020 | ToStmt->setSwitchLoc(ToSwitchLoc); |
| 6021 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6022 | // Now we have to re-chain the cases. |
| 6023 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 6024 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 6025 | SC = SC->getNextSwitchCase()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6026 | Expected<SwitchCase *> ToSCOrErr = import(SC); |
| 6027 | if (!ToSCOrErr) |
| 6028 | return ToSCOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6029 | if (LastChainedSwitchCase) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6030 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6031 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6032 | ToStmt->setSwitchCaseList(*ToSCOrErr); |
| 6033 | LastChainedSwitchCase = *ToSCOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6034 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6035 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6036 | return ToStmt; |
| 6037 | } |
| 6038 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6039 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6040 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6041 | Error Err = Error::success(); |
| 6042 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); |
| 6043 | auto ToCond = importChecked(Err, S->getCond()); |
| 6044 | auto ToBody = importChecked(Err, S->getBody()); |
| 6045 | auto ToWhileLoc = importChecked(Err, S->getWhileLoc()); |
| 6046 | if (Err) |
| 6047 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6048 | |
| Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 6049 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, |
| 6050 | ToBody, ToWhileLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6051 | } |
| 6052 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6053 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6054 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6055 | Error Err = Error::success(); |
| 6056 | auto ToBody = importChecked(Err, S->getBody()); |
| 6057 | auto ToCond = importChecked(Err, S->getCond()); |
| 6058 | auto ToDoLoc = importChecked(Err, S->getDoLoc()); |
| 6059 | auto ToWhileLoc = importChecked(Err, S->getWhileLoc()); |
| 6060 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); |
| 6061 | if (Err) |
| 6062 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6063 | |
| 6064 | return new (Importer.getToContext()) DoStmt( |
| 6065 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6066 | } |
| 6067 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6068 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6069 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6070 | Error Err = Error::success(); |
| 6071 | auto ToInit = importChecked(Err, S->getInit()); |
| 6072 | auto ToCond = importChecked(Err, S->getCond()); |
| 6073 | auto ToConditionVariable = importChecked(Err, S->getConditionVariable()); |
| 6074 | auto ToInc = importChecked(Err, S->getInc()); |
| 6075 | auto ToBody = importChecked(Err, S->getBody()); |
| 6076 | auto ToForLoc = importChecked(Err, S->getForLoc()); |
| 6077 | auto ToLParenLoc = importChecked(Err, S->getLParenLoc()); |
| 6078 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); |
| 6079 | if (Err) |
| 6080 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6081 | |
| 6082 | return new (Importer.getToContext()) ForStmt( |
| 6083 | Importer.getToContext(), |
| 6084 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, |
| 6085 | ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6086 | } |
| 6087 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6088 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6089 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6090 | Error Err = Error::success(); |
| 6091 | auto ToLabel = importChecked(Err, S->getLabel()); |
| 6092 | auto ToGotoLoc = importChecked(Err, S->getGotoLoc()); |
| 6093 | auto ToLabelLoc = importChecked(Err, S->getLabelLoc()); |
| 6094 | if (Err) |
| 6095 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6096 | |
| 6097 | return new (Importer.getToContext()) GotoStmt( |
| 6098 | ToLabel, ToGotoLoc, ToLabelLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6099 | } |
| 6100 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6101 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6102 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6103 | Error Err = Error::success(); |
| 6104 | auto ToGotoLoc = importChecked(Err, S->getGotoLoc()); |
| 6105 | auto ToStarLoc = importChecked(Err, S->getStarLoc()); |
| 6106 | auto ToTarget = importChecked(Err, S->getTarget()); |
| 6107 | if (Err) |
| 6108 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6109 | |
| 6110 | return new (Importer.getToContext()) IndirectGotoStmt( |
| 6111 | ToGotoLoc, ToStarLoc, ToTarget); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6112 | } |
| 6113 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6114 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 6115 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); |
| 6116 | if (!ToContinueLocOrErr) |
| 6117 | return ToContinueLocOrErr.takeError(); |
| 6118 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6119 | } |
| 6120 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6121 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 6122 | auto ToBreakLocOrErr = import(S->getBreakLoc()); |
| 6123 | if (!ToBreakLocOrErr) |
| 6124 | return ToBreakLocOrErr.takeError(); |
| 6125 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6126 | } |
| 6127 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6128 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6129 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6130 | Error Err = Error::success(); |
| 6131 | auto ToReturnLoc = importChecked(Err, S->getReturnLoc()); |
| 6132 | auto ToRetValue = importChecked(Err, S->getRetValue()); |
| 6133 | auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate()); |
| 6134 | if (Err) |
| 6135 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6136 | |
| Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 6137 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, |
| 6138 | ToNRVOCandidate); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6139 | } |
| 6140 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6141 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6142 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6143 | Error Err = Error::success(); |
| 6144 | auto ToCatchLoc = importChecked(Err, S->getCatchLoc()); |
| 6145 | auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl()); |
| 6146 | auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock()); |
| 6147 | if (Err) |
| 6148 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6149 | |
| 6150 | return new (Importer.getToContext()) CXXCatchStmt ( |
| 6151 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6152 | } |
| 6153 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6154 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 6155 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); |
| 6156 | if (!ToTryLocOrErr) |
| 6157 | return ToTryLocOrErr.takeError(); |
| 6158 | |
| 6159 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); |
| 6160 | if (!ToTryBlockOrErr) |
| 6161 | return ToTryBlockOrErr.takeError(); |
| 6162 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6163 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 6164 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 6165 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6166 | if (auto ToHandlerOrErr = import(FromHandler)) |
| 6167 | ToHandlers[HI] = *ToHandlerOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6168 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6169 | return ToHandlerOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6170 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6171 | |
| 6172 | return CXXTryStmt::Create( |
| 6173 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6174 | } |
| 6175 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6176 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6177 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6178 | Error Err = Error::success(); |
| 6179 | auto ToInit = importChecked(Err, S->getInit()); |
| 6180 | auto ToRangeStmt = importChecked(Err, S->getRangeStmt()); |
| 6181 | auto ToBeginStmt = importChecked(Err, S->getBeginStmt()); |
| 6182 | auto ToEndStmt = importChecked(Err, S->getEndStmt()); |
| 6183 | auto ToCond = importChecked(Err, S->getCond()); |
| 6184 | auto ToInc = importChecked(Err, S->getInc()); |
| 6185 | auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt()); |
| 6186 | auto ToBody = importChecked(Err, S->getBody()); |
| 6187 | auto ToForLoc = importChecked(Err, S->getForLoc()); |
| 6188 | auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc()); |
| 6189 | auto ToColonLoc = importChecked(Err, S->getColonLoc()); |
| 6190 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); |
| 6191 | if (Err) |
| 6192 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6193 | |
| 6194 | return new (Importer.getToContext()) CXXForRangeStmt( |
| 6195 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 6196 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6197 | } |
| 6198 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6199 | ExpectedStmt |
| 6200 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6201 | Error Err = Error::success(); |
| 6202 | auto ToElement = importChecked(Err, S->getElement()); |
| 6203 | auto ToCollection = importChecked(Err, S->getCollection()); |
| 6204 | auto ToBody = importChecked(Err, S->getBody()); |
| 6205 | auto ToForLoc = importChecked(Err, S->getForLoc()); |
| 6206 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); |
| 6207 | if (Err) |
| 6208 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6209 | |
| 6210 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, |
| 6211 | ToCollection, |
| 6212 | ToBody, |
| 6213 | ToForLoc, |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6214 | ToRParenLoc); |
| 6215 | } |
| 6216 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6217 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6218 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6219 | Error Err = Error::success(); |
| 6220 | auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc()); |
| 6221 | auto ToRParenLoc = importChecked(Err, S->getRParenLoc()); |
| 6222 | auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl()); |
| 6223 | auto ToCatchBody = importChecked(Err, S->getCatchBody()); |
| 6224 | if (Err) |
| 6225 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6226 | |
| 6227 | return new (Importer.getToContext()) ObjCAtCatchStmt ( |
| 6228 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6229 | } |
| 6230 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6231 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 6232 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); |
| 6233 | if (!ToAtFinallyLocOrErr) |
| 6234 | return ToAtFinallyLocOrErr.takeError(); |
| 6235 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); |
| 6236 | if (!ToAtFinallyStmtOrErr) |
| 6237 | return ToAtFinallyStmtOrErr.takeError(); |
| 6238 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, |
| 6239 | *ToAtFinallyStmtOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6240 | } |
| 6241 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6242 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6243 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6244 | Error Err = Error::success(); |
| 6245 | auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc()); |
| 6246 | auto ToTryBody = importChecked(Err, S->getTryBody()); |
| 6247 | auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt()); |
| 6248 | if (Err) |
| 6249 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6250 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6251 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 6252 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 6253 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6254 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) |
| 6255 | ToCatchStmts[CI] = *ToCatchStmtOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6256 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6257 | return ToCatchStmtOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6258 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6259 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6260 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6261 | ToAtTryLoc, ToTryBody, |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6262 | ToCatchStmts.begin(), ToCatchStmts.size(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6263 | ToFinallyStmt); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6264 | } |
| 6265 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6266 | ExpectedStmt |
| 6267 | ASTNodeImporter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6268 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6269 | Error Err = Error::success(); |
| 6270 | auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc()); |
| 6271 | auto ToSynchExpr = importChecked(Err, S->getSynchExpr()); |
| 6272 | auto ToSynchBody = importChecked(Err, S->getSynchBody()); |
| 6273 | if (Err) |
| 6274 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6275 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6276 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 6277 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 6278 | } |
| 6279 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6280 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 6281 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); |
| 6282 | if (!ToThrowLocOrErr) |
| 6283 | return ToThrowLocOrErr.takeError(); |
| 6284 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); |
| 6285 | if (!ToThrowExprOrErr) |
| 6286 | return ToThrowExprOrErr.takeError(); |
| 6287 | return new (Importer.getToContext()) ObjCAtThrowStmt( |
| 6288 | *ToThrowLocOrErr, *ToThrowExprOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6289 | } |
| 6290 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6291 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( |
| 6292 | ObjCAutoreleasePoolStmt *S) { |
| 6293 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); |
| 6294 | if (!ToAtLocOrErr) |
| 6295 | return ToAtLocOrErr.takeError(); |
| 6296 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 6297 | if (!ToSubStmtOrErr) |
| 6298 | return ToSubStmtOrErr.takeError(); |
| 6299 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, |
| 6300 | *ToSubStmtOrErr); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6301 | } |
| 6302 | |
| 6303 | //---------------------------------------------------------------------------- |
| 6304 | // Import Expressions |
| 6305 | //---------------------------------------------------------------------------- |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6306 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6307 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) |
| 6308 | << E->getStmtClassName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6309 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6310 | } |
| 6311 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6312 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6313 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6314 | Error Err = Error::success(); |
| 6315 | auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); |
| 6316 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 6317 | auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo()); |
| 6318 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 6319 | auto ToType = importChecked(Err, E->getType()); |
| 6320 | if (Err) |
| 6321 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6322 | |
| 6323 | return new (Importer.getToContext()) VAArgExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6324 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, |
| 6325 | E->isMicrosoftABI()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6326 | } |
| 6327 | |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6328 | ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) { |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6329 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6330 | Error Err = Error::success(); |
| 6331 | auto ToCond = importChecked(Err, E->getCond()); |
| 6332 | auto ToLHS = importChecked(Err, E->getLHS()); |
| 6333 | auto ToRHS = importChecked(Err, E->getRHS()); |
| 6334 | auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); |
| 6335 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 6336 | auto ToType = importChecked(Err, E->getType()); |
| 6337 | if (Err) |
| 6338 | return std::move(Err); |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6339 | |
| 6340 | ExprValueKind VK = E->getValueKind(); |
| 6341 | ExprObjectKind OK = E->getObjectKind(); |
| 6342 | |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6343 | // The value of CondIsTrue only matters if the value is not |
| 6344 | // condition-dependent. |
| 6345 | bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue(); |
| 6346 | |
| 6347 | return new (Importer.getToContext()) |
| 6348 | ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK, |
| Haojian Wu | 876bb86 | 2020-03-17 08:33:37 +0100 | [diff] [blame] | 6349 | ToRParenLoc, CondIsTrue); |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6350 | } |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6351 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6352 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 6353 | ExpectedType TypeOrErr = import(E->getType()); |
| 6354 | if (!TypeOrErr) |
| 6355 | return TypeOrErr.takeError(); |
| 6356 | |
| 6357 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); |
| 6358 | if (!BeginLocOrErr) |
| 6359 | return BeginLocOrErr.takeError(); |
| 6360 | |
| 6361 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6362 | } |
| 6363 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6364 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6365 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6366 | Error Err = Error::success(); |
| 6367 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 6368 | auto ToType = importChecked(Err, E->getType()); |
| 6369 | auto ToFunctionName = importChecked(Err, E->getFunctionName()); |
| 6370 | if (Err) |
| 6371 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6372 | |
| Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 6373 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, |
| 6374 | E->getIdentKind(), ToFunctionName); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6375 | } |
| 6376 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6377 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6378 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6379 | Error Err = Error::success(); |
| 6380 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 6381 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); |
| 6382 | auto ToDecl = importChecked(Err, E->getDecl()); |
| 6383 | auto ToLocation = importChecked(Err, E->getLocation()); |
| 6384 | auto ToType = importChecked(Err, E->getType()); |
| 6385 | if (Err) |
| 6386 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6387 | |
| 6388 | NamedDecl *ToFoundD = nullptr; |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6389 | if (E->getDecl() != E->getFoundDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6390 | auto FoundDOrErr = import(E->getFoundDecl()); |
| 6391 | if (!FoundDOrErr) |
| 6392 | return FoundDOrErr.takeError(); |
| 6393 | ToFoundD = *FoundDOrErr; |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6394 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6395 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6396 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6397 | TemplateArgumentListInfo *ToResInfo = nullptr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6398 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6399 | if (Error Err = |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 6400 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6401 | E->template_arguments(), ToTAInfo)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6402 | return std::move(Err); |
| 6403 | ToResInfo = &ToTAInfo; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6404 | } |
| 6405 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6406 | auto *ToE = DeclRefExpr::Create( |
| 6407 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, |
| 6408 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, |
| Richard Smith | 715f7a1 | 2019-06-11 17:50:32 +0000 | [diff] [blame] | 6409 | E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse()); |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 6410 | if (E->hadMultipleCandidates()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6411 | ToE->setHadMultipleCandidates(true); |
| 6412 | return ToE; |
| Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 6413 | } |
| 6414 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6415 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 6416 | ExpectedType TypeOrErr = import(E->getType()); |
| 6417 | if (!TypeOrErr) |
| 6418 | return TypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6419 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6420 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6421 | } |
| 6422 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6423 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 6424 | ExpectedExpr ToInitOrErr = import(E->getInit()); |
| 6425 | if (!ToInitOrErr) |
| 6426 | return ToInitOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6427 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6428 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); |
| 6429 | if (!ToEqualOrColonLocOrErr) |
| 6430 | return ToEqualOrColonLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6431 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6432 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6433 | // List elements from the second, the first is Init itself |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6434 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { |
| 6435 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) |
| 6436 | ToIndexExprs[I - 1] = *ToArgOrErr; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6437 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6438 | return ToArgOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6439 | } |
| 6440 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6441 | SmallVector<Designator, 4> ToDesignators(E->size()); |
| 6442 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) |
| 6443 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6444 | |
| 6445 | return DesignatedInitExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6446 | Importer.getToContext(), ToDesignators, |
| 6447 | ToIndexExprs, *ToEqualOrColonLocOrErr, |
| 6448 | E->usesGNUSyntax(), *ToInitOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6449 | } |
| 6450 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6451 | ExpectedStmt |
| 6452 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 6453 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6454 | if (!ToTypeOrErr) |
| 6455 | return ToTypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6456 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6457 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6458 | if (!ToLocationOrErr) |
| 6459 | return ToLocationOrErr.takeError(); |
| 6460 | |
| 6461 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( |
| 6462 | *ToTypeOrErr, *ToLocationOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6463 | } |
| 6464 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6465 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 6466 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6467 | if (!ToTypeOrErr) |
| 6468 | return ToTypeOrErr.takeError(); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6469 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6470 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6471 | if (!ToLocationOrErr) |
| 6472 | return ToLocationOrErr.takeError(); |
| 6473 | |
| 6474 | return IntegerLiteral::Create( |
| 6475 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6476 | } |
| 6477 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6478 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6479 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 6480 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6481 | if (!ToTypeOrErr) |
| 6482 | return ToTypeOrErr.takeError(); |
| 6483 | |
| 6484 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6485 | if (!ToLocationOrErr) |
| 6486 | return ToLocationOrErr.takeError(); |
| 6487 | |
| 6488 | return FloatingLiteral::Create( |
| 6489 | Importer.getToContext(), E->getValue(), E->isExact(), |
| 6490 | *ToTypeOrErr, *ToLocationOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6491 | } |
| 6492 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6493 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 6494 | auto ToTypeOrErr = import(E->getType()); |
| 6495 | if (!ToTypeOrErr) |
| 6496 | return ToTypeOrErr.takeError(); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6497 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6498 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6499 | if (!ToSubExprOrErr) |
| 6500 | return ToSubExprOrErr.takeError(); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6501 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6502 | return new (Importer.getToContext()) ImaginaryLiteral( |
| 6503 | *ToSubExprOrErr, *ToTypeOrErr); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6504 | } |
| 6505 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6506 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 6507 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6508 | if (!ToTypeOrErr) |
| 6509 | return ToTypeOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6510 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6511 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6512 | if (!ToLocationOrErr) |
| 6513 | return ToLocationOrErr.takeError(); |
| 6514 | |
| 6515 | return new (Importer.getToContext()) CharacterLiteral( |
| 6516 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); |
| Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 6517 | } |
| 6518 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6519 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 6520 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6521 | if (!ToTypeOrErr) |
| 6522 | return ToTypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6523 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6524 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); |
| 6525 | if (Error Err = ImportArrayChecked( |
| 6526 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) |
| 6527 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6528 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6529 | return StringLiteral::Create( |
| 6530 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), |
| 6531 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6532 | } |
| 6533 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6534 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6535 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6536 | Error Err = Error::success(); |
| 6537 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); |
| 6538 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); |
| 6539 | auto ToType = importChecked(Err, E->getType()); |
| 6540 | auto ToInitializer = importChecked(Err, E->getInitializer()); |
| 6541 | if (Err) |
| 6542 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6543 | |
| 6544 | return new (Importer.getToContext()) CompoundLiteralExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6545 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), |
| 6546 | ToInitializer, E->isFileScope()); |
| 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::VisitAtomicExpr(AtomicExpr *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 ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc()); |
| 6553 | auto ToType = importChecked(Err, E->getType()); |
| 6554 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 6555 | if (Err) |
| 6556 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6557 | |
| 6558 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); |
| 6559 | if (Error Err = ImportArrayChecked( |
| 6560 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 6561 | ToExprs.begin())) |
| 6562 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6563 | |
| 6564 | return new (Importer.getToContext()) AtomicExpr( |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6565 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6566 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6567 | } |
| 6568 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6569 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6570 | Error Err = Error::success(); |
| 6571 | auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc()); |
| 6572 | auto ToLabelLoc = importChecked(Err, E->getLabelLoc()); |
| 6573 | auto ToLabel = importChecked(Err, E->getLabel()); |
| 6574 | auto ToType = importChecked(Err, E->getType()); |
| 6575 | if (Err) |
| 6576 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6577 | |
| 6578 | return new (Importer.getToContext()) AddrLabelExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6579 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6580 | } |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6581 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6582 | Error Err = Error::success(); |
| 6583 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 6584 | if (Err) |
| 6585 | return std::move(Err); |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6586 | |
| Gauthier Harnisch | 83c7b61 | 2019-06-15 10:24:47 +0000 | [diff] [blame] | 6587 | // TODO : Handle APValue::ValueKind that require importing. |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6588 | |
| Gauthier Harnisch | 83c7b61 | 2019-06-15 10:24:47 +0000 | [diff] [blame] | 6589 | APValue::ValueKind Kind = E->getResultAPValueKind(); |
| 6590 | if (Kind == APValue::Int || Kind == APValue::Float || |
| 6591 | Kind == APValue::FixedPoint || Kind == APValue::ComplexFloat || |
| 6592 | Kind == APValue::ComplexInt) |
| 6593 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, |
| 6594 | E->getAPValueResult()); |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 6595 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr); |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6596 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6597 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6598 | Error Err = Error::success(); |
| 6599 | auto ToLParen = importChecked(Err, E->getLParen()); |
| 6600 | auto ToRParen = importChecked(Err, E->getRParen()); |
| 6601 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 6602 | if (Err) |
| 6603 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6604 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6605 | return new (Importer.getToContext()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6606 | ParenExpr(ToLParen, ToRParen, ToSubExpr); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6607 | } |
| 6608 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6609 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 6610 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); |
| 6611 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) |
| 6612 | return std::move(Err); |
| 6613 | |
| 6614 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); |
| 6615 | if (!ToLParenLocOrErr) |
| 6616 | return ToLParenLocOrErr.takeError(); |
| 6617 | |
| 6618 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); |
| 6619 | if (!ToRParenLocOrErr) |
| 6620 | return ToRParenLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6621 | |
| Bruno Ricci | f49e1ca | 2018-11-20 16:20:40 +0000 | [diff] [blame] | 6622 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, |
| 6623 | ToExprs, *ToRParenLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6624 | } |
| 6625 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6626 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6627 | Error Err = Error::success(); |
| 6628 | auto ToSubStmt = importChecked(Err, E->getSubStmt()); |
| 6629 | auto ToType = importChecked(Err, E->getType()); |
| 6630 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); |
| 6631 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 6632 | if (Err) |
| 6633 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6634 | |
| Richard Smith | 5c845c1 | 2020-03-09 17:34:33 -0700 | [diff] [blame] | 6635 | return new (Importer.getToContext()) |
| 6636 | StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc, |
| 6637 | E->getTemplateDepth()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6638 | } |
| 6639 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6640 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6641 | Error Err = Error::success(); |
| 6642 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 6643 | auto ToType = importChecked(Err, E->getType()); |
| 6644 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 6645 | if (Err) |
| 6646 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6647 | |
| Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6648 | return new (Importer.getToContext()) UnaryOperator( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6649 | ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), |
| 6650 | ToOperatorLoc, E->canOverflow()); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6651 | } |
| 6652 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6653 | ExpectedStmt |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6654 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6655 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
| 6656 | Error Err = Error::success(); |
| 6657 | auto ToType = importChecked(Err, E->getType()); |
| 6658 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 6659 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 6660 | if (Err) |
| 6661 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6662 | |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6663 | if (E->isArgumentType()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6664 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = |
| 6665 | import(E->getArgumentTypeInfo()); |
| 6666 | if (!ToArgumentTypeInfoOrErr) |
| 6667 | return ToArgumentTypeInfoOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6668 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6669 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6670 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, |
| 6671 | ToRParenLoc); |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6672 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6673 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6674 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); |
| 6675 | if (!ToArgumentExprOrErr) |
| 6676 | return ToArgumentExprOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6677 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6678 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6679 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6680 | } |
| 6681 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6682 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6683 | Error Err = Error::success(); |
| 6684 | auto ToLHS = importChecked(Err, E->getLHS()); |
| 6685 | auto ToRHS = importChecked(Err, E->getRHS()); |
| 6686 | auto ToType = importChecked(Err, E->getType()); |
| 6687 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 6688 | if (Err) |
| 6689 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6690 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6691 | return new (Importer.getToContext()) BinaryOperator( |
| 6692 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6693 | E->getObjectKind(), ToOperatorLoc, E->getFPFeatures()); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6694 | } |
| 6695 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6696 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6697 | Error Err = Error::success(); |
| 6698 | auto ToCond = importChecked(Err, E->getCond()); |
| 6699 | auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc()); |
| 6700 | auto ToLHS = importChecked(Err, E->getLHS()); |
| 6701 | auto ToColonLoc = importChecked(Err, E->getColonLoc()); |
| 6702 | auto ToRHS = importChecked(Err, E->getRHS()); |
| 6703 | auto ToType = importChecked(Err, E->getType()); |
| 6704 | if (Err) |
| 6705 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6706 | |
| 6707 | return new (Importer.getToContext()) ConditionalOperator( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6708 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, |
| 6709 | E->getValueKind(), E->getObjectKind()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6710 | } |
| 6711 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6712 | ExpectedStmt |
| 6713 | ASTNodeImporter::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) { |
| 6714 | Error Err = Error::success(); |
| 6715 | auto ToCommon = importChecked(Err, E->getCommon()); |
| 6716 | auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue()); |
| 6717 | auto ToCond = importChecked(Err, E->getCond()); |
| 6718 | auto ToTrueExpr = importChecked(Err, E->getTrueExpr()); |
| 6719 | auto ToFalseExpr = importChecked(Err, E->getFalseExpr()); |
| 6720 | auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc()); |
| 6721 | auto ToColonLoc = importChecked(Err, E->getColonLoc()); |
| 6722 | auto ToType = importChecked(Err, E->getType()); |
| 6723 | if (Err) |
| 6724 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6725 | |
| 6726 | return new (Importer.getToContext()) BinaryConditionalOperator( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6727 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, |
| 6728 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), |
| 6729 | E->getObjectKind()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6730 | } |
| 6731 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6732 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6733 | Error Err = Error::success(); |
| 6734 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 6735 | auto ToQueriedTypeSourceInfo = |
| 6736 | importChecked(Err, E->getQueriedTypeSourceInfo()); |
| 6737 | auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression()); |
| 6738 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); |
| 6739 | auto ToType = importChecked(Err, E->getType()); |
| 6740 | if (Err) |
| 6741 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6742 | |
| 6743 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6744 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), |
| 6745 | ToDimensionExpression, ToEndLoc, ToType); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6746 | } |
| 6747 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6748 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6749 | Error Err = Error::success(); |
| 6750 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 6751 | auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression()); |
| 6752 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); |
| 6753 | auto ToType = importChecked(Err, E->getType()); |
| 6754 | if (Err) |
| 6755 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6756 | |
| 6757 | return new (Importer.getToContext()) ExpressionTraitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6758 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), |
| 6759 | ToEndLoc, ToType); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6760 | } |
| 6761 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6762 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6763 | Error Err = Error::success(); |
| 6764 | auto ToLocation = importChecked(Err, E->getLocation()); |
| 6765 | auto ToType = importChecked(Err, E->getType()); |
| 6766 | auto ToSourceExpr = importChecked(Err, E->getSourceExpr()); |
| 6767 | if (Err) |
| 6768 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6769 | |
| 6770 | return new (Importer.getToContext()) OpaqueValueExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6771 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6772 | } |
| 6773 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6774 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6775 | Error Err = Error::success(); |
| 6776 | auto ToLHS = importChecked(Err, E->getLHS()); |
| 6777 | auto ToRHS = importChecked(Err, E->getRHS()); |
| 6778 | auto ToType = importChecked(Err, E->getType()); |
| 6779 | auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc()); |
| 6780 | if (Err) |
| 6781 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6782 | |
| 6783 | return new (Importer.getToContext()) ArraySubscriptExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6784 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), |
| 6785 | ToRBracketLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6786 | } |
| 6787 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6788 | ExpectedStmt |
| 6789 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6790 | Error Err = Error::success(); |
| 6791 | auto ToLHS = importChecked(Err, E->getLHS()); |
| 6792 | auto ToRHS = importChecked(Err, E->getRHS()); |
| 6793 | auto ToType = importChecked(Err, E->getType()); |
| 6794 | auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType()); |
| 6795 | auto ToComputationResultType = |
| 6796 | importChecked(Err, E->getComputationResultType()); |
| 6797 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 6798 | if (Err) |
| 6799 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6800 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6801 | return new (Importer.getToContext()) CompoundAssignOperator( |
| 6802 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6803 | E->getObjectKind(), ToComputationLHSType, ToComputationResultType, |
| 6804 | ToOperatorLoc, E->getFPFeatures()); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6805 | } |
| 6806 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6807 | Expected<CXXCastPath> |
| 6808 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { |
| 6809 | CXXCastPath Path; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6810 | 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] | 6811 | if (auto SpecOrErr = import(*I)) |
| 6812 | Path.push_back(*SpecOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6813 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6814 | return SpecOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6815 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6816 | return Path; |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6817 | } |
| 6818 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6819 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 6820 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6821 | if (!ToTypeOrErr) |
| 6822 | return ToTypeOrErr.takeError(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6823 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6824 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6825 | if (!ToSubExprOrErr) |
| 6826 | return ToSubExprOrErr.takeError(); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6827 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6828 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6829 | if (!ToBasePathOrErr) |
| 6830 | return ToBasePathOrErr.takeError(); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6831 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6832 | return ImplicitCastExpr::Create( |
| 6833 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, |
| 6834 | &(*ToBasePathOrErr), E->getValueKind()); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6835 | } |
| 6836 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6837 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6838 | Error Err = Error::success(); |
| 6839 | auto ToType = importChecked(Err, E->getType()); |
| 6840 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 6841 | auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten()); |
| 6842 | if (Err) |
| 6843 | return std::move(Err); |
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6844 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6845 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6846 | if (!ToBasePathOrErr) |
| 6847 | return ToBasePathOrErr.takeError(); |
| 6848 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6849 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6850 | switch (E->getStmtClass()) { |
| 6851 | case Stmt::CStyleCastExprClass: { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6852 | auto *CCE = cast<CStyleCastExpr>(E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6853 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); |
| 6854 | if (!ToLParenLocOrErr) |
| 6855 | return ToLParenLocOrErr.takeError(); |
| 6856 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); |
| 6857 | if (!ToRParenLocOrErr) |
| 6858 | return ToRParenLocOrErr.takeError(); |
| 6859 | return CStyleCastExpr::Create( |
| 6860 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), |
| 6861 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, |
| 6862 | *ToRParenLocOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6863 | } |
| 6864 | |
| 6865 | case Stmt::CXXFunctionalCastExprClass: { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6866 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6867 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); |
| 6868 | if (!ToLParenLocOrErr) |
| 6869 | return ToLParenLocOrErr.takeError(); |
| 6870 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); |
| 6871 | if (!ToRParenLocOrErr) |
| 6872 | return ToRParenLocOrErr.takeError(); |
| 6873 | return CXXFunctionalCastExpr::Create( |
| 6874 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, |
| 6875 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, |
| 6876 | *ToRParenLocOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6877 | } |
| 6878 | |
| 6879 | case Stmt::ObjCBridgedCastExprClass: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6880 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
| 6881 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); |
| 6882 | if (!ToLParenLocOrErr) |
| 6883 | return ToLParenLocOrErr.takeError(); |
| 6884 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); |
| 6885 | if (!ToBridgeKeywordLocOrErr) |
| 6886 | return ToBridgeKeywordLocOrErr.takeError(); |
| 6887 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 6888 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), |
| 6889 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6890 | } |
| 6891 | default: |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6892 | llvm_unreachable("Cast expression of unsupported type!"); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6893 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6894 | } |
| 6895 | } |
| 6896 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6897 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { |
| 6898 | SmallVector<OffsetOfNode, 4> ToNodes; |
| 6899 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { |
| 6900 | const OffsetOfNode &FromNode = E->getComponent(I); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6901 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6902 | SourceLocation ToBeginLoc, ToEndLoc; |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6903 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6904 | if (FromNode.getKind() != OffsetOfNode::Base) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6905 | Error Err = Error::success(); |
| 6906 | ToBeginLoc = importChecked(Err, FromNode.getBeginLoc()); |
| 6907 | ToEndLoc = importChecked(Err, FromNode.getEndLoc()); |
| 6908 | if (Err) |
| 6909 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6910 | } |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6911 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6912 | switch (FromNode.getKind()) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6913 | case OffsetOfNode::Array: |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6914 | ToNodes.push_back( |
| 6915 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6916 | break; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6917 | case OffsetOfNode::Base: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6918 | auto ToBSOrErr = import(FromNode.getBase()); |
| 6919 | if (!ToBSOrErr) |
| 6920 | return ToBSOrErr.takeError(); |
| 6921 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6922 | break; |
| 6923 | } |
| 6924 | case OffsetOfNode::Field: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6925 | auto ToFieldOrErr = import(FromNode.getField()); |
| 6926 | if (!ToFieldOrErr) |
| 6927 | return ToFieldOrErr.takeError(); |
| 6928 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6929 | break; |
| 6930 | } |
| 6931 | case OffsetOfNode::Identifier: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6932 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); |
| 6933 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6934 | break; |
| 6935 | } |
| 6936 | } |
| 6937 | } |
| 6938 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6939 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); |
| 6940 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { |
| 6941 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); |
| 6942 | if (!ToIndexExprOrErr) |
| 6943 | return ToIndexExprOrErr.takeError(); |
| 6944 | ToExprs[I] = *ToIndexExprOrErr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6945 | } |
| 6946 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6947 | Error Err = Error::success(); |
| 6948 | auto ToType = importChecked(Err, E->getType()); |
| 6949 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); |
| 6950 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 6951 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 6952 | if (Err) |
| 6953 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6954 | |
| 6955 | return OffsetOfExpr::Create( |
| 6956 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, |
| 6957 | ToExprs, ToRParenLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6958 | } |
| 6959 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6960 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6961 | Error Err = Error::success(); |
| 6962 | auto ToType = importChecked(Err, E->getType()); |
| 6963 | auto ToOperand = importChecked(Err, E->getOperand()); |
| 6964 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 6965 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); |
| 6966 | if (Err) |
| 6967 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6968 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6969 | CanThrowResult ToCanThrow; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6970 | if (E->isValueDependent()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6971 | ToCanThrow = CT_Dependent; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6972 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6973 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6974 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6975 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 6976 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6977 | } |
| 6978 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6979 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 6980 | Error Err = Error::success(); |
| 6981 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 6982 | auto ToType = importChecked(Err, E->getType()); |
| 6983 | auto ToThrowLoc = importChecked(Err, E->getThrowLoc()); |
| 6984 | if (Err) |
| 6985 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6986 | |
| 6987 | return new (Importer.getToContext()) CXXThrowExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6988 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6989 | } |
| 6990 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6991 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 6992 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); |
| 6993 | if (!ToUsedLocOrErr) |
| 6994 | return ToUsedLocOrErr.takeError(); |
| 6995 | |
| 6996 | auto ToParamOrErr = import(E->getParam()); |
| 6997 | if (!ToParamOrErr) |
| 6998 | return ToParamOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6999 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7000 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); |
| 7001 | if (!UsedContextOrErr) |
| 7002 | return UsedContextOrErr.takeError(); |
| 7003 | |
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 7004 | // Import the default arg if it was not imported yet. |
| 7005 | // This is needed because it can happen that during the import of the |
| 7006 | // default expression (from VisitParmVarDecl) the same ParmVarDecl is |
| 7007 | // encountered here. The default argument for a ParmVarDecl is set in the |
| 7008 | // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here, |
| 7009 | // see VisitParmVarDecl). |
| 7010 | ParmVarDecl *ToParam = *ToParamOrErr; |
| 7011 | if (!ToParam->getDefaultArg()) { |
| 7012 | Optional<ParmVarDecl *> FromParam = Importer.getImportedFromDecl(ToParam); |
| 7013 | assert(FromParam && "ParmVarDecl was not imported?"); |
| 7014 | |
| 7015 | if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam)) |
| 7016 | return std::move(Err); |
| 7017 | } |
| 7018 | |
| 7019 | return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr, |
| 7020 | *ToParamOrErr, *UsedContextOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7021 | } |
| 7022 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7023 | ExpectedStmt |
| 7024 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7025 | Error Err = Error::success(); |
| 7026 | auto ToType = importChecked(Err, E->getType()); |
| 7027 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); |
| 7028 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7029 | if (Err) |
| 7030 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7031 | |
| 7032 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7033 | ToType, ToTypeSourceInfo, ToRParenLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7034 | } |
| 7035 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7036 | ExpectedStmt |
| 7037 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 7038 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7039 | if (!ToSubExprOrErr) |
| 7040 | return ToSubExprOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7041 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7042 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); |
| 7043 | if (!ToDtorOrErr) |
| 7044 | return ToDtorOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7045 | |
| 7046 | ASTContext &ToCtx = Importer.getToContext(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7047 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); |
| 7048 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7049 | } |
| 7050 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7051 | ExpectedStmt |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7052 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7053 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { |
| 7054 | Error Err = Error::success(); |
| 7055 | auto ToConstructor = importChecked(Err, E->getConstructor()); |
| 7056 | auto ToType = importChecked(Err, E->getType()); |
| 7057 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); |
| 7058 | auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange()); |
| 7059 | if (Err) |
| 7060 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7061 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7062 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); |
| 7063 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7064 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7065 | |
| Bruno Ricci | ddb8f6b | 2018-12-22 14:39:30 +0000 | [diff] [blame] | 7066 | return CXXTemporaryObjectExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7067 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, |
| 7068 | ToParenOrBraceRange, E->hadMultipleCandidates(), |
| 7069 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 7070 | E->requiresZeroInitialization()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7071 | } |
| 7072 | |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7073 | ExpectedDecl ASTNodeImporter::VisitLifetimeExtendedTemporaryDecl( |
| 7074 | LifetimeExtendedTemporaryDecl *D) { |
| 7075 | DeclContext *DC, *LexicalDC; |
| 7076 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 7077 | return std::move(Err); |
| 7078 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7079 | Error Err = Error::success(); |
| 7080 | auto Temporary = importChecked(Err, D->getTemporaryExpr()); |
| 7081 | auto ExtendingDecl = importChecked(Err, D->getExtendingDecl()); |
| 7082 | if (Err) |
| 7083 | return std::move(Err); |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7084 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
| 7085 | |
| 7086 | LifetimeExtendedTemporaryDecl *To; |
| 7087 | if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl, |
| 7088 | D->getManglingNumber())) |
| 7089 | return To; |
| 7090 | |
| 7091 | To->setLexicalDeclContext(LexicalDC); |
| 7092 | LexicalDC->addDeclInternal(To); |
| 7093 | return To; |
| 7094 | } |
| 7095 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7096 | ExpectedStmt |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7097 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7098 | Error Err = Error::success(); |
| 7099 | auto ToType = importChecked(Err, E->getType()); |
| 7100 | Expr *ToTemporaryExpr = importChecked( |
| 7101 | Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr()); |
| 7102 | auto ToMaterializedDecl = |
| 7103 | importChecked(Err, E->getLifetimeExtendedTemporaryDecl()); |
| 7104 | if (Err) |
| 7105 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7106 | |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7107 | if (!ToTemporaryExpr) |
| 7108 | ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7109 | |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7110 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
| 7111 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference(), |
| 7112 | ToMaterializedDecl); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7113 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7114 | return ToMTE; |
| 7115 | } |
| 7116 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7117 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7118 | Error Err = Error::success(); |
| 7119 | auto ToType = importChecked(Err, E->getType()); |
| 7120 | auto ToPattern = importChecked(Err, E->getPattern()); |
| 7121 | auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc()); |
| 7122 | if (Err) |
| 7123 | return std::move(Err); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7124 | |
| 7125 | return new (Importer.getToContext()) PackExpansionExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7126 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7127 | } |
| 7128 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7129 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7130 | Error Err = Error::success(); |
| 7131 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7132 | auto ToPack = importChecked(Err, E->getPack()); |
| 7133 | auto ToPackLoc = importChecked(Err, E->getPackLoc()); |
| 7134 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7135 | if (Err) |
| 7136 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7137 | |
| 7138 | Optional<unsigned> Length; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7139 | if (!E->isValueDependent()) |
| 7140 | Length = E->getPackLength(); |
| 7141 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7142 | SmallVector<TemplateArgument, 8> ToPartialArguments; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7143 | if (E->isPartiallySubstituted()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7144 | if (Error Err = ImportTemplateArguments( |
| 7145 | E->getPartialArguments().data(), |
| 7146 | E->getPartialArguments().size(), |
| 7147 | ToPartialArguments)) |
| 7148 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7149 | } |
| 7150 | |
| 7151 | return SizeOfPackExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7152 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, |
| 7153 | Length, ToPartialArguments); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7154 | } |
| 7155 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7156 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7157 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7158 | Error Err = Error::success(); |
| 7159 | auto ToOperatorNew = importChecked(Err, E->getOperatorNew()); |
| 7160 | auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete()); |
| 7161 | auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens()); |
| 7162 | auto ToArraySize = importChecked(Err, E->getArraySize()); |
| 7163 | auto ToInitializer = importChecked(Err, E->getInitializer()); |
| 7164 | auto ToType = importChecked(Err, E->getType()); |
| 7165 | auto ToAllocatedTypeSourceInfo = |
| 7166 | importChecked(Err, E->getAllocatedTypeSourceInfo()); |
| 7167 | auto ToSourceRange = importChecked(Err, E->getSourceRange()); |
| 7168 | auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange()); |
| 7169 | if (Err) |
| 7170 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7171 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7172 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); |
| 7173 | if (Error Err = |
| 7174 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) |
| 7175 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7176 | |
| Bruno Ricci | 9b6dfac | 2019-01-07 15:04:45 +0000 | [diff] [blame] | 7177 | return CXXNewExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7178 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, |
| 7179 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), |
| 7180 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), |
| 7181 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, |
| 7182 | ToDirectInitRange); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7183 | } |
| 7184 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7185 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7186 | Error Err = Error::success(); |
| 7187 | auto ToType = importChecked(Err, E->getType()); |
| 7188 | auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete()); |
| 7189 | auto ToArgument = importChecked(Err, E->getArgument()); |
| 7190 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 7191 | if (Err) |
| 7192 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7193 | |
| 7194 | return new (Importer.getToContext()) CXXDeleteExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7195 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), |
| 7196 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, |
| 7197 | ToBeginLoc); |
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 7198 | } |
| 7199 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7200 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7201 | Error Err = Error::success(); |
| 7202 | auto ToType = importChecked(Err, E->getType()); |
| 7203 | auto ToLocation = importChecked(Err, E->getLocation()); |
| 7204 | auto ToConstructor = importChecked(Err, E->getConstructor()); |
| 7205 | auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange()); |
| 7206 | if (Err) |
| 7207 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7208 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7209 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7210 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7211 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7212 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7213 | return CXXConstructExpr::Create( |
| 7214 | Importer.getToContext(), ToType, ToLocation, ToConstructor, |
| 7215 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), |
| 7216 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 7217 | E->requiresZeroInitialization(), E->getConstructionKind(), |
| 7218 | ToParenOrBraceRange); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7219 | } |
| 7220 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7221 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { |
| 7222 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7223 | if (!ToSubExprOrErr) |
| 7224 | return ToSubExprOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7225 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7226 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); |
| 7227 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) |
| 7228 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7229 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7230 | return ExprWithCleanups::Create( |
| 7231 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), |
| 7232 | ToObjects); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7233 | } |
| 7234 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7235 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7236 | Error Err = Error::success(); |
| 7237 | auto ToCallee = importChecked(Err, E->getCallee()); |
| 7238 | auto ToType = importChecked(Err, E->getType()); |
| 7239 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7240 | if (Err) |
| 7241 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7242 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7243 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7244 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7245 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7246 | |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7247 | return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, |
| 7248 | ToType, E->getValueKind(), ToRParenLoc); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7249 | } |
| 7250 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7251 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 7252 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7253 | if (!ToTypeOrErr) |
| 7254 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7255 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7256 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7257 | if (!ToLocationOrErr) |
| 7258 | return ToLocationOrErr.takeError(); |
| 7259 | |
| 7260 | return new (Importer.getToContext()) CXXThisExpr( |
| 7261 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7262 | } |
| 7263 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7264 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 7265 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7266 | if (!ToTypeOrErr) |
| 7267 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7268 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7269 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7270 | if (!ToLocationOrErr) |
| 7271 | return ToLocationOrErr.takeError(); |
| 7272 | |
| 7273 | return new (Importer.getToContext()) CXXBoolLiteralExpr( |
| 7274 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7275 | } |
| 7276 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7277 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7278 | Error Err = Error::success(); |
| 7279 | auto ToBase = importChecked(Err, E->getBase()); |
| 7280 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7281 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 7282 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); |
| 7283 | auto ToMemberDecl = importChecked(Err, E->getMemberDecl()); |
| 7284 | auto ToType = importChecked(Err, E->getType()); |
| 7285 | auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl()); |
| 7286 | auto ToName = importChecked(Err, E->getMemberNameInfo().getName()); |
| 7287 | auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc()); |
| 7288 | if (Err) |
| 7289 | return std::move(Err); |
| Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 7290 | |
| 7291 | DeclAccessPair ToFoundDecl = |
| 7292 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7293 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7294 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7295 | |
| Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7296 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7297 | if (E->hasExplicitTemplateArgs()) { |
| Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7298 | if (Error Err = |
| 7299 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 7300 | E->template_arguments(), ToTAInfo)) |
| 7301 | return std::move(Err); |
| 7302 | ResInfo = &ToTAInfo; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7303 | } |
| 7304 | |
| Richard Smith | 1bbad59 | 2019-06-11 17:50:36 +0000 | [diff] [blame] | 7305 | return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(), |
| 7306 | ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7307 | ToMemberDecl, ToFoundDecl, ToMemberNameInfo, |
| 7308 | ResInfo, ToType, E->getValueKind(), |
| 7309 | E->getObjectKind(), E->isNonOdrUse()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7310 | } |
| 7311 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7312 | ExpectedStmt |
| 7313 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7314 | Error Err = Error::success(); |
| 7315 | auto ToBase = importChecked(Err, E->getBase()); |
| 7316 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7317 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 7318 | auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo()); |
| 7319 | auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc()); |
| 7320 | auto ToTildeLoc = importChecked(Err, E->getTildeLoc()); |
| 7321 | if (Err) |
| 7322 | return std::move(Err); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7323 | |
| 7324 | PseudoDestructorTypeStorage Storage; |
| 7325 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 7326 | IdentifierInfo *ToII = Importer.Import(FromII); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7327 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); |
| 7328 | if (!ToDestroyedTypeLocOrErr) |
| 7329 | return ToDestroyedTypeLocOrErr.takeError(); |
| 7330 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7331 | } else { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7332 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) |
| 7333 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); |
| 7334 | else |
| 7335 | return ToTIOrErr.takeError(); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7336 | } |
| 7337 | |
| 7338 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7339 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7340 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7341 | } |
| 7342 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7343 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7344 | CXXDependentScopeMemberExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7345 | Error Err = Error::success(); |
| 7346 | auto ToType = importChecked(Err, E->getType()); |
| 7347 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7348 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 7349 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); |
| 7350 | auto ToFirstQualifierFoundInScope = |
| 7351 | importChecked(Err, E->getFirstQualifierFoundInScope()); |
| 7352 | if (Err) |
| 7353 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7354 | |
| 7355 | Expr *ToBase = nullptr; |
| 7356 | if (!E->isImplicitAccess()) { |
| 7357 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7358 | ToBase = *ToBaseOrErr; |
| 7359 | else |
| 7360 | return ToBaseOrErr.takeError(); |
| 7361 | } |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7362 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7363 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7364 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7365 | if (E->hasExplicitTemplateArgs()) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7366 | if (Error Err = |
| 7367 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 7368 | E->template_arguments(), ToTAInfo)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7369 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7370 | ResInfo = &ToTAInfo; |
| 7371 | } |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7372 | auto ToMember = importChecked(Err, E->getMember()); |
| 7373 | auto ToMemberLoc = importChecked(Err, E->getMemberLoc()); |
| 7374 | if (Err) |
| 7375 | return std::move(Err); |
| 7376 | DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7377 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7378 | // Import additional name location/type info. |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7379 | if (Error Err = |
| 7380 | ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7381 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7382 | |
| 7383 | return CXXDependentScopeMemberExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7384 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, |
| 7385 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, |
| 7386 | ToMemberNameInfo, ResInfo); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7387 | } |
| 7388 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7389 | ExpectedStmt |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7390 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7391 | Error Err = Error::success(); |
| 7392 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 7393 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); |
| 7394 | auto ToDeclName = importChecked(Err, E->getDeclName()); |
| 7395 | auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc()); |
| 7396 | auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc()); |
| 7397 | auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc()); |
| 7398 | if (Err) |
| 7399 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7400 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7401 | DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7402 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7403 | return std::move(Err); |
| 7404 | |
| 7405 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7406 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7407 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7408 | if (Error Err = |
| 7409 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7410 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7411 | ResInfo = &ToTAInfo; |
| 7412 | } |
| 7413 | |
| 7414 | return DependentScopeDeclRefExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7415 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, |
| 7416 | ToNameInfo, ResInfo); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7417 | } |
| 7418 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7419 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 7420 | CXXUnresolvedConstructExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7421 | Error Err = Error::success(); |
| 7422 | auto ToLParenLoc = importChecked(Err, E->getLParenLoc()); |
| 7423 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7424 | auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo()); |
| 7425 | if (Err) |
| 7426 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7427 | |
| 7428 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); |
| 7429 | if (Error Err = |
| 7430 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) |
| 7431 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7432 | |
| 7433 | return CXXUnresolvedConstructExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7434 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, |
| 7435 | llvm::makeArrayRef(ToArgs), ToRParenLoc); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7436 | } |
| 7437 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7438 | ExpectedStmt |
| 7439 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
| 7440 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); |
| 7441 | if (!ToNamingClassOrErr) |
| 7442 | return ToNamingClassOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7443 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7444 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); |
| 7445 | if (!ToQualifierLocOrErr) |
| 7446 | return ToQualifierLocOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7447 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7448 | Error Err = Error::success(); |
| 7449 | auto ToName = importChecked(Err, E->getName()); |
| 7450 | auto ToNameLoc = importChecked(Err, E->getNameLoc()); |
| 7451 | if (Err) |
| 7452 | return std::move(Err); |
| 7453 | DeclarationNameInfo ToNameInfo(ToName, ToNameLoc); |
| 7454 | |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7455 | // Import additional name location/type info. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7456 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7457 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7458 | |
| 7459 | UnresolvedSet<8> ToDecls; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7460 | for (auto *D : E->decls()) |
| 7461 | if (auto ToDOrErr = import(D)) |
| 7462 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7463 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7464 | return ToDOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7465 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7466 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7467 | TemplateArgumentListInfo ToTAInfo; |
| 7468 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7469 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7470 | ToTAInfo)) |
| 7471 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7472 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7473 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); |
| 7474 | if (!ToTemplateKeywordLocOrErr) |
| 7475 | return ToTemplateKeywordLocOrErr.takeError(); |
| 7476 | |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7477 | return UnresolvedLookupExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7478 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7479 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, |
| 7480 | ToDecls.begin(), ToDecls.end()); |
| 7481 | } |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7482 | |
| 7483 | return UnresolvedLookupExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7484 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7485 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), |
| 7486 | ToDecls.end()); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7487 | } |
| 7488 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7489 | ExpectedStmt |
| 7490 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7491 | Error Err = Error::success(); |
| 7492 | auto ToType = importChecked(Err, E->getType()); |
| 7493 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7494 | auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc()); |
| 7495 | auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc()); |
| 7496 | auto ToName = importChecked(Err, E->getName()); |
| 7497 | auto ToNameLoc = importChecked(Err, E->getNameLoc()); |
| 7498 | if (Err) |
| 7499 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7500 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7501 | DeclarationNameInfo ToNameInfo(ToName, ToNameLoc); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7502 | // Import additional name location/type info. |
| 7503 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7504 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7505 | |
| 7506 | UnresolvedSet<8> ToDecls; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7507 | for (Decl *D : E->decls()) |
| 7508 | if (auto ToDOrErr = import(D)) |
| 7509 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7510 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7511 | return ToDOrErr.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7512 | |
| 7513 | TemplateArgumentListInfo ToTAInfo; |
| 7514 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7515 | if (E->hasExplicitTemplateArgs()) { |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7516 | TemplateArgumentListInfo FromTAInfo; |
| 7517 | E->copyTemplateArgumentsInto(FromTAInfo); |
| 7518 | if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7519 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7520 | ResInfo = &ToTAInfo; |
| 7521 | } |
| 7522 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7523 | Expr *ToBase = nullptr; |
| 7524 | if (!E->isImplicitAccess()) { |
| 7525 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7526 | ToBase = *ToBaseOrErr; |
| 7527 | else |
| 7528 | return ToBaseOrErr.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7529 | } |
| 7530 | |
| 7531 | return UnresolvedMemberExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7532 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, |
| 7533 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7534 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7535 | } |
| 7536 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7537 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7538 | Error Err = Error::success(); |
| 7539 | auto ToCallee = importChecked(Err, E->getCallee()); |
| 7540 | auto ToType = importChecked(Err, E->getType()); |
| 7541 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7542 | if (Err) |
| 7543 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7544 | |
| 7545 | unsigned NumArgs = E->getNumArgs(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7546 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 7547 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7548 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7549 | |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7550 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7551 | return CXXOperatorCallExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7552 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, |
| Eric Fiselier | 5cdc2cd | 2018-12-12 21:50:55 +0000 | [diff] [blame] | 7553 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), |
| 7554 | OCE->getADLCallKind()); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7555 | } |
| 7556 | |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7557 | return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType, |
| 7558 | E->getValueKind(), ToRParenLoc, /*MinNumArgs=*/0, |
| 7559 | E->getADLCallKind()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7560 | } |
| 7561 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7562 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { |
| 7563 | CXXRecordDecl *FromClass = E->getLambdaClass(); |
| 7564 | auto ToClassOrErr = import(FromClass); |
| 7565 | if (!ToClassOrErr) |
| 7566 | return ToClassOrErr.takeError(); |
| 7567 | CXXRecordDecl *ToClass = *ToClassOrErr; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7568 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7569 | auto ToCallOpOrErr = import(E->getCallOperator()); |
| 7570 | if (!ToCallOpOrErr) |
| 7571 | return ToCallOpOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7572 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7573 | SmallVector<LambdaCapture, 8> ToCaptures; |
| 7574 | ToCaptures.reserve(E->capture_size()); |
| 7575 | for (const auto &FromCapture : E->captures()) { |
| 7576 | if (auto ToCaptureOrErr = import(FromCapture)) |
| 7577 | ToCaptures.push_back(*ToCaptureOrErr); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7578 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7579 | return ToCaptureOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7580 | } |
| 7581 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7582 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); |
| 7583 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) |
| 7584 | return std::move(Err); |
| 7585 | |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7586 | Error Err = Error::success(); |
| 7587 | auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange()); |
| 7588 | auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc()); |
| 7589 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); |
| 7590 | if (Err) |
| 7591 | return std::move(Err); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7592 | |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7593 | return LambdaExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7594 | Importer.getToContext(), ToClass, ToIntroducerRange, |
| 7595 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, |
| 7596 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, |
| 7597 | ToEndLoc, E->containsUnexpandedParameterPack()); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7598 | } |
| 7599 | |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7600 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7601 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7602 | Error Err = Error::success(); |
| 7603 | auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc()); |
| 7604 | auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc()); |
| 7605 | auto ToType = importChecked(Err, E->getType()); |
| 7606 | if (Err) |
| 7607 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7608 | |
| 7609 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); |
| 7610 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) |
| 7611 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7612 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7613 | ASTContext &ToCtx = Importer.getToContext(); |
| 7614 | InitListExpr *To = new (ToCtx) InitListExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7615 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); |
| 7616 | To->setType(ToType); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7617 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7618 | if (E->hasArrayFiller()) { |
| 7619 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) |
| 7620 | To->setArrayFiller(*ToFillerOrErr); |
| 7621 | else |
| 7622 | return ToFillerOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7623 | } |
| 7624 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7625 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { |
| 7626 | if (auto ToFDOrErr = import(FromFD)) |
| 7627 | To->setInitializedFieldInUnion(*ToFDOrErr); |
| 7628 | else |
| 7629 | return ToFDOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7630 | } |
| 7631 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7632 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { |
| 7633 | if (auto ToSyntFormOrErr = import(SyntForm)) |
| 7634 | To->setSyntacticForm(*ToSyntFormOrErr); |
| 7635 | else |
| 7636 | return ToSyntFormOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7637 | } |
| 7638 | |
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7639 | // Copy InitListExprBitfields, which are not handled in the ctor of |
| 7640 | // InitListExpr. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7641 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7642 | |
| 7643 | return To; |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7644 | } |
| 7645 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7646 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7647 | CXXStdInitializerListExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7648 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7649 | if (!ToTypeOrErr) |
| 7650 | return ToTypeOrErr.takeError(); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7651 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7652 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7653 | if (!ToSubExprOrErr) |
| 7654 | return ToSubExprOrErr.takeError(); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7655 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7656 | return new (Importer.getToContext()) CXXStdInitializerListExpr( |
| 7657 | *ToTypeOrErr, *ToSubExprOrErr); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7658 | } |
| 7659 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7660 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7661 | CXXInheritedCtorInitExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7662 | Error Err = Error::success(); |
| 7663 | auto ToLocation = importChecked(Err, E->getLocation()); |
| 7664 | auto ToType = importChecked(Err, E->getType()); |
| 7665 | auto ToConstructor = importChecked(Err, E->getConstructor()); |
| 7666 | if (Err) |
| 7667 | return std::move(Err); |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7668 | |
| 7669 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7670 | ToLocation, ToType, ToConstructor, E->constructsVBase(), |
| 7671 | E->inheritedFromVBase()); |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7672 | } |
| 7673 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7674 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7675 | Error Err = Error::success(); |
| 7676 | auto ToType = importChecked(Err, E->getType()); |
| 7677 | auto ToCommonExpr = importChecked(Err, E->getCommonExpr()); |
| 7678 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 7679 | if (Err) |
| 7680 | return std::move(Err); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7681 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7682 | return new (Importer.getToContext()) ArrayInitLoopExpr( |
| 7683 | ToType, ToCommonExpr, ToSubExpr); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7684 | } |
| 7685 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7686 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 7687 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7688 | if (!ToTypeOrErr) |
| 7689 | return ToTypeOrErr.takeError(); |
| 7690 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7691 | } |
| 7692 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7693 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7694 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); |
| 7695 | if (!ToBeginLocOrErr) |
| 7696 | return ToBeginLocOrErr.takeError(); |
| 7697 | |
| 7698 | auto ToFieldOrErr = import(E->getField()); |
| 7699 | if (!ToFieldOrErr) |
| 7700 | return ToFieldOrErr.takeError(); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7701 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7702 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); |
| 7703 | if (!UsedContextOrErr) |
| 7704 | return UsedContextOrErr.takeError(); |
| 7705 | |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7706 | return CXXDefaultInitExpr::Create( |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7707 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr, *UsedContextOrErr); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7708 | } |
| 7709 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7710 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7711 | Error Err = Error::success(); |
| 7712 | auto ToType = importChecked(Err, E->getType()); |
| 7713 | auto ToSubExpr = importChecked(Err, E->getSubExpr()); |
| 7714 | auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten()); |
| 7715 | auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc()); |
| 7716 | auto ToRParenLoc = importChecked(Err, E->getRParenLoc()); |
| 7717 | auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets()); |
| 7718 | if (Err) |
| 7719 | return std::move(Err); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7720 | |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7721 | ExprValueKind VK = E->getValueKind(); |
| 7722 | CastKind CK = E->getCastKind(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7723 | auto ToBasePathOrErr = ImportCastPath(E); |
| 7724 | if (!ToBasePathOrErr) |
| 7725 | return ToBasePathOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7726 | |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7727 | if (isa<CXXStaticCastExpr>(E)) { |
| 7728 | return CXXStaticCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7729 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7730 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7731 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 7732 | return CXXDynamicCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7733 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7734 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7735 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 7736 | return CXXReinterpretCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7737 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7738 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 7739 | } else if (isa<CXXConstCastExpr>(E)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7740 | return CXXConstCastExpr::Create( |
| 7741 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, |
| 7742 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7743 | } else { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7744 | llvm_unreachable("Unknown cast type"); |
| 7745 | return make_error<ImportError>(); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7746 | } |
| 7747 | } |
| 7748 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7749 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7750 | SubstNonTypeTemplateParmExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7751 | Error Err = Error::success(); |
| 7752 | auto ToType = importChecked(Err, E->getType()); |
| 7753 | auto ToExprLoc = importChecked(Err, E->getExprLoc()); |
| 7754 | auto ToParameter = importChecked(Err, E->getParameter()); |
| 7755 | auto ToReplacement = importChecked(Err, E->getReplacement()); |
| 7756 | if (Err) |
| 7757 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7758 | |
| 7759 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7760 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7761 | } |
| 7762 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7763 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| Reid Kleckner | 1091730 | 2020-02-04 15:22:15 -0800 | [diff] [blame] | 7764 | Error Err = Error::success(); |
| 7765 | auto ToType = importChecked(Err, E->getType()); |
| 7766 | auto ToBeginLoc = importChecked(Err, E->getBeginLoc()); |
| 7767 | auto ToEndLoc = importChecked(Err, E->getEndLoc()); |
| 7768 | if (Err) |
| 7769 | return std::move(Err); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7770 | |
| 7771 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7772 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) |
| 7773 | return std::move(Err); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7774 | |
| 7775 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 7776 | // Value is always false. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7777 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7778 | |
| 7779 | return TypeTraitExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7780 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, |
| 7781 | ToEndLoc, ToValue); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7782 | } |
| 7783 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7784 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 7785 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7786 | if (!ToTypeOrErr) |
| 7787 | return ToTypeOrErr.takeError(); |
| 7788 | |
| 7789 | auto ToSourceRangeOrErr = import(E->getSourceRange()); |
| 7790 | if (!ToSourceRangeOrErr) |
| 7791 | return ToSourceRangeOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7792 | |
| 7793 | if (E->isTypeOperand()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7794 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) |
| 7795 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7796 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); |
| 7797 | else |
| 7798 | return ToTSIOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7799 | } |
| 7800 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7801 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); |
| 7802 | if (!ToExprOperandOrErr) |
| 7803 | return ToExprOperandOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7804 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7805 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7806 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7807 | } |
| 7808 | |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7809 | Error ASTNodeImporter::ImportOverriddenMethods(CXXMethodDecl *ToMethod, |
| 7810 | CXXMethodDecl *FromMethod) { |
| 7811 | Error ImportErrors = Error::success(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7812 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { |
| 7813 | if (auto ImportedOrErr = import(FromOverriddenMethod)) |
| 7814 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( |
| 7815 | (*ImportedOrErr)->getCanonicalDecl())); |
| 7816 | else |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7817 | ImportErrors = |
| 7818 | joinErrors(std::move(ImportErrors), ImportedOrErr.takeError()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7819 | } |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7820 | return ImportErrors; |
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7821 | } |
| 7822 | |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7823 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7824 | ASTContext &FromContext, FileManager &FromFileManager, |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7825 | bool MinimalImport, |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7826 | std::shared_ptr<ASTImporterSharedState> SharedState) |
| 7827 | : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext), |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7828 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 7829 | Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) { |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7830 | |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7831 | // Create a default state without the lookup table: LLDB case. |
| 7832 | if (!SharedState) { |
| 7833 | this->SharedState = std::make_shared<ASTImporterSharedState>(); |
| 7834 | } |
| 7835 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7836 | ImportedDecls[FromContext.getTranslationUnitDecl()] = |
| 7837 | ToContext.getTranslationUnitDecl(); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7838 | } |
| 7839 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7840 | ASTImporter::~ASTImporter() = default; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7841 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7842 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { |
| 7843 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && |
| 7844 | "Try to get field index for non-field."); |
| 7845 | |
| 7846 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 7847 | if (!Owner) |
| 7848 | return None; |
| 7849 | |
| 7850 | unsigned Index = 0; |
| 7851 | for (const auto *D : Owner->decls()) { |
| 7852 | if (D == F) |
| 7853 | return Index; |
| 7854 | |
| 7855 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 7856 | ++Index; |
| 7857 | } |
| 7858 | |
| 7859 | llvm_unreachable("Field was not found in its parent context."); |
| 7860 | |
| 7861 | return None; |
| 7862 | } |
| 7863 | |
| 7864 | ASTImporter::FoundDeclsTy |
| 7865 | ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) { |
| 7866 | // We search in the redecl context because of transparent contexts. |
| 7867 | // E.g. a simple C language enum is a transparent context: |
| 7868 | // enum E { A, B }; |
| 7869 | // Now if we had a global variable in the TU |
| 7870 | // int A; |
| 7871 | // then the enum constant 'A' and the variable 'A' violates ODR. |
| 7872 | // We can diagnose this only if we search in the redecl context. |
| 7873 | DeclContext *ReDC = DC->getRedeclContext(); |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7874 | if (SharedState->getLookupTable()) { |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7875 | ASTImporterLookupTable::LookupResult LookupResult = |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7876 | SharedState->getLookupTable()->lookup(ReDC, Name); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7877 | return FoundDeclsTy(LookupResult.begin(), LookupResult.end()); |
| 7878 | } else { |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 7879 | DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name); |
| 7880 | FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end()); |
| 7881 | // We must search by the slow case of localUncachedLookup because that is |
| 7882 | // working even if there is no LookupPtr for the DC. We could use |
| 7883 | // DC::buildLookup() to create the LookupPtr, but that would load external |
| 7884 | // decls again, we must avoid that case. |
| 7885 | // Also, even if we had the LookupPtr, we must find Decls which are not |
| 7886 | // in the LookupPtr, so we need the slow case. |
| 7887 | // These cases are handled in ASTImporterLookupTable, but we cannot use |
| 7888 | // that with LLDB since that traverses through the AST which initiates the |
| 7889 | // load of external decls again via DC::decls(). And again, we must avoid |
| 7890 | // loading external decls during the import. |
| 7891 | if (Result.empty()) |
| 7892 | ReDC->localUncachedLookup(Name, Result); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7893 | return Result; |
| 7894 | } |
| 7895 | } |
| 7896 | |
| 7897 | void ASTImporter::AddToLookupTable(Decl *ToD) { |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7898 | SharedState->addDeclToLookup(ToD); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7899 | } |
| 7900 | |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7901 | Expected<Decl *> ASTImporter::ImportImpl(Decl *FromD) { |
| 7902 | // Import the decl using ASTNodeImporter. |
| 7903 | ASTNodeImporter Importer(*this); |
| 7904 | return Importer.Visit(FromD); |
| 7905 | } |
| 7906 | |
| 7907 | void ASTImporter::RegisterImportedDecl(Decl *FromD, Decl *ToD) { |
| 7908 | MapImported(FromD, ToD); |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7909 | } |
| 7910 | |
| Akira Hatanaka | 40568fe | 2020-03-10 14:06:25 -0700 | [diff] [blame] | 7911 | llvm::Expected<ExprWithCleanups::CleanupObject> |
| 7912 | ASTImporter::Import(ExprWithCleanups::CleanupObject From) { |
| 7913 | if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) { |
| 7914 | if (Expected<Expr *> R = Import(CLE)) |
| 7915 | return ExprWithCleanups::CleanupObject(cast<CompoundLiteralExpr>(*R)); |
| 7916 | } |
| 7917 | |
| 7918 | // FIXME: Handle BlockDecl when we implement importing BlockExpr in |
| 7919 | // ASTNodeImporter. |
| 7920 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| 7921 | } |
| 7922 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7923 | Expected<QualType> ASTImporter::Import(QualType FromT) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7924 | if (FromT.isNull()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7925 | return QualType{}; |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7926 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7927 | const Type *FromTy = FromT.getTypePtr(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7928 | |
| 7929 | // Check whether we've already imported this type. |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7930 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7931 | = ImportedTypes.find(FromTy); |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7932 | if (Pos != ImportedTypes.end()) |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7933 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7934 | |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7935 | // Import the type |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7936 | ASTNodeImporter Importer(*this); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7937 | ExpectedType ToTOrErr = Importer.Visit(FromTy); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7938 | if (!ToTOrErr) |
| 7939 | return ToTOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7940 | |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7941 | // Record the imported type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7942 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7943 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7944 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7945 | } |
| 7946 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7947 | Expected<TypeSourceInfo *> ASTImporter::Import(TypeSourceInfo *FromTSI) { |
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7948 | if (!FromTSI) |
| 7949 | return FromTSI; |
| 7950 | |
| 7951 | // FIXME: For now we just create a "trivial" type source info based |
| Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 7952 | // 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] | 7953 | ExpectedType TOrErr = Import(FromTSI->getType()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7954 | if (!TOrErr) |
| 7955 | return TOrErr.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7956 | ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7957 | if (!BeginLocOrErr) |
| 7958 | return BeginLocOrErr.takeError(); |
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7959 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7960 | return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr); |
| 7961 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7962 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7963 | Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) { |
| Balázs Kéri | b17f292 | 2020-02-28 08:32:32 +0100 | [diff] [blame] | 7964 | Attr *ToAttr = nullptr; |
| 7965 | SourceRange ToRange; |
| 7966 | if (Error Err = importInto(ToRange, FromAttr->getRange())) |
| 7967 | return std::move(Err); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7968 | |
| Balázs Kéri | b17f292 | 2020-02-28 08:32:32 +0100 | [diff] [blame] | 7969 | // FIXME: Is there some kind of AttrVisitor to use here? |
| 7970 | switch (FromAttr->getKind()) { |
| 7971 | case attr::Aligned: { |
| 7972 | auto *From = cast<AlignedAttr>(FromAttr); |
| 7973 | AlignedAttr *To; |
| 7974 | auto CreateAlign = [&](bool IsAlignmentExpr, void *Alignment) { |
| 7975 | return AlignedAttr::Create(ToContext, IsAlignmentExpr, Alignment, ToRange, |
| 7976 | From->getSyntax(), |
| 7977 | From->getSemanticSpelling()); |
| 7978 | }; |
| 7979 | if (From->isAlignmentExpr()) { |
| 7980 | if (auto ToEOrErr = Import(From->getAlignmentExpr())) |
| 7981 | To = CreateAlign(true, *ToEOrErr); |
| 7982 | else |
| 7983 | return ToEOrErr.takeError(); |
| 7984 | } else { |
| 7985 | if (auto ToTOrErr = Import(From->getAlignmentType())) |
| 7986 | To = CreateAlign(false, *ToTOrErr); |
| 7987 | else |
| 7988 | return ToTOrErr.takeError(); |
| 7989 | } |
| 7990 | To->setInherited(From->isInherited()); |
| 7991 | To->setPackExpansion(From->isPackExpansion()); |
| 7992 | To->setImplicit(From->isImplicit()); |
| 7993 | ToAttr = To; |
| 7994 | break; |
| 7995 | } |
| 7996 | default: |
| 7997 | // FIXME: 'clone' copies every member but some of them should be imported. |
| 7998 | // Handle other Attrs that have parameters that should be imported. |
| 7999 | ToAttr = FromAttr->clone(ToContext); |
| 8000 | ToAttr->setRange(ToRange); |
| 8001 | break; |
| 8002 | } |
| 8003 | assert(ToAttr && "Attribute should be created."); |
| 8004 | |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8005 | return ToAttr; |
| Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8006 | } |
| Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 8007 | |
| Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 8008 | Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { |
| 8009 | auto Pos = ImportedDecls.find(FromD); |
| 8010 | if (Pos != ImportedDecls.end()) |
| 8011 | return Pos->second; |
| 8012 | else |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 8013 | return nullptr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 8014 | } |
| 8015 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 8016 | TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) { |
| 8017 | auto FromDPos = ImportedFromDecls.find(ToD); |
| 8018 | if (FromDPos == ImportedFromDecls.end()) |
| 8019 | return nullptr; |
| 8020 | return FromDPos->second->getTranslationUnitDecl(); |
| 8021 | } |
| 8022 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8023 | Expected<Decl *> ASTImporter::Import(Decl *FromD) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8024 | if (!FromD) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8025 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8026 | |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8027 | // Push FromD to the stack, and remove that when we return. |
| 8028 | ImportPath.push(FromD); |
| 8029 | auto ImportPathBuilder = |
| 8030 | llvm::make_scope_exit([this]() { ImportPath.pop(); }); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8031 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8032 | // Check whether there was a previous failed import. |
| 8033 | // If yes return the existing error. |
| 8034 | if (auto Error = getImportDeclErrorIfAny(FromD)) |
| 8035 | return make_error<ImportError>(*Error); |
| 8036 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8037 | // Check whether we've already imported this declaration. |
| 8038 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 8039 | if (ToD) { |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8040 | // Already imported (possibly from another TU) and with an error. |
| 8041 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { |
| 8042 | setImportDeclError(FromD, *Error); |
| 8043 | return make_error<ImportError>(*Error); |
| 8044 | } |
| 8045 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8046 | // If FromD has some updated flags after last import, apply it |
| 8047 | updateFlags(FromD, ToD); |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8048 | // If we encounter a cycle during an import then we save the relevant part |
| 8049 | // of the import path associated to the Decl. |
| 8050 | if (ImportPath.hasCycleAtBack()) |
| 8051 | SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack()); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8052 | return ToD; |
| 8053 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8054 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8055 | // Import the declaration. |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 8056 | ExpectedDecl ToDOrErr = ImportImpl(FromD); |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8057 | if (!ToDOrErr) { |
| 8058 | // Failed to import. |
| 8059 | |
| 8060 | auto Pos = ImportedDecls.find(FromD); |
| 8061 | if (Pos != ImportedDecls.end()) { |
| 8062 | // Import failed after the object was created. |
| 8063 | // Remove all references to it. |
| 8064 | auto *ToD = Pos->second; |
| 8065 | ImportedDecls.erase(Pos); |
| 8066 | |
| 8067 | // ImportedDecls and ImportedFromDecls are not symmetric. It may happen |
| 8068 | // (e.g. with namespaces) that several decls from the 'from' context are |
| 8069 | // mapped to the same decl in the 'to' context. If we removed entries |
| 8070 | // from the LookupTable here then we may end up removing them multiple |
| 8071 | // times. |
| 8072 | |
| 8073 | // The Lookuptable contains decls only which are in the 'to' context. |
| 8074 | // Remove from the Lookuptable only if it is *imported* into the 'to' |
| 8075 | // context (and do not remove it if it was added during the initial |
| 8076 | // traverse of the 'to' context). |
| 8077 | auto PosF = ImportedFromDecls.find(ToD); |
| 8078 | if (PosF != ImportedFromDecls.end()) { |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8079 | SharedState->removeDeclFromLookup(ToD); |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8080 | ImportedFromDecls.erase(PosF); |
| 8081 | } |
| 8082 | |
| 8083 | // FIXME: AST may contain remaining references to the failed object. |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8084 | // However, the ImportDeclErrors in the shared state contains all the |
| 8085 | // failed objects together with their error. |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8086 | } |
| 8087 | |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8088 | // Error encountered for the first time. |
| 8089 | // After takeError the error is not usable any more in ToDOrErr. |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8090 | // Get a copy of the error object (any more simple solution for this?). |
| 8091 | ImportError ErrOut; |
| 8092 | handleAllErrors(ToDOrErr.takeError(), |
| 8093 | [&ErrOut](const ImportError &E) { ErrOut = E; }); |
| 8094 | setImportDeclError(FromD, ErrOut); |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8095 | // Set the error for the mapped to Decl, which is in the "to" context. |
| 8096 | if (Pos != ImportedDecls.end()) |
| 8097 | SharedState->setImportDeclError(Pos->second, ErrOut); |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8098 | |
| 8099 | // Set the error for all nodes which have been created before we |
| 8100 | // recognized the error. |
| 8101 | for (const auto &Path : SavedImportPaths[FromD]) |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8102 | for (Decl *FromDi : Path) { |
| 8103 | setImportDeclError(FromDi, ErrOut); |
| 8104 | //FIXME Should we remove these Decls from ImportedDecls? |
| 8105 | // Set the error for the mapped to Decl, which is in the "to" context. |
| 8106 | auto Ii = ImportedDecls.find(FromDi); |
| 8107 | if (Ii != ImportedDecls.end()) |
| 8108 | SharedState->setImportDeclError(Ii->second, ErrOut); |
| 8109 | // FIXME Should we remove these Decls from the LookupTable, |
| 8110 | // and from ImportedFromDecls? |
| 8111 | } |
| Jaroslav Sevcik | 4481eef | 2020-01-22 15:19:44 +0100 | [diff] [blame] | 8112 | SavedImportPaths.erase(FromD); |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8113 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8114 | // Do not return ToDOrErr, error was taken out of it. |
| 8115 | return make_error<ImportError>(ErrOut); |
| 8116 | } |
| 8117 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8118 | ToD = *ToDOrErr; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8119 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8120 | // FIXME: Handle the "already imported with error" case. We can get here |
| 8121 | // nullptr only if GetImportedOrCreateDecl returned nullptr (after a |
| 8122 | // previously failed create was requested). |
| 8123 | // Later GetImportedOrCreateDecl can be updated to return the error. |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 8124 | if (!ToD) { |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8125 | auto Err = getImportDeclErrorIfAny(FromD); |
| 8126 | assert(Err); |
| 8127 | return make_error<ImportError>(*Err); |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 8128 | } |
| 8129 | |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8130 | // We could import from the current TU without error. But previously we |
| 8131 | // already had imported a Decl as `ToD` from another TU (with another |
| 8132 | // ASTImporter object) and with an error. |
| 8133 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { |
| 8134 | setImportDeclError(FromD, *Error); |
| 8135 | return make_error<ImportError>(*Error); |
| 8136 | } |
| 8137 | |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 8138 | // Make sure that ImportImpl registered the imported decl. |
| 8139 | assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?"); |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8140 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8141 | // Notify subclasses. |
| 8142 | Imported(FromD, ToD); |
| 8143 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 8144 | updateFlags(FromD, ToD); |
| Jaroslav Sevcik | 4481eef | 2020-01-22 15:19:44 +0100 | [diff] [blame] | 8145 | SavedImportPaths.erase(FromD); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8146 | return ToDOrErr; |
| 8147 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8148 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8149 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8150 | if (!FromDC) |
| 8151 | return FromDC; |
| 8152 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8153 | ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC)); |
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8154 | if (!ToDCOrErr) |
| 8155 | return ToDCOrErr.takeError(); |
| 8156 | auto *ToDC = cast<DeclContext>(*ToDCOrErr); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8157 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8158 | // 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] | 8159 | // need it to have a definition. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8160 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 8161 | auto *FromRecord = cast<RecordDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8162 | if (ToRecord->isCompleteDefinition()) { |
| 8163 | // Do nothing. |
| 8164 | } else if (FromRecord->isCompleteDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8165 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8166 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) |
| 8167 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8168 | } else { |
| 8169 | CompleteDecl(ToRecord); |
| 8170 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8171 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 8172 | auto *FromEnum = cast<EnumDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8173 | if (ToEnum->isCompleteDefinition()) { |
| 8174 | // Do nothing. |
| 8175 | } else if (FromEnum->isCompleteDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8176 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8177 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) |
| 8178 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8179 | } else { |
| 8180 | CompleteDecl(ToEnum); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8181 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8182 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 8183 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8184 | if (ToClass->getDefinition()) { |
| 8185 | // Do nothing. |
| 8186 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8187 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8188 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) |
| 8189 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8190 | } else { |
| 8191 | CompleteDecl(ToClass); |
| 8192 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8193 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 8194 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8195 | if (ToProto->getDefinition()) { |
| 8196 | // Do nothing. |
| 8197 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8198 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8199 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) |
| 8200 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8201 | } else { |
| 8202 | CompleteDecl(ToProto); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8203 | } |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 8204 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8205 | |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 8206 | return ToDC; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8207 | } |
| 8208 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8209 | Expected<Expr *> ASTImporter::Import(Expr *FromE) { |
| 8210 | if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE))) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8211 | return cast_or_null<Expr>(*ToSOrErr); |
| 8212 | else |
| 8213 | return ToSOrErr.takeError(); |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8214 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8215 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8216 | Expected<Stmt *> ASTImporter::Import(Stmt *FromS) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8217 | if (!FromS) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8218 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8219 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8220 | // Check whether we've already imported this statement. |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 8221 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 8222 | if (Pos != ImportedStmts.end()) |
| 8223 | return Pos->second; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8224 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8225 | // Import the statement. |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 8226 | ASTNodeImporter Importer(*this); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8227 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8228 | if (!ToSOrErr) |
| 8229 | return ToSOrErr; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8230 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8231 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { |
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 8232 | auto *FromE = cast<Expr>(FromS); |
| 8233 | // Copy ExprBitfields, which may not be handled in Expr subclasses |
| 8234 | // constructors. |
| 8235 | ToE->setValueKind(FromE->getValueKind()); |
| 8236 | ToE->setObjectKind(FromE->getObjectKind()); |
| Ilya Biryukov | ec3060c | 2020-03-02 16:07:09 +0100 | [diff] [blame] | 8237 | ToE->setDependence(FromE->getDependence()); |
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 8238 | } |
| 8239 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8240 | // Record the imported statement object. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8241 | ImportedStmts[FromS] = *ToSOrErr; |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8242 | return ToSOrErr; |
| 8243 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8244 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8245 | Expected<NestedNameSpecifier *> |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8246 | ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8247 | if (!FromNNS) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8248 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8249 | |
| Simon Pilgrim | 130df2c | 2019-07-15 13:00:43 +0000 | [diff] [blame] | 8250 | NestedNameSpecifier *Prefix = nullptr; |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8251 | if (Error Err = importInto(Prefix, FromNNS->getPrefix())) |
| 8252 | return std::move(Err); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8253 | |
| 8254 | switch (FromNNS->getKind()) { |
| 8255 | case NestedNameSpecifier::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8256 | assert(FromNNS->getAsIdentifier() && "NNS should contain identifier."); |
| 8257 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8258 | Import(FromNNS->getAsIdentifier())); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8259 | |
| 8260 | case NestedNameSpecifier::Namespace: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8261 | if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8262 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8263 | cast<NamespaceDecl>(*NSOrErr)); |
| 8264 | } else |
| 8265 | return NSOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8266 | |
| 8267 | case NestedNameSpecifier::NamespaceAlias: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8268 | if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8269 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8270 | cast<NamespaceAliasDecl>(*NSADOrErr)); |
| 8271 | else |
| 8272 | return NSADOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8273 | |
| 8274 | case NestedNameSpecifier::Global: |
| 8275 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 8276 | |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8277 | case NestedNameSpecifier::Super: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8278 | if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8279 | return NestedNameSpecifier::SuperSpecifier(ToContext, |
| 8280 | cast<CXXRecordDecl>(*RDOrErr)); |
| 8281 | else |
| 8282 | return RDOrErr.takeError(); |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8283 | |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8284 | case NestedNameSpecifier::TypeSpec: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8285 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 8286 | if (Expected<QualType> TyOrErr = |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8287 | Import(QualType(FromNNS->getAsType(), 0u))) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8288 | bool TSTemplate = |
| 8289 | FromNNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate; |
| 8290 | return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate, |
| 8291 | TyOrErr->getTypePtr()); |
| 8292 | } else { |
| 8293 | return TyOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8294 | } |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8295 | } |
| 8296 | |
| 8297 | llvm_unreachable("Invalid nested name specifier kind"); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8298 | } |
| 8299 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8300 | Expected<NestedNameSpecifierLoc> |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8301 | ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8302 | // Copied from NestedNameSpecifier mostly. |
| 8303 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 8304 | NestedNameSpecifierLoc NNS = FromNNS; |
| 8305 | |
| 8306 | // Push each of the nested-name-specifiers's onto a stack for |
| 8307 | // serialization in reverse order. |
| 8308 | while (NNS) { |
| 8309 | NestedNames.push_back(NNS); |
| 8310 | NNS = NNS.getPrefix(); |
| 8311 | } |
| 8312 | |
| 8313 | NestedNameSpecifierLocBuilder Builder; |
| 8314 | |
| 8315 | while (!NestedNames.empty()) { |
| 8316 | NNS = NestedNames.pop_back_val(); |
| Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 8317 | NestedNameSpecifier *Spec = nullptr; |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8318 | if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier())) |
| 8319 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8320 | |
| 8321 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8322 | |
| 8323 | SourceLocation ToLocalBeginLoc, ToLocalEndLoc; |
| 8324 | if (Kind != NestedNameSpecifier::Super) { |
| 8325 | if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc())) |
| 8326 | return std::move(Err); |
| 8327 | |
| 8328 | if (Kind != NestedNameSpecifier::Global) |
| 8329 | if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc())) |
| 8330 | return std::move(Err); |
| 8331 | } |
| 8332 | |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8333 | switch (Kind) { |
| 8334 | case NestedNameSpecifier::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8335 | Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc, |
| 8336 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8337 | break; |
| 8338 | |
| 8339 | case NestedNameSpecifier::Namespace: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8340 | Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc, |
| 8341 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8342 | break; |
| 8343 | |
| 8344 | case NestedNameSpecifier::NamespaceAlias: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8345 | Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(), |
| 8346 | ToLocalBeginLoc, ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8347 | break; |
| 8348 | |
| 8349 | case NestedNameSpecifier::TypeSpec: |
| 8350 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8351 | SourceLocation ToTLoc; |
| 8352 | if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc())) |
| 8353 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8354 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8355 | QualType(Spec->getAsType(), 0), ToTLoc); |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 8356 | if (Kind == NestedNameSpecifier::TypeSpecWithTemplate) |
| 8357 | // ToLocalBeginLoc is here the location of the 'template' keyword. |
| 8358 | Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(), |
| 8359 | ToLocalEndLoc); |
| 8360 | else |
| 8361 | // No location for 'template' keyword here. |
| 8362 | Builder.Extend(getToContext(), SourceLocation{}, TSI->getTypeLoc(), |
| 8363 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8364 | break; |
| 8365 | } |
| 8366 | |
| 8367 | case NestedNameSpecifier::Global: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8368 | Builder.MakeGlobal(getToContext(), ToLocalBeginLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8369 | break; |
| 8370 | |
| 8371 | case NestedNameSpecifier::Super: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8372 | auto ToSourceRangeOrErr = Import(NNS.getSourceRange()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8373 | if (!ToSourceRangeOrErr) |
| 8374 | return ToSourceRangeOrErr.takeError(); |
| 8375 | |
| 8376 | Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(), |
| 8377 | ToSourceRangeOrErr->getBegin(), |
| 8378 | ToSourceRangeOrErr->getEnd()); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8379 | } |
| 8380 | } |
| 8381 | } |
| 8382 | |
| 8383 | return Builder.getWithLocInContext(getToContext()); |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 8384 | } |
| 8385 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8386 | Expected<TemplateName> ASTImporter::Import(TemplateName From) { |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8387 | switch (From.getKind()) { |
| 8388 | case TemplateName::Template: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8389 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8390 | return TemplateName(cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8391 | else |
| 8392 | return ToTemplateOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8393 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8394 | case TemplateName::OverloadedTemplate: { |
| 8395 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 8396 | UnresolvedSet<2> ToTemplates; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8397 | for (auto *I : *FromStorage) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8398 | if (auto ToOrErr = Import(I)) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8399 | ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr)); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8400 | else |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8401 | return ToOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8402 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8403 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8404 | ToTemplates.end()); |
| 8405 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8406 | |
| Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8407 | case TemplateName::AssumedTemplate: { |
| 8408 | AssumedTemplateStorage *FromStorage = From.getAsAssumedTemplateName(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8409 | auto DeclNameOrErr = Import(FromStorage->getDeclName()); |
| Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8410 | if (!DeclNameOrErr) |
| 8411 | return DeclNameOrErr.takeError(); |
| 8412 | return ToContext.getAssumedTemplateName(*DeclNameOrErr); |
| 8413 | } |
| 8414 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8415 | case TemplateName::QualifiedTemplate: { |
| 8416 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8417 | auto QualifierOrErr = Import(QTN->getQualifier()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8418 | if (!QualifierOrErr) |
| 8419 | return QualifierOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8420 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8421 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8422 | return ToContext.getQualifiedTemplateName( |
| 8423 | *QualifierOrErr, QTN->hasTemplateKeyword(), |
| 8424 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8425 | else |
| 8426 | return ToTemplateOrErr.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 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8429 | case TemplateName::DependentTemplate: { |
| 8430 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8431 | auto QualifierOrErr = Import(DTN->getQualifier()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8432 | if (!QualifierOrErr) |
| 8433 | return QualifierOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8434 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8435 | if (DTN->isIdentifier()) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8436 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8437 | Import(DTN->getIdentifier())); |
| 8438 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8439 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8440 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
| 8441 | DTN->getOperator()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8442 | } |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8443 | |
| 8444 | case TemplateName::SubstTemplateTemplateParm: { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8445 | SubstTemplateTemplateParmStorage *Subst = |
| 8446 | From.getAsSubstTemplateTemplateParm(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8447 | ExpectedDecl ParamOrErr = Import(Subst->getParameter()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8448 | if (!ParamOrErr) |
| 8449 | return ParamOrErr.takeError(); |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8450 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8451 | auto ReplacementOrErr = Import(Subst->getReplacement()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8452 | if (!ReplacementOrErr) |
| 8453 | return ReplacementOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8454 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8455 | return ToContext.getSubstTemplateTemplateParm( |
| 8456 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ReplacementOrErr); |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8457 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8458 | |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8459 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 8460 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 8461 | = From.getAsSubstTemplateTemplateParmPack(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8462 | ExpectedDecl ParamOrErr = Import(SubstPack->getParameterPack()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8463 | if (!ParamOrErr) |
| 8464 | return ParamOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8465 | |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8466 | ASTNodeImporter Importer(*this); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8467 | auto ArgPackOrErr = |
| 8468 | Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 8469 | if (!ArgPackOrErr) |
| 8470 | return ArgPackOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8471 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8472 | return ToContext.getSubstTemplateTemplateParmPack( |
| 8473 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ArgPackOrErr); |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8474 | } |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8475 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8476 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8477 | llvm_unreachable("Invalid template name kind"); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8478 | } |
| 8479 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8480 | Expected<SourceLocation> ASTImporter::Import(SourceLocation FromLoc) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8481 | if (FromLoc.isInvalid()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8482 | return SourceLocation{}; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8483 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8484 | SourceManager &FromSM = FromContext.getSourceManager(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8485 | bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8486 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8487 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8488 | Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8489 | if (!ToFileIDOrErr) |
| 8490 | return ToFileIDOrErr.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8491 | SourceManager &ToSM = ToContext.getSourceManager(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8492 | return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second); |
| 8493 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8494 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8495 | Expected<SourceRange> ASTImporter::Import(SourceRange FromRange) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8496 | SourceLocation ToBegin, ToEnd; |
| 8497 | if (Error Err = importInto(ToBegin, FromRange.getBegin())) |
| 8498 | return std::move(Err); |
| 8499 | if (Error Err = importInto(ToEnd, FromRange.getEnd())) |
| 8500 | return std::move(Err); |
| 8501 | |
| 8502 | return SourceRange(ToBegin, ToEnd); |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8503 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8504 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8505 | Expected<FileID> ASTImporter::Import(FileID FromID, bool IsBuiltin) { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8506 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8507 | if (Pos != ImportedFileIDs.end()) |
| 8508 | return Pos->second; |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8509 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8510 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 8511 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8512 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8513 | |
| 8514 | // Map the FromID to the "to" source manager. |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8515 | FileID ToID; |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8516 | if (FromSLoc.isExpansion()) { |
| 8517 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8518 | ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8519 | if (!ToSpLoc) |
| 8520 | return ToSpLoc.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8521 | ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8522 | if (!ToExLocS) |
| 8523 | return ToExLocS.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8524 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 8525 | SourceLocation MLoc; |
| 8526 | if (FromEx.isMacroArgExpansion()) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8527 | MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, TokenLen); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8528 | } else { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8529 | if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8530 | MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, TokenLen, |
| 8531 | FromEx.isExpansionTokenRange()); |
| 8532 | else |
| 8533 | return ToExLocE.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8534 | } |
| 8535 | ToID = ToSM.getFileID(MLoc); |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8536 | } else { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8537 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8538 | |
| 8539 | if (!IsBuiltin) { |
| 8540 | // Include location of this file. |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8541 | ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8542 | if (!ToIncludeLoc) |
| 8543 | return ToIncludeLoc.takeError(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8544 | |
| Raphael Isemann | a37734f | 2020-02-17 19:43:33 +0100 | [diff] [blame] | 8545 | // Every FileID that is not the main FileID needs to have a valid include |
| 8546 | // location so that the include chain points to the main FileID. When |
| 8547 | // importing the main FileID (which has no include location), we need to |
| 8548 | // create a fake include location in the main file to keep this property |
| 8549 | // intact. |
| 8550 | SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc; |
| 8551 | if (FromID == FromSM.getMainFileID()) |
| 8552 | ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID()); |
| 8553 | |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8554 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 8555 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 8556 | // disk again |
| 8557 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 8558 | // than mmap the files several times. |
| Harlan Haskins | 8d323d1 | 2019-08-01 21:31:56 +0000 | [diff] [blame] | 8559 | auto Entry = |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8560 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 8561 | // FIXME: The filename may be a virtual name that does probably not |
| 8562 | // point to a valid file and we get no Entry here. In this case try with |
| 8563 | // the memory buffer below. |
| 8564 | if (Entry) |
| Raphael Isemann | a37734f | 2020-02-17 19:43:33 +0100 | [diff] [blame] | 8565 | ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc, |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8566 | FromSLoc.getFile().getFileCharacteristic()); |
| 8567 | } |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8568 | } |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8569 | |
| 8570 | if (ToID.isInvalid() || IsBuiltin) { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8571 | // FIXME: We want to re-use the existing MemoryBuffer! |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8572 | bool Invalid = true; |
| Duncan P. N. Exon Smith | f584819 | 2019-08-26 20:32:05 +0000 | [diff] [blame] | 8573 | const llvm::MemoryBuffer *FromBuf = |
| 8574 | Cache->getBuffer(FromContext.getDiagnostics(), |
| 8575 | FromSM.getFileManager(), SourceLocation{}, &Invalid); |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8576 | if (!FromBuf || Invalid) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8577 | // FIXME: Use a new error kind? |
| 8578 | return llvm::make_error<ImportError>(ImportError::Unknown); |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8579 | |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8580 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 8581 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 8582 | FromBuf->getBufferIdentifier()); |
| 8583 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 8584 | FromSLoc.getFile().getFileCharacteristic()); |
| 8585 | } |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8586 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8587 | |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8588 | assert(ToID.isValid() && "Unexpected invalid fileID was created."); |
| 8589 | |
| Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 8590 | ImportedFileIDs[FromID] = ToID; |
| Balazs Keri | d22f877 | 2019-07-24 10:16:37 +0000 | [diff] [blame] | 8591 | |
| 8592 | if (FileIDImportHandler) |
| 8593 | FileIDImportHandler(ToID, FromID); |
| 8594 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8595 | return ToID; |
| 8596 | } |
| 8597 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8598 | Expected<CXXCtorInitializer *> ASTImporter::Import(CXXCtorInitializer *From) { |
| 8599 | ExpectedExpr ToExprOrErr = Import(From->getInit()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8600 | if (!ToExprOrErr) |
| 8601 | return ToExprOrErr.takeError(); |
| 8602 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8603 | auto LParenLocOrErr = Import(From->getLParenLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8604 | if (!LParenLocOrErr) |
| 8605 | return LParenLocOrErr.takeError(); |
| 8606 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8607 | auto RParenLocOrErr = Import(From->getRParenLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8608 | if (!RParenLocOrErr) |
| 8609 | return RParenLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8610 | |
| 8611 | if (From->isBaseInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8612 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8613 | if (!ToTInfoOrErr) |
| 8614 | return ToTInfoOrErr.takeError(); |
| 8615 | |
| 8616 | SourceLocation EllipsisLoc; |
| 8617 | if (From->isPackExpansion()) |
| 8618 | if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc())) |
| 8619 | return std::move(Err); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8620 | |
| 8621 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8622 | ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr, |
| 8623 | *ToExprOrErr, *RParenLocOrErr, EllipsisLoc); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8624 | } else if (From->isMemberInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8625 | ExpectedDecl ToFieldOrErr = Import(From->getMember()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8626 | if (!ToFieldOrErr) |
| 8627 | return ToFieldOrErr.takeError(); |
| 8628 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8629 | auto MemberLocOrErr = Import(From->getMemberLocation()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8630 | if (!MemberLocOrErr) |
| 8631 | return MemberLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8632 | |
| 8633 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8634 | ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr, |
| 8635 | *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8636 | } else if (From->isIndirectMemberInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8637 | ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8638 | if (!ToIFieldOrErr) |
| 8639 | return ToIFieldOrErr.takeError(); |
| 8640 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8641 | auto MemberLocOrErr = Import(From->getMemberLocation()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8642 | if (!MemberLocOrErr) |
| 8643 | return MemberLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8644 | |
| 8645 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8646 | ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr), |
| 8647 | *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8648 | } else if (From->isDelegatingInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8649 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8650 | if (!ToTInfoOrErr) |
| 8651 | return ToTInfoOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8652 | |
| 8653 | return new (ToContext) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8654 | CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr, |
| 8655 | *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8656 | } else { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8657 | // FIXME: assert? |
| 8658 | return make_error<ImportError>(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8659 | } |
| Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8660 | } |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8661 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8662 | Expected<CXXBaseSpecifier *> |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8663 | ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8664 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 8665 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 8666 | return Pos->second; |
| 8667 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8668 | Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8669 | if (!ToSourceRange) |
| 8670 | return ToSourceRange.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8671 | Expected<TypeSourceInfo *> ToTSI = Import(BaseSpec->getTypeSourceInfo()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8672 | if (!ToTSI) |
| 8673 | return ToTSI.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8674 | ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8675 | if (!ToEllipsisLoc) |
| 8676 | return ToEllipsisLoc.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8677 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8678 | *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 8679 | BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8680 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 8681 | return Imported; |
| 8682 | } |
| 8683 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8684 | Error ASTImporter::ImportDefinition(Decl *From) { |
| 8685 | ExpectedDecl ToOrErr = Import(From); |
| 8686 | if (!ToOrErr) |
| 8687 | return ToOrErr.takeError(); |
| 8688 | Decl *To = *ToOrErr; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8689 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8690 | auto *FromDC = cast<DeclContext>(From); |
| 8691 | ASTNodeImporter Importer(*this); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8692 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8693 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
| 8694 | if (!ToRecord->getDefinition()) { |
| 8695 | return Importer.ImportDefinition( |
| 8696 | cast<RecordDecl>(FromDC), ToRecord, |
| 8697 | ASTNodeImporter::IDK_Everything); |
| Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8698 | } |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8699 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8700 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8701 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
| 8702 | if (!ToEnum->getDefinition()) { |
| 8703 | return Importer.ImportDefinition( |
| 8704 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); |
| 8705 | } |
| 8706 | } |
| 8707 | |
| 8708 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
| 8709 | if (!ToIFace->getDefinition()) { |
| 8710 | return Importer.ImportDefinition( |
| 8711 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
| 8712 | ASTNodeImporter::IDK_Everything); |
| 8713 | } |
| 8714 | } |
| 8715 | |
| 8716 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
| 8717 | if (!ToProto->getDefinition()) { |
| 8718 | return Importer.ImportDefinition( |
| 8719 | cast<ObjCProtocolDecl>(FromDC), ToProto, |
| 8720 | ASTNodeImporter::IDK_Everything); |
| 8721 | } |
| 8722 | } |
| 8723 | |
| 8724 | return Importer.ImportDeclContext(FromDC, true); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8725 | } |
| 8726 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8727 | Expected<DeclarationName> ASTImporter::Import(DeclarationName FromName) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8728 | if (!FromName) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8729 | return DeclarationName{}; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8730 | |
| 8731 | switch (FromName.getNameKind()) { |
| 8732 | case DeclarationName::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8733 | return DeclarationName(Import(FromName.getAsIdentifierInfo())); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8734 | |
| 8735 | case DeclarationName::ObjCZeroArgSelector: |
| 8736 | case DeclarationName::ObjCOneArgSelector: |
| 8737 | case DeclarationName::ObjCMultiArgSelector: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8738 | if (auto ToSelOrErr = Import(FromName.getObjCSelector())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8739 | return DeclarationName(*ToSelOrErr); |
| 8740 | else |
| 8741 | return ToSelOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8742 | |
| 8743 | case DeclarationName::CXXConstructorName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8744 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8745 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 8746 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8747 | else |
| 8748 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8749 | } |
| 8750 | |
| 8751 | case DeclarationName::CXXDestructorName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8752 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8753 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 8754 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8755 | else |
| 8756 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8757 | } |
| 8758 | |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8759 | case DeclarationName::CXXDeductionGuideName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8760 | if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8761 | return ToContext.DeclarationNames.getCXXDeductionGuideName( |
| 8762 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8763 | else |
| 8764 | return ToTemplateOrErr.takeError(); |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8765 | } |
| 8766 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8767 | case DeclarationName::CXXConversionFunctionName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8768 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8769 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 8770 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8771 | else |
| 8772 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8773 | } |
| 8774 | |
| 8775 | case DeclarationName::CXXOperatorName: |
| 8776 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 8777 | FromName.getCXXOverloadedOperator()); |
| 8778 | |
| 8779 | case DeclarationName::CXXLiteralOperatorName: |
| 8780 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8781 | Import(FromName.getCXXLiteralIdentifier())); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8782 | |
| 8783 | case DeclarationName::CXXUsingDirective: |
| 8784 | // FIXME: STATICS! |
| 8785 | return DeclarationName::getUsingDirectiveName(); |
| 8786 | } |
| 8787 | |
| David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 8788 | llvm_unreachable("Invalid DeclarationName Kind!"); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8789 | } |
| 8790 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8791 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8792 | if (!FromId) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8793 | return nullptr; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8794 | |
| Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 8795 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 8796 | |
| 8797 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 8798 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 8799 | |
| 8800 | return ToId; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8801 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8802 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8803 | Expected<Selector> ASTImporter::Import(Selector FromSel) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8804 | if (FromSel.isNull()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8805 | return Selector{}; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8806 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8807 | SmallVector<IdentifierInfo *, 4> Idents; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8808 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 8809 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 8810 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 8811 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 8812 | } |
| 8813 | |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 8814 | Expected<DeclarationName> ASTImporter::HandleNameConflict(DeclarationName Name, |
| 8815 | DeclContext *DC, |
| 8816 | unsigned IDNS, |
| 8817 | NamedDecl **Decls, |
| 8818 | unsigned NumDecls) { |
| 8819 | if (ODRHandling == ODRHandlingType::Conservative) |
| 8820 | // Report error at any name conflict. |
| 8821 | return make_error<ImportError>(ImportError::NameConflict); |
| 8822 | else |
| 8823 | // Allow to create the new Decl with the same name. |
| 8824 | return Name; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8825 | } |
| 8826 | |
| 8827 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
| Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8828 | if (LastDiagFromFrom) |
| 8829 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8830 | FromContext.getDiagnostics()); |
| 8831 | LastDiagFromFrom = false; |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8832 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8833 | } |
| 8834 | |
| 8835 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
| Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8836 | if (!LastDiagFromFrom) |
| 8837 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8838 | ToContext.getDiagnostics()); |
| 8839 | LastDiagFromFrom = true; |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8840 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8841 | } |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8842 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8843 | void ASTImporter::CompleteDecl (Decl *D) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8844 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8845 | if (!ID->getDefinition()) |
| 8846 | ID->startDefinition(); |
| 8847 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8848 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8849 | if (!PD->getDefinition()) |
| 8850 | PD->startDefinition(); |
| 8851 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8852 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8853 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 8854 | TD->startDefinition(); |
| 8855 | TD->setCompleteDefinition(true); |
| 8856 | } |
| 8857 | } |
| 8858 | else { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8859 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8860 | } |
| 8861 | } |
| 8862 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8863 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 8864 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 8865 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 8866 | "Try to import an already imported Decl"); |
| 8867 | if (Pos != ImportedDecls.end()) |
| 8868 | return Pos->second; |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8869 | ImportedDecls[From] = To; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 8870 | // This mapping should be maintained only in this function. Therefore do not |
| 8871 | // check for additional consistency. |
| 8872 | ImportedFromDecls[To] = From; |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8873 | AddToLookupTable(To); |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8874 | return To; |
| Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 8875 | } |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8876 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8877 | llvm::Optional<ImportError> |
| 8878 | ASTImporter::getImportDeclErrorIfAny(Decl *FromD) const { |
| 8879 | auto Pos = ImportDeclErrors.find(FromD); |
| 8880 | if (Pos != ImportDeclErrors.end()) |
| 8881 | return Pos->second; |
| 8882 | else |
| 8883 | return Optional<ImportError>(); |
| 8884 | } |
| 8885 | |
| 8886 | void ASTImporter::setImportDeclError(Decl *From, ImportError Error) { |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8887 | auto InsertRes = ImportDeclErrors.insert({From, Error}); |
| Benjamin Kramer | 4f76936 | 2019-07-01 14:33:26 +0000 | [diff] [blame] | 8888 | (void)InsertRes; |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8889 | // Either we set the error for the first time, or we already had set one and |
| 8890 | // now we want to set the same error. |
| 8891 | assert(InsertRes.second || InsertRes.first->second.Error == Error.Error); |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8892 | } |
| 8893 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8894 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 8895 | bool Complain) { |
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8896 | llvm::DenseMap<const Type *, const Type *>::iterator Pos = |
| 8897 | ImportedTypes.find(From.getTypePtr()); |
| 8898 | if (Pos != ImportedTypes.end()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8899 | if (ExpectedType ToFromOrErr = Import(From)) { |
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8900 | if (ToContext.hasSameType(*ToFromOrErr, To)) |
| 8901 | return true; |
| 8902 | } else { |
| 8903 | llvm::consumeError(ToFromOrErr.takeError()); |
| 8904 | } |
| 8905 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 8906 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8907 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8908 | getStructuralEquivalenceKind(*this), false, |
| 8909 | Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 8910 | return Ctx.IsEquivalent(From, To); |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8911 | } |