| 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 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 189 | template <class T> |
| 190 | Expected<std::tuple<T>> |
| 191 | importSeq(const T &From) { |
| 192 | Expected<T> ToOrErr = import(From); |
| 193 | if (!ToOrErr) |
| 194 | return ToOrErr.takeError(); |
| 195 | return std::make_tuple<T>(std::move(*ToOrErr)); |
| 196 | } |
| 197 | |
| 198 | // Import multiple objects with a single function call. |
| 199 | // This should work for every type for which a variant of `import` exists. |
| 200 | // The arguments are processed from left to right and import is stopped on |
| 201 | // first error. |
| 202 | template <class THead, class... TTail> |
| 203 | Expected<std::tuple<THead, TTail...>> |
| 204 | importSeq(const THead &FromHead, const TTail &...FromTail) { |
| 205 | Expected<std::tuple<THead>> ToHeadOrErr = importSeq(FromHead); |
| 206 | if (!ToHeadOrErr) |
| 207 | return ToHeadOrErr.takeError(); |
| 208 | Expected<std::tuple<TTail...>> ToTailOrErr = importSeq(FromTail...); |
| 209 | if (!ToTailOrErr) |
| 210 | return ToTailOrErr.takeError(); |
| 211 | return std::tuple_cat(*ToHeadOrErr, *ToTailOrErr); |
| 212 | } |
| 213 | |
| 214 | // Wrapper for an overload set. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 215 | template <typename ToDeclT> struct CallOverloadedCreateFun { |
| 216 | template <typename... Args> |
| 217 | auto operator()(Args &&... args) |
| 218 | -> decltype(ToDeclT::Create(std::forward<Args>(args)...)) { |
| 219 | return ToDeclT::Create(std::forward<Args>(args)...); |
| 220 | } |
| 221 | }; |
| 222 | |
| 223 | // Always use these functions to create a Decl during import. There are |
| 224 | // certain tasks which must be done after the Decl was created, e.g. we |
| 225 | // must immediately register that as an imported Decl. The parameter `ToD` |
| 226 | // will be set to the newly created Decl or if had been imported before |
| 227 | // then to the already imported Decl. Returns a bool value set to true if |
| 228 | // the `FromD` had been imported before. |
| 229 | template <typename ToDeclT, typename FromDeclT, typename... Args> |
| 230 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 231 | Args &&... args) { |
| 232 | // There may be several overloads of ToDeclT::Create. We must make sure |
| 233 | // to call the one which would be chosen by the arguments, thus we use a |
| 234 | // wrapper for the overload set. |
| 235 | CallOverloadedCreateFun<ToDeclT> OC; |
| 236 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 237 | std::forward<Args>(args)...); |
| 238 | } |
| 239 | // Use this overload if a special Type is needed to be created. E.g if we |
| 240 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` |
| 241 | // then: |
| 242 | // TypedefNameDecl *ToTypedef; |
| 243 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); |
| 244 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, |
| 245 | typename... Args> |
| 246 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 247 | Args &&... args) { |
| 248 | CallOverloadedCreateFun<NewDeclT> OC; |
| 249 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 250 | std::forward<Args>(args)...); |
| 251 | } |
| 252 | // Use this version if a special create function must be |
| 253 | // used, e.g. CXXRecordDecl::CreateLambda . |
| 254 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, |
| 255 | typename... Args> |
| 256 | LLVM_NODISCARD bool |
| 257 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, |
| 258 | FromDeclT *FromD, Args &&... args) { |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 259 | if (Importer.getImportDeclErrorIfAny(FromD)) { |
| 260 | ToD = nullptr; |
| 261 | return true; // Already imported but with error. |
| 262 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 263 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); |
| 264 | if (ToD) |
| 265 | return true; // Already imported. |
| 266 | ToD = CreateFun(std::forward<Args>(args)...); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 267 | // Keep track of imported Decls. |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 268 | Importer.RegisterImportedDecl(FromD, ToD); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 269 | InitializeImportedDecl(FromD, ToD); |
| 270 | return false; // A new Decl is created. |
| 271 | } |
| 272 | |
| 273 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 274 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; |
| 275 | if (FromD->hasAttrs()) |
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 276 | for (const Attr *FromAttr : FromD->getAttrs()) { |
| 277 | // FIXME: Return of the error here is not possible until store of |
| 278 | // import errors is implemented. |
| 279 | auto ToAttrOrErr = import(FromAttr); |
| 280 | if (ToAttrOrErr) |
| 281 | ToD->addAttr(*ToAttrOrErr); |
| 282 | else |
| 283 | llvm::consumeError(ToAttrOrErr.takeError()); |
| 284 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 285 | if (FromD->isUsed()) |
| 286 | ToD->setIsUsed(); |
| 287 | if (FromD->isImplicit()) |
| 288 | ToD->setImplicit(); |
| 289 | } |
| 290 | |
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 291 | // Check if we have found an existing definition. Returns with that |
| 292 | // definition if yes, otherwise returns null. |
| 293 | Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) { |
| 294 | const FunctionDecl *Definition = nullptr; |
| 295 | if (D->doesThisDeclarationHaveABody() && |
| 296 | FoundFunction->hasBody(Definition)) |
| 297 | return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition)); |
| 298 | return nullptr; |
| 299 | } |
| 300 | |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 301 | void addDeclToContexts(Decl *FromD, Decl *ToD) { |
| 302 | if (Importer.isMinimalImport()) { |
| 303 | // In minimal import case the decl must be added even if it is not |
| 304 | // contained in original context, for LLDB compatibility. |
| 305 | // FIXME: Check if a better solution is possible. |
| 306 | if (!FromD->getDescribedTemplate() && |
| 307 | FromD->getFriendObjectKind() == Decl::FOK_None) |
| 308 | ToD->getLexicalDeclContext()->addDeclInternal(ToD); |
| 309 | return; |
| 310 | } |
| 311 | |
| 312 | DeclContext *FromDC = FromD->getDeclContext(); |
| 313 | DeclContext *FromLexicalDC = FromD->getLexicalDeclContext(); |
| 314 | DeclContext *ToDC = ToD->getDeclContext(); |
| 315 | DeclContext *ToLexicalDC = ToD->getLexicalDeclContext(); |
| 316 | |
| 317 | bool Visible = false; |
| 318 | if (FromDC->containsDeclAndLoad(FromD)) { |
| 319 | ToDC->addDeclInternal(ToD); |
| 320 | Visible = true; |
| 321 | } |
| 322 | if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) { |
| 323 | ToLexicalDC->addDeclInternal(ToD); |
| 324 | Visible = true; |
| 325 | } |
| 326 | |
| 327 | // If the Decl was added to any context, it was made already visible. |
| 328 | // Otherwise it is still possible that it should be visible. |
| 329 | if (!Visible) { |
| 330 | if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) { |
| 331 | auto *ToNamed = cast<NamedDecl>(ToD); |
| 332 | DeclContextLookupResult FromLookup = |
| 333 | FromDC->lookup(FromNamed->getDeclName()); |
| 334 | for (NamedDecl *ND : FromLookup) |
| 335 | if (ND == FromNamed) { |
| 336 | ToDC->makeDeclVisibleInContext(ToNamed); |
| 337 | break; |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 343 | public: |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 344 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} |
| Gabor Marton | 344b099 | 2018-05-16 11:48:11 +0000 | [diff] [blame] | 345 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 346 | using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit; |
| 347 | using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit; |
| 348 | using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 349 | |
| 350 | // Importing types |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 351 | ExpectedType VisitType(const Type *T); |
| 352 | ExpectedType VisitAtomicType(const AtomicType *T); |
| 353 | ExpectedType VisitBuiltinType(const BuiltinType *T); |
| 354 | ExpectedType VisitDecayedType(const DecayedType *T); |
| 355 | ExpectedType VisitComplexType(const ComplexType *T); |
| 356 | ExpectedType VisitPointerType(const PointerType *T); |
| 357 | ExpectedType VisitBlockPointerType(const BlockPointerType *T); |
| 358 | ExpectedType VisitLValueReferenceType(const LValueReferenceType *T); |
| 359 | ExpectedType VisitRValueReferenceType(const RValueReferenceType *T); |
| 360 | ExpectedType VisitMemberPointerType(const MemberPointerType *T); |
| 361 | ExpectedType VisitConstantArrayType(const ConstantArrayType *T); |
| 362 | ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T); |
| 363 | ExpectedType VisitVariableArrayType(const VariableArrayType *T); |
| 364 | ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 365 | // FIXME: DependentSizedExtVectorType |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 366 | ExpectedType VisitVectorType(const VectorType *T); |
| 367 | ExpectedType VisitExtVectorType(const ExtVectorType *T); |
| 368 | ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T); |
| 369 | ExpectedType VisitFunctionProtoType(const FunctionProtoType *T); |
| 370 | ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T); |
| 371 | ExpectedType VisitParenType(const ParenType *T); |
| 372 | ExpectedType VisitTypedefType(const TypedefType *T); |
| 373 | ExpectedType VisitTypeOfExprType(const TypeOfExprType *T); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 374 | // FIXME: DependentTypeOfExprType |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 375 | ExpectedType VisitTypeOfType(const TypeOfType *T); |
| 376 | ExpectedType VisitDecltypeType(const DecltypeType *T); |
| 377 | ExpectedType VisitUnaryTransformType(const UnaryTransformType *T); |
| 378 | ExpectedType VisitAutoType(const AutoType *T); |
| 379 | ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 380 | // FIXME: DependentDecltypeType |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 381 | ExpectedType VisitRecordType(const RecordType *T); |
| 382 | ExpectedType VisitEnumType(const EnumType *T); |
| 383 | ExpectedType VisitAttributedType(const AttributedType *T); |
| 384 | ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T); |
| 385 | ExpectedType VisitSubstTemplateTypeParmType( |
| 386 | const SubstTemplateTypeParmType *T); |
| 387 | ExpectedType VisitTemplateSpecializationType( |
| 388 | const TemplateSpecializationType *T); |
| 389 | ExpectedType VisitElaboratedType(const ElaboratedType *T); |
| 390 | ExpectedType VisitDependentNameType(const DependentNameType *T); |
| 391 | ExpectedType VisitPackExpansionType(const PackExpansionType *T); |
| 392 | ExpectedType VisitDependentTemplateSpecializationType( |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 393 | const DependentTemplateSpecializationType *T); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 394 | ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T); |
| 395 | ExpectedType VisitObjCObjectType(const ObjCObjectType *T); |
| 396 | ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); |
| Rafael Stahl | df55620 | 2018-05-29 08:12:15 +0000 | [diff] [blame] | 397 | |
| 398 | // Importing declarations |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 399 | Error ImportDeclParts( |
| 400 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 401 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc); |
| 402 | Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); |
| 403 | Error ImportDeclarationNameLoc( |
| 404 | const DeclarationNameInfo &From, DeclarationNameInfo &To); |
| 405 | Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); |
| 406 | Error ImportDeclContext( |
| 407 | Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC); |
| 408 | Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 409 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 410 | Expected<CXXCastPath> ImportCastPath(CastExpr *E); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 411 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 412 | using Designator = DesignatedInitExpr::Designator; |
| 413 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 414 | /// What we should import from the definition. |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 415 | enum ImportDefinitionKind { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 416 | /// Import the default subset of the definition, which might be |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 417 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 418 | /// import is not set). |
| 419 | IDK_Default, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 420 | /// Import everything. |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 421 | IDK_Everything, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 422 | /// Import only the bare bones needed to establish a valid |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 423 | /// DeclContext. |
| 424 | IDK_Basic |
| 425 | }; |
| 426 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 427 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 428 | return IDK == IDK_Everything || |
| 429 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 430 | } |
| 431 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 432 | Error ImportInitializer(VarDecl *From, VarDecl *To); |
| 433 | Error ImportDefinition( |
| 434 | RecordDecl *From, RecordDecl *To, |
| 435 | ImportDefinitionKind Kind = IDK_Default); |
| 436 | Error ImportDefinition( |
| 437 | EnumDecl *From, EnumDecl *To, |
| 438 | ImportDefinitionKind Kind = IDK_Default); |
| 439 | Error ImportDefinition( |
| 440 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
| 441 | ImportDefinitionKind Kind = IDK_Default); |
| 442 | Error ImportDefinition( |
| 443 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
| 444 | ImportDefinitionKind Kind = IDK_Default); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 445 | Error ImportTemplateArguments( |
| 446 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 447 | SmallVectorImpl<TemplateArgument> &ToArgs); |
| 448 | Expected<TemplateArgument> |
| 449 | ImportTemplateArgument(const TemplateArgument &From); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 450 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 451 | template <typename InContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 452 | Error ImportTemplateArgumentListInfo( |
| 453 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 454 | |
| 455 | template<typename InContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 456 | Error ImportTemplateArgumentListInfo( |
| 457 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 458 | const InContainerTy &Container, TemplateArgumentListInfo &Result); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 459 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 460 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 461 | using FunctionTemplateAndArgsTy = |
| 462 | std::tuple<FunctionTemplateDecl *, TemplateArgsTy>; |
| 463 | Expected<FunctionTemplateAndArgsTy> |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 464 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 465 | FunctionDecl *FromFD); |
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 466 | Error ImportTemplateParameterLists(const DeclaratorDecl *FromD, |
| 467 | DeclaratorDecl *ToD); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 468 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 469 | Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 470 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 471 | Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD); |
| 472 | |
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 473 | Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam, |
| 474 | ParmVarDecl *ToParam); |
| 475 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 476 | template <typename T> |
| 477 | bool hasSameVisibilityContext(T *Found, T *From); |
| 478 | |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 479 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 480 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 481 | bool Complain = true); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 482 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 483 | bool Complain = true); |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 484 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 485 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 486 | bool IsStructuralMatch(FunctionTemplateDecl *From, |
| 487 | FunctionTemplateDecl *To); |
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 488 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 489 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 490 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 491 | ExpectedDecl VisitDecl(Decl *D); |
| 492 | ExpectedDecl VisitImportDecl(ImportDecl *D); |
| 493 | ExpectedDecl VisitEmptyDecl(EmptyDecl *D); |
| 494 | ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); |
| 495 | ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); |
| 496 | ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 497 | ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); |
| 498 | ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
| 499 | ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
| 500 | ExpectedDecl VisitTypedefDecl(TypedefDecl *D); |
| 501 | ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D); |
| 502 | ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
| 503 | ExpectedDecl VisitLabelDecl(LabelDecl *D); |
| 504 | ExpectedDecl VisitEnumDecl(EnumDecl *D); |
| 505 | ExpectedDecl VisitRecordDecl(RecordDecl *D); |
| 506 | ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D); |
| 507 | ExpectedDecl VisitFunctionDecl(FunctionDecl *D); |
| 508 | ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D); |
| 509 | ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 510 | ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 511 | ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); |
| 512 | ExpectedDecl VisitFieldDecl(FieldDecl *D); |
| 513 | ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); |
| 514 | ExpectedDecl VisitFriendDecl(FriendDecl *D); |
| 515 | ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 516 | ExpectedDecl VisitVarDecl(VarDecl *D); |
| 517 | ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D); |
| 518 | ExpectedDecl VisitParmVarDecl(ParmVarDecl *D); |
| 519 | ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 520 | ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
| 521 | ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 522 | ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 523 | ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D); |
| 524 | ExpectedDecl VisitUsingDecl(UsingDecl *D); |
| 525 | ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); |
| 526 | ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 527 | ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 528 | ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
| Raphael Isemann | ba7bde6 | 2019-10-30 14:50:35 +0100 | [diff] [blame] | 529 | ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D); |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 530 | ExpectedDecl |
| 531 | VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 532 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 533 | Expected<ObjCTypeParamList *> |
| 534 | ImportObjCTypeParamList(ObjCTypeParamList *list); |
| 535 | |
| 536 | ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 537 | ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 538 | ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 539 | ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 540 | ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
| 541 | ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 542 | ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 543 | ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 544 | ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D); |
| 545 | ExpectedDecl VisitClassTemplateSpecializationDecl( |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 546 | ClassTemplateSpecializationDecl *D); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 547 | ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); |
| 548 | ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
| 549 | ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 550 | |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 551 | // Importing statements |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 552 | ExpectedStmt VisitStmt(Stmt *S); |
| 553 | ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S); |
| 554 | ExpectedStmt VisitDeclStmt(DeclStmt *S); |
| 555 | ExpectedStmt VisitNullStmt(NullStmt *S); |
| 556 | ExpectedStmt VisitCompoundStmt(CompoundStmt *S); |
| 557 | ExpectedStmt VisitCaseStmt(CaseStmt *S); |
| 558 | ExpectedStmt VisitDefaultStmt(DefaultStmt *S); |
| 559 | ExpectedStmt VisitLabelStmt(LabelStmt *S); |
| 560 | ExpectedStmt VisitAttributedStmt(AttributedStmt *S); |
| 561 | ExpectedStmt VisitIfStmt(IfStmt *S); |
| 562 | ExpectedStmt VisitSwitchStmt(SwitchStmt *S); |
| 563 | ExpectedStmt VisitWhileStmt(WhileStmt *S); |
| 564 | ExpectedStmt VisitDoStmt(DoStmt *S); |
| 565 | ExpectedStmt VisitForStmt(ForStmt *S); |
| 566 | ExpectedStmt VisitGotoStmt(GotoStmt *S); |
| 567 | ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 568 | ExpectedStmt VisitContinueStmt(ContinueStmt *S); |
| 569 | ExpectedStmt VisitBreakStmt(BreakStmt *S); |
| 570 | ExpectedStmt VisitReturnStmt(ReturnStmt *S); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 571 | // FIXME: MSAsmStmt |
| 572 | // FIXME: SEHExceptStmt |
| 573 | // FIXME: SEHFinallyStmt |
| 574 | // FIXME: SEHTryStmt |
| 575 | // FIXME: SEHLeaveStmt |
| 576 | // FIXME: CapturedStmt |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 577 | ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S); |
| 578 | ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S); |
| 579 | ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 580 | // FIXME: MSDependentExistsStmt |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 581 | ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 582 | ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 583 | ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 584 | ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 585 | ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 586 | ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 587 | ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 588 | |
| 589 | // Importing expressions |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 590 | ExpectedStmt VisitExpr(Expr *E); |
| 591 | ExpectedStmt VisitVAArgExpr(VAArgExpr *E); |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 592 | ExpectedStmt VisitChooseExpr(ChooseExpr *E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 593 | ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); |
| 594 | ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E); |
| 595 | ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E); |
| 596 | ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); |
| 597 | ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 598 | ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
| 599 | ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E); |
| 600 | ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E); |
| 601 | ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E); |
| 602 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); |
| 603 | ExpectedStmt VisitStringLiteral(StringLiteral *E); |
| 604 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 605 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); |
| 606 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 607 | ExpectedStmt VisitConstantExpr(ConstantExpr *E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 608 | ExpectedStmt VisitParenExpr(ParenExpr *E); |
| 609 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); |
| 610 | ExpectedStmt VisitStmtExpr(StmtExpr *E); |
| 611 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); |
| 612 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
| 613 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); |
| 614 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); |
| 615 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 616 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); |
| 617 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 618 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 619 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
| 620 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 621 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); |
| 622 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 623 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 624 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); |
| 625 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 626 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 627 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 628 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 629 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); |
| 630 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
| 631 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); |
| 632 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); |
| 633 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); |
| 634 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); |
| 635 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); |
| 636 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
| 637 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
| 638 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); |
| 639 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); |
| 640 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
| 641 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
| 642 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); |
| 643 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); |
| 644 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
| 645 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
| 646 | ExpectedStmt VisitMemberExpr(MemberExpr *E); |
| 647 | ExpectedStmt VisitCallExpr(CallExpr *E); |
| 648 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); |
| 649 | ExpectedStmt VisitInitListExpr(InitListExpr *E); |
| 650 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); |
| 651 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); |
| 652 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 653 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
| 654 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 655 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
| 656 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
| 657 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); |
| 658 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 659 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 660 | template<typename IIter, typename OIter> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 661 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 662 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 663 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { |
| 664 | Expected<ItemT> ToOrErr = import(*Ibegin); |
| 665 | if (!ToOrErr) |
| 666 | return ToOrErr.takeError(); |
| 667 | *Obegin = *ToOrErr; |
| 668 | } |
| 669 | return Error::success(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 670 | } |
| 671 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 672 | // Import every item from a container structure into an output container. |
| 673 | // If error occurs, stops at first error and returns the error. |
| 674 | // The output container should have space for all needed elements (it is not |
| 675 | // expanded, new items are put into from the beginning). |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 676 | template<typename InContainerTy, typename OutContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 677 | Error ImportContainerChecked( |
| 678 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { |
| 679 | return ImportArrayChecked( |
| 680 | InContainer.begin(), InContainer.end(), OutContainer.begin()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | template<typename InContainerTy, typename OIter> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 684 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 685 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 686 | } |
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 687 | |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 688 | Error ImportOverriddenMethods(CXXMethodDecl *ToMethod, |
| 689 | CXXMethodDecl *FromMethod); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 690 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 691 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( |
| 692 | FunctionDecl *FromFD); |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 693 | |
| 694 | // Returns true if the given function has a placeholder return type and |
| 695 | // that type is declared inside the body of the function. |
| 696 | // E.g. auto f() { struct X{}; return X(); } |
| 697 | bool hasAutoReturnTypeDeclaredInside(FunctionDecl *D); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 698 | }; |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 699 | |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 700 | template <typename InContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 701 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 702 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 703 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 704 | auto ToLAngleLocOrErr = import(FromLAngleLoc); |
| 705 | if (!ToLAngleLocOrErr) |
| 706 | return ToLAngleLocOrErr.takeError(); |
| 707 | auto ToRAngleLocOrErr = import(FromRAngleLoc); |
| 708 | if (!ToRAngleLocOrErr) |
| 709 | return ToRAngleLocOrErr.takeError(); |
| 710 | |
| 711 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); |
| 712 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 713 | return Err; |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 714 | Result = ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 715 | return Error::success(); |
| Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 716 | } |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 717 | |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 718 | template <> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 719 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 720 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 721 | return ImportTemplateArgumentListInfo( |
| 722 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 723 | } |
| 724 | |
| 725 | template <> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 726 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 727 | ASTTemplateArgumentListInfo>( |
| 728 | const ASTTemplateArgumentListInfo &From, |
| 729 | TemplateArgumentListInfo &Result) { |
| 730 | return ImportTemplateArgumentListInfo( |
| 731 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 732 | } |
| 733 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 734 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 735 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 736 | FunctionDecl *FromFD) { |
| 737 | assert(FromFD->getTemplatedKind() == |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 738 | FunctionDecl::TK_FunctionTemplateSpecialization); |
| 739 | |
| 740 | FunctionTemplateAndArgsTy Result; |
| 741 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 742 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 743 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) |
| 744 | return std::move(Err); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 745 | |
| 746 | // Import template arguments. |
| 747 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 748 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 749 | std::get<1>(Result))) |
| 750 | return std::move(Err); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 751 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 752 | return Result; |
| 753 | } |
| 754 | |
| 755 | template <> |
| 756 | Expected<TemplateParameterList *> |
| 757 | ASTNodeImporter::import(TemplateParameterList *From) { |
| 758 | SmallVector<NamedDecl *, 4> To(From->size()); |
| 759 | if (Error Err = ImportContainerChecked(*From, To)) |
| 760 | return std::move(Err); |
| 761 | |
| 762 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); |
| 763 | if (!ToRequiresClause) |
| 764 | return ToRequiresClause.takeError(); |
| 765 | |
| 766 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); |
| 767 | if (!ToTemplateLocOrErr) |
| 768 | return ToTemplateLocOrErr.takeError(); |
| 769 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); |
| 770 | if (!ToLAngleLocOrErr) |
| 771 | return ToLAngleLocOrErr.takeError(); |
| 772 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); |
| 773 | if (!ToRAngleLocOrErr) |
| 774 | return ToRAngleLocOrErr.takeError(); |
| 775 | |
| 776 | return TemplateParameterList::Create( |
| 777 | Importer.getToContext(), |
| 778 | *ToTemplateLocOrErr, |
| 779 | *ToLAngleLocOrErr, |
| 780 | To, |
| 781 | *ToRAngleLocOrErr, |
| 782 | *ToRequiresClause); |
| 783 | } |
| 784 | |
| 785 | template <> |
| 786 | Expected<TemplateArgument> |
| 787 | ASTNodeImporter::import(const TemplateArgument &From) { |
| 788 | switch (From.getKind()) { |
| 789 | case TemplateArgument::Null: |
| 790 | return TemplateArgument(); |
| 791 | |
| 792 | case TemplateArgument::Type: { |
| 793 | ExpectedType ToTypeOrErr = import(From.getAsType()); |
| 794 | if (!ToTypeOrErr) |
| 795 | return ToTypeOrErr.takeError(); |
| 796 | return TemplateArgument(*ToTypeOrErr); |
| 797 | } |
| 798 | |
| 799 | case TemplateArgument::Integral: { |
| 800 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); |
| 801 | if (!ToTypeOrErr) |
| 802 | return ToTypeOrErr.takeError(); |
| 803 | return TemplateArgument(From, *ToTypeOrErr); |
| 804 | } |
| 805 | |
| 806 | case TemplateArgument::Declaration: { |
| 807 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); |
| 808 | if (!ToOrErr) |
| 809 | return ToOrErr.takeError(); |
| 810 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); |
| 811 | if (!ToTypeOrErr) |
| 812 | return ToTypeOrErr.takeError(); |
| 813 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); |
| 814 | } |
| 815 | |
| 816 | case TemplateArgument::NullPtr: { |
| 817 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); |
| 818 | if (!ToTypeOrErr) |
| 819 | return ToTypeOrErr.takeError(); |
| 820 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); |
| 821 | } |
| 822 | |
| 823 | case TemplateArgument::Template: { |
| 824 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); |
| 825 | if (!ToTemplateOrErr) |
| 826 | return ToTemplateOrErr.takeError(); |
| 827 | |
| 828 | return TemplateArgument(*ToTemplateOrErr); |
| 829 | } |
| 830 | |
| 831 | case TemplateArgument::TemplateExpansion: { |
| 832 | Expected<TemplateName> ToTemplateOrErr = |
| 833 | import(From.getAsTemplateOrTemplatePattern()); |
| 834 | if (!ToTemplateOrErr) |
| 835 | return ToTemplateOrErr.takeError(); |
| 836 | |
| 837 | return TemplateArgument( |
| 838 | *ToTemplateOrErr, From.getNumTemplateExpansions()); |
| 839 | } |
| 840 | |
| 841 | case TemplateArgument::Expression: |
| 842 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) |
| 843 | return TemplateArgument(*ToExpr); |
| 844 | else |
| 845 | return ToExpr.takeError(); |
| 846 | |
| 847 | case TemplateArgument::Pack: { |
| 848 | SmallVector<TemplateArgument, 2> ToPack; |
| 849 | ToPack.reserve(From.pack_size()); |
| 850 | if (Error Err = ImportTemplateArguments( |
| 851 | From.pack_begin(), From.pack_size(), ToPack)) |
| 852 | return std::move(Err); |
| 853 | |
| 854 | return TemplateArgument( |
| 855 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | llvm_unreachable("Invalid template argument kind"); |
| 860 | } |
| 861 | |
| 862 | template <> |
| 863 | Expected<TemplateArgumentLoc> |
| 864 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { |
| 865 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); |
| 866 | if (!ArgOrErr) |
| 867 | return ArgOrErr.takeError(); |
| 868 | TemplateArgument Arg = *ArgOrErr; |
| 869 | |
| 870 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 871 | |
| 872 | TemplateArgumentLocInfo ToInfo; |
| 873 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 874 | ExpectedExpr E = import(FromInfo.getAsExpr()); |
| 875 | if (!E) |
| 876 | return E.takeError(); |
| 877 | ToInfo = TemplateArgumentLocInfo(*E); |
| 878 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 879 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) |
| 880 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); |
| 881 | else |
| 882 | return TSIOrErr.takeError(); |
| 883 | } else { |
| 884 | auto ToTemplateQualifierLocOrErr = |
| 885 | import(FromInfo.getTemplateQualifierLoc()); |
| 886 | if (!ToTemplateQualifierLocOrErr) |
| 887 | return ToTemplateQualifierLocOrErr.takeError(); |
| 888 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); |
| 889 | if (!ToTemplateNameLocOrErr) |
| 890 | return ToTemplateNameLocOrErr.takeError(); |
| 891 | auto ToTemplateEllipsisLocOrErr = |
| 892 | import(FromInfo.getTemplateEllipsisLoc()); |
| 893 | if (!ToTemplateEllipsisLocOrErr) |
| 894 | return ToTemplateEllipsisLocOrErr.takeError(); |
| 895 | |
| 896 | ToInfo = TemplateArgumentLocInfo( |
| 897 | *ToTemplateQualifierLocOrErr, |
| 898 | *ToTemplateNameLocOrErr, |
| 899 | *ToTemplateEllipsisLocOrErr); |
| 900 | } |
| 901 | |
| 902 | return TemplateArgumentLoc(Arg, ToInfo); |
| 903 | } |
| 904 | |
| 905 | template <> |
| 906 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { |
| 907 | if (DG.isNull()) |
| 908 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 909 | size_t NumDecls = DG.end() - DG.begin(); |
| 910 | SmallVector<Decl *, 1> ToDecls; |
| 911 | ToDecls.reserve(NumDecls); |
| 912 | for (Decl *FromD : DG) { |
| 913 | if (auto ToDOrErr = import(FromD)) |
| 914 | ToDecls.push_back(*ToDOrErr); |
| 915 | else |
| 916 | return ToDOrErr.takeError(); |
| 917 | } |
| 918 | return DeclGroupRef::Create(Importer.getToContext(), |
| 919 | ToDecls.begin(), |
| 920 | NumDecls); |
| 921 | } |
| 922 | |
| 923 | template <> |
| 924 | Expected<ASTNodeImporter::Designator> |
| 925 | ASTNodeImporter::import(const Designator &D) { |
| 926 | if (D.isFieldDesignator()) { |
| 927 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 928 | |
| 929 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); |
| 930 | if (!ToDotLocOrErr) |
| 931 | return ToDotLocOrErr.takeError(); |
| 932 | |
| 933 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); |
| 934 | if (!ToFieldLocOrErr) |
| 935 | return ToFieldLocOrErr.takeError(); |
| 936 | |
| 937 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); |
| 938 | } |
| 939 | |
| 940 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); |
| 941 | if (!ToLBracketLocOrErr) |
| 942 | return ToLBracketLocOrErr.takeError(); |
| 943 | |
| 944 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); |
| 945 | if (!ToRBracketLocOrErr) |
| 946 | return ToRBracketLocOrErr.takeError(); |
| 947 | |
| 948 | if (D.isArrayDesignator()) |
| 949 | return Designator(D.getFirstExprIndex(), |
| 950 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); |
| 951 | |
| 952 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); |
| 953 | if (!ToEllipsisLocOrErr) |
| 954 | return ToEllipsisLocOrErr.takeError(); |
| 955 | |
| 956 | assert(D.isArrayRangeDesignator()); |
| 957 | return Designator( |
| 958 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, |
| 959 | *ToRBracketLocOrErr); |
| 960 | } |
| 961 | |
| 962 | template <> |
| 963 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { |
| 964 | VarDecl *Var = nullptr; |
| 965 | if (From.capturesVariable()) { |
| 966 | if (auto VarOrErr = import(From.getCapturedVar())) |
| 967 | Var = *VarOrErr; |
| 968 | else |
| 969 | return VarOrErr.takeError(); |
| 970 | } |
| 971 | |
| 972 | auto LocationOrErr = import(From.getLocation()); |
| 973 | if (!LocationOrErr) |
| 974 | return LocationOrErr.takeError(); |
| 975 | |
| 976 | SourceLocation EllipsisLoc; |
| 977 | if (From.isPackExpansion()) |
| 978 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) |
| 979 | return std::move(Err); |
| 980 | |
| 981 | return LambdaCapture( |
| 982 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, |
| 983 | EllipsisLoc); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 984 | } |
| 985 | |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 986 | template <typename T> |
| 987 | bool ASTNodeImporter::hasSameVisibilityContext(T *Found, T *From) { |
| 988 | if (From->hasExternalFormalLinkage()) |
| 989 | return Found->hasExternalFormalLinkage(); |
| 990 | if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl()) |
| 991 | return false; |
| 992 | if (From->isInAnonymousNamespace()) |
| 993 | return Found->isInAnonymousNamespace(); |
| 994 | else |
| 995 | return !Found->isInAnonymousNamespace() && |
| 996 | !Found->hasExternalFormalLinkage(); |
| 997 | } |
| 998 | |
| 999 | template <> |
| 1000 | bool ASTNodeImporter::hasSameVisibilityContext(TypedefNameDecl *Found, |
| 1001 | TypedefNameDecl *From) { |
| 1002 | if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace()) |
| 1003 | return Importer.GetFromTU(Found) == From->getTranslationUnitDecl(); |
| 1004 | return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace(); |
| 1005 | } |
| 1006 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1007 | } // namespace clang |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 1008 | |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1009 | //---------------------------------------------------------------------------- |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1010 | // Import Types |
| 1011 | //---------------------------------------------------------------------------- |
| 1012 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1013 | using namespace clang; |
| 1014 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1015 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1016 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 1017 | << T->getTypeClassName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1018 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1021 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 1022 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); |
| 1023 | if (!UnderlyingTypeOrErr) |
| 1024 | return UnderlyingTypeOrErr.takeError(); |
| Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 1025 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1026 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); |
| Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1029 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1030 | switch (T->getKind()) { |
| Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 1031 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 1032 | case BuiltinType::Id: \ |
| 1033 | return Importer.getToContext().SingletonId; |
| Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 1034 | #include "clang/Basic/OpenCLImageTypes.def" |
| Andrew Savonichev | 3fee351 | 2018-11-08 11:25:41 +0000 | [diff] [blame] | 1035 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
| 1036 | case BuiltinType::Id: \ |
| 1037 | return Importer.getToContext().Id##Ty; |
| 1038 | #include "clang/Basic/OpenCLExtensionTypes.def" |
| Richard Sandiford | eb485fb | 2019-08-09 08:52:54 +0000 | [diff] [blame] | 1039 | #define SVE_TYPE(Name, Id, SingletonId) \ |
| 1040 | case BuiltinType::Id: \ |
| 1041 | return Importer.getToContext().SingletonId; |
| 1042 | #include "clang/Basic/AArch64SVEACLETypes.def" |
| John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 1043 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 1044 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 1045 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 1046 | #include "clang/AST/BuiltinTypes.def" |
| 1047 | |
| 1048 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 1049 | // context supports C++. |
| 1050 | |
| 1051 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 1052 | // context supports ObjC. |
| 1053 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1054 | case BuiltinType::Char_U: |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1055 | // The context we're importing from has an unsigned 'char'. If we're |
| 1056 | // importing into a context with a signed 'char', translate to |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1057 | // 'unsigned char' instead. |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1058 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1059 | return Importer.getToContext().UnsignedCharTy; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1060 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1061 | return Importer.getToContext().CharTy; |
| 1062 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1063 | case BuiltinType::Char_S: |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1064 | // The context we're importing from has an unsigned 'char'. If we're |
| 1065 | // importing into a context with a signed 'char', translate to |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1066 | // 'unsigned char' instead. |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1067 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1068 | return Importer.getToContext().SignedCharTy; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1069 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1070 | return Importer.getToContext().CharTy; |
| 1071 | |
| Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 1072 | case BuiltinType::WChar_S: |
| 1073 | case BuiltinType::WChar_U: |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1074 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 1075 | // wchar_t? |
| 1076 | return Importer.getToContext().WCharTy; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1077 | } |
| David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 1078 | |
| 1079 | llvm_unreachable("Invalid BuiltinType Kind!"); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1082 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 1083 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); |
| 1084 | if (!ToOriginalTypeOrErr) |
| 1085 | return ToOriginalTypeOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1086 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1087 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1090 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
| 1091 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1092 | if (!ToElementTypeOrErr) |
| 1093 | return ToElementTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1094 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1095 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1098 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
| 1099 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1100 | if (!ToPointeeTypeOrErr) |
| 1101 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1102 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1103 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1106 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1107 | // FIXME: Check for blocks support in "to" context. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1108 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1109 | if (!ToPointeeTypeOrErr) |
| 1110 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1111 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1112 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1115 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1116 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1117 | // FIXME: Check for C++ support in "to" context. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1118 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1119 | if (!ToPointeeTypeOrErr) |
| 1120 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1121 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1122 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1125 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1126 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1127 | // FIXME: Check for C++0x support in "to" context. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1128 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1129 | if (!ToPointeeTypeOrErr) |
| 1130 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1131 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1132 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1135 | ExpectedType |
| 1136 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1137 | // FIXME: Check for C++ support in "to" context. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1138 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1139 | if (!ToPointeeTypeOrErr) |
| 1140 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1141 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1142 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); |
| 1143 | if (!ClassTypeOrErr) |
| 1144 | return ClassTypeOrErr.takeError(); |
| 1145 | |
| 1146 | return Importer.getToContext().getMemberPointerType( |
| 1147 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1150 | ExpectedType |
| 1151 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
| Richard Smith | 772e266 | 2019-10-04 01:25:59 +0000 | [diff] [blame] | 1152 | QualType ToElementType; |
| 1153 | const Expr *ToSizeExpr; |
| 1154 | if (auto Imp = importSeq(T->getElementType(), T->getSizeExpr())) |
| 1155 | std::tie(ToElementType, ToSizeExpr) = *Imp; |
| 1156 | else |
| 1157 | return Imp.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1158 | |
| Richard Smith | 772e266 | 2019-10-04 01:25:59 +0000 | [diff] [blame] | 1159 | return Importer.getToContext().getConstantArrayType( |
| 1160 | ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(), |
| 1161 | T->getIndexTypeCVRQualifiers()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1162 | } |
| 1163 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1164 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1165 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1166 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1167 | if (!ToElementTypeOrErr) |
| 1168 | return ToElementTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1169 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1170 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1171 | T->getSizeModifier(), |
| 1172 | T->getIndexTypeCVRQualifiers()); |
| 1173 | } |
| 1174 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1175 | ExpectedType |
| 1176 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
| 1177 | QualType ToElementType; |
| 1178 | Expr *ToSizeExpr; |
| 1179 | SourceRange ToBracketsRange; |
| 1180 | if (auto Imp = importSeq( |
| 1181 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1182 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1183 | else |
| 1184 | return Imp.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1185 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1186 | return Importer.getToContext().getVariableArrayType( |
| 1187 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1188 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1189 | } |
| 1190 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1191 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1192 | const DependentSizedArrayType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1193 | QualType ToElementType; |
| 1194 | Expr *ToSizeExpr; |
| 1195 | SourceRange ToBracketsRange; |
| 1196 | if (auto Imp = importSeq( |
| 1197 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1198 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1199 | else |
| 1200 | return Imp.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1201 | // SizeExpr may be null if size is not specified directly. |
| 1202 | // For example, 'int a[]'. |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1203 | |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1204 | return Importer.getToContext().getDependentSizedArrayType( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1205 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1206 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1209 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
| 1210 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1211 | if (!ToElementTypeOrErr) |
| 1212 | return ToElementTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1213 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1214 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1215 | T->getNumElements(), |
| Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 1216 | T->getVectorKind()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1219 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
| 1220 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1221 | if (!ToElementTypeOrErr) |
| 1222 | return ToElementTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1223 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1224 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1225 | T->getNumElements()); |
| 1226 | } |
| 1227 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1228 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1229 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1230 | // FIXME: What happens if we're importing a function without a prototype |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1231 | // into C++? Should we make it variadic? |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1232 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1233 | if (!ToReturnTypeOrErr) |
| 1234 | return ToReturnTypeOrErr.takeError(); |
| Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1235 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1236 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, |
| Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1237 | T->getExtInfo()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1240 | ExpectedType |
| 1241 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 1242 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1243 | if (!ToReturnTypeOrErr) |
| 1244 | return ToReturnTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1245 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1246 | // Import argument types |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1247 | SmallVector<QualType, 4> ArgTypes; |
| Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 1248 | for (const auto &A : T->param_types()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1249 | ExpectedType TyOrErr = import(A); |
| 1250 | if (!TyOrErr) |
| 1251 | return TyOrErr.takeError(); |
| 1252 | ArgTypes.push_back(*TyOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1253 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1254 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1255 | // Import exception types |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1256 | SmallVector<QualType, 4> ExceptionTypes; |
| Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 1257 | for (const auto &E : T->exceptions()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1258 | ExpectedType TyOrErr = import(E); |
| 1259 | if (!TyOrErr) |
| 1260 | return TyOrErr.takeError(); |
| 1261 | ExceptionTypes.push_back(*TyOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1262 | } |
| John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 1263 | |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1264 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 1265 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 1266 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1267 | auto Imp = importSeq( |
| 1268 | FromEPI.ExceptionSpec.NoexceptExpr, |
| 1269 | FromEPI.ExceptionSpec.SourceDecl, |
| 1270 | FromEPI.ExceptionSpec.SourceTemplate); |
| 1271 | if (!Imp) |
| 1272 | return Imp.takeError(); |
| 1273 | |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1274 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 1275 | ToEPI.Variadic = FromEPI.Variadic; |
| 1276 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 1277 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 1278 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1279 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 1280 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1281 | std::tie( |
| 1282 | ToEPI.ExceptionSpec.NoexceptExpr, |
| 1283 | ToEPI.ExceptionSpec.SourceDecl, |
| 1284 | ToEPI.ExceptionSpec.SourceTemplate) = *Imp; |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1285 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1286 | return Importer.getToContext().getFunctionType( |
| 1287 | *ToReturnTypeOrErr, ArgTypes, ToEPI); |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1288 | } |
| 1289 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1290 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1291 | const UnresolvedUsingType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1292 | UnresolvedUsingTypenameDecl *ToD; |
| 1293 | Decl *ToPrevD; |
| 1294 | if (auto Imp = importSeq(T->getDecl(), T->getDecl()->getPreviousDecl())) |
| 1295 | std::tie(ToD, ToPrevD) = *Imp; |
| 1296 | else |
| 1297 | return Imp.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1298 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1299 | return Importer.getToContext().getTypeDeclType( |
| 1300 | ToD, cast_or_null<TypeDecl>(ToPrevD)); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1301 | } |
| 1302 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1303 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 1304 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); |
| 1305 | if (!ToInnerTypeOrErr) |
| 1306 | return ToInnerTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1307 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1308 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); |
| Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1311 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
| 1312 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1313 | if (!ToDeclOrErr) |
| 1314 | return ToDeclOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1315 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1316 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1319 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
| 1320 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1321 | if (!ToExprOrErr) |
| 1322 | return ToExprOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1323 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1324 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1325 | } |
| 1326 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1327 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
| 1328 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1329 | if (!ToUnderlyingTypeOrErr) |
| 1330 | return ToUnderlyingTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1331 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1332 | return Importer.getToContext().getTypeOfType(*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 ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1336 | // FIXME: Make sure that the "to" context supports C++0x! |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1337 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1338 | if (!ToExprOrErr) |
| 1339 | return ToExprOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +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(); |
| Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 1344 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1345 | return Importer.getToContext().getDecltypeType( |
| 1346 | *ToExprOrErr, *ToUnderlyingTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1349 | ExpectedType |
| 1350 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 1351 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1352 | if (!ToBaseTypeOrErr) |
| 1353 | return ToBaseTypeOrErr.takeError(); |
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1354 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1355 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1356 | if (!ToUnderlyingTypeOrErr) |
| 1357 | return ToUnderlyingTypeOrErr.takeError(); |
| 1358 | |
| 1359 | return Importer.getToContext().getUnaryTransformType( |
| 1360 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); |
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1363 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
| Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 1364 | // FIXME: Make sure that the "to" context supports C++11! |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1365 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); |
| 1366 | if (!ToDeducedTypeOrErr) |
| 1367 | return ToDeducedTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1368 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1369 | return Importer.getToContext().getAutoType(*ToDeducedTypeOrErr, |
| 1370 | T->getKeyword(), |
| Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 1371 | /*IsDependent*/false); |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1374 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1375 | const InjectedClassNameType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1376 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1377 | if (!ToDeclOrErr) |
| 1378 | return ToDeclOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1379 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1380 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); |
| 1381 | if (!ToInjTypeOrErr) |
| 1382 | return ToInjTypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1383 | |
| 1384 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 1385 | // See comments in InjectedClassNameType definition for details |
| 1386 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 1387 | enum { |
| 1388 | TypeAlignmentInBits = 4, |
| 1389 | TypeAlignment = 1 << TypeAlignmentInBits |
| 1390 | }; |
| 1391 | |
| 1392 | return QualType(new (Importer.getToContext(), TypeAlignment) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1393 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1394 | } |
| 1395 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1396 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
| 1397 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1398 | if (!ToDeclOrErr) |
| 1399 | return ToDeclOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1400 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1401 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1402 | } |
| 1403 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1404 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
| 1405 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1406 | if (!ToDeclOrErr) |
| 1407 | return ToDeclOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1408 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1409 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1410 | } |
| 1411 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1412 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 1413 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); |
| 1414 | if (!ToModifiedTypeOrErr) |
| 1415 | return ToModifiedTypeOrErr.takeError(); |
| 1416 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); |
| 1417 | if (!ToEquivalentTypeOrErr) |
| 1418 | return ToEquivalentTypeOrErr.takeError(); |
| Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1419 | |
| 1420 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1421 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); |
| Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1422 | } |
| 1423 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1424 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1425 | const TemplateTypeParmType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1426 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1427 | if (!ToDeclOrErr) |
| 1428 | return ToDeclOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1429 | |
| 1430 | return Importer.getToContext().getTemplateTypeParmType( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1431 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1434 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1435 | const SubstTemplateTypeParmType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1436 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); |
| 1437 | if (!ReplacedOrErr) |
| 1438 | return ReplacedOrErr.takeError(); |
| 1439 | const TemplateTypeParmType *Replaced = |
| 1440 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1441 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1442 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); |
| 1443 | if (!ToReplacementTypeOrErr) |
| 1444 | return ToReplacementTypeOrErr.takeError(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1445 | |
| 1446 | return Importer.getToContext().getSubstTemplateTypeParmType( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1447 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1448 | } |
| 1449 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1450 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1451 | const TemplateSpecializationType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1452 | auto ToTemplateOrErr = import(T->getTemplateName()); |
| 1453 | if (!ToTemplateOrErr) |
| 1454 | return ToTemplateOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1455 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1456 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1457 | if (Error Err = ImportTemplateArguments( |
| 1458 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
| 1459 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1460 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1461 | QualType ToCanonType; |
| 1462 | if (!QualType(T, 0).isCanonical()) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1463 | QualType FromCanonType |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1464 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1465 | if (ExpectedType TyOrErr = import(FromCanonType)) |
| 1466 | ToCanonType = *TyOrErr; |
| 1467 | else |
| 1468 | return TyOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1469 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1470 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, |
| David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 1471 | ToTemplateArgs, |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1472 | ToCanonType); |
| 1473 | } |
| 1474 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1475 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1476 | // Note: the qualifier in an ElaboratedType is optional. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1477 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1478 | if (!ToQualifierOrErr) |
| 1479 | return ToQualifierOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1480 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1481 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); |
| 1482 | if (!ToNamedTypeOrErr) |
| 1483 | return ToNamedTypeOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1484 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1485 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); |
| 1486 | if (!ToOwnedTagDeclOrErr) |
| 1487 | return ToOwnedTagDeclOrErr.takeError(); |
| Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1488 | |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1489 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1490 | *ToQualifierOrErr, |
| 1491 | *ToNamedTypeOrErr, |
| 1492 | *ToOwnedTagDeclOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1493 | } |
| 1494 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1495 | ExpectedType |
| 1496 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 1497 | ExpectedType ToPatternOrErr = import(T->getPattern()); |
| 1498 | if (!ToPatternOrErr) |
| 1499 | return ToPatternOrErr.takeError(); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1500 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1501 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1502 | T->getNumExpansions()); |
| 1503 | } |
| 1504 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1505 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1506 | const DependentTemplateSpecializationType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1507 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1508 | if (!ToQualifierOrErr) |
| 1509 | return ToQualifierOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1510 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1511 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1512 | |
| 1513 | SmallVector<TemplateArgument, 2> ToPack; |
| 1514 | ToPack.reserve(T->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1515 | if (Error Err = ImportTemplateArguments( |
| 1516 | T->getArgs(), T->getNumArgs(), ToPack)) |
| 1517 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1518 | |
| 1519 | return Importer.getToContext().getDependentTemplateSpecializationType( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1520 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1521 | } |
| 1522 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1523 | ExpectedType |
| 1524 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { |
| 1525 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1526 | if (!ToQualifierOrErr) |
| 1527 | return ToQualifierOrErr.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1528 | |
| 1529 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1530 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1531 | QualType Canon; |
| 1532 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { |
| 1533 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) |
| 1534 | Canon = (*TyOrErr).getCanonicalType(); |
| 1535 | else |
| 1536 | return TyOrErr.takeError(); |
| 1537 | } |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1538 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1539 | return Importer.getToContext().getDependentNameType(T->getKeyword(), |
| 1540 | *ToQualifierOrErr, |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1541 | Name, Canon); |
| 1542 | } |
| 1543 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1544 | ExpectedType |
| 1545 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
| 1546 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1547 | if (!ToDeclOrErr) |
| 1548 | return ToDeclOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1549 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1550 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1551 | } |
| 1552 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1553 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
| 1554 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1555 | if (!ToBaseTypeOrErr) |
| 1556 | return ToBaseTypeOrErr.takeError(); |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1557 | |
| Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1558 | SmallVector<QualType, 4> TypeArgs; |
| Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1559 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1560 | if (ExpectedType TyOrErr = import(TypeArg)) |
| 1561 | TypeArgs.push_back(*TyOrErr); |
| 1562 | else |
| 1563 | return TyOrErr.takeError(); |
| Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1566 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1567 | for (auto *P : T->quals()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1568 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) |
| 1569 | Protocols.push_back(*ProtocolOrErr); |
| 1570 | else |
| 1571 | return ProtocolOrErr.takeError(); |
| 1572 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1573 | } |
| 1574 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1575 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, |
| Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1576 | Protocols, |
| 1577 | T->isKindOfTypeAsWritten()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1580 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1581 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1582 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1583 | if (!ToPointeeTypeOrErr) |
| 1584 | return ToPointeeTypeOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1585 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1586 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1589 | //---------------------------------------------------------------------------- |
| 1590 | // Import Declarations |
| 1591 | //---------------------------------------------------------------------------- |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1592 | Error ASTNodeImporter::ImportDeclParts( |
| 1593 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 1594 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { |
| Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1595 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. |
| 1596 | // 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] | 1597 | // FIXME: We could support these constructs by importing a different type of |
| 1598 | // this parameter and by importing the original type of the parameter only |
| 1599 | // after the FunctionDecl is created. See |
| 1600 | // VisitFunctionDecl::UsedDifferentProtoType. |
| Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1601 | DeclContext *OrigDC = D->getDeclContext(); |
| 1602 | FunctionDecl *FunDecl; |
| 1603 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && |
| 1604 | FunDecl->hasBody()) { |
| Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1605 | auto getLeafPointeeType = [](const Type *T) { |
| 1606 | while (T->isPointerType() || T->isArrayType()) { |
| 1607 | T = T->getPointeeOrArrayElementType(); |
| 1608 | } |
| 1609 | return T; |
| 1610 | }; |
| 1611 | for (const ParmVarDecl *P : FunDecl->parameters()) { |
| 1612 | const Type *LeafT = |
| 1613 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); |
| 1614 | auto *RT = dyn_cast<RecordType>(LeafT); |
| 1615 | if (RT && RT->getDecl() == D) { |
| 1616 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 1617 | << D->getDeclKindName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1618 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1619 | } |
| Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1620 | } |
| 1621 | } |
| 1622 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1623 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1624 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 1625 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1626 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1627 | // Import the name of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1628 | if (Error Err = importInto(Name, D->getDeclName())) |
| 1629 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1630 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1631 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1632 | if (Error Err = importInto(Loc, D->getLocation())) |
| 1633 | return Err; |
| 1634 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1635 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
| Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 1636 | if (ToD) |
| 1637 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD)) |
| 1638 | return Err; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1639 | |
| 1640 | return Error::success(); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1641 | } |
| 1642 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1643 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1644 | if (!FromD) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1645 | return Error::success(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1646 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1647 | if (!ToD) |
| 1648 | if (Error Err = importInto(ToD, FromD)) |
| 1649 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1650 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1651 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1652 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { |
| 1653 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && |
| 1654 | !ToRecord->getDefinition()) { |
| 1655 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) |
| 1656 | return Err; |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1657 | } |
| 1658 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1659 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1660 | } |
| 1661 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1662 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1663 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1664 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1665 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) |
| 1666 | return Err; |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1667 | } |
| 1668 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1669 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1670 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1671 | |
| 1672 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1675 | Error |
| 1676 | ASTNodeImporter::ImportDeclarationNameLoc( |
| 1677 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1678 | // NOTE: To.Name and To.Loc are already imported. |
| 1679 | // We only have to import To.LocInfo. |
| 1680 | switch (To.getName().getNameKind()) { |
| 1681 | case DeclarationName::Identifier: |
| 1682 | case DeclarationName::ObjCZeroArgSelector: |
| 1683 | case DeclarationName::ObjCOneArgSelector: |
| 1684 | case DeclarationName::ObjCMultiArgSelector: |
| 1685 | case DeclarationName::CXXUsingDirective: |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1686 | case DeclarationName::CXXDeductionGuideName: |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1687 | return Error::success(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1688 | |
| 1689 | case DeclarationName::CXXOperatorName: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1690 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) |
| 1691 | To.setCXXOperatorNameRange(*ToRangeOrErr); |
| 1692 | else |
| 1693 | return ToRangeOrErr.takeError(); |
| 1694 | return Error::success(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1695 | } |
| 1696 | case DeclarationName::CXXLiteralOperatorName: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1697 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) |
| 1698 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); |
| 1699 | else |
| 1700 | return LocOrErr.takeError(); |
| 1701 | return Error::success(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1702 | } |
| 1703 | case DeclarationName::CXXConstructorName: |
| 1704 | case DeclarationName::CXXDestructorName: |
| 1705 | case DeclarationName::CXXConversionFunctionName: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1706 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) |
| 1707 | To.setNamedTypeInfo(*ToTInfoOrErr); |
| 1708 | else |
| 1709 | return ToTInfoOrErr.takeError(); |
| 1710 | return Error::success(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1711 | } |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1712 | } |
| Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1713 | llvm_unreachable("Unknown name kind."); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1714 | } |
| 1715 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1716 | Error |
| 1717 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1718 | if (Importer.isMinimalImport() && !ForceImport) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1719 | auto ToDCOrErr = Importer.ImportContext(FromDC); |
| 1720 | return ToDCOrErr.takeError(); |
| 1721 | } |
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1722 | |
| 1723 | // We use strict error handling in case of records and enums, but not |
| 1724 | // with e.g. namespaces. |
| 1725 | // |
| 1726 | // FIXME Clients of the ASTImporter should be able to choose an |
| 1727 | // appropriate error handling strategy for their needs. For instance, |
| 1728 | // they may not want to mark an entire namespace as erroneous merely |
| 1729 | // because there is an ODR error with two typedefs. As another example, |
| 1730 | // the client may allow EnumConstantDecls with same names but with |
| 1731 | // different values in two distinct translation units. |
| 1732 | bool AccumulateChildErrors = isa<TagDecl>(FromDC); |
| 1733 | |
| 1734 | Error ChildErrors = Error::success(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1735 | for (auto *From : FromDC->decls()) { |
| 1736 | ExpectedDecl ImportedOrErr = import(From); |
| shafik | 6a7df3a | 2019-12-19 11:14:39 -0800 | [diff] [blame] | 1737 | |
| 1738 | // If we are in the process of ImportDefinition(...) for a RecordDecl we |
| 1739 | // want to make sure that we are also completing each FieldDecl. There |
| 1740 | // are currently cases where this does not happen and this is correctness |
| 1741 | // fix since operations such as code generation will expect this to be so. |
| 1742 | if (ImportedOrErr) { |
| 1743 | FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From); |
| 1744 | Decl *ImportedDecl = (Decl*)*ImportedOrErr; |
| 1745 | FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl); |
| 1746 | if (FieldFrom && FieldTo) { |
| 1747 | const RecordType *RecordFrom = FieldFrom->getType()->getAs<RecordType>(); |
| 1748 | const RecordType *RecordTo = FieldTo->getType()->getAs<RecordType>(); |
| 1749 | if (RecordFrom && RecordTo) { |
| 1750 | RecordDecl *FromRecordDecl = RecordFrom->getDecl(); |
| 1751 | RecordDecl *ToRecordDecl = RecordTo->getDecl(); |
| 1752 | |
| 1753 | if (FromRecordDecl->isCompleteDefinition() && |
| 1754 | !ToRecordDecl->isCompleteDefinition()) { |
| 1755 | Error Err = ImportDefinition(FromRecordDecl, ToRecordDecl); |
| 1756 | |
| 1757 | if (Err && AccumulateChildErrors) |
| 1758 | ChildErrors = joinErrors(std::move(ChildErrors), std::move(Err)); |
| 1759 | else |
| 1760 | consumeError(std::move(Err)); |
| 1761 | } |
| 1762 | } |
| 1763 | } |
| 1764 | } else { |
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1765 | if (AccumulateChildErrors) |
| 1766 | ChildErrors = |
| 1767 | joinErrors(std::move(ChildErrors), ImportedOrErr.takeError()); |
| 1768 | else |
| 1769 | consumeError(ImportedOrErr.takeError()); |
| 1770 | } |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1771 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1772 | |
| Gabor Marton | 48b16e1 | 2019-07-25 09:07:17 +0000 | [diff] [blame] | 1773 | // We reorder declarations in RecordDecls because they may have another order |
| 1774 | // in the "to" context than they have in the "from" context. This may happen |
| 1775 | // e.g when we import a class like this: |
| 1776 | // struct declToImport { |
| 1777 | // int a = c + b; |
| 1778 | // int b = 1; |
| 1779 | // int c = 2; |
| 1780 | // }; |
| 1781 | // During the import of `a` we import first the dependencies in sequence, |
| 1782 | // thus the order would be `c`, `b`, `a`. We will get the normal order by |
| 1783 | // first removing the already imported members and then adding them in the |
| 1784 | // order as they apper in the "from" context. |
| 1785 | // |
| 1786 | // Keeping field order is vital because it determines structure layout. |
| 1787 | // |
| 1788 | // Here and below, we cannot call field_begin() method and its callers on |
| 1789 | // ToDC if it has an external storage. Calling field_begin() will |
| 1790 | // automatically load all the fields by calling |
| 1791 | // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would |
| 1792 | // call ASTImporter::Import(). This is because the ExternalASTSource |
| 1793 | // interface in LLDB is implemented by the means of the ASTImporter. However, |
| 1794 | // calling an import at this point would result in an uncontrolled import, we |
| 1795 | // must avoid that. |
| 1796 | const auto *FromRD = dyn_cast<RecordDecl>(FromDC); |
| 1797 | if (!FromRD) |
| 1798 | return ChildErrors; |
| 1799 | |
| 1800 | auto ToDCOrErr = Importer.ImportContext(FromDC); |
| 1801 | if (!ToDCOrErr) { |
| 1802 | consumeError(std::move(ChildErrors)); |
| 1803 | return ToDCOrErr.takeError(); |
| 1804 | } |
| 1805 | |
| 1806 | DeclContext *ToDC = *ToDCOrErr; |
| 1807 | // Remove all declarations, which may be in wrong order in the |
| 1808 | // lexical DeclContext and then add them in the proper order. |
| 1809 | for (auto *D : FromRD->decls()) { |
| Balazs Keri | 6e08669 | 2019-09-02 07:17:01 +0000 | [diff] [blame] | 1810 | if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<FriendDecl>(D)) { |
| Gabor Marton | 48b16e1 | 2019-07-25 09:07:17 +0000 | [diff] [blame] | 1811 | assert(D && "DC contains a null decl"); |
| 1812 | Decl *ToD = Importer.GetAlreadyImportedOrNull(D); |
| 1813 | // Remove only the decls which we successfully imported. |
| 1814 | if (ToD) { |
| 1815 | assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD)); |
| 1816 | // Remove the decl from its wrong place in the linked list. |
| 1817 | ToDC->removeDecl(ToD); |
| 1818 | // Add the decl to the end of the linked list. |
| 1819 | // This time it will be at the proper place because the enclosing for |
| 1820 | // loop iterates in the original (good) order of the decls. |
| 1821 | ToDC->addDeclInternal(ToD); |
| 1822 | } |
| 1823 | } |
| 1824 | } |
| 1825 | |
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1826 | return ChildErrors; |
| Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1827 | } |
| 1828 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1829 | Error ASTNodeImporter::ImportDeclContext( |
| 1830 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { |
| 1831 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); |
| 1832 | if (!ToDCOrErr) |
| 1833 | return ToDCOrErr.takeError(); |
| 1834 | ToDC = *ToDCOrErr; |
| 1835 | |
| 1836 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { |
| 1837 | auto ToLexicalDCOrErr = Importer.ImportContext( |
| 1838 | FromD->getLexicalDeclContext()); |
| 1839 | if (!ToLexicalDCOrErr) |
| 1840 | return ToLexicalDCOrErr.takeError(); |
| 1841 | ToLexicalDC = *ToLexicalDCOrErr; |
| 1842 | } else |
| 1843 | ToLexicalDC = ToDC; |
| 1844 | |
| 1845 | return Error::success(); |
| 1846 | } |
| 1847 | |
| 1848 | Error ASTNodeImporter::ImportImplicitMethods( |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1849 | const CXXRecordDecl *From, CXXRecordDecl *To) { |
| 1850 | assert(From->isCompleteDefinition() && To->getDefinition() == To && |
| 1851 | "Import implicit methods to or from non-definition"); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1852 | |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1853 | for (CXXMethodDecl *FromM : From->methods()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1854 | if (FromM->isImplicit()) { |
| 1855 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); |
| 1856 | if (!ToMOrErr) |
| 1857 | return ToMOrErr.takeError(); |
| 1858 | } |
| 1859 | |
| 1860 | return Error::success(); |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1863 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1864 | ASTImporter &Importer) { |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1865 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 1866 | if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef)) |
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 1867 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); |
| 1868 | else |
| 1869 | return ToTypedefOrErr.takeError(); |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1870 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1871 | return Error::success(); |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1872 | } |
| 1873 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1874 | Error ASTNodeImporter::ImportDefinition( |
| 1875 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1876 | auto DefinitionCompleter = [To]() { |
| 1877 | // There are cases in LLDB when we first import a class without its |
| 1878 | // members. The class will have DefinitionData, but no members. Then, |
| 1879 | // importDefinition is called from LLDB, which tries to get the members, so |
| 1880 | // when we get here, the class already has the DefinitionData set, so we |
| 1881 | // must unset the CompleteDefinition here to be able to complete again the |
| 1882 | // definition. |
| 1883 | To->setCompleteDefinition(false); |
| 1884 | To->completeDefinition(); |
| 1885 | }; |
| 1886 | |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1887 | if (To->getDefinition() || To->isBeingDefined()) { |
| Gabor Marton | e73805f | 2019-07-08 12:49:13 +0000 | [diff] [blame] | 1888 | if (Kind == IDK_Everything || |
| 1889 | // In case of lambdas, the class already has a definition ptr set, but |
| 1890 | // the contained decls are not imported yet. Also, isBeingDefined was |
| 1891 | // set in CXXRecordDecl::CreateLambda. We must import the contained |
| 1892 | // decls here and finish the definition. |
| 1893 | (To->isLambda() && shouldForceImportDeclContext(Kind))) { |
| 1894 | Error Result = ImportDeclContext(From, /*ForceImport=*/true); |
| 1895 | // Finish the definition of the lambda, set isBeingDefined to false. |
| 1896 | if (To->isLambda()) |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1897 | DefinitionCompleter(); |
| Gabor Marton | e73805f | 2019-07-08 12:49:13 +0000 | [diff] [blame] | 1898 | return Result; |
| 1899 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1900 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1901 | return Error::success(); |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1902 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1903 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1904 | To->startDefinition(); |
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1905 | // Complete the definition even if error is returned. |
| 1906 | // The RecordDecl may be already part of the AST so it is better to |
| 1907 | // have it in complete state even if something is wrong with it. |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1908 | auto DefinitionCompleterScopeExit = |
| 1909 | llvm::make_scope_exit(DefinitionCompleter); |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1910 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1911 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1912 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1913 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1914 | // Add base classes. |
| Gabor Marton | 17d3967 | 2018-11-26 15:54:08 +0000 | [diff] [blame] | 1915 | auto *ToCXX = dyn_cast<CXXRecordDecl>(To); |
| 1916 | auto *FromCXX = dyn_cast<CXXRecordDecl>(From); |
| 1917 | if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) { |
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1918 | |
| 1919 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1920 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 1921 | |
| 1922 | #define FIELD(Name, Width, Merge) \ |
| 1923 | ToData.Name = FromData.Name; |
| 1924 | #include "clang/AST/CXXRecordDeclDefinitionBits.def" |
| Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1925 | |
| Shafik Yaghmour | 16b9073 | 2019-04-26 18:51:28 +0000 | [diff] [blame] | 1926 | // Copy over the data stored in RecordDeclBits |
| 1927 | ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions()); |
| 1928 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1929 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1930 | for (const auto &Base1 : FromCXX->bases()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1931 | ExpectedType TyOrErr = import(Base1.getType()); |
| 1932 | if (!TyOrErr) |
| 1933 | return TyOrErr.takeError(); |
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1934 | |
| 1935 | SourceLocation EllipsisLoc; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1936 | if (Base1.isPackExpansion()) { |
| 1937 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) |
| 1938 | EllipsisLoc = *LocOrErr; |
| 1939 | else |
| 1940 | return LocOrErr.takeError(); |
| 1941 | } |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1942 | |
| 1943 | // Ensure that we have a definition for the base. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1944 | if (Error Err = |
| 1945 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) |
| 1946 | return Err; |
| 1947 | |
| 1948 | auto RangeOrErr = import(Base1.getSourceRange()); |
| 1949 | if (!RangeOrErr) |
| 1950 | return RangeOrErr.takeError(); |
| 1951 | |
| 1952 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); |
| 1953 | if (!TSIOrErr) |
| 1954 | return TSIOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1955 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1956 | Bases.push_back( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1957 | new (Importer.getToContext()) CXXBaseSpecifier( |
| 1958 | *RangeOrErr, |
| 1959 | Base1.isVirtual(), |
| 1960 | Base1.isBaseOfClass(), |
| 1961 | Base1.getAccessSpecifierAsWritten(), |
| 1962 | *TSIOrErr, |
| 1963 | EllipsisLoc)); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1964 | } |
| 1965 | if (!Bases.empty()) |
| Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1966 | ToCXX->setBases(Bases.data(), Bases.size()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1967 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1968 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1969 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1970 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1971 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1972 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1973 | return Error::success(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1974 | } |
| 1975 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1976 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1977 | if (To->getAnyInitializer()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1978 | return Error::success(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1979 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1980 | Expr *FromInit = From->getInit(); |
| 1981 | if (!FromInit) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1982 | return Error::success(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1983 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1984 | ExpectedExpr ToInitOrErr = import(FromInit); |
| 1985 | if (!ToInitOrErr) |
| 1986 | return ToInitOrErr.takeError(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1987 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1988 | To->setInit(*ToInitOrErr); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1989 | if (From->isInitKnownICE()) { |
| 1990 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); |
| 1991 | Eval->CheckedICE = true; |
| 1992 | Eval->IsICE = From->isInitICE(); |
| 1993 | } |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1994 | |
| 1995 | // FIXME: Other bits to merge? |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1996 | return Error::success(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1997 | } |
| 1998 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1999 | Error ASTNodeImporter::ImportDefinition( |
| 2000 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2001 | if (To->getDefinition() || To->isBeingDefined()) { |
| 2002 | if (Kind == IDK_Everything) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2003 | return ImportDeclContext(From, /*ForceImport=*/true); |
| 2004 | return Error::success(); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2005 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2006 | |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2007 | To->startDefinition(); |
| 2008 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2009 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 2010 | return Err; |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 2011 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2012 | ExpectedType ToTypeOrErr = |
| 2013 | import(Importer.getFromContext().getTypeDeclType(From)); |
| 2014 | if (!ToTypeOrErr) |
| 2015 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2016 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2017 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); |
| 2018 | if (!ToPromotionTypeOrErr) |
| 2019 | return ToPromotionTypeOrErr.takeError(); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 2020 | |
| 2021 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2022 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 2023 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2024 | |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2025 | // FIXME: we might need to merge the number of positive or negative bits |
| 2026 | // if the enumerator lists don't match. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2027 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2028 | From->getNumPositiveBits(), |
| 2029 | From->getNumNegativeBits()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2030 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2031 | } |
| 2032 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2033 | Error ASTNodeImporter::ImportTemplateArguments( |
| 2034 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 2035 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 2036 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2037 | if (auto ToOrErr = import(FromArgs[I])) |
| 2038 | ToArgs.push_back(*ToOrErr); |
| 2039 | else |
| 2040 | return ToOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 2041 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2042 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2043 | return Error::success(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 2044 | } |
| 2045 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2046 | // FIXME: Do not forget to remove this and use only 'import'. |
| 2047 | Expected<TemplateArgument> |
| 2048 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 2049 | return import(From); |
| 2050 | } |
| 2051 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2052 | template <typename InContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2053 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2054 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 2055 | for (const auto &FromLoc : Container) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2056 | if (auto ToLocOrErr = import(FromLoc)) |
| 2057 | ToTAInfo.addArgument(*ToLocOrErr); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2058 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2059 | return ToLocOrErr.takeError(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2060 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2061 | return Error::success(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2062 | } |
| 2063 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2064 | static StructuralEquivalenceKind |
| 2065 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 2066 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 2067 | : StructuralEquivalenceKind::Default; |
| 2068 | } |
| 2069 | |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2070 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { |
| 2071 | StructuralEquivalenceContext Ctx( |
| 2072 | Importer.getFromContext(), Importer.getToContext(), |
| 2073 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2074 | false, Complain); |
| 2075 | return Ctx.IsEquivalent(From, To); |
| 2076 | } |
| 2077 | |
| 2078 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2079 | RecordDecl *ToRecord, bool Complain) { |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2080 | // Eliminate a potential failure point where we attempt to re-import |
| 2081 | // something we're trying to import while completing ToRecord. |
| 2082 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 2083 | if (ToOrigin) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2084 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2085 | if (ToOriginRecord) |
| 2086 | ToRecord = ToOriginRecord; |
| 2087 | } |
| 2088 | |
| Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 2089 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2090 | ToRecord->getASTContext(), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2091 | Importer.getNonEquivalentDecls(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2092 | getStructuralEquivalenceKind(Importer), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2093 | false, Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2094 | return Ctx.IsEquivalent(FromRecord, ToRecord); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2095 | } |
| 2096 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2097 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 2098 | bool Complain) { |
| 2099 | StructuralEquivalenceContext Ctx( |
| 2100 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2101 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2102 | false, Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2103 | return Ctx.IsEquivalent(FromVar, ToVar); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2104 | } |
| 2105 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2106 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
| Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 2107 | // Eliminate a potential failure point where we attempt to re-import |
| Raphael Isemann | fa26c20 | 2019-04-09 14:18:23 +0000 | [diff] [blame] | 2108 | // something we're trying to import while completing ToEnum. |
| Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 2109 | if (Decl *ToOrigin = Importer.GetOriginalDecl(ToEnum)) |
| 2110 | if (auto *ToOriginEnum = dyn_cast<EnumDecl>(ToOrigin)) |
| 2111 | ToEnum = ToOriginEnum; |
| 2112 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2113 | StructuralEquivalenceContext Ctx( |
| 2114 | Importer.getFromContext(), Importer.getToContext(), |
| 2115 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2116 | return Ctx.IsEquivalent(FromEnum, ToEnum); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2117 | } |
| 2118 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2119 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 2120 | FunctionTemplateDecl *To) { |
| 2121 | StructuralEquivalenceContext Ctx( |
| 2122 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2123 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2124 | false, false); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2125 | return Ctx.IsEquivalent(From, To); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2126 | } |
| 2127 | |
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2128 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 2129 | StructuralEquivalenceContext Ctx( |
| 2130 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2131 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2132 | false, false); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2133 | return Ctx.IsEquivalent(From, To); |
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2134 | } |
| 2135 | |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2136 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2137 | EnumConstantDecl *ToEC) { |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2138 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 2139 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 2140 | |
| 2141 | return FromVal.isSigned() == ToVal.isSigned() && |
| 2142 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 2143 | FromVal == ToVal; |
| 2144 | } |
| 2145 | |
| 2146 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2147 | ClassTemplateDecl *To) { |
| 2148 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2149 | Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2150 | Importer.getNonEquivalentDecls(), |
| 2151 | getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2152 | return Ctx.IsEquivalent(From, To); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2153 | } |
| 2154 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2155 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 2156 | VarTemplateDecl *To) { |
| 2157 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2158 | Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2159 | Importer.getNonEquivalentDecls(), |
| 2160 | getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2161 | return Ctx.IsEquivalent(From, To); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2162 | } |
| 2163 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2164 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 2165 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2166 | << D->getDeclKindName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2167 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2168 | } |
| 2169 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2170 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { |
| 2171 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 2172 | << D->getDeclKindName(); |
| 2173 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| 2174 | } |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2175 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2176 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 2177 | // Import the context of this declaration. |
| 2178 | DeclContext *DC, *LexicalDC; |
| 2179 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 2180 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2181 | |
| 2182 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2183 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2184 | if (!LocOrErr) |
| 2185 | return LocOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2186 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2187 | EmptyDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2188 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2189 | return ToD; |
| 2190 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2191 | ToD->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2192 | LexicalDC->addDeclInternal(ToD); |
| 2193 | return ToD; |
| 2194 | } |
| 2195 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2196 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2197 | TranslationUnitDecl *ToD = |
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2198 | Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2199 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2200 | Importer.MapImported(D, ToD); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2201 | |
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2202 | return ToD; |
| 2203 | } |
| 2204 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2205 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 2206 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2207 | if (!LocOrErr) |
| 2208 | return LocOrErr.takeError(); |
| 2209 | auto ColonLocOrErr = import(D->getColonLoc()); |
| 2210 | if (!ColonLocOrErr) |
| 2211 | return ColonLocOrErr.takeError(); |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2212 | |
| 2213 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2214 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2215 | if (!DCOrErr) |
| 2216 | return DCOrErr.takeError(); |
| 2217 | DeclContext *DC = *DCOrErr; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2218 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2219 | AccessSpecDecl *ToD; |
| 2220 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2221 | DC, *LocOrErr, *ColonLocOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2222 | return ToD; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2223 | |
| 2224 | // Lexical DeclContext and Semantic DeclContext |
| 2225 | // is always the same for the accessSpec. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2226 | ToD->setLexicalDeclContext(DC); |
| 2227 | DC->addDeclInternal(ToD); |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2228 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2229 | return ToD; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2230 | } |
| 2231 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2232 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 2233 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2234 | if (!DCOrErr) |
| 2235 | return DCOrErr.takeError(); |
| 2236 | DeclContext *DC = *DCOrErr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2237 | DeclContext *LexicalDC = DC; |
| 2238 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2239 | SourceLocation ToLocation, ToRParenLoc; |
| 2240 | Expr *ToAssertExpr; |
| 2241 | StringLiteral *ToMessage; |
| 2242 | if (auto Imp = importSeq( |
| 2243 | D->getLocation(), D->getAssertExpr(), D->getMessage(), D->getRParenLoc())) |
| 2244 | std::tie(ToLocation, ToAssertExpr, ToMessage, ToRParenLoc) = *Imp; |
| 2245 | else |
| 2246 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2247 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2248 | StaticAssertDecl *ToD; |
| 2249 | if (GetImportedOrCreateDecl( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2250 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, |
| 2251 | ToRParenLoc, D->isFailed())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2252 | return ToD; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2253 | |
| 2254 | ToD->setLexicalDeclContext(LexicalDC); |
| 2255 | LexicalDC->addDeclInternal(ToD); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2256 | return ToD; |
| 2257 | } |
| 2258 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2259 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2260 | // Import the major distinguishing characteristics of this namespace. |
| 2261 | DeclContext *DC, *LexicalDC; |
| 2262 | DeclarationName Name; |
| 2263 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2264 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2265 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2266 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2267 | if (ToD) |
| 2268 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2269 | |
| 2270 | NamespaceDecl *MergeWithNamespace = nullptr; |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2271 | if (!Name) { |
| 2272 | // This is an anonymous namespace. Adopt an existing anonymous |
| 2273 | // namespace if we can. |
| 2274 | // FIXME: Not testable. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2275 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2276 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 2277 | else |
| 2278 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 2279 | } else { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2280 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2281 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2282 | for (auto *FoundDecl : FoundDecls) { |
| 2283 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2284 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2285 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2286 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2287 | MergeWithNamespace = FoundNS; |
| 2288 | ConflictingDecls.clear(); |
| 2289 | break; |
| 2290 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2291 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2292 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2293 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2294 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2295 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2296 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2297 | Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(), |
| 2298 | ConflictingDecls.size()); |
| 2299 | if (NameOrErr) |
| 2300 | Name = NameOrErr.get(); |
| 2301 | else |
| 2302 | return NameOrErr.takeError(); |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2303 | } |
| 2304 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2305 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2306 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2307 | if (!BeginLocOrErr) |
| 2308 | return BeginLocOrErr.takeError(); |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2309 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 2310 | if (!RBraceLocOrErr) |
| 2311 | return RBraceLocOrErr.takeError(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2312 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2313 | // Create the "to" namespace, if needed. |
| 2314 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 2315 | if (!ToNamespace) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2316 | if (GetImportedOrCreateDecl( |
| 2317 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2318 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2319 | /*PrevDecl=*/nullptr)) |
| 2320 | return ToNamespace; |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2321 | ToNamespace->setRBraceLoc(*RBraceLocOrErr); |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2322 | ToNamespace->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2323 | LexicalDC->addDeclInternal(ToNamespace); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2324 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2325 | // If this is an anonymous namespace, register it as the anonymous |
| 2326 | // namespace within its context. |
| 2327 | if (!Name) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2328 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2329 | TU->setAnonymousNamespace(ToNamespace); |
| 2330 | else |
| 2331 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 2332 | } |
| 2333 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2334 | Importer.MapImported(D, ToNamespace); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2335 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2336 | if (Error Err = ImportDeclContext(D)) |
| 2337 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2338 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2339 | return ToNamespace; |
| 2340 | } |
| 2341 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2342 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2343 | // Import the major distinguishing characteristics of this namespace. |
| 2344 | DeclContext *DC, *LexicalDC; |
| 2345 | DeclarationName Name; |
| 2346 | SourceLocation Loc; |
| 2347 | NamedDecl *LookupD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2348 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 2349 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2350 | if (LookupD) |
| 2351 | return LookupD; |
| 2352 | |
| 2353 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 2354 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2355 | SourceLocation ToNamespaceLoc, ToAliasLoc, ToTargetNameLoc; |
| 2356 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2357 | NamespaceDecl *ToNamespace; |
| 2358 | if (auto Imp = importSeq( |
| 2359 | D->getNamespaceLoc(), D->getAliasLoc(), D->getQualifierLoc(), |
| 2360 | D->getTargetNameLoc(), D->getNamespace())) |
| 2361 | std::tie( |
| 2362 | ToNamespaceLoc, ToAliasLoc, ToQualifierLoc, ToTargetNameLoc, |
| 2363 | ToNamespace) = *Imp; |
| 2364 | else |
| 2365 | return Imp.takeError(); |
| 2366 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2367 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2368 | NamespaceAliasDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2369 | if (GetImportedOrCreateDecl( |
| 2370 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, |
| 2371 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2372 | return ToD; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2373 | |
| 2374 | ToD->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2375 | LexicalDC->addDeclInternal(ToD); |
| 2376 | |
| 2377 | return ToD; |
| 2378 | } |
| 2379 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2380 | ExpectedDecl |
| 2381 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2382 | // Import the major distinguishing characteristics of this typedef. |
| 2383 | DeclContext *DC, *LexicalDC; |
| 2384 | DeclarationName Name; |
| 2385 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2386 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2387 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2388 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2389 | if (ToD) |
| 2390 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2391 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2392 | // If this typedef is not in block scope, determine whether we've |
| 2393 | // seen a typedef with the same name (that we can merge with) or any |
| 2394 | // other entity by that name (which name lookup could conflict with). |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 2395 | // Note: Repeated typedefs are not valid in C99: |
| 2396 | // 'typedef int T; typedef int T;' is invalid |
| 2397 | // We do not care about this now. |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2398 | if (!DC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2399 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2400 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2401 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2402 | for (auto *FoundDecl : FoundDecls) { |
| 2403 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2404 | continue; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2405 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 2406 | if (!hasSameVisibilityContext(FoundTypedef, D)) |
| 2407 | continue; |
| 2408 | |
| Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2409 | QualType FromUT = D->getUnderlyingType(); |
| 2410 | QualType FoundUT = FoundTypedef->getUnderlyingType(); |
| 2411 | if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) { |
| 2412 | // If the "From" context has a complete underlying type but we |
| 2413 | // already have a complete underlying type then return with that. |
| 2414 | if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2415 | return Importer.MapImported(D, FoundTypedef); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2416 | // FIXME Handle redecl chain. When you do that make consistent changes |
| 2417 | // in ASTImporterLookupTable too. |
| 2418 | } else { |
| 2419 | ConflictingDecls.push_back(FoundDecl); |
| Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2420 | } |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2421 | } |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2422 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2423 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2424 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2425 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2426 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 2427 | if (NameOrErr) |
| 2428 | Name = NameOrErr.get(); |
| 2429 | else |
| 2430 | return NameOrErr.takeError(); |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2431 | } |
| 2432 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2433 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2434 | QualType ToUnderlyingType; |
| 2435 | TypeSourceInfo *ToTypeSourceInfo; |
| 2436 | SourceLocation ToBeginLoc; |
| 2437 | if (auto Imp = importSeq( |
| 2438 | D->getUnderlyingType(), D->getTypeSourceInfo(), D->getBeginLoc())) |
| 2439 | std::tie(ToUnderlyingType, ToTypeSourceInfo, ToBeginLoc) = *Imp; |
| 2440 | else |
| 2441 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2442 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2443 | // Create the new typedef node. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2444 | // FIXME: ToUnderlyingType is not used. |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2445 | TypedefNameDecl *ToTypedef; |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2446 | if (IsAlias) { |
| 2447 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2448 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2449 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2450 | return ToTypedef; |
| 2451 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2452 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2453 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2454 | return ToTypedef; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2455 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2456 | ToTypedef->setAccess(D->getAccess()); |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2457 | ToTypedef->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2458 | |
| 2459 | // Templated declarations should not appear in DeclContext. |
| 2460 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 2461 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 2462 | LexicalDC->addDeclInternal(ToTypedef); |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2463 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2464 | return ToTypedef; |
| 2465 | } |
| 2466 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2467 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2468 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 2469 | } |
| 2470 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2471 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2472 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 2473 | } |
| 2474 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2475 | ExpectedDecl |
| 2476 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2477 | // Import the major distinguishing characteristics of this typedef. |
| 2478 | DeclContext *DC, *LexicalDC; |
| 2479 | DeclarationName Name; |
| 2480 | SourceLocation Loc; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2481 | NamedDecl *FoundD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2482 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
| 2483 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2484 | if (FoundD) |
| 2485 | return FoundD; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2486 | |
| 2487 | // If this typedef is not in block scope, determine whether we've |
| 2488 | // seen a typedef with the same name (that we can merge with) or any |
| 2489 | // other entity by that name (which name lookup could conflict with). |
| 2490 | if (!DC->isFunctionOrMethod()) { |
| 2491 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 2492 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2493 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2494 | for (auto *FoundDecl : FoundDecls) { |
| 2495 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2496 | continue; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2497 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2498 | return Importer.MapImported(D, FoundAlias); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2499 | ConflictingDecls.push_back(FoundDecl); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2500 | } |
| 2501 | |
| 2502 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2503 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2504 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 2505 | if (NameOrErr) |
| 2506 | Name = NameOrErr.get(); |
| 2507 | else |
| 2508 | return NameOrErr.takeError(); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2509 | } |
| 2510 | } |
| 2511 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2512 | TemplateParameterList *ToTemplateParameters; |
| 2513 | TypeAliasDecl *ToTemplatedDecl; |
| 2514 | if (auto Imp = importSeq(D->getTemplateParameters(), D->getTemplatedDecl())) |
| 2515 | std::tie(ToTemplateParameters, ToTemplatedDecl) = *Imp; |
| 2516 | else |
| 2517 | return Imp.takeError(); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2518 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2519 | TypeAliasTemplateDecl *ToAlias; |
| 2520 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2521 | Name, ToTemplateParameters, ToTemplatedDecl)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2522 | return ToAlias; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2523 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2524 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2525 | |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2526 | ToAlias->setAccess(D->getAccess()); |
| 2527 | ToAlias->setLexicalDeclContext(LexicalDC); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2528 | LexicalDC->addDeclInternal(ToAlias); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2529 | return ToAlias; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2530 | } |
| 2531 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2532 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2533 | // Import the major distinguishing characteristics of this label. |
| 2534 | DeclContext *DC, *LexicalDC; |
| 2535 | DeclarationName Name; |
| 2536 | SourceLocation Loc; |
| 2537 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2538 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2539 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2540 | if (ToD) |
| 2541 | return ToD; |
| 2542 | |
| 2543 | assert(LexicalDC->isFunctionOrMethod()); |
| 2544 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2545 | LabelDecl *ToLabel; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2546 | if (D->isGnuLocal()) { |
| 2547 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2548 | if (!BeginLocOrErr) |
| 2549 | return BeginLocOrErr.takeError(); |
| 2550 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2551 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) |
| 2552 | return ToLabel; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2553 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2554 | } else { |
| 2555 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2556 | Name.getAsIdentifierInfo())) |
| 2557 | return ToLabel; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2558 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); |
| 2562 | if (!ToStmtOrErr) |
| 2563 | return ToStmtOrErr.takeError(); |
| 2564 | |
| 2565 | ToLabel->setStmt(*ToStmtOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2566 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2567 | LexicalDC->addDeclInternal(ToLabel); |
| 2568 | return ToLabel; |
| 2569 | } |
| 2570 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2571 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2572 | // Import the major distinguishing characteristics of this enum. |
| 2573 | DeclContext *DC, *LexicalDC; |
| 2574 | DeclarationName Name; |
| 2575 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2576 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2577 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2578 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2579 | if (ToD) |
| 2580 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2581 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2582 | // Figure out what enum name we're looking for. |
| 2583 | unsigned IDNS = Decl::IDNS_Tag; |
| 2584 | DeclarationName SearchName = Name; |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2585 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2586 | if (Error Err = importInto( |
| 2587 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2588 | return std::move(Err); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2589 | IDNS = Decl::IDNS_Ordinary; |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2590 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2591 | IDNS |= Decl::IDNS_Ordinary; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2592 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2593 | // We may already have an enum of the same name; try to find and match it. |
| 2594 | if (!DC->isFunctionOrMethod() && SearchName) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2595 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2596 | auto FoundDecls = |
| 2597 | Importer.findDeclsInToCtx(DC, SearchName); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2598 | for (auto *FoundDecl : FoundDecls) { |
| 2599 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2600 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2601 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2602 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2603 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2604 | FoundDecl = Tag->getDecl(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2605 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2606 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2607 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { |
| Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 2608 | if (!hasSameVisibilityContext(FoundEnum, D)) |
| 2609 | continue; |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2610 | if (IsStructuralMatch(D, FoundEnum)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2611 | return Importer.MapImported(D, FoundEnum); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2612 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2613 | } |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2614 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2615 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2616 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2617 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2618 | SearchName, DC, IDNS, ConflictingDecls.data(), |
| 2619 | ConflictingDecls.size()); |
| 2620 | if (NameOrErr) |
| 2621 | Name = NameOrErr.get(); |
| 2622 | else |
| 2623 | return NameOrErr.takeError(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2624 | } |
| 2625 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2626 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2627 | SourceLocation ToBeginLoc; |
| 2628 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2629 | QualType ToIntegerType; |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2630 | SourceRange ToBraceRange; |
| 2631 | if (auto Imp = importSeq(D->getBeginLoc(), D->getQualifierLoc(), |
| 2632 | D->getIntegerType(), D->getBraceRange())) |
| 2633 | std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType, ToBraceRange) = *Imp; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2634 | else |
| 2635 | return Imp.takeError(); |
| 2636 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2637 | // Create the enum declaration. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2638 | EnumDecl *D2; |
| 2639 | if (GetImportedOrCreateDecl( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2640 | D2, D, Importer.getToContext(), DC, ToBeginLoc, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2641 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), |
| 2642 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2643 | return D2; |
| 2644 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2645 | D2->setQualifierInfo(ToQualifierLoc); |
| 2646 | D2->setIntegerType(ToIntegerType); |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2647 | D2->setBraceRange(ToBraceRange); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2648 | D2->setAccess(D->getAccess()); |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2649 | D2->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2650 | LexicalDC->addDeclInternal(D2); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2651 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2652 | // Import the definition |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2653 | if (D->isCompleteDefinition()) |
| 2654 | if (Error Err = ImportDefinition(D, D2)) |
| 2655 | return std::move(Err); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2656 | |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2657 | return D2; |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2658 | } |
| 2659 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2660 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2661 | bool IsFriendTemplate = false; |
| 2662 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2663 | IsFriendTemplate = |
| 2664 | DCXX->getDescribedClassTemplate() && |
| 2665 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != |
| 2666 | Decl::FOK_None; |
| 2667 | } |
| 2668 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2669 | // Import the major distinguishing characteristics of this record. |
| Simon Pilgrim | 4706f3b | 2019-10-15 10:23:05 +0000 | [diff] [blame] | 2670 | DeclContext *DC = nullptr, *LexicalDC = nullptr; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2671 | DeclarationName Name; |
| 2672 | SourceLocation Loc; |
| Simon Pilgrim | 4706f3b | 2019-10-15 10:23:05 +0000 | [diff] [blame] | 2673 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2674 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2675 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2676 | if (ToD) |
| 2677 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2678 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2679 | // Figure out what structure name we're looking for. |
| 2680 | unsigned IDNS = Decl::IDNS_Tag; |
| 2681 | DeclarationName SearchName = Name; |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2682 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2683 | if (Error Err = importInto( |
| 2684 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2685 | return std::move(Err); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2686 | IDNS = Decl::IDNS_Ordinary; |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2687 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2688 | IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2689 | |
| 2690 | // 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] | 2691 | RecordDecl *PrevDecl = nullptr; |
| Gabor Marton | e3e83d7 | 2019-08-30 10:55:41 +0000 | [diff] [blame] | 2692 | if (!DC->isFunctionOrMethod() && !D->isLambda()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2693 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2694 | auto FoundDecls = |
| 2695 | Importer.findDeclsInToCtx(DC, SearchName); |
| Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2696 | if (!FoundDecls.empty()) { |
| Gabor Marton | 41e3892 | 2019-03-05 11:23:24 +0000 | [diff] [blame] | 2697 | // We're going to have to compare D against potentially conflicting Decls, |
| 2698 | // so complete it. |
| Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2699 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2700 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2701 | } |
| 2702 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2703 | for (auto *FoundDecl : FoundDecls) { |
| 2704 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2705 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2706 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2707 | Decl *Found = FoundDecl; |
| 2708 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2709 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2710 | Found = Tag->getDecl(); |
| 2711 | } |
| Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2712 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2713 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2714 | // Do not emit false positive diagnostic in case of unnamed |
| 2715 | // struct/union and in case of anonymous structs. Would be false |
| 2716 | // because there may be several anonymous/unnamed structs in a class. |
| 2717 | // E.g. these are both valid: |
| 2718 | // struct A { // unnamed structs |
| 2719 | // struct { struct A *next; } entry0; |
| 2720 | // struct { struct A *next; } entry1; |
| 2721 | // }; |
| 2722 | // struct X { struct { int a; }; struct { int b; }; }; // anon structs |
| 2723 | if (!SearchName) |
| Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2724 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2725 | continue; |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2726 | |
| Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 2727 | if (!hasSameVisibilityContext(FoundRecord, D)) |
| 2728 | continue; |
| 2729 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2730 | if (IsStructuralMatch(D, FoundRecord)) { |
| 2731 | RecordDecl *FoundDef = FoundRecord->getDefinition(); |
| 2732 | if (D->isThisDeclarationADefinition() && FoundDef) { |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2733 | // FIXME: Structural equivalence check should check for same |
| 2734 | // user-defined methods. |
| 2735 | Importer.MapImported(D, FoundDef); |
| 2736 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2737 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); |
| 2738 | assert(FoundCXX && "Record type mismatch"); |
| 2739 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2740 | if (!Importer.isMinimalImport()) |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2741 | // FoundDef may not have every implicit method that D has |
| 2742 | // because implicit methods are created only if they are used. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2743 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) |
| 2744 | return std::move(Err); |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2745 | } |
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2746 | } |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2747 | PrevDecl = FoundRecord->getMostRecentDecl(); |
| 2748 | break; |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2749 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2750 | ConflictingDecls.push_back(FoundDecl); |
| 2751 | } // kind is RecordDecl |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2752 | } // for |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2753 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2754 | if (!ConflictingDecls.empty() && SearchName) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2755 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2756 | SearchName, DC, IDNS, ConflictingDecls.data(), |
| 2757 | ConflictingDecls.size()); |
| 2758 | if (NameOrErr) |
| 2759 | Name = NameOrErr.get(); |
| 2760 | else |
| 2761 | return NameOrErr.takeError(); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2762 | } |
| 2763 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2764 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2765 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2766 | if (!BeginLocOrErr) |
| 2767 | return BeginLocOrErr.takeError(); |
| 2768 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2769 | // Create the record declaration. |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2770 | RecordDecl *D2 = nullptr; |
| 2771 | CXXRecordDecl *D2CXX = nullptr; |
| 2772 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2773 | if (DCXX->isLambda()) { |
| 2774 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); |
| 2775 | if (!TInfoOrErr) |
| 2776 | return TInfoOrErr.takeError(); |
| 2777 | if (GetImportedOrCreateSpecialDecl( |
| 2778 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
| 2779 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), |
| 2780 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2781 | return D2CXX; |
| 2782 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); |
| 2783 | if (!CDeclOrErr) |
| 2784 | return CDeclOrErr.takeError(); |
| Michael Liao | 243ebfb | 2019-10-19 00:15:19 +0000 | [diff] [blame] | 2785 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr, |
| 2786 | DCXX->hasKnownLambdaInternalLinkage()); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2787 | } else if (DCXX->isInjectedClassName()) { |
| 2788 | // We have to be careful to do a similar dance to the one in |
| 2789 | // Sema::ActOnStartCXXMemberDeclarations |
| 2790 | const bool DelayTypeCreation = true; |
| 2791 | if (GetImportedOrCreateDecl( |
| 2792 | D2CXX, D, Importer.getToContext(), D->getTagKind(), DC, |
| 2793 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
| 2794 | cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation)) |
| 2795 | return D2CXX; |
| 2796 | Importer.getToContext().getTypeDeclType( |
| 2797 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
| 2798 | } else { |
| 2799 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2800 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2801 | Name.getAsIdentifierInfo(), |
| 2802 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2803 | return D2CXX; |
| 2804 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2805 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2806 | D2 = D2CXX; |
| 2807 | D2->setAccess(D->getAccess()); |
| 2808 | D2->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 2809 | addDeclToContexts(D, D2); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2810 | |
| 2811 | if (ClassTemplateDecl *FromDescribed = |
| 2812 | DCXX->getDescribedClassTemplate()) { |
| 2813 | ClassTemplateDecl *ToDescribed; |
| 2814 | if (Error Err = importInto(ToDescribed, FromDescribed)) |
| 2815 | return std::move(Err); |
| 2816 | D2CXX->setDescribedClassTemplate(ToDescribed); |
| 2817 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { |
| 2818 | // In a record describing a template the type should be an |
| 2819 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2820 | // previously set type to the correct value here (ToDescribed is not |
| 2821 | // available at record create). |
| 2822 | // FIXME: The previous type is cleared but not removed from |
| 2823 | // ASTContext's internal storage. |
| 2824 | CXXRecordDecl *Injected = nullptr; |
| 2825 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2826 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2827 | if (Record && Record->isInjectedClassName()) { |
| 2828 | Injected = Record; |
| 2829 | break; |
| Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2830 | } |
| 2831 | } |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2832 | // Create an injected type for the whole redecl chain. |
| 2833 | SmallVector<Decl *, 2> Redecls = |
| 2834 | getCanonicalForwardRedeclChain(D2CXX); |
| 2835 | for (auto *R : Redecls) { |
| 2836 | auto *RI = cast<CXXRecordDecl>(R); |
| 2837 | RI->setTypeForDecl(nullptr); |
| 2838 | // Below we create a new injected type and assign that to the |
| 2839 | // canonical decl, subsequent declarations in the chain will reuse |
| 2840 | // that type. |
| 2841 | Importer.getToContext().getInjectedClassNameType( |
| 2842 | RI, ToDescribed->getInjectedClassNameSpecialization()); |
| 2843 | } |
| 2844 | // Set the new type for the previous injected decl too. |
| 2845 | if (Injected) { |
| 2846 | Injected->setTypeForDecl(nullptr); |
| 2847 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2848 | } |
| 2849 | } |
| 2850 | } else if (MemberSpecializationInfo *MemberInfo = |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2851 | DCXX->getMemberSpecializationInfo()) { |
| 2852 | TemplateSpecializationKind SK = |
| 2853 | MemberInfo->getTemplateSpecializationKind(); |
| 2854 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2855 | |
| 2856 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) |
| 2857 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); |
| 2858 | else |
| 2859 | return ToInstOrErr.takeError(); |
| 2860 | |
| 2861 | if (ExpectedSLoc POIOrErr = |
| 2862 | import(MemberInfo->getPointOfInstantiation())) |
| 2863 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2864 | *POIOrErr); |
| 2865 | else |
| 2866 | return POIOrErr.takeError(); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2867 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2868 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2869 | } else { |
| 2870 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
| 2871 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2872 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2873 | return D2; |
| 2874 | D2->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 2875 | addDeclToContexts(D, D2); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2876 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2877 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2878 | if (auto BraceRangeOrErr = import(D->getBraceRange())) |
| 2879 | D2->setBraceRange(*BraceRangeOrErr); |
| 2880 | else |
| 2881 | return BraceRangeOrErr.takeError(); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2882 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) |
| 2883 | D2->setQualifierInfo(*QualifierLocOrErr); |
| 2884 | else |
| 2885 | return QualifierLocOrErr.takeError(); |
| 2886 | |
| 2887 | if (D->isAnonymousStructOrUnion()) |
| 2888 | D2->setAnonymousStructOrUnion(true); |
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2889 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2890 | if (D->isCompleteDefinition()) |
| 2891 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) |
| 2892 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2893 | |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2894 | return D2; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2895 | } |
| 2896 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2897 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2898 | // Import the major distinguishing characteristics of this enumerator. |
| 2899 | DeclContext *DC, *LexicalDC; |
| 2900 | DeclarationName Name; |
| 2901 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2902 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2903 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2904 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2905 | if (ToD) |
| 2906 | return ToD; |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2907 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2908 | // Determine whether there are any other declarations with the same name and |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2909 | // in the same context. |
| 2910 | if (!LexicalDC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2911 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2912 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2913 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2914 | for (auto *FoundDecl : FoundDecls) { |
| 2915 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2916 | continue; |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2917 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2918 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2919 | if (IsStructuralMatch(D, FoundEnumConstant)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2920 | return Importer.MapImported(D, FoundEnumConstant); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2921 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2922 | } |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2923 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2924 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2925 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2926 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2927 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 2928 | if (NameOrErr) |
| 2929 | Name = NameOrErr.get(); |
| 2930 | else |
| 2931 | return NameOrErr.takeError(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2932 | } |
| 2933 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2934 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2935 | ExpectedType TypeOrErr = import(D->getType()); |
| 2936 | if (!TypeOrErr) |
| 2937 | return TypeOrErr.takeError(); |
| 2938 | |
| 2939 | ExpectedExpr InitOrErr = import(D->getInitExpr()); |
| 2940 | if (!InitOrErr) |
| 2941 | return InitOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2942 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2943 | EnumConstantDecl *ToEnumerator; |
| 2944 | if (GetImportedOrCreateDecl( |
| 2945 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2946 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2947 | return ToEnumerator; |
| 2948 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2949 | ToEnumerator->setAccess(D->getAccess()); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2950 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2951 | LexicalDC->addDeclInternal(ToEnumerator); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2952 | return ToEnumerator; |
| 2953 | } |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2954 | |
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 2955 | Error ASTNodeImporter::ImportTemplateParameterLists(const DeclaratorDecl *FromD, |
| 2956 | DeclaratorDecl *ToD) { |
| 2957 | unsigned int Num = FromD->getNumTemplateParameterLists(); |
| 2958 | if (Num == 0) |
| 2959 | return Error::success(); |
| 2960 | SmallVector<TemplateParameterList *, 2> ToTPLists(Num); |
| 2961 | for (unsigned int I = 0; I < Num; ++I) |
| 2962 | if (Expected<TemplateParameterList *> ToTPListOrErr = |
| 2963 | import(FromD->getTemplateParameterList(I))) |
| 2964 | ToTPLists[I] = *ToTPListOrErr; |
| 2965 | else |
| 2966 | return ToTPListOrErr.takeError(); |
| 2967 | ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists); |
| 2968 | return Error::success(); |
| 2969 | } |
| 2970 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2971 | Error ASTNodeImporter::ImportTemplateInformation( |
| 2972 | FunctionDecl *FromFD, FunctionDecl *ToFD) { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2973 | switch (FromFD->getTemplatedKind()) { |
| 2974 | case FunctionDecl::TK_NonTemplate: |
| 2975 | case FunctionDecl::TK_FunctionTemplate: |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2976 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2977 | |
| 2978 | case FunctionDecl::TK_MemberSpecialization: { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2979 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2980 | |
| 2981 | if (Expected<FunctionDecl *> InstFDOrErr = |
| 2982 | import(FromFD->getInstantiatedFromMemberFunction())) |
| 2983 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); |
| 2984 | else |
| 2985 | return InstFDOrErr.takeError(); |
| 2986 | |
| 2987 | if (ExpectedSLoc POIOrErr = import( |
| 2988 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) |
| 2989 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); |
| 2990 | else |
| 2991 | return POIOrErr.takeError(); |
| 2992 | |
| 2993 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2994 | } |
| 2995 | |
| 2996 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2997 | auto FunctionAndArgsOrErr = |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2998 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2999 | if (!FunctionAndArgsOrErr) |
| 3000 | return FunctionAndArgsOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3001 | |
| 3002 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3003 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3004 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3005 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3006 | TemplateArgumentListInfo ToTAInfo; |
| 3007 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3008 | if (FromTAArgsAsWritten) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3009 | if (Error Err = ImportTemplateArgumentListInfo( |
| 3010 | *FromTAArgsAsWritten, ToTAInfo)) |
| 3011 | return Err; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3012 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3013 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); |
| 3014 | if (!POIOrErr) |
| 3015 | return POIOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3016 | |
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 3017 | if (Error Err = ImportTemplateParameterLists(FromFD, ToFD)) |
| 3018 | return Err; |
| 3019 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3020 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3021 | ToFD->setFunctionTemplateSpecialization( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3022 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, |
| 3023 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); |
| 3024 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3025 | } |
| 3026 | |
| 3027 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 3028 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 3029 | UnresolvedSet<8> TemplDecls; |
| 3030 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 3031 | for (unsigned I = 0; I < NumTemplates; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3032 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = |
| 3033 | import(FromInfo->getTemplate(I))) |
| 3034 | TemplDecls.addDecl(*ToFTDOrErr); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3035 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3036 | return ToFTDOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | // Import TemplateArgumentListInfo. |
| 3040 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3041 | if (Error Err = ImportTemplateArgumentListInfo( |
| 3042 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 3043 | llvm::makeArrayRef( |
| 3044 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), |
| 3045 | ToTAInfo)) |
| 3046 | return Err; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3047 | |
| 3048 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 3049 | TemplDecls, ToTAInfo); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3050 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3051 | } |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3052 | } |
| Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 3053 | llvm_unreachable("All cases should be covered!"); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3054 | } |
| 3055 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3056 | Expected<FunctionDecl *> |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3057 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3058 | auto FunctionAndArgsOrErr = |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3059 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3060 | if (!FunctionAndArgsOrErr) |
| 3061 | return FunctionAndArgsOrErr.takeError(); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3062 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3063 | FunctionTemplateDecl *Template; |
| 3064 | TemplateArgsTy ToTemplArgs; |
| 3065 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3066 | void *InsertPos = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3067 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3068 | return FoundSpec; |
| 3069 | } |
| 3070 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3071 | Error ASTNodeImporter::ImportFunctionDeclBody(FunctionDecl *FromFD, |
| 3072 | FunctionDecl *ToFD) { |
| 3073 | if (Stmt *FromBody = FromFD->getBody()) { |
| 3074 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) |
| 3075 | ToFD->setBody(*ToBodyOrErr); |
| 3076 | else |
| 3077 | return ToBodyOrErr.takeError(); |
| 3078 | } |
| 3079 | return Error::success(); |
| 3080 | } |
| 3081 | |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3082 | // Returns true if the given D has a DeclContext up to the TranslationUnitDecl |
| 3083 | // which is equal to the given DC. |
| Benjamin Kramer | df18650 | 2020-01-14 14:06:12 +0100 | [diff] [blame] | 3084 | static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) { |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3085 | const DeclContext *DCi = D->getDeclContext(); |
| 3086 | while (DCi != D->getTranslationUnitDecl()) { |
| 3087 | if (DCi == DC) |
| 3088 | return true; |
| 3089 | DCi = DCi->getParent(); |
| 3090 | } |
| 3091 | return false; |
| 3092 | } |
| 3093 | |
| 3094 | bool ASTNodeImporter::hasAutoReturnTypeDeclaredInside(FunctionDecl *D) { |
| 3095 | QualType FromTy = D->getType(); |
| 3096 | const FunctionProtoType *FromFPT = FromTy->getAs<FunctionProtoType>(); |
| 3097 | assert(FromFPT && "Must be called on FunctionProtoType"); |
| 3098 | if (AutoType *AutoT = FromFPT->getReturnType()->getContainedAutoType()) { |
| 3099 | QualType DeducedT = AutoT->getDeducedType(); |
| 3100 | if (const RecordType *RecordT = |
| 3101 | DeducedT.isNull() ? nullptr : dyn_cast<RecordType>(DeducedT)) { |
| 3102 | RecordDecl *RD = RecordT->getDecl(); |
| 3103 | assert(RD); |
| 3104 | if (isAncestorDeclContextOf(D, RD)) { |
| 3105 | assert(RD->getLexicalDeclContext() == RD->getDeclContext()); |
| 3106 | return true; |
| 3107 | } |
| 3108 | } |
| 3109 | } |
| 3110 | if (const TypedefType *TypedefT = |
| 3111 | dyn_cast<TypedefType>(FromFPT->getReturnType())) { |
| 3112 | TypedefNameDecl *TD = TypedefT->getDecl(); |
| 3113 | assert(TD); |
| 3114 | if (isAncestorDeclContextOf(D, TD)) { |
| 3115 | assert(TD->getLexicalDeclContext() == TD->getDeclContext()); |
| 3116 | return true; |
| 3117 | } |
| 3118 | } |
| 3119 | return false; |
| 3120 | } |
| 3121 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3122 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3123 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3124 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3125 | auto RedeclIt = Redecls.begin(); |
| 3126 | // Import the first part of the decl chain. I.e. import all previous |
| 3127 | // declarations starting from the canonical decl. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3128 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3129 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3130 | if (!ToRedeclOrErr) |
| 3131 | return ToRedeclOrErr.takeError(); |
| 3132 | } |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3133 | assert(*RedeclIt == D); |
| 3134 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3135 | // Import the major distinguishing characteristics of this function. |
| 3136 | DeclContext *DC, *LexicalDC; |
| 3137 | DeclarationName Name; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3138 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3139 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3140 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3141 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3142 | if (ToD) |
| 3143 | return ToD; |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3144 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3145 | FunctionDecl *FoundByLookup = nullptr; |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3146 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); |
| Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 3147 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3148 | // 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] | 3149 | // existing specialization in the "to" context. The lookup below will not |
| 3150 | // find any specialization, but would find the primary template; thus, we |
| 3151 | // have to skip normal lookup in case of specializations. |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3152 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 3153 | if (D->getTemplatedKind() == |
| 3154 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3155 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); |
| 3156 | if (!FoundFunctionOrErr) |
| 3157 | return FoundFunctionOrErr.takeError(); |
| 3158 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { |
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 3159 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 3160 | return Def; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3161 | FoundByLookup = FoundFunction; |
| 3162 | } |
| 3163 | } |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3164 | // Try to find a function in our own ("to") context with the same name, same |
| 3165 | // type, and in the same context as the function we're importing. |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3166 | else if (!LexicalDC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3167 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3168 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3169 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3170 | for (auto *FoundDecl : FoundDecls) { |
| 3171 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3172 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3173 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3174 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3175 | if (!hasSameVisibilityContext(FoundFunction, D)) |
| 3176 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3177 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3178 | if (IsStructuralMatch(D, FoundFunction)) { |
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 3179 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 3180 | return Def; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3181 | FoundByLookup = FoundFunction; |
| 3182 | break; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3183 | } |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3184 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 3185 | // Sema::IsOverload out to the AST library. |
| 3186 | |
| 3187 | // Function overloading is okay in C++. |
| 3188 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
| 3189 | continue; |
| 3190 | |
| 3191 | // Complain about inconsistent function types. |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3192 | Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3193 | << Name << D->getType() << FoundFunction->getType(); |
| 3194 | Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here) |
| 3195 | << FoundFunction->getType(); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3196 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3197 | } |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3198 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3199 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3200 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3201 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 3202 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 3203 | if (NameOrErr) |
| 3204 | Name = NameOrErr.get(); |
| 3205 | else |
| 3206 | return NameOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3207 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3208 | } |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3209 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3210 | // We do not allow more than one in-class declaration of a function. This is |
| 3211 | // because AST clients like VTableBuilder asserts on this. VTableBuilder |
| 3212 | // assumes there is only one in-class declaration. Building a redecl |
| 3213 | // chain would result in more than one in-class declaration for |
| 3214 | // overrides (even if they are part of the same redecl chain inside the |
| 3215 | // derived class.) |
| 3216 | if (FoundByLookup) { |
| Mikael Holmen | c1c97aa | 2019-01-29 06:53:31 +0000 | [diff] [blame] | 3217 | if (isa<CXXMethodDecl>(FoundByLookup)) { |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3218 | if (D->getLexicalDeclContext() == D->getDeclContext()) { |
| Balazs Keri | e9719f9 | 2019-08-07 12:40:17 +0000 | [diff] [blame] | 3219 | if (!D->doesThisDeclarationHaveABody()) { |
| 3220 | if (FunctionTemplateDecl *DescribedD = |
| 3221 | D->getDescribedFunctionTemplate()) { |
| 3222 | // Handle a "templated" function together with its described |
| 3223 | // template. This avoids need for a similar check at import of the |
| 3224 | // described template. |
| 3225 | assert(FoundByLookup->getDescribedFunctionTemplate() && |
| 3226 | "Templated function mapped to non-templated?"); |
| 3227 | Importer.MapImported(DescribedD, |
| 3228 | FoundByLookup->getDescribedFunctionTemplate()); |
| 3229 | } |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3230 | return Importer.MapImported(D, FoundByLookup); |
| Balazs Keri | e9719f9 | 2019-08-07 12:40:17 +0000 | [diff] [blame] | 3231 | } else { |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3232 | // Let's continue and build up the redecl chain in this case. |
| 3233 | // FIXME Merge the functions into one decl. |
| 3234 | } |
| 3235 | } |
| 3236 | } |
| 3237 | } |
| 3238 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3239 | DeclarationNameInfo NameInfo(Name, Loc); |
| 3240 | // Import additional name location/type info. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3241 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 3242 | return std::move(Err); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3243 | |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3244 | QualType FromTy = D->getType(); |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3245 | // Set to true if we do not import the type of the function as is. There are |
| 3246 | // cases when the original type would result in an infinite recursion during |
| 3247 | // the import. To avoid an infinite recursion when importing, we create the |
| 3248 | // FunctionDecl with a simplified function type and update it only after the |
| 3249 | // relevant AST nodes are already imported. |
| 3250 | bool UsedDifferentProtoType = false; |
| 3251 | if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) { |
| 3252 | QualType FromReturnTy = FromFPT->getReturnType(); |
| 3253 | // Functions with auto return type may define a struct inside their body |
| 3254 | // and the return type could refer to that struct. |
| 3255 | // E.g.: auto foo() { struct X{}; return X(); } |
| 3256 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 3257 | // with a simplified return type. |
| 3258 | if (hasAutoReturnTypeDeclaredInside(D)) { |
| 3259 | FromReturnTy = Importer.getFromContext().VoidTy; |
| 3260 | UsedDifferentProtoType = true; |
| 3261 | } |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3262 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 3263 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 3264 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 3265 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3266 | // with a simplified function type. |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 3267 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 3268 | FromEPI.ExceptionSpec.SourceTemplate || |
| 3269 | FromEPI.ExceptionSpec.NoexceptExpr) { |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3270 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3271 | FromEPI = DefaultEPI; |
| 3272 | UsedDifferentProtoType = true; |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3273 | } |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3274 | FromTy = Importer.getFromContext().getFunctionType( |
| 3275 | FromReturnTy, FromFPT->getParamTypes(), FromEPI); |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3276 | } |
| 3277 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3278 | QualType T; |
| 3279 | TypeSourceInfo *TInfo; |
| 3280 | SourceLocation ToInnerLocStart, ToEndLoc; |
| 3281 | NestedNameSpecifierLoc ToQualifierLoc; |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3282 | Expr *TrailingRequiresClause; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3283 | if (auto Imp = importSeq( |
| 3284 | FromTy, D->getTypeSourceInfo(), D->getInnerLocStart(), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3285 | D->getQualifierLoc(), D->getEndLoc(), D->getTrailingRequiresClause())) |
| 3286 | std::tie(T, TInfo, ToInnerLocStart, ToQualifierLoc, ToEndLoc, |
| 3287 | TrailingRequiresClause) = *Imp; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3288 | else |
| 3289 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3290 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3291 | // Import the function parameters. |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3292 | SmallVector<ParmVarDecl *, 8> Parameters; |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3293 | for (auto P : D->parameters()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3294 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) |
| 3295 | Parameters.push_back(*ToPOrErr); |
| 3296 | else |
| 3297 | return ToPOrErr.takeError(); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3298 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3299 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3300 | // Create the imported function. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3301 | FunctionDecl *ToFunction = nullptr; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3302 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3303 | Expr *ExplicitExpr = nullptr; |
| 3304 | if (FromConstructor->getExplicitSpecifier().getExpr()) { |
| 3305 | auto Imp = importSeq(FromConstructor->getExplicitSpecifier().getExpr()); |
| 3306 | if (!Imp) |
| 3307 | return Imp.takeError(); |
| 3308 | std::tie(ExplicitExpr) = *Imp; |
| 3309 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3310 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3311 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3312 | ToInnerLocStart, NameInfo, T, TInfo, |
| 3313 | ExplicitSpecifier( |
| 3314 | ExplicitExpr, |
| 3315 | FromConstructor->getExplicitSpecifier().getKind()), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3316 | D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(), |
| 3317 | InheritedConstructor(), // FIXME: Properly import inherited |
| 3318 | // constructor info |
| 3319 | TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3320 | return ToFunction; |
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3321 | } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { |
| 3322 | |
| 3323 | auto Imp = |
| 3324 | importSeq(const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()), |
| 3325 | FromDtor->getOperatorDeleteThisArg()); |
| 3326 | |
| 3327 | if (!Imp) |
| 3328 | return Imp.takeError(); |
| 3329 | |
| 3330 | FunctionDecl *ToOperatorDelete; |
| 3331 | Expr *ToThisArg; |
| 3332 | std::tie(ToOperatorDelete, ToThisArg) = *Imp; |
| 3333 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3334 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3335 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3336 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3337 | D->isImplicit(), D->getConstexprKind(), TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3338 | return ToFunction; |
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3339 | |
| 3340 | CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction); |
| 3341 | |
| 3342 | ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3343 | } else if (CXXConversionDecl *FromConversion = |
| 3344 | dyn_cast<CXXConversionDecl>(D)) { |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3345 | Expr *ExplicitExpr = nullptr; |
| 3346 | if (FromConversion->getExplicitSpecifier().getExpr()) { |
| 3347 | auto Imp = importSeq(FromConversion->getExplicitSpecifier().getExpr()); |
| 3348 | if (!Imp) |
| 3349 | return Imp.takeError(); |
| 3350 | std::tie(ExplicitExpr) = *Imp; |
| 3351 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3352 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 3353 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3354 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3355 | ExplicitSpecifier(ExplicitExpr, |
| 3356 | FromConversion->getExplicitSpecifier().getKind()), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3357 | D->getConstexprKind(), SourceLocation(), TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3358 | return ToFunction; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3359 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3360 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 3361 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3362 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3363 | Method->isInlineSpecified(), D->getConstexprKind(), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3364 | SourceLocation(), TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3365 | return ToFunction; |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3366 | } else { |
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3367 | if (GetImportedOrCreateDecl( |
| 3368 | ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, |
| 3369 | NameInfo, T, TInfo, D->getStorageClass(), D->isInlineSpecified(), |
| Saar Raz | b65b1f3 | 2020-01-09 15:07:51 +0200 | [diff] [blame] | 3370 | D->hasWrittenPrototype(), D->getConstexprKind(), |
| 3371 | TrailingRequiresClause)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3372 | return ToFunction; |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3373 | } |
| John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3374 | |
| Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3375 | // Connect the redecl chain. |
| 3376 | if (FoundByLookup) { |
| 3377 | auto *Recent = const_cast<FunctionDecl *>( |
| 3378 | FoundByLookup->getMostRecentDecl()); |
| 3379 | ToFunction->setPreviousDecl(Recent); |
| Gabor Marton | ce6b781 | 2019-05-08 15:23:48 +0000 | [diff] [blame] | 3380 | // FIXME Probably we should merge exception specifications. E.g. In the |
| 3381 | // "To" context the existing function may have exception specification with |
| 3382 | // noexcept-unevaluated, while the newly imported function may have an |
| 3383 | // evaluated noexcept. A call to adjustExceptionSpec() on the imported |
| 3384 | // decl and its redeclarations may be required. |
| Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3385 | } |
| 3386 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3387 | ToFunction->setQualifierInfo(ToQualifierLoc); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3388 | ToFunction->setAccess(D->getAccess()); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3389 | ToFunction->setLexicalDeclContext(LexicalDC); |
| John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 3390 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 3391 | ToFunction->setTrivial(D->isTrivial()); |
| 3392 | ToFunction->setPure(D->isPure()); |
| Balazs Keri | b427c06 | 2019-08-13 08:04:06 +0000 | [diff] [blame] | 3393 | ToFunction->setDefaulted(D->isDefaulted()); |
| 3394 | ToFunction->setExplicitlyDefaulted(D->isExplicitlyDefaulted()); |
| 3395 | ToFunction->setDeletedAsWritten(D->isDeletedAsWritten()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3396 | ToFunction->setRangeEnd(ToEndLoc); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3397 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3398 | // Set the parameters. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3399 | for (auto *Param : Parameters) { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3400 | Param->setOwningFunction(ToFunction); |
| 3401 | ToFunction->addDeclInternal(Param); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3402 | } |
| David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 3403 | ToFunction->setParams(Parameters); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3404 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3405 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 3406 | // params it refers to. |
| 3407 | if (TInfo) { |
| 3408 | if (auto ProtoLoc = |
| 3409 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 3410 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 3411 | ProtoLoc.setParam(I, Parameters[I]); |
| 3412 | } |
| 3413 | } |
| 3414 | |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3415 | // Import the describing template function, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3416 | if (FromFT) { |
| 3417 | auto ToFTOrErr = import(FromFT); |
| 3418 | if (!ToFTOrErr) |
| 3419 | return ToFTOrErr.takeError(); |
| 3420 | } |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3421 | |
| Balazs Keri | e13e836 | 2019-08-16 12:10:03 +0000 | [diff] [blame] | 3422 | // Import Ctor initializers. |
| 3423 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 3424 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 3425 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); |
| 3426 | // Import first, then allocate memory and copy if there was no error. |
| 3427 | if (Error Err = ImportContainerChecked( |
| 3428 | FromConstructor->inits(), CtorInitializers)) |
| 3429 | return std::move(Err); |
| 3430 | auto **Memory = |
| 3431 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 3432 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
| 3433 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
| 3434 | ToCtor->setCtorInitializers(Memory); |
| 3435 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 3436 | } |
| 3437 | } |
| 3438 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3439 | if (D->doesThisDeclarationHaveABody()) { |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3440 | Error Err = ImportFunctionDeclBody(D, ToFunction); |
| 3441 | |
| 3442 | if (Err) |
| 3443 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3444 | } |
| 3445 | |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3446 | // Import and set the original type in case we used another type. |
| 3447 | if (UsedDifferentProtoType) { |
| 3448 | if (ExpectedType TyOrErr = import(D->getType())) |
| 3449 | ToFunction->setType(*TyOrErr); |
| 3450 | else |
| 3451 | return TyOrErr.takeError(); |
| 3452 | } |
| 3453 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3454 | // FIXME: Other bits to merge? |
| Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3455 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3456 | // If it is a template, import all related things. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3457 | if (Error Err = ImportTemplateInformation(D, ToFunction)) |
| 3458 | return std::move(Err); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3459 | |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 3460 | addDeclToContexts(D, ToFunction); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3461 | |
| Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3462 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 3463 | if (Error Err = ImportOverriddenMethods(cast<CXXMethodDecl>(ToFunction), |
| 3464 | FromCXXMethod)) |
| 3465 | return std::move(Err); |
| Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3466 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3467 | // Import the rest of the chain. I.e. import all subsequent declarations. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3468 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3469 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3470 | if (!ToRedeclOrErr) |
| 3471 | return ToRedeclOrErr.takeError(); |
| 3472 | } |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3473 | |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3474 | return ToFunction; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3475 | } |
| 3476 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3477 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3478 | return VisitFunctionDecl(D); |
| 3479 | } |
| 3480 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3481 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3482 | return VisitCXXMethodDecl(D); |
| 3483 | } |
| 3484 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3485 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3486 | return VisitCXXMethodDecl(D); |
| 3487 | } |
| 3488 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3489 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3490 | return VisitCXXMethodDecl(D); |
| 3491 | } |
| 3492 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3493 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3494 | // Import the major distinguishing characteristics of a variable. |
| 3495 | DeclContext *DC, *LexicalDC; |
| 3496 | DeclarationName Name; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3497 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3498 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3499 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3500 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3501 | if (ToD) |
| 3502 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3503 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3504 | // Determine whether we've already imported this field. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3505 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3506 | for (auto *FoundDecl : FoundDecls) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3507 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3508 | // For anonymous fields, match up by index. |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3509 | if (!Name && |
| 3510 | ASTImporter::getFieldIndex(D) != |
| 3511 | ASTImporter::getFieldIndex(FoundField)) |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3512 | continue; |
| 3513 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3514 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3515 | FoundField->getType())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3516 | Importer.MapImported(D, FoundField); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3517 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the |
| 3518 | // initializer of a FieldDecl might not had been instantiated in the |
| 3519 | // "To" context. However, the "From" context might instantiated that, |
| 3520 | // thus we have to merge that. |
| 3521 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
| 3522 | // We don't have yet the initializer set. |
| 3523 | if (FoundField->hasInClassInitializer() && |
| 3524 | !FoundField->getInClassInitializer()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3525 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) |
| 3526 | FoundField->setInClassInitializer(*ToInitializerOrErr); |
| 3527 | else { |
| 3528 | // We can't return error here, |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3529 | // since we already mapped D as imported. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3530 | // FIXME: warning message? |
| 3531 | consumeError(ToInitializerOrErr.takeError()); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3532 | return FoundField; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3533 | } |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3534 | } |
| 3535 | } |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3536 | return FoundField; |
| 3537 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3538 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3539 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3540 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3541 | << Name << D->getType() << FoundField->getType(); |
| 3542 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3543 | << FoundField->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3544 | |
| 3545 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3546 | } |
| 3547 | } |
| 3548 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3549 | QualType ToType; |
| 3550 | TypeSourceInfo *ToTInfo; |
| 3551 | Expr *ToBitWidth; |
| 3552 | SourceLocation ToInnerLocStart; |
| 3553 | Expr *ToInitializer; |
| 3554 | if (auto Imp = importSeq( |
| 3555 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), |
| 3556 | D->getInnerLocStart(), D->getInClassInitializer())) |
| 3557 | std::tie( |
| 3558 | ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp; |
| 3559 | else |
| 3560 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3561 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3562 | FieldDecl *ToField; |
| 3563 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3564 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3565 | ToType, ToTInfo, ToBitWidth, D->isMutable(), |
| 3566 | D->getInClassInitStyle())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3567 | return ToField; |
| 3568 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3569 | ToField->setAccess(D->getAccess()); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3570 | ToField->setLexicalDeclContext(LexicalDC); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3571 | if (ToInitializer) |
| 3572 | ToField->setInClassInitializer(ToInitializer); |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3573 | ToField->setImplicit(D->isImplicit()); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3574 | LexicalDC->addDeclInternal(ToField); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3575 | return ToField; |
| 3576 | } |
| 3577 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3578 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3579 | // Import the major distinguishing characteristics of a variable. |
| 3580 | DeclContext *DC, *LexicalDC; |
| 3581 | DeclarationName Name; |
| 3582 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3583 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3584 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3585 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3586 | if (ToD) |
| 3587 | return ToD; |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3588 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3589 | // Determine whether we've already imported this field. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3590 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3591 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3592 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3593 | // For anonymous indirect fields, match up by index. |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3594 | if (!Name && |
| 3595 | ASTImporter::getFieldIndex(D) != |
| 3596 | ASTImporter::getFieldIndex(FoundField)) |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3597 | continue; |
| 3598 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3599 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3600 | FoundField->getType(), |
| David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 3601 | !Name.isEmpty())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3602 | Importer.MapImported(D, FoundField); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3603 | return FoundField; |
| 3604 | } |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3605 | |
| 3606 | // If there are more anonymous fields to check, continue. |
| 3607 | if (!Name && I < N-1) |
| 3608 | continue; |
| 3609 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3610 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3611 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3612 | << Name << D->getType() << FoundField->getType(); |
| 3613 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3614 | << FoundField->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3615 | |
| 3616 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3617 | } |
| 3618 | } |
| 3619 | |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3620 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3621 | auto TypeOrErr = import(D->getType()); |
| 3622 | if (!TypeOrErr) |
| 3623 | return TypeOrErr.takeError(); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3624 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3625 | auto **NamedChain = |
| 3626 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3627 | |
| 3628 | unsigned i = 0; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3629 | for (auto *PI : D->chain()) |
| 3630 | if (Expected<NamedDecl *> ToD = import(PI)) |
| 3631 | NamedChain[i++] = *ToD; |
| 3632 | else |
| 3633 | return ToD.takeError(); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3634 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3635 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 3636 | IndirectFieldDecl *ToIndirectField; |
| 3637 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3638 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3639 | // FIXME here we leak `NamedChain` which is allocated before |
| 3640 | return ToIndirectField; |
| Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3641 | |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3642 | ToIndirectField->setAccess(D->getAccess()); |
| 3643 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3644 | LexicalDC->addDeclInternal(ToIndirectField); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3645 | return ToIndirectField; |
| 3646 | } |
| 3647 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3648 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3649 | // Import the major distinguishing characteristics of a declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3650 | DeclContext *DC, *LexicalDC; |
| 3651 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 3652 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3653 | |
| 3654 | // Determine whether we've already imported this decl. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3655 | // FriendDecl is not a NamedDecl so we cannot use lookup. |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3656 | auto *RD = cast<CXXRecordDecl>(DC); |
| 3657 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3658 | |
| 3659 | while (ImportedFriend) { |
| 3660 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3661 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 3662 | /*Complain=*/false)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3663 | return Importer.MapImported(D, ImportedFriend); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3664 | |
| 3665 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 3666 | if (Importer.IsStructurallyEquivalent( |
| 3667 | D->getFriendType()->getType(), |
| 3668 | ImportedFriend->getFriendType()->getType(), true)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3669 | return Importer.MapImported(D, ImportedFriend); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3670 | } |
| 3671 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3672 | } |
| 3673 | |
| 3674 | // Not found. Create it. |
| 3675 | FriendDecl::FriendUnion ToFU; |
| Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3676 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3677 | NamedDecl *ToFriendD; |
| 3678 | if (Error Err = importInto(ToFriendD, FriendD)) |
| 3679 | return std::move(Err); |
| 3680 | |
| 3681 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && |
| Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3682 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3683 | ToFriendD->setObjectOfFriendDecl(false); |
| 3684 | |
| 3685 | ToFU = ToFriendD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3686 | } else { // The friend is a type, not a decl. |
| 3687 | if (auto TSIOrErr = import(D->getFriendType())) |
| 3688 | ToFU = *TSIOrErr; |
| 3689 | else |
| 3690 | return TSIOrErr.takeError(); |
| 3691 | } |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3692 | |
| 3693 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3694 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3695 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 3696 | if (auto ListOrErr = import(FromTPLists[I])) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3697 | ToTPLists[I] = *ListOrErr; |
| 3698 | else |
| 3699 | return ListOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3700 | } |
| 3701 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3702 | auto LocationOrErr = import(D->getLocation()); |
| 3703 | if (!LocationOrErr) |
| 3704 | return LocationOrErr.takeError(); |
| 3705 | auto FriendLocOrErr = import(D->getFriendLoc()); |
| 3706 | if (!FriendLocOrErr) |
| 3707 | return FriendLocOrErr.takeError(); |
| 3708 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3709 | FriendDecl *FrD; |
| 3710 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3711 | *LocationOrErr, ToFU, |
| 3712 | *FriendLocOrErr, ToTPLists)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3713 | return FrD; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3714 | |
| 3715 | FrD->setAccess(D->getAccess()); |
| 3716 | FrD->setLexicalDeclContext(LexicalDC); |
| 3717 | LexicalDC->addDeclInternal(FrD); |
| 3718 | return FrD; |
| 3719 | } |
| 3720 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3721 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3722 | // Import the major distinguishing characteristics of an ivar. |
| 3723 | DeclContext *DC, *LexicalDC; |
| 3724 | DeclarationName Name; |
| 3725 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3726 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3727 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3728 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3729 | if (ToD) |
| 3730 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3731 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3732 | // Determine whether we've already imported this ivar |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3733 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3734 | for (auto *FoundDecl : FoundDecls) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3735 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3736 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3737 | FoundIvar->getType())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3738 | Importer.MapImported(D, FoundIvar); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3739 | return FoundIvar; |
| 3740 | } |
| 3741 | |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3742 | Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent) |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3743 | << Name << D->getType() << FoundIvar->getType(); |
| 3744 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3745 | << FoundIvar->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3746 | |
| 3747 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3748 | } |
| 3749 | } |
| 3750 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3751 | QualType ToType; |
| 3752 | TypeSourceInfo *ToTypeSourceInfo; |
| 3753 | Expr *ToBitWidth; |
| 3754 | SourceLocation ToInnerLocStart; |
| 3755 | if (auto Imp = importSeq( |
| 3756 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), D->getInnerLocStart())) |
| 3757 | std::tie(ToType, ToTypeSourceInfo, ToBitWidth, ToInnerLocStart) = *Imp; |
| 3758 | else |
| 3759 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3760 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3761 | ObjCIvarDecl *ToIvar; |
| 3762 | if (GetImportedOrCreateDecl( |
| 3763 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3764 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3765 | ToType, ToTypeSourceInfo, |
| 3766 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3767 | return ToIvar; |
| 3768 | |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3769 | ToIvar->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3770 | LexicalDC->addDeclInternal(ToIvar); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3771 | return ToIvar; |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3772 | } |
| 3773 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3774 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3775 | |
| 3776 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 3777 | auto RedeclIt = Redecls.begin(); |
| 3778 | // Import the first part of the decl chain. I.e. import all previous |
| 3779 | // declarations starting from the canonical decl. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3780 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3781 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3782 | if (!RedeclOrErr) |
| 3783 | return RedeclOrErr.takeError(); |
| 3784 | } |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3785 | assert(*RedeclIt == D); |
| 3786 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3787 | // Import the major distinguishing characteristics of a variable. |
| 3788 | DeclContext *DC, *LexicalDC; |
| 3789 | DeclarationName Name; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3790 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3791 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3792 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3793 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3794 | if (ToD) |
| 3795 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3796 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3797 | // Try to find a variable in our own ("to") context with the same name and |
| 3798 | // in the same context as the variable we're importing. |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3799 | VarDecl *FoundByLookup = nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3800 | if (D->isFileVarDecl()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3801 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3802 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3803 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3804 | for (auto *FoundDecl : FoundDecls) { |
| 3805 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3806 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3807 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3808 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3809 | if (!hasSameVisibilityContext(FoundVar, D)) |
| 3810 | continue; |
| 3811 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| 3812 | FoundVar->getType())) { |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3813 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3814 | // The VarDecl in the "From" context has a definition, but in the |
| 3815 | // "To" context we already have a definition. |
| 3816 | VarDecl *FoundDef = FoundVar->getDefinition(); |
| 3817 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 3818 | // FIXME Check for ODR error if the two definitions have |
| 3819 | // different initializers? |
| 3820 | return Importer.MapImported(D, FoundDef); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3821 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3822 | // The VarDecl in the "From" context has an initializer, but in the |
| 3823 | // "To" context we already have an initializer. |
| 3824 | const VarDecl *FoundDInit = nullptr; |
| 3825 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) |
| 3826 | // FIXME Diagnose ODR error if the two initializers are different? |
| 3827 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); |
| 3828 | |
| 3829 | FoundByLookup = FoundVar; |
| 3830 | break; |
| 3831 | } |
| 3832 | |
| 3833 | const ArrayType *FoundArray |
| 3834 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3835 | const ArrayType *TArray |
| 3836 | = Importer.getToContext().getAsArrayType(D->getType()); |
| 3837 | if (FoundArray && TArray) { |
| 3838 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3839 | isa<ConstantArrayType>(TArray)) { |
| 3840 | // Import the type. |
| 3841 | if (auto TyOrErr = import(D->getType())) |
| 3842 | FoundVar->setType(*TyOrErr); |
| 3843 | else |
| 3844 | return TyOrErr.takeError(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3845 | |
| 3846 | FoundByLookup = FoundVar; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3847 | break; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3848 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3849 | isa<ConstantArrayType>(FoundArray)) { |
| 3850 | FoundByLookup = FoundVar; |
| 3851 | break; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3852 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3853 | } |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3854 | |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3855 | Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3856 | << Name << D->getType() << FoundVar->getType(); |
| 3857 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3858 | << FoundVar->getType(); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3859 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3860 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3861 | } |
| 3862 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3863 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3864 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 3865 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 3866 | if (NameOrErr) |
| 3867 | Name = NameOrErr.get(); |
| 3868 | else |
| 3869 | return NameOrErr.takeError(); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3870 | } |
| 3871 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3872 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3873 | QualType ToType; |
| 3874 | TypeSourceInfo *ToTypeSourceInfo; |
| 3875 | SourceLocation ToInnerLocStart; |
| 3876 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3877 | if (auto Imp = importSeq( |
| 3878 | D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3879 | D->getQualifierLoc())) |
| 3880 | std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp; |
| 3881 | else |
| 3882 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3883 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3884 | // Create the imported variable. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3885 | VarDecl *ToVar; |
| 3886 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3887 | ToInnerLocStart, Loc, |
| 3888 | Name.getAsIdentifierInfo(), |
| 3889 | ToType, ToTypeSourceInfo, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3890 | D->getStorageClass())) |
| 3891 | return ToVar; |
| 3892 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3893 | ToVar->setQualifierInfo(ToQualifierLoc); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3894 | ToVar->setAccess(D->getAccess()); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3895 | ToVar->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3896 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3897 | if (FoundByLookup) { |
| 3898 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); |
| 3899 | ToVar->setPreviousDecl(Recent); |
| 3900 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3901 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3902 | if (Error Err = ImportInitializer(D, ToVar)) |
| 3903 | return std::move(Err); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3904 | |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3905 | if (D->isConstexpr()) |
| 3906 | ToVar->setConstexpr(true); |
| 3907 | |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 3908 | addDeclToContexts(D, ToVar); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3909 | |
| 3910 | // Import the rest of the chain. I.e. import all subsequent declarations. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3911 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3912 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3913 | if (!RedeclOrErr) |
| 3914 | return RedeclOrErr.takeError(); |
| 3915 | } |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3916 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3917 | return ToVar; |
| 3918 | } |
| 3919 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3920 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3921 | // Parameters are created in the translation unit's context, then moved |
| 3922 | // into the function declaration's context afterward. |
| 3923 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3924 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3925 | DeclarationName ToDeclName; |
| 3926 | SourceLocation ToLocation; |
| 3927 | QualType ToType; |
| 3928 | if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType())) |
| 3929 | std::tie(ToDeclName, ToLocation, ToType) = *Imp; |
| 3930 | else |
| 3931 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3932 | |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3933 | // Create the imported parameter. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3934 | ImplicitParamDecl *ToParm = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3935 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3936 | ToLocation, ToDeclName.getAsIdentifierInfo(), |
| 3937 | ToType, D->getParameterKind())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3938 | return ToParm; |
| 3939 | return ToParm; |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3940 | } |
| 3941 | |
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 3942 | Error ASTNodeImporter::ImportDefaultArgOfParmVarDecl( |
| 3943 | const ParmVarDecl *FromParam, ParmVarDecl *ToParam) { |
| 3944 | ToParam->setHasInheritedDefaultArg(FromParam->hasInheritedDefaultArg()); |
| 3945 | ToParam->setKNRPromoted(FromParam->isKNRPromoted()); |
| 3946 | |
| 3947 | if (FromParam->hasUninstantiatedDefaultArg()) { |
| 3948 | if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg())) |
| 3949 | ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr); |
| 3950 | else |
| 3951 | return ToDefArgOrErr.takeError(); |
| 3952 | } else if (FromParam->hasUnparsedDefaultArg()) { |
| 3953 | ToParam->setUnparsedDefaultArg(); |
| 3954 | } else if (FromParam->hasDefaultArg()) { |
| 3955 | if (auto ToDefArgOrErr = import(FromParam->getDefaultArg())) |
| 3956 | ToParam->setDefaultArg(*ToDefArgOrErr); |
| 3957 | else |
| 3958 | return ToDefArgOrErr.takeError(); |
| 3959 | } |
| 3960 | |
| 3961 | return Error::success(); |
| 3962 | } |
| 3963 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3964 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3965 | // Parameters are created in the translation unit's context, then moved |
| 3966 | // into the function declaration's context afterward. |
| 3967 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3968 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3969 | DeclarationName ToDeclName; |
| 3970 | SourceLocation ToLocation, ToInnerLocStart; |
| 3971 | QualType ToType; |
| 3972 | TypeSourceInfo *ToTypeSourceInfo; |
| 3973 | if (auto Imp = importSeq( |
| 3974 | D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(), |
| 3975 | D->getTypeSourceInfo())) |
| 3976 | std::tie( |
| 3977 | ToDeclName, ToLocation, ToType, ToInnerLocStart, |
| 3978 | ToTypeSourceInfo) = *Imp; |
| 3979 | else |
| 3980 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3981 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3982 | ParmVarDecl *ToParm; |
| 3983 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3984 | ToInnerLocStart, ToLocation, |
| 3985 | ToDeclName.getAsIdentifierInfo(), ToType, |
| 3986 | ToTypeSourceInfo, D->getStorageClass(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3987 | /*DefaultArg*/ nullptr)) |
| 3988 | return ToParm; |
| Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3989 | |
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 3990 | // Set the default argument. It should be no problem if it was already done. |
| 3991 | // Do not import the default expression before GetImportedOrCreateDecl call |
| 3992 | // to avoid possible infinite import loop because circular dependency. |
| 3993 | if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm)) |
| 3994 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3995 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3996 | if (D->isObjCMethodParameter()) { |
| 3997 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3998 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3999 | } else { |
| 4000 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 4001 | D->getFunctionScopeIndex()); |
| 4002 | } |
| 4003 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4004 | return ToParm; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 4005 | } |
| 4006 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4007 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4008 | // Import the major distinguishing characteristics of a method. |
| 4009 | DeclContext *DC, *LexicalDC; |
| 4010 | DeclarationName Name; |
| 4011 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4012 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4013 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4014 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4015 | if (ToD) |
| 4016 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4017 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4018 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4019 | for (auto *FoundDecl : FoundDecls) { |
| 4020 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4021 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 4022 | continue; |
| 4023 | |
| 4024 | // Check return types. |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4025 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 4026 | FoundMethod->getReturnType())) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4027 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent) |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 4028 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 4029 | << FoundMethod->getReturnType(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4030 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4031 | diag::note_odr_objc_method_here) |
| 4032 | << D->isInstanceMethod() << Name; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4033 | |
| 4034 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4035 | } |
| 4036 | |
| 4037 | // Check the number of parameters. |
| 4038 | if (D->param_size() != FoundMethod->param_size()) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4039 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4040 | << D->isInstanceMethod() << Name |
| 4041 | << D->param_size() << FoundMethod->param_size(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4042 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4043 | diag::note_odr_objc_method_here) |
| 4044 | << D->isInstanceMethod() << Name; |
| 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 | // Check parameter types. |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4050 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4051 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 4052 | P != PEnd; ++P, ++FoundP) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4053 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4054 | (*FoundP)->getType())) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4055 | Importer.FromDiag((*P)->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4056 | diag::warn_odr_objc_method_param_type_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4057 | << D->isInstanceMethod() << Name |
| 4058 | << (*P)->getType() << (*FoundP)->getType(); |
| 4059 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 4060 | << (*FoundP)->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4061 | |
| 4062 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4063 | } |
| 4064 | } |
| 4065 | |
| 4066 | // Check variadic/non-variadic. |
| 4067 | // Check the number of parameters. |
| 4068 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4069 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4070 | << D->isInstanceMethod() << Name; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4071 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4072 | diag::note_odr_objc_method_here) |
| 4073 | << D->isInstanceMethod() << Name; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4074 | |
| 4075 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4076 | } |
| 4077 | |
| 4078 | // FIXME: Any other bits we need to merge? |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4079 | return Importer.MapImported(D, FoundMethod); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4080 | } |
| 4081 | } |
| 4082 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4083 | SourceLocation ToEndLoc; |
| 4084 | QualType ToReturnType; |
| 4085 | TypeSourceInfo *ToReturnTypeSourceInfo; |
| 4086 | if (auto Imp = importSeq( |
| 4087 | D->getEndLoc(), D->getReturnType(), D->getReturnTypeSourceInfo())) |
| 4088 | std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp; |
| 4089 | else |
| 4090 | return Imp.takeError(); |
| Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 4091 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4092 | ObjCMethodDecl *ToMethod; |
| 4093 | if (GetImportedOrCreateDecl( |
| Adrian Prantl | 2073dd2 | 2019-11-04 14:28:14 -0800 | [diff] [blame] | 4094 | ToMethod, D, Importer.getToContext(), Loc, ToEndLoc, |
| 4095 | Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC, |
| 4096 | D->isInstanceMethod(), D->isVariadic(), D->isPropertyAccessor(), |
| 4097 | D->isSynthesizedAccessorStub(), D->isImplicit(), D->isDefined(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4098 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 4099 | return ToMethod; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4100 | |
| 4101 | // FIXME: When we decide to merge method definitions, we'll need to |
| 4102 | // deal with implicit parameters. |
| 4103 | |
| 4104 | // Import the parameters |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4105 | SmallVector<ParmVarDecl *, 5> ToParams; |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 4106 | for (auto *FromP : D->parameters()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4107 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) |
| 4108 | ToParams.push_back(*ToPOrErr); |
| 4109 | else |
| 4110 | return ToPOrErr.takeError(); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4111 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4112 | |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4113 | // Set the parameters. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4114 | for (auto *ToParam : ToParams) { |
| 4115 | ToParam->setOwningFunction(ToMethod); |
| 4116 | ToMethod->addDeclInternal(ToParam); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4117 | } |
| Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 4118 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4119 | SmallVector<SourceLocation, 12> FromSelLocs; |
| 4120 | D->getSelectorLocs(FromSelLocs); |
| 4121 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); |
| 4122 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) |
| 4123 | return std::move(Err); |
| Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 4124 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4125 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4126 | |
| 4127 | ToMethod->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4128 | LexicalDC->addDeclInternal(ToMethod); |
| Raphael Isemann | 164e0fc | 2019-12-06 18:10:23 +0100 | [diff] [blame] | 4129 | |
| 4130 | // Implicit params are declared when Sema encounters the definition but this |
| 4131 | // never happens when the method is imported. Manually declare the implicit |
| 4132 | // params now that the MethodDecl knows its class interface. |
| 4133 | if (D->getSelfDecl()) |
| 4134 | ToMethod->createImplicitParams(Importer.getToContext(), |
| 4135 | ToMethod->getClassInterface()); |
| 4136 | |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4137 | return ToMethod; |
| 4138 | } |
| 4139 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4140 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4141 | // Import the major distinguishing characteristics of a category. |
| 4142 | DeclContext *DC, *LexicalDC; |
| 4143 | DeclarationName Name; |
| 4144 | SourceLocation Loc; |
| 4145 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4146 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4147 | return std::move(Err); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4148 | if (ToD) |
| 4149 | return ToD; |
| 4150 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4151 | SourceLocation ToVarianceLoc, ToLocation, ToColonLoc; |
| 4152 | TypeSourceInfo *ToTypeSourceInfo; |
| 4153 | if (auto Imp = importSeq( |
| 4154 | D->getVarianceLoc(), D->getLocation(), D->getColonLoc(), |
| 4155 | D->getTypeSourceInfo())) |
| 4156 | std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp; |
| 4157 | else |
| 4158 | return Imp.takeError(); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4159 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4160 | ObjCTypeParamDecl *Result; |
| 4161 | if (GetImportedOrCreateDecl( |
| 4162 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4163 | ToVarianceLoc, D->getIndex(), |
| 4164 | ToLocation, Name.getAsIdentifierInfo(), |
| 4165 | ToColonLoc, ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4166 | return Result; |
| 4167 | |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4168 | Result->setLexicalDeclContext(LexicalDC); |
| 4169 | return Result; |
| 4170 | } |
| 4171 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4172 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4173 | // Import the major distinguishing characteristics of a category. |
| 4174 | DeclContext *DC, *LexicalDC; |
| 4175 | DeclarationName Name; |
| 4176 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4177 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4178 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4179 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4180 | if (ToD) |
| 4181 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4182 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4183 | ObjCInterfaceDecl *ToInterface; |
| 4184 | if (Error Err = importInto(ToInterface, D->getClassInterface())) |
| 4185 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4186 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4187 | // Determine if we've already encountered this category. |
| 4188 | ObjCCategoryDecl *MergeWithCategory |
| 4189 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 4190 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 4191 | if (!ToCategory) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4192 | SourceLocation ToAtStartLoc, ToCategoryNameLoc; |
| 4193 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 4194 | if (auto Imp = importSeq( |
| 4195 | D->getAtStartLoc(), D->getCategoryNameLoc(), |
| 4196 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 4197 | std::tie( |
| 4198 | ToAtStartLoc, ToCategoryNameLoc, |
| 4199 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 4200 | else |
| 4201 | return Imp.takeError(); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4202 | |
| 4203 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4204 | ToAtStartLoc, Loc, |
| 4205 | ToCategoryNameLoc, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4206 | Name.getAsIdentifierInfo(), ToInterface, |
| 4207 | /*TypeParamList=*/nullptr, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4208 | ToIvarLBraceLoc, |
| 4209 | ToIvarRBraceLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4210 | return ToCategory; |
| 4211 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4212 | ToCategory->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4213 | LexicalDC->addDeclInternal(ToCategory); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4214 | // Import the type parameter list after MapImported, to avoid |
| Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4215 | // loops when bringing in their DeclContext. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4216 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) |
| 4217 | ToCategory->setTypeParamList(*PListOrErr); |
| 4218 | else |
| 4219 | return PListOrErr.takeError(); |
| 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 | // Import protocols |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4222 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4223 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4224 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 4225 | = D->protocol_loc_begin(); |
| 4226 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 4227 | FromProtoEnd = D->protocol_end(); |
| 4228 | FromProto != FromProtoEnd; |
| 4229 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4230 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4231 | Protocols.push_back(*ToProtoOrErr); |
| 4232 | else |
| 4233 | return ToProtoOrErr.takeError(); |
| 4234 | |
| 4235 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4236 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4237 | else |
| 4238 | return ToProtoLocOrErr.takeError(); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4239 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4240 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4241 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4242 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 4243 | ProtocolLocs.data(), Importer.getToContext()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4244 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4245 | } else { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4246 | Importer.MapImported(D, ToCategory); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4247 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4248 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4249 | // Import all of the members of this category. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4250 | if (Error Err = ImportDeclContext(D)) |
| 4251 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4252 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4253 | // If we have an implementation, import it as well. |
| 4254 | if (D->getImplementation()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4255 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = |
| 4256 | import(D->getImplementation())) |
| 4257 | ToCategory->setImplementation(*ToImplOrErr); |
| 4258 | else |
| 4259 | return ToImplOrErr.takeError(); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4260 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4261 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4262 | return ToCategory; |
| 4263 | } |
| 4264 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4265 | Error ASTNodeImporter::ImportDefinition( |
| 4266 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4267 | if (To->getDefinition()) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4268 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4269 | if (Error Err = ImportDeclContext(From)) |
| 4270 | return Err; |
| 4271 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4272 | } |
| 4273 | |
| 4274 | // Start the protocol definition |
| 4275 | To->startDefinition(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4276 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4277 | // Import protocols |
| 4278 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4279 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4280 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = |
| 4281 | From->protocol_loc_begin(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4282 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4283 | FromProtoEnd = From->protocol_end(); |
| 4284 | FromProto != FromProtoEnd; |
| 4285 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4286 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4287 | Protocols.push_back(*ToProtoOrErr); |
| 4288 | else |
| 4289 | return ToProtoOrErr.takeError(); |
| 4290 | |
| 4291 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4292 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4293 | else |
| 4294 | return ToProtoLocOrErr.takeError(); |
| 4295 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4296 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4297 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4298 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4299 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4300 | ProtocolLocs.data(), Importer.getToContext()); |
| 4301 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4302 | if (shouldForceImportDeclContext(Kind)) { |
| 4303 | // Import all of the members of this protocol. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4304 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4305 | return Err; |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4306 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4307 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4308 | } |
| 4309 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4310 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4311 | // 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] | 4312 | // from, but this particular declaration is not that definition, import the |
| 4313 | // definition and map to that. |
| 4314 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 4315 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4316 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4317 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4318 | else |
| 4319 | return ImportedDefOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4320 | } |
| 4321 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4322 | // Import the major distinguishing characteristics of a protocol. |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4323 | DeclContext *DC, *LexicalDC; |
| 4324 | DeclarationName Name; |
| 4325 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4326 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4327 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4328 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4329 | if (ToD) |
| 4330 | return ToD; |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4331 | |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4332 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4333 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4334 | for (auto *FoundDecl : FoundDecls) { |
| 4335 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4336 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4337 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4338 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4339 | break; |
| 4340 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4341 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4342 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4343 | if (!ToProto) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4344 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4345 | if (!ToAtBeginLocOrErr) |
| 4346 | return ToAtBeginLocOrErr.takeError(); |
| 4347 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4348 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 4349 | Name.getAsIdentifierInfo(), Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4350 | *ToAtBeginLocOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4351 | /*PrevDecl=*/nullptr)) |
| 4352 | return ToProto; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4353 | ToProto->setLexicalDeclContext(LexicalDC); |
| 4354 | LexicalDC->addDeclInternal(ToProto); |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4355 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4356 | |
| 4357 | Importer.MapImported(D, ToProto); |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4358 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4359 | if (D->isThisDeclarationADefinition()) |
| 4360 | if (Error Err = ImportDefinition(D, ToProto)) |
| 4361 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4362 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4363 | return ToProto; |
| 4364 | } |
| 4365 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4366 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 4367 | DeclContext *DC, *LexicalDC; |
| 4368 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4369 | return std::move(Err); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4370 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4371 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); |
| 4372 | if (!ExternLocOrErr) |
| 4373 | return ExternLocOrErr.takeError(); |
| 4374 | |
| 4375 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); |
| 4376 | if (!LangLocOrErr) |
| 4377 | return LangLocOrErr.takeError(); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4378 | |
| 4379 | bool HasBraces = D->hasBraces(); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4380 | |
| 4381 | LinkageSpecDecl *ToLinkageSpec; |
| 4382 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4383 | *ExternLocOrErr, *LangLocOrErr, |
| 4384 | D->getLanguage(), HasBraces)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4385 | return ToLinkageSpec; |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4386 | |
| 4387 | if (HasBraces) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4388 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 4389 | if (!RBraceLocOrErr) |
| 4390 | return RBraceLocOrErr.takeError(); |
| 4391 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4392 | } |
| 4393 | |
| 4394 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 4395 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 4396 | |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4397 | return ToLinkageSpec; |
| 4398 | } |
| 4399 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4400 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4401 | DeclContext *DC, *LexicalDC; |
| 4402 | DeclarationName Name; |
| 4403 | SourceLocation Loc; |
| 4404 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4405 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4406 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4407 | if (ToD) |
| 4408 | return ToD; |
| 4409 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4410 | SourceLocation ToLoc, ToUsingLoc; |
| 4411 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4412 | if (auto Imp = importSeq( |
| 4413 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc())) |
| 4414 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp; |
| 4415 | else |
| 4416 | return Imp.takeError(); |
| 4417 | |
| 4418 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4419 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4420 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4421 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4422 | UsingDecl *ToUsing; |
| 4423 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4424 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4425 | D->hasTypename())) |
| 4426 | return ToUsing; |
| 4427 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4428 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4429 | LexicalDC->addDeclInternal(ToUsing); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4430 | |
| 4431 | if (NamedDecl *FromPattern = |
| 4432 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4433 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) |
| 4434 | Importer.getToContext().setInstantiatedFromUsingDecl( |
| 4435 | ToUsing, *ToPatternOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4436 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4437 | return ToPatternOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4438 | } |
| 4439 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4440 | for (UsingShadowDecl *FromShadow : D->shadows()) { |
| 4441 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) |
| 4442 | ToUsing->addShadowDecl(*ToShadowOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4443 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4444 | // FIXME: We return error here but the definition is already created |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4445 | // and available with lookups. How to fix this?.. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4446 | return ToShadowOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4447 | } |
| 4448 | return ToUsing; |
| 4449 | } |
| 4450 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4451 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4452 | DeclContext *DC, *LexicalDC; |
| 4453 | DeclarationName Name; |
| 4454 | SourceLocation Loc; |
| 4455 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4456 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4457 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4458 | if (ToD) |
| 4459 | return ToD; |
| 4460 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4461 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); |
| 4462 | if (!ToUsingOrErr) |
| 4463 | return ToUsingOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4464 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4465 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); |
| 4466 | if (!ToTargetOrErr) |
| 4467 | return ToTargetOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4468 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4469 | UsingShadowDecl *ToShadow; |
| 4470 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4471 | *ToUsingOrErr, *ToTargetOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4472 | return ToShadow; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4473 | |
| 4474 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 4475 | ToShadow->setAccess(D->getAccess()); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4476 | |
| 4477 | if (UsingShadowDecl *FromPattern = |
| 4478 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4479 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) |
| 4480 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( |
| 4481 | ToShadow, *ToPatternOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4482 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4483 | // FIXME: We return error here but the definition is already created |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4484 | // and available with lookups. How to fix this?.. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4485 | return ToPatternOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4486 | } |
| 4487 | |
| 4488 | LexicalDC->addDeclInternal(ToShadow); |
| 4489 | |
| 4490 | return ToShadow; |
| 4491 | } |
| 4492 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4493 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4494 | DeclContext *DC, *LexicalDC; |
| 4495 | DeclarationName Name; |
| 4496 | SourceLocation Loc; |
| 4497 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4498 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4499 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4500 | if (ToD) |
| 4501 | return ToD; |
| 4502 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4503 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); |
| 4504 | if (!ToComAncestorOrErr) |
| 4505 | return ToComAncestorOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4506 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4507 | NamespaceDecl *ToNominatedNamespace; |
| 4508 | SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation; |
| 4509 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4510 | if (auto Imp = importSeq( |
| 4511 | D->getNominatedNamespace(), D->getUsingLoc(), |
| 4512 | D->getNamespaceKeyLocation(), D->getQualifierLoc(), |
| 4513 | D->getIdentLocation())) |
| 4514 | std::tie( |
| 4515 | ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation, |
| 4516 | ToQualifierLoc, ToIdentLocation) = *Imp; |
| 4517 | else |
| 4518 | return Imp.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4519 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4520 | UsingDirectiveDecl *ToUsingDir; |
| 4521 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4522 | ToUsingLoc, |
| 4523 | ToNamespaceKeyLocation, |
| 4524 | ToQualifierLoc, |
| 4525 | ToIdentLocation, |
| 4526 | ToNominatedNamespace, *ToComAncestorOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4527 | return ToUsingDir; |
| 4528 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4529 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 4530 | LexicalDC->addDeclInternal(ToUsingDir); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4531 | |
| 4532 | return ToUsingDir; |
| 4533 | } |
| 4534 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4535 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4536 | UnresolvedUsingValueDecl *D) { |
| 4537 | DeclContext *DC, *LexicalDC; |
| 4538 | DeclarationName Name; |
| 4539 | SourceLocation Loc; |
| 4540 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4541 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4542 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4543 | if (ToD) |
| 4544 | return ToD; |
| 4545 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4546 | SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc; |
| 4547 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4548 | if (auto Imp = importSeq( |
| 4549 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(), |
| 4550 | D->getEllipsisLoc())) |
| 4551 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4552 | else |
| 4553 | return Imp.takeError(); |
| 4554 | |
| 4555 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4556 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4557 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4558 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4559 | UnresolvedUsingValueDecl *ToUsingValue; |
| 4560 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4561 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| 4562 | ToEllipsisLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4563 | return ToUsingValue; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4564 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4565 | ToUsingValue->setAccess(D->getAccess()); |
| 4566 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 4567 | LexicalDC->addDeclInternal(ToUsingValue); |
| 4568 | |
| 4569 | return ToUsingValue; |
| 4570 | } |
| 4571 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4572 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4573 | UnresolvedUsingTypenameDecl *D) { |
| 4574 | DeclContext *DC, *LexicalDC; |
| 4575 | DeclarationName Name; |
| 4576 | SourceLocation Loc; |
| 4577 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4578 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4579 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4580 | if (ToD) |
| 4581 | return ToD; |
| 4582 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4583 | SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc; |
| 4584 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4585 | if (auto Imp = importSeq( |
| 4586 | D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(), |
| 4587 | D->getEllipsisLoc())) |
| 4588 | std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4589 | else |
| 4590 | return Imp.takeError(); |
| 4591 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4592 | UnresolvedUsingTypenameDecl *ToUsing; |
| 4593 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4594 | ToUsingLoc, ToTypenameLoc, |
| 4595 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4596 | return ToUsing; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4597 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4598 | ToUsing->setAccess(D->getAccess()); |
| 4599 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4600 | LexicalDC->addDeclInternal(ToUsing); |
| 4601 | |
| 4602 | return ToUsing; |
| 4603 | } |
| 4604 | |
| Raphael Isemann | ba7bde6 | 2019-10-30 14:50:35 +0100 | [diff] [blame] | 4605 | ExpectedDecl ASTNodeImporter::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) { |
| 4606 | Decl* ToD = nullptr; |
| 4607 | switch (D->getBuiltinTemplateKind()) { |
| 4608 | case BuiltinTemplateKind::BTK__make_integer_seq: |
| 4609 | ToD = Importer.getToContext().getMakeIntegerSeqDecl(); |
| 4610 | break; |
| 4611 | case BuiltinTemplateKind::BTK__type_pack_element: |
| 4612 | ToD = Importer.getToContext().getTypePackElementDecl(); |
| 4613 | break; |
| 4614 | } |
| 4615 | assert(ToD && "BuiltinTemplateDecl of unsupported kind!"); |
| 4616 | Importer.MapImported(D, ToD); |
| 4617 | return ToD; |
| 4618 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4619 | |
| 4620 | Error ASTNodeImporter::ImportDefinition( |
| 4621 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4622 | if (To->getDefinition()) { |
| 4623 | // Check consistency of superclass. |
| 4624 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 4625 | if (FromSuper) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4626 | if (auto FromSuperOrErr = import(FromSuper)) |
| 4627 | FromSuper = *FromSuperOrErr; |
| 4628 | else |
| 4629 | return FromSuperOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4630 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4631 | |
| 4632 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4633 | if ((bool)FromSuper != (bool)ToSuper || |
| 4634 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4635 | Importer.ToDiag(To->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4636 | diag::warn_odr_objc_superclass_inconsistent) |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4637 | << To->getDeclName(); |
| 4638 | if (ToSuper) |
| 4639 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 4640 | << To->getSuperClass()->getDeclName(); |
| 4641 | else |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4642 | Importer.ToDiag(To->getLocation(), |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4643 | diag::note_odr_objc_missing_superclass); |
| 4644 | if (From->getSuperClass()) |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4645 | Importer.FromDiag(From->getSuperClassLoc(), |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4646 | diag::note_odr_objc_superclass) |
| 4647 | << From->getSuperClass()->getDeclName(); |
| 4648 | else |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4649 | Importer.FromDiag(From->getLocation(), |
| 4650 | diag::note_odr_objc_missing_superclass); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4651 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4652 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4653 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4654 | if (Error Err = ImportDeclContext(From)) |
| 4655 | return Err; |
| 4656 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4657 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4658 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4659 | // Start the definition. |
| 4660 | To->startDefinition(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4661 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4662 | // If this class has a superclass, import it. |
| 4663 | if (From->getSuperClass()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4664 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) |
| 4665 | To->setSuperClass(*SuperTInfoOrErr); |
| 4666 | else |
| 4667 | return SuperTInfoOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4668 | } |
| 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 protocols |
| 4671 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4672 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4673 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = |
| 4674 | From->protocol_loc_begin(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4675 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4676 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4677 | FromProtoEnd = From->protocol_end(); |
| 4678 | FromProto != FromProtoEnd; |
| 4679 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4680 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4681 | Protocols.push_back(*ToProtoOrErr); |
| 4682 | else |
| 4683 | return ToProtoOrErr.takeError(); |
| 4684 | |
| 4685 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4686 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4687 | else |
| 4688 | return ToProtoLocOrErr.takeError(); |
| 4689 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4690 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4691 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4692 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4693 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4694 | ProtocolLocs.data(), Importer.getToContext()); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4695 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4696 | // Import categories. When the categories themselves are imported, they'll |
| 4697 | // hook themselves into this interface. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4698 | for (auto *Cat : From->known_categories()) { |
| 4699 | auto ToCatOrErr = import(Cat); |
| 4700 | if (!ToCatOrErr) |
| 4701 | return ToCatOrErr.takeError(); |
| 4702 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4703 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4704 | // If we have an @implementation, import it as well. |
| 4705 | if (From->getImplementation()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4706 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = |
| 4707 | import(From->getImplementation())) |
| 4708 | To->setImplementation(*ToImplOrErr); |
| 4709 | else |
| 4710 | return ToImplOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4711 | } |
| 4712 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4713 | if (shouldForceImportDeclContext(Kind)) { |
| 4714 | // Import all of the members of this class. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4715 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4716 | return Err; |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4717 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4718 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4719 | } |
| 4720 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4721 | Expected<ObjCTypeParamList *> |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4722 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 4723 | if (!list) |
| 4724 | return nullptr; |
| 4725 | |
| 4726 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4727 | for (auto *fromTypeParam : *list) { |
| 4728 | if (auto toTypeParamOrErr = import(fromTypeParam)) |
| 4729 | toTypeParams.push_back(*toTypeParamOrErr); |
| 4730 | else |
| 4731 | return toTypeParamOrErr.takeError(); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4732 | } |
| 4733 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4734 | auto LAngleLocOrErr = import(list->getLAngleLoc()); |
| 4735 | if (!LAngleLocOrErr) |
| 4736 | return LAngleLocOrErr.takeError(); |
| 4737 | |
| 4738 | auto RAngleLocOrErr = import(list->getRAngleLoc()); |
| 4739 | if (!RAngleLocOrErr) |
| 4740 | return RAngleLocOrErr.takeError(); |
| 4741 | |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4742 | return ObjCTypeParamList::create(Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4743 | *LAngleLocOrErr, |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4744 | toTypeParams, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4745 | *RAngleLocOrErr); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4746 | } |
| 4747 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4748 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4749 | // If this class has a definition in the translation unit we're coming from, |
| 4750 | // but this particular declaration is not that definition, import the |
| 4751 | // definition and map to that. |
| 4752 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 4753 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4754 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4755 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4756 | else |
| 4757 | return ImportedDefOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4758 | } |
| 4759 | |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4760 | // Import the major distinguishing characteristics of an @interface. |
| 4761 | DeclContext *DC, *LexicalDC; |
| 4762 | DeclarationName Name; |
| 4763 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4764 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4765 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4766 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4767 | if (ToD) |
| 4768 | return ToD; |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4769 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4770 | // Look for an existing interface with the same name. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4771 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4772 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4773 | for (auto *FoundDecl : FoundDecls) { |
| 4774 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4775 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4776 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4777 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4778 | break; |
| 4779 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4780 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4781 | // Create an interface declaration, if one does not already exist. |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4782 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4783 | if (!ToIface) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4784 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4785 | if (!AtBeginLocOrErr) |
| 4786 | return AtBeginLocOrErr.takeError(); |
| 4787 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4788 | if (GetImportedOrCreateDecl( |
| 4789 | ToIface, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4790 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4791 | /*TypeParamList=*/nullptr, |
| 4792 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 4793 | return ToIface; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4794 | ToIface->setLexicalDeclContext(LexicalDC); |
| 4795 | LexicalDC->addDeclInternal(ToIface); |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4796 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4797 | Importer.MapImported(D, ToIface); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4798 | // Import the type parameter list after MapImported, to avoid |
| Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4799 | // loops when bringing in their DeclContext. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4800 | if (auto ToPListOrErr = |
| 4801 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) |
| 4802 | ToIface->setTypeParamList(*ToPListOrErr); |
| 4803 | else |
| 4804 | return ToPListOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4805 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4806 | if (D->isThisDeclarationADefinition()) |
| 4807 | if (Error Err = ImportDefinition(D, ToIface)) |
| 4808 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4809 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4810 | return ToIface; |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4811 | } |
| 4812 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4813 | ExpectedDecl |
| 4814 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 4815 | ObjCCategoryDecl *Category; |
| 4816 | if (Error Err = importInto(Category, D->getCategoryDecl())) |
| 4817 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4818 | |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4819 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4820 | if (!ToImpl) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4821 | DeclContext *DC, *LexicalDC; |
| 4822 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4823 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4824 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4825 | SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc; |
| 4826 | if (auto Imp = importSeq( |
| 4827 | D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc())) |
| 4828 | std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp; |
| 4829 | else |
| 4830 | return Imp.takeError(); |
| 4831 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4832 | if (GetImportedOrCreateDecl( |
| 4833 | ToImpl, D, Importer.getToContext(), DC, |
| 4834 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4835 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4836 | return ToImpl; |
| 4837 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4838 | ToImpl->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4839 | LexicalDC->addDeclInternal(ToImpl); |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4840 | Category->setImplementation(ToImpl); |
| 4841 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4842 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4843 | Importer.MapImported(D, ToImpl); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4844 | if (Error Err = ImportDeclContext(D)) |
| 4845 | return std::move(Err); |
| 4846 | |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4847 | return ToImpl; |
| 4848 | } |
| 4849 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4850 | ExpectedDecl |
| 4851 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4852 | // Find the corresponding interface. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4853 | ObjCInterfaceDecl *Iface; |
| 4854 | if (Error Err = importInto(Iface, D->getClassInterface())) |
| 4855 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4856 | |
| 4857 | // Import the superclass, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4858 | ObjCInterfaceDecl *Super; |
| 4859 | if (Error Err = importInto(Super, D->getSuperClass())) |
| 4860 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4861 | |
| 4862 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4863 | if (!Impl) { |
| 4864 | // We haven't imported an implementation yet. Create a new @implementation |
| 4865 | // now. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4866 | DeclContext *DC, *LexicalDC; |
| 4867 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4868 | return std::move(Err); |
| 4869 | |
| 4870 | SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc; |
| 4871 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 4872 | if (auto Imp = importSeq( |
| 4873 | D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(), |
| 4874 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 4875 | std::tie( |
| 4876 | ToLocation, ToAtStartLoc, ToSuperClassLoc, |
| 4877 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 4878 | else |
| 4879 | return Imp.takeError(); |
| 4880 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4881 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4882 | DC, Iface, Super, |
| 4883 | ToLocation, |
| 4884 | ToAtStartLoc, |
| 4885 | ToSuperClassLoc, |
| 4886 | ToIvarLBraceLoc, |
| 4887 | ToIvarRBraceLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4888 | return Impl; |
| 4889 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4890 | Impl->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4891 | |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4892 | // Associate the implementation with the class it implements. |
| 4893 | Iface->setImplementation(Impl); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4894 | Importer.MapImported(D, Iface->getImplementation()); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4895 | } else { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4896 | Importer.MapImported(D, Iface->getImplementation()); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4897 | |
| 4898 | // Verify that the existing @implementation has the same superclass. |
| 4899 | if ((Super && !Impl->getSuperClass()) || |
| 4900 | (!Super && Impl->getSuperClass()) || |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4901 | (Super && Impl->getSuperClass() && |
| 4902 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4903 | Impl->getSuperClass()))) { |
| 4904 | Importer.ToDiag(Impl->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4905 | diag::warn_odr_objc_superclass_inconsistent) |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4906 | << Iface->getDeclName(); |
| 4907 | // FIXME: It would be nice to have the location of the superclass |
| 4908 | // below. |
| 4909 | if (Impl->getSuperClass()) |
| 4910 | Importer.ToDiag(Impl->getLocation(), |
| 4911 | diag::note_odr_objc_superclass) |
| 4912 | << Impl->getSuperClass()->getDeclName(); |
| 4913 | else |
| 4914 | Importer.ToDiag(Impl->getLocation(), |
| 4915 | diag::note_odr_objc_missing_superclass); |
| 4916 | if (D->getSuperClass()) |
| 4917 | Importer.FromDiag(D->getLocation(), |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4918 | diag::note_odr_objc_superclass) |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4919 | << D->getSuperClass()->getDeclName(); |
| 4920 | else |
| 4921 | Importer.FromDiag(D->getLocation(), |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4922 | diag::note_odr_objc_missing_superclass); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4923 | |
| 4924 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4925 | } |
| 4926 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4927 | |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4928 | // Import all of the members of this @implementation. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4929 | if (Error Err = ImportDeclContext(D)) |
| 4930 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4931 | |
| 4932 | return Impl; |
| 4933 | } |
| 4934 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4935 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4936 | // Import the major distinguishing characteristics of an @property. |
| 4937 | DeclContext *DC, *LexicalDC; |
| 4938 | DeclarationName Name; |
| 4939 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4940 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4941 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4942 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4943 | if (ToD) |
| 4944 | return ToD; |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4945 | |
| 4946 | // Check whether we have already imported this property. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4947 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4948 | for (auto *FoundDecl : FoundDecls) { |
| 4949 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4950 | // Check property types. |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4951 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4952 | FoundProp->getType())) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4953 | Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent) |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4954 | << Name << D->getType() << FoundProp->getType(); |
| 4955 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4956 | << FoundProp->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4957 | |
| 4958 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4959 | } |
| 4960 | |
| 4961 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4962 | |
| 4963 | // Consider these properties to be equivalent. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4964 | Importer.MapImported(D, FoundProp); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4965 | return FoundProp; |
| 4966 | } |
| 4967 | } |
| 4968 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4969 | QualType ToType; |
| 4970 | TypeSourceInfo *ToTypeSourceInfo; |
| 4971 | SourceLocation ToAtLoc, ToLParenLoc; |
| 4972 | if (auto Imp = importSeq( |
| 4973 | D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc())) |
| 4974 | std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp; |
| 4975 | else |
| 4976 | return Imp.takeError(); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4977 | |
| 4978 | // Create the new property. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4979 | ObjCPropertyDecl *ToProperty; |
| 4980 | if (GetImportedOrCreateDecl( |
| 4981 | ToProperty, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4982 | Name.getAsIdentifierInfo(), ToAtLoc, |
| 4983 | ToLParenLoc, ToType, |
| 4984 | ToTypeSourceInfo, D->getPropertyImplementation())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4985 | return ToProperty; |
| 4986 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4987 | Selector ToGetterName, ToSetterName; |
| 4988 | SourceLocation ToGetterNameLoc, ToSetterNameLoc; |
| 4989 | ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl; |
| 4990 | ObjCIvarDecl *ToPropertyIvarDecl; |
| 4991 | if (auto Imp = importSeq( |
| 4992 | D->getGetterName(), D->getSetterName(), |
| 4993 | D->getGetterNameLoc(), D->getSetterNameLoc(), |
| 4994 | D->getGetterMethodDecl(), D->getSetterMethodDecl(), |
| 4995 | D->getPropertyIvarDecl())) |
| 4996 | std::tie( |
| 4997 | ToGetterName, ToSetterName, |
| 4998 | ToGetterNameLoc, ToSetterNameLoc, |
| 4999 | ToGetterMethodDecl, ToSetterMethodDecl, |
| 5000 | ToPropertyIvarDecl) = *Imp; |
| 5001 | else |
| 5002 | return Imp.takeError(); |
| 5003 | |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 5004 | ToProperty->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 5005 | LexicalDC->addDeclInternal(ToProperty); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 5006 | |
| 5007 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
| Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 5008 | ToProperty->setPropertyAttributesAsWritten( |
| 5009 | D->getPropertyAttributesAsWritten()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5010 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); |
| 5011 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); |
| 5012 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); |
| 5013 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); |
| 5014 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 5015 | return ToProperty; |
| 5016 | } |
| 5017 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5018 | ExpectedDecl |
| 5019 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 5020 | ObjCPropertyDecl *Property; |
| 5021 | if (Error Err = importInto(Property, D->getPropertyDecl())) |
| 5022 | return std::move(Err); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5023 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5024 | DeclContext *DC, *LexicalDC; |
| 5025 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5026 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5027 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5028 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5029 | |
| 5030 | // Import the ivar (for an @synthesize). |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5031 | ObjCIvarDecl *Ivar = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5032 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) |
| 5033 | return std::move(Err); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5034 | |
| 5035 | ObjCPropertyImplDecl *ToImpl |
| Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 5036 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 5037 | Property->getQueryKind()); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5038 | if (!ToImpl) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5039 | SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc; |
| 5040 | if (auto Imp = importSeq( |
| 5041 | D->getBeginLoc(), D->getLocation(), D->getPropertyIvarDeclLoc())) |
| 5042 | std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp; |
| 5043 | else |
| 5044 | return Imp.takeError(); |
| 5045 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5046 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5047 | ToBeginLoc, |
| 5048 | ToLocation, Property, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5049 | D->getPropertyImplementation(), Ivar, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5050 | ToPropertyIvarDeclLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5051 | return ToImpl; |
| 5052 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5053 | ToImpl->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 5054 | LexicalDC->addDeclInternal(ToImpl); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5055 | } else { |
| 5056 | // Check that we have the same kind of property implementation (@synthesize |
| 5057 | // vs. @dynamic). |
| 5058 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5059 | Importer.ToDiag(ToImpl->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 5060 | diag::warn_odr_objc_property_impl_kind_inconsistent) |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5061 | << Property->getDeclName() |
| 5062 | << (ToImpl->getPropertyImplementation() |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5063 | == ObjCPropertyImplDecl::Dynamic); |
| 5064 | Importer.FromDiag(D->getLocation(), |
| 5065 | diag::note_odr_objc_property_impl_kind) |
| 5066 | << D->getPropertyDecl()->getDeclName() |
| 5067 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5068 | |
| 5069 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5070 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5071 | |
| 5072 | // For @synthesize, check that we have the same |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5073 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 5074 | Ivar != ToImpl->getPropertyIvarDecl()) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5075 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 5076 | diag::warn_odr_objc_synthesize_ivar_inconsistent) |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5077 | << Property->getDeclName() |
| 5078 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 5079 | << Ivar->getDeclName(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5080 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5081 | diag::note_odr_objc_synthesize_ivar_here) |
| 5082 | << D->getPropertyIvarDecl()->getDeclName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5083 | |
| 5084 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5085 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5086 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5087 | // Merge the existing implementation with the new implementation. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5088 | Importer.MapImported(D, ToImpl); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5089 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5090 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5091 | return ToImpl; |
| 5092 | } |
| 5093 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5094 | ExpectedDecl |
| 5095 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5096 | // For template arguments, we adopt the translation unit as our declaration |
| 5097 | // context. This context will be fixed when the actual template declaration |
| 5098 | // is created. |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5099 | |
| Saar Raz | ff1e0fc | 2020-01-15 02:48:42 +0200 | [diff] [blame^] | 5100 | // FIXME: Import default argument and constraint expression. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5101 | |
| 5102 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5103 | if (!BeginLocOrErr) |
| 5104 | return BeginLocOrErr.takeError(); |
| 5105 | |
| 5106 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 5107 | if (!LocationOrErr) |
| 5108 | return LocationOrErr.takeError(); |
| 5109 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5110 | TemplateTypeParmDecl *ToD = nullptr; |
| Saar Raz | ff1e0fc | 2020-01-15 02:48:42 +0200 | [diff] [blame^] | 5111 | if (GetImportedOrCreateDecl( |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5112 | ToD, D, Importer.getToContext(), |
| 5113 | Importer.getToContext().getTranslationUnitDecl(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5114 | *BeginLocOrErr, *LocationOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5115 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| Saar Raz | ff1e0fc | 2020-01-15 02:48:42 +0200 | [diff] [blame^] | 5116 | D->wasDeclaredWithTypename(), D->isParameterPack(), |
| 5117 | D->hasTypeConstraint())) |
| 5118 | return ToD; |
| 5119 | |
| 5120 | // Import the type-constraint |
| 5121 | if (const TypeConstraint *TC = D->getTypeConstraint()) { |
| 5122 | NestedNameSpecifierLoc ToNNS; |
| 5123 | DeclarationName ToName; |
| 5124 | SourceLocation ToNameLoc; |
| 5125 | NamedDecl *ToFoundDecl; |
| 5126 | ConceptDecl *ToNamedConcept; |
| 5127 | Expr *ToIDC; |
| 5128 | if (auto Imp = importSeq(TC->getNestedNameSpecifierLoc(), |
| 5129 | TC->getConceptNameInfo().getName(), TC->getConceptNameInfo().getLoc(), |
| 5130 | TC->getFoundDecl(), TC->getNamedConcept(), |
| 5131 | TC->getImmediatelyDeclaredConstraint())) |
| 5132 | std::tie(ToNNS, ToName, ToNameLoc, ToFoundDecl, ToNamedConcept, |
| 5133 | ToIDC) = *Imp; |
| 5134 | else |
| 5135 | return Imp.takeError(); |
| 5136 | |
| 5137 | TemplateArgumentListInfo ToTAInfo; |
| 5138 | const auto *ASTTemplateArgs = TC->getTemplateArgsAsWritten(); |
| 5139 | if (ASTTemplateArgs) |
| 5140 | if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, |
| 5141 | ToTAInfo)) |
| 5142 | return std::move(Err); |
| 5143 | |
| 5144 | ToD->setTypeConstraint(ToNNS, DeclarationNameInfo(ToName, ToNameLoc), |
| 5145 | ToFoundDecl, ToNamedConcept, |
| 5146 | ASTTemplateArgs ? |
| 5147 | ASTTemplateArgumentListInfo::Create(Importer.getToContext(), |
| 5148 | ToTAInfo) : nullptr, |
| 5149 | ToIDC); |
| 5150 | } |
| 5151 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5152 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5153 | } |
| 5154 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5155 | ExpectedDecl |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5156 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5157 | DeclarationName ToDeclName; |
| 5158 | SourceLocation ToLocation, ToInnerLocStart; |
| 5159 | QualType ToType; |
| 5160 | TypeSourceInfo *ToTypeSourceInfo; |
| 5161 | if (auto Imp = importSeq( |
| 5162 | D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(), |
| 5163 | D->getInnerLocStart())) |
| 5164 | std::tie( |
| 5165 | ToDeclName, ToLocation, ToType, ToTypeSourceInfo, |
| 5166 | ToInnerLocStart) = *Imp; |
| 5167 | else |
| 5168 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5169 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5170 | // FIXME: Import default argument. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5171 | |
| 5172 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 5173 | (void)GetImportedOrCreateDecl( |
| 5174 | ToD, D, Importer.getToContext(), |
| 5175 | Importer.getToContext().getTranslationUnitDecl(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5176 | ToInnerLocStart, ToLocation, D->getDepth(), |
| 5177 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, |
| 5178 | D->isParameterPack(), ToTypeSourceInfo); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5179 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5180 | } |
| 5181 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5182 | ExpectedDecl |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5183 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 5184 | // Import the name of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5185 | auto NameOrErr = import(D->getDeclName()); |
| 5186 | if (!NameOrErr) |
| 5187 | return NameOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5188 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5189 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5190 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 5191 | if (!LocationOrErr) |
| 5192 | return LocationOrErr.takeError(); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5193 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5194 | // Import template parameters. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5195 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5196 | if (!TemplateParamsOrErr) |
| 5197 | return TemplateParamsOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5198 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5199 | // FIXME: Import default argument. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5200 | |
| 5201 | TemplateTemplateParmDecl *ToD = nullptr; |
| 5202 | (void)GetImportedOrCreateDecl( |
| 5203 | ToD, D, Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5204 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, |
| 5205 | D->getDepth(), D->getPosition(), D->isParameterPack(), |
| 5206 | (*NameOrErr).getAsIdentifierInfo(), |
| 5207 | *TemplateParamsOrErr); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5208 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5209 | } |
| 5210 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5211 | // Returns the definition for a (forward) declaration of a TemplateDecl, if |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5212 | // it has any definition in the redecl chain. |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5213 | template <typename T> static auto getTemplateDefinition(T *D) -> T * { |
| 5214 | assert(D->getTemplatedDecl() && "Should be called on templates only"); |
| 5215 | auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5216 | if (!ToTemplatedDef) |
| 5217 | return nullptr; |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5218 | auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate(); |
| 5219 | return cast_or_null<T>(TemplateWithDef); |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5220 | } |
| 5221 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5222 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5223 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5224 | // Import the major distinguishing characteristics of this class template. |
| 5225 | DeclContext *DC, *LexicalDC; |
| 5226 | DeclarationName Name; |
| 5227 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5228 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5229 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5230 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5231 | if (ToD) |
| 5232 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5233 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5234 | ClassTemplateDecl *FoundByLookup = nullptr; |
| 5235 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5236 | // We may already have a template of the same name; try to find and match it. |
| 5237 | if (!DC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5238 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5239 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5240 | for (auto *FoundDecl : FoundDecls) { |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5241 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary | |
| 5242 | Decl::IDNS_TagFriend)) |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5243 | continue; |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5244 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5245 | Decl *Found = FoundDecl; |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5246 | auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found); |
| 5247 | if (FoundTemplate) { |
| Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 5248 | if (!hasSameVisibilityContext(FoundTemplate, D)) |
| 5249 | continue; |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5250 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5251 | if (IsStructuralMatch(D, FoundTemplate)) { |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5252 | ClassTemplateDecl *TemplateWithDef = |
| 5253 | getTemplateDefinition(FoundTemplate); |
| Balazs Keri | 2e16060 | 2019-08-12 10:07:38 +0000 | [diff] [blame] | 5254 | if (D->isThisDeclarationADefinition() && TemplateWithDef) |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5255 | return Importer.MapImported(D, TemplateWithDef); |
| Balazs Keri | 2e16060 | 2019-08-12 10:07:38 +0000 | [diff] [blame] | 5256 | if (!FoundByLookup) |
| 5257 | FoundByLookup = FoundTemplate; |
| 5258 | // Search in all matches because there may be multiple decl chains, |
| 5259 | // see ASTTests test ImportExistingFriendClassTemplateDef. |
| 5260 | continue; |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5261 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5262 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5263 | } |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5264 | } |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5265 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5266 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5267 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 5268 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), |
| 5269 | ConflictingDecls.size()); |
| 5270 | if (NameOrErr) |
| 5271 | Name = NameOrErr.get(); |
| 5272 | else |
| 5273 | return NameOrErr.takeError(); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5274 | } |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5275 | } |
| 5276 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5277 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 5278 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5279 | // Create the declaration that is being templated. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5280 | CXXRecordDecl *ToTemplated; |
| 5281 | if (Error Err = importInto(ToTemplated, FromTemplated)) |
| 5282 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5283 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5284 | // Create the class template declaration itself. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5285 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5286 | if (!TemplateParamsOrErr) |
| 5287 | return TemplateParamsOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5288 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5289 | ClassTemplateDecl *D2; |
| 5290 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5291 | *TemplateParamsOrErr, ToTemplated)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5292 | return D2; |
| 5293 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5294 | ToTemplated->setDescribedClassTemplate(D2); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5295 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5296 | D2->setAccess(D->getAccess()); |
| 5297 | D2->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5298 | |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 5299 | addDeclToContexts(D, D2); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5300 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5301 | if (FoundByLookup) { |
| 5302 | auto *Recent = |
| 5303 | const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5304 | |
| 5305 | // It is possible that during the import of the class template definition |
| 5306 | // we start the import of a fwd friend decl of the very same class template |
| 5307 | // and we add the fwd friend decl to the lookup table. But the ToTemplated |
| 5308 | // had been created earlier and by that time the lookup could not find |
| 5309 | // anything existing, so it has no previous decl. Later, (still during the |
| 5310 | // import of the fwd friend decl) we start to import the definition again |
| 5311 | // and this time the lookup finds the previous fwd friend class template. |
| 5312 | // In this case we must set up the previous decl for the templated decl. |
| 5313 | if (!ToTemplated->getPreviousDecl()) { |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5314 | assert(FoundByLookup->getTemplatedDecl() && |
| 5315 | "Found decl must have its templated decl set"); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5316 | CXXRecordDecl *PrevTemplated = |
| 5317 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5318 | if (ToTemplated != PrevTemplated) |
| 5319 | ToTemplated->setPreviousDecl(PrevTemplated); |
| 5320 | } |
| 5321 | |
| 5322 | D2->setPreviousDecl(Recent); |
| 5323 | } |
| 5324 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5325 | if (FromTemplated->isCompleteDefinition() && |
| 5326 | !ToTemplated->isCompleteDefinition()) { |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5327 | // FIXME: Import definition! |
| 5328 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5329 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5330 | return D2; |
| 5331 | } |
| 5332 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5333 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5334 | ClassTemplateSpecializationDecl *D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5335 | ClassTemplateDecl *ClassTemplate; |
| 5336 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) |
| 5337 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5338 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5339 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5340 | DeclContext *DC, *LexicalDC; |
| 5341 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5342 | return std::move(Err); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5343 | |
| 5344 | // Import template arguments. |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5345 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5346 | if (Error Err = ImportTemplateArguments( |
| 5347 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5348 | return std::move(Err); |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5349 | // Try to find an existing specialization with these template arguments and |
| 5350 | // template parameter list. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5351 | void *InsertPos = nullptr; |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5352 | ClassTemplateSpecializationDecl *PrevDecl = nullptr; |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5353 | ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 5354 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5355 | |
| 5356 | // Import template parameters. |
| 5357 | TemplateParameterList *ToTPList = nullptr; |
| 5358 | |
| 5359 | if (PartialSpec) { |
| 5360 | auto ToTPListOrErr = import(PartialSpec->getTemplateParameters()); |
| 5361 | if (!ToTPListOrErr) |
| 5362 | return ToTPListOrErr.takeError(); |
| 5363 | ToTPList = *ToTPListOrErr; |
| 5364 | PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs, |
| 5365 | *ToTPListOrErr, |
| 5366 | InsertPos); |
| 5367 | } else |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5368 | PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5369 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5370 | if (PrevDecl) { |
| 5371 | if (IsStructuralMatch(D, PrevDecl)) { |
| 5372 | if (D->isThisDeclarationADefinition() && PrevDecl->getDefinition()) { |
| 5373 | Importer.MapImported(D, PrevDecl->getDefinition()); |
| 5374 | // Import those default field initializers which have been |
| 5375 | // instantiated in the "From" context, but not in the "To" context. |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5376 | for (auto *FromField : D->fields()) { |
| 5377 | auto ToOrErr = import(FromField); |
| 5378 | if (!ToOrErr) |
| 5379 | return ToOrErr.takeError(); |
| 5380 | } |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5381 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5382 | // Import those methods which have been instantiated in the |
| 5383 | // "From" context, but not in the "To" context. |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5384 | for (CXXMethodDecl *FromM : D->methods()) { |
| 5385 | auto ToOrErr = import(FromM); |
| 5386 | if (!ToOrErr) |
| 5387 | return ToOrErr.takeError(); |
| 5388 | } |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5389 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5390 | // TODO Import instantiated default arguments. |
| 5391 | // TODO Import instantiated exception specifications. |
| 5392 | // |
| 5393 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint |
| 5394 | // what else could be fused during an AST merge. |
| 5395 | return PrevDecl; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5396 | } |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5397 | } else { // ODR violation. |
| 5398 | // FIXME HandleNameConflict |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 5399 | return make_error<ImportError>(ImportError::NameConflict); |
| 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 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5402 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5403 | // Import the location of this declaration. |
| 5404 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5405 | if (!BeginLocOrErr) |
| 5406 | return BeginLocOrErr.takeError(); |
| 5407 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); |
| 5408 | if (!IdLocOrErr) |
| 5409 | return IdLocOrErr.takeError(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5410 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5411 | // Create the specialization. |
| 5412 | ClassTemplateSpecializationDecl *D2 = nullptr; |
| 5413 | if (PartialSpec) { |
| 5414 | // Import TemplateArgumentListInfo. |
| 5415 | TemplateArgumentListInfo ToTAInfo; |
| 5416 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 5417 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
| 5418 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5419 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5420 | QualType CanonInjType; |
| 5421 | if (Error Err = importInto( |
| 5422 | CanonInjType, PartialSpec->getInjectedSpecializationType())) |
| 5423 | return std::move(Err); |
| 5424 | CanonInjType = CanonInjType.getCanonicalType(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5425 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5426 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
| 5427 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5428 | *BeginLocOrErr, *IdLocOrErr, ToTPList, ClassTemplate, |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5429 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 5430 | ToTAInfo, CanonInjType, |
| 5431 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) |
| 5432 | return D2; |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5433 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5434 | // Update InsertPos, because preceding import calls may have invalidated |
| 5435 | // it by adding new specializations. |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5436 | auto *PartSpec2 = cast<ClassTemplatePartialSpecializationDecl>(D2); |
| 5437 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList, |
| 5438 | InsertPos)) |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5439 | // Add this partial specialization to the class template. |
| Saar Raz | df061c3 | 2019-12-23 08:37:35 +0200 | [diff] [blame] | 5440 | ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5441 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5442 | } else { // Not a partial specialization. |
| 5443 | if (GetImportedOrCreateDecl( |
| 5444 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5445 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, |
| 5446 | PrevDecl)) |
| 5447 | return D2; |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5448 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5449 | // Update InsertPos, because preceding import calls may have invalidated |
| 5450 | // it by adding new specializations. |
| 5451 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) |
| 5452 | // Add this specialization to the class template. |
| 5453 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 5454 | } |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5455 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5456 | D2->setSpecializationKind(D->getSpecializationKind()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5457 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5458 | // Set the context of this specialization/instantiation. |
| 5459 | D2->setLexicalDeclContext(LexicalDC); |
| 5460 | |
| 5461 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 5462 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 5463 | LexicalDC->addDeclInternal(D2); |
| 5464 | } |
| 5465 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 5466 | if (auto BraceRangeOrErr = import(D->getBraceRange())) |
| 5467 | D2->setBraceRange(*BraceRangeOrErr); |
| 5468 | else |
| 5469 | return BraceRangeOrErr.takeError(); |
| 5470 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5471 | // Import the qualifier, if any. |
| 5472 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5473 | D2->setQualifierInfo(*LocOrErr); |
| 5474 | else |
| 5475 | return LocOrErr.takeError(); |
| 5476 | |
| 5477 | if (auto *TSI = D->getTypeAsWritten()) { |
| 5478 | if (auto TInfoOrErr = import(TSI)) |
| 5479 | D2->setTypeAsWritten(*TInfoOrErr); |
| 5480 | else |
| 5481 | return TInfoOrErr.takeError(); |
| 5482 | |
| 5483 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) |
| 5484 | D2->setTemplateKeywordLoc(*LocOrErr); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5485 | else |
| 5486 | return LocOrErr.takeError(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5487 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5488 | if (auto LocOrErr = import(D->getExternLoc())) |
| 5489 | D2->setExternLoc(*LocOrErr); |
| 5490 | else |
| 5491 | return LocOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5492 | } |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5493 | |
| 5494 | if (D->getPointOfInstantiation().isValid()) { |
| 5495 | if (auto POIOrErr = import(D->getPointOfInstantiation())) |
| 5496 | D2->setPointOfInstantiation(*POIOrErr); |
| 5497 | else |
| 5498 | return POIOrErr.takeError(); |
| 5499 | } |
| 5500 | |
| 5501 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 5502 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5503 | if (D->isCompleteDefinition()) |
| 5504 | if (Error Err = ImportDefinition(D, D2)) |
| 5505 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5506 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5507 | return D2; |
| 5508 | } |
| 5509 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5510 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5511 | // If this variable has a definition in the translation unit we're coming |
| 5512 | // from, |
| 5513 | // but this particular declaration is not that definition, import the |
| 5514 | // definition and map to that. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5515 | auto *Definition = |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5516 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 5517 | if (Definition && Definition != D->getTemplatedDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5518 | if (ExpectedDecl ImportedDefOrErr = import( |
| 5519 | Definition->getDescribedVarTemplate())) |
| 5520 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5521 | else |
| 5522 | return ImportedDefOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5523 | } |
| 5524 | |
| 5525 | // Import the major distinguishing characteristics of this variable template. |
| 5526 | DeclContext *DC, *LexicalDC; |
| 5527 | DeclarationName Name; |
| 5528 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5529 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5530 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5531 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5532 | if (ToD) |
| 5533 | return ToD; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5534 | |
| 5535 | // We may already have a template of the same name; try to find and match it. |
| 5536 | assert(!DC->isFunctionOrMethod() && |
| 5537 | "Variable templates cannot be declared at function scope"); |
| 5538 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5539 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5540 | for (auto *FoundDecl : FoundDecls) { |
| 5541 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5542 | continue; |
| 5543 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5544 | Decl *Found = FoundDecl; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5545 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5546 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5547 | // The variable templates structurally match; call it the same template. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5548 | Importer.MapImported(D->getTemplatedDecl(), |
| 5549 | FoundTemplate->getTemplatedDecl()); |
| 5550 | return Importer.MapImported(D, FoundTemplate); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5551 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5552 | ConflictingDecls.push_back(FoundDecl); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5553 | } |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5554 | } |
| 5555 | |
| 5556 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5557 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 5558 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), |
| 5559 | ConflictingDecls.size()); |
| 5560 | if (NameOrErr) |
| 5561 | Name = NameOrErr.get(); |
| 5562 | else |
| 5563 | return NameOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5564 | } |
| 5565 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5566 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 5567 | |
| 5568 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5569 | // FIXME: Value not used? |
| 5570 | ExpectedType TypeOrErr = import(DTemplated->getType()); |
| 5571 | if (!TypeOrErr) |
| 5572 | return TypeOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5573 | |
| 5574 | // Create the declaration that is being templated. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5575 | VarDecl *ToTemplated; |
| 5576 | if (Error Err = importInto(ToTemplated, DTemplated)) |
| 5577 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5578 | |
| 5579 | // Create the variable template declaration itself. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5580 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5581 | if (!TemplateParamsOrErr) |
| 5582 | return TemplateParamsOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5583 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5584 | VarTemplateDecl *ToVarTD; |
| 5585 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5586 | Name, *TemplateParamsOrErr, ToTemplated)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5587 | return ToVarTD; |
| 5588 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5589 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5590 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5591 | ToVarTD->setAccess(D->getAccess()); |
| 5592 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 5593 | LexicalDC->addDeclInternal(ToVarTD); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5594 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5595 | if (DTemplated->isThisDeclarationADefinition() && |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5596 | !ToTemplated->isThisDeclarationADefinition()) { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5597 | // FIXME: Import definition! |
| 5598 | } |
| 5599 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5600 | return ToVarTD; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5601 | } |
| 5602 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5603 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5604 | VarTemplateSpecializationDecl *D) { |
| 5605 | // If this record has a definition in the translation unit we're coming from, |
| 5606 | // but this particular declaration is not that definition, import the |
| 5607 | // definition and map to that. |
| 5608 | VarDecl *Definition = D->getDefinition(); |
| 5609 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5610 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5611 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5612 | else |
| 5613 | return ImportedDefOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5614 | } |
| 5615 | |
| Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 5616 | VarTemplateDecl *VarTemplate = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5617 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) |
| 5618 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5619 | |
| 5620 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5621 | DeclContext *DC, *LexicalDC; |
| 5622 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5623 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5624 | |
| 5625 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5626 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5627 | if (!BeginLocOrErr) |
| 5628 | return BeginLocOrErr.takeError(); |
| 5629 | |
| 5630 | auto IdLocOrErr = import(D->getLocation()); |
| 5631 | if (!IdLocOrErr) |
| 5632 | return IdLocOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5633 | |
| 5634 | // Import template arguments. |
| 5635 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5636 | if (Error Err = ImportTemplateArguments( |
| 5637 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5638 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5639 | |
| 5640 | // Try to find an existing specialization with these template arguments. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5641 | void *InsertPos = nullptr; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5642 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
| Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 5643 | TemplateArgs, InsertPos); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5644 | if (D2) { |
| 5645 | // We already have a variable template specialization with these template |
| 5646 | // arguments. |
| 5647 | |
| 5648 | // FIXME: Check for specialization vs. instantiation errors. |
| 5649 | |
| 5650 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 5651 | if (!D->isThisDeclarationADefinition() || |
| 5652 | IsStructuralMatch(D, FoundDef)) { |
| 5653 | // The record types structurally match, or the "from" translation |
| 5654 | // unit only had a forward declaration anyway; call it the same |
| 5655 | // variable. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5656 | return Importer.MapImported(D, FoundDef); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5657 | } |
| 5658 | } |
| 5659 | } else { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5660 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5661 | QualType T; |
| 5662 | if (Error Err = importInto(T, D->getType())) |
| 5663 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5664 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5665 | auto TInfoOrErr = import(D->getTypeSourceInfo()); |
| 5666 | if (!TInfoOrErr) |
| 5667 | return TInfoOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5668 | |
| 5669 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5670 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5671 | D->getTemplateArgsInfo(), ToTAInfo)) |
| 5672 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5673 | |
| 5674 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5675 | // Create a new specialization. |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5676 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 5677 | // Import TemplateArgumentListInfo |
| 5678 | TemplateArgumentListInfo ArgInfos; |
| 5679 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 5680 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5681 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5682 | *FromTAArgsAsWritten, ArgInfos)) |
| 5683 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5684 | |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5685 | auto ToTPListOrErr = import(FromPartial->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5686 | if (!ToTPListOrErr) |
| 5687 | return ToTPListOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5688 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5689 | PartVarSpecDecl *ToPartial; |
| 5690 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5691 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, |
| 5692 | VarTemplate, T, *TInfoOrErr, |
| 5693 | D->getStorageClass(), TemplateArgs, ArgInfos)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5694 | return ToPartial; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5695 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5696 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( |
| 5697 | FromPartial->getInstantiatedFromMember())) |
| 5698 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); |
| 5699 | else |
| 5700 | return ToInstOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5701 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5702 | if (FromPartial->isMemberSpecialization()) |
| 5703 | ToPartial->setMemberSpecialization(); |
| 5704 | |
| 5705 | D2 = ToPartial; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5706 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5707 | } else { // Full specialization |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5708 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, |
| 5709 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, |
| 5710 | T, *TInfoOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5711 | D->getStorageClass(), TemplateArgs)) |
| 5712 | return D2; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5713 | } |
| 5714 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5715 | if (D->getPointOfInstantiation().isValid()) { |
| 5716 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) |
| 5717 | D2->setPointOfInstantiation(*POIOrErr); |
| 5718 | else |
| 5719 | return POIOrErr.takeError(); |
| 5720 | } |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5721 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5722 | D2->setSpecializationKind(D->getSpecializationKind()); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5723 | D2->setTemplateArgsInfo(ToTAInfo); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5724 | |
| 5725 | // Add this specialization to the class template. |
| 5726 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 5727 | |
| 5728 | // Import the qualifier, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5729 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5730 | D2->setQualifierInfo(*LocOrErr); |
| 5731 | else |
| 5732 | return LocOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5733 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5734 | if (D->isConstexpr()) |
| 5735 | D2->setConstexpr(true); |
| 5736 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5737 | // Add the specialization to this context. |
| 5738 | D2->setLexicalDeclContext(LexicalDC); |
| 5739 | LexicalDC->addDeclInternal(D2); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5740 | |
| 5741 | D2->setAccess(D->getAccess()); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5742 | } |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5743 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5744 | if (Error Err = ImportInitializer(D, D2)) |
| 5745 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5746 | |
| 5747 | return D2; |
| 5748 | } |
| 5749 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5750 | ExpectedDecl |
| 5751 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5752 | DeclContext *DC, *LexicalDC; |
| 5753 | DeclarationName Name; |
| 5754 | SourceLocation Loc; |
| 5755 | NamedDecl *ToD; |
| 5756 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5757 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5758 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5759 | |
| 5760 | if (ToD) |
| 5761 | return ToD; |
| 5762 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5763 | const FunctionTemplateDecl *FoundByLookup = nullptr; |
| 5764 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5765 | // Try to find a function in our own ("to") context with the same name, same |
| 5766 | // type, and in the same context as the function we're importing. |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5767 | // FIXME Split this into a separate function. |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5768 | if (!LexicalDC->isFunctionOrMethod()) { |
| Gabor Marton | e331e63 | 2019-02-18 13:09:27 +0000 | [diff] [blame] | 5769 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5770 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5771 | for (auto *FoundDecl : FoundDecls) { |
| 5772 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5773 | continue; |
| 5774 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5775 | if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
| Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 5776 | if (!hasSameVisibilityContext(FoundTemplate, D)) |
| 5777 | continue; |
| 5778 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5779 | FunctionTemplateDecl *TemplateWithDef = |
| 5780 | getTemplateDefinition(FoundTemplate); |
| 5781 | if (D->isThisDeclarationADefinition() && TemplateWithDef) |
| 5782 | return Importer.MapImported(D, TemplateWithDef); |
| 5783 | |
| 5784 | FoundByLookup = FoundTemplate; |
| 5785 | break; |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5786 | // TODO: handle conflicting names |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5787 | } |
| 5788 | } |
| 5789 | } |
| 5790 | } |
| 5791 | |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5792 | auto ParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5793 | if (!ParamsOrErr) |
| 5794 | return ParamsOrErr.takeError(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5795 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5796 | FunctionDecl *TemplatedFD; |
| 5797 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) |
| 5798 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5799 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5800 | FunctionTemplateDecl *ToFunc; |
| 5801 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5802 | *ParamsOrErr, TemplatedFD)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5803 | return ToFunc; |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5804 | |
| 5805 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5806 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5807 | ToFunc->setAccess(D->getAccess()); |
| 5808 | ToFunc->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5809 | LexicalDC->addDeclInternal(ToFunc); |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5810 | |
| 5811 | if (FoundByLookup) { |
| 5812 | auto *Recent = |
| 5813 | const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5814 | if (!TemplatedFD->getPreviousDecl()) { |
| 5815 | assert(FoundByLookup->getTemplatedDecl() && |
| 5816 | "Found decl must have its templated decl set"); |
| 5817 | auto *PrevTemplated = |
| 5818 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5819 | if (TemplatedFD != PrevTemplated) |
| 5820 | TemplatedFD->setPreviousDecl(PrevTemplated); |
| 5821 | } |
| 5822 | ToFunc->setPreviousDecl(Recent); |
| 5823 | } |
| 5824 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5825 | return ToFunc; |
| 5826 | } |
| 5827 | |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5828 | //---------------------------------------------------------------------------- |
| 5829 | // Import Statements |
| 5830 | //---------------------------------------------------------------------------- |
| 5831 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5832 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5833 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) |
| 5834 | << S->getStmtClassName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5835 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5836 | } |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5837 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5838 | |
| 5839 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 5840 | if (Importer.returnWithErrorInTest()) |
| 5841 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5842 | SmallVector<IdentifierInfo *, 4> Names; |
| 5843 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 5844 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
| Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5845 | // ToII is nullptr when no symbolic name is given for output operand |
| 5846 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5847 | Names.push_back(ToII); |
| 5848 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5849 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5850 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 5851 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
| Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5852 | // ToII is nullptr when no symbolic name is given for input operand |
| 5853 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5854 | Names.push_back(ToII); |
| 5855 | } |
| 5856 | |
| 5857 | SmallVector<StringLiteral *, 4> Clobbers; |
| 5858 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5859 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) |
| 5860 | Clobbers.push_back(*ClobberOrErr); |
| 5861 | else |
| 5862 | return ClobberOrErr.takeError(); |
| 5863 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5864 | } |
| 5865 | |
| 5866 | SmallVector<StringLiteral *, 4> Constraints; |
| 5867 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5868 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) |
| 5869 | Constraints.push_back(*OutputOrErr); |
| 5870 | else |
| 5871 | return OutputOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5872 | } |
| 5873 | |
| 5874 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5875 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) |
| 5876 | Constraints.push_back(*InputOrErr); |
| 5877 | else |
| 5878 | return InputOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5879 | } |
| 5880 | |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5881 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() + |
| 5882 | S->getNumLabels()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5883 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) |
| 5884 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5885 | |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5886 | if (Error Err = |
| 5887 | ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
| 5888 | return std::move(Err); |
| 5889 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5890 | if (Error Err = ImportArrayChecked( |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5891 | S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs())) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5892 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5893 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5894 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); |
| 5895 | if (!AsmLocOrErr) |
| 5896 | return AsmLocOrErr.takeError(); |
| 5897 | auto AsmStrOrErr = import(S->getAsmString()); |
| 5898 | if (!AsmStrOrErr) |
| 5899 | return AsmStrOrErr.takeError(); |
| 5900 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); |
| 5901 | if (!RParenLocOrErr) |
| 5902 | return RParenLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5903 | |
| 5904 | return new (Importer.getToContext()) GCCAsmStmt( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5905 | Importer.getToContext(), |
| 5906 | *AsmLocOrErr, |
| 5907 | S->isSimple(), |
| 5908 | S->isVolatile(), |
| 5909 | S->getNumOutputs(), |
| 5910 | S->getNumInputs(), |
| 5911 | Names.data(), |
| 5912 | Constraints.data(), |
| 5913 | Exprs.data(), |
| 5914 | *AsmStrOrErr, |
| 5915 | S->getNumClobbers(), |
| 5916 | Clobbers.data(), |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5917 | S->getNumLabels(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5918 | *RParenLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5919 | } |
| 5920 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5921 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 5922 | auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc()); |
| 5923 | if (!Imp) |
| 5924 | return Imp.takeError(); |
| 5925 | |
| 5926 | DeclGroupRef ToDG; |
| 5927 | SourceLocation ToBeginLoc, ToEndLoc; |
| 5928 | std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp; |
| 5929 | |
| 5930 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5931 | } |
| 5932 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5933 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5934 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); |
| 5935 | if (!ToSemiLocOrErr) |
| 5936 | return ToSemiLocOrErr.takeError(); |
| 5937 | return new (Importer.getToContext()) NullStmt( |
| 5938 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5939 | } |
| 5940 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5941 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5942 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5943 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5944 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) |
| 5945 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5946 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5947 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); |
| 5948 | if (!ToLBracLocOrErr) |
| 5949 | return ToLBracLocOrErr.takeError(); |
| 5950 | |
| 5951 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); |
| 5952 | if (!ToRBracLocOrErr) |
| 5953 | return ToRBracLocOrErr.takeError(); |
| 5954 | |
| 5955 | return CompoundStmt::Create( |
| 5956 | Importer.getToContext(), ToStmts, |
| 5957 | *ToLBracLocOrErr, *ToRBracLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5958 | } |
| 5959 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5960 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 5961 | auto Imp = importSeq( |
| 5962 | S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(), |
| 5963 | S->getEllipsisLoc(), S->getColonLoc()); |
| 5964 | if (!Imp) |
| 5965 | return Imp.takeError(); |
| 5966 | |
| 5967 | Expr *ToLHS, *ToRHS; |
| 5968 | Stmt *ToSubStmt; |
| 5969 | SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc; |
| 5970 | std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) = |
| 5971 | *Imp; |
| 5972 | |
| Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 5973 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, |
| 5974 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
| Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5975 | ToStmt->setSubStmt(ToSubStmt); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5976 | |
| Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5977 | return ToStmt; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5978 | } |
| 5979 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5980 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 5981 | auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt()); |
| 5982 | if (!Imp) |
| 5983 | return Imp.takeError(); |
| 5984 | |
| 5985 | SourceLocation ToDefaultLoc, ToColonLoc; |
| 5986 | Stmt *ToSubStmt; |
| 5987 | std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp; |
| 5988 | |
| 5989 | return new (Importer.getToContext()) DefaultStmt( |
| 5990 | ToDefaultLoc, ToColonLoc, ToSubStmt); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5991 | } |
| 5992 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5993 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 5994 | auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt()); |
| 5995 | if (!Imp) |
| 5996 | return Imp.takeError(); |
| 5997 | |
| 5998 | SourceLocation ToIdentLoc; |
| 5999 | LabelDecl *ToLabelDecl; |
| 6000 | Stmt *ToSubStmt; |
| 6001 | std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp; |
| 6002 | |
| 6003 | return new (Importer.getToContext()) LabelStmt( |
| 6004 | ToIdentLoc, ToLabelDecl, ToSubStmt); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6005 | } |
| 6006 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6007 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 6008 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); |
| 6009 | if (!ToAttrLocOrErr) |
| 6010 | return ToAttrLocOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6011 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 6012 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6013 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) |
| 6014 | return std::move(Err); |
| 6015 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 6016 | if (!ToSubStmtOrErr) |
| 6017 | return ToSubStmtOrErr.takeError(); |
| 6018 | |
| 6019 | return AttributedStmt::Create( |
| 6020 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6021 | } |
| 6022 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6023 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 6024 | auto Imp = importSeq( |
| 6025 | S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(), |
| 6026 | S->getThen(), S->getElseLoc(), S->getElse()); |
| 6027 | if (!Imp) |
| 6028 | return Imp.takeError(); |
| 6029 | |
| 6030 | SourceLocation ToIfLoc, ToElseLoc; |
| 6031 | Stmt *ToInit, *ToThen, *ToElse; |
| 6032 | VarDecl *ToConditionVariable; |
| 6033 | Expr *ToCond; |
| 6034 | std::tie( |
| 6035 | ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) = |
| 6036 | *Imp; |
| 6037 | |
| Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 6038 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), |
| 6039 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, |
| 6040 | ToElse); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6041 | } |
| 6042 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6043 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
| 6044 | auto Imp = importSeq( |
| 6045 | S->getInit(), S->getConditionVariable(), S->getCond(), |
| 6046 | S->getBody(), S->getSwitchLoc()); |
| 6047 | if (!Imp) |
| 6048 | return Imp.takeError(); |
| 6049 | |
| 6050 | Stmt *ToInit, *ToBody; |
| 6051 | VarDecl *ToConditionVariable; |
| 6052 | Expr *ToCond; |
| 6053 | SourceLocation ToSwitchLoc; |
| 6054 | std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp; |
| 6055 | |
| Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 6056 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, |
| 6057 | ToConditionVariable, ToCond); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6058 | ToStmt->setBody(ToBody); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6059 | ToStmt->setSwitchLoc(ToSwitchLoc); |
| 6060 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6061 | // Now we have to re-chain the cases. |
| 6062 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 6063 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 6064 | SC = SC->getNextSwitchCase()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6065 | Expected<SwitchCase *> ToSCOrErr = import(SC); |
| 6066 | if (!ToSCOrErr) |
| 6067 | return ToSCOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6068 | if (LastChainedSwitchCase) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6069 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6070 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6071 | ToStmt->setSwitchCaseList(*ToSCOrErr); |
| 6072 | LastChainedSwitchCase = *ToSCOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6073 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6074 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6075 | return ToStmt; |
| 6076 | } |
| 6077 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6078 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 6079 | auto Imp = importSeq( |
| 6080 | S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc()); |
| 6081 | if (!Imp) |
| 6082 | return Imp.takeError(); |
| 6083 | |
| 6084 | VarDecl *ToConditionVariable; |
| 6085 | Expr *ToCond; |
| 6086 | Stmt *ToBody; |
| 6087 | SourceLocation ToWhileLoc; |
| 6088 | std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp; |
| 6089 | |
| Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 6090 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, |
| 6091 | ToBody, ToWhileLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6092 | } |
| 6093 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6094 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 6095 | auto Imp = importSeq( |
| 6096 | S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(), |
| 6097 | S->getRParenLoc()); |
| 6098 | if (!Imp) |
| 6099 | return Imp.takeError(); |
| 6100 | |
| 6101 | Stmt *ToBody; |
| 6102 | Expr *ToCond; |
| 6103 | SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc; |
| 6104 | std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp; |
| 6105 | |
| 6106 | return new (Importer.getToContext()) DoStmt( |
| 6107 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6108 | } |
| 6109 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6110 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 6111 | auto Imp = importSeq( |
| 6112 | S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(), |
| 6113 | S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc()); |
| 6114 | if (!Imp) |
| 6115 | return Imp.takeError(); |
| 6116 | |
| 6117 | Stmt *ToInit; |
| 6118 | Expr *ToCond, *ToInc; |
| 6119 | VarDecl *ToConditionVariable; |
| 6120 | Stmt *ToBody; |
| 6121 | SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc; |
| 6122 | std::tie( |
| 6123 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, |
| 6124 | ToLParenLoc, ToRParenLoc) = *Imp; |
| 6125 | |
| 6126 | return new (Importer.getToContext()) ForStmt( |
| 6127 | Importer.getToContext(), |
| 6128 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, |
| 6129 | ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6130 | } |
| 6131 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6132 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 6133 | auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc()); |
| 6134 | if (!Imp) |
| 6135 | return Imp.takeError(); |
| 6136 | |
| 6137 | LabelDecl *ToLabel; |
| 6138 | SourceLocation ToGotoLoc, ToLabelLoc; |
| 6139 | std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp; |
| 6140 | |
| 6141 | return new (Importer.getToContext()) GotoStmt( |
| 6142 | ToLabel, ToGotoLoc, ToLabelLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6143 | } |
| 6144 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6145 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 6146 | auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget()); |
| 6147 | if (!Imp) |
| 6148 | return Imp.takeError(); |
| 6149 | |
| 6150 | SourceLocation ToGotoLoc, ToStarLoc; |
| 6151 | Expr *ToTarget; |
| 6152 | std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp; |
| 6153 | |
| 6154 | return new (Importer.getToContext()) IndirectGotoStmt( |
| 6155 | ToGotoLoc, ToStarLoc, ToTarget); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6156 | } |
| 6157 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6158 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 6159 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); |
| 6160 | if (!ToContinueLocOrErr) |
| 6161 | return ToContinueLocOrErr.takeError(); |
| 6162 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6163 | } |
| 6164 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6165 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 6166 | auto ToBreakLocOrErr = import(S->getBreakLoc()); |
| 6167 | if (!ToBreakLocOrErr) |
| 6168 | return ToBreakLocOrErr.takeError(); |
| 6169 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6170 | } |
| 6171 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6172 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 6173 | auto Imp = importSeq( |
| 6174 | S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate()); |
| 6175 | if (!Imp) |
| 6176 | return Imp.takeError(); |
| 6177 | |
| 6178 | SourceLocation ToReturnLoc; |
| 6179 | Expr *ToRetValue; |
| 6180 | const VarDecl *ToNRVOCandidate; |
| 6181 | std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp; |
| 6182 | |
| Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 6183 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, |
| 6184 | ToNRVOCandidate); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6185 | } |
| 6186 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6187 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 6188 | auto Imp = importSeq( |
| 6189 | S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock()); |
| 6190 | if (!Imp) |
| 6191 | return Imp.takeError(); |
| 6192 | |
| 6193 | SourceLocation ToCatchLoc; |
| 6194 | VarDecl *ToExceptionDecl; |
| 6195 | Stmt *ToHandlerBlock; |
| 6196 | std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp; |
| 6197 | |
| 6198 | return new (Importer.getToContext()) CXXCatchStmt ( |
| 6199 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6200 | } |
| 6201 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6202 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 6203 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); |
| 6204 | if (!ToTryLocOrErr) |
| 6205 | return ToTryLocOrErr.takeError(); |
| 6206 | |
| 6207 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); |
| 6208 | if (!ToTryBlockOrErr) |
| 6209 | return ToTryBlockOrErr.takeError(); |
| 6210 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6211 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 6212 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 6213 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6214 | if (auto ToHandlerOrErr = import(FromHandler)) |
| 6215 | ToHandlers[HI] = *ToHandlerOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6216 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6217 | return ToHandlerOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6218 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6219 | |
| 6220 | return CXXTryStmt::Create( |
| 6221 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6222 | } |
| 6223 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6224 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| 6225 | auto Imp1 = importSeq( |
| 6226 | S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(), |
| 6227 | S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody()); |
| 6228 | if (!Imp1) |
| 6229 | return Imp1.takeError(); |
| 6230 | auto Imp2 = importSeq( |
| 6231 | S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc()); |
| 6232 | if (!Imp2) |
| 6233 | return Imp2.takeError(); |
| 6234 | |
| 6235 | DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt; |
| 6236 | Expr *ToCond, *ToInc; |
| 6237 | Stmt *ToInit, *ToBody; |
| 6238 | std::tie( |
| 6239 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 6240 | ToBody) = *Imp1; |
| 6241 | SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc; |
| 6242 | std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2; |
| 6243 | |
| 6244 | return new (Importer.getToContext()) CXXForRangeStmt( |
| 6245 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 6246 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6247 | } |
| 6248 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6249 | ExpectedStmt |
| 6250 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 6251 | auto Imp = importSeq( |
| 6252 | S->getElement(), S->getCollection(), S->getBody(), |
| 6253 | S->getForLoc(), S->getRParenLoc()); |
| 6254 | if (!Imp) |
| 6255 | return Imp.takeError(); |
| 6256 | |
| 6257 | Stmt *ToElement, *ToBody; |
| 6258 | Expr *ToCollection; |
| 6259 | SourceLocation ToForLoc, ToRParenLoc; |
| 6260 | std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp; |
| 6261 | |
| 6262 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, |
| 6263 | ToCollection, |
| 6264 | ToBody, |
| 6265 | ToForLoc, |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6266 | ToRParenLoc); |
| 6267 | } |
| 6268 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6269 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 6270 | auto Imp = importSeq( |
| 6271 | S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(), |
| 6272 | S->getCatchBody()); |
| 6273 | if (!Imp) |
| 6274 | return Imp.takeError(); |
| 6275 | |
| 6276 | SourceLocation ToAtCatchLoc, ToRParenLoc; |
| 6277 | VarDecl *ToCatchParamDecl; |
| 6278 | Stmt *ToCatchBody; |
| 6279 | std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp; |
| 6280 | |
| 6281 | return new (Importer.getToContext()) ObjCAtCatchStmt ( |
| 6282 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6283 | } |
| 6284 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6285 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 6286 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); |
| 6287 | if (!ToAtFinallyLocOrErr) |
| 6288 | return ToAtFinallyLocOrErr.takeError(); |
| 6289 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); |
| 6290 | if (!ToAtFinallyStmtOrErr) |
| 6291 | return ToAtFinallyStmtOrErr.takeError(); |
| 6292 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, |
| 6293 | *ToAtFinallyStmtOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6294 | } |
| 6295 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6296 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 6297 | auto Imp = importSeq( |
| 6298 | S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt()); |
| 6299 | if (!Imp) |
| 6300 | return Imp.takeError(); |
| 6301 | |
| 6302 | SourceLocation ToAtTryLoc; |
| 6303 | Stmt *ToTryBody, *ToFinallyStmt; |
| 6304 | std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp; |
| 6305 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6306 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 6307 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 6308 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6309 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) |
| 6310 | ToCatchStmts[CI] = *ToCatchStmtOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6311 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6312 | return ToCatchStmtOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6313 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6314 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6315 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6316 | ToAtTryLoc, ToTryBody, |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6317 | ToCatchStmts.begin(), ToCatchStmts.size(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6318 | ToFinallyStmt); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6319 | } |
| 6320 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6321 | ExpectedStmt ASTNodeImporter::VisitObjCAtSynchronizedStmt |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6322 | (ObjCAtSynchronizedStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6323 | auto Imp = importSeq( |
| 6324 | S->getAtSynchronizedLoc(), S->getSynchExpr(), S->getSynchBody()); |
| 6325 | if (!Imp) |
| 6326 | return Imp.takeError(); |
| 6327 | |
| 6328 | SourceLocation ToAtSynchronizedLoc; |
| 6329 | Expr *ToSynchExpr; |
| 6330 | Stmt *ToSynchBody; |
| 6331 | std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp; |
| 6332 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6333 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 6334 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 6335 | } |
| 6336 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6337 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 6338 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); |
| 6339 | if (!ToThrowLocOrErr) |
| 6340 | return ToThrowLocOrErr.takeError(); |
| 6341 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); |
| 6342 | if (!ToThrowExprOrErr) |
| 6343 | return ToThrowExprOrErr.takeError(); |
| 6344 | return new (Importer.getToContext()) ObjCAtThrowStmt( |
| 6345 | *ToThrowLocOrErr, *ToThrowExprOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6346 | } |
| 6347 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6348 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( |
| 6349 | ObjCAutoreleasePoolStmt *S) { |
| 6350 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); |
| 6351 | if (!ToAtLocOrErr) |
| 6352 | return ToAtLocOrErr.takeError(); |
| 6353 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 6354 | if (!ToSubStmtOrErr) |
| 6355 | return ToSubStmtOrErr.takeError(); |
| 6356 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, |
| 6357 | *ToSubStmtOrErr); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6358 | } |
| 6359 | |
| 6360 | //---------------------------------------------------------------------------- |
| 6361 | // Import Expressions |
| 6362 | //---------------------------------------------------------------------------- |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6363 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6364 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) |
| 6365 | << E->getStmtClassName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6366 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6367 | } |
| 6368 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6369 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 6370 | auto Imp = importSeq( |
| 6371 | E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(), |
| 6372 | E->getRParenLoc(), E->getType()); |
| 6373 | if (!Imp) |
| 6374 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6375 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6376 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6377 | Expr *ToSubExpr; |
| 6378 | TypeSourceInfo *ToWrittenTypeInfo; |
| 6379 | QualType ToType; |
| 6380 | std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) = |
| 6381 | *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6382 | |
| 6383 | return new (Importer.getToContext()) VAArgExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6384 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, |
| 6385 | E->isMicrosoftABI()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6386 | } |
| 6387 | |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6388 | ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) { |
| 6389 | auto Imp = importSeq(E->getCond(), E->getLHS(), E->getRHS(), |
| 6390 | E->getBuiltinLoc(), E->getRParenLoc(), E->getType()); |
| 6391 | if (!Imp) |
| 6392 | return Imp.takeError(); |
| 6393 | |
| 6394 | Expr *ToCond; |
| 6395 | Expr *ToLHS; |
| 6396 | Expr *ToRHS; |
| 6397 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6398 | QualType ToType; |
| 6399 | std::tie(ToCond, ToLHS, ToRHS, ToBuiltinLoc, ToRParenLoc, ToType) = *Imp; |
| 6400 | |
| 6401 | ExprValueKind VK = E->getValueKind(); |
| 6402 | ExprObjectKind OK = E->getObjectKind(); |
| 6403 | |
| 6404 | bool TypeDependent = ToCond->isTypeDependent(); |
| 6405 | bool ValueDependent = ToCond->isValueDependent(); |
| 6406 | |
| 6407 | // The value of CondIsTrue only matters if the value is not |
| 6408 | // condition-dependent. |
| 6409 | bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue(); |
| 6410 | |
| 6411 | return new (Importer.getToContext()) |
| 6412 | ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK, |
| 6413 | ToRParenLoc, CondIsTrue, TypeDependent, ValueDependent); |
| 6414 | } |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6415 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6416 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 6417 | ExpectedType TypeOrErr = import(E->getType()); |
| 6418 | if (!TypeOrErr) |
| 6419 | return TypeOrErr.takeError(); |
| 6420 | |
| 6421 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); |
| 6422 | if (!BeginLocOrErr) |
| 6423 | return BeginLocOrErr.takeError(); |
| 6424 | |
| 6425 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6426 | } |
| 6427 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6428 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 6429 | auto Imp = importSeq( |
| 6430 | E->getBeginLoc(), E->getType(), E->getFunctionName()); |
| 6431 | if (!Imp) |
| 6432 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6433 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6434 | SourceLocation ToBeginLoc; |
| 6435 | QualType ToType; |
| 6436 | StringLiteral *ToFunctionName; |
| 6437 | std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6438 | |
| Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 6439 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, |
| 6440 | E->getIdentKind(), ToFunctionName); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6441 | } |
| 6442 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6443 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
| 6444 | auto Imp = importSeq( |
| 6445 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDecl(), |
| 6446 | E->getLocation(), E->getType()); |
| 6447 | if (!Imp) |
| 6448 | return Imp.takeError(); |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6449 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6450 | NestedNameSpecifierLoc ToQualifierLoc; |
| 6451 | SourceLocation ToTemplateKeywordLoc, ToLocation; |
| 6452 | ValueDecl *ToDecl; |
| 6453 | QualType ToType; |
| 6454 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) = |
| 6455 | *Imp; |
| 6456 | |
| 6457 | NamedDecl *ToFoundD = nullptr; |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6458 | if (E->getDecl() != E->getFoundDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6459 | auto FoundDOrErr = import(E->getFoundDecl()); |
| 6460 | if (!FoundDOrErr) |
| 6461 | return FoundDOrErr.takeError(); |
| 6462 | ToFoundD = *FoundDOrErr; |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6463 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6464 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6465 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6466 | TemplateArgumentListInfo *ToResInfo = nullptr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6467 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6468 | if (Error Err = |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 6469 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6470 | E->template_arguments(), ToTAInfo)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6471 | return std::move(Err); |
| 6472 | ToResInfo = &ToTAInfo; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6473 | } |
| 6474 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6475 | auto *ToE = DeclRefExpr::Create( |
| 6476 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, |
| 6477 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, |
| Richard Smith | 715f7a1 | 2019-06-11 17:50:32 +0000 | [diff] [blame] | 6478 | E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse()); |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 6479 | if (E->hadMultipleCandidates()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6480 | ToE->setHadMultipleCandidates(true); |
| 6481 | return ToE; |
| Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 6482 | } |
| 6483 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6484 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 6485 | ExpectedType TypeOrErr = import(E->getType()); |
| 6486 | if (!TypeOrErr) |
| 6487 | return TypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6488 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6489 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6490 | } |
| 6491 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6492 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 6493 | ExpectedExpr ToInitOrErr = import(E->getInit()); |
| 6494 | if (!ToInitOrErr) |
| 6495 | return ToInitOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6496 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6497 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); |
| 6498 | if (!ToEqualOrColonLocOrErr) |
| 6499 | return ToEqualOrColonLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6500 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6501 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6502 | // List elements from the second, the first is Init itself |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6503 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { |
| 6504 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) |
| 6505 | ToIndexExprs[I - 1] = *ToArgOrErr; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6506 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6507 | return ToArgOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6508 | } |
| 6509 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6510 | SmallVector<Designator, 4> ToDesignators(E->size()); |
| 6511 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) |
| 6512 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6513 | |
| 6514 | return DesignatedInitExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6515 | Importer.getToContext(), ToDesignators, |
| 6516 | ToIndexExprs, *ToEqualOrColonLocOrErr, |
| 6517 | E->usesGNUSyntax(), *ToInitOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6518 | } |
| 6519 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6520 | ExpectedStmt |
| 6521 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 6522 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6523 | if (!ToTypeOrErr) |
| 6524 | return ToTypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6525 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6526 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6527 | if (!ToLocationOrErr) |
| 6528 | return ToLocationOrErr.takeError(); |
| 6529 | |
| 6530 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( |
| 6531 | *ToTypeOrErr, *ToLocationOrErr); |
| 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::VisitIntegerLiteral(IntegerLiteral *E) { |
| 6535 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6536 | if (!ToTypeOrErr) |
| 6537 | return ToTypeOrErr.takeError(); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6538 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6539 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6540 | if (!ToLocationOrErr) |
| 6541 | return ToLocationOrErr.takeError(); |
| 6542 | |
| 6543 | return IntegerLiteral::Create( |
| 6544 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6545 | } |
| 6546 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6547 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6548 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 6549 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6550 | if (!ToTypeOrErr) |
| 6551 | return ToTypeOrErr.takeError(); |
| 6552 | |
| 6553 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6554 | if (!ToLocationOrErr) |
| 6555 | return ToLocationOrErr.takeError(); |
| 6556 | |
| 6557 | return FloatingLiteral::Create( |
| 6558 | Importer.getToContext(), E->getValue(), E->isExact(), |
| 6559 | *ToTypeOrErr, *ToLocationOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6560 | } |
| 6561 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6562 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 6563 | auto ToTypeOrErr = import(E->getType()); |
| 6564 | if (!ToTypeOrErr) |
| 6565 | return ToTypeOrErr.takeError(); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6566 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6567 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6568 | if (!ToSubExprOrErr) |
| 6569 | return ToSubExprOrErr.takeError(); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6570 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6571 | return new (Importer.getToContext()) ImaginaryLiteral( |
| 6572 | *ToSubExprOrErr, *ToTypeOrErr); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6573 | } |
| 6574 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6575 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 6576 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6577 | if (!ToTypeOrErr) |
| 6578 | return ToTypeOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6579 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6580 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6581 | if (!ToLocationOrErr) |
| 6582 | return ToLocationOrErr.takeError(); |
| 6583 | |
| 6584 | return new (Importer.getToContext()) CharacterLiteral( |
| 6585 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); |
| Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 6586 | } |
| 6587 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6588 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 6589 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6590 | if (!ToTypeOrErr) |
| 6591 | return ToTypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6592 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6593 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); |
| 6594 | if (Error Err = ImportArrayChecked( |
| 6595 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) |
| 6596 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6597 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6598 | return StringLiteral::Create( |
| 6599 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), |
| 6600 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6601 | } |
| 6602 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6603 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 6604 | auto Imp = importSeq( |
| 6605 | E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(), |
| 6606 | E->getInitializer()); |
| 6607 | if (!Imp) |
| 6608 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6609 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6610 | SourceLocation ToLParenLoc; |
| 6611 | TypeSourceInfo *ToTypeSourceInfo; |
| 6612 | QualType ToType; |
| 6613 | Expr *ToInitializer; |
| 6614 | std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6615 | |
| 6616 | return new (Importer.getToContext()) CompoundLiteralExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6617 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), |
| 6618 | ToInitializer, E->isFileScope()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6619 | } |
| 6620 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6621 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 6622 | auto Imp = importSeq( |
| 6623 | E->getBuiltinLoc(), E->getType(), E->getRParenLoc()); |
| 6624 | if (!Imp) |
| 6625 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6626 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6627 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6628 | QualType ToType; |
| 6629 | std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp; |
| 6630 | |
| 6631 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); |
| 6632 | if (Error Err = ImportArrayChecked( |
| 6633 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 6634 | ToExprs.begin())) |
| 6635 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6636 | |
| 6637 | return new (Importer.getToContext()) AtomicExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6638 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6639 | } |
| 6640 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6641 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 6642 | auto Imp = importSeq( |
| 6643 | E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType()); |
| 6644 | if (!Imp) |
| 6645 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6646 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6647 | SourceLocation ToAmpAmpLoc, ToLabelLoc; |
| 6648 | LabelDecl *ToLabel; |
| 6649 | QualType ToType; |
| 6650 | std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6651 | |
| 6652 | return new (Importer.getToContext()) AddrLabelExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6653 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6654 | } |
| 6655 | |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6656 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { |
| 6657 | auto Imp = importSeq(E->getSubExpr()); |
| 6658 | if (!Imp) |
| 6659 | return Imp.takeError(); |
| 6660 | |
| 6661 | Expr *ToSubExpr; |
| 6662 | std::tie(ToSubExpr) = *Imp; |
| 6663 | |
| Gauthier Harnisch | 83c7b61 | 2019-06-15 10:24:47 +0000 | [diff] [blame] | 6664 | // TODO : Handle APValue::ValueKind that require importing. |
| 6665 | APValue::ValueKind Kind = E->getResultAPValueKind(); |
| 6666 | if (Kind == APValue::Int || Kind == APValue::Float || |
| 6667 | Kind == APValue::FixedPoint || Kind == APValue::ComplexFloat || |
| 6668 | Kind == APValue::ComplexInt) |
| 6669 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, |
| 6670 | E->getAPValueResult()); |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 6671 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr); |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6672 | } |
| 6673 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6674 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 6675 | auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr()); |
| 6676 | if (!Imp) |
| 6677 | return Imp.takeError(); |
| 6678 | |
| 6679 | SourceLocation ToLParen, ToRParen; |
| 6680 | Expr *ToSubExpr; |
| 6681 | std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6682 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6683 | return new (Importer.getToContext()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6684 | ParenExpr(ToLParen, ToRParen, ToSubExpr); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6685 | } |
| 6686 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6687 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 6688 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); |
| 6689 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) |
| 6690 | return std::move(Err); |
| 6691 | |
| 6692 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); |
| 6693 | if (!ToLParenLocOrErr) |
| 6694 | return ToLParenLocOrErr.takeError(); |
| 6695 | |
| 6696 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); |
| 6697 | if (!ToRParenLocOrErr) |
| 6698 | return ToRParenLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6699 | |
| Bruno Ricci | f49e1ca | 2018-11-20 16:20:40 +0000 | [diff] [blame] | 6700 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, |
| 6701 | ToExprs, *ToRParenLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6702 | } |
| 6703 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6704 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 6705 | auto Imp = importSeq( |
| 6706 | E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc()); |
| 6707 | if (!Imp) |
| 6708 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6709 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6710 | CompoundStmt *ToSubStmt; |
| 6711 | QualType ToType; |
| 6712 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 6713 | std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6714 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6715 | return new (Importer.getToContext()) StmtExpr( |
| 6716 | ToSubStmt, ToType, ToLParenLoc, ToRParenLoc); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6717 | } |
| 6718 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6719 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 6720 | auto Imp = importSeq( |
| 6721 | E->getSubExpr(), E->getType(), E->getOperatorLoc()); |
| 6722 | if (!Imp) |
| 6723 | return Imp.takeError(); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6724 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6725 | Expr *ToSubExpr; |
| 6726 | QualType ToType; |
| 6727 | SourceLocation ToOperatorLoc; |
| 6728 | std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6729 | |
| Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6730 | return new (Importer.getToContext()) UnaryOperator( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6731 | ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), |
| 6732 | ToOperatorLoc, E->canOverflow()); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6733 | } |
| 6734 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6735 | ExpectedStmt |
| Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6736 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6737 | auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc()); |
| 6738 | if (!Imp) |
| 6739 | return Imp.takeError(); |
| 6740 | |
| 6741 | QualType ToType; |
| 6742 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6743 | std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6744 | |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6745 | if (E->isArgumentType()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6746 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = |
| 6747 | import(E->getArgumentTypeInfo()); |
| 6748 | if (!ToArgumentTypeInfoOrErr) |
| 6749 | return ToArgumentTypeInfoOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6750 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6751 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6752 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, |
| 6753 | ToRParenLoc); |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6754 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6755 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6756 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); |
| 6757 | if (!ToArgumentExprOrErr) |
| 6758 | return ToArgumentExprOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6759 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6760 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6761 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6762 | } |
| 6763 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6764 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 6765 | auto Imp = importSeq( |
| 6766 | E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc()); |
| 6767 | if (!Imp) |
| 6768 | return Imp.takeError(); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6769 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6770 | Expr *ToLHS, *ToRHS; |
| 6771 | QualType ToType; |
| 6772 | SourceLocation ToOperatorLoc; |
| 6773 | std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6774 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6775 | return new (Importer.getToContext()) BinaryOperator( |
| 6776 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6777 | E->getObjectKind(), ToOperatorLoc, E->getFPFeatures()); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6778 | } |
| 6779 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6780 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 6781 | auto Imp = importSeq( |
| 6782 | E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(), |
| 6783 | E->getRHS(), E->getType()); |
| 6784 | if (!Imp) |
| 6785 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6786 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6787 | Expr *ToCond, *ToLHS, *ToRHS; |
| 6788 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6789 | QualType ToType; |
| 6790 | std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6791 | |
| 6792 | return new (Importer.getToContext()) ConditionalOperator( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6793 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, |
| 6794 | E->getValueKind(), E->getObjectKind()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6795 | } |
| 6796 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6797 | ExpectedStmt ASTNodeImporter::VisitBinaryConditionalOperator( |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6798 | BinaryConditionalOperator *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6799 | auto Imp = importSeq( |
| 6800 | E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(), |
| 6801 | E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType()); |
| 6802 | if (!Imp) |
| 6803 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6804 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6805 | Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr; |
| 6806 | OpaqueValueExpr *ToOpaqueValue; |
| 6807 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6808 | QualType ToType; |
| 6809 | std::tie( |
| 6810 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc, |
| 6811 | ToColonLoc, ToType) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6812 | |
| 6813 | return new (Importer.getToContext()) BinaryConditionalOperator( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6814 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, |
| 6815 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), |
| 6816 | E->getObjectKind()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6817 | } |
| 6818 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6819 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 6820 | auto Imp = importSeq( |
| 6821 | E->getBeginLoc(), E->getQueriedTypeSourceInfo(), |
| 6822 | E->getDimensionExpression(), E->getEndLoc(), E->getType()); |
| 6823 | if (!Imp) |
| 6824 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6825 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6826 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6827 | TypeSourceInfo *ToQueriedTypeSourceInfo; |
| 6828 | Expr *ToDimensionExpression; |
| 6829 | QualType ToType; |
| 6830 | std::tie( |
| 6831 | ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc, |
| 6832 | ToType) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6833 | |
| 6834 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6835 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), |
| 6836 | ToDimensionExpression, ToEndLoc, ToType); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6837 | } |
| 6838 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6839 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 6840 | auto Imp = importSeq( |
| 6841 | E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType()); |
| 6842 | if (!Imp) |
| 6843 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6844 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6845 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6846 | Expr *ToQueriedExpression; |
| 6847 | QualType ToType; |
| 6848 | std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6849 | |
| 6850 | return new (Importer.getToContext()) ExpressionTraitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6851 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), |
| 6852 | ToEndLoc, ToType); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6853 | } |
| 6854 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6855 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6856 | auto Imp = importSeq( |
| 6857 | E->getLocation(), E->getType(), E->getSourceExpr()); |
| 6858 | if (!Imp) |
| 6859 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6860 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6861 | SourceLocation ToLocation; |
| 6862 | QualType ToType; |
| 6863 | Expr *ToSourceExpr; |
| 6864 | std::tie(ToLocation, ToType, ToSourceExpr) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6865 | |
| 6866 | return new (Importer.getToContext()) OpaqueValueExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6867 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6868 | } |
| 6869 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6870 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 6871 | auto Imp = importSeq( |
| 6872 | E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc()); |
| 6873 | if (!Imp) |
| 6874 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6875 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6876 | Expr *ToLHS, *ToRHS; |
| 6877 | SourceLocation ToRBracketLoc; |
| 6878 | QualType ToType; |
| 6879 | std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6880 | |
| 6881 | return new (Importer.getToContext()) ArraySubscriptExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6882 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), |
| 6883 | ToRBracketLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6884 | } |
| 6885 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6886 | ExpectedStmt |
| 6887 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 6888 | auto Imp = importSeq( |
| 6889 | E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(), |
| 6890 | E->getComputationResultType(), E->getOperatorLoc()); |
| 6891 | if (!Imp) |
| 6892 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6893 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6894 | Expr *ToLHS, *ToRHS; |
| 6895 | QualType ToType, ToComputationLHSType, ToComputationResultType; |
| 6896 | SourceLocation ToOperatorLoc; |
| 6897 | std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType, |
| 6898 | ToOperatorLoc) = *Imp; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6899 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6900 | return new (Importer.getToContext()) CompoundAssignOperator( |
| 6901 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6902 | E->getObjectKind(), ToComputationLHSType, ToComputationResultType, |
| 6903 | ToOperatorLoc, E->getFPFeatures()); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6904 | } |
| 6905 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6906 | Expected<CXXCastPath> |
| 6907 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { |
| 6908 | CXXCastPath Path; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6909 | 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] | 6910 | if (auto SpecOrErr = import(*I)) |
| 6911 | Path.push_back(*SpecOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6912 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6913 | return SpecOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6914 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6915 | return Path; |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6916 | } |
| 6917 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6918 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 6919 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6920 | if (!ToTypeOrErr) |
| 6921 | return ToTypeOrErr.takeError(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6922 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6923 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6924 | if (!ToSubExprOrErr) |
| 6925 | return ToSubExprOrErr.takeError(); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6926 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6927 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6928 | if (!ToBasePathOrErr) |
| 6929 | return ToBasePathOrErr.takeError(); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6930 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6931 | return ImplicitCastExpr::Create( |
| 6932 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, |
| 6933 | &(*ToBasePathOrErr), E->getValueKind()); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6934 | } |
| 6935 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6936 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 6937 | auto Imp1 = importSeq( |
| 6938 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten()); |
| 6939 | if (!Imp1) |
| 6940 | return Imp1.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6941 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6942 | QualType ToType; |
| 6943 | Expr *ToSubExpr; |
| 6944 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 6945 | std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1; |
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6946 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6947 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6948 | if (!ToBasePathOrErr) |
| 6949 | return ToBasePathOrErr.takeError(); |
| 6950 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6951 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6952 | switch (E->getStmtClass()) { |
| 6953 | case Stmt::CStyleCastExprClass: { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6954 | auto *CCE = cast<CStyleCastExpr>(E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6955 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); |
| 6956 | if (!ToLParenLocOrErr) |
| 6957 | return ToLParenLocOrErr.takeError(); |
| 6958 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); |
| 6959 | if (!ToRParenLocOrErr) |
| 6960 | return ToRParenLocOrErr.takeError(); |
| 6961 | return CStyleCastExpr::Create( |
| 6962 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), |
| 6963 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, |
| 6964 | *ToRParenLocOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6965 | } |
| 6966 | |
| 6967 | case Stmt::CXXFunctionalCastExprClass: { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6968 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6969 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); |
| 6970 | if (!ToLParenLocOrErr) |
| 6971 | return ToLParenLocOrErr.takeError(); |
| 6972 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); |
| 6973 | if (!ToRParenLocOrErr) |
| 6974 | return ToRParenLocOrErr.takeError(); |
| 6975 | return CXXFunctionalCastExpr::Create( |
| 6976 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, |
| 6977 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, |
| 6978 | *ToRParenLocOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6979 | } |
| 6980 | |
| 6981 | case Stmt::ObjCBridgedCastExprClass: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6982 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
| 6983 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); |
| 6984 | if (!ToLParenLocOrErr) |
| 6985 | return ToLParenLocOrErr.takeError(); |
| 6986 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); |
| 6987 | if (!ToBridgeKeywordLocOrErr) |
| 6988 | return ToBridgeKeywordLocOrErr.takeError(); |
| 6989 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 6990 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), |
| 6991 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6992 | } |
| 6993 | default: |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6994 | llvm_unreachable("Cast expression of unsupported type!"); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6995 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6996 | } |
| 6997 | } |
| 6998 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6999 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { |
| 7000 | SmallVector<OffsetOfNode, 4> ToNodes; |
| 7001 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { |
| 7002 | const OffsetOfNode &FromNode = E->getComponent(I); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7003 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7004 | SourceLocation ToBeginLoc, ToEndLoc; |
| 7005 | if (FromNode.getKind() != OffsetOfNode::Base) { |
| 7006 | auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc()); |
| 7007 | if (!Imp) |
| 7008 | return Imp.takeError(); |
| 7009 | std::tie(ToBeginLoc, ToEndLoc) = *Imp; |
| 7010 | } |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7011 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7012 | switch (FromNode.getKind()) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7013 | case OffsetOfNode::Array: |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7014 | ToNodes.push_back( |
| 7015 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7016 | break; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7017 | case OffsetOfNode::Base: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7018 | auto ToBSOrErr = import(FromNode.getBase()); |
| 7019 | if (!ToBSOrErr) |
| 7020 | return ToBSOrErr.takeError(); |
| 7021 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7022 | break; |
| 7023 | } |
| 7024 | case OffsetOfNode::Field: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7025 | auto ToFieldOrErr = import(FromNode.getField()); |
| 7026 | if (!ToFieldOrErr) |
| 7027 | return ToFieldOrErr.takeError(); |
| 7028 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7029 | break; |
| 7030 | } |
| 7031 | case OffsetOfNode::Identifier: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7032 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); |
| 7033 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7034 | break; |
| 7035 | } |
| 7036 | } |
| 7037 | } |
| 7038 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7039 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); |
| 7040 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { |
| 7041 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); |
| 7042 | if (!ToIndexExprOrErr) |
| 7043 | return ToIndexExprOrErr.takeError(); |
| 7044 | ToExprs[I] = *ToIndexExprOrErr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7045 | } |
| 7046 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7047 | auto Imp = importSeq( |
| 7048 | E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(), |
| 7049 | E->getRParenLoc()); |
| 7050 | if (!Imp) |
| 7051 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7052 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7053 | QualType ToType; |
| 7054 | TypeSourceInfo *ToTypeSourceInfo; |
| 7055 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 7056 | std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp; |
| 7057 | |
| 7058 | return OffsetOfExpr::Create( |
| 7059 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, |
| 7060 | ToExprs, ToRParenLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7061 | } |
| 7062 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7063 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 7064 | auto Imp = importSeq( |
| 7065 | E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc()); |
| 7066 | if (!Imp) |
| 7067 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7068 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7069 | QualType ToType; |
| 7070 | Expr *ToOperand; |
| 7071 | SourceLocation ToBeginLoc, ToEndLoc; |
| 7072 | std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7073 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7074 | CanThrowResult ToCanThrow; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7075 | if (E->isValueDependent()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7076 | ToCanThrow = CT_Dependent; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7077 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7078 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7079 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7080 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 7081 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7082 | } |
| 7083 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7084 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 7085 | auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc()); |
| 7086 | if (!Imp) |
| 7087 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7088 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7089 | Expr *ToSubExpr; |
| 7090 | QualType ToType; |
| 7091 | SourceLocation ToThrowLoc; |
| 7092 | std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7093 | |
| 7094 | return new (Importer.getToContext()) CXXThrowExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7095 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7096 | } |
| 7097 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7098 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 7099 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); |
| 7100 | if (!ToUsedLocOrErr) |
| 7101 | return ToUsedLocOrErr.takeError(); |
| 7102 | |
| 7103 | auto ToParamOrErr = import(E->getParam()); |
| 7104 | if (!ToParamOrErr) |
| 7105 | return ToParamOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7106 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7107 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); |
| 7108 | if (!UsedContextOrErr) |
| 7109 | return UsedContextOrErr.takeError(); |
| 7110 | |
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 7111 | // Import the default arg if it was not imported yet. |
| 7112 | // This is needed because it can happen that during the import of the |
| 7113 | // default expression (from VisitParmVarDecl) the same ParmVarDecl is |
| 7114 | // encountered here. The default argument for a ParmVarDecl is set in the |
| 7115 | // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here, |
| 7116 | // see VisitParmVarDecl). |
| 7117 | ParmVarDecl *ToParam = *ToParamOrErr; |
| 7118 | if (!ToParam->getDefaultArg()) { |
| 7119 | Optional<ParmVarDecl *> FromParam = Importer.getImportedFromDecl(ToParam); |
| 7120 | assert(FromParam && "ParmVarDecl was not imported?"); |
| 7121 | |
| 7122 | if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam)) |
| 7123 | return std::move(Err); |
| 7124 | } |
| 7125 | |
| 7126 | return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr, |
| 7127 | *ToParamOrErr, *UsedContextOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7128 | } |
| 7129 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7130 | ExpectedStmt |
| 7131 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 7132 | auto Imp = importSeq( |
| 7133 | E->getType(), E->getTypeSourceInfo(), E->getRParenLoc()); |
| 7134 | if (!Imp) |
| 7135 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7136 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7137 | QualType ToType; |
| 7138 | TypeSourceInfo *ToTypeSourceInfo; |
| 7139 | SourceLocation ToRParenLoc; |
| 7140 | std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7141 | |
| 7142 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7143 | ToType, ToTypeSourceInfo, ToRParenLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7144 | } |
| 7145 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7146 | ExpectedStmt |
| 7147 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 7148 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7149 | if (!ToSubExprOrErr) |
| 7150 | return ToSubExprOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7151 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7152 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); |
| 7153 | if (!ToDtorOrErr) |
| 7154 | return ToDtorOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7155 | |
| 7156 | ASTContext &ToCtx = Importer.getToContext(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7157 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); |
| 7158 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7159 | } |
| 7160 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7161 | ExpectedStmt |
| 7162 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { |
| 7163 | auto Imp = importSeq( |
| 7164 | E->getConstructor(), E->getType(), E->getTypeSourceInfo(), |
| 7165 | E->getParenOrBraceRange()); |
| 7166 | if (!Imp) |
| 7167 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7168 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7169 | CXXConstructorDecl *ToConstructor; |
| 7170 | QualType ToType; |
| 7171 | TypeSourceInfo *ToTypeSourceInfo; |
| 7172 | SourceRange ToParenOrBraceRange; |
| 7173 | std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7174 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7175 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); |
| 7176 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7177 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7178 | |
| Bruno Ricci | ddb8f6b | 2018-12-22 14:39:30 +0000 | [diff] [blame] | 7179 | return CXXTemporaryObjectExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7180 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, |
| 7181 | ToParenOrBraceRange, E->hadMultipleCandidates(), |
| 7182 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 7183 | E->requiresZeroInitialization()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7184 | } |
| 7185 | |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7186 | ExpectedDecl ASTNodeImporter::VisitLifetimeExtendedTemporaryDecl( |
| 7187 | LifetimeExtendedTemporaryDecl *D) { |
| 7188 | DeclContext *DC, *LexicalDC; |
| 7189 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 7190 | return std::move(Err); |
| 7191 | |
| 7192 | auto Imp = importSeq(D->getTemporaryExpr(), D->getExtendingDecl()); |
| 7193 | // FIXME: the APValue should be imported as well if present. |
| 7194 | if (!Imp) |
| 7195 | return Imp.takeError(); |
| 7196 | |
| 7197 | Expr *Temporary; |
| 7198 | ValueDecl *ExtendingDecl; |
| 7199 | std::tie(Temporary, ExtendingDecl) = *Imp; |
| 7200 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
| 7201 | |
| 7202 | LifetimeExtendedTemporaryDecl *To; |
| 7203 | if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl, |
| 7204 | D->getManglingNumber())) |
| 7205 | return To; |
| 7206 | |
| 7207 | To->setLexicalDeclContext(LexicalDC); |
| 7208 | LexicalDC->addDeclInternal(To); |
| 7209 | return To; |
| 7210 | } |
| 7211 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7212 | ExpectedStmt |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7213 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7214 | auto Imp = importSeq(E->getType(), |
| 7215 | E->getLifetimeExtendedTemporaryDecl() ? nullptr |
| 7216 | : E->getSubExpr(), |
| 7217 | E->getLifetimeExtendedTemporaryDecl()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7218 | if (!Imp) |
| 7219 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7220 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7221 | QualType ToType; |
| 7222 | Expr *ToTemporaryExpr; |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7223 | LifetimeExtendedTemporaryDecl *ToMaterializedDecl; |
| 7224 | std::tie(ToType, ToTemporaryExpr, ToMaterializedDecl) = *Imp; |
| 7225 | if (!ToTemporaryExpr) |
| 7226 | ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7227 | |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7228 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
| 7229 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference(), |
| 7230 | ToMaterializedDecl); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7231 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7232 | return ToMTE; |
| 7233 | } |
| 7234 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7235 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 7236 | auto Imp = importSeq( |
| 7237 | E->getType(), E->getPattern(), E->getEllipsisLoc()); |
| 7238 | if (!Imp) |
| 7239 | return Imp.takeError(); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7240 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7241 | QualType ToType; |
| 7242 | Expr *ToPattern; |
| 7243 | SourceLocation ToEllipsisLoc; |
| 7244 | std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7245 | |
| 7246 | return new (Importer.getToContext()) PackExpansionExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7247 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7248 | } |
| 7249 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7250 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 7251 | auto Imp = importSeq( |
| 7252 | E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc()); |
| 7253 | if (!Imp) |
| 7254 | return Imp.takeError(); |
| 7255 | |
| 7256 | SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc; |
| 7257 | NamedDecl *ToPack; |
| 7258 | std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7259 | |
| 7260 | Optional<unsigned> Length; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7261 | if (!E->isValueDependent()) |
| 7262 | Length = E->getPackLength(); |
| 7263 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7264 | SmallVector<TemplateArgument, 8> ToPartialArguments; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7265 | if (E->isPartiallySubstituted()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7266 | if (Error Err = ImportTemplateArguments( |
| 7267 | E->getPartialArguments().data(), |
| 7268 | E->getPartialArguments().size(), |
| 7269 | ToPartialArguments)) |
| 7270 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7271 | } |
| 7272 | |
| 7273 | return SizeOfPackExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7274 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, |
| 7275 | Length, ToPartialArguments); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7276 | } |
| 7277 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7278 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7279 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { |
| 7280 | auto Imp = importSeq( |
| 7281 | E->getOperatorNew(), E->getOperatorDelete(), E->getTypeIdParens(), |
| 7282 | E->getArraySize(), E->getInitializer(), E->getType(), |
| 7283 | E->getAllocatedTypeSourceInfo(), E->getSourceRange(), |
| 7284 | E->getDirectInitRange()); |
| 7285 | if (!Imp) |
| 7286 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7287 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7288 | FunctionDecl *ToOperatorNew, *ToOperatorDelete; |
| 7289 | SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange; |
| Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 7290 | Optional<Expr *> ToArraySize; |
| 7291 | Expr *ToInitializer; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7292 | QualType ToType; |
| 7293 | TypeSourceInfo *ToAllocatedTypeSourceInfo; |
| 7294 | std::tie( |
| 7295 | ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer, |
| 7296 | ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7297 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7298 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); |
| 7299 | if (Error Err = |
| 7300 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) |
| 7301 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7302 | |
| Bruno Ricci | 9b6dfac | 2019-01-07 15:04:45 +0000 | [diff] [blame] | 7303 | return CXXNewExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7304 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, |
| 7305 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), |
| 7306 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), |
| 7307 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, |
| 7308 | ToDirectInitRange); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7309 | } |
| 7310 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7311 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 7312 | auto Imp = importSeq( |
| 7313 | E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc()); |
| 7314 | if (!Imp) |
| 7315 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7316 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7317 | QualType ToType; |
| 7318 | FunctionDecl *ToOperatorDelete; |
| 7319 | Expr *ToArgument; |
| 7320 | SourceLocation ToBeginLoc; |
| 7321 | std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7322 | |
| 7323 | return new (Importer.getToContext()) CXXDeleteExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7324 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), |
| 7325 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, |
| 7326 | ToBeginLoc); |
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 7327 | } |
| 7328 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7329 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 7330 | auto Imp = importSeq( |
| 7331 | E->getType(), E->getLocation(), E->getConstructor(), |
| 7332 | E->getParenOrBraceRange()); |
| 7333 | if (!Imp) |
| 7334 | return Imp.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7335 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7336 | QualType ToType; |
| 7337 | SourceLocation ToLocation; |
| 7338 | CXXConstructorDecl *ToConstructor; |
| 7339 | SourceRange ToParenOrBraceRange; |
| 7340 | std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7341 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7342 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7343 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7344 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7345 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7346 | return CXXConstructExpr::Create( |
| 7347 | Importer.getToContext(), ToType, ToLocation, ToConstructor, |
| 7348 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), |
| 7349 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 7350 | E->requiresZeroInitialization(), E->getConstructionKind(), |
| 7351 | ToParenOrBraceRange); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7352 | } |
| 7353 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7354 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { |
| 7355 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7356 | if (!ToSubExprOrErr) |
| 7357 | return ToSubExprOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7358 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7359 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); |
| 7360 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) |
| 7361 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7362 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7363 | return ExprWithCleanups::Create( |
| 7364 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), |
| 7365 | ToObjects); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7366 | } |
| 7367 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7368 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7369 | auto Imp = importSeq( |
| 7370 | E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7371 | if (!Imp) |
| 7372 | return Imp.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7373 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7374 | Expr *ToCallee; |
| 7375 | QualType ToType; |
| 7376 | SourceLocation ToRParenLoc; |
| 7377 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7378 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7379 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7380 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7381 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7382 | |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7383 | return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, |
| 7384 | ToType, E->getValueKind(), ToRParenLoc); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7385 | } |
| 7386 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7387 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 7388 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7389 | if (!ToTypeOrErr) |
| 7390 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7391 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7392 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7393 | if (!ToLocationOrErr) |
| 7394 | return ToLocationOrErr.takeError(); |
| 7395 | |
| 7396 | return new (Importer.getToContext()) CXXThisExpr( |
| 7397 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7398 | } |
| 7399 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7400 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 7401 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7402 | if (!ToTypeOrErr) |
| 7403 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7404 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7405 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7406 | if (!ToLocationOrErr) |
| 7407 | return ToLocationOrErr.takeError(); |
| 7408 | |
| 7409 | return new (Importer.getToContext()) CXXBoolLiteralExpr( |
| 7410 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7411 | } |
| 7412 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7413 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 7414 | auto Imp1 = importSeq( |
| 7415 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7416 | E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType()); |
| 7417 | if (!Imp1) |
| 7418 | return Imp1.takeError(); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7419 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7420 | Expr *ToBase; |
| 7421 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7422 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7423 | ValueDecl *ToMemberDecl; |
| 7424 | QualType ToType; |
| 7425 | std::tie( |
| 7426 | ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, |
| 7427 | ToType) = *Imp1; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7428 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7429 | auto Imp2 = importSeq( |
| 7430 | E->getFoundDecl().getDecl(), E->getMemberNameInfo().getName(), |
| 7431 | E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7432 | if (!Imp2) |
| 7433 | return Imp2.takeError(); |
| 7434 | NamedDecl *ToDecl; |
| 7435 | DeclarationName ToName; |
| 7436 | SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc; |
| 7437 | std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2; |
| Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 7438 | |
| 7439 | DeclAccessPair ToFoundDecl = |
| 7440 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7441 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7442 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7443 | |
| Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7444 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7445 | if (E->hasExplicitTemplateArgs()) { |
| Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7446 | if (Error Err = |
| 7447 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 7448 | E->template_arguments(), ToTAInfo)) |
| 7449 | return std::move(Err); |
| 7450 | ResInfo = &ToTAInfo; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7451 | } |
| 7452 | |
| Richard Smith | 1bbad59 | 2019-06-11 17:50:36 +0000 | [diff] [blame] | 7453 | return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(), |
| 7454 | ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7455 | ToMemberDecl, ToFoundDecl, ToMemberNameInfo, |
| 7456 | ResInfo, ToType, E->getValueKind(), |
| 7457 | E->getObjectKind(), E->isNonOdrUse()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7458 | } |
| 7459 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7460 | ExpectedStmt |
| 7461 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { |
| 7462 | auto Imp = importSeq( |
| 7463 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7464 | E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc()); |
| 7465 | if (!Imp) |
| 7466 | return Imp.takeError(); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7467 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7468 | Expr *ToBase; |
| 7469 | SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc; |
| 7470 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7471 | TypeSourceInfo *ToScopeTypeInfo; |
| 7472 | std::tie( |
| 7473 | ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, |
| 7474 | ToTildeLoc) = *Imp; |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7475 | |
| 7476 | PseudoDestructorTypeStorage Storage; |
| 7477 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 7478 | IdentifierInfo *ToII = Importer.Import(FromII); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7479 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); |
| 7480 | if (!ToDestroyedTypeLocOrErr) |
| 7481 | return ToDestroyedTypeLocOrErr.takeError(); |
| 7482 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7483 | } else { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7484 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) |
| 7485 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); |
| 7486 | else |
| 7487 | return ToTIOrErr.takeError(); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7488 | } |
| 7489 | |
| 7490 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7491 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7492 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7493 | } |
| 7494 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7495 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7496 | CXXDependentScopeMemberExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7497 | auto Imp = importSeq( |
| 7498 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7499 | E->getTemplateKeywordLoc(), E->getFirstQualifierFoundInScope()); |
| 7500 | if (!Imp) |
| 7501 | return Imp.takeError(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7502 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7503 | QualType ToType; |
| 7504 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7505 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7506 | NamedDecl *ToFirstQualifierFoundInScope; |
| 7507 | std::tie( |
| 7508 | ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7509 | ToFirstQualifierFoundInScope) = *Imp; |
| 7510 | |
| 7511 | Expr *ToBase = nullptr; |
| 7512 | if (!E->isImplicitAccess()) { |
| 7513 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7514 | ToBase = *ToBaseOrErr; |
| 7515 | else |
| 7516 | return ToBaseOrErr.takeError(); |
| 7517 | } |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7518 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7519 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7520 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7521 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7522 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7523 | ToTAInfo)) |
| 7524 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7525 | ResInfo = &ToTAInfo; |
| 7526 | } |
| 7527 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7528 | auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc()); |
| 7529 | if (!ToMemberNameInfoOrErr) |
| 7530 | return ToMemberNameInfoOrErr.takeError(); |
| 7531 | DeclarationNameInfo ToMemberNameInfo( |
| 7532 | std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr)); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7533 | // Import additional name location/type info. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7534 | if (Error Err = ImportDeclarationNameLoc( |
| 7535 | E->getMemberNameInfo(), ToMemberNameInfo)) |
| 7536 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7537 | |
| 7538 | return CXXDependentScopeMemberExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7539 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, |
| 7540 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, |
| 7541 | ToMemberNameInfo, ResInfo); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7542 | } |
| 7543 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7544 | ExpectedStmt |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7545 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7546 | auto Imp = importSeq(E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 7547 | E->getDeclName(), E->getNameInfo().getLoc(), |
| 7548 | E->getLAngleLoc(), E->getRAngleLoc()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7549 | if (!Imp) |
| 7550 | return Imp.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7551 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7552 | NestedNameSpecifierLoc ToQualifierLoc; |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7553 | SourceLocation ToTemplateKeywordLoc, ToNameLoc, ToLAngleLoc, ToRAngleLoc; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7554 | DeclarationName ToDeclName; |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7555 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToNameLoc, |
| 7556 | ToLAngleLoc, ToRAngleLoc) = *Imp; |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7557 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7558 | DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7559 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7560 | return std::move(Err); |
| 7561 | |
| 7562 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7563 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7564 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7565 | if (Error Err = |
| 7566 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7567 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7568 | ResInfo = &ToTAInfo; |
| 7569 | } |
| 7570 | |
| 7571 | return DependentScopeDeclRefExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7572 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, |
| 7573 | ToNameInfo, ResInfo); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7574 | } |
| 7575 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7576 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 7577 | CXXUnresolvedConstructExpr *E) { |
| 7578 | auto Imp = importSeq( |
| 7579 | E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo()); |
| 7580 | if (!Imp) |
| 7581 | return Imp.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7582 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7583 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 7584 | TypeSourceInfo *ToTypeSourceInfo; |
| 7585 | std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp; |
| 7586 | |
| 7587 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); |
| 7588 | if (Error Err = |
| 7589 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) |
| 7590 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7591 | |
| 7592 | return CXXUnresolvedConstructExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7593 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, |
| 7594 | llvm::makeArrayRef(ToArgs), ToRParenLoc); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7595 | } |
| 7596 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7597 | ExpectedStmt |
| 7598 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
| 7599 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); |
| 7600 | if (!ToNamingClassOrErr) |
| 7601 | return ToNamingClassOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7602 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7603 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); |
| 7604 | if (!ToQualifierLocOrErr) |
| 7605 | return ToQualifierLocOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7606 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7607 | auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc()); |
| 7608 | if (!ToNameInfoOrErr) |
| 7609 | return ToNameInfoOrErr.takeError(); |
| 7610 | DeclarationNameInfo ToNameInfo( |
| 7611 | std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr)); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7612 | // Import additional name location/type info. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7613 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7614 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7615 | |
| 7616 | UnresolvedSet<8> ToDecls; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7617 | for (auto *D : E->decls()) |
| 7618 | if (auto ToDOrErr = import(D)) |
| 7619 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7620 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7621 | return ToDOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7622 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7623 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7624 | TemplateArgumentListInfo ToTAInfo; |
| 7625 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7626 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7627 | ToTAInfo)) |
| 7628 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7629 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7630 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); |
| 7631 | if (!ToTemplateKeywordLocOrErr) |
| 7632 | return ToTemplateKeywordLocOrErr.takeError(); |
| 7633 | |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7634 | return UnresolvedLookupExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7635 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7636 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, |
| 7637 | ToDecls.begin(), ToDecls.end()); |
| 7638 | } |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7639 | |
| 7640 | return UnresolvedLookupExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7641 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7642 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), |
| 7643 | ToDecls.end()); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7644 | } |
| 7645 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7646 | ExpectedStmt |
| 7647 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 7648 | auto Imp1 = importSeq( |
| 7649 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7650 | E->getTemplateKeywordLoc()); |
| 7651 | if (!Imp1) |
| 7652 | return Imp1.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7653 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7654 | QualType ToType; |
| 7655 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7656 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7657 | std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1; |
| 7658 | |
| 7659 | auto Imp2 = importSeq(E->getName(), E->getNameLoc()); |
| 7660 | if (!Imp2) |
| 7661 | return Imp2.takeError(); |
| 7662 | DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2)); |
| 7663 | // Import additional name location/type info. |
| 7664 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7665 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7666 | |
| 7667 | UnresolvedSet<8> ToDecls; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7668 | for (Decl *D : E->decls()) |
| 7669 | if (auto ToDOrErr = import(D)) |
| 7670 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7671 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7672 | return ToDOrErr.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7673 | |
| 7674 | TemplateArgumentListInfo ToTAInfo; |
| 7675 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7676 | if (E->hasExplicitTemplateArgs()) { |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7677 | TemplateArgumentListInfo FromTAInfo; |
| 7678 | E->copyTemplateArgumentsInto(FromTAInfo); |
| 7679 | if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7680 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7681 | ResInfo = &ToTAInfo; |
| 7682 | } |
| 7683 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7684 | Expr *ToBase = nullptr; |
| 7685 | if (!E->isImplicitAccess()) { |
| 7686 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7687 | ToBase = *ToBaseOrErr; |
| 7688 | else |
| 7689 | return ToBaseOrErr.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7690 | } |
| 7691 | |
| 7692 | return UnresolvedMemberExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7693 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, |
| 7694 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7695 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7696 | } |
| 7697 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7698 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 7699 | auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7700 | if (!Imp) |
| 7701 | return Imp.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7702 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7703 | Expr *ToCallee; |
| 7704 | QualType ToType; |
| 7705 | SourceLocation ToRParenLoc; |
| 7706 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7707 | |
| 7708 | unsigned NumArgs = E->getNumArgs(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7709 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 7710 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7711 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7712 | |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7713 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7714 | return CXXOperatorCallExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7715 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, |
| Eric Fiselier | 5cdc2cd | 2018-12-12 21:50:55 +0000 | [diff] [blame] | 7716 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), |
| 7717 | OCE->getADLCallKind()); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7718 | } |
| 7719 | |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7720 | return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType, |
| 7721 | E->getValueKind(), ToRParenLoc, /*MinNumArgs=*/0, |
| 7722 | E->getADLCallKind()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7723 | } |
| 7724 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7725 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { |
| 7726 | CXXRecordDecl *FromClass = E->getLambdaClass(); |
| 7727 | auto ToClassOrErr = import(FromClass); |
| 7728 | if (!ToClassOrErr) |
| 7729 | return ToClassOrErr.takeError(); |
| 7730 | CXXRecordDecl *ToClass = *ToClassOrErr; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7731 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7732 | auto ToCallOpOrErr = import(E->getCallOperator()); |
| 7733 | if (!ToCallOpOrErr) |
| 7734 | return ToCallOpOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7735 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7736 | SmallVector<LambdaCapture, 8> ToCaptures; |
| 7737 | ToCaptures.reserve(E->capture_size()); |
| 7738 | for (const auto &FromCapture : E->captures()) { |
| 7739 | if (auto ToCaptureOrErr = import(FromCapture)) |
| 7740 | ToCaptures.push_back(*ToCaptureOrErr); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7741 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7742 | return ToCaptureOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7743 | } |
| 7744 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7745 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); |
| 7746 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) |
| 7747 | return std::move(Err); |
| 7748 | |
| 7749 | auto Imp = importSeq( |
| 7750 | E->getIntroducerRange(), E->getCaptureDefaultLoc(), E->getEndLoc()); |
| 7751 | if (!Imp) |
| 7752 | return Imp.takeError(); |
| 7753 | |
| 7754 | SourceRange ToIntroducerRange; |
| 7755 | SourceLocation ToCaptureDefaultLoc, ToEndLoc; |
| 7756 | std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7757 | |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7758 | return LambdaExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7759 | Importer.getToContext(), ToClass, ToIntroducerRange, |
| 7760 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, |
| 7761 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, |
| 7762 | ToEndLoc, E->containsUnexpandedParameterPack()); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7763 | } |
| 7764 | |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7765 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7766 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { |
| 7767 | auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType()); |
| 7768 | if (!Imp) |
| 7769 | return Imp.takeError(); |
| 7770 | |
| 7771 | SourceLocation ToLBraceLoc, ToRBraceLoc; |
| 7772 | QualType ToType; |
| 7773 | std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp; |
| 7774 | |
| 7775 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); |
| 7776 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) |
| 7777 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7778 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7779 | ASTContext &ToCtx = Importer.getToContext(); |
| 7780 | InitListExpr *To = new (ToCtx) InitListExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7781 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); |
| 7782 | To->setType(ToType); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7783 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7784 | if (E->hasArrayFiller()) { |
| 7785 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) |
| 7786 | To->setArrayFiller(*ToFillerOrErr); |
| 7787 | else |
| 7788 | return ToFillerOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7789 | } |
| 7790 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7791 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { |
| 7792 | if (auto ToFDOrErr = import(FromFD)) |
| 7793 | To->setInitializedFieldInUnion(*ToFDOrErr); |
| 7794 | else |
| 7795 | return ToFDOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7796 | } |
| 7797 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7798 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { |
| 7799 | if (auto ToSyntFormOrErr = import(SyntForm)) |
| 7800 | To->setSyntacticForm(*ToSyntFormOrErr); |
| 7801 | else |
| 7802 | return ToSyntFormOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7803 | } |
| 7804 | |
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7805 | // Copy InitListExprBitfields, which are not handled in the ctor of |
| 7806 | // InitListExpr. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7807 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7808 | |
| 7809 | return To; |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7810 | } |
| 7811 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7812 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7813 | CXXStdInitializerListExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7814 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7815 | if (!ToTypeOrErr) |
| 7816 | return ToTypeOrErr.takeError(); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7817 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7818 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7819 | if (!ToSubExprOrErr) |
| 7820 | return ToSubExprOrErr.takeError(); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7821 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7822 | return new (Importer.getToContext()) CXXStdInitializerListExpr( |
| 7823 | *ToTypeOrErr, *ToSubExprOrErr); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7824 | } |
| 7825 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7826 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7827 | CXXInheritedCtorInitExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7828 | auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor()); |
| 7829 | if (!Imp) |
| 7830 | return Imp.takeError(); |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7831 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7832 | SourceLocation ToLocation; |
| 7833 | QualType ToType; |
| 7834 | CXXConstructorDecl *ToConstructor; |
| 7835 | std::tie(ToLocation, ToType, ToConstructor) = *Imp; |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7836 | |
| 7837 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7838 | ToLocation, ToType, ToConstructor, E->constructsVBase(), |
| 7839 | E->inheritedFromVBase()); |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7840 | } |
| 7841 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7842 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 7843 | auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr()); |
| 7844 | if (!Imp) |
| 7845 | return Imp.takeError(); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7846 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7847 | QualType ToType; |
| 7848 | Expr *ToCommonExpr, *ToSubExpr; |
| 7849 | std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp; |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7850 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7851 | return new (Importer.getToContext()) ArrayInitLoopExpr( |
| 7852 | ToType, ToCommonExpr, ToSubExpr); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7853 | } |
| 7854 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7855 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 7856 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7857 | if (!ToTypeOrErr) |
| 7858 | return ToTypeOrErr.takeError(); |
| 7859 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7860 | } |
| 7861 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7862 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7863 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); |
| 7864 | if (!ToBeginLocOrErr) |
| 7865 | return ToBeginLocOrErr.takeError(); |
| 7866 | |
| 7867 | auto ToFieldOrErr = import(E->getField()); |
| 7868 | if (!ToFieldOrErr) |
| 7869 | return ToFieldOrErr.takeError(); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7870 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7871 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); |
| 7872 | if (!UsedContextOrErr) |
| 7873 | return UsedContextOrErr.takeError(); |
| 7874 | |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7875 | return CXXDefaultInitExpr::Create( |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7876 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr, *UsedContextOrErr); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7877 | } |
| 7878 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7879 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 7880 | auto Imp = importSeq( |
| 7881 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(), |
| 7882 | E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets()); |
| 7883 | if (!Imp) |
| 7884 | return Imp.takeError(); |
| 7885 | |
| 7886 | QualType ToType; |
| 7887 | Expr *ToSubExpr; |
| 7888 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 7889 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 7890 | SourceRange ToAngleBrackets; |
| 7891 | std::tie( |
| 7892 | ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, |
| 7893 | ToAngleBrackets) = *Imp; |
| 7894 | |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7895 | ExprValueKind VK = E->getValueKind(); |
| 7896 | CastKind CK = E->getCastKind(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7897 | auto ToBasePathOrErr = ImportCastPath(E); |
| 7898 | if (!ToBasePathOrErr) |
| 7899 | return ToBasePathOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7900 | |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7901 | if (isa<CXXStaticCastExpr>(E)) { |
| 7902 | return CXXStaticCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7903 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7904 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7905 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 7906 | return CXXDynamicCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7907 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7908 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7909 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 7910 | return CXXReinterpretCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7911 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7912 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 7913 | } else if (isa<CXXConstCastExpr>(E)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7914 | return CXXConstCastExpr::Create( |
| 7915 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, |
| 7916 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7917 | } else { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7918 | llvm_unreachable("Unknown cast type"); |
| 7919 | return make_error<ImportError>(); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7920 | } |
| 7921 | } |
| 7922 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7923 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7924 | SubstNonTypeTemplateParmExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7925 | auto Imp = importSeq( |
| 7926 | E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement()); |
| 7927 | if (!Imp) |
| 7928 | return Imp.takeError(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7929 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7930 | QualType ToType; |
| 7931 | SourceLocation ToExprLoc; |
| 7932 | NonTypeTemplateParmDecl *ToParameter; |
| 7933 | Expr *ToReplacement; |
| 7934 | std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp; |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7935 | |
| 7936 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7937 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7938 | } |
| 7939 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7940 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 7941 | auto Imp = importSeq( |
| 7942 | E->getType(), E->getBeginLoc(), E->getEndLoc()); |
| 7943 | if (!Imp) |
| 7944 | return Imp.takeError(); |
| 7945 | |
| 7946 | QualType ToType; |
| 7947 | SourceLocation ToBeginLoc, ToEndLoc; |
| 7948 | std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp; |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7949 | |
| 7950 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7951 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) |
| 7952 | return std::move(Err); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7953 | |
| 7954 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 7955 | // Value is always false. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7956 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7957 | |
| 7958 | return TypeTraitExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7959 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, |
| 7960 | ToEndLoc, ToValue); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7961 | } |
| 7962 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7963 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 7964 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7965 | if (!ToTypeOrErr) |
| 7966 | return ToTypeOrErr.takeError(); |
| 7967 | |
| 7968 | auto ToSourceRangeOrErr = import(E->getSourceRange()); |
| 7969 | if (!ToSourceRangeOrErr) |
| 7970 | return ToSourceRangeOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7971 | |
| 7972 | if (E->isTypeOperand()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7973 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) |
| 7974 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7975 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); |
| 7976 | else |
| 7977 | return ToTSIOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7978 | } |
| 7979 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7980 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); |
| 7981 | if (!ToExprOperandOrErr) |
| 7982 | return ToExprOperandOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7983 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7984 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7985 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7986 | } |
| 7987 | |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7988 | Error ASTNodeImporter::ImportOverriddenMethods(CXXMethodDecl *ToMethod, |
| 7989 | CXXMethodDecl *FromMethod) { |
| 7990 | Error ImportErrors = Error::success(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7991 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { |
| 7992 | if (auto ImportedOrErr = import(FromOverriddenMethod)) |
| 7993 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( |
| 7994 | (*ImportedOrErr)->getCanonicalDecl())); |
| 7995 | else |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7996 | ImportErrors = |
| 7997 | joinErrors(std::move(ImportErrors), ImportedOrErr.takeError()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7998 | } |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7999 | return ImportErrors; |
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 8000 | } |
| 8001 | |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8002 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8003 | ASTContext &FromContext, FileManager &FromFileManager, |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 8004 | bool MinimalImport, |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8005 | std::shared_ptr<ASTImporterSharedState> SharedState) |
| 8006 | : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext), |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8007 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 8008 | Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) { |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 8009 | |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8010 | // Create a default state without the lookup table: LLDB case. |
| 8011 | if (!SharedState) { |
| 8012 | this->SharedState = std::make_shared<ASTImporterSharedState>(); |
| 8013 | } |
| 8014 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 8015 | ImportedDecls[FromContext.getTranslationUnitDecl()] = |
| 8016 | ToContext.getTranslationUnitDecl(); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8017 | } |
| 8018 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8019 | ASTImporter::~ASTImporter() = default; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8020 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 8021 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { |
| 8022 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && |
| 8023 | "Try to get field index for non-field."); |
| 8024 | |
| 8025 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 8026 | if (!Owner) |
| 8027 | return None; |
| 8028 | |
| 8029 | unsigned Index = 0; |
| 8030 | for (const auto *D : Owner->decls()) { |
| 8031 | if (D == F) |
| 8032 | return Index; |
| 8033 | |
| 8034 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 8035 | ++Index; |
| 8036 | } |
| 8037 | |
| 8038 | llvm_unreachable("Field was not found in its parent context."); |
| 8039 | |
| 8040 | return None; |
| 8041 | } |
| 8042 | |
| 8043 | ASTImporter::FoundDeclsTy |
| 8044 | ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) { |
| 8045 | // We search in the redecl context because of transparent contexts. |
| 8046 | // E.g. a simple C language enum is a transparent context: |
| 8047 | // enum E { A, B }; |
| 8048 | // Now if we had a global variable in the TU |
| 8049 | // int A; |
| 8050 | // then the enum constant 'A' and the variable 'A' violates ODR. |
| 8051 | // We can diagnose this only if we search in the redecl context. |
| 8052 | DeclContext *ReDC = DC->getRedeclContext(); |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8053 | if (SharedState->getLookupTable()) { |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 8054 | ASTImporterLookupTable::LookupResult LookupResult = |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8055 | SharedState->getLookupTable()->lookup(ReDC, Name); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 8056 | return FoundDeclsTy(LookupResult.begin(), LookupResult.end()); |
| 8057 | } else { |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 8058 | DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name); |
| 8059 | FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end()); |
| 8060 | // We must search by the slow case of localUncachedLookup because that is |
| 8061 | // working even if there is no LookupPtr for the DC. We could use |
| 8062 | // DC::buildLookup() to create the LookupPtr, but that would load external |
| 8063 | // decls again, we must avoid that case. |
| 8064 | // Also, even if we had the LookupPtr, we must find Decls which are not |
| 8065 | // in the LookupPtr, so we need the slow case. |
| 8066 | // These cases are handled in ASTImporterLookupTable, but we cannot use |
| 8067 | // that with LLDB since that traverses through the AST which initiates the |
| 8068 | // load of external decls again via DC::decls(). And again, we must avoid |
| 8069 | // loading external decls during the import. |
| 8070 | if (Result.empty()) |
| 8071 | ReDC->localUncachedLookup(Name, Result); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 8072 | return Result; |
| 8073 | } |
| 8074 | } |
| 8075 | |
| 8076 | void ASTImporter::AddToLookupTable(Decl *ToD) { |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8077 | SharedState->addDeclToLookup(ToD); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 8078 | } |
| 8079 | |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 8080 | Expected<Decl *> ASTImporter::ImportImpl(Decl *FromD) { |
| 8081 | // Import the decl using ASTNodeImporter. |
| 8082 | ASTNodeImporter Importer(*this); |
| 8083 | return Importer.Visit(FromD); |
| 8084 | } |
| 8085 | |
| 8086 | void ASTImporter::RegisterImportedDecl(Decl *FromD, Decl *ToD) { |
| 8087 | MapImported(FromD, ToD); |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 8088 | } |
| 8089 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8090 | Expected<QualType> ASTImporter::Import(QualType FromT) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8091 | if (FromT.isNull()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8092 | return QualType{}; |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 8093 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8094 | const Type *FromTy = FromT.getTypePtr(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8095 | |
| 8096 | // Check whether we've already imported this type. |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 8097 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8098 | = ImportedTypes.find(FromTy); |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 8099 | if (Pos != ImportedTypes.end()) |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 8100 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8101 | |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 8102 | // Import the type |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8103 | ASTNodeImporter Importer(*this); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8104 | ExpectedType ToTOrErr = Importer.Visit(FromTy); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8105 | if (!ToTOrErr) |
| 8106 | return ToTOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8107 | |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 8108 | // Record the imported type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8109 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8110 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8111 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8112 | } |
| 8113 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8114 | Expected<TypeSourceInfo *> ASTImporter::Import(TypeSourceInfo *FromTSI) { |
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 8115 | if (!FromTSI) |
| 8116 | return FromTSI; |
| 8117 | |
| 8118 | // FIXME: For now we just create a "trivial" type source info based |
| Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 8119 | // 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] | 8120 | ExpectedType TOrErr = Import(FromTSI->getType()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8121 | if (!TOrErr) |
| 8122 | return TOrErr.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8123 | ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8124 | if (!BeginLocOrErr) |
| 8125 | return BeginLocOrErr.takeError(); |
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 8126 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8127 | return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr); |
| 8128 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8129 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8130 | Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) { |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8131 | Attr *ToAttr = FromAttr->clone(ToContext); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8132 | if (auto ToRangeOrErr = Import(FromAttr->getRange())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8133 | ToAttr->setRange(*ToRangeOrErr); |
| 8134 | else |
| 8135 | return ToRangeOrErr.takeError(); |
| 8136 | |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8137 | return ToAttr; |
| Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8138 | } |
| Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 8139 | |
| Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 8140 | Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { |
| 8141 | auto Pos = ImportedDecls.find(FromD); |
| 8142 | if (Pos != ImportedDecls.end()) |
| 8143 | return Pos->second; |
| 8144 | else |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 8145 | return nullptr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 8146 | } |
| 8147 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 8148 | TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) { |
| 8149 | auto FromDPos = ImportedFromDecls.find(ToD); |
| 8150 | if (FromDPos == ImportedFromDecls.end()) |
| 8151 | return nullptr; |
| 8152 | return FromDPos->second->getTranslationUnitDecl(); |
| 8153 | } |
| 8154 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8155 | Expected<Decl *> ASTImporter::Import(Decl *FromD) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8156 | if (!FromD) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8157 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8158 | |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8159 | // Push FromD to the stack, and remove that when we return. |
| 8160 | ImportPath.push(FromD); |
| 8161 | auto ImportPathBuilder = |
| 8162 | llvm::make_scope_exit([this]() { ImportPath.pop(); }); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8163 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8164 | // Check whether there was a previous failed import. |
| 8165 | // If yes return the existing error. |
| 8166 | if (auto Error = getImportDeclErrorIfAny(FromD)) |
| 8167 | return make_error<ImportError>(*Error); |
| 8168 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8169 | // Check whether we've already imported this declaration. |
| 8170 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 8171 | if (ToD) { |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8172 | // Already imported (possibly from another TU) and with an error. |
| 8173 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { |
| 8174 | setImportDeclError(FromD, *Error); |
| 8175 | return make_error<ImportError>(*Error); |
| 8176 | } |
| 8177 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8178 | // If FromD has some updated flags after last import, apply it |
| 8179 | updateFlags(FromD, ToD); |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8180 | // If we encounter a cycle during an import then we save the relevant part |
| 8181 | // of the import path associated to the Decl. |
| 8182 | if (ImportPath.hasCycleAtBack()) |
| 8183 | SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack()); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8184 | return ToD; |
| 8185 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8186 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8187 | // Import the declaration. |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 8188 | ExpectedDecl ToDOrErr = ImportImpl(FromD); |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8189 | if (!ToDOrErr) { |
| 8190 | // Failed to import. |
| 8191 | |
| 8192 | auto Pos = ImportedDecls.find(FromD); |
| 8193 | if (Pos != ImportedDecls.end()) { |
| 8194 | // Import failed after the object was created. |
| 8195 | // Remove all references to it. |
| 8196 | auto *ToD = Pos->second; |
| 8197 | ImportedDecls.erase(Pos); |
| 8198 | |
| 8199 | // ImportedDecls and ImportedFromDecls are not symmetric. It may happen |
| 8200 | // (e.g. with namespaces) that several decls from the 'from' context are |
| 8201 | // mapped to the same decl in the 'to' context. If we removed entries |
| 8202 | // from the LookupTable here then we may end up removing them multiple |
| 8203 | // times. |
| 8204 | |
| 8205 | // The Lookuptable contains decls only which are in the 'to' context. |
| 8206 | // Remove from the Lookuptable only if it is *imported* into the 'to' |
| 8207 | // context (and do not remove it if it was added during the initial |
| 8208 | // traverse of the 'to' context). |
| 8209 | auto PosF = ImportedFromDecls.find(ToD); |
| 8210 | if (PosF != ImportedFromDecls.end()) { |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8211 | SharedState->removeDeclFromLookup(ToD); |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8212 | ImportedFromDecls.erase(PosF); |
| 8213 | } |
| 8214 | |
| 8215 | // FIXME: AST may contain remaining references to the failed object. |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8216 | // However, the ImportDeclErrors in the shared state contains all the |
| 8217 | // failed objects together with their error. |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8218 | } |
| 8219 | |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8220 | // Error encountered for the first time. |
| 8221 | // After takeError the error is not usable any more in ToDOrErr. |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8222 | // Get a copy of the error object (any more simple solution for this?). |
| 8223 | ImportError ErrOut; |
| 8224 | handleAllErrors(ToDOrErr.takeError(), |
| 8225 | [&ErrOut](const ImportError &E) { ErrOut = E; }); |
| 8226 | setImportDeclError(FromD, ErrOut); |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8227 | // Set the error for the mapped to Decl, which is in the "to" context. |
| 8228 | if (Pos != ImportedDecls.end()) |
| 8229 | SharedState->setImportDeclError(Pos->second, ErrOut); |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8230 | |
| 8231 | // Set the error for all nodes which have been created before we |
| 8232 | // recognized the error. |
| 8233 | for (const auto &Path : SavedImportPaths[FromD]) |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8234 | for (Decl *FromDi : Path) { |
| 8235 | setImportDeclError(FromDi, ErrOut); |
| 8236 | //FIXME Should we remove these Decls from ImportedDecls? |
| 8237 | // Set the error for the mapped to Decl, which is in the "to" context. |
| 8238 | auto Ii = ImportedDecls.find(FromDi); |
| 8239 | if (Ii != ImportedDecls.end()) |
| 8240 | SharedState->setImportDeclError(Ii->second, ErrOut); |
| 8241 | // FIXME Should we remove these Decls from the LookupTable, |
| 8242 | // and from ImportedFromDecls? |
| 8243 | } |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8244 | SavedImportPaths[FromD].clear(); |
| 8245 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8246 | // Do not return ToDOrErr, error was taken out of it. |
| 8247 | return make_error<ImportError>(ErrOut); |
| 8248 | } |
| 8249 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8250 | ToD = *ToDOrErr; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8251 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8252 | // FIXME: Handle the "already imported with error" case. We can get here |
| 8253 | // nullptr only if GetImportedOrCreateDecl returned nullptr (after a |
| 8254 | // previously failed create was requested). |
| 8255 | // Later GetImportedOrCreateDecl can be updated to return the error. |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 8256 | if (!ToD) { |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8257 | auto Err = getImportDeclErrorIfAny(FromD); |
| 8258 | assert(Err); |
| 8259 | return make_error<ImportError>(*Err); |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 8260 | } |
| 8261 | |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8262 | // We could import from the current TU without error. But previously we |
| 8263 | // already had imported a Decl as `ToD` from another TU (with another |
| 8264 | // ASTImporter object) and with an error. |
| 8265 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { |
| 8266 | setImportDeclError(FromD, *Error); |
| 8267 | return make_error<ImportError>(*Error); |
| 8268 | } |
| 8269 | |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 8270 | // Make sure that ImportImpl registered the imported decl. |
| 8271 | assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?"); |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8272 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8273 | // Notify subclasses. |
| 8274 | Imported(FromD, ToD); |
| 8275 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 8276 | updateFlags(FromD, ToD); |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8277 | SavedImportPaths[FromD].clear(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8278 | return ToDOrErr; |
| 8279 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8280 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8281 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8282 | if (!FromDC) |
| 8283 | return FromDC; |
| 8284 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8285 | ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC)); |
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8286 | if (!ToDCOrErr) |
| 8287 | return ToDCOrErr.takeError(); |
| 8288 | auto *ToDC = cast<DeclContext>(*ToDCOrErr); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8289 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8290 | // 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] | 8291 | // need it to have a definition. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8292 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 8293 | auto *FromRecord = cast<RecordDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8294 | if (ToRecord->isCompleteDefinition()) { |
| 8295 | // Do nothing. |
| 8296 | } else if (FromRecord->isCompleteDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8297 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8298 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) |
| 8299 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8300 | } else { |
| 8301 | CompleteDecl(ToRecord); |
| 8302 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8303 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 8304 | auto *FromEnum = cast<EnumDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8305 | if (ToEnum->isCompleteDefinition()) { |
| 8306 | // Do nothing. |
| 8307 | } else if (FromEnum->isCompleteDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8308 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8309 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) |
| 8310 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8311 | } else { |
| 8312 | CompleteDecl(ToEnum); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8313 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8314 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 8315 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8316 | if (ToClass->getDefinition()) { |
| 8317 | // Do nothing. |
| 8318 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8319 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8320 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) |
| 8321 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8322 | } else { |
| 8323 | CompleteDecl(ToClass); |
| 8324 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8325 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 8326 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8327 | if (ToProto->getDefinition()) { |
| 8328 | // Do nothing. |
| 8329 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8330 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8331 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) |
| 8332 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8333 | } else { |
| 8334 | CompleteDecl(ToProto); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8335 | } |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 8336 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8337 | |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 8338 | return ToDC; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8339 | } |
| 8340 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8341 | Expected<Expr *> ASTImporter::Import(Expr *FromE) { |
| 8342 | if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE))) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8343 | return cast_or_null<Expr>(*ToSOrErr); |
| 8344 | else |
| 8345 | return ToSOrErr.takeError(); |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8346 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8347 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8348 | Expected<Stmt *> ASTImporter::Import(Stmt *FromS) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8349 | if (!FromS) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8350 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8351 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8352 | // Check whether we've already imported this statement. |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 8353 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 8354 | if (Pos != ImportedStmts.end()) |
| 8355 | return Pos->second; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8356 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8357 | // Import the statement. |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 8358 | ASTNodeImporter Importer(*this); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8359 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8360 | if (!ToSOrErr) |
| 8361 | return ToSOrErr; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8362 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8363 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { |
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 8364 | auto *FromE = cast<Expr>(FromS); |
| 8365 | // Copy ExprBitfields, which may not be handled in Expr subclasses |
| 8366 | // constructors. |
| 8367 | ToE->setValueKind(FromE->getValueKind()); |
| 8368 | ToE->setObjectKind(FromE->getObjectKind()); |
| 8369 | ToE->setTypeDependent(FromE->isTypeDependent()); |
| 8370 | ToE->setValueDependent(FromE->isValueDependent()); |
| 8371 | ToE->setInstantiationDependent(FromE->isInstantiationDependent()); |
| 8372 | ToE->setContainsUnexpandedParameterPack( |
| 8373 | FromE->containsUnexpandedParameterPack()); |
| 8374 | } |
| 8375 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8376 | // Record the imported statement object. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8377 | ImportedStmts[FromS] = *ToSOrErr; |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8378 | return ToSOrErr; |
| 8379 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8380 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8381 | Expected<NestedNameSpecifier *> |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8382 | ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8383 | if (!FromNNS) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8384 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8385 | |
| Simon Pilgrim | 130df2c | 2019-07-15 13:00:43 +0000 | [diff] [blame] | 8386 | NestedNameSpecifier *Prefix = nullptr; |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8387 | if (Error Err = importInto(Prefix, FromNNS->getPrefix())) |
| 8388 | return std::move(Err); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8389 | |
| 8390 | switch (FromNNS->getKind()) { |
| 8391 | case NestedNameSpecifier::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8392 | assert(FromNNS->getAsIdentifier() && "NNS should contain identifier."); |
| 8393 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8394 | Import(FromNNS->getAsIdentifier())); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8395 | |
| 8396 | case NestedNameSpecifier::Namespace: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8397 | if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8398 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8399 | cast<NamespaceDecl>(*NSOrErr)); |
| 8400 | } else |
| 8401 | return NSOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8402 | |
| 8403 | case NestedNameSpecifier::NamespaceAlias: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8404 | if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8405 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8406 | cast<NamespaceAliasDecl>(*NSADOrErr)); |
| 8407 | else |
| 8408 | return NSADOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8409 | |
| 8410 | case NestedNameSpecifier::Global: |
| 8411 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 8412 | |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8413 | case NestedNameSpecifier::Super: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8414 | if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8415 | return NestedNameSpecifier::SuperSpecifier(ToContext, |
| 8416 | cast<CXXRecordDecl>(*RDOrErr)); |
| 8417 | else |
| 8418 | return RDOrErr.takeError(); |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8419 | |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8420 | case NestedNameSpecifier::TypeSpec: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8421 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 8422 | if (Expected<QualType> TyOrErr = |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8423 | Import(QualType(FromNNS->getAsType(), 0u))) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8424 | bool TSTemplate = |
| 8425 | FromNNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate; |
| 8426 | return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate, |
| 8427 | TyOrErr->getTypePtr()); |
| 8428 | } else { |
| 8429 | return TyOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8430 | } |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8431 | } |
| 8432 | |
| 8433 | llvm_unreachable("Invalid nested name specifier kind"); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8434 | } |
| 8435 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8436 | Expected<NestedNameSpecifierLoc> |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8437 | ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8438 | // Copied from NestedNameSpecifier mostly. |
| 8439 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 8440 | NestedNameSpecifierLoc NNS = FromNNS; |
| 8441 | |
| 8442 | // Push each of the nested-name-specifiers's onto a stack for |
| 8443 | // serialization in reverse order. |
| 8444 | while (NNS) { |
| 8445 | NestedNames.push_back(NNS); |
| 8446 | NNS = NNS.getPrefix(); |
| 8447 | } |
| 8448 | |
| 8449 | NestedNameSpecifierLocBuilder Builder; |
| 8450 | |
| 8451 | while (!NestedNames.empty()) { |
| 8452 | NNS = NestedNames.pop_back_val(); |
| Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 8453 | NestedNameSpecifier *Spec = nullptr; |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8454 | if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier())) |
| 8455 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8456 | |
| 8457 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8458 | |
| 8459 | SourceLocation ToLocalBeginLoc, ToLocalEndLoc; |
| 8460 | if (Kind != NestedNameSpecifier::Super) { |
| 8461 | if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc())) |
| 8462 | return std::move(Err); |
| 8463 | |
| 8464 | if (Kind != NestedNameSpecifier::Global) |
| 8465 | if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc())) |
| 8466 | return std::move(Err); |
| 8467 | } |
| 8468 | |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8469 | switch (Kind) { |
| 8470 | case NestedNameSpecifier::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8471 | Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc, |
| 8472 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8473 | break; |
| 8474 | |
| 8475 | case NestedNameSpecifier::Namespace: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8476 | Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc, |
| 8477 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8478 | break; |
| 8479 | |
| 8480 | case NestedNameSpecifier::NamespaceAlias: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8481 | Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(), |
| 8482 | ToLocalBeginLoc, ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8483 | break; |
| 8484 | |
| 8485 | case NestedNameSpecifier::TypeSpec: |
| 8486 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8487 | SourceLocation ToTLoc; |
| 8488 | if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc())) |
| 8489 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8490 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8491 | QualType(Spec->getAsType(), 0), ToTLoc); |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 8492 | if (Kind == NestedNameSpecifier::TypeSpecWithTemplate) |
| 8493 | // ToLocalBeginLoc is here the location of the 'template' keyword. |
| 8494 | Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(), |
| 8495 | ToLocalEndLoc); |
| 8496 | else |
| 8497 | // No location for 'template' keyword here. |
| 8498 | Builder.Extend(getToContext(), SourceLocation{}, TSI->getTypeLoc(), |
| 8499 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8500 | break; |
| 8501 | } |
| 8502 | |
| 8503 | case NestedNameSpecifier::Global: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8504 | Builder.MakeGlobal(getToContext(), ToLocalBeginLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8505 | break; |
| 8506 | |
| 8507 | case NestedNameSpecifier::Super: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8508 | auto ToSourceRangeOrErr = Import(NNS.getSourceRange()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8509 | if (!ToSourceRangeOrErr) |
| 8510 | return ToSourceRangeOrErr.takeError(); |
| 8511 | |
| 8512 | Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(), |
| 8513 | ToSourceRangeOrErr->getBegin(), |
| 8514 | ToSourceRangeOrErr->getEnd()); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8515 | } |
| 8516 | } |
| 8517 | } |
| 8518 | |
| 8519 | return Builder.getWithLocInContext(getToContext()); |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 8520 | } |
| 8521 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8522 | Expected<TemplateName> ASTImporter::Import(TemplateName From) { |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8523 | switch (From.getKind()) { |
| 8524 | case TemplateName::Template: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8525 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8526 | return TemplateName(cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8527 | else |
| 8528 | return ToTemplateOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8529 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8530 | case TemplateName::OverloadedTemplate: { |
| 8531 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 8532 | UnresolvedSet<2> ToTemplates; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8533 | for (auto *I : *FromStorage) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8534 | if (auto ToOrErr = Import(I)) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8535 | ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr)); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8536 | else |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8537 | return ToOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8538 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8539 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8540 | ToTemplates.end()); |
| 8541 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8542 | |
| Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8543 | case TemplateName::AssumedTemplate: { |
| 8544 | AssumedTemplateStorage *FromStorage = From.getAsAssumedTemplateName(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8545 | auto DeclNameOrErr = Import(FromStorage->getDeclName()); |
| Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8546 | if (!DeclNameOrErr) |
| 8547 | return DeclNameOrErr.takeError(); |
| 8548 | return ToContext.getAssumedTemplateName(*DeclNameOrErr); |
| 8549 | } |
| 8550 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8551 | case TemplateName::QualifiedTemplate: { |
| 8552 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8553 | auto QualifierOrErr = Import(QTN->getQualifier()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8554 | if (!QualifierOrErr) |
| 8555 | return QualifierOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8556 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8557 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8558 | return ToContext.getQualifiedTemplateName( |
| 8559 | *QualifierOrErr, QTN->hasTemplateKeyword(), |
| 8560 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8561 | else |
| 8562 | return ToTemplateOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8563 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8564 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8565 | case TemplateName::DependentTemplate: { |
| 8566 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8567 | auto QualifierOrErr = Import(DTN->getQualifier()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8568 | if (!QualifierOrErr) |
| 8569 | return QualifierOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8570 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8571 | if (DTN->isIdentifier()) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8572 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8573 | Import(DTN->getIdentifier())); |
| 8574 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8575 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8576 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
| 8577 | DTN->getOperator()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8578 | } |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8579 | |
| 8580 | case TemplateName::SubstTemplateTemplateParm: { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8581 | SubstTemplateTemplateParmStorage *Subst = |
| 8582 | From.getAsSubstTemplateTemplateParm(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8583 | ExpectedDecl ParamOrErr = Import(Subst->getParameter()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8584 | if (!ParamOrErr) |
| 8585 | return ParamOrErr.takeError(); |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8586 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8587 | auto ReplacementOrErr = Import(Subst->getReplacement()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8588 | if (!ReplacementOrErr) |
| 8589 | return ReplacementOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8590 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8591 | return ToContext.getSubstTemplateTemplateParm( |
| 8592 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ReplacementOrErr); |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8593 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8594 | |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8595 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 8596 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 8597 | = From.getAsSubstTemplateTemplateParmPack(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8598 | ExpectedDecl ParamOrErr = Import(SubstPack->getParameterPack()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8599 | if (!ParamOrErr) |
| 8600 | return ParamOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8601 | |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8602 | ASTNodeImporter Importer(*this); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8603 | auto ArgPackOrErr = |
| 8604 | Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 8605 | if (!ArgPackOrErr) |
| 8606 | return ArgPackOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8607 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8608 | return ToContext.getSubstTemplateTemplateParmPack( |
| 8609 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ArgPackOrErr); |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8610 | } |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8611 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8612 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8613 | llvm_unreachable("Invalid template name kind"); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8614 | } |
| 8615 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8616 | Expected<SourceLocation> ASTImporter::Import(SourceLocation FromLoc) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8617 | if (FromLoc.isInvalid()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8618 | return SourceLocation{}; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8619 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8620 | SourceManager &FromSM = FromContext.getSourceManager(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8621 | bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8622 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8623 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8624 | Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8625 | if (!ToFileIDOrErr) |
| 8626 | return ToFileIDOrErr.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8627 | SourceManager &ToSM = ToContext.getSourceManager(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8628 | return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second); |
| 8629 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8630 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8631 | Expected<SourceRange> ASTImporter::Import(SourceRange FromRange) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8632 | SourceLocation ToBegin, ToEnd; |
| 8633 | if (Error Err = importInto(ToBegin, FromRange.getBegin())) |
| 8634 | return std::move(Err); |
| 8635 | if (Error Err = importInto(ToEnd, FromRange.getEnd())) |
| 8636 | return std::move(Err); |
| 8637 | |
| 8638 | return SourceRange(ToBegin, ToEnd); |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8639 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8640 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8641 | Expected<FileID> ASTImporter::Import(FileID FromID, bool IsBuiltin) { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8642 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8643 | if (Pos != ImportedFileIDs.end()) |
| 8644 | return Pos->second; |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8645 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8646 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 8647 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8648 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8649 | |
| 8650 | // Map the FromID to the "to" source manager. |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8651 | FileID ToID; |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8652 | if (FromSLoc.isExpansion()) { |
| 8653 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8654 | ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8655 | if (!ToSpLoc) |
| 8656 | return ToSpLoc.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8657 | ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8658 | if (!ToExLocS) |
| 8659 | return ToExLocS.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8660 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 8661 | SourceLocation MLoc; |
| 8662 | if (FromEx.isMacroArgExpansion()) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8663 | MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, TokenLen); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8664 | } else { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8665 | if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8666 | MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, TokenLen, |
| 8667 | FromEx.isExpansionTokenRange()); |
| 8668 | else |
| 8669 | return ToExLocE.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8670 | } |
| 8671 | ToID = ToSM.getFileID(MLoc); |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8672 | } else { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8673 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8674 | |
| 8675 | if (!IsBuiltin) { |
| 8676 | // Include location of this file. |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8677 | ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8678 | if (!ToIncludeLoc) |
| 8679 | return ToIncludeLoc.takeError(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8680 | |
| 8681 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 8682 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 8683 | // disk again |
| 8684 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 8685 | // than mmap the files several times. |
| Harlan Haskins | 8d323d1 | 2019-08-01 21:31:56 +0000 | [diff] [blame] | 8686 | auto Entry = |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8687 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 8688 | // FIXME: The filename may be a virtual name that does probably not |
| 8689 | // point to a valid file and we get no Entry here. In this case try with |
| 8690 | // the memory buffer below. |
| 8691 | if (Entry) |
| Harlan Haskins | 8d323d1 | 2019-08-01 21:31:56 +0000 | [diff] [blame] | 8692 | ToID = ToSM.createFileID(*Entry, *ToIncludeLoc, |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8693 | FromSLoc.getFile().getFileCharacteristic()); |
| 8694 | } |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8695 | } |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8696 | |
| 8697 | if (ToID.isInvalid() || IsBuiltin) { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8698 | // FIXME: We want to re-use the existing MemoryBuffer! |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8699 | bool Invalid = true; |
| Duncan P. N. Exon Smith | f584819 | 2019-08-26 20:32:05 +0000 | [diff] [blame] | 8700 | const llvm::MemoryBuffer *FromBuf = |
| 8701 | Cache->getBuffer(FromContext.getDiagnostics(), |
| 8702 | FromSM.getFileManager(), SourceLocation{}, &Invalid); |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8703 | if (!FromBuf || Invalid) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8704 | // FIXME: Use a new error kind? |
| 8705 | return llvm::make_error<ImportError>(ImportError::Unknown); |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8706 | |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8707 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 8708 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 8709 | FromBuf->getBufferIdentifier()); |
| 8710 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 8711 | FromSLoc.getFile().getFileCharacteristic()); |
| 8712 | } |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8713 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8714 | |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8715 | assert(ToID.isValid() && "Unexpected invalid fileID was created."); |
| 8716 | |
| Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 8717 | ImportedFileIDs[FromID] = ToID; |
| Balazs Keri | d22f877 | 2019-07-24 10:16:37 +0000 | [diff] [blame] | 8718 | |
| 8719 | if (FileIDImportHandler) |
| 8720 | FileIDImportHandler(ToID, FromID); |
| 8721 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8722 | return ToID; |
| 8723 | } |
| 8724 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8725 | Expected<CXXCtorInitializer *> ASTImporter::Import(CXXCtorInitializer *From) { |
| 8726 | ExpectedExpr ToExprOrErr = Import(From->getInit()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8727 | if (!ToExprOrErr) |
| 8728 | return ToExprOrErr.takeError(); |
| 8729 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8730 | auto LParenLocOrErr = Import(From->getLParenLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8731 | if (!LParenLocOrErr) |
| 8732 | return LParenLocOrErr.takeError(); |
| 8733 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8734 | auto RParenLocOrErr = Import(From->getRParenLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8735 | if (!RParenLocOrErr) |
| 8736 | return RParenLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8737 | |
| 8738 | if (From->isBaseInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8739 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8740 | if (!ToTInfoOrErr) |
| 8741 | return ToTInfoOrErr.takeError(); |
| 8742 | |
| 8743 | SourceLocation EllipsisLoc; |
| 8744 | if (From->isPackExpansion()) |
| 8745 | if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc())) |
| 8746 | return std::move(Err); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8747 | |
| 8748 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8749 | ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr, |
| 8750 | *ToExprOrErr, *RParenLocOrErr, EllipsisLoc); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8751 | } else if (From->isMemberInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8752 | ExpectedDecl ToFieldOrErr = Import(From->getMember()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8753 | if (!ToFieldOrErr) |
| 8754 | return ToFieldOrErr.takeError(); |
| 8755 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8756 | auto MemberLocOrErr = Import(From->getMemberLocation()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8757 | if (!MemberLocOrErr) |
| 8758 | return MemberLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8759 | |
| 8760 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8761 | ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr, |
| 8762 | *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8763 | } else if (From->isIndirectMemberInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8764 | ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8765 | if (!ToIFieldOrErr) |
| 8766 | return ToIFieldOrErr.takeError(); |
| 8767 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8768 | auto MemberLocOrErr = Import(From->getMemberLocation()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8769 | if (!MemberLocOrErr) |
| 8770 | return MemberLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8771 | |
| 8772 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8773 | ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr), |
| 8774 | *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8775 | } else if (From->isDelegatingInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8776 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8777 | if (!ToTInfoOrErr) |
| 8778 | return ToTInfoOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8779 | |
| 8780 | return new (ToContext) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8781 | CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr, |
| 8782 | *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8783 | } else { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8784 | // FIXME: assert? |
| 8785 | return make_error<ImportError>(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8786 | } |
| Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8787 | } |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8788 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8789 | Expected<CXXBaseSpecifier *> |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8790 | ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8791 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 8792 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 8793 | return Pos->second; |
| 8794 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8795 | Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8796 | if (!ToSourceRange) |
| 8797 | return ToSourceRange.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8798 | Expected<TypeSourceInfo *> ToTSI = Import(BaseSpec->getTypeSourceInfo()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8799 | if (!ToTSI) |
| 8800 | return ToTSI.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8801 | ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8802 | if (!ToEllipsisLoc) |
| 8803 | return ToEllipsisLoc.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8804 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8805 | *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 8806 | BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8807 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 8808 | return Imported; |
| 8809 | } |
| 8810 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8811 | Error ASTImporter::ImportDefinition(Decl *From) { |
| 8812 | ExpectedDecl ToOrErr = Import(From); |
| 8813 | if (!ToOrErr) |
| 8814 | return ToOrErr.takeError(); |
| 8815 | Decl *To = *ToOrErr; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8816 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8817 | auto *FromDC = cast<DeclContext>(From); |
| 8818 | ASTNodeImporter Importer(*this); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8819 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8820 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
| 8821 | if (!ToRecord->getDefinition()) { |
| 8822 | return Importer.ImportDefinition( |
| 8823 | cast<RecordDecl>(FromDC), ToRecord, |
| 8824 | ASTNodeImporter::IDK_Everything); |
| Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8825 | } |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8826 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8827 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8828 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
| 8829 | if (!ToEnum->getDefinition()) { |
| 8830 | return Importer.ImportDefinition( |
| 8831 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); |
| 8832 | } |
| 8833 | } |
| 8834 | |
| 8835 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
| 8836 | if (!ToIFace->getDefinition()) { |
| 8837 | return Importer.ImportDefinition( |
| 8838 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
| 8839 | ASTNodeImporter::IDK_Everything); |
| 8840 | } |
| 8841 | } |
| 8842 | |
| 8843 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
| 8844 | if (!ToProto->getDefinition()) { |
| 8845 | return Importer.ImportDefinition( |
| 8846 | cast<ObjCProtocolDecl>(FromDC), ToProto, |
| 8847 | ASTNodeImporter::IDK_Everything); |
| 8848 | } |
| 8849 | } |
| 8850 | |
| 8851 | return Importer.ImportDeclContext(FromDC, true); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8852 | } |
| 8853 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8854 | Expected<DeclarationName> ASTImporter::Import(DeclarationName FromName) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8855 | if (!FromName) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8856 | return DeclarationName{}; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8857 | |
| 8858 | switch (FromName.getNameKind()) { |
| 8859 | case DeclarationName::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8860 | return DeclarationName(Import(FromName.getAsIdentifierInfo())); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8861 | |
| 8862 | case DeclarationName::ObjCZeroArgSelector: |
| 8863 | case DeclarationName::ObjCOneArgSelector: |
| 8864 | case DeclarationName::ObjCMultiArgSelector: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8865 | if (auto ToSelOrErr = Import(FromName.getObjCSelector())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8866 | return DeclarationName(*ToSelOrErr); |
| 8867 | else |
| 8868 | return ToSelOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8869 | |
| 8870 | case DeclarationName::CXXConstructorName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8871 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8872 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 8873 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8874 | else |
| 8875 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8876 | } |
| 8877 | |
| 8878 | case DeclarationName::CXXDestructorName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8879 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8880 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 8881 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8882 | else |
| 8883 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8884 | } |
| 8885 | |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8886 | case DeclarationName::CXXDeductionGuideName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8887 | if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8888 | return ToContext.DeclarationNames.getCXXDeductionGuideName( |
| 8889 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8890 | else |
| 8891 | return ToTemplateOrErr.takeError(); |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8892 | } |
| 8893 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8894 | case DeclarationName::CXXConversionFunctionName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8895 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8896 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 8897 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8898 | else |
| 8899 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8900 | } |
| 8901 | |
| 8902 | case DeclarationName::CXXOperatorName: |
| 8903 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 8904 | FromName.getCXXOverloadedOperator()); |
| 8905 | |
| 8906 | case DeclarationName::CXXLiteralOperatorName: |
| 8907 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8908 | Import(FromName.getCXXLiteralIdentifier())); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8909 | |
| 8910 | case DeclarationName::CXXUsingDirective: |
| 8911 | // FIXME: STATICS! |
| 8912 | return DeclarationName::getUsingDirectiveName(); |
| 8913 | } |
| 8914 | |
| David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 8915 | llvm_unreachable("Invalid DeclarationName Kind!"); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8916 | } |
| 8917 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8918 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8919 | if (!FromId) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8920 | return nullptr; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8921 | |
| Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 8922 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 8923 | |
| 8924 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 8925 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 8926 | |
| 8927 | return ToId; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8928 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8929 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8930 | Expected<Selector> ASTImporter::Import(Selector FromSel) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8931 | if (FromSel.isNull()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8932 | return Selector{}; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8933 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8934 | SmallVector<IdentifierInfo *, 4> Idents; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8935 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 8936 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 8937 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 8938 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 8939 | } |
| 8940 | |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 8941 | Expected<DeclarationName> ASTImporter::HandleNameConflict(DeclarationName Name, |
| 8942 | DeclContext *DC, |
| 8943 | unsigned IDNS, |
| 8944 | NamedDecl **Decls, |
| 8945 | unsigned NumDecls) { |
| 8946 | if (ODRHandling == ODRHandlingType::Conservative) |
| 8947 | // Report error at any name conflict. |
| 8948 | return make_error<ImportError>(ImportError::NameConflict); |
| 8949 | else |
| 8950 | // Allow to create the new Decl with the same name. |
| 8951 | return Name; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8952 | } |
| 8953 | |
| 8954 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
| Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8955 | if (LastDiagFromFrom) |
| 8956 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8957 | FromContext.getDiagnostics()); |
| 8958 | LastDiagFromFrom = false; |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8959 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8960 | } |
| 8961 | |
| 8962 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
| Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8963 | if (!LastDiagFromFrom) |
| 8964 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8965 | ToContext.getDiagnostics()); |
| 8966 | LastDiagFromFrom = true; |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8967 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8968 | } |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8969 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8970 | void ASTImporter::CompleteDecl (Decl *D) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8971 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8972 | if (!ID->getDefinition()) |
| 8973 | ID->startDefinition(); |
| 8974 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8975 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8976 | if (!PD->getDefinition()) |
| 8977 | PD->startDefinition(); |
| 8978 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8979 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8980 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 8981 | TD->startDefinition(); |
| 8982 | TD->setCompleteDefinition(true); |
| 8983 | } |
| 8984 | } |
| 8985 | else { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8986 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8987 | } |
| 8988 | } |
| 8989 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8990 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 8991 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 8992 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 8993 | "Try to import an already imported Decl"); |
| 8994 | if (Pos != ImportedDecls.end()) |
| 8995 | return Pos->second; |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8996 | ImportedDecls[From] = To; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 8997 | // This mapping should be maintained only in this function. Therefore do not |
| 8998 | // check for additional consistency. |
| 8999 | ImportedFromDecls[To] = From; |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 9000 | AddToLookupTable(To); |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 9001 | return To; |
| Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 9002 | } |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 9003 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 9004 | llvm::Optional<ImportError> |
| 9005 | ASTImporter::getImportDeclErrorIfAny(Decl *FromD) const { |
| 9006 | auto Pos = ImportDeclErrors.find(FromD); |
| 9007 | if (Pos != ImportDeclErrors.end()) |
| 9008 | return Pos->second; |
| 9009 | else |
| 9010 | return Optional<ImportError>(); |
| 9011 | } |
| 9012 | |
| 9013 | void ASTImporter::setImportDeclError(Decl *From, ImportError Error) { |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 9014 | auto InsertRes = ImportDeclErrors.insert({From, Error}); |
| Benjamin Kramer | 4f76936 | 2019-07-01 14:33:26 +0000 | [diff] [blame] | 9015 | (void)InsertRes; |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 9016 | // Either we set the error for the first time, or we already had set one and |
| 9017 | // now we want to set the same error. |
| 9018 | assert(InsertRes.second || InsertRes.first->second.Error == Error.Error); |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 9019 | } |
| 9020 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 9021 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 9022 | bool Complain) { |
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 9023 | llvm::DenseMap<const Type *, const Type *>::iterator Pos = |
| 9024 | ImportedTypes.find(From.getTypePtr()); |
| 9025 | if (Pos != ImportedTypes.end()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 9026 | if (ExpectedType ToFromOrErr = Import(From)) { |
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 9027 | if (ToContext.hasSameType(*ToFromOrErr, To)) |
| 9028 | return true; |
| 9029 | } else { |
| 9030 | llvm::consumeError(ToFromOrErr.takeError()); |
| 9031 | } |
| 9032 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 9033 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 9034 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 9035 | getStructuralEquivalenceKind(*this), false, |
| 9036 | Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 9037 | return Ctx.IsEquivalent(From, To); |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 9038 | } |