| 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); |
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1737 | if (!ImportedOrErr) { |
| 1738 | if (AccumulateChildErrors) |
| 1739 | ChildErrors = |
| 1740 | joinErrors(std::move(ChildErrors), ImportedOrErr.takeError()); |
| 1741 | else |
| 1742 | consumeError(ImportedOrErr.takeError()); |
| 1743 | } |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1744 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1745 | |
| Gabor Marton | 48b16e1 | 2019-07-25 09:07:17 +0000 | [diff] [blame] | 1746 | // We reorder declarations in RecordDecls because they may have another order |
| 1747 | // in the "to" context than they have in the "from" context. This may happen |
| 1748 | // e.g when we import a class like this: |
| 1749 | // struct declToImport { |
| 1750 | // int a = c + b; |
| 1751 | // int b = 1; |
| 1752 | // int c = 2; |
| 1753 | // }; |
| 1754 | // During the import of `a` we import first the dependencies in sequence, |
| 1755 | // thus the order would be `c`, `b`, `a`. We will get the normal order by |
| 1756 | // first removing the already imported members and then adding them in the |
| 1757 | // order as they apper in the "from" context. |
| 1758 | // |
| 1759 | // Keeping field order is vital because it determines structure layout. |
| 1760 | // |
| 1761 | // Here and below, we cannot call field_begin() method and its callers on |
| 1762 | // ToDC if it has an external storage. Calling field_begin() will |
| 1763 | // automatically load all the fields by calling |
| 1764 | // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would |
| 1765 | // call ASTImporter::Import(). This is because the ExternalASTSource |
| 1766 | // interface in LLDB is implemented by the means of the ASTImporter. However, |
| 1767 | // calling an import at this point would result in an uncontrolled import, we |
| 1768 | // must avoid that. |
| 1769 | const auto *FromRD = dyn_cast<RecordDecl>(FromDC); |
| 1770 | if (!FromRD) |
| 1771 | return ChildErrors; |
| 1772 | |
| 1773 | auto ToDCOrErr = Importer.ImportContext(FromDC); |
| 1774 | if (!ToDCOrErr) { |
| 1775 | consumeError(std::move(ChildErrors)); |
| 1776 | return ToDCOrErr.takeError(); |
| 1777 | } |
| 1778 | |
| 1779 | DeclContext *ToDC = *ToDCOrErr; |
| 1780 | // Remove all declarations, which may be in wrong order in the |
| 1781 | // lexical DeclContext and then add them in the proper order. |
| 1782 | for (auto *D : FromRD->decls()) { |
| Balazs Keri | 6e08669 | 2019-09-02 07:17:01 +0000 | [diff] [blame] | 1783 | if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<FriendDecl>(D)) { |
| Gabor Marton | 48b16e1 | 2019-07-25 09:07:17 +0000 | [diff] [blame] | 1784 | assert(D && "DC contains a null decl"); |
| 1785 | Decl *ToD = Importer.GetAlreadyImportedOrNull(D); |
| 1786 | // Remove only the decls which we successfully imported. |
| 1787 | if (ToD) { |
| 1788 | assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD)); |
| 1789 | // Remove the decl from its wrong place in the linked list. |
| 1790 | ToDC->removeDecl(ToD); |
| 1791 | // Add the decl to the end of the linked list. |
| 1792 | // This time it will be at the proper place because the enclosing for |
| 1793 | // loop iterates in the original (good) order of the decls. |
| 1794 | ToDC->addDeclInternal(ToD); |
| 1795 | } |
| 1796 | } |
| 1797 | } |
| 1798 | |
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1799 | return ChildErrors; |
| Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1800 | } |
| 1801 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1802 | Error ASTNodeImporter::ImportDeclContext( |
| 1803 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { |
| 1804 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); |
| 1805 | if (!ToDCOrErr) |
| 1806 | return ToDCOrErr.takeError(); |
| 1807 | ToDC = *ToDCOrErr; |
| 1808 | |
| 1809 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { |
| 1810 | auto ToLexicalDCOrErr = Importer.ImportContext( |
| 1811 | FromD->getLexicalDeclContext()); |
| 1812 | if (!ToLexicalDCOrErr) |
| 1813 | return ToLexicalDCOrErr.takeError(); |
| 1814 | ToLexicalDC = *ToLexicalDCOrErr; |
| 1815 | } else |
| 1816 | ToLexicalDC = ToDC; |
| 1817 | |
| 1818 | return Error::success(); |
| 1819 | } |
| 1820 | |
| 1821 | Error ASTNodeImporter::ImportImplicitMethods( |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1822 | const CXXRecordDecl *From, CXXRecordDecl *To) { |
| 1823 | assert(From->isCompleteDefinition() && To->getDefinition() == To && |
| 1824 | "Import implicit methods to or from non-definition"); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1825 | |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1826 | for (CXXMethodDecl *FromM : From->methods()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1827 | if (FromM->isImplicit()) { |
| 1828 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); |
| 1829 | if (!ToMOrErr) |
| 1830 | return ToMOrErr.takeError(); |
| 1831 | } |
| 1832 | |
| 1833 | return Error::success(); |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1834 | } |
| 1835 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1836 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1837 | ASTImporter &Importer) { |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1838 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 1839 | if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef)) |
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 1840 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); |
| 1841 | else |
| 1842 | return ToTypedefOrErr.takeError(); |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1843 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1844 | return Error::success(); |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1845 | } |
| 1846 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1847 | Error ASTNodeImporter::ImportDefinition( |
| 1848 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1849 | auto DefinitionCompleter = [To]() { |
| 1850 | // There are cases in LLDB when we first import a class without its |
| 1851 | // members. The class will have DefinitionData, but no members. Then, |
| 1852 | // importDefinition is called from LLDB, which tries to get the members, so |
| 1853 | // when we get here, the class already has the DefinitionData set, so we |
| 1854 | // must unset the CompleteDefinition here to be able to complete again the |
| 1855 | // definition. |
| 1856 | To->setCompleteDefinition(false); |
| 1857 | To->completeDefinition(); |
| 1858 | }; |
| 1859 | |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1860 | if (To->getDefinition() || To->isBeingDefined()) { |
| Gabor Marton | e73805f | 2019-07-08 12:49:13 +0000 | [diff] [blame] | 1861 | if (Kind == IDK_Everything || |
| 1862 | // In case of lambdas, the class already has a definition ptr set, but |
| 1863 | // the contained decls are not imported yet. Also, isBeingDefined was |
| 1864 | // set in CXXRecordDecl::CreateLambda. We must import the contained |
| 1865 | // decls here and finish the definition. |
| 1866 | (To->isLambda() && shouldForceImportDeclContext(Kind))) { |
| 1867 | Error Result = ImportDeclContext(From, /*ForceImport=*/true); |
| 1868 | // Finish the definition of the lambda, set isBeingDefined to false. |
| 1869 | if (To->isLambda()) |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1870 | DefinitionCompleter(); |
| Gabor Marton | e73805f | 2019-07-08 12:49:13 +0000 | [diff] [blame] | 1871 | return Result; |
| 1872 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1873 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1874 | return Error::success(); |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1875 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1876 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1877 | To->startDefinition(); |
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1878 | // Complete the definition even if error is returned. |
| 1879 | // The RecordDecl may be already part of the AST so it is better to |
| 1880 | // have it in complete state even if something is wrong with it. |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1881 | auto DefinitionCompleterScopeExit = |
| 1882 | llvm::make_scope_exit(DefinitionCompleter); |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1883 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1884 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1885 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1886 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1887 | // Add base classes. |
| Gabor Marton | 17d3967 | 2018-11-26 15:54:08 +0000 | [diff] [blame] | 1888 | auto *ToCXX = dyn_cast<CXXRecordDecl>(To); |
| 1889 | auto *FromCXX = dyn_cast<CXXRecordDecl>(From); |
| 1890 | if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) { |
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1891 | |
| 1892 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1893 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 1894 | |
| 1895 | #define FIELD(Name, Width, Merge) \ |
| 1896 | ToData.Name = FromData.Name; |
| 1897 | #include "clang/AST/CXXRecordDeclDefinitionBits.def" |
| Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1898 | |
| Shafik Yaghmour | 16b9073 | 2019-04-26 18:51:28 +0000 | [diff] [blame] | 1899 | // Copy over the data stored in RecordDeclBits |
| 1900 | ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions()); |
| 1901 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1902 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1903 | for (const auto &Base1 : FromCXX->bases()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1904 | ExpectedType TyOrErr = import(Base1.getType()); |
| 1905 | if (!TyOrErr) |
| 1906 | return TyOrErr.takeError(); |
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1907 | |
| 1908 | SourceLocation EllipsisLoc; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1909 | if (Base1.isPackExpansion()) { |
| 1910 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) |
| 1911 | EllipsisLoc = *LocOrErr; |
| 1912 | else |
| 1913 | return LocOrErr.takeError(); |
| 1914 | } |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1915 | |
| 1916 | // Ensure that we have a definition for the base. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1917 | if (Error Err = |
| 1918 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) |
| 1919 | return Err; |
| 1920 | |
| 1921 | auto RangeOrErr = import(Base1.getSourceRange()); |
| 1922 | if (!RangeOrErr) |
| 1923 | return RangeOrErr.takeError(); |
| 1924 | |
| 1925 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); |
| 1926 | if (!TSIOrErr) |
| 1927 | return TSIOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1928 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1929 | Bases.push_back( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1930 | new (Importer.getToContext()) CXXBaseSpecifier( |
| 1931 | *RangeOrErr, |
| 1932 | Base1.isVirtual(), |
| 1933 | Base1.isBaseOfClass(), |
| 1934 | Base1.getAccessSpecifierAsWritten(), |
| 1935 | *TSIOrErr, |
| 1936 | EllipsisLoc)); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1937 | } |
| 1938 | if (!Bases.empty()) |
| Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1939 | ToCXX->setBases(Bases.data(), Bases.size()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1940 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1941 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1942 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1943 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1944 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1945 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1946 | return Error::success(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1947 | } |
| 1948 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1949 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1950 | if (To->getAnyInitializer()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1951 | return Error::success(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1952 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1953 | Expr *FromInit = From->getInit(); |
| 1954 | if (!FromInit) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1955 | return Error::success(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1956 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1957 | ExpectedExpr ToInitOrErr = import(FromInit); |
| 1958 | if (!ToInitOrErr) |
| 1959 | return ToInitOrErr.takeError(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1960 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1961 | To->setInit(*ToInitOrErr); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1962 | if (From->isInitKnownICE()) { |
| 1963 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); |
| 1964 | Eval->CheckedICE = true; |
| 1965 | Eval->IsICE = From->isInitICE(); |
| 1966 | } |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1967 | |
| 1968 | // FIXME: Other bits to merge? |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1969 | return Error::success(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1970 | } |
| 1971 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1972 | Error ASTNodeImporter::ImportDefinition( |
| 1973 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1974 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1975 | if (Kind == IDK_Everything) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1976 | return ImportDeclContext(From, /*ForceImport=*/true); |
| 1977 | return Error::success(); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1978 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1979 | |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1980 | To->startDefinition(); |
| 1981 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1982 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1983 | return Err; |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1984 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1985 | ExpectedType ToTypeOrErr = |
| 1986 | import(Importer.getFromContext().getTypeDeclType(From)); |
| 1987 | if (!ToTypeOrErr) |
| 1988 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1989 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1990 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); |
| 1991 | if (!ToPromotionTypeOrErr) |
| 1992 | return ToPromotionTypeOrErr.takeError(); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1993 | |
| 1994 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1995 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1996 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1997 | |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1998 | // FIXME: we might need to merge the number of positive or negative bits |
| 1999 | // if the enumerator lists don't match. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2000 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2001 | From->getNumPositiveBits(), |
| 2002 | From->getNumNegativeBits()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2003 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 2004 | } |
| 2005 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2006 | Error ASTNodeImporter::ImportTemplateArguments( |
| 2007 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 2008 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 2009 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2010 | if (auto ToOrErr = import(FromArgs[I])) |
| 2011 | ToArgs.push_back(*ToOrErr); |
| 2012 | else |
| 2013 | return ToOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 2014 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2015 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2016 | return Error::success(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 2017 | } |
| 2018 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2019 | // FIXME: Do not forget to remove this and use only 'import'. |
| 2020 | Expected<TemplateArgument> |
| 2021 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 2022 | return import(From); |
| 2023 | } |
| 2024 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2025 | template <typename InContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2026 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2027 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 2028 | for (const auto &FromLoc : Container) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2029 | if (auto ToLocOrErr = import(FromLoc)) |
| 2030 | ToTAInfo.addArgument(*ToLocOrErr); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2031 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2032 | return ToLocOrErr.takeError(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2033 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2034 | return Error::success(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2037 | static StructuralEquivalenceKind |
| 2038 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 2039 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 2040 | : StructuralEquivalenceKind::Default; |
| 2041 | } |
| 2042 | |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2043 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { |
| 2044 | StructuralEquivalenceContext Ctx( |
| 2045 | Importer.getFromContext(), Importer.getToContext(), |
| 2046 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2047 | false, Complain); |
| 2048 | return Ctx.IsEquivalent(From, To); |
| 2049 | } |
| 2050 | |
| 2051 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2052 | RecordDecl *ToRecord, bool Complain) { |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2053 | // Eliminate a potential failure point where we attempt to re-import |
| 2054 | // something we're trying to import while completing ToRecord. |
| 2055 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 2056 | if (ToOrigin) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2057 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2058 | if (ToOriginRecord) |
| 2059 | ToRecord = ToOriginRecord; |
| 2060 | } |
| 2061 | |
| Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 2062 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2063 | ToRecord->getASTContext(), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2064 | Importer.getNonEquivalentDecls(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2065 | getStructuralEquivalenceKind(Importer), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2066 | false, Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2067 | return Ctx.IsEquivalent(FromRecord, ToRecord); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2068 | } |
| 2069 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2070 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 2071 | bool Complain) { |
| 2072 | StructuralEquivalenceContext Ctx( |
| 2073 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2074 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2075 | false, Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2076 | return Ctx.IsEquivalent(FromVar, ToVar); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2077 | } |
| 2078 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2079 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
| Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 2080 | // Eliminate a potential failure point where we attempt to re-import |
| Raphael Isemann | fa26c20 | 2019-04-09 14:18:23 +0000 | [diff] [blame] | 2081 | // something we're trying to import while completing ToEnum. |
| Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 2082 | if (Decl *ToOrigin = Importer.GetOriginalDecl(ToEnum)) |
| 2083 | if (auto *ToOriginEnum = dyn_cast<EnumDecl>(ToOrigin)) |
| 2084 | ToEnum = ToOriginEnum; |
| 2085 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2086 | StructuralEquivalenceContext Ctx( |
| 2087 | Importer.getFromContext(), Importer.getToContext(), |
| 2088 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2089 | return Ctx.IsEquivalent(FromEnum, ToEnum); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2092 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 2093 | FunctionTemplateDecl *To) { |
| 2094 | StructuralEquivalenceContext Ctx( |
| 2095 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2096 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2097 | false, false); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2098 | return Ctx.IsEquivalent(From, To); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2099 | } |
| 2100 | |
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2101 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 2102 | StructuralEquivalenceContext Ctx( |
| 2103 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2104 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2105 | false, false); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2106 | return Ctx.IsEquivalent(From, To); |
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2107 | } |
| 2108 | |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2109 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2110 | EnumConstantDecl *ToEC) { |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2111 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 2112 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 2113 | |
| 2114 | return FromVal.isSigned() == ToVal.isSigned() && |
| 2115 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 2116 | FromVal == ToVal; |
| 2117 | } |
| 2118 | |
| 2119 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2120 | ClassTemplateDecl *To) { |
| 2121 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2122 | Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2123 | Importer.getNonEquivalentDecls(), |
| 2124 | getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2125 | return Ctx.IsEquivalent(From, To); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2126 | } |
| 2127 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2128 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 2129 | VarTemplateDecl *To) { |
| 2130 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2131 | Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2132 | Importer.getNonEquivalentDecls(), |
| 2133 | getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2134 | return Ctx.IsEquivalent(From, To); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2137 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 2138 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2139 | << D->getDeclKindName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2140 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2141 | } |
| 2142 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2143 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { |
| 2144 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 2145 | << D->getDeclKindName(); |
| 2146 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| 2147 | } |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2148 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2149 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 2150 | // Import the context of this declaration. |
| 2151 | DeclContext *DC, *LexicalDC; |
| 2152 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 2153 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2154 | |
| 2155 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2156 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2157 | if (!LocOrErr) |
| 2158 | return LocOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2159 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2160 | EmptyDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2161 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2162 | return ToD; |
| 2163 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2164 | ToD->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2165 | LexicalDC->addDeclInternal(ToD); |
| 2166 | return ToD; |
| 2167 | } |
| 2168 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2169 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2170 | TranslationUnitDecl *ToD = |
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2171 | Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2172 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2173 | Importer.MapImported(D, ToD); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2174 | |
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2175 | return ToD; |
| 2176 | } |
| 2177 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2178 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 2179 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2180 | if (!LocOrErr) |
| 2181 | return LocOrErr.takeError(); |
| 2182 | auto ColonLocOrErr = import(D->getColonLoc()); |
| 2183 | if (!ColonLocOrErr) |
| 2184 | return ColonLocOrErr.takeError(); |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2185 | |
| 2186 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2187 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2188 | if (!DCOrErr) |
| 2189 | return DCOrErr.takeError(); |
| 2190 | DeclContext *DC = *DCOrErr; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2191 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2192 | AccessSpecDecl *ToD; |
| 2193 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2194 | DC, *LocOrErr, *ColonLocOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2195 | return ToD; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2196 | |
| 2197 | // Lexical DeclContext and Semantic DeclContext |
| 2198 | // is always the same for the accessSpec. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2199 | ToD->setLexicalDeclContext(DC); |
| 2200 | DC->addDeclInternal(ToD); |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2201 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2202 | return ToD; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2203 | } |
| 2204 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2205 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 2206 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2207 | if (!DCOrErr) |
| 2208 | return DCOrErr.takeError(); |
| 2209 | DeclContext *DC = *DCOrErr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2210 | DeclContext *LexicalDC = DC; |
| 2211 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2212 | SourceLocation ToLocation, ToRParenLoc; |
| 2213 | Expr *ToAssertExpr; |
| 2214 | StringLiteral *ToMessage; |
| 2215 | if (auto Imp = importSeq( |
| 2216 | D->getLocation(), D->getAssertExpr(), D->getMessage(), D->getRParenLoc())) |
| 2217 | std::tie(ToLocation, ToAssertExpr, ToMessage, ToRParenLoc) = *Imp; |
| 2218 | else |
| 2219 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2220 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2221 | StaticAssertDecl *ToD; |
| 2222 | if (GetImportedOrCreateDecl( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2223 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, |
| 2224 | ToRParenLoc, D->isFailed())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2225 | return ToD; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2226 | |
| 2227 | ToD->setLexicalDeclContext(LexicalDC); |
| 2228 | LexicalDC->addDeclInternal(ToD); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2229 | return ToD; |
| 2230 | } |
| 2231 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2232 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2233 | // Import the major distinguishing characteristics of this namespace. |
| 2234 | DeclContext *DC, *LexicalDC; |
| 2235 | DeclarationName Name; |
| 2236 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2237 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2238 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2239 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2240 | if (ToD) |
| 2241 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2242 | |
| 2243 | NamespaceDecl *MergeWithNamespace = nullptr; |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2244 | if (!Name) { |
| 2245 | // This is an anonymous namespace. Adopt an existing anonymous |
| 2246 | // namespace if we can. |
| 2247 | // FIXME: Not testable. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2248 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2249 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 2250 | else |
| 2251 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 2252 | } else { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2253 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2254 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2255 | for (auto *FoundDecl : FoundDecls) { |
| 2256 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2257 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2258 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2259 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2260 | MergeWithNamespace = FoundNS; |
| 2261 | ConflictingDecls.clear(); |
| 2262 | break; |
| 2263 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2264 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2265 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2266 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2267 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2268 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2269 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2270 | Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(), |
| 2271 | ConflictingDecls.size()); |
| 2272 | if (NameOrErr) |
| 2273 | Name = NameOrErr.get(); |
| 2274 | else |
| 2275 | return NameOrErr.takeError(); |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2276 | } |
| 2277 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2278 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2279 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2280 | if (!BeginLocOrErr) |
| 2281 | return BeginLocOrErr.takeError(); |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2282 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 2283 | if (!RBraceLocOrErr) |
| 2284 | return RBraceLocOrErr.takeError(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2285 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2286 | // Create the "to" namespace, if needed. |
| 2287 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 2288 | if (!ToNamespace) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2289 | if (GetImportedOrCreateDecl( |
| 2290 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2291 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2292 | /*PrevDecl=*/nullptr)) |
| 2293 | return ToNamespace; |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2294 | ToNamespace->setRBraceLoc(*RBraceLocOrErr); |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2295 | ToNamespace->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2296 | LexicalDC->addDeclInternal(ToNamespace); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2297 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2298 | // If this is an anonymous namespace, register it as the anonymous |
| 2299 | // namespace within its context. |
| 2300 | if (!Name) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2301 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2302 | TU->setAnonymousNamespace(ToNamespace); |
| 2303 | else |
| 2304 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 2305 | } |
| 2306 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2307 | Importer.MapImported(D, ToNamespace); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2308 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2309 | if (Error Err = ImportDeclContext(D)) |
| 2310 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2311 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2312 | return ToNamespace; |
| 2313 | } |
| 2314 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2315 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2316 | // Import the major distinguishing characteristics of this namespace. |
| 2317 | DeclContext *DC, *LexicalDC; |
| 2318 | DeclarationName Name; |
| 2319 | SourceLocation Loc; |
| 2320 | NamedDecl *LookupD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2321 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 2322 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2323 | if (LookupD) |
| 2324 | return LookupD; |
| 2325 | |
| 2326 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 2327 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2328 | SourceLocation ToNamespaceLoc, ToAliasLoc, ToTargetNameLoc; |
| 2329 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2330 | NamespaceDecl *ToNamespace; |
| 2331 | if (auto Imp = importSeq( |
| 2332 | D->getNamespaceLoc(), D->getAliasLoc(), D->getQualifierLoc(), |
| 2333 | D->getTargetNameLoc(), D->getNamespace())) |
| 2334 | std::tie( |
| 2335 | ToNamespaceLoc, ToAliasLoc, ToQualifierLoc, ToTargetNameLoc, |
| 2336 | ToNamespace) = *Imp; |
| 2337 | else |
| 2338 | return Imp.takeError(); |
| 2339 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2340 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2341 | NamespaceAliasDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2342 | if (GetImportedOrCreateDecl( |
| 2343 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, |
| 2344 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2345 | return ToD; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2346 | |
| 2347 | ToD->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2348 | LexicalDC->addDeclInternal(ToD); |
| 2349 | |
| 2350 | return ToD; |
| 2351 | } |
| 2352 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2353 | ExpectedDecl |
| 2354 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2355 | // Import the major distinguishing characteristics of this typedef. |
| 2356 | DeclContext *DC, *LexicalDC; |
| 2357 | DeclarationName Name; |
| 2358 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2359 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2360 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2361 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2362 | if (ToD) |
| 2363 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2364 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2365 | // If this typedef is not in block scope, determine whether we've |
| 2366 | // seen a typedef with the same name (that we can merge with) or any |
| 2367 | // other entity by that name (which name lookup could conflict with). |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 2368 | // Note: Repeated typedefs are not valid in C99: |
| 2369 | // 'typedef int T; typedef int T;' is invalid |
| 2370 | // We do not care about this now. |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2371 | if (!DC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2372 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2373 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2374 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2375 | for (auto *FoundDecl : FoundDecls) { |
| 2376 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2377 | continue; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2378 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
| Balazs Keri | c86d47b | 2019-09-04 14:12:18 +0000 | [diff] [blame] | 2379 | if (!hasSameVisibilityContext(FoundTypedef, D)) |
| 2380 | continue; |
| 2381 | |
| Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2382 | QualType FromUT = D->getUnderlyingType(); |
| 2383 | QualType FoundUT = FoundTypedef->getUnderlyingType(); |
| 2384 | if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) { |
| 2385 | // If the "From" context has a complete underlying type but we |
| 2386 | // already have a complete underlying type then return with that. |
| 2387 | if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2388 | return Importer.MapImported(D, FoundTypedef); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2389 | // FIXME Handle redecl chain. When you do that make consistent changes |
| 2390 | // in ASTImporterLookupTable too. |
| 2391 | } else { |
| 2392 | ConflictingDecls.push_back(FoundDecl); |
| Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2393 | } |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2394 | } |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2395 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2396 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2397 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2398 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2399 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 2400 | if (NameOrErr) |
| 2401 | Name = NameOrErr.get(); |
| 2402 | else |
| 2403 | return NameOrErr.takeError(); |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2404 | } |
| 2405 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2406 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2407 | QualType ToUnderlyingType; |
| 2408 | TypeSourceInfo *ToTypeSourceInfo; |
| 2409 | SourceLocation ToBeginLoc; |
| 2410 | if (auto Imp = importSeq( |
| 2411 | D->getUnderlyingType(), D->getTypeSourceInfo(), D->getBeginLoc())) |
| 2412 | std::tie(ToUnderlyingType, ToTypeSourceInfo, ToBeginLoc) = *Imp; |
| 2413 | else |
| 2414 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2415 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2416 | // Create the new typedef node. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2417 | // FIXME: ToUnderlyingType is not used. |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2418 | TypedefNameDecl *ToTypedef; |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2419 | if (IsAlias) { |
| 2420 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2421 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2422 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2423 | return ToTypedef; |
| 2424 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2425 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2426 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2427 | return ToTypedef; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2428 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2429 | ToTypedef->setAccess(D->getAccess()); |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2430 | ToTypedef->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2431 | |
| 2432 | // Templated declarations should not appear in DeclContext. |
| 2433 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 2434 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 2435 | LexicalDC->addDeclInternal(ToTypedef); |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2436 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2437 | return ToTypedef; |
| 2438 | } |
| 2439 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2440 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2441 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 2442 | } |
| 2443 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2444 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2445 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 2446 | } |
| 2447 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2448 | ExpectedDecl |
| 2449 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2450 | // Import the major distinguishing characteristics of this typedef. |
| 2451 | DeclContext *DC, *LexicalDC; |
| 2452 | DeclarationName Name; |
| 2453 | SourceLocation Loc; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2454 | NamedDecl *FoundD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2455 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
| 2456 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2457 | if (FoundD) |
| 2458 | return FoundD; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2459 | |
| 2460 | // If this typedef is not in block scope, determine whether we've |
| 2461 | // seen a typedef with the same name (that we can merge with) or any |
| 2462 | // other entity by that name (which name lookup could conflict with). |
| 2463 | if (!DC->isFunctionOrMethod()) { |
| 2464 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 2465 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2466 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2467 | for (auto *FoundDecl : FoundDecls) { |
| 2468 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2469 | continue; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2470 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2471 | return Importer.MapImported(D, FoundAlias); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2472 | ConflictingDecls.push_back(FoundDecl); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2476 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2477 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 2478 | if (NameOrErr) |
| 2479 | Name = NameOrErr.get(); |
| 2480 | else |
| 2481 | return NameOrErr.takeError(); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2482 | } |
| 2483 | } |
| 2484 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2485 | TemplateParameterList *ToTemplateParameters; |
| 2486 | TypeAliasDecl *ToTemplatedDecl; |
| 2487 | if (auto Imp = importSeq(D->getTemplateParameters(), D->getTemplatedDecl())) |
| 2488 | std::tie(ToTemplateParameters, ToTemplatedDecl) = *Imp; |
| 2489 | else |
| 2490 | return Imp.takeError(); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2491 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2492 | TypeAliasTemplateDecl *ToAlias; |
| 2493 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2494 | Name, ToTemplateParameters, ToTemplatedDecl)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2495 | return ToAlias; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2496 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2497 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2498 | |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2499 | ToAlias->setAccess(D->getAccess()); |
| 2500 | ToAlias->setLexicalDeclContext(LexicalDC); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2501 | LexicalDC->addDeclInternal(ToAlias); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2502 | return ToAlias; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2503 | } |
| 2504 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2505 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2506 | // Import the major distinguishing characteristics of this label. |
| 2507 | DeclContext *DC, *LexicalDC; |
| 2508 | DeclarationName Name; |
| 2509 | SourceLocation Loc; |
| 2510 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2511 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2512 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2513 | if (ToD) |
| 2514 | return ToD; |
| 2515 | |
| 2516 | assert(LexicalDC->isFunctionOrMethod()); |
| 2517 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2518 | LabelDecl *ToLabel; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2519 | if (D->isGnuLocal()) { |
| 2520 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2521 | if (!BeginLocOrErr) |
| 2522 | return BeginLocOrErr.takeError(); |
| 2523 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2524 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) |
| 2525 | return ToLabel; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2526 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2527 | } else { |
| 2528 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2529 | Name.getAsIdentifierInfo())) |
| 2530 | return ToLabel; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2531 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); |
| 2535 | if (!ToStmtOrErr) |
| 2536 | return ToStmtOrErr.takeError(); |
| 2537 | |
| 2538 | ToLabel->setStmt(*ToStmtOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2539 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2540 | LexicalDC->addDeclInternal(ToLabel); |
| 2541 | return ToLabel; |
| 2542 | } |
| 2543 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2544 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2545 | // Import the major distinguishing characteristics of this enum. |
| 2546 | DeclContext *DC, *LexicalDC; |
| 2547 | DeclarationName Name; |
| 2548 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2549 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2550 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2551 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2552 | if (ToD) |
| 2553 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2554 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2555 | // Figure out what enum name we're looking for. |
| 2556 | unsigned IDNS = Decl::IDNS_Tag; |
| 2557 | DeclarationName SearchName = Name; |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2558 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2559 | if (Error Err = importInto( |
| 2560 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2561 | return std::move(Err); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2562 | IDNS = Decl::IDNS_Ordinary; |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2563 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2564 | IDNS |= Decl::IDNS_Ordinary; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2565 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2566 | // We may already have an enum of the same name; try to find and match it. |
| 2567 | if (!DC->isFunctionOrMethod() && SearchName) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2568 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2569 | auto FoundDecls = |
| 2570 | Importer.findDeclsInToCtx(DC, SearchName); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2571 | for (auto *FoundDecl : FoundDecls) { |
| 2572 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2573 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2574 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2575 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2576 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2577 | FoundDecl = Tag->getDecl(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2578 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2579 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2580 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { |
| Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 2581 | if (!hasSameVisibilityContext(FoundEnum, D)) |
| 2582 | continue; |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2583 | if (IsStructuralMatch(D, FoundEnum)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2584 | return Importer.MapImported(D, FoundEnum); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2585 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2586 | } |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2587 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2588 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2589 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2590 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2591 | SearchName, DC, IDNS, ConflictingDecls.data(), |
| 2592 | ConflictingDecls.size()); |
| 2593 | if (NameOrErr) |
| 2594 | Name = NameOrErr.get(); |
| 2595 | else |
| 2596 | return NameOrErr.takeError(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2597 | } |
| 2598 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2599 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2600 | SourceLocation ToBeginLoc; |
| 2601 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2602 | QualType ToIntegerType; |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2603 | SourceRange ToBraceRange; |
| 2604 | if (auto Imp = importSeq(D->getBeginLoc(), D->getQualifierLoc(), |
| 2605 | D->getIntegerType(), D->getBraceRange())) |
| 2606 | std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType, ToBraceRange) = *Imp; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2607 | else |
| 2608 | return Imp.takeError(); |
| 2609 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2610 | // Create the enum declaration. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2611 | EnumDecl *D2; |
| 2612 | if (GetImportedOrCreateDecl( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2613 | D2, D, Importer.getToContext(), DC, ToBeginLoc, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2614 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), |
| 2615 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2616 | return D2; |
| 2617 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2618 | D2->setQualifierInfo(ToQualifierLoc); |
| 2619 | D2->setIntegerType(ToIntegerType); |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2620 | D2->setBraceRange(ToBraceRange); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2621 | D2->setAccess(D->getAccess()); |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2622 | D2->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2623 | LexicalDC->addDeclInternal(D2); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2624 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2625 | // Import the definition |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2626 | if (D->isCompleteDefinition()) |
| 2627 | if (Error Err = ImportDefinition(D, D2)) |
| 2628 | return std::move(Err); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2629 | |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2630 | return D2; |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2631 | } |
| 2632 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2633 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2634 | bool IsFriendTemplate = false; |
| 2635 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2636 | IsFriendTemplate = |
| 2637 | DCXX->getDescribedClassTemplate() && |
| 2638 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != |
| 2639 | Decl::FOK_None; |
| 2640 | } |
| 2641 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2642 | // Import the major distinguishing characteristics of this record. |
| Simon Pilgrim | 4706f3b | 2019-10-15 10:23:05 +0000 | [diff] [blame] | 2643 | DeclContext *DC = nullptr, *LexicalDC = nullptr; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2644 | DeclarationName Name; |
| 2645 | SourceLocation Loc; |
| Simon Pilgrim | 4706f3b | 2019-10-15 10:23:05 +0000 | [diff] [blame] | 2646 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2647 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2648 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2649 | if (ToD) |
| 2650 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2651 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2652 | // Figure out what structure name we're looking for. |
| 2653 | unsigned IDNS = Decl::IDNS_Tag; |
| 2654 | DeclarationName SearchName = Name; |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2655 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2656 | if (Error Err = importInto( |
| 2657 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2658 | return std::move(Err); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2659 | IDNS = Decl::IDNS_Ordinary; |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2660 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2661 | IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2662 | |
| 2663 | // 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] | 2664 | RecordDecl *PrevDecl = nullptr; |
| Gabor Marton | e3e83d7 | 2019-08-30 10:55:41 +0000 | [diff] [blame] | 2665 | if (!DC->isFunctionOrMethod() && !D->isLambda()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2666 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2667 | auto FoundDecls = |
| 2668 | Importer.findDeclsInToCtx(DC, SearchName); |
| Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2669 | if (!FoundDecls.empty()) { |
| Gabor Marton | 41e3892 | 2019-03-05 11:23:24 +0000 | [diff] [blame] | 2670 | // We're going to have to compare D against potentially conflicting Decls, |
| 2671 | // so complete it. |
| Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2672 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2673 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2674 | } |
| 2675 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2676 | for (auto *FoundDecl : FoundDecls) { |
| 2677 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2678 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2679 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2680 | Decl *Found = FoundDecl; |
| 2681 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2682 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2683 | Found = Tag->getDecl(); |
| 2684 | } |
| Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2685 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2686 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2687 | // Do not emit false positive diagnostic in case of unnamed |
| 2688 | // struct/union and in case of anonymous structs. Would be false |
| 2689 | // because there may be several anonymous/unnamed structs in a class. |
| 2690 | // E.g. these are both valid: |
| 2691 | // struct A { // unnamed structs |
| 2692 | // struct { struct A *next; } entry0; |
| 2693 | // struct { struct A *next; } entry1; |
| 2694 | // }; |
| 2695 | // struct X { struct { int a; }; struct { int b; }; }; // anon structs |
| 2696 | if (!SearchName) |
| Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2697 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2698 | continue; |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2699 | |
| Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 2700 | if (!hasSameVisibilityContext(FoundRecord, D)) |
| 2701 | continue; |
| 2702 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2703 | if (IsStructuralMatch(D, FoundRecord)) { |
| 2704 | RecordDecl *FoundDef = FoundRecord->getDefinition(); |
| 2705 | if (D->isThisDeclarationADefinition() && FoundDef) { |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2706 | // FIXME: Structural equivalence check should check for same |
| 2707 | // user-defined methods. |
| 2708 | Importer.MapImported(D, FoundDef); |
| 2709 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2710 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); |
| 2711 | assert(FoundCXX && "Record type mismatch"); |
| 2712 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2713 | if (!Importer.isMinimalImport()) |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2714 | // FoundDef may not have every implicit method that D has |
| 2715 | // because implicit methods are created only if they are used. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2716 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) |
| 2717 | return std::move(Err); |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2718 | } |
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2719 | } |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2720 | PrevDecl = FoundRecord->getMostRecentDecl(); |
| 2721 | break; |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2722 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2723 | ConflictingDecls.push_back(FoundDecl); |
| 2724 | } // kind is RecordDecl |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2725 | } // for |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2726 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2727 | if (!ConflictingDecls.empty() && SearchName) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2728 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2729 | SearchName, DC, IDNS, ConflictingDecls.data(), |
| 2730 | ConflictingDecls.size()); |
| 2731 | if (NameOrErr) |
| 2732 | Name = NameOrErr.get(); |
| 2733 | else |
| 2734 | return NameOrErr.takeError(); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2735 | } |
| 2736 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2737 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2738 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2739 | if (!BeginLocOrErr) |
| 2740 | return BeginLocOrErr.takeError(); |
| 2741 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2742 | // Create the record declaration. |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2743 | RecordDecl *D2 = nullptr; |
| 2744 | CXXRecordDecl *D2CXX = nullptr; |
| 2745 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2746 | if (DCXX->isLambda()) { |
| 2747 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); |
| 2748 | if (!TInfoOrErr) |
| 2749 | return TInfoOrErr.takeError(); |
| 2750 | if (GetImportedOrCreateSpecialDecl( |
| 2751 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
| 2752 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), |
| 2753 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2754 | return D2CXX; |
| 2755 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); |
| 2756 | if (!CDeclOrErr) |
| 2757 | return CDeclOrErr.takeError(); |
| Michael Liao | 243ebfb | 2019-10-19 00:15:19 +0000 | [diff] [blame] | 2758 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr, |
| 2759 | DCXX->hasKnownLambdaInternalLinkage()); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2760 | } else if (DCXX->isInjectedClassName()) { |
| 2761 | // We have to be careful to do a similar dance to the one in |
| 2762 | // Sema::ActOnStartCXXMemberDeclarations |
| 2763 | const bool DelayTypeCreation = true; |
| 2764 | if (GetImportedOrCreateDecl( |
| 2765 | D2CXX, D, Importer.getToContext(), D->getTagKind(), DC, |
| 2766 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
| 2767 | cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation)) |
| 2768 | return D2CXX; |
| 2769 | Importer.getToContext().getTypeDeclType( |
| 2770 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
| 2771 | } else { |
| 2772 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2773 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2774 | Name.getAsIdentifierInfo(), |
| 2775 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2776 | return D2CXX; |
| 2777 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2778 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2779 | D2 = D2CXX; |
| 2780 | D2->setAccess(D->getAccess()); |
| 2781 | D2->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 2782 | addDeclToContexts(D, D2); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2783 | |
| 2784 | if (ClassTemplateDecl *FromDescribed = |
| 2785 | DCXX->getDescribedClassTemplate()) { |
| 2786 | ClassTemplateDecl *ToDescribed; |
| 2787 | if (Error Err = importInto(ToDescribed, FromDescribed)) |
| 2788 | return std::move(Err); |
| 2789 | D2CXX->setDescribedClassTemplate(ToDescribed); |
| 2790 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { |
| 2791 | // In a record describing a template the type should be an |
| 2792 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2793 | // previously set type to the correct value here (ToDescribed is not |
| 2794 | // available at record create). |
| 2795 | // FIXME: The previous type is cleared but not removed from |
| 2796 | // ASTContext's internal storage. |
| 2797 | CXXRecordDecl *Injected = nullptr; |
| 2798 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2799 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2800 | if (Record && Record->isInjectedClassName()) { |
| 2801 | Injected = Record; |
| 2802 | break; |
| Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2803 | } |
| 2804 | } |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2805 | // Create an injected type for the whole redecl chain. |
| 2806 | SmallVector<Decl *, 2> Redecls = |
| 2807 | getCanonicalForwardRedeclChain(D2CXX); |
| 2808 | for (auto *R : Redecls) { |
| 2809 | auto *RI = cast<CXXRecordDecl>(R); |
| 2810 | RI->setTypeForDecl(nullptr); |
| 2811 | // Below we create a new injected type and assign that to the |
| 2812 | // canonical decl, subsequent declarations in the chain will reuse |
| 2813 | // that type. |
| 2814 | Importer.getToContext().getInjectedClassNameType( |
| 2815 | RI, ToDescribed->getInjectedClassNameSpecialization()); |
| 2816 | } |
| 2817 | // Set the new type for the previous injected decl too. |
| 2818 | if (Injected) { |
| 2819 | Injected->setTypeForDecl(nullptr); |
| 2820 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2821 | } |
| 2822 | } |
| 2823 | } else if (MemberSpecializationInfo *MemberInfo = |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2824 | DCXX->getMemberSpecializationInfo()) { |
| 2825 | TemplateSpecializationKind SK = |
| 2826 | MemberInfo->getTemplateSpecializationKind(); |
| 2827 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2828 | |
| 2829 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) |
| 2830 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); |
| 2831 | else |
| 2832 | return ToInstOrErr.takeError(); |
| 2833 | |
| 2834 | if (ExpectedSLoc POIOrErr = |
| 2835 | import(MemberInfo->getPointOfInstantiation())) |
| 2836 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2837 | *POIOrErr); |
| 2838 | else |
| 2839 | return POIOrErr.takeError(); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2840 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2841 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2842 | } else { |
| 2843 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
| 2844 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2845 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2846 | return D2; |
| 2847 | D2->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 2848 | addDeclToContexts(D, D2); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2849 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2850 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 2851 | if (auto BraceRangeOrErr = import(D->getBraceRange())) |
| 2852 | D2->setBraceRange(*BraceRangeOrErr); |
| 2853 | else |
| 2854 | return BraceRangeOrErr.takeError(); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2855 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) |
| 2856 | D2->setQualifierInfo(*QualifierLocOrErr); |
| 2857 | else |
| 2858 | return QualifierLocOrErr.takeError(); |
| 2859 | |
| 2860 | if (D->isAnonymousStructOrUnion()) |
| 2861 | D2->setAnonymousStructOrUnion(true); |
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2862 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2863 | if (D->isCompleteDefinition()) |
| 2864 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) |
| 2865 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2866 | |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2867 | return D2; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2868 | } |
| 2869 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2870 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2871 | // Import the major distinguishing characteristics of this enumerator. |
| 2872 | DeclContext *DC, *LexicalDC; |
| 2873 | DeclarationName Name; |
| 2874 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2875 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2876 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2877 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2878 | if (ToD) |
| 2879 | return ToD; |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2880 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2881 | // Determine whether there are any other declarations with the same name and |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2882 | // in the same context. |
| 2883 | if (!LexicalDC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2884 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2885 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2886 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2887 | for (auto *FoundDecl : FoundDecls) { |
| 2888 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2889 | continue; |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2890 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2891 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2892 | if (IsStructuralMatch(D, FoundEnumConstant)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2893 | return Importer.MapImported(D, FoundEnumConstant); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2894 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2895 | } |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2896 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2897 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2898 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 2899 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 2900 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 2901 | if (NameOrErr) |
| 2902 | Name = NameOrErr.get(); |
| 2903 | else |
| 2904 | return NameOrErr.takeError(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2905 | } |
| 2906 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2907 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2908 | ExpectedType TypeOrErr = import(D->getType()); |
| 2909 | if (!TypeOrErr) |
| 2910 | return TypeOrErr.takeError(); |
| 2911 | |
| 2912 | ExpectedExpr InitOrErr = import(D->getInitExpr()); |
| 2913 | if (!InitOrErr) |
| 2914 | return InitOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2915 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2916 | EnumConstantDecl *ToEnumerator; |
| 2917 | if (GetImportedOrCreateDecl( |
| 2918 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2919 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2920 | return ToEnumerator; |
| 2921 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2922 | ToEnumerator->setAccess(D->getAccess()); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2923 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2924 | LexicalDC->addDeclInternal(ToEnumerator); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2925 | return ToEnumerator; |
| 2926 | } |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2927 | |
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 2928 | Error ASTNodeImporter::ImportTemplateParameterLists(const DeclaratorDecl *FromD, |
| 2929 | DeclaratorDecl *ToD) { |
| 2930 | unsigned int Num = FromD->getNumTemplateParameterLists(); |
| 2931 | if (Num == 0) |
| 2932 | return Error::success(); |
| 2933 | SmallVector<TemplateParameterList *, 2> ToTPLists(Num); |
| 2934 | for (unsigned int I = 0; I < Num; ++I) |
| 2935 | if (Expected<TemplateParameterList *> ToTPListOrErr = |
| 2936 | import(FromD->getTemplateParameterList(I))) |
| 2937 | ToTPLists[I] = *ToTPListOrErr; |
| 2938 | else |
| 2939 | return ToTPListOrErr.takeError(); |
| 2940 | ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists); |
| 2941 | return Error::success(); |
| 2942 | } |
| 2943 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2944 | Error ASTNodeImporter::ImportTemplateInformation( |
| 2945 | FunctionDecl *FromFD, FunctionDecl *ToFD) { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2946 | switch (FromFD->getTemplatedKind()) { |
| 2947 | case FunctionDecl::TK_NonTemplate: |
| 2948 | case FunctionDecl::TK_FunctionTemplate: |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2949 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2950 | |
| 2951 | case FunctionDecl::TK_MemberSpecialization: { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2952 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2953 | |
| 2954 | if (Expected<FunctionDecl *> InstFDOrErr = |
| 2955 | import(FromFD->getInstantiatedFromMemberFunction())) |
| 2956 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); |
| 2957 | else |
| 2958 | return InstFDOrErr.takeError(); |
| 2959 | |
| 2960 | if (ExpectedSLoc POIOrErr = import( |
| 2961 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) |
| 2962 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); |
| 2963 | else |
| 2964 | return POIOrErr.takeError(); |
| 2965 | |
| 2966 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2970 | auto FunctionAndArgsOrErr = |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2971 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2972 | if (!FunctionAndArgsOrErr) |
| 2973 | return FunctionAndArgsOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2974 | |
| 2975 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2976 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2977 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2978 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2979 | TemplateArgumentListInfo ToTAInfo; |
| 2980 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2981 | if (FromTAArgsAsWritten) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2982 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2983 | *FromTAArgsAsWritten, ToTAInfo)) |
| 2984 | return Err; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2985 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2986 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); |
| 2987 | if (!POIOrErr) |
| 2988 | return POIOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2989 | |
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 2990 | if (Error Err = ImportTemplateParameterLists(FromFD, ToFD)) |
| 2991 | return Err; |
| 2992 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2993 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2994 | ToFD->setFunctionTemplateSpecialization( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2995 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, |
| 2996 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); |
| 2997 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2998 | } |
| 2999 | |
| 3000 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 3001 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 3002 | UnresolvedSet<8> TemplDecls; |
| 3003 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 3004 | for (unsigned I = 0; I < NumTemplates; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3005 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = |
| 3006 | import(FromInfo->getTemplate(I))) |
| 3007 | TemplDecls.addDecl(*ToFTDOrErr); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3008 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3009 | return ToFTDOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3010 | } |
| 3011 | |
| 3012 | // Import TemplateArgumentListInfo. |
| 3013 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3014 | if (Error Err = ImportTemplateArgumentListInfo( |
| 3015 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 3016 | llvm::makeArrayRef( |
| 3017 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), |
| 3018 | ToTAInfo)) |
| 3019 | return Err; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3020 | |
| 3021 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 3022 | TemplDecls, ToTAInfo); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3023 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3024 | } |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3025 | } |
| Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 3026 | llvm_unreachable("All cases should be covered!"); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3027 | } |
| 3028 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3029 | Expected<FunctionDecl *> |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3030 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3031 | auto FunctionAndArgsOrErr = |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3032 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3033 | if (!FunctionAndArgsOrErr) |
| 3034 | return FunctionAndArgsOrErr.takeError(); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3035 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3036 | FunctionTemplateDecl *Template; |
| 3037 | TemplateArgsTy ToTemplArgs; |
| 3038 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3039 | void *InsertPos = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3040 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3041 | return FoundSpec; |
| 3042 | } |
| 3043 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3044 | Error ASTNodeImporter::ImportFunctionDeclBody(FunctionDecl *FromFD, |
| 3045 | FunctionDecl *ToFD) { |
| 3046 | if (Stmt *FromBody = FromFD->getBody()) { |
| 3047 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) |
| 3048 | ToFD->setBody(*ToBodyOrErr); |
| 3049 | else |
| 3050 | return ToBodyOrErr.takeError(); |
| 3051 | } |
| 3052 | return Error::success(); |
| 3053 | } |
| 3054 | |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3055 | // Returns true if the given D has a DeclContext up to the TranslationUnitDecl |
| 3056 | // which is equal to the given DC. |
| 3057 | bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) { |
| 3058 | const DeclContext *DCi = D->getDeclContext(); |
| 3059 | while (DCi != D->getTranslationUnitDecl()) { |
| 3060 | if (DCi == DC) |
| 3061 | return true; |
| 3062 | DCi = DCi->getParent(); |
| 3063 | } |
| 3064 | return false; |
| 3065 | } |
| 3066 | |
| 3067 | bool ASTNodeImporter::hasAutoReturnTypeDeclaredInside(FunctionDecl *D) { |
| 3068 | QualType FromTy = D->getType(); |
| 3069 | const FunctionProtoType *FromFPT = FromTy->getAs<FunctionProtoType>(); |
| 3070 | assert(FromFPT && "Must be called on FunctionProtoType"); |
| 3071 | if (AutoType *AutoT = FromFPT->getReturnType()->getContainedAutoType()) { |
| 3072 | QualType DeducedT = AutoT->getDeducedType(); |
| 3073 | if (const RecordType *RecordT = |
| 3074 | DeducedT.isNull() ? nullptr : dyn_cast<RecordType>(DeducedT)) { |
| 3075 | RecordDecl *RD = RecordT->getDecl(); |
| 3076 | assert(RD); |
| 3077 | if (isAncestorDeclContextOf(D, RD)) { |
| 3078 | assert(RD->getLexicalDeclContext() == RD->getDeclContext()); |
| 3079 | return true; |
| 3080 | } |
| 3081 | } |
| 3082 | } |
| 3083 | if (const TypedefType *TypedefT = |
| 3084 | dyn_cast<TypedefType>(FromFPT->getReturnType())) { |
| 3085 | TypedefNameDecl *TD = TypedefT->getDecl(); |
| 3086 | assert(TD); |
| 3087 | if (isAncestorDeclContextOf(D, TD)) { |
| 3088 | assert(TD->getLexicalDeclContext() == TD->getDeclContext()); |
| 3089 | return true; |
| 3090 | } |
| 3091 | } |
| 3092 | return false; |
| 3093 | } |
| 3094 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3095 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3096 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3097 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3098 | auto RedeclIt = Redecls.begin(); |
| 3099 | // Import the first part of the decl chain. I.e. import all previous |
| 3100 | // declarations starting from the canonical decl. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3101 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3102 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3103 | if (!ToRedeclOrErr) |
| 3104 | return ToRedeclOrErr.takeError(); |
| 3105 | } |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3106 | assert(*RedeclIt == D); |
| 3107 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3108 | // Import the major distinguishing characteristics of this function. |
| 3109 | DeclContext *DC, *LexicalDC; |
| 3110 | DeclarationName Name; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3111 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3112 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3113 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3114 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3115 | if (ToD) |
| 3116 | return ToD; |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3117 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3118 | FunctionDecl *FoundByLookup = nullptr; |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3119 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); |
| Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 3120 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3121 | // 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] | 3122 | // existing specialization in the "to" context. The lookup below will not |
| 3123 | // find any specialization, but would find the primary template; thus, we |
| 3124 | // have to skip normal lookup in case of specializations. |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3125 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 3126 | if (D->getTemplatedKind() == |
| 3127 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3128 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); |
| 3129 | if (!FoundFunctionOrErr) |
| 3130 | return FoundFunctionOrErr.takeError(); |
| 3131 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { |
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 3132 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 3133 | return Def; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3134 | FoundByLookup = FoundFunction; |
| 3135 | } |
| 3136 | } |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3137 | // Try to find a function in our own ("to") context with the same name, same |
| 3138 | // type, and in the same context as the function we're importing. |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3139 | else if (!LexicalDC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3140 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3141 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3142 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3143 | for (auto *FoundDecl : FoundDecls) { |
| 3144 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3145 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3146 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3147 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3148 | if (!hasSameVisibilityContext(FoundFunction, D)) |
| 3149 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3150 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3151 | if (IsStructuralMatch(D, FoundFunction)) { |
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 3152 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 3153 | return Def; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3154 | FoundByLookup = FoundFunction; |
| 3155 | break; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3156 | } |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3157 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 3158 | // Sema::IsOverload out to the AST library. |
| 3159 | |
| 3160 | // Function overloading is okay in C++. |
| 3161 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
| 3162 | continue; |
| 3163 | |
| 3164 | // Complain about inconsistent function types. |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3165 | Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3166 | << Name << D->getType() << FoundFunction->getType(); |
| 3167 | Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here) |
| 3168 | << FoundFunction->getType(); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3169 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3170 | } |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3171 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3172 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3173 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3174 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 3175 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 3176 | if (NameOrErr) |
| 3177 | Name = NameOrErr.get(); |
| 3178 | else |
| 3179 | return NameOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3180 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3181 | } |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3182 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3183 | // We do not allow more than one in-class declaration of a function. This is |
| 3184 | // because AST clients like VTableBuilder asserts on this. VTableBuilder |
| 3185 | // assumes there is only one in-class declaration. Building a redecl |
| 3186 | // chain would result in more than one in-class declaration for |
| 3187 | // overrides (even if they are part of the same redecl chain inside the |
| 3188 | // derived class.) |
| 3189 | if (FoundByLookup) { |
| Mikael Holmen | c1c97aa | 2019-01-29 06:53:31 +0000 | [diff] [blame] | 3190 | if (isa<CXXMethodDecl>(FoundByLookup)) { |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3191 | if (D->getLexicalDeclContext() == D->getDeclContext()) { |
| Balazs Keri | e9719f9 | 2019-08-07 12:40:17 +0000 | [diff] [blame] | 3192 | if (!D->doesThisDeclarationHaveABody()) { |
| 3193 | if (FunctionTemplateDecl *DescribedD = |
| 3194 | D->getDescribedFunctionTemplate()) { |
| 3195 | // Handle a "templated" function together with its described |
| 3196 | // template. This avoids need for a similar check at import of the |
| 3197 | // described template. |
| 3198 | assert(FoundByLookup->getDescribedFunctionTemplate() && |
| 3199 | "Templated function mapped to non-templated?"); |
| 3200 | Importer.MapImported(DescribedD, |
| 3201 | FoundByLookup->getDescribedFunctionTemplate()); |
| 3202 | } |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3203 | return Importer.MapImported(D, FoundByLookup); |
| Balazs Keri | e9719f9 | 2019-08-07 12:40:17 +0000 | [diff] [blame] | 3204 | } else { |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3205 | // Let's continue and build up the redecl chain in this case. |
| 3206 | // FIXME Merge the functions into one decl. |
| 3207 | } |
| 3208 | } |
| 3209 | } |
| 3210 | } |
| 3211 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3212 | DeclarationNameInfo NameInfo(Name, Loc); |
| 3213 | // Import additional name location/type info. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3214 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 3215 | return std::move(Err); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3216 | |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3217 | QualType FromTy = D->getType(); |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3218 | // Set to true if we do not import the type of the function as is. There are |
| 3219 | // cases when the original type would result in an infinite recursion during |
| 3220 | // the import. To avoid an infinite recursion when importing, we create the |
| 3221 | // FunctionDecl with a simplified function type and update it only after the |
| 3222 | // relevant AST nodes are already imported. |
| 3223 | bool UsedDifferentProtoType = false; |
| 3224 | if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) { |
| 3225 | QualType FromReturnTy = FromFPT->getReturnType(); |
| 3226 | // Functions with auto return type may define a struct inside their body |
| 3227 | // and the return type could refer to that struct. |
| 3228 | // E.g.: auto foo() { struct X{}; return X(); } |
| 3229 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 3230 | // with a simplified return type. |
| 3231 | if (hasAutoReturnTypeDeclaredInside(D)) { |
| 3232 | FromReturnTy = Importer.getFromContext().VoidTy; |
| 3233 | UsedDifferentProtoType = true; |
| 3234 | } |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3235 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 3236 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 3237 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 3238 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3239 | // with a simplified function type. |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 3240 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 3241 | FromEPI.ExceptionSpec.SourceTemplate || |
| 3242 | FromEPI.ExceptionSpec.NoexceptExpr) { |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3243 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3244 | FromEPI = DefaultEPI; |
| 3245 | UsedDifferentProtoType = true; |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3246 | } |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3247 | FromTy = Importer.getFromContext().getFunctionType( |
| 3248 | FromReturnTy, FromFPT->getParamTypes(), FromEPI); |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3249 | } |
| 3250 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3251 | QualType T; |
| 3252 | TypeSourceInfo *TInfo; |
| 3253 | SourceLocation ToInnerLocStart, ToEndLoc; |
| 3254 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3255 | if (auto Imp = importSeq( |
| 3256 | FromTy, D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3257 | D->getQualifierLoc(), D->getEndLoc())) |
| 3258 | std::tie(T, TInfo, ToInnerLocStart, ToQualifierLoc, ToEndLoc) = *Imp; |
| 3259 | else |
| 3260 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3261 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3262 | // Import the function parameters. |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3263 | SmallVector<ParmVarDecl *, 8> Parameters; |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3264 | for (auto P : D->parameters()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3265 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) |
| 3266 | Parameters.push_back(*ToPOrErr); |
| 3267 | else |
| 3268 | return ToPOrErr.takeError(); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3269 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3270 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3271 | // Create the imported function. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3272 | FunctionDecl *ToFunction = nullptr; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3273 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3274 | Expr *ExplicitExpr = nullptr; |
| 3275 | if (FromConstructor->getExplicitSpecifier().getExpr()) { |
| 3276 | auto Imp = importSeq(FromConstructor->getExplicitSpecifier().getExpr()); |
| 3277 | if (!Imp) |
| 3278 | return Imp.takeError(); |
| 3279 | std::tie(ExplicitExpr) = *Imp; |
| 3280 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3281 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3282 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3283 | ToInnerLocStart, NameInfo, T, TInfo, |
| 3284 | ExplicitSpecifier( |
| 3285 | ExplicitExpr, |
| 3286 | FromConstructor->getExplicitSpecifier().getKind()), |
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3287 | D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3288 | return ToFunction; |
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3289 | } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { |
| 3290 | |
| 3291 | auto Imp = |
| 3292 | importSeq(const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()), |
| 3293 | FromDtor->getOperatorDeleteThisArg()); |
| 3294 | |
| 3295 | if (!Imp) |
| 3296 | return Imp.takeError(); |
| 3297 | |
| 3298 | FunctionDecl *ToOperatorDelete; |
| 3299 | Expr *ToThisArg; |
| 3300 | std::tie(ToOperatorDelete, ToThisArg) = *Imp; |
| 3301 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3302 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3303 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3304 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| Richard Smith | 457226e | 2019-09-23 03:48:44 +0000 | [diff] [blame] | 3305 | D->isImplicit(), D->getConstexprKind())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3306 | return ToFunction; |
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3307 | |
| 3308 | CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction); |
| 3309 | |
| 3310 | ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3311 | } else if (CXXConversionDecl *FromConversion = |
| 3312 | dyn_cast<CXXConversionDecl>(D)) { |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3313 | Expr *ExplicitExpr = nullptr; |
| 3314 | if (FromConversion->getExplicitSpecifier().getExpr()) { |
| 3315 | auto Imp = importSeq(FromConversion->getExplicitSpecifier().getExpr()); |
| 3316 | if (!Imp) |
| 3317 | return Imp.takeError(); |
| 3318 | std::tie(ExplicitExpr) = *Imp; |
| 3319 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3320 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 3321 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3322 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3323 | ExplicitSpecifier(ExplicitExpr, |
| 3324 | FromConversion->getExplicitSpecifier().getKind()), |
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3325 | D->getConstexprKind(), SourceLocation())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3326 | return ToFunction; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3327 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3328 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 3329 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3330 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3331 | Method->isInlineSpecified(), D->getConstexprKind(), |
| 3332 | SourceLocation())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3333 | return ToFunction; |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3334 | } else { |
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3335 | if (GetImportedOrCreateDecl( |
| 3336 | ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, |
| 3337 | NameInfo, T, TInfo, D->getStorageClass(), D->isInlineSpecified(), |
| 3338 | D->hasWrittenPrototype(), D->getConstexprKind())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3339 | return ToFunction; |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3340 | } |
| John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3341 | |
| Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3342 | // Connect the redecl chain. |
| 3343 | if (FoundByLookup) { |
| 3344 | auto *Recent = const_cast<FunctionDecl *>( |
| 3345 | FoundByLookup->getMostRecentDecl()); |
| 3346 | ToFunction->setPreviousDecl(Recent); |
| Gabor Marton | ce6b781 | 2019-05-08 15:23:48 +0000 | [diff] [blame] | 3347 | // FIXME Probably we should merge exception specifications. E.g. In the |
| 3348 | // "To" context the existing function may have exception specification with |
| 3349 | // noexcept-unevaluated, while the newly imported function may have an |
| 3350 | // evaluated noexcept. A call to adjustExceptionSpec() on the imported |
| 3351 | // decl and its redeclarations may be required. |
| Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3352 | } |
| 3353 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3354 | ToFunction->setQualifierInfo(ToQualifierLoc); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3355 | ToFunction->setAccess(D->getAccess()); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3356 | ToFunction->setLexicalDeclContext(LexicalDC); |
| John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 3357 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 3358 | ToFunction->setTrivial(D->isTrivial()); |
| 3359 | ToFunction->setPure(D->isPure()); |
| Balazs Keri | b427c06 | 2019-08-13 08:04:06 +0000 | [diff] [blame] | 3360 | ToFunction->setDefaulted(D->isDefaulted()); |
| 3361 | ToFunction->setExplicitlyDefaulted(D->isExplicitlyDefaulted()); |
| 3362 | ToFunction->setDeletedAsWritten(D->isDeletedAsWritten()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3363 | ToFunction->setRangeEnd(ToEndLoc); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3364 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3365 | // Set the parameters. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3366 | for (auto *Param : Parameters) { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3367 | Param->setOwningFunction(ToFunction); |
| 3368 | ToFunction->addDeclInternal(Param); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3369 | } |
| David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 3370 | ToFunction->setParams(Parameters); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3371 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3372 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 3373 | // params it refers to. |
| 3374 | if (TInfo) { |
| 3375 | if (auto ProtoLoc = |
| 3376 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 3377 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 3378 | ProtoLoc.setParam(I, Parameters[I]); |
| 3379 | } |
| 3380 | } |
| 3381 | |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3382 | // Import the describing template function, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3383 | if (FromFT) { |
| 3384 | auto ToFTOrErr = import(FromFT); |
| 3385 | if (!ToFTOrErr) |
| 3386 | return ToFTOrErr.takeError(); |
| 3387 | } |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3388 | |
| Balazs Keri | e13e836 | 2019-08-16 12:10:03 +0000 | [diff] [blame] | 3389 | // Import Ctor initializers. |
| 3390 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 3391 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 3392 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); |
| 3393 | // Import first, then allocate memory and copy if there was no error. |
| 3394 | if (Error Err = ImportContainerChecked( |
| 3395 | FromConstructor->inits(), CtorInitializers)) |
| 3396 | return std::move(Err); |
| 3397 | auto **Memory = |
| 3398 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 3399 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
| 3400 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
| 3401 | ToCtor->setCtorInitializers(Memory); |
| 3402 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 3403 | } |
| 3404 | } |
| 3405 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3406 | if (D->doesThisDeclarationHaveABody()) { |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3407 | Error Err = ImportFunctionDeclBody(D, ToFunction); |
| 3408 | |
| 3409 | if (Err) |
| 3410 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3411 | } |
| 3412 | |
| Gabor Marton | 25234fd | 2019-12-12 17:13:35 +0100 | [diff] [blame] | 3413 | // Import and set the original type in case we used another type. |
| 3414 | if (UsedDifferentProtoType) { |
| 3415 | if (ExpectedType TyOrErr = import(D->getType())) |
| 3416 | ToFunction->setType(*TyOrErr); |
| 3417 | else |
| 3418 | return TyOrErr.takeError(); |
| 3419 | } |
| 3420 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3421 | // FIXME: Other bits to merge? |
| Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3422 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3423 | // If it is a template, import all related things. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3424 | if (Error Err = ImportTemplateInformation(D, ToFunction)) |
| 3425 | return std::move(Err); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3426 | |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 3427 | addDeclToContexts(D, ToFunction); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3428 | |
| Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3429 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 3430 | if (Error Err = ImportOverriddenMethods(cast<CXXMethodDecl>(ToFunction), |
| 3431 | FromCXXMethod)) |
| 3432 | return std::move(Err); |
| Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3433 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3434 | // Import the rest of the chain. I.e. import all subsequent declarations. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3435 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3436 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3437 | if (!ToRedeclOrErr) |
| 3438 | return ToRedeclOrErr.takeError(); |
| 3439 | } |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3440 | |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3441 | return ToFunction; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3442 | } |
| 3443 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3444 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3445 | return VisitFunctionDecl(D); |
| 3446 | } |
| 3447 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3448 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3449 | return VisitCXXMethodDecl(D); |
| 3450 | } |
| 3451 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3452 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3453 | return VisitCXXMethodDecl(D); |
| 3454 | } |
| 3455 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3456 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3457 | return VisitCXXMethodDecl(D); |
| 3458 | } |
| 3459 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3460 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3461 | // Import the major distinguishing characteristics of a variable. |
| 3462 | DeclContext *DC, *LexicalDC; |
| 3463 | DeclarationName Name; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3464 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3465 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3466 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3467 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3468 | if (ToD) |
| 3469 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3470 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3471 | // Determine whether we've already imported this field. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3472 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3473 | for (auto *FoundDecl : FoundDecls) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3474 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3475 | // For anonymous fields, match up by index. |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3476 | if (!Name && |
| 3477 | ASTImporter::getFieldIndex(D) != |
| 3478 | ASTImporter::getFieldIndex(FoundField)) |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3479 | continue; |
| 3480 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3481 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3482 | FoundField->getType())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3483 | Importer.MapImported(D, FoundField); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3484 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the |
| 3485 | // initializer of a FieldDecl might not had been instantiated in the |
| 3486 | // "To" context. However, the "From" context might instantiated that, |
| 3487 | // thus we have to merge that. |
| 3488 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
| 3489 | // We don't have yet the initializer set. |
| 3490 | if (FoundField->hasInClassInitializer() && |
| 3491 | !FoundField->getInClassInitializer()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3492 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) |
| 3493 | FoundField->setInClassInitializer(*ToInitializerOrErr); |
| 3494 | else { |
| 3495 | // We can't return error here, |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3496 | // since we already mapped D as imported. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3497 | // FIXME: warning message? |
| 3498 | consumeError(ToInitializerOrErr.takeError()); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3499 | return FoundField; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3500 | } |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3501 | } |
| 3502 | } |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3503 | return FoundField; |
| 3504 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3505 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3506 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3507 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3508 | << Name << D->getType() << FoundField->getType(); |
| 3509 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3510 | << FoundField->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3511 | |
| 3512 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3513 | } |
| 3514 | } |
| 3515 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3516 | QualType ToType; |
| 3517 | TypeSourceInfo *ToTInfo; |
| 3518 | Expr *ToBitWidth; |
| 3519 | SourceLocation ToInnerLocStart; |
| 3520 | Expr *ToInitializer; |
| 3521 | if (auto Imp = importSeq( |
| 3522 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), |
| 3523 | D->getInnerLocStart(), D->getInClassInitializer())) |
| 3524 | std::tie( |
| 3525 | ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp; |
| 3526 | else |
| 3527 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3528 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3529 | FieldDecl *ToField; |
| 3530 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3531 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3532 | ToType, ToTInfo, ToBitWidth, D->isMutable(), |
| 3533 | D->getInClassInitStyle())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3534 | return ToField; |
| 3535 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3536 | ToField->setAccess(D->getAccess()); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3537 | ToField->setLexicalDeclContext(LexicalDC); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3538 | if (ToInitializer) |
| 3539 | ToField->setInClassInitializer(ToInitializer); |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3540 | ToField->setImplicit(D->isImplicit()); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3541 | LexicalDC->addDeclInternal(ToField); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3542 | return ToField; |
| 3543 | } |
| 3544 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3545 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3546 | // Import the major distinguishing characteristics of a variable. |
| 3547 | DeclContext *DC, *LexicalDC; |
| 3548 | DeclarationName Name; |
| 3549 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3550 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3551 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3552 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3553 | if (ToD) |
| 3554 | return ToD; |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3555 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3556 | // Determine whether we've already imported this field. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3557 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3558 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3559 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3560 | // For anonymous indirect fields, match up by index. |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3561 | if (!Name && |
| 3562 | ASTImporter::getFieldIndex(D) != |
| 3563 | ASTImporter::getFieldIndex(FoundField)) |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3564 | continue; |
| 3565 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3566 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3567 | FoundField->getType(), |
| David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 3568 | !Name.isEmpty())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3569 | Importer.MapImported(D, FoundField); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3570 | return FoundField; |
| 3571 | } |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3572 | |
| 3573 | // If there are more anonymous fields to check, continue. |
| 3574 | if (!Name && I < N-1) |
| 3575 | continue; |
| 3576 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3577 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3578 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3579 | << Name << D->getType() << FoundField->getType(); |
| 3580 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3581 | << FoundField->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3582 | |
| 3583 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3584 | } |
| 3585 | } |
| 3586 | |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3587 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3588 | auto TypeOrErr = import(D->getType()); |
| 3589 | if (!TypeOrErr) |
| 3590 | return TypeOrErr.takeError(); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3591 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3592 | auto **NamedChain = |
| 3593 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3594 | |
| 3595 | unsigned i = 0; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3596 | for (auto *PI : D->chain()) |
| 3597 | if (Expected<NamedDecl *> ToD = import(PI)) |
| 3598 | NamedChain[i++] = *ToD; |
| 3599 | else |
| 3600 | return ToD.takeError(); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3601 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3602 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 3603 | IndirectFieldDecl *ToIndirectField; |
| 3604 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3605 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3606 | // FIXME here we leak `NamedChain` which is allocated before |
| 3607 | return ToIndirectField; |
| Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3608 | |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3609 | ToIndirectField->setAccess(D->getAccess()); |
| 3610 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3611 | LexicalDC->addDeclInternal(ToIndirectField); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3612 | return ToIndirectField; |
| 3613 | } |
| 3614 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3615 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3616 | // Import the major distinguishing characteristics of a declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3617 | DeclContext *DC, *LexicalDC; |
| 3618 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 3619 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3620 | |
| 3621 | // Determine whether we've already imported this decl. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3622 | // FriendDecl is not a NamedDecl so we cannot use lookup. |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3623 | auto *RD = cast<CXXRecordDecl>(DC); |
| 3624 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3625 | |
| 3626 | while (ImportedFriend) { |
| 3627 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3628 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 3629 | /*Complain=*/false)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3630 | return Importer.MapImported(D, ImportedFriend); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3631 | |
| 3632 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 3633 | if (Importer.IsStructurallyEquivalent( |
| 3634 | D->getFriendType()->getType(), |
| 3635 | ImportedFriend->getFriendType()->getType(), true)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3636 | return Importer.MapImported(D, ImportedFriend); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3637 | } |
| 3638 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3639 | } |
| 3640 | |
| 3641 | // Not found. Create it. |
| 3642 | FriendDecl::FriendUnion ToFU; |
| Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3643 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3644 | NamedDecl *ToFriendD; |
| 3645 | if (Error Err = importInto(ToFriendD, FriendD)) |
| 3646 | return std::move(Err); |
| 3647 | |
| 3648 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && |
| Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3649 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3650 | ToFriendD->setObjectOfFriendDecl(false); |
| 3651 | |
| 3652 | ToFU = ToFriendD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3653 | } else { // The friend is a type, not a decl. |
| 3654 | if (auto TSIOrErr = import(D->getFriendType())) |
| 3655 | ToFU = *TSIOrErr; |
| 3656 | else |
| 3657 | return TSIOrErr.takeError(); |
| 3658 | } |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3659 | |
| 3660 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3661 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3662 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 3663 | if (auto ListOrErr = import(FromTPLists[I])) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3664 | ToTPLists[I] = *ListOrErr; |
| 3665 | else |
| 3666 | return ListOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3667 | } |
| 3668 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3669 | auto LocationOrErr = import(D->getLocation()); |
| 3670 | if (!LocationOrErr) |
| 3671 | return LocationOrErr.takeError(); |
| 3672 | auto FriendLocOrErr = import(D->getFriendLoc()); |
| 3673 | if (!FriendLocOrErr) |
| 3674 | return FriendLocOrErr.takeError(); |
| 3675 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3676 | FriendDecl *FrD; |
| 3677 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3678 | *LocationOrErr, ToFU, |
| 3679 | *FriendLocOrErr, ToTPLists)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3680 | return FrD; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3681 | |
| 3682 | FrD->setAccess(D->getAccess()); |
| 3683 | FrD->setLexicalDeclContext(LexicalDC); |
| 3684 | LexicalDC->addDeclInternal(FrD); |
| 3685 | return FrD; |
| 3686 | } |
| 3687 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3688 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3689 | // Import the major distinguishing characteristics of an ivar. |
| 3690 | DeclContext *DC, *LexicalDC; |
| 3691 | DeclarationName Name; |
| 3692 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3693 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3694 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3695 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3696 | if (ToD) |
| 3697 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3698 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3699 | // Determine whether we've already imported this ivar |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3700 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3701 | for (auto *FoundDecl : FoundDecls) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3702 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3703 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3704 | FoundIvar->getType())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3705 | Importer.MapImported(D, FoundIvar); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3706 | return FoundIvar; |
| 3707 | } |
| 3708 | |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3709 | Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent) |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3710 | << Name << D->getType() << FoundIvar->getType(); |
| 3711 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3712 | << FoundIvar->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3713 | |
| 3714 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3715 | } |
| 3716 | } |
| 3717 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3718 | QualType ToType; |
| 3719 | TypeSourceInfo *ToTypeSourceInfo; |
| 3720 | Expr *ToBitWidth; |
| 3721 | SourceLocation ToInnerLocStart; |
| 3722 | if (auto Imp = importSeq( |
| 3723 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), D->getInnerLocStart())) |
| 3724 | std::tie(ToType, ToTypeSourceInfo, ToBitWidth, ToInnerLocStart) = *Imp; |
| 3725 | else |
| 3726 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3727 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3728 | ObjCIvarDecl *ToIvar; |
| 3729 | if (GetImportedOrCreateDecl( |
| 3730 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3731 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3732 | ToType, ToTypeSourceInfo, |
| 3733 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3734 | return ToIvar; |
| 3735 | |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3736 | ToIvar->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3737 | LexicalDC->addDeclInternal(ToIvar); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3738 | return ToIvar; |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3739 | } |
| 3740 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3741 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3742 | |
| 3743 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 3744 | auto RedeclIt = Redecls.begin(); |
| 3745 | // Import the first part of the decl chain. I.e. import all previous |
| 3746 | // declarations starting from the canonical decl. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3747 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3748 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3749 | if (!RedeclOrErr) |
| 3750 | return RedeclOrErr.takeError(); |
| 3751 | } |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3752 | assert(*RedeclIt == D); |
| 3753 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3754 | // Import the major distinguishing characteristics of a variable. |
| 3755 | DeclContext *DC, *LexicalDC; |
| 3756 | DeclarationName Name; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3757 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3758 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3759 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3760 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3761 | if (ToD) |
| 3762 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3763 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3764 | // Try to find a variable in our own ("to") context with the same name and |
| 3765 | // in the same context as the variable we're importing. |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3766 | VarDecl *FoundByLookup = nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3767 | if (D->isFileVarDecl()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3768 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3769 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3770 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3771 | for (auto *FoundDecl : FoundDecls) { |
| 3772 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3773 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3774 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3775 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3776 | if (!hasSameVisibilityContext(FoundVar, D)) |
| 3777 | continue; |
| 3778 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| 3779 | FoundVar->getType())) { |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3780 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3781 | // The VarDecl in the "From" context has a definition, but in the |
| 3782 | // "To" context we already have a definition. |
| 3783 | VarDecl *FoundDef = FoundVar->getDefinition(); |
| 3784 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 3785 | // FIXME Check for ODR error if the two definitions have |
| 3786 | // different initializers? |
| 3787 | return Importer.MapImported(D, FoundDef); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3788 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3789 | // The VarDecl in the "From" context has an initializer, but in the |
| 3790 | // "To" context we already have an initializer. |
| 3791 | const VarDecl *FoundDInit = nullptr; |
| 3792 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) |
| 3793 | // FIXME Diagnose ODR error if the two initializers are different? |
| 3794 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); |
| 3795 | |
| 3796 | FoundByLookup = FoundVar; |
| 3797 | break; |
| 3798 | } |
| 3799 | |
| 3800 | const ArrayType *FoundArray |
| 3801 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3802 | const ArrayType *TArray |
| 3803 | = Importer.getToContext().getAsArrayType(D->getType()); |
| 3804 | if (FoundArray && TArray) { |
| 3805 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3806 | isa<ConstantArrayType>(TArray)) { |
| 3807 | // Import the type. |
| 3808 | if (auto TyOrErr = import(D->getType())) |
| 3809 | FoundVar->setType(*TyOrErr); |
| 3810 | else |
| 3811 | return TyOrErr.takeError(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3812 | |
| 3813 | FoundByLookup = FoundVar; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3814 | break; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3815 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3816 | isa<ConstantArrayType>(FoundArray)) { |
| 3817 | FoundByLookup = FoundVar; |
| 3818 | break; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3819 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3820 | } |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3821 | |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3822 | Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3823 | << Name << D->getType() << FoundVar->getType(); |
| 3824 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3825 | << FoundVar->getType(); |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3826 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3827 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3828 | } |
| 3829 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3830 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 3831 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 3832 | Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size()); |
| 3833 | if (NameOrErr) |
| 3834 | Name = NameOrErr.get(); |
| 3835 | else |
| 3836 | return NameOrErr.takeError(); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3837 | } |
| 3838 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3839 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3840 | QualType ToType; |
| 3841 | TypeSourceInfo *ToTypeSourceInfo; |
| 3842 | SourceLocation ToInnerLocStart; |
| 3843 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3844 | if (auto Imp = importSeq( |
| 3845 | D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3846 | D->getQualifierLoc())) |
| 3847 | std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp; |
| 3848 | else |
| 3849 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3850 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3851 | // Create the imported variable. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3852 | VarDecl *ToVar; |
| 3853 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3854 | ToInnerLocStart, Loc, |
| 3855 | Name.getAsIdentifierInfo(), |
| 3856 | ToType, ToTypeSourceInfo, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3857 | D->getStorageClass())) |
| 3858 | return ToVar; |
| 3859 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3860 | ToVar->setQualifierInfo(ToQualifierLoc); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3861 | ToVar->setAccess(D->getAccess()); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3862 | ToVar->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3863 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3864 | if (FoundByLookup) { |
| 3865 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); |
| 3866 | ToVar->setPreviousDecl(Recent); |
| 3867 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3868 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3869 | if (Error Err = ImportInitializer(D, ToVar)) |
| 3870 | return std::move(Err); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3871 | |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3872 | if (D->isConstexpr()) |
| 3873 | ToVar->setConstexpr(true); |
| 3874 | |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 3875 | addDeclToContexts(D, ToVar); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3876 | |
| 3877 | // Import the rest of the chain. I.e. import all subsequent declarations. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3878 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3879 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3880 | if (!RedeclOrErr) |
| 3881 | return RedeclOrErr.takeError(); |
| 3882 | } |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3883 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3884 | return ToVar; |
| 3885 | } |
| 3886 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3887 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3888 | // Parameters are created in the translation unit's context, then moved |
| 3889 | // into the function declaration's context afterward. |
| 3890 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3891 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3892 | DeclarationName ToDeclName; |
| 3893 | SourceLocation ToLocation; |
| 3894 | QualType ToType; |
| 3895 | if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType())) |
| 3896 | std::tie(ToDeclName, ToLocation, ToType) = *Imp; |
| 3897 | else |
| 3898 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3899 | |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3900 | // Create the imported parameter. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3901 | ImplicitParamDecl *ToParm = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3902 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3903 | ToLocation, ToDeclName.getAsIdentifierInfo(), |
| 3904 | ToType, D->getParameterKind())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3905 | return ToParm; |
| 3906 | return ToParm; |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3907 | } |
| 3908 | |
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 3909 | Error ASTNodeImporter::ImportDefaultArgOfParmVarDecl( |
| 3910 | const ParmVarDecl *FromParam, ParmVarDecl *ToParam) { |
| 3911 | ToParam->setHasInheritedDefaultArg(FromParam->hasInheritedDefaultArg()); |
| 3912 | ToParam->setKNRPromoted(FromParam->isKNRPromoted()); |
| 3913 | |
| 3914 | if (FromParam->hasUninstantiatedDefaultArg()) { |
| 3915 | if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg())) |
| 3916 | ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr); |
| 3917 | else |
| 3918 | return ToDefArgOrErr.takeError(); |
| 3919 | } else if (FromParam->hasUnparsedDefaultArg()) { |
| 3920 | ToParam->setUnparsedDefaultArg(); |
| 3921 | } else if (FromParam->hasDefaultArg()) { |
| 3922 | if (auto ToDefArgOrErr = import(FromParam->getDefaultArg())) |
| 3923 | ToParam->setDefaultArg(*ToDefArgOrErr); |
| 3924 | else |
| 3925 | return ToDefArgOrErr.takeError(); |
| 3926 | } |
| 3927 | |
| 3928 | return Error::success(); |
| 3929 | } |
| 3930 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3931 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3932 | // Parameters are created in the translation unit's context, then moved |
| 3933 | // into the function declaration's context afterward. |
| 3934 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3935 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3936 | DeclarationName ToDeclName; |
| 3937 | SourceLocation ToLocation, ToInnerLocStart; |
| 3938 | QualType ToType; |
| 3939 | TypeSourceInfo *ToTypeSourceInfo; |
| 3940 | if (auto Imp = importSeq( |
| 3941 | D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(), |
| 3942 | D->getTypeSourceInfo())) |
| 3943 | std::tie( |
| 3944 | ToDeclName, ToLocation, ToType, ToInnerLocStart, |
| 3945 | ToTypeSourceInfo) = *Imp; |
| 3946 | else |
| 3947 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3948 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3949 | ParmVarDecl *ToParm; |
| 3950 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3951 | ToInnerLocStart, ToLocation, |
| 3952 | ToDeclName.getAsIdentifierInfo(), ToType, |
| 3953 | ToTypeSourceInfo, D->getStorageClass(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3954 | /*DefaultArg*/ nullptr)) |
| 3955 | return ToParm; |
| Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3956 | |
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 3957 | // Set the default argument. It should be no problem if it was already done. |
| 3958 | // Do not import the default expression before GetImportedOrCreateDecl call |
| 3959 | // to avoid possible infinite import loop because circular dependency. |
| 3960 | if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm)) |
| 3961 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3962 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3963 | if (D->isObjCMethodParameter()) { |
| 3964 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3965 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3966 | } else { |
| 3967 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3968 | D->getFunctionScopeIndex()); |
| 3969 | } |
| 3970 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3971 | return ToParm; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3972 | } |
| 3973 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3974 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3975 | // Import the major distinguishing characteristics of a method. |
| 3976 | DeclContext *DC, *LexicalDC; |
| 3977 | DeclarationName Name; |
| 3978 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3979 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3980 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3981 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3982 | if (ToD) |
| 3983 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3984 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3985 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3986 | for (auto *FoundDecl : FoundDecls) { |
| 3987 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3988 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3989 | continue; |
| 3990 | |
| 3991 | // Check return types. |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3992 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3993 | FoundMethod->getReturnType())) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3994 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent) |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3995 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3996 | << FoundMethod->getReturnType(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3997 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3998 | diag::note_odr_objc_method_here) |
| 3999 | << D->isInstanceMethod() << Name; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4000 | |
| 4001 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4002 | } |
| 4003 | |
| 4004 | // Check the number of parameters. |
| 4005 | if (D->param_size() != FoundMethod->param_size()) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4006 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4007 | << D->isInstanceMethod() << Name |
| 4008 | << D->param_size() << FoundMethod->param_size(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4009 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4010 | diag::note_odr_objc_method_here) |
| 4011 | << D->isInstanceMethod() << Name; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4012 | |
| 4013 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4014 | } |
| 4015 | |
| 4016 | // Check parameter types. |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4017 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4018 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 4019 | P != PEnd; ++P, ++FoundP) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4020 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4021 | (*FoundP)->getType())) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4022 | Importer.FromDiag((*P)->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4023 | diag::warn_odr_objc_method_param_type_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4024 | << D->isInstanceMethod() << Name |
| 4025 | << (*P)->getType() << (*FoundP)->getType(); |
| 4026 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 4027 | << (*FoundP)->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4028 | |
| 4029 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4030 | } |
| 4031 | } |
| 4032 | |
| 4033 | // Check variadic/non-variadic. |
| 4034 | // Check the number of parameters. |
| 4035 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4036 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4037 | << D->isInstanceMethod() << Name; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4038 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4039 | diag::note_odr_objc_method_here) |
| 4040 | << D->isInstanceMethod() << Name; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4041 | |
| 4042 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4043 | } |
| 4044 | |
| 4045 | // FIXME: Any other bits we need to merge? |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4046 | return Importer.MapImported(D, FoundMethod); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4047 | } |
| 4048 | } |
| 4049 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4050 | SourceLocation ToEndLoc; |
| 4051 | QualType ToReturnType; |
| 4052 | TypeSourceInfo *ToReturnTypeSourceInfo; |
| 4053 | if (auto Imp = importSeq( |
| 4054 | D->getEndLoc(), D->getReturnType(), D->getReturnTypeSourceInfo())) |
| 4055 | std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp; |
| 4056 | else |
| 4057 | return Imp.takeError(); |
| Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 4058 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4059 | ObjCMethodDecl *ToMethod; |
| 4060 | if (GetImportedOrCreateDecl( |
| Adrian Prantl | 2073dd2 | 2019-11-04 14:28:14 -0800 | [diff] [blame] | 4061 | ToMethod, D, Importer.getToContext(), Loc, ToEndLoc, |
| 4062 | Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC, |
| 4063 | D->isInstanceMethod(), D->isVariadic(), D->isPropertyAccessor(), |
| 4064 | D->isSynthesizedAccessorStub(), D->isImplicit(), D->isDefined(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4065 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 4066 | return ToMethod; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4067 | |
| 4068 | // FIXME: When we decide to merge method definitions, we'll need to |
| 4069 | // deal with implicit parameters. |
| 4070 | |
| 4071 | // Import the parameters |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4072 | SmallVector<ParmVarDecl *, 5> ToParams; |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 4073 | for (auto *FromP : D->parameters()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4074 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) |
| 4075 | ToParams.push_back(*ToPOrErr); |
| 4076 | else |
| 4077 | return ToPOrErr.takeError(); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4078 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4079 | |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4080 | // Set the parameters. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4081 | for (auto *ToParam : ToParams) { |
| 4082 | ToParam->setOwningFunction(ToMethod); |
| 4083 | ToMethod->addDeclInternal(ToParam); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4084 | } |
| Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 4085 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4086 | SmallVector<SourceLocation, 12> FromSelLocs; |
| 4087 | D->getSelectorLocs(FromSelLocs); |
| 4088 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); |
| 4089 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) |
| 4090 | return std::move(Err); |
| Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 4091 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4092 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4093 | |
| 4094 | ToMethod->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4095 | LexicalDC->addDeclInternal(ToMethod); |
| Raphael Isemann | 164e0fc | 2019-12-06 18:10:23 +0100 | [diff] [blame] | 4096 | |
| 4097 | // Implicit params are declared when Sema encounters the definition but this |
| 4098 | // never happens when the method is imported. Manually declare the implicit |
| 4099 | // params now that the MethodDecl knows its class interface. |
| 4100 | if (D->getSelfDecl()) |
| 4101 | ToMethod->createImplicitParams(Importer.getToContext(), |
| 4102 | ToMethod->getClassInterface()); |
| 4103 | |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4104 | return ToMethod; |
| 4105 | } |
| 4106 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4107 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4108 | // Import the major distinguishing characteristics of a category. |
| 4109 | DeclContext *DC, *LexicalDC; |
| 4110 | DeclarationName Name; |
| 4111 | SourceLocation Loc; |
| 4112 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4113 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4114 | return std::move(Err); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4115 | if (ToD) |
| 4116 | return ToD; |
| 4117 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4118 | SourceLocation ToVarianceLoc, ToLocation, ToColonLoc; |
| 4119 | TypeSourceInfo *ToTypeSourceInfo; |
| 4120 | if (auto Imp = importSeq( |
| 4121 | D->getVarianceLoc(), D->getLocation(), D->getColonLoc(), |
| 4122 | D->getTypeSourceInfo())) |
| 4123 | std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp; |
| 4124 | else |
| 4125 | return Imp.takeError(); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4126 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4127 | ObjCTypeParamDecl *Result; |
| 4128 | if (GetImportedOrCreateDecl( |
| 4129 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4130 | ToVarianceLoc, D->getIndex(), |
| 4131 | ToLocation, Name.getAsIdentifierInfo(), |
| 4132 | ToColonLoc, ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4133 | return Result; |
| 4134 | |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4135 | Result->setLexicalDeclContext(LexicalDC); |
| 4136 | return Result; |
| 4137 | } |
| 4138 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4139 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4140 | // Import the major distinguishing characteristics of a category. |
| 4141 | DeclContext *DC, *LexicalDC; |
| 4142 | DeclarationName Name; |
| 4143 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4144 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4145 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4146 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4147 | if (ToD) |
| 4148 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4149 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4150 | ObjCInterfaceDecl *ToInterface; |
| 4151 | if (Error Err = importInto(ToInterface, D->getClassInterface())) |
| 4152 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4153 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4154 | // Determine if we've already encountered this category. |
| 4155 | ObjCCategoryDecl *MergeWithCategory |
| 4156 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 4157 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 4158 | if (!ToCategory) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4159 | SourceLocation ToAtStartLoc, ToCategoryNameLoc; |
| 4160 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 4161 | if (auto Imp = importSeq( |
| 4162 | D->getAtStartLoc(), D->getCategoryNameLoc(), |
| 4163 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 4164 | std::tie( |
| 4165 | ToAtStartLoc, ToCategoryNameLoc, |
| 4166 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 4167 | else |
| 4168 | return Imp.takeError(); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4169 | |
| 4170 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4171 | ToAtStartLoc, Loc, |
| 4172 | ToCategoryNameLoc, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4173 | Name.getAsIdentifierInfo(), ToInterface, |
| 4174 | /*TypeParamList=*/nullptr, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4175 | ToIvarLBraceLoc, |
| 4176 | ToIvarRBraceLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4177 | return ToCategory; |
| 4178 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4179 | ToCategory->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4180 | LexicalDC->addDeclInternal(ToCategory); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4181 | // Import the type parameter list after MapImported, to avoid |
| Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4182 | // loops when bringing in their DeclContext. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4183 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) |
| 4184 | ToCategory->setTypeParamList(*PListOrErr); |
| 4185 | else |
| 4186 | return PListOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4187 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4188 | // Import protocols |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4189 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4190 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4191 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 4192 | = D->protocol_loc_begin(); |
| 4193 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 4194 | FromProtoEnd = D->protocol_end(); |
| 4195 | FromProto != FromProtoEnd; |
| 4196 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4197 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4198 | Protocols.push_back(*ToProtoOrErr); |
| 4199 | else |
| 4200 | return ToProtoOrErr.takeError(); |
| 4201 | |
| 4202 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4203 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4204 | else |
| 4205 | return ToProtoLocOrErr.takeError(); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4206 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4207 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4208 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4209 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 4210 | ProtocolLocs.data(), Importer.getToContext()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4211 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4212 | } else { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4213 | Importer.MapImported(D, ToCategory); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4214 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4215 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4216 | // Import all of the members of this category. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4217 | if (Error Err = ImportDeclContext(D)) |
| 4218 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4219 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4220 | // If we have an implementation, import it as well. |
| 4221 | if (D->getImplementation()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4222 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = |
| 4223 | import(D->getImplementation())) |
| 4224 | ToCategory->setImplementation(*ToImplOrErr); |
| 4225 | else |
| 4226 | return ToImplOrErr.takeError(); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4227 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4228 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4229 | return ToCategory; |
| 4230 | } |
| 4231 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4232 | Error ASTNodeImporter::ImportDefinition( |
| 4233 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4234 | if (To->getDefinition()) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4235 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4236 | if (Error Err = ImportDeclContext(From)) |
| 4237 | return Err; |
| 4238 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4239 | } |
| 4240 | |
| 4241 | // Start the protocol definition |
| 4242 | To->startDefinition(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4243 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4244 | // Import protocols |
| 4245 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4246 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4247 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = |
| 4248 | From->protocol_loc_begin(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4249 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4250 | FromProtoEnd = From->protocol_end(); |
| 4251 | FromProto != FromProtoEnd; |
| 4252 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4253 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4254 | Protocols.push_back(*ToProtoOrErr); |
| 4255 | else |
| 4256 | return ToProtoOrErr.takeError(); |
| 4257 | |
| 4258 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4259 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4260 | else |
| 4261 | return ToProtoLocOrErr.takeError(); |
| 4262 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4263 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4264 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4265 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4266 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4267 | ProtocolLocs.data(), Importer.getToContext()); |
| 4268 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4269 | if (shouldForceImportDeclContext(Kind)) { |
| 4270 | // Import all of the members of this protocol. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4271 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4272 | return Err; |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4273 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4274 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4275 | } |
| 4276 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4277 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4278 | // 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] | 4279 | // from, but this particular declaration is not that definition, import the |
| 4280 | // definition and map to that. |
| 4281 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 4282 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4283 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4284 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4285 | else |
| 4286 | return ImportedDefOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4287 | } |
| 4288 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4289 | // Import the major distinguishing characteristics of a protocol. |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4290 | DeclContext *DC, *LexicalDC; |
| 4291 | DeclarationName Name; |
| 4292 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4293 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4294 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4295 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4296 | if (ToD) |
| 4297 | return ToD; |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4298 | |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4299 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4300 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4301 | for (auto *FoundDecl : FoundDecls) { |
| 4302 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4303 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4304 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4305 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4306 | break; |
| 4307 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4308 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4309 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4310 | if (!ToProto) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4311 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4312 | if (!ToAtBeginLocOrErr) |
| 4313 | return ToAtBeginLocOrErr.takeError(); |
| 4314 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4315 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 4316 | Name.getAsIdentifierInfo(), Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4317 | *ToAtBeginLocOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4318 | /*PrevDecl=*/nullptr)) |
| 4319 | return ToProto; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4320 | ToProto->setLexicalDeclContext(LexicalDC); |
| 4321 | LexicalDC->addDeclInternal(ToProto); |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4322 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4323 | |
| 4324 | Importer.MapImported(D, ToProto); |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4325 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4326 | if (D->isThisDeclarationADefinition()) |
| 4327 | if (Error Err = ImportDefinition(D, ToProto)) |
| 4328 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4329 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4330 | return ToProto; |
| 4331 | } |
| 4332 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4333 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 4334 | DeclContext *DC, *LexicalDC; |
| 4335 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4336 | return std::move(Err); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4337 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4338 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); |
| 4339 | if (!ExternLocOrErr) |
| 4340 | return ExternLocOrErr.takeError(); |
| 4341 | |
| 4342 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); |
| 4343 | if (!LangLocOrErr) |
| 4344 | return LangLocOrErr.takeError(); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4345 | |
| 4346 | bool HasBraces = D->hasBraces(); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4347 | |
| 4348 | LinkageSpecDecl *ToLinkageSpec; |
| 4349 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4350 | *ExternLocOrErr, *LangLocOrErr, |
| 4351 | D->getLanguage(), HasBraces)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4352 | return ToLinkageSpec; |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4353 | |
| 4354 | if (HasBraces) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4355 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 4356 | if (!RBraceLocOrErr) |
| 4357 | return RBraceLocOrErr.takeError(); |
| 4358 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4359 | } |
| 4360 | |
| 4361 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 4362 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 4363 | |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4364 | return ToLinkageSpec; |
| 4365 | } |
| 4366 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4367 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4368 | DeclContext *DC, *LexicalDC; |
| 4369 | DeclarationName Name; |
| 4370 | SourceLocation Loc; |
| 4371 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4372 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4373 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4374 | if (ToD) |
| 4375 | return ToD; |
| 4376 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4377 | SourceLocation ToLoc, ToUsingLoc; |
| 4378 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4379 | if (auto Imp = importSeq( |
| 4380 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc())) |
| 4381 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp; |
| 4382 | else |
| 4383 | return Imp.takeError(); |
| 4384 | |
| 4385 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4386 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4387 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4388 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4389 | UsingDecl *ToUsing; |
| 4390 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4391 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4392 | D->hasTypename())) |
| 4393 | return ToUsing; |
| 4394 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4395 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4396 | LexicalDC->addDeclInternal(ToUsing); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4397 | |
| 4398 | if (NamedDecl *FromPattern = |
| 4399 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4400 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) |
| 4401 | Importer.getToContext().setInstantiatedFromUsingDecl( |
| 4402 | ToUsing, *ToPatternOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4403 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4404 | return ToPatternOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4405 | } |
| 4406 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4407 | for (UsingShadowDecl *FromShadow : D->shadows()) { |
| 4408 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) |
| 4409 | ToUsing->addShadowDecl(*ToShadowOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4410 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4411 | // FIXME: We return error here but the definition is already created |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4412 | // and available with lookups. How to fix this?.. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4413 | return ToShadowOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4414 | } |
| 4415 | return ToUsing; |
| 4416 | } |
| 4417 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4418 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4419 | DeclContext *DC, *LexicalDC; |
| 4420 | DeclarationName Name; |
| 4421 | SourceLocation Loc; |
| 4422 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4423 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4424 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4425 | if (ToD) |
| 4426 | return ToD; |
| 4427 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4428 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); |
| 4429 | if (!ToUsingOrErr) |
| 4430 | return ToUsingOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4431 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4432 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); |
| 4433 | if (!ToTargetOrErr) |
| 4434 | return ToTargetOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4435 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4436 | UsingShadowDecl *ToShadow; |
| 4437 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4438 | *ToUsingOrErr, *ToTargetOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4439 | return ToShadow; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4440 | |
| 4441 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 4442 | ToShadow->setAccess(D->getAccess()); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4443 | |
| 4444 | if (UsingShadowDecl *FromPattern = |
| 4445 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4446 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) |
| 4447 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( |
| 4448 | ToShadow, *ToPatternOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4449 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4450 | // FIXME: We return error here but the definition is already created |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4451 | // and available with lookups. How to fix this?.. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4452 | return ToPatternOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4453 | } |
| 4454 | |
| 4455 | LexicalDC->addDeclInternal(ToShadow); |
| 4456 | |
| 4457 | return ToShadow; |
| 4458 | } |
| 4459 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4460 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4461 | DeclContext *DC, *LexicalDC; |
| 4462 | DeclarationName Name; |
| 4463 | SourceLocation Loc; |
| 4464 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4465 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4466 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4467 | if (ToD) |
| 4468 | return ToD; |
| 4469 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4470 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); |
| 4471 | if (!ToComAncestorOrErr) |
| 4472 | return ToComAncestorOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4473 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4474 | NamespaceDecl *ToNominatedNamespace; |
| 4475 | SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation; |
| 4476 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4477 | if (auto Imp = importSeq( |
| 4478 | D->getNominatedNamespace(), D->getUsingLoc(), |
| 4479 | D->getNamespaceKeyLocation(), D->getQualifierLoc(), |
| 4480 | D->getIdentLocation())) |
| 4481 | std::tie( |
| 4482 | ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation, |
| 4483 | ToQualifierLoc, ToIdentLocation) = *Imp; |
| 4484 | else |
| 4485 | return Imp.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4486 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4487 | UsingDirectiveDecl *ToUsingDir; |
| 4488 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4489 | ToUsingLoc, |
| 4490 | ToNamespaceKeyLocation, |
| 4491 | ToQualifierLoc, |
| 4492 | ToIdentLocation, |
| 4493 | ToNominatedNamespace, *ToComAncestorOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4494 | return ToUsingDir; |
| 4495 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4496 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 4497 | LexicalDC->addDeclInternal(ToUsingDir); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4498 | |
| 4499 | return ToUsingDir; |
| 4500 | } |
| 4501 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4502 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4503 | UnresolvedUsingValueDecl *D) { |
| 4504 | DeclContext *DC, *LexicalDC; |
| 4505 | DeclarationName Name; |
| 4506 | SourceLocation Loc; |
| 4507 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4508 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4509 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4510 | if (ToD) |
| 4511 | return ToD; |
| 4512 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4513 | SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc; |
| 4514 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4515 | if (auto Imp = importSeq( |
| 4516 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(), |
| 4517 | D->getEllipsisLoc())) |
| 4518 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4519 | else |
| 4520 | return Imp.takeError(); |
| 4521 | |
| 4522 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4523 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4524 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4525 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4526 | UnresolvedUsingValueDecl *ToUsingValue; |
| 4527 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4528 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| 4529 | ToEllipsisLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4530 | return ToUsingValue; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4531 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4532 | ToUsingValue->setAccess(D->getAccess()); |
| 4533 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 4534 | LexicalDC->addDeclInternal(ToUsingValue); |
| 4535 | |
| 4536 | return ToUsingValue; |
| 4537 | } |
| 4538 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4539 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4540 | UnresolvedUsingTypenameDecl *D) { |
| 4541 | DeclContext *DC, *LexicalDC; |
| 4542 | DeclarationName Name; |
| 4543 | SourceLocation Loc; |
| 4544 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4545 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4546 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4547 | if (ToD) |
| 4548 | return ToD; |
| 4549 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4550 | SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc; |
| 4551 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4552 | if (auto Imp = importSeq( |
| 4553 | D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(), |
| 4554 | D->getEllipsisLoc())) |
| 4555 | std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4556 | else |
| 4557 | return Imp.takeError(); |
| 4558 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4559 | UnresolvedUsingTypenameDecl *ToUsing; |
| 4560 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4561 | ToUsingLoc, ToTypenameLoc, |
| 4562 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4563 | return ToUsing; |
| 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 | ToUsing->setAccess(D->getAccess()); |
| 4566 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4567 | LexicalDC->addDeclInternal(ToUsing); |
| 4568 | |
| 4569 | return ToUsing; |
| 4570 | } |
| 4571 | |
| Raphael Isemann | ba7bde6 | 2019-10-30 14:50:35 +0100 | [diff] [blame] | 4572 | ExpectedDecl ASTNodeImporter::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) { |
| 4573 | Decl* ToD = nullptr; |
| 4574 | switch (D->getBuiltinTemplateKind()) { |
| 4575 | case BuiltinTemplateKind::BTK__make_integer_seq: |
| 4576 | ToD = Importer.getToContext().getMakeIntegerSeqDecl(); |
| 4577 | break; |
| 4578 | case BuiltinTemplateKind::BTK__type_pack_element: |
| 4579 | ToD = Importer.getToContext().getTypePackElementDecl(); |
| 4580 | break; |
| 4581 | } |
| 4582 | assert(ToD && "BuiltinTemplateDecl of unsupported kind!"); |
| 4583 | Importer.MapImported(D, ToD); |
| 4584 | return ToD; |
| 4585 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4586 | |
| 4587 | Error ASTNodeImporter::ImportDefinition( |
| 4588 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4589 | if (To->getDefinition()) { |
| 4590 | // Check consistency of superclass. |
| 4591 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 4592 | if (FromSuper) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4593 | if (auto FromSuperOrErr = import(FromSuper)) |
| 4594 | FromSuper = *FromSuperOrErr; |
| 4595 | else |
| 4596 | return FromSuperOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4597 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4598 | |
| 4599 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4600 | if ((bool)FromSuper != (bool)ToSuper || |
| 4601 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4602 | Importer.ToDiag(To->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4603 | diag::warn_odr_objc_superclass_inconsistent) |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4604 | << To->getDeclName(); |
| 4605 | if (ToSuper) |
| 4606 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 4607 | << To->getSuperClass()->getDeclName(); |
| 4608 | else |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4609 | Importer.ToDiag(To->getLocation(), |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4610 | diag::note_odr_objc_missing_superclass); |
| 4611 | if (From->getSuperClass()) |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4612 | Importer.FromDiag(From->getSuperClassLoc(), |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4613 | diag::note_odr_objc_superclass) |
| 4614 | << From->getSuperClass()->getDeclName(); |
| 4615 | else |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4616 | Importer.FromDiag(From->getLocation(), |
| 4617 | diag::note_odr_objc_missing_superclass); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4618 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4619 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4620 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4621 | if (Error Err = ImportDeclContext(From)) |
| 4622 | return Err; |
| 4623 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4624 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4625 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4626 | // Start the definition. |
| 4627 | To->startDefinition(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4628 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4629 | // If this class has a superclass, import it. |
| 4630 | if (From->getSuperClass()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4631 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) |
| 4632 | To->setSuperClass(*SuperTInfoOrErr); |
| 4633 | else |
| 4634 | return SuperTInfoOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4635 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4636 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4637 | // Import protocols |
| 4638 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4639 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4640 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = |
| 4641 | From->protocol_loc_begin(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4642 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4643 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4644 | FromProtoEnd = From->protocol_end(); |
| 4645 | FromProto != FromProtoEnd; |
| 4646 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4647 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4648 | Protocols.push_back(*ToProtoOrErr); |
| 4649 | else |
| 4650 | return ToProtoOrErr.takeError(); |
| 4651 | |
| 4652 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4653 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4654 | else |
| 4655 | return ToProtoLocOrErr.takeError(); |
| 4656 | |
| 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 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4660 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4661 | ProtocolLocs.data(), Importer.getToContext()); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4662 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4663 | // Import categories. When the categories themselves are imported, they'll |
| 4664 | // hook themselves into this interface. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4665 | for (auto *Cat : From->known_categories()) { |
| 4666 | auto ToCatOrErr = import(Cat); |
| 4667 | if (!ToCatOrErr) |
| 4668 | return ToCatOrErr.takeError(); |
| 4669 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4670 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4671 | // If we have an @implementation, import it as well. |
| 4672 | if (From->getImplementation()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4673 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = |
| 4674 | import(From->getImplementation())) |
| 4675 | To->setImplementation(*ToImplOrErr); |
| 4676 | else |
| 4677 | return ToImplOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4678 | } |
| 4679 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4680 | if (shouldForceImportDeclContext(Kind)) { |
| 4681 | // Import all of the members of this class. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4682 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4683 | return Err; |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4684 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4685 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4686 | } |
| 4687 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4688 | Expected<ObjCTypeParamList *> |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4689 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 4690 | if (!list) |
| 4691 | return nullptr; |
| 4692 | |
| 4693 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4694 | for (auto *fromTypeParam : *list) { |
| 4695 | if (auto toTypeParamOrErr = import(fromTypeParam)) |
| 4696 | toTypeParams.push_back(*toTypeParamOrErr); |
| 4697 | else |
| 4698 | return toTypeParamOrErr.takeError(); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4699 | } |
| 4700 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4701 | auto LAngleLocOrErr = import(list->getLAngleLoc()); |
| 4702 | if (!LAngleLocOrErr) |
| 4703 | return LAngleLocOrErr.takeError(); |
| 4704 | |
| 4705 | auto RAngleLocOrErr = import(list->getRAngleLoc()); |
| 4706 | if (!RAngleLocOrErr) |
| 4707 | return RAngleLocOrErr.takeError(); |
| 4708 | |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4709 | return ObjCTypeParamList::create(Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4710 | *LAngleLocOrErr, |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4711 | toTypeParams, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4712 | *RAngleLocOrErr); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4713 | } |
| 4714 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4715 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4716 | // If this class has a definition in the translation unit we're coming from, |
| 4717 | // but this particular declaration is not that definition, import the |
| 4718 | // definition and map to that. |
| 4719 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 4720 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4721 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4722 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4723 | else |
| 4724 | return ImportedDefOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4725 | } |
| 4726 | |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4727 | // Import the major distinguishing characteristics of an @interface. |
| 4728 | DeclContext *DC, *LexicalDC; |
| 4729 | DeclarationName Name; |
| 4730 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4731 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4732 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4733 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4734 | if (ToD) |
| 4735 | return ToD; |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4736 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4737 | // Look for an existing interface with the same name. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4738 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4739 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4740 | for (auto *FoundDecl : FoundDecls) { |
| 4741 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4742 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4743 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4744 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4745 | break; |
| 4746 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4747 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4748 | // Create an interface declaration, if one does not already exist. |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4749 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4750 | if (!ToIface) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4751 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4752 | if (!AtBeginLocOrErr) |
| 4753 | return AtBeginLocOrErr.takeError(); |
| 4754 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4755 | if (GetImportedOrCreateDecl( |
| 4756 | ToIface, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4757 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4758 | /*TypeParamList=*/nullptr, |
| 4759 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 4760 | return ToIface; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4761 | ToIface->setLexicalDeclContext(LexicalDC); |
| 4762 | LexicalDC->addDeclInternal(ToIface); |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4763 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4764 | Importer.MapImported(D, ToIface); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4765 | // Import the type parameter list after MapImported, to avoid |
| Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4766 | // loops when bringing in their DeclContext. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4767 | if (auto ToPListOrErr = |
| 4768 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) |
| 4769 | ToIface->setTypeParamList(*ToPListOrErr); |
| 4770 | else |
| 4771 | return ToPListOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4772 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4773 | if (D->isThisDeclarationADefinition()) |
| 4774 | if (Error Err = ImportDefinition(D, ToIface)) |
| 4775 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4776 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4777 | return ToIface; |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4778 | } |
| 4779 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4780 | ExpectedDecl |
| 4781 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 4782 | ObjCCategoryDecl *Category; |
| 4783 | if (Error Err = importInto(Category, D->getCategoryDecl())) |
| 4784 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4785 | |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4786 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4787 | if (!ToImpl) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4788 | DeclContext *DC, *LexicalDC; |
| 4789 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4790 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4791 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4792 | SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc; |
| 4793 | if (auto Imp = importSeq( |
| 4794 | D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc())) |
| 4795 | std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp; |
| 4796 | else |
| 4797 | return Imp.takeError(); |
| 4798 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4799 | if (GetImportedOrCreateDecl( |
| 4800 | ToImpl, D, Importer.getToContext(), DC, |
| 4801 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4802 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4803 | return ToImpl; |
| 4804 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4805 | ToImpl->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4806 | LexicalDC->addDeclInternal(ToImpl); |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4807 | Category->setImplementation(ToImpl); |
| 4808 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4809 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4810 | Importer.MapImported(D, ToImpl); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4811 | if (Error Err = ImportDeclContext(D)) |
| 4812 | return std::move(Err); |
| 4813 | |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4814 | return ToImpl; |
| 4815 | } |
| 4816 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4817 | ExpectedDecl |
| 4818 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4819 | // Find the corresponding interface. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4820 | ObjCInterfaceDecl *Iface; |
| 4821 | if (Error Err = importInto(Iface, D->getClassInterface())) |
| 4822 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4823 | |
| 4824 | // Import the superclass, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4825 | ObjCInterfaceDecl *Super; |
| 4826 | if (Error Err = importInto(Super, D->getSuperClass())) |
| 4827 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4828 | |
| 4829 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4830 | if (!Impl) { |
| 4831 | // We haven't imported an implementation yet. Create a new @implementation |
| 4832 | // now. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4833 | DeclContext *DC, *LexicalDC; |
| 4834 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4835 | return std::move(Err); |
| 4836 | |
| 4837 | SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc; |
| 4838 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 4839 | if (auto Imp = importSeq( |
| 4840 | D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(), |
| 4841 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 4842 | std::tie( |
| 4843 | ToLocation, ToAtStartLoc, ToSuperClassLoc, |
| 4844 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 4845 | else |
| 4846 | return Imp.takeError(); |
| 4847 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4848 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4849 | DC, Iface, Super, |
| 4850 | ToLocation, |
| 4851 | ToAtStartLoc, |
| 4852 | ToSuperClassLoc, |
| 4853 | ToIvarLBraceLoc, |
| 4854 | ToIvarRBraceLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4855 | return Impl; |
| 4856 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4857 | Impl->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4858 | |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4859 | // Associate the implementation with the class it implements. |
| 4860 | Iface->setImplementation(Impl); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4861 | Importer.MapImported(D, Iface->getImplementation()); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4862 | } else { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4863 | Importer.MapImported(D, Iface->getImplementation()); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4864 | |
| 4865 | // Verify that the existing @implementation has the same superclass. |
| 4866 | if ((Super && !Impl->getSuperClass()) || |
| 4867 | (!Super && Impl->getSuperClass()) || |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4868 | (Super && Impl->getSuperClass() && |
| 4869 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4870 | Impl->getSuperClass()))) { |
| 4871 | Importer.ToDiag(Impl->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4872 | diag::warn_odr_objc_superclass_inconsistent) |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4873 | << Iface->getDeclName(); |
| 4874 | // FIXME: It would be nice to have the location of the superclass |
| 4875 | // below. |
| 4876 | if (Impl->getSuperClass()) |
| 4877 | Importer.ToDiag(Impl->getLocation(), |
| 4878 | diag::note_odr_objc_superclass) |
| 4879 | << Impl->getSuperClass()->getDeclName(); |
| 4880 | else |
| 4881 | Importer.ToDiag(Impl->getLocation(), |
| 4882 | diag::note_odr_objc_missing_superclass); |
| 4883 | if (D->getSuperClass()) |
| 4884 | Importer.FromDiag(D->getLocation(), |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4885 | diag::note_odr_objc_superclass) |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4886 | << D->getSuperClass()->getDeclName(); |
| 4887 | else |
| 4888 | Importer.FromDiag(D->getLocation(), |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4889 | diag::note_odr_objc_missing_superclass); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4890 | |
| 4891 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4892 | } |
| 4893 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4894 | |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4895 | // Import all of the members of this @implementation. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4896 | if (Error Err = ImportDeclContext(D)) |
| 4897 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4898 | |
| 4899 | return Impl; |
| 4900 | } |
| 4901 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4902 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4903 | // Import the major distinguishing characteristics of an @property. |
| 4904 | DeclContext *DC, *LexicalDC; |
| 4905 | DeclarationName Name; |
| 4906 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4907 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4908 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4909 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4910 | if (ToD) |
| 4911 | return ToD; |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4912 | |
| 4913 | // Check whether we have already imported this property. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4914 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4915 | for (auto *FoundDecl : FoundDecls) { |
| 4916 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4917 | // Check property types. |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4918 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4919 | FoundProp->getType())) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4920 | Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent) |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4921 | << Name << D->getType() << FoundProp->getType(); |
| 4922 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4923 | << FoundProp->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4924 | |
| 4925 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4926 | } |
| 4927 | |
| 4928 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4929 | |
| 4930 | // Consider these properties to be equivalent. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4931 | Importer.MapImported(D, FoundProp); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4932 | return FoundProp; |
| 4933 | } |
| 4934 | } |
| 4935 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4936 | QualType ToType; |
| 4937 | TypeSourceInfo *ToTypeSourceInfo; |
| 4938 | SourceLocation ToAtLoc, ToLParenLoc; |
| 4939 | if (auto Imp = importSeq( |
| 4940 | D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc())) |
| 4941 | std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp; |
| 4942 | else |
| 4943 | return Imp.takeError(); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4944 | |
| 4945 | // Create the new property. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4946 | ObjCPropertyDecl *ToProperty; |
| 4947 | if (GetImportedOrCreateDecl( |
| 4948 | ToProperty, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4949 | Name.getAsIdentifierInfo(), ToAtLoc, |
| 4950 | ToLParenLoc, ToType, |
| 4951 | ToTypeSourceInfo, D->getPropertyImplementation())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4952 | return ToProperty; |
| 4953 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4954 | Selector ToGetterName, ToSetterName; |
| 4955 | SourceLocation ToGetterNameLoc, ToSetterNameLoc; |
| 4956 | ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl; |
| 4957 | ObjCIvarDecl *ToPropertyIvarDecl; |
| 4958 | if (auto Imp = importSeq( |
| 4959 | D->getGetterName(), D->getSetterName(), |
| 4960 | D->getGetterNameLoc(), D->getSetterNameLoc(), |
| 4961 | D->getGetterMethodDecl(), D->getSetterMethodDecl(), |
| 4962 | D->getPropertyIvarDecl())) |
| 4963 | std::tie( |
| 4964 | ToGetterName, ToSetterName, |
| 4965 | ToGetterNameLoc, ToSetterNameLoc, |
| 4966 | ToGetterMethodDecl, ToSetterMethodDecl, |
| 4967 | ToPropertyIvarDecl) = *Imp; |
| 4968 | else |
| 4969 | return Imp.takeError(); |
| 4970 | |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4971 | ToProperty->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4972 | LexicalDC->addDeclInternal(ToProperty); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4973 | |
| 4974 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
| Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4975 | ToProperty->setPropertyAttributesAsWritten( |
| 4976 | D->getPropertyAttributesAsWritten()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4977 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); |
| 4978 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); |
| 4979 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); |
| 4980 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); |
| 4981 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4982 | return ToProperty; |
| 4983 | } |
| 4984 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4985 | ExpectedDecl |
| 4986 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 4987 | ObjCPropertyDecl *Property; |
| 4988 | if (Error Err = importInto(Property, D->getPropertyDecl())) |
| 4989 | return std::move(Err); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4990 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4991 | DeclContext *DC, *LexicalDC; |
| 4992 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4993 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4994 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4995 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4996 | |
| 4997 | // Import the ivar (for an @synthesize). |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4998 | ObjCIvarDecl *Ivar = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4999 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) |
| 5000 | return std::move(Err); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5001 | |
| 5002 | ObjCPropertyImplDecl *ToImpl |
| Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 5003 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 5004 | Property->getQueryKind()); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5005 | if (!ToImpl) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5006 | SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc; |
| 5007 | if (auto Imp = importSeq( |
| 5008 | D->getBeginLoc(), D->getLocation(), D->getPropertyIvarDeclLoc())) |
| 5009 | std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp; |
| 5010 | else |
| 5011 | return Imp.takeError(); |
| 5012 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5013 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5014 | ToBeginLoc, |
| 5015 | ToLocation, Property, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5016 | D->getPropertyImplementation(), Ivar, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5017 | ToPropertyIvarDeclLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5018 | return ToImpl; |
| 5019 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5020 | ToImpl->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 5021 | LexicalDC->addDeclInternal(ToImpl); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5022 | } else { |
| 5023 | // Check that we have the same kind of property implementation (@synthesize |
| 5024 | // vs. @dynamic). |
| 5025 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5026 | Importer.ToDiag(ToImpl->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 5027 | diag::warn_odr_objc_property_impl_kind_inconsistent) |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5028 | << Property->getDeclName() |
| 5029 | << (ToImpl->getPropertyImplementation() |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5030 | == ObjCPropertyImplDecl::Dynamic); |
| 5031 | Importer.FromDiag(D->getLocation(), |
| 5032 | diag::note_odr_objc_property_impl_kind) |
| 5033 | << D->getPropertyDecl()->getDeclName() |
| 5034 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5035 | |
| 5036 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5037 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5038 | |
| 5039 | // For @synthesize, check that we have the same |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5040 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 5041 | Ivar != ToImpl->getPropertyIvarDecl()) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5042 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 5043 | diag::warn_odr_objc_synthesize_ivar_inconsistent) |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5044 | << Property->getDeclName() |
| 5045 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 5046 | << Ivar->getDeclName(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5047 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5048 | diag::note_odr_objc_synthesize_ivar_here) |
| 5049 | << D->getPropertyIvarDecl()->getDeclName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5050 | |
| 5051 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5052 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5053 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5054 | // Merge the existing implementation with the new implementation. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5055 | Importer.MapImported(D, ToImpl); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5056 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5057 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 5058 | return ToImpl; |
| 5059 | } |
| 5060 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5061 | ExpectedDecl |
| 5062 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5063 | // For template arguments, we adopt the translation unit as our declaration |
| 5064 | // context. This context will be fixed when the actual template declaration |
| 5065 | // is created. |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5066 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5067 | // FIXME: Import default argument. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5068 | |
| 5069 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5070 | if (!BeginLocOrErr) |
| 5071 | return BeginLocOrErr.takeError(); |
| 5072 | |
| 5073 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 5074 | if (!LocationOrErr) |
| 5075 | return LocationOrErr.takeError(); |
| 5076 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5077 | TemplateTypeParmDecl *ToD = nullptr; |
| 5078 | (void)GetImportedOrCreateDecl( |
| 5079 | ToD, D, Importer.getToContext(), |
| 5080 | Importer.getToContext().getTranslationUnitDecl(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5081 | *BeginLocOrErr, *LocationOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5082 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| 5083 | D->wasDeclaredWithTypename(), D->isParameterPack()); |
| 5084 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5085 | } |
| 5086 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5087 | ExpectedDecl |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5088 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5089 | DeclarationName ToDeclName; |
| 5090 | SourceLocation ToLocation, ToInnerLocStart; |
| 5091 | QualType ToType; |
| 5092 | TypeSourceInfo *ToTypeSourceInfo; |
| 5093 | if (auto Imp = importSeq( |
| 5094 | D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(), |
| 5095 | D->getInnerLocStart())) |
| 5096 | std::tie( |
| 5097 | ToDeclName, ToLocation, ToType, ToTypeSourceInfo, |
| 5098 | ToInnerLocStart) = *Imp; |
| 5099 | else |
| 5100 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5101 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5102 | // FIXME: Import default argument. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5103 | |
| 5104 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 5105 | (void)GetImportedOrCreateDecl( |
| 5106 | ToD, D, Importer.getToContext(), |
| 5107 | Importer.getToContext().getTranslationUnitDecl(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5108 | ToInnerLocStart, ToLocation, D->getDepth(), |
| 5109 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, |
| 5110 | D->isParameterPack(), ToTypeSourceInfo); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5111 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5112 | } |
| 5113 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5114 | ExpectedDecl |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5115 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 5116 | // Import the name of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5117 | auto NameOrErr = import(D->getDeclName()); |
| 5118 | if (!NameOrErr) |
| 5119 | return NameOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5120 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5121 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5122 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 5123 | if (!LocationOrErr) |
| 5124 | return LocationOrErr.takeError(); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5125 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5126 | // Import template parameters. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5127 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5128 | if (!TemplateParamsOrErr) |
| 5129 | return TemplateParamsOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5130 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5131 | // FIXME: Import default argument. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5132 | |
| 5133 | TemplateTemplateParmDecl *ToD = nullptr; |
| 5134 | (void)GetImportedOrCreateDecl( |
| 5135 | ToD, D, Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5136 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, |
| 5137 | D->getDepth(), D->getPosition(), D->isParameterPack(), |
| 5138 | (*NameOrErr).getAsIdentifierInfo(), |
| 5139 | *TemplateParamsOrErr); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5140 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5141 | } |
| 5142 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5143 | // Returns the definition for a (forward) declaration of a TemplateDecl, if |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5144 | // it has any definition in the redecl chain. |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5145 | template <typename T> static auto getTemplateDefinition(T *D) -> T * { |
| 5146 | assert(D->getTemplatedDecl() && "Should be called on templates only"); |
| 5147 | auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5148 | if (!ToTemplatedDef) |
| 5149 | return nullptr; |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5150 | auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate(); |
| 5151 | return cast_or_null<T>(TemplateWithDef); |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5152 | } |
| 5153 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5154 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5155 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5156 | // Import the major distinguishing characteristics of this class template. |
| 5157 | DeclContext *DC, *LexicalDC; |
| 5158 | DeclarationName Name; |
| 5159 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5160 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5161 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5162 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5163 | if (ToD) |
| 5164 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5165 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5166 | ClassTemplateDecl *FoundByLookup = nullptr; |
| 5167 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5168 | // We may already have a template of the same name; try to find and match it. |
| 5169 | if (!DC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5170 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5171 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5172 | for (auto *FoundDecl : FoundDecls) { |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5173 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary | |
| 5174 | Decl::IDNS_TagFriend)) |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5175 | continue; |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5176 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5177 | Decl *Found = FoundDecl; |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5178 | auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found); |
| 5179 | if (FoundTemplate) { |
| Balázs Kéri | c2f6efc | 2019-11-15 15:05:20 +0100 | [diff] [blame] | 5180 | if (!hasSameVisibilityContext(FoundTemplate, D)) |
| 5181 | continue; |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5182 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5183 | if (IsStructuralMatch(D, FoundTemplate)) { |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5184 | ClassTemplateDecl *TemplateWithDef = |
| 5185 | getTemplateDefinition(FoundTemplate); |
| Balazs Keri | 2e16060 | 2019-08-12 10:07:38 +0000 | [diff] [blame] | 5186 | if (D->isThisDeclarationADefinition() && TemplateWithDef) |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5187 | return Importer.MapImported(D, TemplateWithDef); |
| Balazs Keri | 2e16060 | 2019-08-12 10:07:38 +0000 | [diff] [blame] | 5188 | if (!FoundByLookup) |
| 5189 | FoundByLookup = FoundTemplate; |
| 5190 | // Search in all matches because there may be multiple decl chains, |
| 5191 | // see ASTTests test ImportExistingFriendClassTemplateDef. |
| 5192 | continue; |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5193 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5194 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5195 | } |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5196 | } |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5197 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5198 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5199 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 5200 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), |
| 5201 | ConflictingDecls.size()); |
| 5202 | if (NameOrErr) |
| 5203 | Name = NameOrErr.get(); |
| 5204 | else |
| 5205 | return NameOrErr.takeError(); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5206 | } |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5207 | } |
| 5208 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5209 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 5210 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5211 | // Create the declaration that is being templated. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5212 | CXXRecordDecl *ToTemplated; |
| 5213 | if (Error Err = importInto(ToTemplated, FromTemplated)) |
| 5214 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5215 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5216 | // Create the class template declaration itself. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5217 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5218 | if (!TemplateParamsOrErr) |
| 5219 | return TemplateParamsOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5220 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5221 | ClassTemplateDecl *D2; |
| 5222 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5223 | *TemplateParamsOrErr, ToTemplated)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5224 | return D2; |
| 5225 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5226 | ToTemplated->setDescribedClassTemplate(D2); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5227 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5228 | D2->setAccess(D->getAccess()); |
| 5229 | D2->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5230 | |
| Gabor Marton | bc5b7e2 | 2019-12-04 17:12:08 +0100 | [diff] [blame] | 5231 | addDeclToContexts(D, D2); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5232 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5233 | if (FoundByLookup) { |
| 5234 | auto *Recent = |
| 5235 | const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5236 | |
| 5237 | // It is possible that during the import of the class template definition |
| 5238 | // we start the import of a fwd friend decl of the very same class template |
| 5239 | // and we add the fwd friend decl to the lookup table. But the ToTemplated |
| 5240 | // had been created earlier and by that time the lookup could not find |
| 5241 | // anything existing, so it has no previous decl. Later, (still during the |
| 5242 | // import of the fwd friend decl) we start to import the definition again |
| 5243 | // and this time the lookup finds the previous fwd friend class template. |
| 5244 | // In this case we must set up the previous decl for the templated decl. |
| 5245 | if (!ToTemplated->getPreviousDecl()) { |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5246 | assert(FoundByLookup->getTemplatedDecl() && |
| 5247 | "Found decl must have its templated decl set"); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5248 | CXXRecordDecl *PrevTemplated = |
| 5249 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5250 | if (ToTemplated != PrevTemplated) |
| 5251 | ToTemplated->setPreviousDecl(PrevTemplated); |
| 5252 | } |
| 5253 | |
| 5254 | D2->setPreviousDecl(Recent); |
| 5255 | } |
| 5256 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5257 | if (FromTemplated->isCompleteDefinition() && |
| 5258 | !ToTemplated->isCompleteDefinition()) { |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5259 | // FIXME: Import definition! |
| 5260 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5261 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5262 | return D2; |
| 5263 | } |
| 5264 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5265 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5266 | ClassTemplateSpecializationDecl *D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5267 | ClassTemplateDecl *ClassTemplate; |
| 5268 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) |
| 5269 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5270 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5271 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5272 | DeclContext *DC, *LexicalDC; |
| 5273 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5274 | return std::move(Err); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5275 | |
| 5276 | // Import template arguments. |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5277 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5278 | if (Error Err = ImportTemplateArguments( |
| 5279 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5280 | return std::move(Err); |
| Vedant Kumar | 5094e6d | 2019-12-18 14:52:51 -0800 | [diff] [blame] | 5281 | |
| 5282 | // Try to find an existing specialization with these template arguments. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5283 | void *InsertPos = nullptr; |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5284 | ClassTemplateSpecializationDecl *PrevDecl = nullptr; |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5285 | ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 5286 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); |
| Vedant Kumar | 5094e6d | 2019-12-18 14:52:51 -0800 | [diff] [blame] | 5287 | if (PartialSpec) |
| 5288 | PrevDecl = |
| 5289 | ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos); |
| 5290 | else |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5291 | PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5292 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5293 | if (PrevDecl) { |
| 5294 | if (IsStructuralMatch(D, PrevDecl)) { |
| 5295 | if (D->isThisDeclarationADefinition() && PrevDecl->getDefinition()) { |
| 5296 | Importer.MapImported(D, PrevDecl->getDefinition()); |
| 5297 | // Import those default field initializers which have been |
| 5298 | // instantiated in the "From" context, but not in the "To" context. |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5299 | for (auto *FromField : D->fields()) { |
| 5300 | auto ToOrErr = import(FromField); |
| 5301 | if (!ToOrErr) |
| 5302 | return ToOrErr.takeError(); |
| 5303 | } |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5304 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5305 | // Import those methods which have been instantiated in the |
| 5306 | // "From" context, but not in the "To" context. |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5307 | for (CXXMethodDecl *FromM : D->methods()) { |
| 5308 | auto ToOrErr = import(FromM); |
| 5309 | if (!ToOrErr) |
| 5310 | return ToOrErr.takeError(); |
| 5311 | } |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5312 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5313 | // TODO Import instantiated default arguments. |
| 5314 | // TODO Import instantiated exception specifications. |
| 5315 | // |
| 5316 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint |
| 5317 | // what else could be fused during an AST merge. |
| 5318 | return PrevDecl; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5319 | } |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5320 | } else { // ODR violation. |
| 5321 | // FIXME HandleNameConflict |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 5322 | return make_error<ImportError>(ImportError::NameConflict); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5323 | } |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5324 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5325 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5326 | // Import the location of this declaration. |
| 5327 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5328 | if (!BeginLocOrErr) |
| 5329 | return BeginLocOrErr.takeError(); |
| 5330 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); |
| 5331 | if (!IdLocOrErr) |
| 5332 | return IdLocOrErr.takeError(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5333 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5334 | // Create the specialization. |
| 5335 | ClassTemplateSpecializationDecl *D2 = nullptr; |
| 5336 | if (PartialSpec) { |
| 5337 | // Import TemplateArgumentListInfo. |
| 5338 | TemplateArgumentListInfo ToTAInfo; |
| 5339 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 5340 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
| 5341 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5342 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5343 | QualType CanonInjType; |
| 5344 | if (Error Err = importInto( |
| 5345 | CanonInjType, PartialSpec->getInjectedSpecializationType())) |
| 5346 | return std::move(Err); |
| 5347 | CanonInjType = CanonInjType.getCanonicalType(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5348 | |
| Vedant Kumar | 5094e6d | 2019-12-18 14:52:51 -0800 | [diff] [blame] | 5349 | auto ToTPListOrErr = import(PartialSpec->getTemplateParameters()); |
| 5350 | if (!ToTPListOrErr) |
| 5351 | return ToTPListOrErr.takeError(); |
| 5352 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5353 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
| 5354 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| Vedant Kumar | 5094e6d | 2019-12-18 14:52:51 -0800 | [diff] [blame] | 5355 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, ClassTemplate, |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5356 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 5357 | ToTAInfo, CanonInjType, |
| 5358 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) |
| 5359 | return D2; |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5360 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5361 | // Update InsertPos, because preceding import calls may have invalidated |
| 5362 | // it by adding new specializations. |
| Vedant Kumar | 5094e6d | 2019-12-18 14:52:51 -0800 | [diff] [blame] | 5363 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos)) |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5364 | // Add this partial specialization to the class template. |
| Vedant Kumar | 5094e6d | 2019-12-18 14:52:51 -0800 | [diff] [blame] | 5365 | ClassTemplate->AddPartialSpecialization( |
| 5366 | cast<ClassTemplatePartialSpecializationDecl>(D2), InsertPos); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5367 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5368 | } else { // Not a partial specialization. |
| 5369 | if (GetImportedOrCreateDecl( |
| 5370 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5371 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, |
| 5372 | PrevDecl)) |
| 5373 | return D2; |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5374 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5375 | // Update InsertPos, because preceding import calls may have invalidated |
| 5376 | // it by adding new specializations. |
| 5377 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) |
| 5378 | // Add this specialization to the class template. |
| 5379 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 5380 | } |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5381 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5382 | D2->setSpecializationKind(D->getSpecializationKind()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5383 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5384 | // Set the context of this specialization/instantiation. |
| 5385 | D2->setLexicalDeclContext(LexicalDC); |
| 5386 | |
| 5387 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 5388 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 5389 | LexicalDC->addDeclInternal(D2); |
| 5390 | } |
| 5391 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 5392 | if (auto BraceRangeOrErr = import(D->getBraceRange())) |
| 5393 | D2->setBraceRange(*BraceRangeOrErr); |
| 5394 | else |
| 5395 | return BraceRangeOrErr.takeError(); |
| 5396 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5397 | // Import the qualifier, if any. |
| 5398 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5399 | D2->setQualifierInfo(*LocOrErr); |
| 5400 | else |
| 5401 | return LocOrErr.takeError(); |
| 5402 | |
| 5403 | if (auto *TSI = D->getTypeAsWritten()) { |
| 5404 | if (auto TInfoOrErr = import(TSI)) |
| 5405 | D2->setTypeAsWritten(*TInfoOrErr); |
| 5406 | else |
| 5407 | return TInfoOrErr.takeError(); |
| 5408 | |
| 5409 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) |
| 5410 | D2->setTemplateKeywordLoc(*LocOrErr); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5411 | else |
| 5412 | return LocOrErr.takeError(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5413 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5414 | if (auto LocOrErr = import(D->getExternLoc())) |
| 5415 | D2->setExternLoc(*LocOrErr); |
| 5416 | else |
| 5417 | return LocOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5418 | } |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5419 | |
| 5420 | if (D->getPointOfInstantiation().isValid()) { |
| 5421 | if (auto POIOrErr = import(D->getPointOfInstantiation())) |
| 5422 | D2->setPointOfInstantiation(*POIOrErr); |
| 5423 | else |
| 5424 | return POIOrErr.takeError(); |
| 5425 | } |
| 5426 | |
| 5427 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 5428 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5429 | if (D->isCompleteDefinition()) |
| 5430 | if (Error Err = ImportDefinition(D, D2)) |
| 5431 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5432 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5433 | return D2; |
| 5434 | } |
| 5435 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5436 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5437 | // If this variable has a definition in the translation unit we're coming |
| 5438 | // from, |
| 5439 | // but this particular declaration is not that definition, import the |
| 5440 | // definition and map to that. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5441 | auto *Definition = |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5442 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 5443 | if (Definition && Definition != D->getTemplatedDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5444 | if (ExpectedDecl ImportedDefOrErr = import( |
| 5445 | Definition->getDescribedVarTemplate())) |
| 5446 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5447 | else |
| 5448 | return ImportedDefOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5449 | } |
| 5450 | |
| 5451 | // Import the major distinguishing characteristics of this variable template. |
| 5452 | DeclContext *DC, *LexicalDC; |
| 5453 | DeclarationName Name; |
| 5454 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5455 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5456 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5457 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5458 | if (ToD) |
| 5459 | return ToD; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5460 | |
| 5461 | // We may already have a template of the same name; try to find and match it. |
| 5462 | assert(!DC->isFunctionOrMethod() && |
| 5463 | "Variable templates cannot be declared at function scope"); |
| 5464 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5465 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5466 | for (auto *FoundDecl : FoundDecls) { |
| 5467 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5468 | continue; |
| 5469 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5470 | Decl *Found = FoundDecl; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5471 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5472 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5473 | // The variable templates structurally match; call it the same template. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5474 | Importer.MapImported(D->getTemplatedDecl(), |
| 5475 | FoundTemplate->getTemplatedDecl()); |
| 5476 | return Importer.MapImported(D, FoundTemplate); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5477 | } |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5478 | ConflictingDecls.push_back(FoundDecl); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5479 | } |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5480 | } |
| 5481 | |
| 5482 | if (!ConflictingDecls.empty()) { |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 5483 | ExpectedName NameOrErr = Importer.HandleNameConflict( |
| 5484 | Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(), |
| 5485 | ConflictingDecls.size()); |
| 5486 | if (NameOrErr) |
| 5487 | Name = NameOrErr.get(); |
| 5488 | else |
| 5489 | return NameOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5490 | } |
| 5491 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5492 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 5493 | |
| 5494 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5495 | // FIXME: Value not used? |
| 5496 | ExpectedType TypeOrErr = import(DTemplated->getType()); |
| 5497 | if (!TypeOrErr) |
| 5498 | return TypeOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5499 | |
| 5500 | // Create the declaration that is being templated. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5501 | VarDecl *ToTemplated; |
| 5502 | if (Error Err = importInto(ToTemplated, DTemplated)) |
| 5503 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5504 | |
| 5505 | // Create the variable template declaration itself. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5506 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5507 | if (!TemplateParamsOrErr) |
| 5508 | return TemplateParamsOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5509 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5510 | VarTemplateDecl *ToVarTD; |
| 5511 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5512 | Name, *TemplateParamsOrErr, ToTemplated)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5513 | return ToVarTD; |
| 5514 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5515 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5516 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5517 | ToVarTD->setAccess(D->getAccess()); |
| 5518 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 5519 | LexicalDC->addDeclInternal(ToVarTD); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5520 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5521 | if (DTemplated->isThisDeclarationADefinition() && |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5522 | !ToTemplated->isThisDeclarationADefinition()) { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5523 | // FIXME: Import definition! |
| 5524 | } |
| 5525 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5526 | return ToVarTD; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5527 | } |
| 5528 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5529 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5530 | VarTemplateSpecializationDecl *D) { |
| 5531 | // If this record has a definition in the translation unit we're coming from, |
| 5532 | // but this particular declaration is not that definition, import the |
| 5533 | // definition and map to that. |
| 5534 | VarDecl *Definition = D->getDefinition(); |
| 5535 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5536 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5537 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5538 | else |
| 5539 | return ImportedDefOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5540 | } |
| 5541 | |
| Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 5542 | VarTemplateDecl *VarTemplate = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5543 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) |
| 5544 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5545 | |
| 5546 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5547 | DeclContext *DC, *LexicalDC; |
| 5548 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5549 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5550 | |
| 5551 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5552 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5553 | if (!BeginLocOrErr) |
| 5554 | return BeginLocOrErr.takeError(); |
| 5555 | |
| 5556 | auto IdLocOrErr = import(D->getLocation()); |
| 5557 | if (!IdLocOrErr) |
| 5558 | return IdLocOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5559 | |
| 5560 | // Import template arguments. |
| 5561 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5562 | if (Error Err = ImportTemplateArguments( |
| 5563 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5564 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5565 | |
| 5566 | // Try to find an existing specialization with these template arguments. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5567 | void *InsertPos = nullptr; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5568 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
| Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 5569 | TemplateArgs, InsertPos); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5570 | if (D2) { |
| 5571 | // We already have a variable template specialization with these template |
| 5572 | // arguments. |
| 5573 | |
| 5574 | // FIXME: Check for specialization vs. instantiation errors. |
| 5575 | |
| 5576 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 5577 | if (!D->isThisDeclarationADefinition() || |
| 5578 | IsStructuralMatch(D, FoundDef)) { |
| 5579 | // The record types structurally match, or the "from" translation |
| 5580 | // unit only had a forward declaration anyway; call it the same |
| 5581 | // variable. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5582 | return Importer.MapImported(D, FoundDef); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5583 | } |
| 5584 | } |
| 5585 | } else { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5586 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5587 | QualType T; |
| 5588 | if (Error Err = importInto(T, D->getType())) |
| 5589 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5590 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5591 | auto TInfoOrErr = import(D->getTypeSourceInfo()); |
| 5592 | if (!TInfoOrErr) |
| 5593 | return TInfoOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5594 | |
| 5595 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5596 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5597 | D->getTemplateArgsInfo(), ToTAInfo)) |
| 5598 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5599 | |
| 5600 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5601 | // Create a new specialization. |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5602 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 5603 | // Import TemplateArgumentListInfo |
| 5604 | TemplateArgumentListInfo ArgInfos; |
| 5605 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 5606 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5607 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5608 | *FromTAArgsAsWritten, ArgInfos)) |
| 5609 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5610 | |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5611 | auto ToTPListOrErr = import(FromPartial->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5612 | if (!ToTPListOrErr) |
| 5613 | return ToTPListOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5614 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5615 | PartVarSpecDecl *ToPartial; |
| 5616 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5617 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, |
| 5618 | VarTemplate, T, *TInfoOrErr, |
| 5619 | D->getStorageClass(), TemplateArgs, ArgInfos)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5620 | return ToPartial; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5621 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5622 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( |
| 5623 | FromPartial->getInstantiatedFromMember())) |
| 5624 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); |
| 5625 | else |
| 5626 | return ToInstOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5627 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5628 | if (FromPartial->isMemberSpecialization()) |
| 5629 | ToPartial->setMemberSpecialization(); |
| 5630 | |
| 5631 | D2 = ToPartial; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5632 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5633 | } else { // Full specialization |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5634 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, |
| 5635 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, |
| 5636 | T, *TInfoOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5637 | D->getStorageClass(), TemplateArgs)) |
| 5638 | return D2; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5639 | } |
| 5640 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5641 | if (D->getPointOfInstantiation().isValid()) { |
| 5642 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) |
| 5643 | D2->setPointOfInstantiation(*POIOrErr); |
| 5644 | else |
| 5645 | return POIOrErr.takeError(); |
| 5646 | } |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5647 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5648 | D2->setSpecializationKind(D->getSpecializationKind()); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5649 | D2->setTemplateArgsInfo(ToTAInfo); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5650 | |
| 5651 | // Add this specialization to the class template. |
| 5652 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 5653 | |
| 5654 | // Import the qualifier, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5655 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5656 | D2->setQualifierInfo(*LocOrErr); |
| 5657 | else |
| 5658 | return LocOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5659 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5660 | if (D->isConstexpr()) |
| 5661 | D2->setConstexpr(true); |
| 5662 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5663 | // Add the specialization to this context. |
| 5664 | D2->setLexicalDeclContext(LexicalDC); |
| 5665 | LexicalDC->addDeclInternal(D2); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5666 | |
| 5667 | D2->setAccess(D->getAccess()); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5668 | } |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5669 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5670 | if (Error Err = ImportInitializer(D, D2)) |
| 5671 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5672 | |
| 5673 | return D2; |
| 5674 | } |
| 5675 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5676 | ExpectedDecl |
| 5677 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5678 | DeclContext *DC, *LexicalDC; |
| 5679 | DeclarationName Name; |
| 5680 | SourceLocation Loc; |
| 5681 | NamedDecl *ToD; |
| 5682 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5683 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5684 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5685 | |
| 5686 | if (ToD) |
| 5687 | return ToD; |
| 5688 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5689 | const FunctionTemplateDecl *FoundByLookup = nullptr; |
| 5690 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5691 | // Try to find a function in our own ("to") context with the same name, same |
| 5692 | // type, and in the same context as the function we're importing. |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5693 | // FIXME Split this into a separate function. |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5694 | if (!LexicalDC->isFunctionOrMethod()) { |
| Gabor Marton | e331e63 | 2019-02-18 13:09:27 +0000 | [diff] [blame] | 5695 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5696 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5697 | for (auto *FoundDecl : FoundDecls) { |
| 5698 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5699 | continue; |
| 5700 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5701 | if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
| Balazs Keri | f8a89c8 | 2019-09-13 08:03:49 +0000 | [diff] [blame] | 5702 | if (!hasSameVisibilityContext(FoundTemplate, D)) |
| 5703 | continue; |
| 5704 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5705 | FunctionTemplateDecl *TemplateWithDef = |
| 5706 | getTemplateDefinition(FoundTemplate); |
| 5707 | if (D->isThisDeclarationADefinition() && TemplateWithDef) |
| 5708 | return Importer.MapImported(D, TemplateWithDef); |
| 5709 | |
| 5710 | FoundByLookup = FoundTemplate; |
| 5711 | break; |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5712 | // TODO: handle conflicting names |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5713 | } |
| 5714 | } |
| 5715 | } |
| 5716 | } |
| 5717 | |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5718 | auto ParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5719 | if (!ParamsOrErr) |
| 5720 | return ParamsOrErr.takeError(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5721 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5722 | FunctionDecl *TemplatedFD; |
| 5723 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) |
| 5724 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5725 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5726 | FunctionTemplateDecl *ToFunc; |
| 5727 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5728 | *ParamsOrErr, TemplatedFD)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5729 | return ToFunc; |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5730 | |
| 5731 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5732 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5733 | ToFunc->setAccess(D->getAccess()); |
| 5734 | ToFunc->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5735 | LexicalDC->addDeclInternal(ToFunc); |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5736 | |
| 5737 | if (FoundByLookup) { |
| 5738 | auto *Recent = |
| 5739 | const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5740 | if (!TemplatedFD->getPreviousDecl()) { |
| 5741 | assert(FoundByLookup->getTemplatedDecl() && |
| 5742 | "Found decl must have its templated decl set"); |
| 5743 | auto *PrevTemplated = |
| 5744 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5745 | if (TemplatedFD != PrevTemplated) |
| 5746 | TemplatedFD->setPreviousDecl(PrevTemplated); |
| 5747 | } |
| 5748 | ToFunc->setPreviousDecl(Recent); |
| 5749 | } |
| 5750 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5751 | return ToFunc; |
| 5752 | } |
| 5753 | |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5754 | //---------------------------------------------------------------------------- |
| 5755 | // Import Statements |
| 5756 | //---------------------------------------------------------------------------- |
| 5757 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5758 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5759 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) |
| 5760 | << S->getStmtClassName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5761 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5762 | } |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5763 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5764 | |
| 5765 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 5766 | if (Importer.returnWithErrorInTest()) |
| 5767 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5768 | SmallVector<IdentifierInfo *, 4> Names; |
| 5769 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 5770 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
| Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5771 | // ToII is nullptr when no symbolic name is given for output operand |
| 5772 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5773 | Names.push_back(ToII); |
| 5774 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5775 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5776 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 5777 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
| Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5778 | // ToII is nullptr when no symbolic name is given for input operand |
| 5779 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5780 | Names.push_back(ToII); |
| 5781 | } |
| 5782 | |
| 5783 | SmallVector<StringLiteral *, 4> Clobbers; |
| 5784 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5785 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) |
| 5786 | Clobbers.push_back(*ClobberOrErr); |
| 5787 | else |
| 5788 | return ClobberOrErr.takeError(); |
| 5789 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5790 | } |
| 5791 | |
| 5792 | SmallVector<StringLiteral *, 4> Constraints; |
| 5793 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5794 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) |
| 5795 | Constraints.push_back(*OutputOrErr); |
| 5796 | else |
| 5797 | return OutputOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5798 | } |
| 5799 | |
| 5800 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5801 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) |
| 5802 | Constraints.push_back(*InputOrErr); |
| 5803 | else |
| 5804 | return InputOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5805 | } |
| 5806 | |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5807 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() + |
| 5808 | S->getNumLabels()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5809 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) |
| 5810 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5811 | |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5812 | if (Error Err = |
| 5813 | ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
| 5814 | return std::move(Err); |
| 5815 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5816 | if (Error Err = ImportArrayChecked( |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5817 | S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs())) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5818 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5819 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5820 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); |
| 5821 | if (!AsmLocOrErr) |
| 5822 | return AsmLocOrErr.takeError(); |
| 5823 | auto AsmStrOrErr = import(S->getAsmString()); |
| 5824 | if (!AsmStrOrErr) |
| 5825 | return AsmStrOrErr.takeError(); |
| 5826 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); |
| 5827 | if (!RParenLocOrErr) |
| 5828 | return RParenLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5829 | |
| 5830 | return new (Importer.getToContext()) GCCAsmStmt( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5831 | Importer.getToContext(), |
| 5832 | *AsmLocOrErr, |
| 5833 | S->isSimple(), |
| 5834 | S->isVolatile(), |
| 5835 | S->getNumOutputs(), |
| 5836 | S->getNumInputs(), |
| 5837 | Names.data(), |
| 5838 | Constraints.data(), |
| 5839 | Exprs.data(), |
| 5840 | *AsmStrOrErr, |
| 5841 | S->getNumClobbers(), |
| 5842 | Clobbers.data(), |
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5843 | S->getNumLabels(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5844 | *RParenLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5845 | } |
| 5846 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5847 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 5848 | auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc()); |
| 5849 | if (!Imp) |
| 5850 | return Imp.takeError(); |
| 5851 | |
| 5852 | DeclGroupRef ToDG; |
| 5853 | SourceLocation ToBeginLoc, ToEndLoc; |
| 5854 | std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp; |
| 5855 | |
| 5856 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5857 | } |
| 5858 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5859 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5860 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); |
| 5861 | if (!ToSemiLocOrErr) |
| 5862 | return ToSemiLocOrErr.takeError(); |
| 5863 | return new (Importer.getToContext()) NullStmt( |
| 5864 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5865 | } |
| 5866 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5867 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5868 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5869 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5870 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) |
| 5871 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5872 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5873 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); |
| 5874 | if (!ToLBracLocOrErr) |
| 5875 | return ToLBracLocOrErr.takeError(); |
| 5876 | |
| 5877 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); |
| 5878 | if (!ToRBracLocOrErr) |
| 5879 | return ToRBracLocOrErr.takeError(); |
| 5880 | |
| 5881 | return CompoundStmt::Create( |
| 5882 | Importer.getToContext(), ToStmts, |
| 5883 | *ToLBracLocOrErr, *ToRBracLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5884 | } |
| 5885 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5886 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 5887 | auto Imp = importSeq( |
| 5888 | S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(), |
| 5889 | S->getEllipsisLoc(), S->getColonLoc()); |
| 5890 | if (!Imp) |
| 5891 | return Imp.takeError(); |
| 5892 | |
| 5893 | Expr *ToLHS, *ToRHS; |
| 5894 | Stmt *ToSubStmt; |
| 5895 | SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc; |
| 5896 | std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) = |
| 5897 | *Imp; |
| 5898 | |
| Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 5899 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, |
| 5900 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
| Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5901 | ToStmt->setSubStmt(ToSubStmt); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5902 | |
| Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5903 | return ToStmt; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5904 | } |
| 5905 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5906 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 5907 | auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt()); |
| 5908 | if (!Imp) |
| 5909 | return Imp.takeError(); |
| 5910 | |
| 5911 | SourceLocation ToDefaultLoc, ToColonLoc; |
| 5912 | Stmt *ToSubStmt; |
| 5913 | std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp; |
| 5914 | |
| 5915 | return new (Importer.getToContext()) DefaultStmt( |
| 5916 | ToDefaultLoc, ToColonLoc, ToSubStmt); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5917 | } |
| 5918 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5919 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 5920 | auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt()); |
| 5921 | if (!Imp) |
| 5922 | return Imp.takeError(); |
| 5923 | |
| 5924 | SourceLocation ToIdentLoc; |
| 5925 | LabelDecl *ToLabelDecl; |
| 5926 | Stmt *ToSubStmt; |
| 5927 | std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp; |
| 5928 | |
| 5929 | return new (Importer.getToContext()) LabelStmt( |
| 5930 | ToIdentLoc, ToLabelDecl, ToSubStmt); |
| 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::VisitAttributedStmt(AttributedStmt *S) { |
| 5934 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); |
| 5935 | if (!ToAttrLocOrErr) |
| 5936 | return ToAttrLocOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5937 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 5938 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5939 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) |
| 5940 | return std::move(Err); |
| 5941 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 5942 | if (!ToSubStmtOrErr) |
| 5943 | return ToSubStmtOrErr.takeError(); |
| 5944 | |
| 5945 | return AttributedStmt::Create( |
| 5946 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5947 | } |
| 5948 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5949 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 5950 | auto Imp = importSeq( |
| 5951 | S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5952 | S->getThen(), S->getElseLoc(), S->getElse()); |
| 5953 | if (!Imp) |
| 5954 | return Imp.takeError(); |
| 5955 | |
| 5956 | SourceLocation ToIfLoc, ToElseLoc; |
| 5957 | Stmt *ToInit, *ToThen, *ToElse; |
| 5958 | VarDecl *ToConditionVariable; |
| 5959 | Expr *ToCond; |
| 5960 | std::tie( |
| 5961 | ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) = |
| 5962 | *Imp; |
| 5963 | |
| Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 5964 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), |
| 5965 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, |
| 5966 | ToElse); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5967 | } |
| 5968 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5969 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
| 5970 | auto Imp = importSeq( |
| 5971 | S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5972 | S->getBody(), S->getSwitchLoc()); |
| 5973 | if (!Imp) |
| 5974 | return Imp.takeError(); |
| 5975 | |
| 5976 | Stmt *ToInit, *ToBody; |
| 5977 | VarDecl *ToConditionVariable; |
| 5978 | Expr *ToCond; |
| 5979 | SourceLocation ToSwitchLoc; |
| 5980 | std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp; |
| 5981 | |
| Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 5982 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, |
| 5983 | ToConditionVariable, ToCond); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5984 | ToStmt->setBody(ToBody); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5985 | ToStmt->setSwitchLoc(ToSwitchLoc); |
| 5986 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5987 | // Now we have to re-chain the cases. |
| 5988 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 5989 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 5990 | SC = SC->getNextSwitchCase()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5991 | Expected<SwitchCase *> ToSCOrErr = import(SC); |
| 5992 | if (!ToSCOrErr) |
| 5993 | return ToSCOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5994 | if (LastChainedSwitchCase) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5995 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5996 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5997 | ToStmt->setSwitchCaseList(*ToSCOrErr); |
| 5998 | LastChainedSwitchCase = *ToSCOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5999 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6000 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6001 | return ToStmt; |
| 6002 | } |
| 6003 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6004 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 6005 | auto Imp = importSeq( |
| 6006 | S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc()); |
| 6007 | if (!Imp) |
| 6008 | return Imp.takeError(); |
| 6009 | |
| 6010 | VarDecl *ToConditionVariable; |
| 6011 | Expr *ToCond; |
| 6012 | Stmt *ToBody; |
| 6013 | SourceLocation ToWhileLoc; |
| 6014 | std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp; |
| 6015 | |
| Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 6016 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, |
| 6017 | ToBody, ToWhileLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6018 | } |
| 6019 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6020 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 6021 | auto Imp = importSeq( |
| 6022 | S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(), |
| 6023 | S->getRParenLoc()); |
| 6024 | if (!Imp) |
| 6025 | return Imp.takeError(); |
| 6026 | |
| 6027 | Stmt *ToBody; |
| 6028 | Expr *ToCond; |
| 6029 | SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc; |
| 6030 | std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp; |
| 6031 | |
| 6032 | return new (Importer.getToContext()) DoStmt( |
| 6033 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6034 | } |
| 6035 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6036 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 6037 | auto Imp = importSeq( |
| 6038 | S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(), |
| 6039 | S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc()); |
| 6040 | if (!Imp) |
| 6041 | return Imp.takeError(); |
| 6042 | |
| 6043 | Stmt *ToInit; |
| 6044 | Expr *ToCond, *ToInc; |
| 6045 | VarDecl *ToConditionVariable; |
| 6046 | Stmt *ToBody; |
| 6047 | SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc; |
| 6048 | std::tie( |
| 6049 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, |
| 6050 | ToLParenLoc, ToRParenLoc) = *Imp; |
| 6051 | |
| 6052 | return new (Importer.getToContext()) ForStmt( |
| 6053 | Importer.getToContext(), |
| 6054 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, |
| 6055 | ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6056 | } |
| 6057 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6058 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 6059 | auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc()); |
| 6060 | if (!Imp) |
| 6061 | return Imp.takeError(); |
| 6062 | |
| 6063 | LabelDecl *ToLabel; |
| 6064 | SourceLocation ToGotoLoc, ToLabelLoc; |
| 6065 | std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp; |
| 6066 | |
| 6067 | return new (Importer.getToContext()) GotoStmt( |
| 6068 | ToLabel, ToGotoLoc, ToLabelLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6069 | } |
| 6070 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6071 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 6072 | auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget()); |
| 6073 | if (!Imp) |
| 6074 | return Imp.takeError(); |
| 6075 | |
| 6076 | SourceLocation ToGotoLoc, ToStarLoc; |
| 6077 | Expr *ToTarget; |
| 6078 | std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp; |
| 6079 | |
| 6080 | return new (Importer.getToContext()) IndirectGotoStmt( |
| 6081 | ToGotoLoc, ToStarLoc, ToTarget); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6082 | } |
| 6083 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6084 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 6085 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); |
| 6086 | if (!ToContinueLocOrErr) |
| 6087 | return ToContinueLocOrErr.takeError(); |
| 6088 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6089 | } |
| 6090 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6091 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 6092 | auto ToBreakLocOrErr = import(S->getBreakLoc()); |
| 6093 | if (!ToBreakLocOrErr) |
| 6094 | return ToBreakLocOrErr.takeError(); |
| 6095 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6096 | } |
| 6097 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6098 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 6099 | auto Imp = importSeq( |
| 6100 | S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate()); |
| 6101 | if (!Imp) |
| 6102 | return Imp.takeError(); |
| 6103 | |
| 6104 | SourceLocation ToReturnLoc; |
| 6105 | Expr *ToRetValue; |
| 6106 | const VarDecl *ToNRVOCandidate; |
| 6107 | std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp; |
| 6108 | |
| Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 6109 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, |
| 6110 | ToNRVOCandidate); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6111 | } |
| 6112 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6113 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 6114 | auto Imp = importSeq( |
| 6115 | S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock()); |
| 6116 | if (!Imp) |
| 6117 | return Imp.takeError(); |
| 6118 | |
| 6119 | SourceLocation ToCatchLoc; |
| 6120 | VarDecl *ToExceptionDecl; |
| 6121 | Stmt *ToHandlerBlock; |
| 6122 | std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp; |
| 6123 | |
| 6124 | return new (Importer.getToContext()) CXXCatchStmt ( |
| 6125 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6126 | } |
| 6127 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6128 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 6129 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); |
| 6130 | if (!ToTryLocOrErr) |
| 6131 | return ToTryLocOrErr.takeError(); |
| 6132 | |
| 6133 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); |
| 6134 | if (!ToTryBlockOrErr) |
| 6135 | return ToTryBlockOrErr.takeError(); |
| 6136 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6137 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 6138 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 6139 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6140 | if (auto ToHandlerOrErr = import(FromHandler)) |
| 6141 | ToHandlers[HI] = *ToHandlerOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6142 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6143 | return ToHandlerOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6144 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6145 | |
| 6146 | return CXXTryStmt::Create( |
| 6147 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6148 | } |
| 6149 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6150 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| 6151 | auto Imp1 = importSeq( |
| 6152 | S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(), |
| 6153 | S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody()); |
| 6154 | if (!Imp1) |
| 6155 | return Imp1.takeError(); |
| 6156 | auto Imp2 = importSeq( |
| 6157 | S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc()); |
| 6158 | if (!Imp2) |
| 6159 | return Imp2.takeError(); |
| 6160 | |
| 6161 | DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt; |
| 6162 | Expr *ToCond, *ToInc; |
| 6163 | Stmt *ToInit, *ToBody; |
| 6164 | std::tie( |
| 6165 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 6166 | ToBody) = *Imp1; |
| 6167 | SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc; |
| 6168 | std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2; |
| 6169 | |
| 6170 | return new (Importer.getToContext()) CXXForRangeStmt( |
| 6171 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 6172 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6173 | } |
| 6174 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6175 | ExpectedStmt |
| 6176 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 6177 | auto Imp = importSeq( |
| 6178 | S->getElement(), S->getCollection(), S->getBody(), |
| 6179 | S->getForLoc(), S->getRParenLoc()); |
| 6180 | if (!Imp) |
| 6181 | return Imp.takeError(); |
| 6182 | |
| 6183 | Stmt *ToElement, *ToBody; |
| 6184 | Expr *ToCollection; |
| 6185 | SourceLocation ToForLoc, ToRParenLoc; |
| 6186 | std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp; |
| 6187 | |
| 6188 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, |
| 6189 | ToCollection, |
| 6190 | ToBody, |
| 6191 | ToForLoc, |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6192 | ToRParenLoc); |
| 6193 | } |
| 6194 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6195 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 6196 | auto Imp = importSeq( |
| 6197 | S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(), |
| 6198 | S->getCatchBody()); |
| 6199 | if (!Imp) |
| 6200 | return Imp.takeError(); |
| 6201 | |
| 6202 | SourceLocation ToAtCatchLoc, ToRParenLoc; |
| 6203 | VarDecl *ToCatchParamDecl; |
| 6204 | Stmt *ToCatchBody; |
| 6205 | std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp; |
| 6206 | |
| 6207 | return new (Importer.getToContext()) ObjCAtCatchStmt ( |
| 6208 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6209 | } |
| 6210 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6211 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 6212 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); |
| 6213 | if (!ToAtFinallyLocOrErr) |
| 6214 | return ToAtFinallyLocOrErr.takeError(); |
| 6215 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); |
| 6216 | if (!ToAtFinallyStmtOrErr) |
| 6217 | return ToAtFinallyStmtOrErr.takeError(); |
| 6218 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, |
| 6219 | *ToAtFinallyStmtOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6220 | } |
| 6221 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6222 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 6223 | auto Imp = importSeq( |
| 6224 | S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt()); |
| 6225 | if (!Imp) |
| 6226 | return Imp.takeError(); |
| 6227 | |
| 6228 | SourceLocation ToAtTryLoc; |
| 6229 | Stmt *ToTryBody, *ToFinallyStmt; |
| 6230 | std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp; |
| 6231 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6232 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 6233 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 6234 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6235 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) |
| 6236 | ToCatchStmts[CI] = *ToCatchStmtOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6237 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6238 | return ToCatchStmtOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6239 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6240 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6241 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6242 | ToAtTryLoc, ToTryBody, |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6243 | ToCatchStmts.begin(), ToCatchStmts.size(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6244 | ToFinallyStmt); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6245 | } |
| 6246 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6247 | ExpectedStmt ASTNodeImporter::VisitObjCAtSynchronizedStmt |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6248 | (ObjCAtSynchronizedStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6249 | auto Imp = importSeq( |
| 6250 | S->getAtSynchronizedLoc(), S->getSynchExpr(), S->getSynchBody()); |
| 6251 | if (!Imp) |
| 6252 | return Imp.takeError(); |
| 6253 | |
| 6254 | SourceLocation ToAtSynchronizedLoc; |
| 6255 | Expr *ToSynchExpr; |
| 6256 | Stmt *ToSynchBody; |
| 6257 | std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp; |
| 6258 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6259 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 6260 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 6261 | } |
| 6262 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6263 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 6264 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); |
| 6265 | if (!ToThrowLocOrErr) |
| 6266 | return ToThrowLocOrErr.takeError(); |
| 6267 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); |
| 6268 | if (!ToThrowExprOrErr) |
| 6269 | return ToThrowExprOrErr.takeError(); |
| 6270 | return new (Importer.getToContext()) ObjCAtThrowStmt( |
| 6271 | *ToThrowLocOrErr, *ToThrowExprOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6272 | } |
| 6273 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6274 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( |
| 6275 | ObjCAutoreleasePoolStmt *S) { |
| 6276 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); |
| 6277 | if (!ToAtLocOrErr) |
| 6278 | return ToAtLocOrErr.takeError(); |
| 6279 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 6280 | if (!ToSubStmtOrErr) |
| 6281 | return ToSubStmtOrErr.takeError(); |
| 6282 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, |
| 6283 | *ToSubStmtOrErr); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6284 | } |
| 6285 | |
| 6286 | //---------------------------------------------------------------------------- |
| 6287 | // Import Expressions |
| 6288 | //---------------------------------------------------------------------------- |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6289 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6290 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) |
| 6291 | << E->getStmtClassName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6292 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6293 | } |
| 6294 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6295 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 6296 | auto Imp = importSeq( |
| 6297 | E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(), |
| 6298 | E->getRParenLoc(), E->getType()); |
| 6299 | if (!Imp) |
| 6300 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6301 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6302 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6303 | Expr *ToSubExpr; |
| 6304 | TypeSourceInfo *ToWrittenTypeInfo; |
| 6305 | QualType ToType; |
| 6306 | std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) = |
| 6307 | *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6308 | |
| 6309 | return new (Importer.getToContext()) VAArgExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6310 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, |
| 6311 | E->isMicrosoftABI()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6312 | } |
| 6313 | |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6314 | ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) { |
| 6315 | auto Imp = importSeq(E->getCond(), E->getLHS(), E->getRHS(), |
| 6316 | E->getBuiltinLoc(), E->getRParenLoc(), E->getType()); |
| 6317 | if (!Imp) |
| 6318 | return Imp.takeError(); |
| 6319 | |
| 6320 | Expr *ToCond; |
| 6321 | Expr *ToLHS; |
| 6322 | Expr *ToRHS; |
| 6323 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6324 | QualType ToType; |
| 6325 | std::tie(ToCond, ToLHS, ToRHS, ToBuiltinLoc, ToRParenLoc, ToType) = *Imp; |
| 6326 | |
| 6327 | ExprValueKind VK = E->getValueKind(); |
| 6328 | ExprObjectKind OK = E->getObjectKind(); |
| 6329 | |
| 6330 | bool TypeDependent = ToCond->isTypeDependent(); |
| 6331 | bool ValueDependent = ToCond->isValueDependent(); |
| 6332 | |
| 6333 | // The value of CondIsTrue only matters if the value is not |
| 6334 | // condition-dependent. |
| 6335 | bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue(); |
| 6336 | |
| 6337 | return new (Importer.getToContext()) |
| 6338 | ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK, |
| 6339 | ToRParenLoc, CondIsTrue, TypeDependent, ValueDependent); |
| 6340 | } |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6341 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6342 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 6343 | ExpectedType TypeOrErr = import(E->getType()); |
| 6344 | if (!TypeOrErr) |
| 6345 | return TypeOrErr.takeError(); |
| 6346 | |
| 6347 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); |
| 6348 | if (!BeginLocOrErr) |
| 6349 | return BeginLocOrErr.takeError(); |
| 6350 | |
| 6351 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6352 | } |
| 6353 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6354 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 6355 | auto Imp = importSeq( |
| 6356 | E->getBeginLoc(), E->getType(), E->getFunctionName()); |
| 6357 | if (!Imp) |
| 6358 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6359 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6360 | SourceLocation ToBeginLoc; |
| 6361 | QualType ToType; |
| 6362 | StringLiteral *ToFunctionName; |
| 6363 | std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6364 | |
| Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 6365 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, |
| 6366 | E->getIdentKind(), ToFunctionName); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6367 | } |
| 6368 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6369 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
| 6370 | auto Imp = importSeq( |
| 6371 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDecl(), |
| 6372 | E->getLocation(), E->getType()); |
| 6373 | if (!Imp) |
| 6374 | return Imp.takeError(); |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6375 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6376 | NestedNameSpecifierLoc ToQualifierLoc; |
| 6377 | SourceLocation ToTemplateKeywordLoc, ToLocation; |
| 6378 | ValueDecl *ToDecl; |
| 6379 | QualType ToType; |
| 6380 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) = |
| 6381 | *Imp; |
| 6382 | |
| 6383 | NamedDecl *ToFoundD = nullptr; |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6384 | if (E->getDecl() != E->getFoundDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6385 | auto FoundDOrErr = import(E->getFoundDecl()); |
| 6386 | if (!FoundDOrErr) |
| 6387 | return FoundDOrErr.takeError(); |
| 6388 | ToFoundD = *FoundDOrErr; |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6389 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6390 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6391 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6392 | TemplateArgumentListInfo *ToResInfo = nullptr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6393 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6394 | if (Error Err = |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 6395 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6396 | E->template_arguments(), ToTAInfo)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6397 | return std::move(Err); |
| 6398 | ToResInfo = &ToTAInfo; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6399 | } |
| 6400 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6401 | auto *ToE = DeclRefExpr::Create( |
| 6402 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, |
| 6403 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, |
| Richard Smith | 715f7a1 | 2019-06-11 17:50:32 +0000 | [diff] [blame] | 6404 | E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse()); |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 6405 | if (E->hadMultipleCandidates()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6406 | ToE->setHadMultipleCandidates(true); |
| 6407 | return ToE; |
| Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 6408 | } |
| 6409 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6410 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 6411 | ExpectedType TypeOrErr = import(E->getType()); |
| 6412 | if (!TypeOrErr) |
| 6413 | return TypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6414 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6415 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6416 | } |
| 6417 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6418 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 6419 | ExpectedExpr ToInitOrErr = import(E->getInit()); |
| 6420 | if (!ToInitOrErr) |
| 6421 | return ToInitOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6422 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6423 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); |
| 6424 | if (!ToEqualOrColonLocOrErr) |
| 6425 | return ToEqualOrColonLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6426 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6427 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6428 | // List elements from the second, the first is Init itself |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6429 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { |
| 6430 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) |
| 6431 | ToIndexExprs[I - 1] = *ToArgOrErr; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6432 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6433 | return ToArgOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6434 | } |
| 6435 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6436 | SmallVector<Designator, 4> ToDesignators(E->size()); |
| 6437 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) |
| 6438 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6439 | |
| 6440 | return DesignatedInitExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6441 | Importer.getToContext(), ToDesignators, |
| 6442 | ToIndexExprs, *ToEqualOrColonLocOrErr, |
| 6443 | E->usesGNUSyntax(), *ToInitOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6444 | } |
| 6445 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6446 | ExpectedStmt |
| 6447 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 6448 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6449 | if (!ToTypeOrErr) |
| 6450 | return ToTypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6451 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6452 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6453 | if (!ToLocationOrErr) |
| 6454 | return ToLocationOrErr.takeError(); |
| 6455 | |
| 6456 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( |
| 6457 | *ToTypeOrErr, *ToLocationOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6458 | } |
| 6459 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6460 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 6461 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6462 | if (!ToTypeOrErr) |
| 6463 | return ToTypeOrErr.takeError(); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6464 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6465 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6466 | if (!ToLocationOrErr) |
| 6467 | return ToLocationOrErr.takeError(); |
| 6468 | |
| 6469 | return IntegerLiteral::Create( |
| 6470 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6471 | } |
| 6472 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6473 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6474 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 6475 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6476 | if (!ToTypeOrErr) |
| 6477 | return ToTypeOrErr.takeError(); |
| 6478 | |
| 6479 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6480 | if (!ToLocationOrErr) |
| 6481 | return ToLocationOrErr.takeError(); |
| 6482 | |
| 6483 | return FloatingLiteral::Create( |
| 6484 | Importer.getToContext(), E->getValue(), E->isExact(), |
| 6485 | *ToTypeOrErr, *ToLocationOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6486 | } |
| 6487 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6488 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 6489 | auto ToTypeOrErr = import(E->getType()); |
| 6490 | if (!ToTypeOrErr) |
| 6491 | return ToTypeOrErr.takeError(); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6492 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6493 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6494 | if (!ToSubExprOrErr) |
| 6495 | return ToSubExprOrErr.takeError(); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6496 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6497 | return new (Importer.getToContext()) ImaginaryLiteral( |
| 6498 | *ToSubExprOrErr, *ToTypeOrErr); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6499 | } |
| 6500 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6501 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 6502 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6503 | if (!ToTypeOrErr) |
| 6504 | return ToTypeOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6505 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6506 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6507 | if (!ToLocationOrErr) |
| 6508 | return ToLocationOrErr.takeError(); |
| 6509 | |
| 6510 | return new (Importer.getToContext()) CharacterLiteral( |
| 6511 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); |
| Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 6512 | } |
| 6513 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6514 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 6515 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6516 | if (!ToTypeOrErr) |
| 6517 | return ToTypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6518 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6519 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); |
| 6520 | if (Error Err = ImportArrayChecked( |
| 6521 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) |
| 6522 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6523 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6524 | return StringLiteral::Create( |
| 6525 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), |
| 6526 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6527 | } |
| 6528 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6529 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 6530 | auto Imp = importSeq( |
| 6531 | E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(), |
| 6532 | E->getInitializer()); |
| 6533 | if (!Imp) |
| 6534 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6535 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6536 | SourceLocation ToLParenLoc; |
| 6537 | TypeSourceInfo *ToTypeSourceInfo; |
| 6538 | QualType ToType; |
| 6539 | Expr *ToInitializer; |
| 6540 | std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6541 | |
| 6542 | return new (Importer.getToContext()) CompoundLiteralExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6543 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), |
| 6544 | ToInitializer, E->isFileScope()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6545 | } |
| 6546 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6547 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 6548 | auto Imp = importSeq( |
| 6549 | E->getBuiltinLoc(), E->getType(), E->getRParenLoc()); |
| 6550 | if (!Imp) |
| 6551 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6552 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6553 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6554 | QualType ToType; |
| 6555 | std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp; |
| 6556 | |
| 6557 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); |
| 6558 | if (Error Err = ImportArrayChecked( |
| 6559 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 6560 | ToExprs.begin())) |
| 6561 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6562 | |
| 6563 | return new (Importer.getToContext()) AtomicExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6564 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6565 | } |
| 6566 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6567 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 6568 | auto Imp = importSeq( |
| 6569 | E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType()); |
| 6570 | if (!Imp) |
| 6571 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6572 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6573 | SourceLocation ToAmpAmpLoc, ToLabelLoc; |
| 6574 | LabelDecl *ToLabel; |
| 6575 | QualType ToType; |
| 6576 | std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6577 | |
| 6578 | return new (Importer.getToContext()) AddrLabelExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6579 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6580 | } |
| 6581 | |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6582 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { |
| 6583 | auto Imp = importSeq(E->getSubExpr()); |
| 6584 | if (!Imp) |
| 6585 | return Imp.takeError(); |
| 6586 | |
| 6587 | Expr *ToSubExpr; |
| 6588 | std::tie(ToSubExpr) = *Imp; |
| 6589 | |
| Gauthier Harnisch | 83c7b61 | 2019-06-15 10:24:47 +0000 | [diff] [blame] | 6590 | // TODO : Handle APValue::ValueKind that require importing. |
| 6591 | APValue::ValueKind Kind = E->getResultAPValueKind(); |
| 6592 | if (Kind == APValue::Int || Kind == APValue::Float || |
| 6593 | Kind == APValue::FixedPoint || Kind == APValue::ComplexFloat || |
| 6594 | Kind == APValue::ComplexInt) |
| 6595 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, |
| 6596 | E->getAPValueResult()); |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 6597 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr); |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6598 | } |
| 6599 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6600 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 6601 | auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr()); |
| 6602 | if (!Imp) |
| 6603 | return Imp.takeError(); |
| 6604 | |
| 6605 | SourceLocation ToLParen, ToRParen; |
| 6606 | Expr *ToSubExpr; |
| 6607 | std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6608 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6609 | return new (Importer.getToContext()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6610 | ParenExpr(ToLParen, ToRParen, ToSubExpr); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6611 | } |
| 6612 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6613 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 6614 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); |
| 6615 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) |
| 6616 | return std::move(Err); |
| 6617 | |
| 6618 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); |
| 6619 | if (!ToLParenLocOrErr) |
| 6620 | return ToLParenLocOrErr.takeError(); |
| 6621 | |
| 6622 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); |
| 6623 | if (!ToRParenLocOrErr) |
| 6624 | return ToRParenLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6625 | |
| Bruno Ricci | f49e1ca | 2018-11-20 16:20:40 +0000 | [diff] [blame] | 6626 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, |
| 6627 | ToExprs, *ToRParenLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6628 | } |
| 6629 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6630 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 6631 | auto Imp = importSeq( |
| 6632 | E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc()); |
| 6633 | if (!Imp) |
| 6634 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6635 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6636 | CompoundStmt *ToSubStmt; |
| 6637 | QualType ToType; |
| 6638 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 6639 | std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6640 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6641 | return new (Importer.getToContext()) StmtExpr( |
| 6642 | ToSubStmt, ToType, ToLParenLoc, ToRParenLoc); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6643 | } |
| 6644 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6645 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 6646 | auto Imp = importSeq( |
| 6647 | E->getSubExpr(), E->getType(), E->getOperatorLoc()); |
| 6648 | if (!Imp) |
| 6649 | return Imp.takeError(); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6650 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6651 | Expr *ToSubExpr; |
| 6652 | QualType ToType; |
| 6653 | SourceLocation ToOperatorLoc; |
| 6654 | std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6655 | |
| Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6656 | return new (Importer.getToContext()) UnaryOperator( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6657 | ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), |
| 6658 | ToOperatorLoc, E->canOverflow()); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6659 | } |
| 6660 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6661 | ExpectedStmt |
| Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6662 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6663 | auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc()); |
| 6664 | if (!Imp) |
| 6665 | return Imp.takeError(); |
| 6666 | |
| 6667 | QualType ToType; |
| 6668 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6669 | std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6670 | |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6671 | if (E->isArgumentType()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6672 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = |
| 6673 | import(E->getArgumentTypeInfo()); |
| 6674 | if (!ToArgumentTypeInfoOrErr) |
| 6675 | return ToArgumentTypeInfoOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6676 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6677 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6678 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, |
| 6679 | ToRParenLoc); |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6680 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6681 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6682 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); |
| 6683 | if (!ToArgumentExprOrErr) |
| 6684 | return ToArgumentExprOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6685 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6686 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6687 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6688 | } |
| 6689 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6690 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 6691 | auto Imp = importSeq( |
| 6692 | E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc()); |
| 6693 | if (!Imp) |
| 6694 | return Imp.takeError(); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6695 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6696 | Expr *ToLHS, *ToRHS; |
| 6697 | QualType ToType; |
| 6698 | SourceLocation ToOperatorLoc; |
| 6699 | std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6700 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6701 | return new (Importer.getToContext()) BinaryOperator( |
| 6702 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6703 | E->getObjectKind(), ToOperatorLoc, E->getFPFeatures()); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6704 | } |
| 6705 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6706 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 6707 | auto Imp = importSeq( |
| 6708 | E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(), |
| 6709 | E->getRHS(), E->getType()); |
| 6710 | if (!Imp) |
| 6711 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6712 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6713 | Expr *ToCond, *ToLHS, *ToRHS; |
| 6714 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6715 | QualType ToType; |
| 6716 | std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6717 | |
| 6718 | return new (Importer.getToContext()) ConditionalOperator( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6719 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, |
| 6720 | E->getValueKind(), E->getObjectKind()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6721 | } |
| 6722 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6723 | ExpectedStmt ASTNodeImporter::VisitBinaryConditionalOperator( |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6724 | BinaryConditionalOperator *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6725 | auto Imp = importSeq( |
| 6726 | E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(), |
| 6727 | E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType()); |
| 6728 | if (!Imp) |
| 6729 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6730 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6731 | Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr; |
| 6732 | OpaqueValueExpr *ToOpaqueValue; |
| 6733 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6734 | QualType ToType; |
| 6735 | std::tie( |
| 6736 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc, |
| 6737 | ToColonLoc, ToType) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6738 | |
| 6739 | return new (Importer.getToContext()) BinaryConditionalOperator( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6740 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, |
| 6741 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), |
| 6742 | E->getObjectKind()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6743 | } |
| 6744 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6745 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 6746 | auto Imp = importSeq( |
| 6747 | E->getBeginLoc(), E->getQueriedTypeSourceInfo(), |
| 6748 | E->getDimensionExpression(), E->getEndLoc(), E->getType()); |
| 6749 | if (!Imp) |
| 6750 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6751 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6752 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6753 | TypeSourceInfo *ToQueriedTypeSourceInfo; |
| 6754 | Expr *ToDimensionExpression; |
| 6755 | QualType ToType; |
| 6756 | std::tie( |
| 6757 | ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc, |
| 6758 | ToType) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6759 | |
| 6760 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6761 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), |
| 6762 | ToDimensionExpression, ToEndLoc, ToType); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6763 | } |
| 6764 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6765 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 6766 | auto Imp = importSeq( |
| 6767 | E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType()); |
| 6768 | if (!Imp) |
| 6769 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6770 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6771 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6772 | Expr *ToQueriedExpression; |
| 6773 | QualType ToType; |
| 6774 | std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6775 | |
| 6776 | return new (Importer.getToContext()) ExpressionTraitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6777 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), |
| 6778 | ToEndLoc, ToType); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6779 | } |
| 6780 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6781 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6782 | auto Imp = importSeq( |
| 6783 | E->getLocation(), E->getType(), E->getSourceExpr()); |
| 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 | SourceLocation ToLocation; |
| 6788 | QualType ToType; |
| 6789 | Expr *ToSourceExpr; |
| 6790 | std::tie(ToLocation, ToType, ToSourceExpr) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6791 | |
| 6792 | return new (Importer.getToContext()) OpaqueValueExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6793 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6794 | } |
| 6795 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6796 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 6797 | auto Imp = importSeq( |
| 6798 | E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc()); |
| 6799 | if (!Imp) |
| 6800 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6801 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6802 | Expr *ToLHS, *ToRHS; |
| 6803 | SourceLocation ToRBracketLoc; |
| 6804 | QualType ToType; |
| 6805 | std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6806 | |
| 6807 | return new (Importer.getToContext()) ArraySubscriptExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6808 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), |
| 6809 | ToRBracketLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6810 | } |
| 6811 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6812 | ExpectedStmt |
| 6813 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 6814 | auto Imp = importSeq( |
| 6815 | E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(), |
| 6816 | E->getComputationResultType(), E->getOperatorLoc()); |
| 6817 | if (!Imp) |
| 6818 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6819 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6820 | Expr *ToLHS, *ToRHS; |
| 6821 | QualType ToType, ToComputationLHSType, ToComputationResultType; |
| 6822 | SourceLocation ToOperatorLoc; |
| 6823 | std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType, |
| 6824 | ToOperatorLoc) = *Imp; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6825 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6826 | return new (Importer.getToContext()) CompoundAssignOperator( |
| 6827 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6828 | E->getObjectKind(), ToComputationLHSType, ToComputationResultType, |
| 6829 | ToOperatorLoc, E->getFPFeatures()); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6830 | } |
| 6831 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6832 | Expected<CXXCastPath> |
| 6833 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { |
| 6834 | CXXCastPath Path; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6835 | 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] | 6836 | if (auto SpecOrErr = import(*I)) |
| 6837 | Path.push_back(*SpecOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6838 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6839 | return SpecOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6840 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6841 | return Path; |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6842 | } |
| 6843 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6844 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 6845 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6846 | if (!ToTypeOrErr) |
| 6847 | return ToTypeOrErr.takeError(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6848 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6849 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6850 | if (!ToSubExprOrErr) |
| 6851 | return ToSubExprOrErr.takeError(); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6852 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6853 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6854 | if (!ToBasePathOrErr) |
| 6855 | return ToBasePathOrErr.takeError(); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6856 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6857 | return ImplicitCastExpr::Create( |
| 6858 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, |
| 6859 | &(*ToBasePathOrErr), E->getValueKind()); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6860 | } |
| 6861 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6862 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 6863 | auto Imp1 = importSeq( |
| 6864 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten()); |
| 6865 | if (!Imp1) |
| 6866 | return Imp1.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6867 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6868 | QualType ToType; |
| 6869 | Expr *ToSubExpr; |
| 6870 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 6871 | std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1; |
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6872 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6873 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6874 | if (!ToBasePathOrErr) |
| 6875 | return ToBasePathOrErr.takeError(); |
| 6876 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6877 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6878 | switch (E->getStmtClass()) { |
| 6879 | case Stmt::CStyleCastExprClass: { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6880 | auto *CCE = cast<CStyleCastExpr>(E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6881 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); |
| 6882 | if (!ToLParenLocOrErr) |
| 6883 | return ToLParenLocOrErr.takeError(); |
| 6884 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); |
| 6885 | if (!ToRParenLocOrErr) |
| 6886 | return ToRParenLocOrErr.takeError(); |
| 6887 | return CStyleCastExpr::Create( |
| 6888 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), |
| 6889 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, |
| 6890 | *ToRParenLocOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6891 | } |
| 6892 | |
| 6893 | case Stmt::CXXFunctionalCastExprClass: { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6894 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6895 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); |
| 6896 | if (!ToLParenLocOrErr) |
| 6897 | return ToLParenLocOrErr.takeError(); |
| 6898 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); |
| 6899 | if (!ToRParenLocOrErr) |
| 6900 | return ToRParenLocOrErr.takeError(); |
| 6901 | return CXXFunctionalCastExpr::Create( |
| 6902 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, |
| 6903 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, |
| 6904 | *ToRParenLocOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6905 | } |
| 6906 | |
| 6907 | case Stmt::ObjCBridgedCastExprClass: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6908 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
| 6909 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); |
| 6910 | if (!ToLParenLocOrErr) |
| 6911 | return ToLParenLocOrErr.takeError(); |
| 6912 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); |
| 6913 | if (!ToBridgeKeywordLocOrErr) |
| 6914 | return ToBridgeKeywordLocOrErr.takeError(); |
| 6915 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 6916 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), |
| 6917 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6918 | } |
| 6919 | default: |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6920 | llvm_unreachable("Cast expression of unsupported type!"); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6921 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6922 | } |
| 6923 | } |
| 6924 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6925 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { |
| 6926 | SmallVector<OffsetOfNode, 4> ToNodes; |
| 6927 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { |
| 6928 | const OffsetOfNode &FromNode = E->getComponent(I); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6929 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6930 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6931 | if (FromNode.getKind() != OffsetOfNode::Base) { |
| 6932 | auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc()); |
| 6933 | if (!Imp) |
| 6934 | return Imp.takeError(); |
| 6935 | std::tie(ToBeginLoc, ToEndLoc) = *Imp; |
| 6936 | } |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6937 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6938 | switch (FromNode.getKind()) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6939 | case OffsetOfNode::Array: |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6940 | ToNodes.push_back( |
| 6941 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6942 | break; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6943 | case OffsetOfNode::Base: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6944 | auto ToBSOrErr = import(FromNode.getBase()); |
| 6945 | if (!ToBSOrErr) |
| 6946 | return ToBSOrErr.takeError(); |
| 6947 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6948 | break; |
| 6949 | } |
| 6950 | case OffsetOfNode::Field: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6951 | auto ToFieldOrErr = import(FromNode.getField()); |
| 6952 | if (!ToFieldOrErr) |
| 6953 | return ToFieldOrErr.takeError(); |
| 6954 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6955 | break; |
| 6956 | } |
| 6957 | case OffsetOfNode::Identifier: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6958 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); |
| 6959 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6960 | break; |
| 6961 | } |
| 6962 | } |
| 6963 | } |
| 6964 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6965 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); |
| 6966 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { |
| 6967 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); |
| 6968 | if (!ToIndexExprOrErr) |
| 6969 | return ToIndexExprOrErr.takeError(); |
| 6970 | ToExprs[I] = *ToIndexExprOrErr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6971 | } |
| 6972 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6973 | auto Imp = importSeq( |
| 6974 | E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(), |
| 6975 | E->getRParenLoc()); |
| 6976 | if (!Imp) |
| 6977 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6978 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6979 | QualType ToType; |
| 6980 | TypeSourceInfo *ToTypeSourceInfo; |
| 6981 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6982 | std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp; |
| 6983 | |
| 6984 | return OffsetOfExpr::Create( |
| 6985 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, |
| 6986 | ToExprs, ToRParenLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6987 | } |
| 6988 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6989 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 6990 | auto Imp = importSeq( |
| 6991 | E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc()); |
| 6992 | if (!Imp) |
| 6993 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6994 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6995 | QualType ToType; |
| 6996 | Expr *ToOperand; |
| 6997 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6998 | std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6999 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7000 | CanThrowResult ToCanThrow; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7001 | if (E->isValueDependent()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7002 | ToCanThrow = CT_Dependent; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7003 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7004 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7005 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7006 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 7007 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7008 | } |
| 7009 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7010 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 7011 | auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc()); |
| 7012 | if (!Imp) |
| 7013 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7014 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7015 | Expr *ToSubExpr; |
| 7016 | QualType ToType; |
| 7017 | SourceLocation ToThrowLoc; |
| 7018 | std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7019 | |
| 7020 | return new (Importer.getToContext()) CXXThrowExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7021 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7022 | } |
| 7023 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7024 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 7025 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); |
| 7026 | if (!ToUsedLocOrErr) |
| 7027 | return ToUsedLocOrErr.takeError(); |
| 7028 | |
| 7029 | auto ToParamOrErr = import(E->getParam()); |
| 7030 | if (!ToParamOrErr) |
| 7031 | return ToParamOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7032 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7033 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); |
| 7034 | if (!UsedContextOrErr) |
| 7035 | return UsedContextOrErr.takeError(); |
| 7036 | |
| Balazs Keri | c509594 | 2019-08-14 09:41:39 +0000 | [diff] [blame] | 7037 | // Import the default arg if it was not imported yet. |
| 7038 | // This is needed because it can happen that during the import of the |
| 7039 | // default expression (from VisitParmVarDecl) the same ParmVarDecl is |
| 7040 | // encountered here. The default argument for a ParmVarDecl is set in the |
| 7041 | // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here, |
| 7042 | // see VisitParmVarDecl). |
| 7043 | ParmVarDecl *ToParam = *ToParamOrErr; |
| 7044 | if (!ToParam->getDefaultArg()) { |
| 7045 | Optional<ParmVarDecl *> FromParam = Importer.getImportedFromDecl(ToParam); |
| 7046 | assert(FromParam && "ParmVarDecl was not imported?"); |
| 7047 | |
| 7048 | if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam)) |
| 7049 | return std::move(Err); |
| 7050 | } |
| 7051 | |
| 7052 | return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr, |
| 7053 | *ToParamOrErr, *UsedContextOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7054 | } |
| 7055 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7056 | ExpectedStmt |
| 7057 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 7058 | auto Imp = importSeq( |
| 7059 | E->getType(), E->getTypeSourceInfo(), E->getRParenLoc()); |
| 7060 | if (!Imp) |
| 7061 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7062 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7063 | QualType ToType; |
| 7064 | TypeSourceInfo *ToTypeSourceInfo; |
| 7065 | SourceLocation ToRParenLoc; |
| 7066 | std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7067 | |
| 7068 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7069 | ToType, ToTypeSourceInfo, ToRParenLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7070 | } |
| 7071 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7072 | ExpectedStmt |
| 7073 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 7074 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7075 | if (!ToSubExprOrErr) |
| 7076 | return ToSubExprOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7077 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7078 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); |
| 7079 | if (!ToDtorOrErr) |
| 7080 | return ToDtorOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7081 | |
| 7082 | ASTContext &ToCtx = Importer.getToContext(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7083 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); |
| 7084 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7085 | } |
| 7086 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7087 | ExpectedStmt |
| 7088 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { |
| 7089 | auto Imp = importSeq( |
| 7090 | E->getConstructor(), E->getType(), E->getTypeSourceInfo(), |
| 7091 | E->getParenOrBraceRange()); |
| 7092 | if (!Imp) |
| 7093 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7094 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7095 | CXXConstructorDecl *ToConstructor; |
| 7096 | QualType ToType; |
| 7097 | TypeSourceInfo *ToTypeSourceInfo; |
| 7098 | SourceRange ToParenOrBraceRange; |
| 7099 | std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7100 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7101 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); |
| 7102 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7103 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7104 | |
| Bruno Ricci | ddb8f6b | 2018-12-22 14:39:30 +0000 | [diff] [blame] | 7105 | return CXXTemporaryObjectExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7106 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, |
| 7107 | ToParenOrBraceRange, E->hadMultipleCandidates(), |
| 7108 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 7109 | E->requiresZeroInitialization()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7110 | } |
| 7111 | |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7112 | ExpectedDecl ASTNodeImporter::VisitLifetimeExtendedTemporaryDecl( |
| 7113 | LifetimeExtendedTemporaryDecl *D) { |
| 7114 | DeclContext *DC, *LexicalDC; |
| 7115 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 7116 | return std::move(Err); |
| 7117 | |
| 7118 | auto Imp = importSeq(D->getTemporaryExpr(), D->getExtendingDecl()); |
| 7119 | // FIXME: the APValue should be imported as well if present. |
| 7120 | if (!Imp) |
| 7121 | return Imp.takeError(); |
| 7122 | |
| 7123 | Expr *Temporary; |
| 7124 | ValueDecl *ExtendingDecl; |
| 7125 | std::tie(Temporary, ExtendingDecl) = *Imp; |
| 7126 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
| 7127 | |
| 7128 | LifetimeExtendedTemporaryDecl *To; |
| 7129 | if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl, |
| 7130 | D->getManglingNumber())) |
| 7131 | return To; |
| 7132 | |
| 7133 | To->setLexicalDeclContext(LexicalDC); |
| 7134 | LexicalDC->addDeclInternal(To); |
| 7135 | return To; |
| 7136 | } |
| 7137 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7138 | ExpectedStmt |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7139 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7140 | auto Imp = importSeq(E->getType(), |
| 7141 | E->getLifetimeExtendedTemporaryDecl() ? nullptr |
| 7142 | : E->getSubExpr(), |
| 7143 | E->getLifetimeExtendedTemporaryDecl()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7144 | if (!Imp) |
| 7145 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7146 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7147 | QualType ToType; |
| 7148 | Expr *ToTemporaryExpr; |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7149 | LifetimeExtendedTemporaryDecl *ToMaterializedDecl; |
| 7150 | std::tie(ToType, ToTemporaryExpr, ToMaterializedDecl) = *Imp; |
| 7151 | if (!ToTemporaryExpr) |
| 7152 | ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7153 | |
| Tyker | b0561b3 | 2019-11-17 11:41:55 +0100 | [diff] [blame] | 7154 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
| 7155 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference(), |
| 7156 | ToMaterializedDecl); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7157 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7158 | return ToMTE; |
| 7159 | } |
| 7160 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7161 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 7162 | auto Imp = importSeq( |
| 7163 | E->getType(), E->getPattern(), E->getEllipsisLoc()); |
| 7164 | if (!Imp) |
| 7165 | return Imp.takeError(); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7166 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7167 | QualType ToType; |
| 7168 | Expr *ToPattern; |
| 7169 | SourceLocation ToEllipsisLoc; |
| 7170 | std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7171 | |
| 7172 | return new (Importer.getToContext()) PackExpansionExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7173 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7174 | } |
| 7175 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7176 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 7177 | auto Imp = importSeq( |
| 7178 | E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc()); |
| 7179 | if (!Imp) |
| 7180 | return Imp.takeError(); |
| 7181 | |
| 7182 | SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc; |
| 7183 | NamedDecl *ToPack; |
| 7184 | std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7185 | |
| 7186 | Optional<unsigned> Length; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7187 | if (!E->isValueDependent()) |
| 7188 | Length = E->getPackLength(); |
| 7189 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7190 | SmallVector<TemplateArgument, 8> ToPartialArguments; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7191 | if (E->isPartiallySubstituted()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7192 | if (Error Err = ImportTemplateArguments( |
| 7193 | E->getPartialArguments().data(), |
| 7194 | E->getPartialArguments().size(), |
| 7195 | ToPartialArguments)) |
| 7196 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7197 | } |
| 7198 | |
| 7199 | return SizeOfPackExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7200 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, |
| 7201 | Length, ToPartialArguments); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7202 | } |
| 7203 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7204 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7205 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { |
| 7206 | auto Imp = importSeq( |
| 7207 | E->getOperatorNew(), E->getOperatorDelete(), E->getTypeIdParens(), |
| 7208 | E->getArraySize(), E->getInitializer(), E->getType(), |
| 7209 | E->getAllocatedTypeSourceInfo(), E->getSourceRange(), |
| 7210 | E->getDirectInitRange()); |
| 7211 | if (!Imp) |
| 7212 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7213 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7214 | FunctionDecl *ToOperatorNew, *ToOperatorDelete; |
| 7215 | SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange; |
| Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 7216 | Optional<Expr *> ToArraySize; |
| 7217 | Expr *ToInitializer; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7218 | QualType ToType; |
| 7219 | TypeSourceInfo *ToAllocatedTypeSourceInfo; |
| 7220 | std::tie( |
| 7221 | ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer, |
| 7222 | ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7223 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7224 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); |
| 7225 | if (Error Err = |
| 7226 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) |
| 7227 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7228 | |
| Bruno Ricci | 9b6dfac | 2019-01-07 15:04:45 +0000 | [diff] [blame] | 7229 | return CXXNewExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7230 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, |
| 7231 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), |
| 7232 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), |
| 7233 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, |
| 7234 | ToDirectInitRange); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7235 | } |
| 7236 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7237 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 7238 | auto Imp = importSeq( |
| 7239 | E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc()); |
| 7240 | if (!Imp) |
| 7241 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7242 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7243 | QualType ToType; |
| 7244 | FunctionDecl *ToOperatorDelete; |
| 7245 | Expr *ToArgument; |
| 7246 | SourceLocation ToBeginLoc; |
| 7247 | std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7248 | |
| 7249 | return new (Importer.getToContext()) CXXDeleteExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7250 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), |
| 7251 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, |
| 7252 | ToBeginLoc); |
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 7253 | } |
| 7254 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7255 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 7256 | auto Imp = importSeq( |
| 7257 | E->getType(), E->getLocation(), E->getConstructor(), |
| 7258 | E->getParenOrBraceRange()); |
| 7259 | if (!Imp) |
| 7260 | return Imp.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7261 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7262 | QualType ToType; |
| 7263 | SourceLocation ToLocation; |
| 7264 | CXXConstructorDecl *ToConstructor; |
| 7265 | SourceRange ToParenOrBraceRange; |
| 7266 | std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7267 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7268 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7269 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7270 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7271 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7272 | return CXXConstructExpr::Create( |
| 7273 | Importer.getToContext(), ToType, ToLocation, ToConstructor, |
| 7274 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), |
| 7275 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 7276 | E->requiresZeroInitialization(), E->getConstructionKind(), |
| 7277 | ToParenOrBraceRange); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7278 | } |
| 7279 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7280 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { |
| 7281 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7282 | if (!ToSubExprOrErr) |
| 7283 | return ToSubExprOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7284 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7285 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); |
| 7286 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) |
| 7287 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7288 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7289 | return ExprWithCleanups::Create( |
| 7290 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), |
| 7291 | ToObjects); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7292 | } |
| 7293 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7294 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7295 | auto Imp = importSeq( |
| 7296 | E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7297 | if (!Imp) |
| 7298 | return Imp.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7299 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7300 | Expr *ToCallee; |
| 7301 | QualType ToType; |
| 7302 | SourceLocation ToRParenLoc; |
| 7303 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7304 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7305 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7306 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7307 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7308 | |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7309 | return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, |
| 7310 | ToType, E->getValueKind(), ToRParenLoc); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7311 | } |
| 7312 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7313 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 7314 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7315 | if (!ToTypeOrErr) |
| 7316 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7317 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7318 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7319 | if (!ToLocationOrErr) |
| 7320 | return ToLocationOrErr.takeError(); |
| 7321 | |
| 7322 | return new (Importer.getToContext()) CXXThisExpr( |
| 7323 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7324 | } |
| 7325 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7326 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 7327 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7328 | if (!ToTypeOrErr) |
| 7329 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7330 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7331 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7332 | if (!ToLocationOrErr) |
| 7333 | return ToLocationOrErr.takeError(); |
| 7334 | |
| 7335 | return new (Importer.getToContext()) CXXBoolLiteralExpr( |
| 7336 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7337 | } |
| 7338 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7339 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 7340 | auto Imp1 = importSeq( |
| 7341 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7342 | E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType()); |
| 7343 | if (!Imp1) |
| 7344 | return Imp1.takeError(); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7345 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7346 | Expr *ToBase; |
| 7347 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7348 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7349 | ValueDecl *ToMemberDecl; |
| 7350 | QualType ToType; |
| 7351 | std::tie( |
| 7352 | ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, |
| 7353 | ToType) = *Imp1; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7354 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7355 | auto Imp2 = importSeq( |
| 7356 | E->getFoundDecl().getDecl(), E->getMemberNameInfo().getName(), |
| 7357 | E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7358 | if (!Imp2) |
| 7359 | return Imp2.takeError(); |
| 7360 | NamedDecl *ToDecl; |
| 7361 | DeclarationName ToName; |
| 7362 | SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc; |
| 7363 | std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2; |
| Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 7364 | |
| 7365 | DeclAccessPair ToFoundDecl = |
| 7366 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7367 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7368 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7369 | |
| Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7370 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7371 | if (E->hasExplicitTemplateArgs()) { |
| Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7372 | if (Error Err = |
| 7373 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 7374 | E->template_arguments(), ToTAInfo)) |
| 7375 | return std::move(Err); |
| 7376 | ResInfo = &ToTAInfo; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7377 | } |
| 7378 | |
| Richard Smith | 1bbad59 | 2019-06-11 17:50:36 +0000 | [diff] [blame] | 7379 | return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(), |
| 7380 | ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7381 | ToMemberDecl, ToFoundDecl, ToMemberNameInfo, |
| 7382 | ResInfo, ToType, E->getValueKind(), |
| 7383 | E->getObjectKind(), E->isNonOdrUse()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7384 | } |
| 7385 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7386 | ExpectedStmt |
| 7387 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { |
| 7388 | auto Imp = importSeq( |
| 7389 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7390 | E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc()); |
| 7391 | if (!Imp) |
| 7392 | return Imp.takeError(); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7393 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7394 | Expr *ToBase; |
| 7395 | SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc; |
| 7396 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7397 | TypeSourceInfo *ToScopeTypeInfo; |
| 7398 | std::tie( |
| 7399 | ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, |
| 7400 | ToTildeLoc) = *Imp; |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7401 | |
| 7402 | PseudoDestructorTypeStorage Storage; |
| 7403 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 7404 | IdentifierInfo *ToII = Importer.Import(FromII); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7405 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); |
| 7406 | if (!ToDestroyedTypeLocOrErr) |
| 7407 | return ToDestroyedTypeLocOrErr.takeError(); |
| 7408 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7409 | } else { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7410 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) |
| 7411 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); |
| 7412 | else |
| 7413 | return ToTIOrErr.takeError(); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7414 | } |
| 7415 | |
| 7416 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7417 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7418 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7419 | } |
| 7420 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7421 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7422 | CXXDependentScopeMemberExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7423 | auto Imp = importSeq( |
| 7424 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7425 | E->getTemplateKeywordLoc(), E->getFirstQualifierFoundInScope()); |
| 7426 | if (!Imp) |
| 7427 | return Imp.takeError(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7428 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7429 | QualType ToType; |
| 7430 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7431 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7432 | NamedDecl *ToFirstQualifierFoundInScope; |
| 7433 | std::tie( |
| 7434 | ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7435 | ToFirstQualifierFoundInScope) = *Imp; |
| 7436 | |
| 7437 | Expr *ToBase = nullptr; |
| 7438 | if (!E->isImplicitAccess()) { |
| 7439 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7440 | ToBase = *ToBaseOrErr; |
| 7441 | else |
| 7442 | return ToBaseOrErr.takeError(); |
| 7443 | } |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7444 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7445 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7446 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7447 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7448 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7449 | ToTAInfo)) |
| 7450 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7451 | ResInfo = &ToTAInfo; |
| 7452 | } |
| 7453 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7454 | auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc()); |
| 7455 | if (!ToMemberNameInfoOrErr) |
| 7456 | return ToMemberNameInfoOrErr.takeError(); |
| 7457 | DeclarationNameInfo ToMemberNameInfo( |
| 7458 | std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr)); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7459 | // Import additional name location/type info. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7460 | if (Error Err = ImportDeclarationNameLoc( |
| 7461 | E->getMemberNameInfo(), ToMemberNameInfo)) |
| 7462 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7463 | |
| 7464 | return CXXDependentScopeMemberExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7465 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, |
| 7466 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, |
| 7467 | ToMemberNameInfo, ResInfo); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7468 | } |
| 7469 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7470 | ExpectedStmt |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7471 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7472 | auto Imp = importSeq(E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 7473 | E->getDeclName(), E->getNameInfo().getLoc(), |
| 7474 | E->getLAngleLoc(), E->getRAngleLoc()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7475 | if (!Imp) |
| 7476 | return Imp.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7477 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7478 | NestedNameSpecifierLoc ToQualifierLoc; |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7479 | SourceLocation ToTemplateKeywordLoc, ToNameLoc, ToLAngleLoc, ToRAngleLoc; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7480 | DeclarationName ToDeclName; |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7481 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToNameLoc, |
| 7482 | ToLAngleLoc, ToRAngleLoc) = *Imp; |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7483 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7484 | DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7485 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7486 | return std::move(Err); |
| 7487 | |
| 7488 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7489 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7490 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7491 | if (Error Err = |
| 7492 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7493 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7494 | ResInfo = &ToTAInfo; |
| 7495 | } |
| 7496 | |
| 7497 | return DependentScopeDeclRefExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7498 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, |
| 7499 | ToNameInfo, ResInfo); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7500 | } |
| 7501 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7502 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 7503 | CXXUnresolvedConstructExpr *E) { |
| 7504 | auto Imp = importSeq( |
| 7505 | E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo()); |
| 7506 | if (!Imp) |
| 7507 | return Imp.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7508 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7509 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 7510 | TypeSourceInfo *ToTypeSourceInfo; |
| 7511 | std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp; |
| 7512 | |
| 7513 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); |
| 7514 | if (Error Err = |
| 7515 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) |
| 7516 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7517 | |
| 7518 | return CXXUnresolvedConstructExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7519 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, |
| 7520 | llvm::makeArrayRef(ToArgs), ToRParenLoc); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7521 | } |
| 7522 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7523 | ExpectedStmt |
| 7524 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
| 7525 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); |
| 7526 | if (!ToNamingClassOrErr) |
| 7527 | return ToNamingClassOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7528 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7529 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); |
| 7530 | if (!ToQualifierLocOrErr) |
| 7531 | return ToQualifierLocOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7532 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7533 | auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc()); |
| 7534 | if (!ToNameInfoOrErr) |
| 7535 | return ToNameInfoOrErr.takeError(); |
| 7536 | DeclarationNameInfo ToNameInfo( |
| 7537 | std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr)); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7538 | // Import additional name location/type info. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7539 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7540 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7541 | |
| 7542 | UnresolvedSet<8> ToDecls; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7543 | for (auto *D : E->decls()) |
| 7544 | if (auto ToDOrErr = import(D)) |
| 7545 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7546 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7547 | return ToDOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7548 | |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7549 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7550 | TemplateArgumentListInfo ToTAInfo; |
| 7551 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7552 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7553 | ToTAInfo)) |
| 7554 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7555 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7556 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); |
| 7557 | if (!ToTemplateKeywordLocOrErr) |
| 7558 | return ToTemplateKeywordLocOrErr.takeError(); |
| 7559 | |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7560 | return UnresolvedLookupExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7561 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7562 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, |
| 7563 | ToDecls.begin(), ToDecls.end()); |
| 7564 | } |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7565 | |
| 7566 | return UnresolvedLookupExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7567 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7568 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), |
| 7569 | ToDecls.end()); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7570 | } |
| 7571 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7572 | ExpectedStmt |
| 7573 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 7574 | auto Imp1 = importSeq( |
| 7575 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7576 | E->getTemplateKeywordLoc()); |
| 7577 | if (!Imp1) |
| 7578 | return Imp1.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7579 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7580 | QualType ToType; |
| 7581 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7582 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7583 | std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1; |
| 7584 | |
| 7585 | auto Imp2 = importSeq(E->getName(), E->getNameLoc()); |
| 7586 | if (!Imp2) |
| 7587 | return Imp2.takeError(); |
| 7588 | DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2)); |
| 7589 | // Import additional name location/type info. |
| 7590 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7591 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7592 | |
| 7593 | UnresolvedSet<8> ToDecls; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7594 | for (Decl *D : E->decls()) |
| 7595 | if (auto ToDOrErr = import(D)) |
| 7596 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7597 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7598 | return ToDOrErr.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7599 | |
| 7600 | TemplateArgumentListInfo ToTAInfo; |
| 7601 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7602 | if (E->hasExplicitTemplateArgs()) { |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 7603 | TemplateArgumentListInfo FromTAInfo; |
| 7604 | E->copyTemplateArgumentsInto(FromTAInfo); |
| 7605 | if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7606 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7607 | ResInfo = &ToTAInfo; |
| 7608 | } |
| 7609 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7610 | Expr *ToBase = nullptr; |
| 7611 | if (!E->isImplicitAccess()) { |
| 7612 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7613 | ToBase = *ToBaseOrErr; |
| 7614 | else |
| 7615 | return ToBaseOrErr.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7616 | } |
| 7617 | |
| 7618 | return UnresolvedMemberExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7619 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, |
| 7620 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7621 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7622 | } |
| 7623 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7624 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 7625 | auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7626 | if (!Imp) |
| 7627 | return Imp.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7628 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7629 | Expr *ToCallee; |
| 7630 | QualType ToType; |
| 7631 | SourceLocation ToRParenLoc; |
| 7632 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7633 | |
| 7634 | unsigned NumArgs = E->getNumArgs(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7635 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 7636 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7637 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7638 | |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7639 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7640 | return CXXOperatorCallExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7641 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, |
| Eric Fiselier | 5cdc2cd | 2018-12-12 21:50:55 +0000 | [diff] [blame] | 7642 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), |
| 7643 | OCE->getADLCallKind()); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7644 | } |
| 7645 | |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7646 | return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType, |
| 7647 | E->getValueKind(), ToRParenLoc, /*MinNumArgs=*/0, |
| 7648 | E->getADLCallKind()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7649 | } |
| 7650 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7651 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { |
| 7652 | CXXRecordDecl *FromClass = E->getLambdaClass(); |
| 7653 | auto ToClassOrErr = import(FromClass); |
| 7654 | if (!ToClassOrErr) |
| 7655 | return ToClassOrErr.takeError(); |
| 7656 | CXXRecordDecl *ToClass = *ToClassOrErr; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7657 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7658 | auto ToCallOpOrErr = import(E->getCallOperator()); |
| 7659 | if (!ToCallOpOrErr) |
| 7660 | return ToCallOpOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7661 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7662 | SmallVector<LambdaCapture, 8> ToCaptures; |
| 7663 | ToCaptures.reserve(E->capture_size()); |
| 7664 | for (const auto &FromCapture : E->captures()) { |
| 7665 | if (auto ToCaptureOrErr = import(FromCapture)) |
| 7666 | ToCaptures.push_back(*ToCaptureOrErr); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7667 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7668 | return ToCaptureOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7669 | } |
| 7670 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7671 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); |
| 7672 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) |
| 7673 | return std::move(Err); |
| 7674 | |
| 7675 | auto Imp = importSeq( |
| 7676 | E->getIntroducerRange(), E->getCaptureDefaultLoc(), E->getEndLoc()); |
| 7677 | if (!Imp) |
| 7678 | return Imp.takeError(); |
| 7679 | |
| 7680 | SourceRange ToIntroducerRange; |
| 7681 | SourceLocation ToCaptureDefaultLoc, ToEndLoc; |
| 7682 | std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7683 | |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7684 | return LambdaExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7685 | Importer.getToContext(), ToClass, ToIntroducerRange, |
| 7686 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, |
| 7687 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, |
| 7688 | ToEndLoc, E->containsUnexpandedParameterPack()); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7689 | } |
| 7690 | |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7691 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7692 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { |
| 7693 | auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType()); |
| 7694 | if (!Imp) |
| 7695 | return Imp.takeError(); |
| 7696 | |
| 7697 | SourceLocation ToLBraceLoc, ToRBraceLoc; |
| 7698 | QualType ToType; |
| 7699 | std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp; |
| 7700 | |
| 7701 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); |
| 7702 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) |
| 7703 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7704 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7705 | ASTContext &ToCtx = Importer.getToContext(); |
| 7706 | InitListExpr *To = new (ToCtx) InitListExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7707 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); |
| 7708 | To->setType(ToType); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7709 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7710 | if (E->hasArrayFiller()) { |
| 7711 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) |
| 7712 | To->setArrayFiller(*ToFillerOrErr); |
| 7713 | else |
| 7714 | return ToFillerOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7715 | } |
| 7716 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7717 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { |
| 7718 | if (auto ToFDOrErr = import(FromFD)) |
| 7719 | To->setInitializedFieldInUnion(*ToFDOrErr); |
| 7720 | else |
| 7721 | return ToFDOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7722 | } |
| 7723 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7724 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { |
| 7725 | if (auto ToSyntFormOrErr = import(SyntForm)) |
| 7726 | To->setSyntacticForm(*ToSyntFormOrErr); |
| 7727 | else |
| 7728 | return ToSyntFormOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7729 | } |
| 7730 | |
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7731 | // Copy InitListExprBitfields, which are not handled in the ctor of |
| 7732 | // InitListExpr. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7733 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7734 | |
| 7735 | return To; |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7736 | } |
| 7737 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7738 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7739 | CXXStdInitializerListExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7740 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7741 | if (!ToTypeOrErr) |
| 7742 | return ToTypeOrErr.takeError(); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7743 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7744 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7745 | if (!ToSubExprOrErr) |
| 7746 | return ToSubExprOrErr.takeError(); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7747 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7748 | return new (Importer.getToContext()) CXXStdInitializerListExpr( |
| 7749 | *ToTypeOrErr, *ToSubExprOrErr); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7750 | } |
| 7751 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7752 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7753 | CXXInheritedCtorInitExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7754 | auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor()); |
| 7755 | if (!Imp) |
| 7756 | return Imp.takeError(); |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7757 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7758 | SourceLocation ToLocation; |
| 7759 | QualType ToType; |
| 7760 | CXXConstructorDecl *ToConstructor; |
| 7761 | std::tie(ToLocation, ToType, ToConstructor) = *Imp; |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7762 | |
| 7763 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7764 | ToLocation, ToType, ToConstructor, E->constructsVBase(), |
| 7765 | E->inheritedFromVBase()); |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7766 | } |
| 7767 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7768 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 7769 | auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr()); |
| 7770 | if (!Imp) |
| 7771 | return Imp.takeError(); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7772 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7773 | QualType ToType; |
| 7774 | Expr *ToCommonExpr, *ToSubExpr; |
| 7775 | std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp; |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7776 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7777 | return new (Importer.getToContext()) ArrayInitLoopExpr( |
| 7778 | ToType, ToCommonExpr, ToSubExpr); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7779 | } |
| 7780 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7781 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 7782 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7783 | if (!ToTypeOrErr) |
| 7784 | return ToTypeOrErr.takeError(); |
| 7785 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7786 | } |
| 7787 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7788 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7789 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); |
| 7790 | if (!ToBeginLocOrErr) |
| 7791 | return ToBeginLocOrErr.takeError(); |
| 7792 | |
| 7793 | auto ToFieldOrErr = import(E->getField()); |
| 7794 | if (!ToFieldOrErr) |
| 7795 | return ToFieldOrErr.takeError(); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7796 | |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7797 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); |
| 7798 | if (!UsedContextOrErr) |
| 7799 | return UsedContextOrErr.takeError(); |
| 7800 | |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7801 | return CXXDefaultInitExpr::Create( |
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7802 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr, *UsedContextOrErr); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7803 | } |
| 7804 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7805 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 7806 | auto Imp = importSeq( |
| 7807 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(), |
| 7808 | E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets()); |
| 7809 | if (!Imp) |
| 7810 | return Imp.takeError(); |
| 7811 | |
| 7812 | QualType ToType; |
| 7813 | Expr *ToSubExpr; |
| 7814 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 7815 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 7816 | SourceRange ToAngleBrackets; |
| 7817 | std::tie( |
| 7818 | ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, |
| 7819 | ToAngleBrackets) = *Imp; |
| 7820 | |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7821 | ExprValueKind VK = E->getValueKind(); |
| 7822 | CastKind CK = E->getCastKind(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7823 | auto ToBasePathOrErr = ImportCastPath(E); |
| 7824 | if (!ToBasePathOrErr) |
| 7825 | return ToBasePathOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7826 | |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7827 | if (isa<CXXStaticCastExpr>(E)) { |
| 7828 | return CXXStaticCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7829 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7830 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7831 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 7832 | return CXXDynamicCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7833 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7834 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7835 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 7836 | return CXXReinterpretCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7837 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7838 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 7839 | } else if (isa<CXXConstCastExpr>(E)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7840 | return CXXConstCastExpr::Create( |
| 7841 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, |
| 7842 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7843 | } else { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7844 | llvm_unreachable("Unknown cast type"); |
| 7845 | return make_error<ImportError>(); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7846 | } |
| 7847 | } |
| 7848 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7849 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7850 | SubstNonTypeTemplateParmExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7851 | auto Imp = importSeq( |
| 7852 | E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement()); |
| 7853 | if (!Imp) |
| 7854 | return Imp.takeError(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7855 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7856 | QualType ToType; |
| 7857 | SourceLocation ToExprLoc; |
| 7858 | NonTypeTemplateParmDecl *ToParameter; |
| 7859 | Expr *ToReplacement; |
| 7860 | std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp; |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7861 | |
| 7862 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7863 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7864 | } |
| 7865 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7866 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 7867 | auto Imp = importSeq( |
| 7868 | E->getType(), E->getBeginLoc(), E->getEndLoc()); |
| 7869 | if (!Imp) |
| 7870 | return Imp.takeError(); |
| 7871 | |
| 7872 | QualType ToType; |
| 7873 | SourceLocation ToBeginLoc, ToEndLoc; |
| 7874 | std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp; |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7875 | |
| 7876 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7877 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) |
| 7878 | return std::move(Err); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7879 | |
| 7880 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 7881 | // Value is always false. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7882 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7883 | |
| 7884 | return TypeTraitExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7885 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, |
| 7886 | ToEndLoc, ToValue); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7887 | } |
| 7888 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7889 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 7890 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7891 | if (!ToTypeOrErr) |
| 7892 | return ToTypeOrErr.takeError(); |
| 7893 | |
| 7894 | auto ToSourceRangeOrErr = import(E->getSourceRange()); |
| 7895 | if (!ToSourceRangeOrErr) |
| 7896 | return ToSourceRangeOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7897 | |
| 7898 | if (E->isTypeOperand()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7899 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) |
| 7900 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7901 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); |
| 7902 | else |
| 7903 | return ToTSIOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7904 | } |
| 7905 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7906 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); |
| 7907 | if (!ToExprOperandOrErr) |
| 7908 | return ToExprOperandOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7909 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7910 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7911 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7912 | } |
| 7913 | |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7914 | Error ASTNodeImporter::ImportOverriddenMethods(CXXMethodDecl *ToMethod, |
| 7915 | CXXMethodDecl *FromMethod) { |
| 7916 | Error ImportErrors = Error::success(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7917 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { |
| 7918 | if (auto ImportedOrErr = import(FromOverriddenMethod)) |
| 7919 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( |
| 7920 | (*ImportedOrErr)->getCanonicalDecl())); |
| 7921 | else |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7922 | ImportErrors = |
| 7923 | joinErrors(std::move(ImportErrors), ImportedOrErr.takeError()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7924 | } |
| Balazs Keri | b4fd7d4 | 2019-08-30 10:12:14 +0000 | [diff] [blame] | 7925 | return ImportErrors; |
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7926 | } |
| 7927 | |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7928 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7929 | ASTContext &FromContext, FileManager &FromFileManager, |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7930 | bool MinimalImport, |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7931 | std::shared_ptr<ASTImporterSharedState> SharedState) |
| 7932 | : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext), |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7933 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 7934 | Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) { |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7935 | |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7936 | // Create a default state without the lookup table: LLDB case. |
| 7937 | if (!SharedState) { |
| 7938 | this->SharedState = std::make_shared<ASTImporterSharedState>(); |
| 7939 | } |
| 7940 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7941 | ImportedDecls[FromContext.getTranslationUnitDecl()] = |
| 7942 | ToContext.getTranslationUnitDecl(); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7943 | } |
| 7944 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7945 | ASTImporter::~ASTImporter() = default; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7946 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7947 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { |
| 7948 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && |
| 7949 | "Try to get field index for non-field."); |
| 7950 | |
| 7951 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 7952 | if (!Owner) |
| 7953 | return None; |
| 7954 | |
| 7955 | unsigned Index = 0; |
| 7956 | for (const auto *D : Owner->decls()) { |
| 7957 | if (D == F) |
| 7958 | return Index; |
| 7959 | |
| 7960 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 7961 | ++Index; |
| 7962 | } |
| 7963 | |
| 7964 | llvm_unreachable("Field was not found in its parent context."); |
| 7965 | |
| 7966 | return None; |
| 7967 | } |
| 7968 | |
| 7969 | ASTImporter::FoundDeclsTy |
| 7970 | ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) { |
| 7971 | // We search in the redecl context because of transparent contexts. |
| 7972 | // E.g. a simple C language enum is a transparent context: |
| 7973 | // enum E { A, B }; |
| 7974 | // Now if we had a global variable in the TU |
| 7975 | // int A; |
| 7976 | // then the enum constant 'A' and the variable 'A' violates ODR. |
| 7977 | // We can diagnose this only if we search in the redecl context. |
| 7978 | DeclContext *ReDC = DC->getRedeclContext(); |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7979 | if (SharedState->getLookupTable()) { |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7980 | ASTImporterLookupTable::LookupResult LookupResult = |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7981 | SharedState->getLookupTable()->lookup(ReDC, Name); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7982 | return FoundDeclsTy(LookupResult.begin(), LookupResult.end()); |
| 7983 | } else { |
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 7984 | DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name); |
| 7985 | FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end()); |
| 7986 | // We must search by the slow case of localUncachedLookup because that is |
| 7987 | // working even if there is no LookupPtr for the DC. We could use |
| 7988 | // DC::buildLookup() to create the LookupPtr, but that would load external |
| 7989 | // decls again, we must avoid that case. |
| 7990 | // Also, even if we had the LookupPtr, we must find Decls which are not |
| 7991 | // in the LookupPtr, so we need the slow case. |
| 7992 | // These cases are handled in ASTImporterLookupTable, but we cannot use |
| 7993 | // that with LLDB since that traverses through the AST which initiates the |
| 7994 | // load of external decls again via DC::decls(). And again, we must avoid |
| 7995 | // loading external decls during the import. |
| 7996 | if (Result.empty()) |
| 7997 | ReDC->localUncachedLookup(Name, Result); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7998 | return Result; |
| 7999 | } |
| 8000 | } |
| 8001 | |
| 8002 | void ASTImporter::AddToLookupTable(Decl *ToD) { |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8003 | SharedState->addDeclToLookup(ToD); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 8004 | } |
| 8005 | |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 8006 | Expected<Decl *> ASTImporter::ImportImpl(Decl *FromD) { |
| 8007 | // Import the decl using ASTNodeImporter. |
| 8008 | ASTNodeImporter Importer(*this); |
| 8009 | return Importer.Visit(FromD); |
| 8010 | } |
| 8011 | |
| 8012 | void ASTImporter::RegisterImportedDecl(Decl *FromD, Decl *ToD) { |
| 8013 | MapImported(FromD, ToD); |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 8014 | } |
| 8015 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8016 | Expected<QualType> ASTImporter::Import(QualType FromT) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8017 | if (FromT.isNull()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8018 | return QualType{}; |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 8019 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8020 | const Type *FromTy = FromT.getTypePtr(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8021 | |
| 8022 | // Check whether we've already imported this type. |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 8023 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8024 | = ImportedTypes.find(FromTy); |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 8025 | if (Pos != ImportedTypes.end()) |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 8026 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8027 | |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 8028 | // Import the type |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8029 | ASTNodeImporter Importer(*this); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8030 | ExpectedType ToTOrErr = Importer.Visit(FromTy); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8031 | if (!ToTOrErr) |
| 8032 | return ToTOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8033 | |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 8034 | // Record the imported type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8035 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8036 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8037 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8038 | } |
| 8039 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8040 | Expected<TypeSourceInfo *> ASTImporter::Import(TypeSourceInfo *FromTSI) { |
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 8041 | if (!FromTSI) |
| 8042 | return FromTSI; |
| 8043 | |
| 8044 | // FIXME: For now we just create a "trivial" type source info based |
| Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 8045 | // 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] | 8046 | ExpectedType TOrErr = Import(FromTSI->getType()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8047 | if (!TOrErr) |
| 8048 | return TOrErr.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8049 | ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8050 | if (!BeginLocOrErr) |
| 8051 | return BeginLocOrErr.takeError(); |
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 8052 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8053 | return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr); |
| 8054 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8055 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8056 | Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) { |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8057 | Attr *ToAttr = FromAttr->clone(ToContext); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8058 | if (auto ToRangeOrErr = Import(FromAttr->getRange())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8059 | ToAttr->setRange(*ToRangeOrErr); |
| 8060 | else |
| 8061 | return ToRangeOrErr.takeError(); |
| 8062 | |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8063 | return ToAttr; |
| Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8064 | } |
| Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 8065 | |
| Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 8066 | Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { |
| 8067 | auto Pos = ImportedDecls.find(FromD); |
| 8068 | if (Pos != ImportedDecls.end()) |
| 8069 | return Pos->second; |
| 8070 | else |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 8071 | return nullptr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 8072 | } |
| 8073 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 8074 | TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) { |
| 8075 | auto FromDPos = ImportedFromDecls.find(ToD); |
| 8076 | if (FromDPos == ImportedFromDecls.end()) |
| 8077 | return nullptr; |
| 8078 | return FromDPos->second->getTranslationUnitDecl(); |
| 8079 | } |
| 8080 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8081 | Expected<Decl *> ASTImporter::Import(Decl *FromD) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8082 | if (!FromD) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8083 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8084 | |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8085 | // Push FromD to the stack, and remove that when we return. |
| 8086 | ImportPath.push(FromD); |
| 8087 | auto ImportPathBuilder = |
| 8088 | llvm::make_scope_exit([this]() { ImportPath.pop(); }); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8089 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8090 | // Check whether there was a previous failed import. |
| 8091 | // If yes return the existing error. |
| 8092 | if (auto Error = getImportDeclErrorIfAny(FromD)) |
| 8093 | return make_error<ImportError>(*Error); |
| 8094 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8095 | // Check whether we've already imported this declaration. |
| 8096 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 8097 | if (ToD) { |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8098 | // Already imported (possibly from another TU) and with an error. |
| 8099 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { |
| 8100 | setImportDeclError(FromD, *Error); |
| 8101 | return make_error<ImportError>(*Error); |
| 8102 | } |
| 8103 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8104 | // If FromD has some updated flags after last import, apply it |
| 8105 | updateFlags(FromD, ToD); |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8106 | // If we encounter a cycle during an import then we save the relevant part |
| 8107 | // of the import path associated to the Decl. |
| 8108 | if (ImportPath.hasCycleAtBack()) |
| 8109 | SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack()); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 8110 | return ToD; |
| 8111 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8112 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8113 | // Import the declaration. |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 8114 | ExpectedDecl ToDOrErr = ImportImpl(FromD); |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8115 | if (!ToDOrErr) { |
| 8116 | // Failed to import. |
| 8117 | |
| 8118 | auto Pos = ImportedDecls.find(FromD); |
| 8119 | if (Pos != ImportedDecls.end()) { |
| 8120 | // Import failed after the object was created. |
| 8121 | // Remove all references to it. |
| 8122 | auto *ToD = Pos->second; |
| 8123 | ImportedDecls.erase(Pos); |
| 8124 | |
| 8125 | // ImportedDecls and ImportedFromDecls are not symmetric. It may happen |
| 8126 | // (e.g. with namespaces) that several decls from the 'from' context are |
| 8127 | // mapped to the same decl in the 'to' context. If we removed entries |
| 8128 | // from the LookupTable here then we may end up removing them multiple |
| 8129 | // times. |
| 8130 | |
| 8131 | // The Lookuptable contains decls only which are in the 'to' context. |
| 8132 | // Remove from the Lookuptable only if it is *imported* into the 'to' |
| 8133 | // context (and do not remove it if it was added during the initial |
| 8134 | // traverse of the 'to' context). |
| 8135 | auto PosF = ImportedFromDecls.find(ToD); |
| 8136 | if (PosF != ImportedFromDecls.end()) { |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8137 | SharedState->removeDeclFromLookup(ToD); |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8138 | ImportedFromDecls.erase(PosF); |
| 8139 | } |
| 8140 | |
| 8141 | // FIXME: AST may contain remaining references to the failed object. |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8142 | // However, the ImportDeclErrors in the shared state contains all the |
| 8143 | // failed objects together with their error. |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8144 | } |
| 8145 | |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8146 | // Error encountered for the first time. |
| 8147 | // After takeError the error is not usable any more in ToDOrErr. |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8148 | // Get a copy of the error object (any more simple solution for this?). |
| 8149 | ImportError ErrOut; |
| 8150 | handleAllErrors(ToDOrErr.takeError(), |
| 8151 | [&ErrOut](const ImportError &E) { ErrOut = E; }); |
| 8152 | setImportDeclError(FromD, ErrOut); |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8153 | // Set the error for the mapped to Decl, which is in the "to" context. |
| 8154 | if (Pos != ImportedDecls.end()) |
| 8155 | SharedState->setImportDeclError(Pos->second, ErrOut); |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8156 | |
| 8157 | // Set the error for all nodes which have been created before we |
| 8158 | // recognized the error. |
| 8159 | for (const auto &Path : SavedImportPaths[FromD]) |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8160 | for (Decl *FromDi : Path) { |
| 8161 | setImportDeclError(FromDi, ErrOut); |
| 8162 | //FIXME Should we remove these Decls from ImportedDecls? |
| 8163 | // Set the error for the mapped to Decl, which is in the "to" context. |
| 8164 | auto Ii = ImportedDecls.find(FromDi); |
| 8165 | if (Ii != ImportedDecls.end()) |
| 8166 | SharedState->setImportDeclError(Ii->second, ErrOut); |
| 8167 | // FIXME Should we remove these Decls from the LookupTable, |
| 8168 | // and from ImportedFromDecls? |
| 8169 | } |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8170 | SavedImportPaths[FromD].clear(); |
| 8171 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8172 | // Do not return ToDOrErr, error was taken out of it. |
| 8173 | return make_error<ImportError>(ErrOut); |
| 8174 | } |
| 8175 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8176 | ToD = *ToDOrErr; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8177 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8178 | // FIXME: Handle the "already imported with error" case. We can get here |
| 8179 | // nullptr only if GetImportedOrCreateDecl returned nullptr (after a |
| 8180 | // previously failed create was requested). |
| 8181 | // Later GetImportedOrCreateDecl can be updated to return the error. |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 8182 | if (!ToD) { |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8183 | auto Err = getImportDeclErrorIfAny(FromD); |
| 8184 | assert(Err); |
| 8185 | return make_error<ImportError>(*Err); |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 8186 | } |
| 8187 | |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8188 | // We could import from the current TU without error. But previously we |
| 8189 | // already had imported a Decl as `ToD` from another TU (with another |
| 8190 | // ASTImporter object) and with an error. |
| 8191 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { |
| 8192 | setImportDeclError(FromD, *Error); |
| 8193 | return make_error<ImportError>(*Error); |
| 8194 | } |
| 8195 | |
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 8196 | // Make sure that ImportImpl registered the imported decl. |
| 8197 | assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?"); |
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8198 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8199 | // Notify subclasses. |
| 8200 | Imported(FromD, ToD); |
| 8201 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 8202 | updateFlags(FromD, ToD); |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8203 | SavedImportPaths[FromD].clear(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8204 | return ToDOrErr; |
| 8205 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8206 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8207 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8208 | if (!FromDC) |
| 8209 | return FromDC; |
| 8210 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8211 | ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC)); |
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8212 | if (!ToDCOrErr) |
| 8213 | return ToDCOrErr.takeError(); |
| 8214 | auto *ToDC = cast<DeclContext>(*ToDCOrErr); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8215 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8216 | // 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] | 8217 | // need it to have a definition. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8218 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 8219 | auto *FromRecord = cast<RecordDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8220 | if (ToRecord->isCompleteDefinition()) { |
| 8221 | // Do nothing. |
| 8222 | } else if (FromRecord->isCompleteDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8223 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8224 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) |
| 8225 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8226 | } else { |
| 8227 | CompleteDecl(ToRecord); |
| 8228 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8229 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 8230 | auto *FromEnum = cast<EnumDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8231 | if (ToEnum->isCompleteDefinition()) { |
| 8232 | // Do nothing. |
| 8233 | } else if (FromEnum->isCompleteDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8234 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8235 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) |
| 8236 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8237 | } else { |
| 8238 | CompleteDecl(ToEnum); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8239 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8240 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 8241 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8242 | if (ToClass->getDefinition()) { |
| 8243 | // Do nothing. |
| 8244 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8245 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8246 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) |
| 8247 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8248 | } else { |
| 8249 | CompleteDecl(ToClass); |
| 8250 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8251 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 8252 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8253 | if (ToProto->getDefinition()) { |
| 8254 | // Do nothing. |
| 8255 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8256 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 8257 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) |
| 8258 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8259 | } else { |
| 8260 | CompleteDecl(ToProto); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8261 | } |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 8262 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8263 | |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 8264 | return ToDC; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8265 | } |
| 8266 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8267 | Expected<Expr *> ASTImporter::Import(Expr *FromE) { |
| 8268 | if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE))) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8269 | return cast_or_null<Expr>(*ToSOrErr); |
| 8270 | else |
| 8271 | return ToSOrErr.takeError(); |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8272 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8273 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8274 | Expected<Stmt *> ASTImporter::Import(Stmt *FromS) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8275 | if (!FromS) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8276 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8277 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8278 | // Check whether we've already imported this statement. |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 8279 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 8280 | if (Pos != ImportedStmts.end()) |
| 8281 | return Pos->second; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8282 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8283 | // Import the statement. |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 8284 | ASTNodeImporter Importer(*this); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8285 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8286 | if (!ToSOrErr) |
| 8287 | return ToSOrErr; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8288 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8289 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { |
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 8290 | auto *FromE = cast<Expr>(FromS); |
| 8291 | // Copy ExprBitfields, which may not be handled in Expr subclasses |
| 8292 | // constructors. |
| 8293 | ToE->setValueKind(FromE->getValueKind()); |
| 8294 | ToE->setObjectKind(FromE->getObjectKind()); |
| 8295 | ToE->setTypeDependent(FromE->isTypeDependent()); |
| 8296 | ToE->setValueDependent(FromE->isValueDependent()); |
| 8297 | ToE->setInstantiationDependent(FromE->isInstantiationDependent()); |
| 8298 | ToE->setContainsUnexpandedParameterPack( |
| 8299 | FromE->containsUnexpandedParameterPack()); |
| 8300 | } |
| 8301 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8302 | // Record the imported statement object. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8303 | ImportedStmts[FromS] = *ToSOrErr; |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8304 | return ToSOrErr; |
| 8305 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8306 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8307 | Expected<NestedNameSpecifier *> |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8308 | ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8309 | if (!FromNNS) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8310 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8311 | |
| Simon Pilgrim | 130df2c | 2019-07-15 13:00:43 +0000 | [diff] [blame] | 8312 | NestedNameSpecifier *Prefix = nullptr; |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8313 | if (Error Err = importInto(Prefix, FromNNS->getPrefix())) |
| 8314 | return std::move(Err); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8315 | |
| 8316 | switch (FromNNS->getKind()) { |
| 8317 | case NestedNameSpecifier::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8318 | assert(FromNNS->getAsIdentifier() && "NNS should contain identifier."); |
| 8319 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8320 | Import(FromNNS->getAsIdentifier())); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8321 | |
| 8322 | case NestedNameSpecifier::Namespace: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8323 | if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8324 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8325 | cast<NamespaceDecl>(*NSOrErr)); |
| 8326 | } else |
| 8327 | return NSOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8328 | |
| 8329 | case NestedNameSpecifier::NamespaceAlias: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8330 | if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8331 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8332 | cast<NamespaceAliasDecl>(*NSADOrErr)); |
| 8333 | else |
| 8334 | return NSADOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8335 | |
| 8336 | case NestedNameSpecifier::Global: |
| 8337 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 8338 | |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8339 | case NestedNameSpecifier::Super: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8340 | if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8341 | return NestedNameSpecifier::SuperSpecifier(ToContext, |
| 8342 | cast<CXXRecordDecl>(*RDOrErr)); |
| 8343 | else |
| 8344 | return RDOrErr.takeError(); |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8345 | |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8346 | case NestedNameSpecifier::TypeSpec: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8347 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 8348 | if (Expected<QualType> TyOrErr = |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8349 | Import(QualType(FromNNS->getAsType(), 0u))) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8350 | bool TSTemplate = |
| 8351 | FromNNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate; |
| 8352 | return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate, |
| 8353 | TyOrErr->getTypePtr()); |
| 8354 | } else { |
| 8355 | return TyOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8356 | } |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8357 | } |
| 8358 | |
| 8359 | llvm_unreachable("Invalid nested name specifier kind"); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8360 | } |
| 8361 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8362 | Expected<NestedNameSpecifierLoc> |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8363 | ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8364 | // Copied from NestedNameSpecifier mostly. |
| 8365 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 8366 | NestedNameSpecifierLoc NNS = FromNNS; |
| 8367 | |
| 8368 | // Push each of the nested-name-specifiers's onto a stack for |
| 8369 | // serialization in reverse order. |
| 8370 | while (NNS) { |
| 8371 | NestedNames.push_back(NNS); |
| 8372 | NNS = NNS.getPrefix(); |
| 8373 | } |
| 8374 | |
| 8375 | NestedNameSpecifierLocBuilder Builder; |
| 8376 | |
| 8377 | while (!NestedNames.empty()) { |
| 8378 | NNS = NestedNames.pop_back_val(); |
| Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 8379 | NestedNameSpecifier *Spec = nullptr; |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8380 | if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier())) |
| 8381 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8382 | |
| 8383 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8384 | |
| 8385 | SourceLocation ToLocalBeginLoc, ToLocalEndLoc; |
| 8386 | if (Kind != NestedNameSpecifier::Super) { |
| 8387 | if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc())) |
| 8388 | return std::move(Err); |
| 8389 | |
| 8390 | if (Kind != NestedNameSpecifier::Global) |
| 8391 | if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc())) |
| 8392 | return std::move(Err); |
| 8393 | } |
| 8394 | |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8395 | switch (Kind) { |
| 8396 | case NestedNameSpecifier::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8397 | Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc, |
| 8398 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8399 | break; |
| 8400 | |
| 8401 | case NestedNameSpecifier::Namespace: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8402 | Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc, |
| 8403 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8404 | break; |
| 8405 | |
| 8406 | case NestedNameSpecifier::NamespaceAlias: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8407 | Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(), |
| 8408 | ToLocalBeginLoc, ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8409 | break; |
| 8410 | |
| 8411 | case NestedNameSpecifier::TypeSpec: |
| 8412 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8413 | SourceLocation ToTLoc; |
| 8414 | if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc())) |
| 8415 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8416 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8417 | QualType(Spec->getAsType(), 0), ToTLoc); |
| Balázs Kéri | a9f10eb | 2019-12-05 16:21:21 +0100 | [diff] [blame] | 8418 | if (Kind == NestedNameSpecifier::TypeSpecWithTemplate) |
| 8419 | // ToLocalBeginLoc is here the location of the 'template' keyword. |
| 8420 | Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(), |
| 8421 | ToLocalEndLoc); |
| 8422 | else |
| 8423 | // No location for 'template' keyword here. |
| 8424 | Builder.Extend(getToContext(), SourceLocation{}, TSI->getTypeLoc(), |
| 8425 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8426 | break; |
| 8427 | } |
| 8428 | |
| 8429 | case NestedNameSpecifier::Global: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8430 | Builder.MakeGlobal(getToContext(), ToLocalBeginLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8431 | break; |
| 8432 | |
| 8433 | case NestedNameSpecifier::Super: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8434 | auto ToSourceRangeOrErr = Import(NNS.getSourceRange()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8435 | if (!ToSourceRangeOrErr) |
| 8436 | return ToSourceRangeOrErr.takeError(); |
| 8437 | |
| 8438 | Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(), |
| 8439 | ToSourceRangeOrErr->getBegin(), |
| 8440 | ToSourceRangeOrErr->getEnd()); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8441 | } |
| 8442 | } |
| 8443 | } |
| 8444 | |
| 8445 | return Builder.getWithLocInContext(getToContext()); |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 8446 | } |
| 8447 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8448 | Expected<TemplateName> ASTImporter::Import(TemplateName From) { |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8449 | switch (From.getKind()) { |
| 8450 | case TemplateName::Template: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8451 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8452 | return TemplateName(cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8453 | else |
| 8454 | return ToTemplateOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8455 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8456 | case TemplateName::OverloadedTemplate: { |
| 8457 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 8458 | UnresolvedSet<2> ToTemplates; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8459 | for (auto *I : *FromStorage) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8460 | if (auto ToOrErr = Import(I)) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8461 | ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr)); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8462 | else |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8463 | return ToOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8464 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8465 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8466 | ToTemplates.end()); |
| 8467 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8468 | |
| Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8469 | case TemplateName::AssumedTemplate: { |
| 8470 | AssumedTemplateStorage *FromStorage = From.getAsAssumedTemplateName(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8471 | auto DeclNameOrErr = Import(FromStorage->getDeclName()); |
| Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8472 | if (!DeclNameOrErr) |
| 8473 | return DeclNameOrErr.takeError(); |
| 8474 | return ToContext.getAssumedTemplateName(*DeclNameOrErr); |
| 8475 | } |
| 8476 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8477 | case TemplateName::QualifiedTemplate: { |
| 8478 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8479 | auto QualifierOrErr = Import(QTN->getQualifier()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8480 | if (!QualifierOrErr) |
| 8481 | return QualifierOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8482 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8483 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8484 | return ToContext.getQualifiedTemplateName( |
| 8485 | *QualifierOrErr, QTN->hasTemplateKeyword(), |
| 8486 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8487 | else |
| 8488 | return ToTemplateOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8489 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8490 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8491 | case TemplateName::DependentTemplate: { |
| 8492 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8493 | auto QualifierOrErr = Import(DTN->getQualifier()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8494 | if (!QualifierOrErr) |
| 8495 | return QualifierOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8496 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8497 | if (DTN->isIdentifier()) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8498 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8499 | Import(DTN->getIdentifier())); |
| 8500 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8501 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8502 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
| 8503 | DTN->getOperator()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8504 | } |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8505 | |
| 8506 | case TemplateName::SubstTemplateTemplateParm: { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8507 | SubstTemplateTemplateParmStorage *Subst = |
| 8508 | From.getAsSubstTemplateTemplateParm(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8509 | ExpectedDecl ParamOrErr = Import(Subst->getParameter()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8510 | if (!ParamOrErr) |
| 8511 | return ParamOrErr.takeError(); |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8512 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8513 | auto ReplacementOrErr = Import(Subst->getReplacement()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8514 | if (!ReplacementOrErr) |
| 8515 | return ReplacementOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8516 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8517 | return ToContext.getSubstTemplateTemplateParm( |
| 8518 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ReplacementOrErr); |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8519 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8520 | |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8521 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 8522 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 8523 | = From.getAsSubstTemplateTemplateParmPack(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8524 | ExpectedDecl ParamOrErr = Import(SubstPack->getParameterPack()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8525 | if (!ParamOrErr) |
| 8526 | return ParamOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8527 | |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8528 | ASTNodeImporter Importer(*this); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8529 | auto ArgPackOrErr = |
| 8530 | Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 8531 | if (!ArgPackOrErr) |
| 8532 | return ArgPackOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8533 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8534 | return ToContext.getSubstTemplateTemplateParmPack( |
| 8535 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ArgPackOrErr); |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8536 | } |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8537 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8538 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8539 | llvm_unreachable("Invalid template name kind"); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8540 | } |
| 8541 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8542 | Expected<SourceLocation> ASTImporter::Import(SourceLocation FromLoc) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8543 | if (FromLoc.isInvalid()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8544 | return SourceLocation{}; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8545 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8546 | SourceManager &FromSM = FromContext.getSourceManager(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8547 | bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8548 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8549 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8550 | Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8551 | if (!ToFileIDOrErr) |
| 8552 | return ToFileIDOrErr.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8553 | SourceManager &ToSM = ToContext.getSourceManager(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8554 | return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second); |
| 8555 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8556 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8557 | Expected<SourceRange> ASTImporter::Import(SourceRange FromRange) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8558 | SourceLocation ToBegin, ToEnd; |
| 8559 | if (Error Err = importInto(ToBegin, FromRange.getBegin())) |
| 8560 | return std::move(Err); |
| 8561 | if (Error Err = importInto(ToEnd, FromRange.getEnd())) |
| 8562 | return std::move(Err); |
| 8563 | |
| 8564 | return SourceRange(ToBegin, ToEnd); |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8565 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8566 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8567 | Expected<FileID> ASTImporter::Import(FileID FromID, bool IsBuiltin) { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8568 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8569 | if (Pos != ImportedFileIDs.end()) |
| 8570 | return Pos->second; |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8571 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8572 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 8573 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8574 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8575 | |
| 8576 | // Map the FromID to the "to" source manager. |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8577 | FileID ToID; |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8578 | if (FromSLoc.isExpansion()) { |
| 8579 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8580 | ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8581 | if (!ToSpLoc) |
| 8582 | return ToSpLoc.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8583 | ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8584 | if (!ToExLocS) |
| 8585 | return ToExLocS.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8586 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 8587 | SourceLocation MLoc; |
| 8588 | if (FromEx.isMacroArgExpansion()) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8589 | MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, TokenLen); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8590 | } else { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8591 | if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8592 | MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, TokenLen, |
| 8593 | FromEx.isExpansionTokenRange()); |
| 8594 | else |
| 8595 | return ToExLocE.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8596 | } |
| 8597 | ToID = ToSM.getFileID(MLoc); |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8598 | } else { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8599 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8600 | |
| 8601 | if (!IsBuiltin) { |
| 8602 | // Include location of this file. |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8603 | ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8604 | if (!ToIncludeLoc) |
| 8605 | return ToIncludeLoc.takeError(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8606 | |
| 8607 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 8608 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 8609 | // disk again |
| 8610 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 8611 | // than mmap the files several times. |
| Harlan Haskins | 8d323d1 | 2019-08-01 21:31:56 +0000 | [diff] [blame] | 8612 | auto Entry = |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8613 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 8614 | // FIXME: The filename may be a virtual name that does probably not |
| 8615 | // point to a valid file and we get no Entry here. In this case try with |
| 8616 | // the memory buffer below. |
| 8617 | if (Entry) |
| Harlan Haskins | 8d323d1 | 2019-08-01 21:31:56 +0000 | [diff] [blame] | 8618 | ToID = ToSM.createFileID(*Entry, *ToIncludeLoc, |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8619 | FromSLoc.getFile().getFileCharacteristic()); |
| 8620 | } |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8621 | } |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8622 | |
| 8623 | if (ToID.isInvalid() || IsBuiltin) { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8624 | // FIXME: We want to re-use the existing MemoryBuffer! |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8625 | bool Invalid = true; |
| Duncan P. N. Exon Smith | f584819 | 2019-08-26 20:32:05 +0000 | [diff] [blame] | 8626 | const llvm::MemoryBuffer *FromBuf = |
| 8627 | Cache->getBuffer(FromContext.getDiagnostics(), |
| 8628 | FromSM.getFileManager(), SourceLocation{}, &Invalid); |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8629 | if (!FromBuf || Invalid) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8630 | // FIXME: Use a new error kind? |
| 8631 | return llvm::make_error<ImportError>(ImportError::Unknown); |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8632 | |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8633 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 8634 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 8635 | FromBuf->getBufferIdentifier()); |
| 8636 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 8637 | FromSLoc.getFile().getFileCharacteristic()); |
| 8638 | } |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8639 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8640 | |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8641 | assert(ToID.isValid() && "Unexpected invalid fileID was created."); |
| 8642 | |
| Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 8643 | ImportedFileIDs[FromID] = ToID; |
| Balazs Keri | d22f877 | 2019-07-24 10:16:37 +0000 | [diff] [blame] | 8644 | |
| 8645 | if (FileIDImportHandler) |
| 8646 | FileIDImportHandler(ToID, FromID); |
| 8647 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8648 | return ToID; |
| 8649 | } |
| 8650 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8651 | Expected<CXXCtorInitializer *> ASTImporter::Import(CXXCtorInitializer *From) { |
| 8652 | ExpectedExpr ToExprOrErr = Import(From->getInit()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8653 | if (!ToExprOrErr) |
| 8654 | return ToExprOrErr.takeError(); |
| 8655 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8656 | auto LParenLocOrErr = Import(From->getLParenLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8657 | if (!LParenLocOrErr) |
| 8658 | return LParenLocOrErr.takeError(); |
| 8659 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8660 | auto RParenLocOrErr = Import(From->getRParenLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8661 | if (!RParenLocOrErr) |
| 8662 | return RParenLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8663 | |
| 8664 | if (From->isBaseInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8665 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8666 | if (!ToTInfoOrErr) |
| 8667 | return ToTInfoOrErr.takeError(); |
| 8668 | |
| 8669 | SourceLocation EllipsisLoc; |
| 8670 | if (From->isPackExpansion()) |
| 8671 | if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc())) |
| 8672 | return std::move(Err); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8673 | |
| 8674 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8675 | ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr, |
| 8676 | *ToExprOrErr, *RParenLocOrErr, EllipsisLoc); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8677 | } else if (From->isMemberInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8678 | ExpectedDecl ToFieldOrErr = Import(From->getMember()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8679 | if (!ToFieldOrErr) |
| 8680 | return ToFieldOrErr.takeError(); |
| 8681 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8682 | auto MemberLocOrErr = Import(From->getMemberLocation()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8683 | if (!MemberLocOrErr) |
| 8684 | return MemberLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8685 | |
| 8686 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8687 | ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr, |
| 8688 | *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8689 | } else if (From->isIndirectMemberInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8690 | ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8691 | if (!ToIFieldOrErr) |
| 8692 | return ToIFieldOrErr.takeError(); |
| 8693 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8694 | auto MemberLocOrErr = Import(From->getMemberLocation()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8695 | if (!MemberLocOrErr) |
| 8696 | return MemberLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8697 | |
| 8698 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8699 | ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr), |
| 8700 | *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8701 | } else if (From->isDelegatingInitializer()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8702 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8703 | if (!ToTInfoOrErr) |
| 8704 | return ToTInfoOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8705 | |
| 8706 | return new (ToContext) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8707 | CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr, |
| 8708 | *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8709 | } else { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8710 | // FIXME: assert? |
| 8711 | return make_error<ImportError>(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8712 | } |
| Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8713 | } |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8714 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8715 | Expected<CXXBaseSpecifier *> |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8716 | ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8717 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 8718 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 8719 | return Pos->second; |
| 8720 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8721 | Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8722 | if (!ToSourceRange) |
| 8723 | return ToSourceRange.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8724 | Expected<TypeSourceInfo *> ToTSI = Import(BaseSpec->getTypeSourceInfo()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8725 | if (!ToTSI) |
| 8726 | return ToTSI.takeError(); |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8727 | ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc()); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8728 | if (!ToEllipsisLoc) |
| 8729 | return ToEllipsisLoc.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8730 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8731 | *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 8732 | BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8733 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 8734 | return Imported; |
| 8735 | } |
| 8736 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8737 | Error ASTImporter::ImportDefinition(Decl *From) { |
| 8738 | ExpectedDecl ToOrErr = Import(From); |
| 8739 | if (!ToOrErr) |
| 8740 | return ToOrErr.takeError(); |
| 8741 | Decl *To = *ToOrErr; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8742 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8743 | auto *FromDC = cast<DeclContext>(From); |
| 8744 | ASTNodeImporter Importer(*this); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8745 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8746 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
| 8747 | if (!ToRecord->getDefinition()) { |
| 8748 | return Importer.ImportDefinition( |
| 8749 | cast<RecordDecl>(FromDC), ToRecord, |
| 8750 | ASTNodeImporter::IDK_Everything); |
| Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8751 | } |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8752 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8753 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8754 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
| 8755 | if (!ToEnum->getDefinition()) { |
| 8756 | return Importer.ImportDefinition( |
| 8757 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); |
| 8758 | } |
| 8759 | } |
| 8760 | |
| 8761 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
| 8762 | if (!ToIFace->getDefinition()) { |
| 8763 | return Importer.ImportDefinition( |
| 8764 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
| 8765 | ASTNodeImporter::IDK_Everything); |
| 8766 | } |
| 8767 | } |
| 8768 | |
| 8769 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
| 8770 | if (!ToProto->getDefinition()) { |
| 8771 | return Importer.ImportDefinition( |
| 8772 | cast<ObjCProtocolDecl>(FromDC), ToProto, |
| 8773 | ASTNodeImporter::IDK_Everything); |
| 8774 | } |
| 8775 | } |
| 8776 | |
| 8777 | return Importer.ImportDeclContext(FromDC, true); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8778 | } |
| 8779 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8780 | Expected<DeclarationName> ASTImporter::Import(DeclarationName FromName) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8781 | if (!FromName) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8782 | return DeclarationName{}; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8783 | |
| 8784 | switch (FromName.getNameKind()) { |
| 8785 | case DeclarationName::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8786 | return DeclarationName(Import(FromName.getAsIdentifierInfo())); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8787 | |
| 8788 | case DeclarationName::ObjCZeroArgSelector: |
| 8789 | case DeclarationName::ObjCOneArgSelector: |
| 8790 | case DeclarationName::ObjCMultiArgSelector: |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8791 | if (auto ToSelOrErr = Import(FromName.getObjCSelector())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8792 | return DeclarationName(*ToSelOrErr); |
| 8793 | else |
| 8794 | return ToSelOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8795 | |
| 8796 | case DeclarationName::CXXConstructorName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8797 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8798 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 8799 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8800 | else |
| 8801 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8802 | } |
| 8803 | |
| 8804 | case DeclarationName::CXXDestructorName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8805 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8806 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 8807 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8808 | else |
| 8809 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8810 | } |
| 8811 | |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8812 | case DeclarationName::CXXDeductionGuideName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8813 | if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8814 | return ToContext.DeclarationNames.getCXXDeductionGuideName( |
| 8815 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8816 | else |
| 8817 | return ToTemplateOrErr.takeError(); |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8818 | } |
| 8819 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8820 | case DeclarationName::CXXConversionFunctionName: { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8821 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8822 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 8823 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8824 | else |
| 8825 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8826 | } |
| 8827 | |
| 8828 | case DeclarationName::CXXOperatorName: |
| 8829 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 8830 | FromName.getCXXOverloadedOperator()); |
| 8831 | |
| 8832 | case DeclarationName::CXXLiteralOperatorName: |
| 8833 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8834 | Import(FromName.getCXXLiteralIdentifier())); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8835 | |
| 8836 | case DeclarationName::CXXUsingDirective: |
| 8837 | // FIXME: STATICS! |
| 8838 | return DeclarationName::getUsingDirectiveName(); |
| 8839 | } |
| 8840 | |
| David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 8841 | llvm_unreachable("Invalid DeclarationName Kind!"); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8842 | } |
| 8843 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8844 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8845 | if (!FromId) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8846 | return nullptr; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8847 | |
| Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 8848 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 8849 | |
| 8850 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 8851 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 8852 | |
| 8853 | return ToId; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8854 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8855 | |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8856 | Expected<Selector> ASTImporter::Import(Selector FromSel) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8857 | if (FromSel.isNull()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8858 | return Selector{}; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8859 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8860 | SmallVector<IdentifierInfo *, 4> Idents; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8861 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 8862 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 8863 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 8864 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 8865 | } |
| 8866 | |
| Gabor Marton | f035b75 | 2019-08-27 11:36:10 +0000 | [diff] [blame] | 8867 | Expected<DeclarationName> ASTImporter::HandleNameConflict(DeclarationName Name, |
| 8868 | DeclContext *DC, |
| 8869 | unsigned IDNS, |
| 8870 | NamedDecl **Decls, |
| 8871 | unsigned NumDecls) { |
| 8872 | if (ODRHandling == ODRHandlingType::Conservative) |
| 8873 | // Report error at any name conflict. |
| 8874 | return make_error<ImportError>(ImportError::NameConflict); |
| 8875 | else |
| 8876 | // Allow to create the new Decl with the same name. |
| 8877 | return Name; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8878 | } |
| 8879 | |
| 8880 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
| Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8881 | if (LastDiagFromFrom) |
| 8882 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8883 | FromContext.getDiagnostics()); |
| 8884 | LastDiagFromFrom = false; |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8885 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8886 | } |
| 8887 | |
| 8888 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
| Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8889 | if (!LastDiagFromFrom) |
| 8890 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8891 | ToContext.getDiagnostics()); |
| 8892 | LastDiagFromFrom = true; |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8893 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8894 | } |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8895 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8896 | void ASTImporter::CompleteDecl (Decl *D) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8897 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8898 | if (!ID->getDefinition()) |
| 8899 | ID->startDefinition(); |
| 8900 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8901 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8902 | if (!PD->getDefinition()) |
| 8903 | PD->startDefinition(); |
| 8904 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8905 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8906 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 8907 | TD->startDefinition(); |
| 8908 | TD->setCompleteDefinition(true); |
| 8909 | } |
| 8910 | } |
| 8911 | else { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8912 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8913 | } |
| 8914 | } |
| 8915 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8916 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 8917 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 8918 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 8919 | "Try to import an already imported Decl"); |
| 8920 | if (Pos != ImportedDecls.end()) |
| 8921 | return Pos->second; |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8922 | ImportedDecls[From] = To; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 8923 | // This mapping should be maintained only in this function. Therefore do not |
| 8924 | // check for additional consistency. |
| 8925 | ImportedFromDecls[To] = From; |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8926 | AddToLookupTable(To); |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8927 | return To; |
| Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 8928 | } |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8929 | |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8930 | llvm::Optional<ImportError> |
| 8931 | ASTImporter::getImportDeclErrorIfAny(Decl *FromD) const { |
| 8932 | auto Pos = ImportDeclErrors.find(FromD); |
| 8933 | if (Pos != ImportDeclErrors.end()) |
| 8934 | return Pos->second; |
| 8935 | else |
| 8936 | return Optional<ImportError>(); |
| 8937 | } |
| 8938 | |
| 8939 | void ASTImporter::setImportDeclError(Decl *From, ImportError Error) { |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8940 | auto InsertRes = ImportDeclErrors.insert({From, Error}); |
| Benjamin Kramer | 4f76936 | 2019-07-01 14:33:26 +0000 | [diff] [blame] | 8941 | (void)InsertRes; |
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8942 | // Either we set the error for the first time, or we already had set one and |
| 8943 | // now we want to set the same error. |
| 8944 | assert(InsertRes.second || InsertRes.first->second.Error == Error.Error); |
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8945 | } |
| 8946 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8947 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 8948 | bool Complain) { |
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8949 | llvm::DenseMap<const Type *, const Type *>::iterator Pos = |
| 8950 | ImportedTypes.find(From.getTypePtr()); |
| 8951 | if (Pos != ImportedTypes.end()) { |
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8952 | if (ExpectedType ToFromOrErr = Import(From)) { |
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8953 | if (ToContext.hasSameType(*ToFromOrErr, To)) |
| 8954 | return true; |
| 8955 | } else { |
| 8956 | llvm::consumeError(ToFromOrErr.takeError()); |
| 8957 | } |
| 8958 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 8959 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8960 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8961 | getStructuralEquivalenceKind(*this), false, |
| 8962 | Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 8963 | return Ctx.IsEquivalent(From, To); |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8964 | } |