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" |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTImporterLookupTable.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" |
| 47 | #include "clang/Basic/ExceptionSpecificationType.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 48 | #include "clang/Basic/FileManager.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 49 | #include "clang/Basic/IdentifierTable.h" |
| 50 | #include "clang/Basic/LLVM.h" |
| 51 | #include "clang/Basic/LangOptions.h" |
| 52 | #include "clang/Basic/SourceLocation.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 53 | #include "clang/Basic/SourceManager.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 54 | #include "clang/Basic/Specifiers.h" |
| 55 | #include "llvm/ADT/APSInt.h" |
| 56 | #include "llvm/ADT/ArrayRef.h" |
| 57 | #include "llvm/ADT/DenseMap.h" |
| 58 | #include "llvm/ADT/None.h" |
| 59 | #include "llvm/ADT/Optional.h" |
Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 60 | #include "llvm/ADT/ScopeExit.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 61 | #include "llvm/ADT/STLExtras.h" |
| 62 | #include "llvm/ADT/SmallVector.h" |
| 63 | #include "llvm/Support/Casting.h" |
| 64 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 65 | #include "llvm/Support/MemoryBuffer.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 66 | #include <algorithm> |
| 67 | #include <cassert> |
| 68 | #include <cstddef> |
| 69 | #include <memory> |
| 70 | #include <type_traits> |
| 71 | #include <utility> |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 72 | |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 73 | namespace clang { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 74 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 75 | using llvm::make_error; |
| 76 | using llvm::Error; |
| 77 | using llvm::Expected; |
| 78 | using ExpectedType = llvm::Expected<QualType>; |
| 79 | using ExpectedStmt = llvm::Expected<Stmt *>; |
| 80 | using ExpectedExpr = llvm::Expected<Expr *>; |
| 81 | using ExpectedDecl = llvm::Expected<Decl *>; |
| 82 | using ExpectedSLoc = llvm::Expected<SourceLocation>; |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 83 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 84 | std::string ImportError::toString() const { |
| 85 | // FIXME: Improve error texts. |
| 86 | switch (Error) { |
| 87 | case NameConflict: |
| 88 | return "NameConflict"; |
| 89 | case UnsupportedConstruct: |
| 90 | return "UnsupportedConstruct"; |
| 91 | case Unknown: |
| 92 | return "Unknown error"; |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 93 | } |
Balazs Keri | 2a13d66 | 2018-10-19 15:16:51 +0000 | [diff] [blame] | 94 | llvm_unreachable("Invalid error code."); |
| 95 | return "Invalid error code."; |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 98 | void ImportError::log(raw_ostream &OS) const { |
| 99 | OS << toString(); |
| 100 | } |
| 101 | |
| 102 | std::error_code ImportError::convertToErrorCode() const { |
| 103 | llvm_unreachable("Function not implemented."); |
| 104 | } |
| 105 | |
| 106 | char ImportError::ID; |
| 107 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 108 | template <class T> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 109 | SmallVector<Decl *, 2> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 110 | getCanonicalForwardRedeclChain(Redeclarable<T>* D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 111 | SmallVector<Decl *, 2> Redecls; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 112 | for (auto *R : D->getFirstDecl()->redecls()) { |
| 113 | if (R != D->getFirstDecl()) |
| 114 | Redecls.push_back(R); |
| 115 | } |
| 116 | Redecls.push_back(D->getFirstDecl()); |
| 117 | std::reverse(Redecls.begin(), Redecls.end()); |
| 118 | return Redecls; |
| 119 | } |
| 120 | |
| 121 | SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 122 | if (auto *FD = dyn_cast<FunctionDecl>(D)) |
| 123 | return getCanonicalForwardRedeclChain<FunctionDecl>(FD); |
| 124 | if (auto *VD = dyn_cast<VarDecl>(D)) |
| 125 | return getCanonicalForwardRedeclChain<VarDecl>(VD); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 126 | if (auto *TD = dyn_cast<TagDecl>(D)) |
| 127 | return getCanonicalForwardRedeclChain<TagDecl>(TD); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 128 | llvm_unreachable("Bad declaration kind"); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 131 | void updateFlags(const Decl *From, Decl *To) { |
| 132 | // Check if some flags or attrs are new in 'From' and copy into 'To'. |
| 133 | // FIXME: Other flags or attrs? |
| 134 | if (From->isUsed(false) && !To->isUsed(false)) |
| 135 | To->setIsUsed(); |
| 136 | } |
| 137 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 138 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>, |
| 139 | public DeclVisitor<ASTNodeImporter, ExpectedDecl>, |
| 140 | public StmtVisitor<ASTNodeImporter, ExpectedStmt> { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 141 | ASTImporter &Importer; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 142 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 143 | // Use this instead of Importer.importInto . |
| 144 | template <typename ImportT> |
| 145 | LLVM_NODISCARD Error importInto(ImportT &To, const ImportT &From) { |
| 146 | return Importer.importInto(To, From); |
| 147 | } |
| 148 | |
| 149 | // Use this to import pointers of specific type. |
| 150 | template <typename ImportT> |
| 151 | LLVM_NODISCARD Error importInto(ImportT *&To, ImportT *From) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 152 | auto ToOrErr = Importer.Import(From); |
Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 153 | if (ToOrErr) |
| 154 | To = cast_or_null<ImportT>(*ToOrErr); |
| 155 | return ToOrErr.takeError(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | // Call the import function of ASTImporter for a baseclass of type `T` and |
| 159 | // cast the return value to `T`. |
| 160 | template <typename T> |
| 161 | Expected<T *> import(T *From) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 162 | auto ToOrErr = Importer.Import(From); |
Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 163 | if (!ToOrErr) |
| 164 | return ToOrErr.takeError(); |
| 165 | return cast_or_null<T>(*ToOrErr); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | template <typename T> |
| 169 | Expected<T *> import(const T *From) { |
| 170 | return import(const_cast<T *>(From)); |
| 171 | } |
| 172 | |
| 173 | // Call the import function of ASTImporter for type `T`. |
| 174 | template <typename T> |
| 175 | Expected<T> import(const T &From) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 176 | return Importer.Import(From); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 179 | // Import an Optional<T> by importing the contained T, if any. |
| 180 | template<typename T> |
| 181 | Expected<Optional<T>> import(Optional<T> From) { |
| 182 | if (!From) |
| 183 | return Optional<T>(); |
| 184 | return import(*From); |
| 185 | } |
| 186 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 187 | template <class T> |
| 188 | Expected<std::tuple<T>> |
| 189 | importSeq(const T &From) { |
| 190 | Expected<T> ToOrErr = import(From); |
| 191 | if (!ToOrErr) |
| 192 | return ToOrErr.takeError(); |
| 193 | return std::make_tuple<T>(std::move(*ToOrErr)); |
| 194 | } |
| 195 | |
| 196 | // Import multiple objects with a single function call. |
| 197 | // This should work for every type for which a variant of `import` exists. |
| 198 | // The arguments are processed from left to right and import is stopped on |
| 199 | // first error. |
| 200 | template <class THead, class... TTail> |
| 201 | Expected<std::tuple<THead, TTail...>> |
| 202 | importSeq(const THead &FromHead, const TTail &...FromTail) { |
| 203 | Expected<std::tuple<THead>> ToHeadOrErr = importSeq(FromHead); |
| 204 | if (!ToHeadOrErr) |
| 205 | return ToHeadOrErr.takeError(); |
| 206 | Expected<std::tuple<TTail...>> ToTailOrErr = importSeq(FromTail...); |
| 207 | if (!ToTailOrErr) |
| 208 | return ToTailOrErr.takeError(); |
| 209 | return std::tuple_cat(*ToHeadOrErr, *ToTailOrErr); |
| 210 | } |
| 211 | |
| 212 | // Wrapper for an overload set. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 213 | template <typename ToDeclT> struct CallOverloadedCreateFun { |
| 214 | template <typename... Args> |
| 215 | auto operator()(Args &&... args) |
| 216 | -> decltype(ToDeclT::Create(std::forward<Args>(args)...)) { |
| 217 | return ToDeclT::Create(std::forward<Args>(args)...); |
| 218 | } |
| 219 | }; |
| 220 | |
| 221 | // Always use these functions to create a Decl during import. There are |
| 222 | // certain tasks which must be done after the Decl was created, e.g. we |
| 223 | // must immediately register that as an imported Decl. The parameter `ToD` |
| 224 | // will be set to the newly created Decl or if had been imported before |
| 225 | // then to the already imported Decl. Returns a bool value set to true if |
| 226 | // the `FromD` had been imported before. |
| 227 | template <typename ToDeclT, typename FromDeclT, typename... Args> |
| 228 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 229 | Args &&... args) { |
| 230 | // There may be several overloads of ToDeclT::Create. We must make sure |
| 231 | // to call the one which would be chosen by the arguments, thus we use a |
| 232 | // wrapper for the overload set. |
| 233 | CallOverloadedCreateFun<ToDeclT> OC; |
| 234 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 235 | std::forward<Args>(args)...); |
| 236 | } |
| 237 | // Use this overload if a special Type is needed to be created. E.g if we |
| 238 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` |
| 239 | // then: |
| 240 | // TypedefNameDecl *ToTypedef; |
| 241 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); |
| 242 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, |
| 243 | typename... Args> |
| 244 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 245 | Args &&... args) { |
| 246 | CallOverloadedCreateFun<NewDeclT> OC; |
| 247 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 248 | std::forward<Args>(args)...); |
| 249 | } |
| 250 | // Use this version if a special create function must be |
| 251 | // used, e.g. CXXRecordDecl::CreateLambda . |
| 252 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, |
| 253 | typename... Args> |
| 254 | LLVM_NODISCARD bool |
| 255 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, |
| 256 | FromDeclT *FromD, Args &&... args) { |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 257 | if (Importer.getImportDeclErrorIfAny(FromD)) { |
| 258 | ToD = nullptr; |
| 259 | return true; // Already imported but with error. |
| 260 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 261 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); |
| 262 | if (ToD) |
| 263 | return true; // Already imported. |
| 264 | ToD = CreateFun(std::forward<Args>(args)...); |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 265 | // Keep track of imported Decls. |
Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 266 | Importer.RegisterImportedDecl(FromD, ToD); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 267 | InitializeImportedDecl(FromD, ToD); |
| 268 | return false; // A new Decl is created. |
| 269 | } |
| 270 | |
| 271 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 272 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; |
| 273 | if (FromD->hasAttrs()) |
Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 274 | for (const Attr *FromAttr : FromD->getAttrs()) { |
| 275 | // FIXME: Return of the error here is not possible until store of |
| 276 | // import errors is implemented. |
| 277 | auto ToAttrOrErr = import(FromAttr); |
| 278 | if (ToAttrOrErr) |
| 279 | ToD->addAttr(*ToAttrOrErr); |
| 280 | else |
| 281 | llvm::consumeError(ToAttrOrErr.takeError()); |
| 282 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 283 | if (FromD->isUsed()) |
| 284 | ToD->setIsUsed(); |
| 285 | if (FromD->isImplicit()) |
| 286 | ToD->setImplicit(); |
| 287 | } |
| 288 | |
Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 289 | // Check if we have found an existing definition. Returns with that |
| 290 | // definition if yes, otherwise returns null. |
| 291 | Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) { |
| 292 | const FunctionDecl *Definition = nullptr; |
| 293 | if (D->doesThisDeclarationHaveABody() && |
| 294 | FoundFunction->hasBody(Definition)) |
| 295 | return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition)); |
| 296 | return nullptr; |
| 297 | } |
| 298 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 299 | public: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 300 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} |
Gabor Marton | 344b099 | 2018-05-16 11:48:11 +0000 | [diff] [blame] | 301 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 302 | using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit; |
| 303 | using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit; |
| 304 | using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 305 | |
| 306 | // Importing types |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 307 | ExpectedType VisitType(const Type *T); |
| 308 | ExpectedType VisitAtomicType(const AtomicType *T); |
| 309 | ExpectedType VisitBuiltinType(const BuiltinType *T); |
| 310 | ExpectedType VisitDecayedType(const DecayedType *T); |
| 311 | ExpectedType VisitComplexType(const ComplexType *T); |
| 312 | ExpectedType VisitPointerType(const PointerType *T); |
| 313 | ExpectedType VisitBlockPointerType(const BlockPointerType *T); |
| 314 | ExpectedType VisitLValueReferenceType(const LValueReferenceType *T); |
| 315 | ExpectedType VisitRValueReferenceType(const RValueReferenceType *T); |
| 316 | ExpectedType VisitMemberPointerType(const MemberPointerType *T); |
| 317 | ExpectedType VisitConstantArrayType(const ConstantArrayType *T); |
| 318 | ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T); |
| 319 | ExpectedType VisitVariableArrayType(const VariableArrayType *T); |
| 320 | ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 321 | // FIXME: DependentSizedExtVectorType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 322 | ExpectedType VisitVectorType(const VectorType *T); |
| 323 | ExpectedType VisitExtVectorType(const ExtVectorType *T); |
| 324 | ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T); |
| 325 | ExpectedType VisitFunctionProtoType(const FunctionProtoType *T); |
| 326 | ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T); |
| 327 | ExpectedType VisitParenType(const ParenType *T); |
| 328 | ExpectedType VisitTypedefType(const TypedefType *T); |
| 329 | ExpectedType VisitTypeOfExprType(const TypeOfExprType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 330 | // FIXME: DependentTypeOfExprType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 331 | ExpectedType VisitTypeOfType(const TypeOfType *T); |
| 332 | ExpectedType VisitDecltypeType(const DecltypeType *T); |
| 333 | ExpectedType VisitUnaryTransformType(const UnaryTransformType *T); |
| 334 | ExpectedType VisitAutoType(const AutoType *T); |
| 335 | ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 336 | // FIXME: DependentDecltypeType |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 337 | ExpectedType VisitRecordType(const RecordType *T); |
| 338 | ExpectedType VisitEnumType(const EnumType *T); |
| 339 | ExpectedType VisitAttributedType(const AttributedType *T); |
| 340 | ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T); |
| 341 | ExpectedType VisitSubstTemplateTypeParmType( |
| 342 | const SubstTemplateTypeParmType *T); |
| 343 | ExpectedType VisitTemplateSpecializationType( |
| 344 | const TemplateSpecializationType *T); |
| 345 | ExpectedType VisitElaboratedType(const ElaboratedType *T); |
| 346 | ExpectedType VisitDependentNameType(const DependentNameType *T); |
| 347 | ExpectedType VisitPackExpansionType(const PackExpansionType *T); |
| 348 | ExpectedType VisitDependentTemplateSpecializationType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 349 | const DependentTemplateSpecializationType *T); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 350 | ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T); |
| 351 | ExpectedType VisitObjCObjectType(const ObjCObjectType *T); |
| 352 | ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); |
Rafael Stahl | df55620 | 2018-05-29 08:12:15 +0000 | [diff] [blame] | 353 | |
| 354 | // Importing declarations |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 355 | Error ImportDeclParts( |
| 356 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 357 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc); |
| 358 | Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); |
| 359 | Error ImportDeclarationNameLoc( |
| 360 | const DeclarationNameInfo &From, DeclarationNameInfo &To); |
| 361 | Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); |
| 362 | Error ImportDeclContext( |
| 363 | Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC); |
| 364 | Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 365 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 366 | Expected<CXXCastPath> ImportCastPath(CastExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 367 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 368 | using Designator = DesignatedInitExpr::Designator; |
| 369 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 370 | /// What we should import from the definition. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 371 | enum ImportDefinitionKind { |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 372 | /// Import the default subset of the definition, which might be |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 373 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 374 | /// import is not set). |
| 375 | IDK_Default, |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 376 | /// Import everything. |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 377 | IDK_Everything, |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 378 | /// Import only the bare bones needed to establish a valid |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 379 | /// DeclContext. |
| 380 | IDK_Basic |
| 381 | }; |
| 382 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 383 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 384 | return IDK == IDK_Everything || |
| 385 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 386 | } |
| 387 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 388 | Error ImportInitializer(VarDecl *From, VarDecl *To); |
| 389 | Error ImportDefinition( |
| 390 | RecordDecl *From, RecordDecl *To, |
| 391 | ImportDefinitionKind Kind = IDK_Default); |
| 392 | Error ImportDefinition( |
| 393 | EnumDecl *From, EnumDecl *To, |
| 394 | ImportDefinitionKind Kind = IDK_Default); |
| 395 | Error ImportDefinition( |
| 396 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
| 397 | ImportDefinitionKind Kind = IDK_Default); |
| 398 | Error ImportDefinition( |
| 399 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
| 400 | ImportDefinitionKind Kind = IDK_Default); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 401 | Error ImportTemplateArguments( |
| 402 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 403 | SmallVectorImpl<TemplateArgument> &ToArgs); |
| 404 | Expected<TemplateArgument> |
| 405 | ImportTemplateArgument(const TemplateArgument &From); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 406 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 407 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 408 | Error ImportTemplateArgumentListInfo( |
| 409 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 410 | |
| 411 | template<typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 412 | Error ImportTemplateArgumentListInfo( |
| 413 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 414 | const InContainerTy &Container, TemplateArgumentListInfo &Result); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 415 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 416 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 417 | using FunctionTemplateAndArgsTy = |
| 418 | std::tuple<FunctionTemplateDecl *, TemplateArgsTy>; |
| 419 | Expected<FunctionTemplateAndArgsTy> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 420 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 421 | FunctionDecl *FromFD); |
Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 422 | Error ImportTemplateParameterLists(const DeclaratorDecl *FromD, |
| 423 | DeclaratorDecl *ToD); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 424 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 425 | Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 426 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 427 | Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD); |
| 428 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 429 | template <typename T> |
| 430 | bool hasSameVisibilityContext(T *Found, T *From); |
| 431 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 432 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 433 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 434 | bool Complain = true); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 435 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 436 | bool Complain = true); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 437 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 438 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 439 | bool IsStructuralMatch(FunctionTemplateDecl *From, |
| 440 | FunctionTemplateDecl *To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 441 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 442 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 443 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 444 | ExpectedDecl VisitDecl(Decl *D); |
| 445 | ExpectedDecl VisitImportDecl(ImportDecl *D); |
| 446 | ExpectedDecl VisitEmptyDecl(EmptyDecl *D); |
| 447 | ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); |
| 448 | ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); |
| 449 | ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 450 | ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); |
| 451 | ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
| 452 | ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
| 453 | ExpectedDecl VisitTypedefDecl(TypedefDecl *D); |
| 454 | ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D); |
| 455 | ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
| 456 | ExpectedDecl VisitLabelDecl(LabelDecl *D); |
| 457 | ExpectedDecl VisitEnumDecl(EnumDecl *D); |
| 458 | ExpectedDecl VisitRecordDecl(RecordDecl *D); |
| 459 | ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D); |
| 460 | ExpectedDecl VisitFunctionDecl(FunctionDecl *D); |
| 461 | ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D); |
| 462 | ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 463 | ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 464 | ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); |
| 465 | ExpectedDecl VisitFieldDecl(FieldDecl *D); |
| 466 | ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); |
| 467 | ExpectedDecl VisitFriendDecl(FriendDecl *D); |
| 468 | ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 469 | ExpectedDecl VisitVarDecl(VarDecl *D); |
| 470 | ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D); |
| 471 | ExpectedDecl VisitParmVarDecl(ParmVarDecl *D); |
| 472 | ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 473 | ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
| 474 | ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 475 | ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 476 | ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D); |
| 477 | ExpectedDecl VisitUsingDecl(UsingDecl *D); |
| 478 | ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); |
| 479 | ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 480 | ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 481 | ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 482 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 483 | Expected<ObjCTypeParamList *> |
| 484 | ImportObjCTypeParamList(ObjCTypeParamList *list); |
| 485 | |
| 486 | ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 487 | ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 488 | ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 489 | ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 490 | ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
| 491 | ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 492 | ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 493 | ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 494 | ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D); |
| 495 | ExpectedDecl VisitClassTemplateSpecializationDecl( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 496 | ClassTemplateSpecializationDecl *D); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 497 | ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); |
| 498 | ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
| 499 | ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 500 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 501 | // Importing statements |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 502 | ExpectedStmt VisitStmt(Stmt *S); |
| 503 | ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S); |
| 504 | ExpectedStmt VisitDeclStmt(DeclStmt *S); |
| 505 | ExpectedStmt VisitNullStmt(NullStmt *S); |
| 506 | ExpectedStmt VisitCompoundStmt(CompoundStmt *S); |
| 507 | ExpectedStmt VisitCaseStmt(CaseStmt *S); |
| 508 | ExpectedStmt VisitDefaultStmt(DefaultStmt *S); |
| 509 | ExpectedStmt VisitLabelStmt(LabelStmt *S); |
| 510 | ExpectedStmt VisitAttributedStmt(AttributedStmt *S); |
| 511 | ExpectedStmt VisitIfStmt(IfStmt *S); |
| 512 | ExpectedStmt VisitSwitchStmt(SwitchStmt *S); |
| 513 | ExpectedStmt VisitWhileStmt(WhileStmt *S); |
| 514 | ExpectedStmt VisitDoStmt(DoStmt *S); |
| 515 | ExpectedStmt VisitForStmt(ForStmt *S); |
| 516 | ExpectedStmt VisitGotoStmt(GotoStmt *S); |
| 517 | ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 518 | ExpectedStmt VisitContinueStmt(ContinueStmt *S); |
| 519 | ExpectedStmt VisitBreakStmt(BreakStmt *S); |
| 520 | ExpectedStmt VisitReturnStmt(ReturnStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 521 | // FIXME: MSAsmStmt |
| 522 | // FIXME: SEHExceptStmt |
| 523 | // FIXME: SEHFinallyStmt |
| 524 | // FIXME: SEHTryStmt |
| 525 | // FIXME: SEHLeaveStmt |
| 526 | // FIXME: CapturedStmt |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 527 | ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S); |
| 528 | ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S); |
| 529 | ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 530 | // FIXME: MSDependentExistsStmt |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 531 | ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 532 | ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 533 | ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 534 | ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 535 | ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 536 | ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 537 | ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 538 | |
| 539 | // Importing expressions |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 540 | ExpectedStmt VisitExpr(Expr *E); |
| 541 | ExpectedStmt VisitVAArgExpr(VAArgExpr *E); |
Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 542 | ExpectedStmt VisitChooseExpr(ChooseExpr *E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 543 | ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); |
| 544 | ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E); |
| 545 | ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E); |
| 546 | ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); |
| 547 | ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 548 | ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
| 549 | ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E); |
| 550 | ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E); |
| 551 | ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E); |
| 552 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); |
| 553 | ExpectedStmt VisitStringLiteral(StringLiteral *E); |
| 554 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 555 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); |
| 556 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 557 | ExpectedStmt VisitConstantExpr(ConstantExpr *E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 558 | ExpectedStmt VisitParenExpr(ParenExpr *E); |
| 559 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); |
| 560 | ExpectedStmt VisitStmtExpr(StmtExpr *E); |
| 561 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); |
| 562 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
| 563 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); |
| 564 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); |
| 565 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 566 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); |
| 567 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 568 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 569 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
| 570 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 571 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); |
| 572 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 573 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 574 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); |
| 575 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 576 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 577 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 578 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 579 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); |
| 580 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
| 581 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); |
| 582 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); |
| 583 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); |
| 584 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); |
| 585 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); |
| 586 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
| 587 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
| 588 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); |
| 589 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); |
| 590 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
| 591 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
| 592 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); |
| 593 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); |
| 594 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
| 595 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
| 596 | ExpectedStmt VisitMemberExpr(MemberExpr *E); |
| 597 | ExpectedStmt VisitCallExpr(CallExpr *E); |
| 598 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); |
| 599 | ExpectedStmt VisitInitListExpr(InitListExpr *E); |
| 600 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); |
| 601 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); |
| 602 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 603 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
| 604 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 605 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
| 606 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
| 607 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); |
| 608 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 609 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 610 | template<typename IIter, typename OIter> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 611 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 612 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 613 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { |
| 614 | Expected<ItemT> ToOrErr = import(*Ibegin); |
| 615 | if (!ToOrErr) |
| 616 | return ToOrErr.takeError(); |
| 617 | *Obegin = *ToOrErr; |
| 618 | } |
| 619 | return Error::success(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 620 | } |
| 621 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 622 | // Import every item from a container structure into an output container. |
| 623 | // If error occurs, stops at first error and returns the error. |
| 624 | // The output container should have space for all needed elements (it is not |
| 625 | // expanded, new items are put into from the beginning). |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 626 | template<typename InContainerTy, typename OutContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 627 | Error ImportContainerChecked( |
| 628 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { |
| 629 | return ImportArrayChecked( |
| 630 | InContainer.begin(), InContainer.end(), OutContainer.begin()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | template<typename InContainerTy, typename OIter> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 634 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 635 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 636 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 637 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 638 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 639 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 640 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( |
| 641 | FunctionDecl *FromFD); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 642 | }; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 643 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 644 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 645 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 646 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 647 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 648 | auto ToLAngleLocOrErr = import(FromLAngleLoc); |
| 649 | if (!ToLAngleLocOrErr) |
| 650 | return ToLAngleLocOrErr.takeError(); |
| 651 | auto ToRAngleLocOrErr = import(FromRAngleLoc); |
| 652 | if (!ToRAngleLocOrErr) |
| 653 | return ToRAngleLocOrErr.takeError(); |
| 654 | |
| 655 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); |
| 656 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 657 | return Err; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 658 | Result = ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 659 | return Error::success(); |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 660 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 661 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 662 | template <> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 663 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 664 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 665 | return ImportTemplateArgumentListInfo( |
| 666 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 667 | } |
| 668 | |
| 669 | template <> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 670 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 671 | ASTTemplateArgumentListInfo>( |
| 672 | const ASTTemplateArgumentListInfo &From, |
| 673 | TemplateArgumentListInfo &Result) { |
| 674 | return ImportTemplateArgumentListInfo( |
| 675 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 678 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 679 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 680 | FunctionDecl *FromFD) { |
| 681 | assert(FromFD->getTemplatedKind() == |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 682 | FunctionDecl::TK_FunctionTemplateSpecialization); |
| 683 | |
| 684 | FunctionTemplateAndArgsTy Result; |
| 685 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 686 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 687 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) |
| 688 | return std::move(Err); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 689 | |
| 690 | // Import template arguments. |
| 691 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 692 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 693 | std::get<1>(Result))) |
| 694 | return std::move(Err); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 695 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 696 | return Result; |
| 697 | } |
| 698 | |
| 699 | template <> |
| 700 | Expected<TemplateParameterList *> |
| 701 | ASTNodeImporter::import(TemplateParameterList *From) { |
| 702 | SmallVector<NamedDecl *, 4> To(From->size()); |
| 703 | if (Error Err = ImportContainerChecked(*From, To)) |
| 704 | return std::move(Err); |
| 705 | |
| 706 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); |
| 707 | if (!ToRequiresClause) |
| 708 | return ToRequiresClause.takeError(); |
| 709 | |
| 710 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); |
| 711 | if (!ToTemplateLocOrErr) |
| 712 | return ToTemplateLocOrErr.takeError(); |
| 713 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); |
| 714 | if (!ToLAngleLocOrErr) |
| 715 | return ToLAngleLocOrErr.takeError(); |
| 716 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); |
| 717 | if (!ToRAngleLocOrErr) |
| 718 | return ToRAngleLocOrErr.takeError(); |
| 719 | |
| 720 | return TemplateParameterList::Create( |
| 721 | Importer.getToContext(), |
| 722 | *ToTemplateLocOrErr, |
| 723 | *ToLAngleLocOrErr, |
| 724 | To, |
| 725 | *ToRAngleLocOrErr, |
| 726 | *ToRequiresClause); |
| 727 | } |
| 728 | |
| 729 | template <> |
| 730 | Expected<TemplateArgument> |
| 731 | ASTNodeImporter::import(const TemplateArgument &From) { |
| 732 | switch (From.getKind()) { |
| 733 | case TemplateArgument::Null: |
| 734 | return TemplateArgument(); |
| 735 | |
| 736 | case TemplateArgument::Type: { |
| 737 | ExpectedType ToTypeOrErr = import(From.getAsType()); |
| 738 | if (!ToTypeOrErr) |
| 739 | return ToTypeOrErr.takeError(); |
| 740 | return TemplateArgument(*ToTypeOrErr); |
| 741 | } |
| 742 | |
| 743 | case TemplateArgument::Integral: { |
| 744 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); |
| 745 | if (!ToTypeOrErr) |
| 746 | return ToTypeOrErr.takeError(); |
| 747 | return TemplateArgument(From, *ToTypeOrErr); |
| 748 | } |
| 749 | |
| 750 | case TemplateArgument::Declaration: { |
| 751 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); |
| 752 | if (!ToOrErr) |
| 753 | return ToOrErr.takeError(); |
| 754 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); |
| 755 | if (!ToTypeOrErr) |
| 756 | return ToTypeOrErr.takeError(); |
| 757 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); |
| 758 | } |
| 759 | |
| 760 | case TemplateArgument::NullPtr: { |
| 761 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); |
| 762 | if (!ToTypeOrErr) |
| 763 | return ToTypeOrErr.takeError(); |
| 764 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); |
| 765 | } |
| 766 | |
| 767 | case TemplateArgument::Template: { |
| 768 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); |
| 769 | if (!ToTemplateOrErr) |
| 770 | return ToTemplateOrErr.takeError(); |
| 771 | |
| 772 | return TemplateArgument(*ToTemplateOrErr); |
| 773 | } |
| 774 | |
| 775 | case TemplateArgument::TemplateExpansion: { |
| 776 | Expected<TemplateName> ToTemplateOrErr = |
| 777 | import(From.getAsTemplateOrTemplatePattern()); |
| 778 | if (!ToTemplateOrErr) |
| 779 | return ToTemplateOrErr.takeError(); |
| 780 | |
| 781 | return TemplateArgument( |
| 782 | *ToTemplateOrErr, From.getNumTemplateExpansions()); |
| 783 | } |
| 784 | |
| 785 | case TemplateArgument::Expression: |
| 786 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) |
| 787 | return TemplateArgument(*ToExpr); |
| 788 | else |
| 789 | return ToExpr.takeError(); |
| 790 | |
| 791 | case TemplateArgument::Pack: { |
| 792 | SmallVector<TemplateArgument, 2> ToPack; |
| 793 | ToPack.reserve(From.pack_size()); |
| 794 | if (Error Err = ImportTemplateArguments( |
| 795 | From.pack_begin(), From.pack_size(), ToPack)) |
| 796 | return std::move(Err); |
| 797 | |
| 798 | return TemplateArgument( |
| 799 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | llvm_unreachable("Invalid template argument kind"); |
| 804 | } |
| 805 | |
| 806 | template <> |
| 807 | Expected<TemplateArgumentLoc> |
| 808 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { |
| 809 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); |
| 810 | if (!ArgOrErr) |
| 811 | return ArgOrErr.takeError(); |
| 812 | TemplateArgument Arg = *ArgOrErr; |
| 813 | |
| 814 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 815 | |
| 816 | TemplateArgumentLocInfo ToInfo; |
| 817 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 818 | ExpectedExpr E = import(FromInfo.getAsExpr()); |
| 819 | if (!E) |
| 820 | return E.takeError(); |
| 821 | ToInfo = TemplateArgumentLocInfo(*E); |
| 822 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 823 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) |
| 824 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); |
| 825 | else |
| 826 | return TSIOrErr.takeError(); |
| 827 | } else { |
| 828 | auto ToTemplateQualifierLocOrErr = |
| 829 | import(FromInfo.getTemplateQualifierLoc()); |
| 830 | if (!ToTemplateQualifierLocOrErr) |
| 831 | return ToTemplateQualifierLocOrErr.takeError(); |
| 832 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); |
| 833 | if (!ToTemplateNameLocOrErr) |
| 834 | return ToTemplateNameLocOrErr.takeError(); |
| 835 | auto ToTemplateEllipsisLocOrErr = |
| 836 | import(FromInfo.getTemplateEllipsisLoc()); |
| 837 | if (!ToTemplateEllipsisLocOrErr) |
| 838 | return ToTemplateEllipsisLocOrErr.takeError(); |
| 839 | |
| 840 | ToInfo = TemplateArgumentLocInfo( |
| 841 | *ToTemplateQualifierLocOrErr, |
| 842 | *ToTemplateNameLocOrErr, |
| 843 | *ToTemplateEllipsisLocOrErr); |
| 844 | } |
| 845 | |
| 846 | return TemplateArgumentLoc(Arg, ToInfo); |
| 847 | } |
| 848 | |
| 849 | template <> |
| 850 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { |
| 851 | if (DG.isNull()) |
| 852 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 853 | size_t NumDecls = DG.end() - DG.begin(); |
| 854 | SmallVector<Decl *, 1> ToDecls; |
| 855 | ToDecls.reserve(NumDecls); |
| 856 | for (Decl *FromD : DG) { |
| 857 | if (auto ToDOrErr = import(FromD)) |
| 858 | ToDecls.push_back(*ToDOrErr); |
| 859 | else |
| 860 | return ToDOrErr.takeError(); |
| 861 | } |
| 862 | return DeclGroupRef::Create(Importer.getToContext(), |
| 863 | ToDecls.begin(), |
| 864 | NumDecls); |
| 865 | } |
| 866 | |
| 867 | template <> |
| 868 | Expected<ASTNodeImporter::Designator> |
| 869 | ASTNodeImporter::import(const Designator &D) { |
| 870 | if (D.isFieldDesignator()) { |
| 871 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 872 | |
| 873 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); |
| 874 | if (!ToDotLocOrErr) |
| 875 | return ToDotLocOrErr.takeError(); |
| 876 | |
| 877 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); |
| 878 | if (!ToFieldLocOrErr) |
| 879 | return ToFieldLocOrErr.takeError(); |
| 880 | |
| 881 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); |
| 882 | } |
| 883 | |
| 884 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); |
| 885 | if (!ToLBracketLocOrErr) |
| 886 | return ToLBracketLocOrErr.takeError(); |
| 887 | |
| 888 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); |
| 889 | if (!ToRBracketLocOrErr) |
| 890 | return ToRBracketLocOrErr.takeError(); |
| 891 | |
| 892 | if (D.isArrayDesignator()) |
| 893 | return Designator(D.getFirstExprIndex(), |
| 894 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); |
| 895 | |
| 896 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); |
| 897 | if (!ToEllipsisLocOrErr) |
| 898 | return ToEllipsisLocOrErr.takeError(); |
| 899 | |
| 900 | assert(D.isArrayRangeDesignator()); |
| 901 | return Designator( |
| 902 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, |
| 903 | *ToRBracketLocOrErr); |
| 904 | } |
| 905 | |
| 906 | template <> |
| 907 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { |
| 908 | VarDecl *Var = nullptr; |
| 909 | if (From.capturesVariable()) { |
| 910 | if (auto VarOrErr = import(From.getCapturedVar())) |
| 911 | Var = *VarOrErr; |
| 912 | else |
| 913 | return VarOrErr.takeError(); |
| 914 | } |
| 915 | |
| 916 | auto LocationOrErr = import(From.getLocation()); |
| 917 | if (!LocationOrErr) |
| 918 | return LocationOrErr.takeError(); |
| 919 | |
| 920 | SourceLocation EllipsisLoc; |
| 921 | if (From.isPackExpansion()) |
| 922 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) |
| 923 | return std::move(Err); |
| 924 | |
| 925 | return LambdaCapture( |
| 926 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, |
| 927 | EllipsisLoc); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 928 | } |
| 929 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 930 | } // namespace clang |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 931 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 932 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 933 | // Import Types |
| 934 | //---------------------------------------------------------------------------- |
| 935 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 936 | using namespace clang; |
| 937 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 938 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 939 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 940 | << T->getTypeClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 941 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 942 | } |
| 943 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 944 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 945 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); |
| 946 | if (!UnderlyingTypeOrErr) |
| 947 | return UnderlyingTypeOrErr.takeError(); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 948 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 949 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 950 | } |
| 951 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 952 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 953 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 954 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 955 | case BuiltinType::Id: \ |
| 956 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 957 | #include "clang/Basic/OpenCLImageTypes.def" |
Andrew Savonichev | 3fee351 | 2018-11-08 11:25:41 +0000 | [diff] [blame] | 958 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
| 959 | case BuiltinType::Id: \ |
| 960 | return Importer.getToContext().Id##Ty; |
| 961 | #include "clang/Basic/OpenCLExtensionTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 962 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 963 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 964 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 965 | #include "clang/AST/BuiltinTypes.def" |
| 966 | |
| 967 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 968 | // context supports C++. |
| 969 | |
| 970 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 971 | // context supports ObjC. |
| 972 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 973 | case BuiltinType::Char_U: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 974 | // The context we're importing from has an unsigned 'char'. If we're |
| 975 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 976 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 977 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 978 | return Importer.getToContext().UnsignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 979 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 980 | return Importer.getToContext().CharTy; |
| 981 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 982 | case BuiltinType::Char_S: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 983 | // The context we're importing from has an unsigned 'char'. If we're |
| 984 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 985 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 986 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 987 | return Importer.getToContext().SignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 988 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 989 | return Importer.getToContext().CharTy; |
| 990 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 991 | case BuiltinType::WChar_S: |
| 992 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 993 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 994 | // wchar_t? |
| 995 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 996 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 997 | |
| 998 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1001 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 1002 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); |
| 1003 | if (!ToOriginalTypeOrErr) |
| 1004 | return ToOriginalTypeOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1005 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1006 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1009 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
| 1010 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1011 | if (!ToElementTypeOrErr) |
| 1012 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1013 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1014 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1017 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
| 1018 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1019 | if (!ToPointeeTypeOrErr) |
| 1020 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1021 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1022 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1025 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1026 | // FIXME: Check for blocks support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1027 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1028 | if (!ToPointeeTypeOrErr) |
| 1029 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1030 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1031 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1034 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1035 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1036 | // FIXME: Check for C++ support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1037 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1038 | if (!ToPointeeTypeOrErr) |
| 1039 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1040 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1041 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1044 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1045 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1046 | // FIXME: Check for C++0x support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1047 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1048 | if (!ToPointeeTypeOrErr) |
| 1049 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1050 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1051 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1054 | ExpectedType |
| 1055 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1056 | // FIXME: Check for C++ support in "to" context. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1057 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1058 | if (!ToPointeeTypeOrErr) |
| 1059 | return ToPointeeTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1060 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1061 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); |
| 1062 | if (!ClassTypeOrErr) |
| 1063 | return ClassTypeOrErr.takeError(); |
| 1064 | |
| 1065 | return Importer.getToContext().getMemberPointerType( |
| 1066 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1069 | ExpectedType |
| 1070 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
| 1071 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1072 | if (!ToElementTypeOrErr) |
| 1073 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1074 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1075 | return Importer.getToContext().getConstantArrayType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1076 | T->getSize(), |
| 1077 | T->getSizeModifier(), |
| 1078 | T->getIndexTypeCVRQualifiers()); |
| 1079 | } |
| 1080 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1081 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1082 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1083 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1084 | if (!ToElementTypeOrErr) |
| 1085 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1086 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1087 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1088 | T->getSizeModifier(), |
| 1089 | T->getIndexTypeCVRQualifiers()); |
| 1090 | } |
| 1091 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1092 | ExpectedType |
| 1093 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
| 1094 | QualType ToElementType; |
| 1095 | Expr *ToSizeExpr; |
| 1096 | SourceRange ToBracketsRange; |
| 1097 | if (auto Imp = importSeq( |
| 1098 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1099 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1100 | else |
| 1101 | return Imp.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1102 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1103 | return Importer.getToContext().getVariableArrayType( |
| 1104 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1105 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1108 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1109 | const DependentSizedArrayType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1110 | QualType ToElementType; |
| 1111 | Expr *ToSizeExpr; |
| 1112 | SourceRange ToBracketsRange; |
| 1113 | if (auto Imp = importSeq( |
| 1114 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1115 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1116 | else |
| 1117 | return Imp.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1118 | // SizeExpr may be null if size is not specified directly. |
| 1119 | // For example, 'int a[]'. |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1120 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1121 | return Importer.getToContext().getDependentSizedArrayType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1122 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1123 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1126 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
| 1127 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1128 | if (!ToElementTypeOrErr) |
| 1129 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1130 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1131 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1132 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 1133 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1136 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
| 1137 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1138 | if (!ToElementTypeOrErr) |
| 1139 | return ToElementTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1140 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1141 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1142 | T->getNumElements()); |
| 1143 | } |
| 1144 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1145 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1146 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1147 | // FIXME: What happens if we're importing a function without a prototype |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1148 | // into C++? Should we make it variadic? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1149 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1150 | if (!ToReturnTypeOrErr) |
| 1151 | return ToReturnTypeOrErr.takeError(); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1152 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1153 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1154 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1157 | ExpectedType |
| 1158 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 1159 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1160 | if (!ToReturnTypeOrErr) |
| 1161 | return ToReturnTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1162 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1163 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1164 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 1165 | for (const auto &A : T->param_types()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1166 | ExpectedType TyOrErr = import(A); |
| 1167 | if (!TyOrErr) |
| 1168 | return TyOrErr.takeError(); |
| 1169 | ArgTypes.push_back(*TyOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1170 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1171 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1172 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1173 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 1174 | for (const auto &E : T->exceptions()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1175 | ExpectedType TyOrErr = import(E); |
| 1176 | if (!TyOrErr) |
| 1177 | return TyOrErr.takeError(); |
| 1178 | ExceptionTypes.push_back(*TyOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1179 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 1180 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1181 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 1182 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 1183 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1184 | auto Imp = importSeq( |
| 1185 | FromEPI.ExceptionSpec.NoexceptExpr, |
| 1186 | FromEPI.ExceptionSpec.SourceDecl, |
| 1187 | FromEPI.ExceptionSpec.SourceTemplate); |
| 1188 | if (!Imp) |
| 1189 | return Imp.takeError(); |
| 1190 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1191 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 1192 | ToEPI.Variadic = FromEPI.Variadic; |
| 1193 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 1194 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 1195 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1196 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 1197 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1198 | std::tie( |
| 1199 | ToEPI.ExceptionSpec.NoexceptExpr, |
| 1200 | ToEPI.ExceptionSpec.SourceDecl, |
| 1201 | ToEPI.ExceptionSpec.SourceTemplate) = *Imp; |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1202 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1203 | return Importer.getToContext().getFunctionType( |
| 1204 | *ToReturnTypeOrErr, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1207 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1208 | const UnresolvedUsingType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1209 | UnresolvedUsingTypenameDecl *ToD; |
| 1210 | Decl *ToPrevD; |
| 1211 | if (auto Imp = importSeq(T->getDecl(), T->getDecl()->getPreviousDecl())) |
| 1212 | std::tie(ToD, ToPrevD) = *Imp; |
| 1213 | else |
| 1214 | return Imp.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1215 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1216 | return Importer.getToContext().getTypeDeclType( |
| 1217 | ToD, cast_or_null<TypeDecl>(ToPrevD)); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1220 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 1221 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); |
| 1222 | if (!ToInnerTypeOrErr) |
| 1223 | return ToInnerTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1224 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1225 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1228 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
| 1229 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1230 | if (!ToDeclOrErr) |
| 1231 | return ToDeclOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1232 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1233 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1234 | } |
| 1235 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1236 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
| 1237 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1238 | if (!ToExprOrErr) |
| 1239 | return ToExprOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1240 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1241 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1244 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
| 1245 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1246 | if (!ToUnderlyingTypeOrErr) |
| 1247 | return ToUnderlyingTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1248 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1249 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1252 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1253 | // FIXME: Make sure that the "to" context supports C++0x! |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1254 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1255 | if (!ToExprOrErr) |
| 1256 | return ToExprOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1257 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1258 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1259 | if (!ToUnderlyingTypeOrErr) |
| 1260 | return ToUnderlyingTypeOrErr.takeError(); |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 1261 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1262 | return Importer.getToContext().getDecltypeType( |
| 1263 | *ToExprOrErr, *ToUnderlyingTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1264 | } |
| 1265 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1266 | ExpectedType |
| 1267 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 1268 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1269 | if (!ToBaseTypeOrErr) |
| 1270 | return ToBaseTypeOrErr.takeError(); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1271 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1272 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1273 | if (!ToUnderlyingTypeOrErr) |
| 1274 | return ToUnderlyingTypeOrErr.takeError(); |
| 1275 | |
| 1276 | return Importer.getToContext().getUnaryTransformType( |
| 1277 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1280 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 1281 | // FIXME: Make sure that the "to" context supports C++11! |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1282 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); |
| 1283 | if (!ToDeducedTypeOrErr) |
| 1284 | return ToDeducedTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1285 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1286 | return Importer.getToContext().getAutoType(*ToDeducedTypeOrErr, |
| 1287 | T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 1288 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1291 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1292 | const InjectedClassNameType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1293 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1294 | if (!ToDeclOrErr) |
| 1295 | return ToDeclOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1296 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1297 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); |
| 1298 | if (!ToInjTypeOrErr) |
| 1299 | return ToInjTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1300 | |
| 1301 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 1302 | // See comments in InjectedClassNameType definition for details |
| 1303 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 1304 | enum { |
| 1305 | TypeAlignmentInBits = 4, |
| 1306 | TypeAlignment = 1 << TypeAlignmentInBits |
| 1307 | }; |
| 1308 | |
| 1309 | return QualType(new (Importer.getToContext(), TypeAlignment) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1310 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1311 | } |
| 1312 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1313 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
| 1314 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1315 | if (!ToDeclOrErr) |
| 1316 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1317 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1318 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1321 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
| 1322 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1323 | if (!ToDeclOrErr) |
| 1324 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1325 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1326 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1329 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 1330 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); |
| 1331 | if (!ToModifiedTypeOrErr) |
| 1332 | return ToModifiedTypeOrErr.takeError(); |
| 1333 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); |
| 1334 | if (!ToEquivalentTypeOrErr) |
| 1335 | return ToEquivalentTypeOrErr.takeError(); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1336 | |
| 1337 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1338 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1341 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1342 | const TemplateTypeParmType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1343 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1344 | if (!ToDeclOrErr) |
| 1345 | return ToDeclOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1346 | |
| 1347 | return Importer.getToContext().getTemplateTypeParmType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1348 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1351 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1352 | const SubstTemplateTypeParmType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1353 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); |
| 1354 | if (!ReplacedOrErr) |
| 1355 | return ReplacedOrErr.takeError(); |
| 1356 | const TemplateTypeParmType *Replaced = |
| 1357 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1358 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1359 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); |
| 1360 | if (!ToReplacementTypeOrErr) |
| 1361 | return ToReplacementTypeOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1362 | |
| 1363 | return Importer.getToContext().getSubstTemplateTypeParmType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1364 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1367 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1368 | const TemplateSpecializationType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1369 | auto ToTemplateOrErr = import(T->getTemplateName()); |
| 1370 | if (!ToTemplateOrErr) |
| 1371 | return ToTemplateOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1372 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1373 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1374 | if (Error Err = ImportTemplateArguments( |
| 1375 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
| 1376 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1377 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1378 | QualType ToCanonType; |
| 1379 | if (!QualType(T, 0).isCanonical()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1380 | QualType FromCanonType |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1381 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1382 | if (ExpectedType TyOrErr = import(FromCanonType)) |
| 1383 | ToCanonType = *TyOrErr; |
| 1384 | else |
| 1385 | return TyOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1386 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1387 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 1388 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1389 | ToCanonType); |
| 1390 | } |
| 1391 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1392 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1393 | // Note: the qualifier in an ElaboratedType is optional. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1394 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1395 | if (!ToQualifierOrErr) |
| 1396 | return ToQualifierOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1397 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1398 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); |
| 1399 | if (!ToNamedTypeOrErr) |
| 1400 | return ToNamedTypeOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1401 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1402 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); |
| 1403 | if (!ToOwnedTagDeclOrErr) |
| 1404 | return ToOwnedTagDeclOrErr.takeError(); |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1405 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1406 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1407 | *ToQualifierOrErr, |
| 1408 | *ToNamedTypeOrErr, |
| 1409 | *ToOwnedTagDeclOrErr); |
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 |
| 1413 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 1414 | ExpectedType ToPatternOrErr = import(T->getPattern()); |
| 1415 | if (!ToPatternOrErr) |
| 1416 | return ToPatternOrErr.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1417 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1418 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1419 | T->getNumExpansions()); |
| 1420 | } |
| 1421 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1422 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1423 | const DependentTemplateSpecializationType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1424 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1425 | if (!ToQualifierOrErr) |
| 1426 | return ToQualifierOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1427 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1428 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1429 | |
| 1430 | SmallVector<TemplateArgument, 2> ToPack; |
| 1431 | ToPack.reserve(T->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1432 | if (Error Err = ImportTemplateArguments( |
| 1433 | T->getArgs(), T->getNumArgs(), ToPack)) |
| 1434 | return std::move(Err); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1435 | |
| 1436 | return Importer.getToContext().getDependentTemplateSpecializationType( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1437 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1440 | ExpectedType |
| 1441 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { |
| 1442 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1443 | if (!ToQualifierOrErr) |
| 1444 | return ToQualifierOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1445 | |
| 1446 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1447 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1448 | QualType Canon; |
| 1449 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { |
| 1450 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) |
| 1451 | Canon = (*TyOrErr).getCanonicalType(); |
| 1452 | else |
| 1453 | return TyOrErr.takeError(); |
| 1454 | } |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1455 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1456 | return Importer.getToContext().getDependentNameType(T->getKeyword(), |
| 1457 | *ToQualifierOrErr, |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1458 | Name, Canon); |
| 1459 | } |
| 1460 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1461 | ExpectedType |
| 1462 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
| 1463 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1464 | if (!ToDeclOrErr) |
| 1465 | return ToDeclOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1466 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1467 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1470 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
| 1471 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1472 | if (!ToBaseTypeOrErr) |
| 1473 | return ToBaseTypeOrErr.takeError(); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1474 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1475 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1476 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1477 | if (ExpectedType TyOrErr = import(TypeArg)) |
| 1478 | TypeArgs.push_back(*TyOrErr); |
| 1479 | else |
| 1480 | return TyOrErr.takeError(); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1483 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1484 | for (auto *P : T->quals()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1485 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) |
| 1486 | Protocols.push_back(*ProtocolOrErr); |
| 1487 | else |
| 1488 | return ProtocolOrErr.takeError(); |
| 1489 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1492 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1493 | Protocols, |
| 1494 | T->isKindOfTypeAsWritten()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1497 | ExpectedType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1498 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1499 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1500 | if (!ToPointeeTypeOrErr) |
| 1501 | return ToPointeeTypeOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1502 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1503 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1506 | //---------------------------------------------------------------------------- |
| 1507 | // Import Declarations |
| 1508 | //---------------------------------------------------------------------------- |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1509 | Error ASTNodeImporter::ImportDeclParts( |
| 1510 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 1511 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1512 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. |
| 1513 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); |
| 1514 | DeclContext *OrigDC = D->getDeclContext(); |
| 1515 | FunctionDecl *FunDecl; |
| 1516 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && |
| 1517 | FunDecl->hasBody()) { |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1518 | auto getLeafPointeeType = [](const Type *T) { |
| 1519 | while (T->isPointerType() || T->isArrayType()) { |
| 1520 | T = T->getPointeeOrArrayElementType(); |
| 1521 | } |
| 1522 | return T; |
| 1523 | }; |
| 1524 | for (const ParmVarDecl *P : FunDecl->parameters()) { |
| 1525 | const Type *LeafT = |
| 1526 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); |
| 1527 | auto *RT = dyn_cast<RecordType>(LeafT); |
| 1528 | if (RT && RT->getDecl() == D) { |
| 1529 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 1530 | << D->getDeclKindName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1531 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1532 | } |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1533 | } |
| 1534 | } |
| 1535 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1536 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1537 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 1538 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1539 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1540 | // Import the name of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1541 | if (Error Err = importInto(Name, D->getDeclName())) |
| 1542 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1543 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1544 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1545 | if (Error Err = importInto(Loc, D->getLocation())) |
| 1546 | return Err; |
| 1547 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1548 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 1549 | if (ToD) |
| 1550 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD)) |
| 1551 | return Err; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1552 | |
| 1553 | return Error::success(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1556 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1557 | if (!FromD) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1558 | return Error::success(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1559 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1560 | if (!ToD) |
| 1561 | if (Error Err = importInto(ToD, FromD)) |
| 1562 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1563 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1564 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1565 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { |
| 1566 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && |
| 1567 | !ToRecord->getDefinition()) { |
| 1568 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) |
| 1569 | return Err; |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1570 | } |
| 1571 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1572 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1573 | } |
| 1574 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1575 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1576 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1577 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1578 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) |
| 1579 | return Err; |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1580 | } |
| 1581 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1582 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1583 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1584 | |
| 1585 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1586 | } |
| 1587 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1588 | Error |
| 1589 | ASTNodeImporter::ImportDeclarationNameLoc( |
| 1590 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1591 | // NOTE: To.Name and To.Loc are already imported. |
| 1592 | // We only have to import To.LocInfo. |
| 1593 | switch (To.getName().getNameKind()) { |
| 1594 | case DeclarationName::Identifier: |
| 1595 | case DeclarationName::ObjCZeroArgSelector: |
| 1596 | case DeclarationName::ObjCOneArgSelector: |
| 1597 | case DeclarationName::ObjCMultiArgSelector: |
| 1598 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1599 | case DeclarationName::CXXDeductionGuideName: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1600 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1601 | |
| 1602 | case DeclarationName::CXXOperatorName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1603 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) |
| 1604 | To.setCXXOperatorNameRange(*ToRangeOrErr); |
| 1605 | else |
| 1606 | return ToRangeOrErr.takeError(); |
| 1607 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1608 | } |
| 1609 | case DeclarationName::CXXLiteralOperatorName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1610 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) |
| 1611 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); |
| 1612 | else |
| 1613 | return LocOrErr.takeError(); |
| 1614 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1615 | } |
| 1616 | case DeclarationName::CXXConstructorName: |
| 1617 | case DeclarationName::CXXDestructorName: |
| 1618 | case DeclarationName::CXXConversionFunctionName: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1619 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) |
| 1620 | To.setNamedTypeInfo(*ToTInfoOrErr); |
| 1621 | else |
| 1622 | return ToTInfoOrErr.takeError(); |
| 1623 | return Error::success(); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1624 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1625 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1626 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1627 | } |
| 1628 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1629 | Error |
| 1630 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1631 | if (Importer.isMinimalImport() && !ForceImport) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1632 | auto ToDCOrErr = Importer.ImportContext(FromDC); |
| 1633 | return ToDCOrErr.takeError(); |
| 1634 | } |
Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1635 | |
| 1636 | // We use strict error handling in case of records and enums, but not |
| 1637 | // with e.g. namespaces. |
| 1638 | // |
| 1639 | // FIXME Clients of the ASTImporter should be able to choose an |
| 1640 | // appropriate error handling strategy for their needs. For instance, |
| 1641 | // they may not want to mark an entire namespace as erroneous merely |
| 1642 | // because there is an ODR error with two typedefs. As another example, |
| 1643 | // the client may allow EnumConstantDecls with same names but with |
| 1644 | // different values in two distinct translation units. |
| 1645 | bool AccumulateChildErrors = isa<TagDecl>(FromDC); |
| 1646 | |
| 1647 | Error ChildErrors = Error::success(); |
Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1648 | llvm::SmallVector<Decl *, 8> ImportedDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1649 | for (auto *From : FromDC->decls()) { |
| 1650 | ExpectedDecl ImportedOrErr = import(From); |
Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1651 | if (!ImportedOrErr) { |
| 1652 | if (AccumulateChildErrors) |
| 1653 | ChildErrors = |
| 1654 | joinErrors(std::move(ChildErrors), ImportedOrErr.takeError()); |
| 1655 | else |
| 1656 | consumeError(ImportedOrErr.takeError()); |
| 1657 | } |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1658 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1659 | |
Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1660 | return ChildErrors; |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1663 | Error ASTNodeImporter::ImportDeclContext( |
| 1664 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { |
| 1665 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); |
| 1666 | if (!ToDCOrErr) |
| 1667 | return ToDCOrErr.takeError(); |
| 1668 | ToDC = *ToDCOrErr; |
| 1669 | |
| 1670 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { |
| 1671 | auto ToLexicalDCOrErr = Importer.ImportContext( |
| 1672 | FromD->getLexicalDeclContext()); |
| 1673 | if (!ToLexicalDCOrErr) |
| 1674 | return ToLexicalDCOrErr.takeError(); |
| 1675 | ToLexicalDC = *ToLexicalDCOrErr; |
| 1676 | } else |
| 1677 | ToLexicalDC = ToDC; |
| 1678 | |
| 1679 | return Error::success(); |
| 1680 | } |
| 1681 | |
| 1682 | Error ASTNodeImporter::ImportImplicitMethods( |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1683 | const CXXRecordDecl *From, CXXRecordDecl *To) { |
| 1684 | assert(From->isCompleteDefinition() && To->getDefinition() == To && |
| 1685 | "Import implicit methods to or from non-definition"); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1686 | |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1687 | for (CXXMethodDecl *FromM : From->methods()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1688 | if (FromM->isImplicit()) { |
| 1689 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); |
| 1690 | if (!ToMOrErr) |
| 1691 | return ToMOrErr.takeError(); |
| 1692 | } |
| 1693 | |
| 1694 | return Error::success(); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1695 | } |
| 1696 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1697 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1698 | ASTImporter &Importer) { |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1699 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 1700 | if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef)) |
Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 1701 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); |
| 1702 | else |
| 1703 | return ToTypedefOrErr.takeError(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1704 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1705 | return Error::success(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1706 | } |
| 1707 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1708 | Error ASTNodeImporter::ImportDefinition( |
| 1709 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1710 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1711 | if (Kind == IDK_Everything) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1712 | return ImportDeclContext(From, /*ForceImport=*/true); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1713 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1714 | return Error::success(); |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1715 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1716 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1717 | To->startDefinition(); |
Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1718 | // Complete the definition even if error is returned. |
| 1719 | // The RecordDecl may be already part of the AST so it is better to |
| 1720 | // have it in complete state even if something is wrong with it. |
| 1721 | auto DefinitionCompleter = |
| 1722 | llvm::make_scope_exit([To]() { To->completeDefinition(); }); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1723 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1724 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1725 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1726 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1727 | // Add base classes. |
Gabor Marton | 17d3967 | 2018-11-26 15:54:08 +0000 | [diff] [blame] | 1728 | auto *ToCXX = dyn_cast<CXXRecordDecl>(To); |
| 1729 | auto *FromCXX = dyn_cast<CXXRecordDecl>(From); |
| 1730 | if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) { |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1731 | |
| 1732 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1733 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 1734 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1735 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1736 | ToData.Aggregate = FromData.Aggregate; |
| 1737 | ToData.PlainOldData = FromData.PlainOldData; |
| 1738 | ToData.Empty = FromData.Empty; |
| 1739 | ToData.Polymorphic = FromData.Polymorphic; |
| 1740 | ToData.Abstract = FromData.Abstract; |
| 1741 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1742 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; |
| 1743 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; |
| 1744 | ToData.HasBasesWithNonStaticDataMembers = |
| 1745 | FromData.HasBasesWithNonStaticDataMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1746 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 1747 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 1748 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 1749 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1750 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1751 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1752 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1753 | ToData.HasUninitializedReferenceMember |
| 1754 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1755 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1756 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1757 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1758 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1759 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1760 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1761 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1762 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1763 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1764 | ToData.NeedOverloadResolutionForDestructor |
| 1765 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1766 | ToData.DefaultedCopyConstructorIsDeleted |
| 1767 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1768 | ToData.DefaultedMoveConstructorIsDeleted |
| 1769 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1770 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1771 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1772 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1773 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1774 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1775 | ToData.HasConstexprNonCopyMoveConstructor |
| 1776 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1777 | ToData.HasDefaultedDefaultConstructor |
| 1778 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1779 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1780 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1781 | ToData.HasConstexprDefaultConstructor |
| 1782 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1783 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1784 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1785 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1786 | ToData.UserProvidedDefaultConstructor |
| 1787 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1788 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1789 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1790 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1791 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1792 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1793 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1794 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1795 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1796 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1797 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1798 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1799 | |
Shafik Yaghmour | 16b9073 | 2019-04-26 18:51:28 +0000 | [diff] [blame] | 1800 | // Copy over the data stored in RecordDeclBits |
| 1801 | ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions()); |
| 1802 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1803 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1804 | for (const auto &Base1 : FromCXX->bases()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1805 | ExpectedType TyOrErr = import(Base1.getType()); |
| 1806 | if (!TyOrErr) |
| 1807 | return TyOrErr.takeError(); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1808 | |
| 1809 | SourceLocation EllipsisLoc; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1810 | if (Base1.isPackExpansion()) { |
| 1811 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) |
| 1812 | EllipsisLoc = *LocOrErr; |
| 1813 | else |
| 1814 | return LocOrErr.takeError(); |
| 1815 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1816 | |
| 1817 | // Ensure that we have a definition for the base. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1818 | if (Error Err = |
| 1819 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) |
| 1820 | return Err; |
| 1821 | |
| 1822 | auto RangeOrErr = import(Base1.getSourceRange()); |
| 1823 | if (!RangeOrErr) |
| 1824 | return RangeOrErr.takeError(); |
| 1825 | |
| 1826 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); |
| 1827 | if (!TSIOrErr) |
| 1828 | return TSIOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1829 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1830 | Bases.push_back( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1831 | new (Importer.getToContext()) CXXBaseSpecifier( |
| 1832 | *RangeOrErr, |
| 1833 | Base1.isVirtual(), |
| 1834 | Base1.isBaseOfClass(), |
| 1835 | Base1.getAccessSpecifierAsWritten(), |
| 1836 | *TSIOrErr, |
| 1837 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1838 | } |
| 1839 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1840 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1841 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1842 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1843 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1844 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1845 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1846 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1847 | return Error::success(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1850 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1851 | if (To->getAnyInitializer()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1852 | return Error::success(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1853 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1854 | Expr *FromInit = From->getInit(); |
| 1855 | if (!FromInit) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1856 | return Error::success(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1857 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1858 | ExpectedExpr ToInitOrErr = import(FromInit); |
| 1859 | if (!ToInitOrErr) |
| 1860 | return ToInitOrErr.takeError(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1861 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1862 | To->setInit(*ToInitOrErr); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1863 | if (From->isInitKnownICE()) { |
| 1864 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); |
| 1865 | Eval->CheckedICE = true; |
| 1866 | Eval->IsICE = From->isInitICE(); |
| 1867 | } |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1868 | |
| 1869 | // FIXME: Other bits to merge? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1870 | return Error::success(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1871 | } |
| 1872 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1873 | Error ASTNodeImporter::ImportDefinition( |
| 1874 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1875 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1876 | if (Kind == IDK_Everything) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1877 | return ImportDeclContext(From, /*ForceImport=*/true); |
| 1878 | return Error::success(); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1879 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1880 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1881 | To->startDefinition(); |
| 1882 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1883 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1884 | return Err; |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1885 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1886 | ExpectedType ToTypeOrErr = |
| 1887 | import(Importer.getFromContext().getTypeDeclType(From)); |
| 1888 | if (!ToTypeOrErr) |
| 1889 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1890 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1891 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); |
| 1892 | if (!ToPromotionTypeOrErr) |
| 1893 | return ToPromotionTypeOrErr.takeError(); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1894 | |
| 1895 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1896 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1897 | return Err; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1898 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1899 | // FIXME: we might need to merge the number of positive or negative bits |
| 1900 | // if the enumerator lists don't match. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1901 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1902 | From->getNumPositiveBits(), |
| 1903 | From->getNumNegativeBits()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1904 | return Error::success(); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1907 | Error ASTNodeImporter::ImportTemplateArguments( |
| 1908 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 1909 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1910 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1911 | if (auto ToOrErr = import(FromArgs[I])) |
| 1912 | ToArgs.push_back(*ToOrErr); |
| 1913 | else |
| 1914 | return ToOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1915 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1916 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1917 | return Error::success(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1918 | } |
| 1919 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1920 | // FIXME: Do not forget to remove this and use only 'import'. |
| 1921 | Expected<TemplateArgument> |
| 1922 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1923 | return import(From); |
| 1924 | } |
| 1925 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1926 | template <typename InContainerTy> |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1927 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1928 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1929 | for (const auto &FromLoc : Container) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1930 | if (auto ToLocOrErr = import(FromLoc)) |
| 1931 | ToTAInfo.addArgument(*ToLocOrErr); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1932 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1933 | return ToLocOrErr.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1934 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1935 | return Error::success(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1936 | } |
| 1937 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1938 | static StructuralEquivalenceKind |
| 1939 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 1940 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 1941 | : StructuralEquivalenceKind::Default; |
| 1942 | } |
| 1943 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1944 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { |
| 1945 | StructuralEquivalenceContext Ctx( |
| 1946 | Importer.getFromContext(), Importer.getToContext(), |
| 1947 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1948 | false, Complain); |
| 1949 | return Ctx.IsEquivalent(From, To); |
| 1950 | } |
| 1951 | |
| 1952 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1953 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1954 | // Eliminate a potential failure point where we attempt to re-import |
| 1955 | // something we're trying to import while completing ToRecord. |
| 1956 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1957 | if (ToOrigin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1958 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1959 | if (ToOriginRecord) |
| 1960 | ToRecord = ToOriginRecord; |
| 1961 | } |
| 1962 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1963 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1964 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1965 | Importer.getNonEquivalentDecls(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1966 | getStructuralEquivalenceKind(Importer), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1967 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1968 | return Ctx.IsEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1969 | } |
| 1970 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1971 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 1972 | bool Complain) { |
| 1973 | StructuralEquivalenceContext Ctx( |
| 1974 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1975 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1976 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1977 | return Ctx.IsEquivalent(FromVar, ToVar); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1978 | } |
| 1979 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1980 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 1981 | // Eliminate a potential failure point where we attempt to re-import |
Raphael Isemann | fa26c20 | 2019-04-09 14:18:23 +0000 | [diff] [blame] | 1982 | // something we're trying to import while completing ToEnum. |
Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 1983 | if (Decl *ToOrigin = Importer.GetOriginalDecl(ToEnum)) |
| 1984 | if (auto *ToOriginEnum = dyn_cast<EnumDecl>(ToOrigin)) |
| 1985 | ToEnum = ToOriginEnum; |
| 1986 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1987 | StructuralEquivalenceContext Ctx( |
| 1988 | Importer.getFromContext(), Importer.getToContext(), |
| 1989 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1990 | return Ctx.IsEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1991 | } |
| 1992 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1993 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 1994 | FunctionTemplateDecl *To) { |
| 1995 | StructuralEquivalenceContext Ctx( |
| 1996 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1997 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1998 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1999 | return Ctx.IsEquivalent(From, To); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2000 | } |
| 2001 | |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2002 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 2003 | StructuralEquivalenceContext Ctx( |
| 2004 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2005 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2006 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2007 | return Ctx.IsEquivalent(From, To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2008 | } |
| 2009 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2010 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2011 | EnumConstantDecl *ToEC) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2012 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 2013 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 2014 | |
| 2015 | return FromVal.isSigned() == ToVal.isSigned() && |
| 2016 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 2017 | FromVal == ToVal; |
| 2018 | } |
| 2019 | |
| 2020 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2021 | ClassTemplateDecl *To) { |
| 2022 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2023 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2024 | Importer.getNonEquivalentDecls(), |
| 2025 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2026 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2027 | } |
| 2028 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2029 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 2030 | VarTemplateDecl *To) { |
| 2031 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2032 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2033 | Importer.getNonEquivalentDecls(), |
| 2034 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2035 | return Ctx.IsEquivalent(From, To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2038 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 2039 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2040 | << D->getDeclKindName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2041 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2042 | } |
| 2043 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2044 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { |
| 2045 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 2046 | << D->getDeclKindName(); |
| 2047 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| 2048 | } |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2049 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2050 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 2051 | // Import the context of this declaration. |
| 2052 | DeclContext *DC, *LexicalDC; |
| 2053 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 2054 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2055 | |
| 2056 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2057 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2058 | if (!LocOrErr) |
| 2059 | return LocOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2060 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2061 | EmptyDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2062 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2063 | return ToD; |
| 2064 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2065 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2066 | LexicalDC->addDeclInternal(ToD); |
| 2067 | return ToD; |
| 2068 | } |
| 2069 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2070 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2071 | TranslationUnitDecl *ToD = |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2072 | Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2073 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2074 | Importer.MapImported(D, ToD); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2075 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2076 | return ToD; |
| 2077 | } |
| 2078 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2079 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 2080 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2081 | if (!LocOrErr) |
| 2082 | return LocOrErr.takeError(); |
| 2083 | auto ColonLocOrErr = import(D->getColonLoc()); |
| 2084 | if (!ColonLocOrErr) |
| 2085 | return ColonLocOrErr.takeError(); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2086 | |
| 2087 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2088 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2089 | if (!DCOrErr) |
| 2090 | return DCOrErr.takeError(); |
| 2091 | DeclContext *DC = *DCOrErr; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2092 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2093 | AccessSpecDecl *ToD; |
| 2094 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2095 | DC, *LocOrErr, *ColonLocOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2096 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2097 | |
| 2098 | // Lexical DeclContext and Semantic DeclContext |
| 2099 | // is always the same for the accessSpec. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2100 | ToD->setLexicalDeclContext(DC); |
| 2101 | DC->addDeclInternal(ToD); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2102 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2103 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2104 | } |
| 2105 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2106 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 2107 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2108 | if (!DCOrErr) |
| 2109 | return DCOrErr.takeError(); |
| 2110 | DeclContext *DC = *DCOrErr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2111 | DeclContext *LexicalDC = DC; |
| 2112 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2113 | SourceLocation ToLocation, ToRParenLoc; |
| 2114 | Expr *ToAssertExpr; |
| 2115 | StringLiteral *ToMessage; |
| 2116 | if (auto Imp = importSeq( |
| 2117 | D->getLocation(), D->getAssertExpr(), D->getMessage(), D->getRParenLoc())) |
| 2118 | std::tie(ToLocation, ToAssertExpr, ToMessage, ToRParenLoc) = *Imp; |
| 2119 | else |
| 2120 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2121 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2122 | StaticAssertDecl *ToD; |
| 2123 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2124 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, |
| 2125 | ToRParenLoc, D->isFailed())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2126 | return ToD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2127 | |
| 2128 | ToD->setLexicalDeclContext(LexicalDC); |
| 2129 | LexicalDC->addDeclInternal(ToD); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2130 | return ToD; |
| 2131 | } |
| 2132 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2133 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2134 | // Import the major distinguishing characteristics of this namespace. |
| 2135 | DeclContext *DC, *LexicalDC; |
| 2136 | DeclarationName Name; |
| 2137 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2138 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2139 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2140 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2141 | if (ToD) |
| 2142 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2143 | |
| 2144 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2145 | if (!Name) { |
| 2146 | // This is an anonymous namespace. Adopt an existing anonymous |
| 2147 | // namespace if we can. |
| 2148 | // FIXME: Not testable. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2149 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2150 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 2151 | else |
| 2152 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 2153 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2154 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2155 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2156 | for (auto *FoundDecl : FoundDecls) { |
| 2157 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2158 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2159 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2160 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2161 | MergeWithNamespace = FoundNS; |
| 2162 | ConflictingDecls.clear(); |
| 2163 | break; |
| 2164 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2165 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2166 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2167 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2168 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2169 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 2170 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2171 | ConflictingDecls.data(), |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2172 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2173 | if (!Name) |
| 2174 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2175 | } |
| 2176 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2177 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2178 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2179 | if (!BeginLocOrErr) |
| 2180 | return BeginLocOrErr.takeError(); |
| 2181 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2182 | // Create the "to" namespace, if needed. |
| 2183 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 2184 | if (!ToNamespace) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2185 | if (GetImportedOrCreateDecl( |
| 2186 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2187 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2188 | /*PrevDecl=*/nullptr)) |
| 2189 | return ToNamespace; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2190 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2191 | LexicalDC->addDeclInternal(ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2192 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2193 | // If this is an anonymous namespace, register it as the anonymous |
| 2194 | // namespace within its context. |
| 2195 | if (!Name) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2196 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2197 | TU->setAnonymousNamespace(ToNamespace); |
| 2198 | else |
| 2199 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 2200 | } |
| 2201 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2202 | Importer.MapImported(D, ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2203 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2204 | if (Error Err = ImportDeclContext(D)) |
| 2205 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2206 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2207 | return ToNamespace; |
| 2208 | } |
| 2209 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2210 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2211 | // Import the major distinguishing characteristics of this namespace. |
| 2212 | DeclContext *DC, *LexicalDC; |
| 2213 | DeclarationName Name; |
| 2214 | SourceLocation Loc; |
| 2215 | NamedDecl *LookupD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2216 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 2217 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2218 | if (LookupD) |
| 2219 | return LookupD; |
| 2220 | |
| 2221 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 2222 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2223 | SourceLocation ToNamespaceLoc, ToAliasLoc, ToTargetNameLoc; |
| 2224 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2225 | NamespaceDecl *ToNamespace; |
| 2226 | if (auto Imp = importSeq( |
| 2227 | D->getNamespaceLoc(), D->getAliasLoc(), D->getQualifierLoc(), |
| 2228 | D->getTargetNameLoc(), D->getNamespace())) |
| 2229 | std::tie( |
| 2230 | ToNamespaceLoc, ToAliasLoc, ToQualifierLoc, ToTargetNameLoc, |
| 2231 | ToNamespace) = *Imp; |
| 2232 | else |
| 2233 | return Imp.takeError(); |
| 2234 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2235 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2236 | NamespaceAliasDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2237 | if (GetImportedOrCreateDecl( |
| 2238 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, |
| 2239 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2240 | return ToD; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2241 | |
| 2242 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2243 | LexicalDC->addDeclInternal(ToD); |
| 2244 | |
| 2245 | return ToD; |
| 2246 | } |
| 2247 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2248 | ExpectedDecl |
| 2249 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2250 | // Import the major distinguishing characteristics of this typedef. |
| 2251 | DeclContext *DC, *LexicalDC; |
| 2252 | DeclarationName Name; |
| 2253 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2254 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2255 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2256 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2257 | if (ToD) |
| 2258 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2259 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2260 | // If this typedef is not in block scope, determine whether we've |
| 2261 | // seen a typedef with the same name (that we can merge with) or any |
| 2262 | // other entity by that name (which name lookup could conflict with). |
| 2263 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2264 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2265 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2266 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2267 | for (auto *FoundDecl : FoundDecls) { |
| 2268 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2269 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2270 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2271 | QualType FromUT = D->getUnderlyingType(); |
| 2272 | QualType FoundUT = FoundTypedef->getUnderlyingType(); |
| 2273 | if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) { |
| 2274 | // If the "From" context has a complete underlying type but we |
| 2275 | // already have a complete underlying type then return with that. |
| 2276 | if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2277 | return Importer.MapImported(D, FoundTypedef); |
Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2278 | } |
Gabor Marton | dd2b76e | 2019-06-11 13:35:25 +0000 | [diff] [blame] | 2279 | // FIXME Handle redecl chain. When you do that make consistent changes |
| 2280 | // in ASTImporterLookupTable too. |
Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2281 | break; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2282 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2283 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2284 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2285 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2286 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2287 | if (!ConflictingDecls.empty()) { |
| 2288 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2289 | ConflictingDecls.data(), |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2290 | ConflictingDecls.size()); |
| 2291 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2292 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2293 | } |
| 2294 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2295 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2296 | QualType ToUnderlyingType; |
| 2297 | TypeSourceInfo *ToTypeSourceInfo; |
| 2298 | SourceLocation ToBeginLoc; |
| 2299 | if (auto Imp = importSeq( |
| 2300 | D->getUnderlyingType(), D->getTypeSourceInfo(), D->getBeginLoc())) |
| 2301 | std::tie(ToUnderlyingType, ToTypeSourceInfo, ToBeginLoc) = *Imp; |
| 2302 | else |
| 2303 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2304 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2305 | // Create the new typedef node. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2306 | // FIXME: ToUnderlyingType is not used. |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2307 | TypedefNameDecl *ToTypedef; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2308 | if (IsAlias) { |
| 2309 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2310 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2311 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2312 | return ToTypedef; |
| 2313 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2314 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2315 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2316 | return ToTypedef; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2317 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2318 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2319 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2320 | |
| 2321 | // Templated declarations should not appear in DeclContext. |
| 2322 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 2323 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 2324 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2325 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2326 | return ToTypedef; |
| 2327 | } |
| 2328 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2329 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2330 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 2331 | } |
| 2332 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2333 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2334 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 2335 | } |
| 2336 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2337 | ExpectedDecl |
| 2338 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2339 | // Import the major distinguishing characteristics of this typedef. |
| 2340 | DeclContext *DC, *LexicalDC; |
| 2341 | DeclarationName Name; |
| 2342 | SourceLocation Loc; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2343 | NamedDecl *FoundD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2344 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
| 2345 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2346 | if (FoundD) |
| 2347 | return FoundD; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2348 | |
| 2349 | // If this typedef is not in block scope, determine whether we've |
| 2350 | // seen a typedef with the same name (that we can merge with) or any |
| 2351 | // other entity by that name (which name lookup could conflict with). |
| 2352 | if (!DC->isFunctionOrMethod()) { |
| 2353 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 2354 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2355 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2356 | for (auto *FoundDecl : FoundDecls) { |
| 2357 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2358 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2359 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2360 | return Importer.MapImported(D, FoundAlias); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2361 | ConflictingDecls.push_back(FoundDecl); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | if (!ConflictingDecls.empty()) { |
| 2365 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2366 | ConflictingDecls.data(), |
| 2367 | ConflictingDecls.size()); |
| 2368 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2369 | return make_error<ImportError>(ImportError::NameConflict); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2370 | } |
| 2371 | } |
| 2372 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2373 | TemplateParameterList *ToTemplateParameters; |
| 2374 | TypeAliasDecl *ToTemplatedDecl; |
| 2375 | if (auto Imp = importSeq(D->getTemplateParameters(), D->getTemplatedDecl())) |
| 2376 | std::tie(ToTemplateParameters, ToTemplatedDecl) = *Imp; |
| 2377 | else |
| 2378 | return Imp.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2379 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2380 | TypeAliasTemplateDecl *ToAlias; |
| 2381 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2382 | Name, ToTemplateParameters, ToTemplatedDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2383 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2384 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2385 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2386 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2387 | ToAlias->setAccess(D->getAccess()); |
| 2388 | ToAlias->setLexicalDeclContext(LexicalDC); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2389 | LexicalDC->addDeclInternal(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2390 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2391 | } |
| 2392 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2393 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2394 | // Import the major distinguishing characteristics of this label. |
| 2395 | DeclContext *DC, *LexicalDC; |
| 2396 | DeclarationName Name; |
| 2397 | SourceLocation Loc; |
| 2398 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2399 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2400 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2401 | if (ToD) |
| 2402 | return ToD; |
| 2403 | |
| 2404 | assert(LexicalDC->isFunctionOrMethod()); |
| 2405 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2406 | LabelDecl *ToLabel; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2407 | if (D->isGnuLocal()) { |
| 2408 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2409 | if (!BeginLocOrErr) |
| 2410 | return BeginLocOrErr.takeError(); |
| 2411 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2412 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) |
| 2413 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2414 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2415 | } else { |
| 2416 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2417 | Name.getAsIdentifierInfo())) |
| 2418 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2419 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); |
| 2423 | if (!ToStmtOrErr) |
| 2424 | return ToStmtOrErr.takeError(); |
| 2425 | |
| 2426 | ToLabel->setStmt(*ToStmtOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2427 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2428 | LexicalDC->addDeclInternal(ToLabel); |
| 2429 | return ToLabel; |
| 2430 | } |
| 2431 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2432 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2433 | // Import the major distinguishing characteristics of this enum. |
| 2434 | DeclContext *DC, *LexicalDC; |
| 2435 | DeclarationName Name; |
| 2436 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2437 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2438 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2439 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2440 | if (ToD) |
| 2441 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2442 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2443 | // Figure out what enum name we're looking for. |
| 2444 | unsigned IDNS = Decl::IDNS_Tag; |
| 2445 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2446 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2447 | if (Error Err = importInto( |
| 2448 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2449 | return std::move(Err); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2450 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2451 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2452 | IDNS |= Decl::IDNS_Ordinary; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2453 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2454 | // We may already have an enum of the same name; try to find and match it. |
| 2455 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2456 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2457 | auto FoundDecls = |
| 2458 | Importer.findDeclsInToCtx(DC, SearchName); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2459 | for (auto *FoundDecl : FoundDecls) { |
| 2460 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2461 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2462 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2463 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2464 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2465 | FoundDecl = Tag->getDecl(); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2466 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2467 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2468 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2469 | if (IsStructuralMatch(D, FoundEnum)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2470 | return Importer.MapImported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2471 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2472 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2473 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2474 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2475 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2476 | if (!ConflictingDecls.empty()) { |
Shafik Yaghmour | d426312 | 2019-04-08 20:50:21 +0000 | [diff] [blame] | 2477 | Name = Importer.HandleNameConflict(SearchName, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2478 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2479 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2480 | if (!Name) |
| 2481 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2482 | } |
| 2483 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2484 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2485 | SourceLocation ToBeginLoc; |
| 2486 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2487 | QualType ToIntegerType; |
| 2488 | if (auto Imp = importSeq( |
| 2489 | D->getBeginLoc(), D->getQualifierLoc(), D->getIntegerType())) |
| 2490 | std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType) = *Imp; |
| 2491 | else |
| 2492 | return Imp.takeError(); |
| 2493 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2494 | // Create the enum declaration. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2495 | EnumDecl *D2; |
| 2496 | if (GetImportedOrCreateDecl( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2497 | D2, D, Importer.getToContext(), DC, ToBeginLoc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2498 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), |
| 2499 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2500 | return D2; |
| 2501 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2502 | D2->setQualifierInfo(ToQualifierLoc); |
| 2503 | D2->setIntegerType(ToIntegerType); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2504 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2505 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2506 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2507 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2508 | // Import the definition |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2509 | if (D->isCompleteDefinition()) |
| 2510 | if (Error Err = ImportDefinition(D, D2)) |
| 2511 | return std::move(Err); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2512 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2513 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2514 | } |
| 2515 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2516 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2517 | bool IsFriendTemplate = false; |
| 2518 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2519 | IsFriendTemplate = |
| 2520 | DCXX->getDescribedClassTemplate() && |
| 2521 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != |
| 2522 | Decl::FOK_None; |
| 2523 | } |
| 2524 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2525 | // Import the major distinguishing characteristics of this record. |
| 2526 | DeclContext *DC, *LexicalDC; |
| 2527 | DeclarationName Name; |
| 2528 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2529 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2530 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2531 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2532 | if (ToD) |
| 2533 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2534 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2535 | // Figure out what structure name we're looking for. |
| 2536 | unsigned IDNS = Decl::IDNS_Tag; |
| 2537 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2538 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2539 | if (Error Err = importInto( |
| 2540 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2541 | return std::move(Err); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2542 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2543 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2544 | IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2545 | |
| 2546 | // 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] | 2547 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2548 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2549 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2550 | auto FoundDecls = |
| 2551 | Importer.findDeclsInToCtx(DC, SearchName); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2552 | if (!FoundDecls.empty()) { |
Gabor Marton | 41e3892 | 2019-03-05 11:23:24 +0000 | [diff] [blame] | 2553 | // We're going to have to compare D against potentially conflicting Decls, |
| 2554 | // so complete it. |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2555 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2556 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2557 | } |
| 2558 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2559 | for (auto *FoundDecl : FoundDecls) { |
| 2560 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2561 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2562 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2563 | Decl *Found = FoundDecl; |
| 2564 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2565 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2566 | Found = Tag->getDecl(); |
| 2567 | } |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2568 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2569 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2570 | // Do not emit false positive diagnostic in case of unnamed |
| 2571 | // struct/union and in case of anonymous structs. Would be false |
| 2572 | // because there may be several anonymous/unnamed structs in a class. |
| 2573 | // E.g. these are both valid: |
| 2574 | // struct A { // unnamed structs |
| 2575 | // struct { struct A *next; } entry0; |
| 2576 | // struct { struct A *next; } entry1; |
| 2577 | // }; |
| 2578 | // struct X { struct { int a; }; struct { int b; }; }; // anon structs |
| 2579 | if (!SearchName) |
Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2580 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2581 | continue; |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2582 | |
Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 2583 | if (!hasSameVisibilityContext(FoundRecord, D)) |
| 2584 | continue; |
| 2585 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2586 | if (IsStructuralMatch(D, FoundRecord)) { |
| 2587 | RecordDecl *FoundDef = FoundRecord->getDefinition(); |
| 2588 | if (D->isThisDeclarationADefinition() && FoundDef) { |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2589 | // FIXME: Structural equivalence check should check for same |
| 2590 | // user-defined methods. |
| 2591 | Importer.MapImported(D, FoundDef); |
| 2592 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2593 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); |
| 2594 | assert(FoundCXX && "Record type mismatch"); |
| 2595 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2596 | if (!Importer.isMinimalImport()) |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2597 | // FoundDef may not have every implicit method that D has |
| 2598 | // because implicit methods are created only if they are used. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2599 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) |
| 2600 | return std::move(Err); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2601 | } |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2602 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2603 | PrevDecl = FoundRecord->getMostRecentDecl(); |
| 2604 | break; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2605 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2606 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2607 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2608 | ConflictingDecls.push_back(FoundDecl); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2609 | } // for |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2610 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2611 | if (!ConflictingDecls.empty() && SearchName) { |
Shafik Yaghmour | 468724e | 2019-05-24 16:53:44 +0000 | [diff] [blame] | 2612 | Name = Importer.HandleNameConflict(SearchName, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2613 | ConflictingDecls.data(), |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2614 | ConflictingDecls.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2615 | if (!Name) |
| 2616 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2617 | } |
| 2618 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2619 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2620 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2621 | if (!BeginLocOrErr) |
| 2622 | return BeginLocOrErr.takeError(); |
| 2623 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2624 | // Create the record declaration. |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2625 | RecordDecl *D2 = nullptr; |
| 2626 | CXXRecordDecl *D2CXX = nullptr; |
| 2627 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2628 | if (DCXX->isLambda()) { |
| 2629 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); |
| 2630 | if (!TInfoOrErr) |
| 2631 | return TInfoOrErr.takeError(); |
| 2632 | if (GetImportedOrCreateSpecialDecl( |
| 2633 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
| 2634 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), |
| 2635 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2636 | return D2CXX; |
| 2637 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); |
| 2638 | if (!CDeclOrErr) |
| 2639 | return CDeclOrErr.takeError(); |
| 2640 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr); |
| 2641 | } else if (DCXX->isInjectedClassName()) { |
| 2642 | // We have to be careful to do a similar dance to the one in |
| 2643 | // Sema::ActOnStartCXXMemberDeclarations |
| 2644 | const bool DelayTypeCreation = true; |
| 2645 | if (GetImportedOrCreateDecl( |
| 2646 | D2CXX, D, Importer.getToContext(), D->getTagKind(), DC, |
| 2647 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
| 2648 | cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation)) |
| 2649 | return D2CXX; |
| 2650 | Importer.getToContext().getTypeDeclType( |
| 2651 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
| 2652 | } else { |
| 2653 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2654 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2655 | Name.getAsIdentifierInfo(), |
| 2656 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2657 | return D2CXX; |
| 2658 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2659 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2660 | D2 = D2CXX; |
| 2661 | D2->setAccess(D->getAccess()); |
| 2662 | D2->setLexicalDeclContext(LexicalDC); |
| 2663 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) |
| 2664 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2665 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2666 | if (LexicalDC != DC && D->isInIdentifierNamespace(Decl::IDNS_TagFriend)) |
| 2667 | DC->makeDeclVisibleInContext(D2); |
| 2668 | |
| 2669 | if (ClassTemplateDecl *FromDescribed = |
| 2670 | DCXX->getDescribedClassTemplate()) { |
| 2671 | ClassTemplateDecl *ToDescribed; |
| 2672 | if (Error Err = importInto(ToDescribed, FromDescribed)) |
| 2673 | return std::move(Err); |
| 2674 | D2CXX->setDescribedClassTemplate(ToDescribed); |
| 2675 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { |
| 2676 | // In a record describing a template the type should be an |
| 2677 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2678 | // previously set type to the correct value here (ToDescribed is not |
| 2679 | // available at record create). |
| 2680 | // FIXME: The previous type is cleared but not removed from |
| 2681 | // ASTContext's internal storage. |
| 2682 | CXXRecordDecl *Injected = nullptr; |
| 2683 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2684 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2685 | if (Record && Record->isInjectedClassName()) { |
| 2686 | Injected = Record; |
| 2687 | break; |
Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2688 | } |
| 2689 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2690 | // Create an injected type for the whole redecl chain. |
| 2691 | SmallVector<Decl *, 2> Redecls = |
| 2692 | getCanonicalForwardRedeclChain(D2CXX); |
| 2693 | for (auto *R : Redecls) { |
| 2694 | auto *RI = cast<CXXRecordDecl>(R); |
| 2695 | RI->setTypeForDecl(nullptr); |
| 2696 | // Below we create a new injected type and assign that to the |
| 2697 | // canonical decl, subsequent declarations in the chain will reuse |
| 2698 | // that type. |
| 2699 | Importer.getToContext().getInjectedClassNameType( |
| 2700 | RI, ToDescribed->getInjectedClassNameSpecialization()); |
| 2701 | } |
| 2702 | // Set the new type for the previous injected decl too. |
| 2703 | if (Injected) { |
| 2704 | Injected->setTypeForDecl(nullptr); |
| 2705 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2706 | } |
| 2707 | } |
| 2708 | } else if (MemberSpecializationInfo *MemberInfo = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2709 | DCXX->getMemberSpecializationInfo()) { |
| 2710 | TemplateSpecializationKind SK = |
| 2711 | MemberInfo->getTemplateSpecializationKind(); |
| 2712 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2713 | |
| 2714 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) |
| 2715 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); |
| 2716 | else |
| 2717 | return ToInstOrErr.takeError(); |
| 2718 | |
| 2719 | if (ExpectedSLoc POIOrErr = |
| 2720 | import(MemberInfo->getPointOfInstantiation())) |
| 2721 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2722 | *POIOrErr); |
| 2723 | else |
| 2724 | return POIOrErr.takeError(); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2725 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2726 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2727 | } else { |
| 2728 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
| 2729 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2730 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2731 | return D2; |
| 2732 | D2->setLexicalDeclContext(LexicalDC); |
| 2733 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2734 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2735 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2736 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) |
| 2737 | D2->setQualifierInfo(*QualifierLocOrErr); |
| 2738 | else |
| 2739 | return QualifierLocOrErr.takeError(); |
| 2740 | |
| 2741 | if (D->isAnonymousStructOrUnion()) |
| 2742 | D2->setAnonymousStructOrUnion(true); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2743 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2744 | if (D->isCompleteDefinition()) |
| 2745 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) |
| 2746 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2747 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2748 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2749 | } |
| 2750 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2751 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2752 | // Import the major distinguishing characteristics of this enumerator. |
| 2753 | DeclContext *DC, *LexicalDC; |
| 2754 | DeclarationName Name; |
| 2755 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2756 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2757 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2758 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2759 | if (ToD) |
| 2760 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2761 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2762 | // Determine whether there are any other declarations with the same name and |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2763 | // in the same context. |
| 2764 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2765 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2766 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2767 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2768 | for (auto *FoundDecl : FoundDecls) { |
| 2769 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2770 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2771 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2772 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2773 | if (IsStructuralMatch(D, FoundEnumConstant)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2774 | return Importer.MapImported(D, FoundEnumConstant); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2775 | } |
| 2776 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2777 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2778 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2779 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2780 | if (!ConflictingDecls.empty()) { |
| 2781 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2782 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2783 | ConflictingDecls.size()); |
| 2784 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2785 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2786 | } |
| 2787 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2788 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2789 | ExpectedType TypeOrErr = import(D->getType()); |
| 2790 | if (!TypeOrErr) |
| 2791 | return TypeOrErr.takeError(); |
| 2792 | |
| 2793 | ExpectedExpr InitOrErr = import(D->getInitExpr()); |
| 2794 | if (!InitOrErr) |
| 2795 | return InitOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2796 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2797 | EnumConstantDecl *ToEnumerator; |
| 2798 | if (GetImportedOrCreateDecl( |
| 2799 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2800 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2801 | return ToEnumerator; |
| 2802 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2803 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2804 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2805 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2806 | return ToEnumerator; |
| 2807 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2808 | |
Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 2809 | Error ASTNodeImporter::ImportTemplateParameterLists(const DeclaratorDecl *FromD, |
| 2810 | DeclaratorDecl *ToD) { |
| 2811 | unsigned int Num = FromD->getNumTemplateParameterLists(); |
| 2812 | if (Num == 0) |
| 2813 | return Error::success(); |
| 2814 | SmallVector<TemplateParameterList *, 2> ToTPLists(Num); |
| 2815 | for (unsigned int I = 0; I < Num; ++I) |
| 2816 | if (Expected<TemplateParameterList *> ToTPListOrErr = |
| 2817 | import(FromD->getTemplateParameterList(I))) |
| 2818 | ToTPLists[I] = *ToTPListOrErr; |
| 2819 | else |
| 2820 | return ToTPListOrErr.takeError(); |
| 2821 | ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists); |
| 2822 | return Error::success(); |
| 2823 | } |
| 2824 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2825 | Error ASTNodeImporter::ImportTemplateInformation( |
| 2826 | FunctionDecl *FromFD, FunctionDecl *ToFD) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2827 | switch (FromFD->getTemplatedKind()) { |
| 2828 | case FunctionDecl::TK_NonTemplate: |
| 2829 | case FunctionDecl::TK_FunctionTemplate: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2830 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2831 | |
| 2832 | case FunctionDecl::TK_MemberSpecialization: { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2833 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2834 | |
| 2835 | if (Expected<FunctionDecl *> InstFDOrErr = |
| 2836 | import(FromFD->getInstantiatedFromMemberFunction())) |
| 2837 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); |
| 2838 | else |
| 2839 | return InstFDOrErr.takeError(); |
| 2840 | |
| 2841 | if (ExpectedSLoc POIOrErr = import( |
| 2842 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) |
| 2843 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); |
| 2844 | else |
| 2845 | return POIOrErr.takeError(); |
| 2846 | |
| 2847 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2851 | auto FunctionAndArgsOrErr = |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2852 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2853 | if (!FunctionAndArgsOrErr) |
| 2854 | return FunctionAndArgsOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2855 | |
| 2856 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2857 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2858 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2859 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2860 | TemplateArgumentListInfo ToTAInfo; |
| 2861 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2862 | if (FromTAArgsAsWritten) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2863 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2864 | *FromTAArgsAsWritten, ToTAInfo)) |
| 2865 | return Err; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2866 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2867 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); |
| 2868 | if (!POIOrErr) |
| 2869 | return POIOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2870 | |
Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 2871 | if (Error Err = ImportTemplateParameterLists(FromFD, ToFD)) |
| 2872 | return Err; |
| 2873 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2874 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2875 | ToFD->setFunctionTemplateSpecialization( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2876 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, |
| 2877 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); |
| 2878 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2879 | } |
| 2880 | |
| 2881 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 2882 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 2883 | UnresolvedSet<8> TemplDecls; |
| 2884 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 2885 | for (unsigned I = 0; I < NumTemplates; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2886 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = |
| 2887 | import(FromInfo->getTemplate(I))) |
| 2888 | TemplDecls.addDecl(*ToFTDOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2889 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2890 | return ToFTDOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2891 | } |
| 2892 | |
| 2893 | // Import TemplateArgumentListInfo. |
| 2894 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2895 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2896 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 2897 | llvm::makeArrayRef( |
| 2898 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), |
| 2899 | ToTAInfo)) |
| 2900 | return Err; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2901 | |
| 2902 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 2903 | TemplDecls, ToTAInfo); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2904 | return Error::success(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2905 | } |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2906 | } |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2907 | llvm_unreachable("All cases should be covered!"); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2908 | } |
| 2909 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2910 | Expected<FunctionDecl *> |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2911 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2912 | auto FunctionAndArgsOrErr = |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2913 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2914 | if (!FunctionAndArgsOrErr) |
| 2915 | return FunctionAndArgsOrErr.takeError(); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2916 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2917 | FunctionTemplateDecl *Template; |
| 2918 | TemplateArgsTy ToTemplArgs; |
| 2919 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2920 | void *InsertPos = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2921 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2922 | return FoundSpec; |
| 2923 | } |
| 2924 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 2925 | Error ASTNodeImporter::ImportFunctionDeclBody(FunctionDecl *FromFD, |
| 2926 | FunctionDecl *ToFD) { |
| 2927 | if (Stmt *FromBody = FromFD->getBody()) { |
| 2928 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) |
| 2929 | ToFD->setBody(*ToBodyOrErr); |
| 2930 | else |
| 2931 | return ToBodyOrErr.takeError(); |
| 2932 | } |
| 2933 | return Error::success(); |
| 2934 | } |
| 2935 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2936 | template <typename T> |
| 2937 | bool ASTNodeImporter::hasSameVisibilityContext(T *Found, T *From) { |
| 2938 | if (From->hasExternalFormalLinkage()) |
| 2939 | return Found->hasExternalFormalLinkage(); |
| 2940 | if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl()) |
| 2941 | return false; |
| 2942 | if (From->isInAnonymousNamespace()) |
| 2943 | return Found->isInAnonymousNamespace(); |
| 2944 | else |
| 2945 | return !Found->isInAnonymousNamespace() && |
| 2946 | !Found->hasExternalFormalLinkage(); |
| 2947 | } |
| 2948 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2949 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2950 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2951 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2952 | auto RedeclIt = Redecls.begin(); |
| 2953 | // Import the first part of the decl chain. I.e. import all previous |
| 2954 | // declarations starting from the canonical decl. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2955 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 2956 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 2957 | if (!ToRedeclOrErr) |
| 2958 | return ToRedeclOrErr.takeError(); |
| 2959 | } |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2960 | assert(*RedeclIt == D); |
| 2961 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2962 | // Import the major distinguishing characteristics of this function. |
| 2963 | DeclContext *DC, *LexicalDC; |
| 2964 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2965 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2966 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2967 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2968 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2969 | if (ToD) |
| 2970 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2971 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 2972 | FunctionDecl *FoundByLookup = nullptr; |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 2973 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2974 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2975 | // 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] | 2976 | // existing specialization in the "to" context. The lookup below will not |
| 2977 | // find any specialization, but would find the primary template; thus, we |
| 2978 | // have to skip normal lookup in case of specializations. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2979 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 2980 | if (D->getTemplatedKind() == |
| 2981 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2982 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); |
| 2983 | if (!FoundFunctionOrErr) |
| 2984 | return FoundFunctionOrErr.takeError(); |
| 2985 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { |
Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 2986 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 2987 | return Def; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2988 | FoundByLookup = FoundFunction; |
| 2989 | } |
| 2990 | } |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2991 | // Try to find a function in our own ("to") context with the same name, same |
| 2992 | // type, and in the same context as the function we're importing. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2993 | else if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2994 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2995 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2996 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2997 | for (auto *FoundDecl : FoundDecls) { |
| 2998 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2999 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3000 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3001 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3002 | if (!hasSameVisibilityContext(FoundFunction, D)) |
| 3003 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3004 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3005 | if (IsStructuralMatch(D, FoundFunction)) { |
Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 3006 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 3007 | return Def; |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3008 | FoundByLookup = FoundFunction; |
| 3009 | break; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3010 | } |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3011 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 3012 | // Sema::IsOverload out to the AST library. |
| 3013 | |
| 3014 | // Function overloading is okay in C++. |
| 3015 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
| 3016 | continue; |
| 3017 | |
| 3018 | // Complain about inconsistent function types. |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3019 | Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent) |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3020 | << Name << D->getType() << FoundFunction->getType(); |
| 3021 | Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here) |
| 3022 | << FoundFunction->getType(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3023 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3024 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3025 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3026 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3027 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3028 | if (!ConflictingDecls.empty()) { |
| 3029 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3030 | ConflictingDecls.data(), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3031 | ConflictingDecls.size()); |
| 3032 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3033 | return make_error<ImportError>(ImportError::NameConflict); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3034 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3035 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3036 | |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3037 | // We do not allow more than one in-class declaration of a function. This is |
| 3038 | // because AST clients like VTableBuilder asserts on this. VTableBuilder |
| 3039 | // assumes there is only one in-class declaration. Building a redecl |
| 3040 | // chain would result in more than one in-class declaration for |
| 3041 | // overrides (even if they are part of the same redecl chain inside the |
| 3042 | // derived class.) |
| 3043 | if (FoundByLookup) { |
Mikael Holmen | c1c97aa | 2019-01-29 06:53:31 +0000 | [diff] [blame] | 3044 | if (isa<CXXMethodDecl>(FoundByLookup)) { |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3045 | if (D->getLexicalDeclContext() == D->getDeclContext()) { |
| 3046 | if (!D->doesThisDeclarationHaveABody()) |
| 3047 | return Importer.MapImported(D, FoundByLookup); |
| 3048 | else { |
| 3049 | // Let's continue and build up the redecl chain in this case. |
| 3050 | // FIXME Merge the functions into one decl. |
| 3051 | } |
| 3052 | } |
| 3053 | } |
| 3054 | } |
| 3055 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3056 | DeclarationNameInfo NameInfo(Name, Loc); |
| 3057 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3058 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 3059 | return std::move(Err); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3060 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3061 | QualType FromTy = D->getType(); |
| 3062 | bool usedDifferentExceptionSpec = false; |
| 3063 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3064 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3065 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 3066 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 3067 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 3068 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 3069 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 3070 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 3071 | FromEPI.ExceptionSpec.SourceTemplate || |
| 3072 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3073 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 3074 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3075 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3076 | usedDifferentExceptionSpec = true; |
| 3077 | } |
| 3078 | } |
| 3079 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3080 | QualType T; |
| 3081 | TypeSourceInfo *TInfo; |
| 3082 | SourceLocation ToInnerLocStart, ToEndLoc; |
| 3083 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3084 | if (auto Imp = importSeq( |
| 3085 | FromTy, D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3086 | D->getQualifierLoc(), D->getEndLoc())) |
| 3087 | std::tie(T, TInfo, ToInnerLocStart, ToQualifierLoc, ToEndLoc) = *Imp; |
| 3088 | else |
| 3089 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3090 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3091 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3092 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3093 | for (auto P : D->parameters()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3094 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) |
| 3095 | Parameters.push_back(*ToPOrErr); |
| 3096 | else |
| 3097 | return ToPOrErr.takeError(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3098 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3099 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3100 | // Create the imported function. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3101 | FunctionDecl *ToFunction = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3102 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3103 | Expr *ExplicitExpr = nullptr; |
| 3104 | if (FromConstructor->getExplicitSpecifier().getExpr()) { |
| 3105 | auto Imp = importSeq(FromConstructor->getExplicitSpecifier().getExpr()); |
| 3106 | if (!Imp) |
| 3107 | return Imp.takeError(); |
| 3108 | std::tie(ExplicitExpr) = *Imp; |
| 3109 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3110 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3111 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3112 | ToInnerLocStart, NameInfo, T, TInfo, |
| 3113 | ExplicitSpecifier( |
| 3114 | ExplicitExpr, |
| 3115 | FromConstructor->getExplicitSpecifier().getKind()), |
Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3116 | D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3117 | return ToFunction; |
Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3118 | } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { |
| 3119 | |
| 3120 | auto Imp = |
| 3121 | importSeq(const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()), |
| 3122 | FromDtor->getOperatorDeleteThisArg()); |
| 3123 | |
| 3124 | if (!Imp) |
| 3125 | return Imp.takeError(); |
| 3126 | |
| 3127 | FunctionDecl *ToOperatorDelete; |
| 3128 | Expr *ToThisArg; |
| 3129 | std::tie(ToOperatorDelete, ToThisArg) = *Imp; |
| 3130 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3131 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3132 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3133 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 3134 | D->isImplicit())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3135 | return ToFunction; |
Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3136 | |
| 3137 | CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction); |
| 3138 | |
| 3139 | ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3140 | } else if (CXXConversionDecl *FromConversion = |
| 3141 | dyn_cast<CXXConversionDecl>(D)) { |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3142 | Expr *ExplicitExpr = nullptr; |
| 3143 | if (FromConversion->getExplicitSpecifier().getExpr()) { |
| 3144 | auto Imp = importSeq(FromConversion->getExplicitSpecifier().getExpr()); |
| 3145 | if (!Imp) |
| 3146 | return Imp.takeError(); |
| 3147 | std::tie(ExplicitExpr) = *Imp; |
| 3148 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3149 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 3150 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3151 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3152 | ExplicitSpecifier(ExplicitExpr, |
| 3153 | FromConversion->getExplicitSpecifier().getKind()), |
Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3154 | D->getConstexprKind(), SourceLocation())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3155 | return ToFunction; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3156 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3157 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 3158 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3159 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3160 | Method->isInlineSpecified(), D->getConstexprKind(), |
| 3161 | SourceLocation())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3162 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3163 | } else { |
Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3164 | if (GetImportedOrCreateDecl( |
| 3165 | ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, |
| 3166 | NameInfo, T, TInfo, D->getStorageClass(), D->isInlineSpecified(), |
| 3167 | D->hasWrittenPrototype(), D->getConstexprKind())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3168 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3169 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3170 | |
Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3171 | // Connect the redecl chain. |
| 3172 | if (FoundByLookup) { |
| 3173 | auto *Recent = const_cast<FunctionDecl *>( |
| 3174 | FoundByLookup->getMostRecentDecl()); |
| 3175 | ToFunction->setPreviousDecl(Recent); |
Gabor Marton | ce6b781 | 2019-05-08 15:23:48 +0000 | [diff] [blame] | 3176 | // FIXME Probably we should merge exception specifications. E.g. In the |
| 3177 | // "To" context the existing function may have exception specification with |
| 3178 | // noexcept-unevaluated, while the newly imported function may have an |
| 3179 | // evaluated noexcept. A call to adjustExceptionSpec() on the imported |
| 3180 | // decl and its redeclarations may be required. |
Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3181 | } |
| 3182 | |
| 3183 | // Import Ctor initializers. |
| 3184 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 3185 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 3186 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); |
| 3187 | // Import first, then allocate memory and copy if there was no error. |
| 3188 | if (Error Err = ImportContainerChecked( |
| 3189 | FromConstructor->inits(), CtorInitializers)) |
| 3190 | return std::move(Err); |
| 3191 | auto **Memory = |
| 3192 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 3193 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
| 3194 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
| 3195 | ToCtor->setCtorInitializers(Memory); |
| 3196 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 3197 | } |
| 3198 | } |
| 3199 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3200 | ToFunction->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3201 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3202 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 3203 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 3204 | ToFunction->setTrivial(D->isTrivial()); |
| 3205 | ToFunction->setPure(D->isPure()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3206 | ToFunction->setRangeEnd(ToEndLoc); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3207 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3208 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3209 | for (auto *Param : Parameters) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3210 | Param->setOwningFunction(ToFunction); |
| 3211 | ToFunction->addDeclInternal(Param); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3212 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 3213 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3214 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3215 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 3216 | // params it refers to. |
| 3217 | if (TInfo) { |
| 3218 | if (auto ProtoLoc = |
| 3219 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 3220 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 3221 | ProtoLoc.setParam(I, Parameters[I]); |
| 3222 | } |
| 3223 | } |
| 3224 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3225 | if (usedDifferentExceptionSpec) { |
| 3226 | // Update FunctionProtoType::ExtProtoInfo. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3227 | if (ExpectedType TyOrErr = import(D->getType())) |
| 3228 | ToFunction->setType(*TyOrErr); |
| 3229 | else |
| 3230 | return TyOrErr.takeError(); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 3231 | } |
| 3232 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3233 | // Import the describing template function, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3234 | if (FromFT) { |
| 3235 | auto ToFTOrErr = import(FromFT); |
| 3236 | if (!ToFTOrErr) |
| 3237 | return ToFTOrErr.takeError(); |
| 3238 | } |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3239 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3240 | if (D->doesThisDeclarationHaveABody()) { |
Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3241 | Error Err = ImportFunctionDeclBody(D, ToFunction); |
| 3242 | |
| 3243 | if (Err) |
| 3244 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3245 | } |
| 3246 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3247 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3248 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3249 | // If it is a template, import all related things. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3250 | if (Error Err = ImportTemplateInformation(D, ToFunction)) |
| 3251 | return std::move(Err); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3252 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3253 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); |
| 3254 | |
| 3255 | // TODO Can we generalize this approach to other AST nodes as well? |
| 3256 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3257 | DC->addDeclInternal(ToFunction); |
| 3258 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3259 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3260 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3261 | // Friend declaration's lexical context is the befriending class, but the |
| 3262 | // semantic context is the enclosing scope of the befriending class. |
| 3263 | // We want the friend functions to be found in the semantic context by lookup. |
| 3264 | // FIXME should we handle this generically in VisitFriendDecl? |
| 3265 | // In Other cases when LexicalDC != DC we don't want it to be added, |
| 3266 | // e.g out-of-class definitions like void B::f() {} . |
| 3267 | if (LexicalDC != DC && IsFriend) { |
| 3268 | DC->makeDeclVisibleInContext(ToFunction); |
| 3269 | } |
| 3270 | |
Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3271 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 3272 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 3273 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3274 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3275 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3276 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3277 | if (!ToRedeclOrErr) |
| 3278 | return ToRedeclOrErr.takeError(); |
| 3279 | } |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3280 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3281 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3282 | } |
| 3283 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3284 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3285 | return VisitFunctionDecl(D); |
| 3286 | } |
| 3287 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3288 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3289 | return VisitCXXMethodDecl(D); |
| 3290 | } |
| 3291 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3292 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3293 | return VisitCXXMethodDecl(D); |
| 3294 | } |
| 3295 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3296 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3297 | return VisitCXXMethodDecl(D); |
| 3298 | } |
| 3299 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3300 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3301 | // Import the major distinguishing characteristics of a variable. |
| 3302 | DeclContext *DC, *LexicalDC; |
| 3303 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3304 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3305 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3306 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3307 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3308 | if (ToD) |
| 3309 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3310 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3311 | // Determine whether we've already imported this field. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3312 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3313 | for (auto *FoundDecl : FoundDecls) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3314 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3315 | // For anonymous fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3316 | if (!Name && |
| 3317 | ASTImporter::getFieldIndex(D) != |
| 3318 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3319 | continue; |
| 3320 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3321 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3322 | FoundField->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3323 | Importer.MapImported(D, FoundField); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3324 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the |
| 3325 | // initializer of a FieldDecl might not had been instantiated in the |
| 3326 | // "To" context. However, the "From" context might instantiated that, |
| 3327 | // thus we have to merge that. |
| 3328 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
| 3329 | // We don't have yet the initializer set. |
| 3330 | if (FoundField->hasInClassInitializer() && |
| 3331 | !FoundField->getInClassInitializer()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3332 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) |
| 3333 | FoundField->setInClassInitializer(*ToInitializerOrErr); |
| 3334 | else { |
| 3335 | // We can't return error here, |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3336 | // since we already mapped D as imported. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3337 | // FIXME: warning message? |
| 3338 | consumeError(ToInitializerOrErr.takeError()); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3339 | return FoundField; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3340 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3341 | } |
| 3342 | } |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3343 | return FoundField; |
| 3344 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3345 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3346 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3347 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3348 | << Name << D->getType() << FoundField->getType(); |
| 3349 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3350 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3351 | |
| 3352 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3353 | } |
| 3354 | } |
| 3355 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3356 | QualType ToType; |
| 3357 | TypeSourceInfo *ToTInfo; |
| 3358 | Expr *ToBitWidth; |
| 3359 | SourceLocation ToInnerLocStart; |
| 3360 | Expr *ToInitializer; |
| 3361 | if (auto Imp = importSeq( |
| 3362 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), |
| 3363 | D->getInnerLocStart(), D->getInClassInitializer())) |
| 3364 | std::tie( |
| 3365 | ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp; |
| 3366 | else |
| 3367 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3368 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3369 | FieldDecl *ToField; |
| 3370 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3371 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3372 | ToType, ToTInfo, ToBitWidth, D->isMutable(), |
| 3373 | D->getInClassInitStyle())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3374 | return ToField; |
| 3375 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3376 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3377 | ToField->setLexicalDeclContext(LexicalDC); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3378 | if (ToInitializer) |
| 3379 | ToField->setInClassInitializer(ToInitializer); |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3380 | ToField->setImplicit(D->isImplicit()); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3381 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3382 | return ToField; |
| 3383 | } |
| 3384 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3385 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3386 | // Import the major distinguishing characteristics of a variable. |
| 3387 | DeclContext *DC, *LexicalDC; |
| 3388 | DeclarationName Name; |
| 3389 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3390 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3391 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3392 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3393 | if (ToD) |
| 3394 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3395 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3396 | // Determine whether we've already imported this field. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3397 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3398 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3399 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3400 | // For anonymous indirect fields, match up by index. |
Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3401 | if (!Name && |
| 3402 | ASTImporter::getFieldIndex(D) != |
| 3403 | ASTImporter::getFieldIndex(FoundField)) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3404 | continue; |
| 3405 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3406 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3407 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 3408 | !Name.isEmpty())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3409 | Importer.MapImported(D, FoundField); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3410 | return FoundField; |
| 3411 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3412 | |
| 3413 | // If there are more anonymous fields to check, continue. |
| 3414 | if (!Name && I < N-1) |
| 3415 | continue; |
| 3416 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3417 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3418 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3419 | << Name << D->getType() << FoundField->getType(); |
| 3420 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3421 | << FoundField->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3422 | |
| 3423 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3424 | } |
| 3425 | } |
| 3426 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3427 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3428 | auto TypeOrErr = import(D->getType()); |
| 3429 | if (!TypeOrErr) |
| 3430 | return TypeOrErr.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3431 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3432 | auto **NamedChain = |
| 3433 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3434 | |
| 3435 | unsigned i = 0; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3436 | for (auto *PI : D->chain()) |
| 3437 | if (Expected<NamedDecl *> ToD = import(PI)) |
| 3438 | NamedChain[i++] = *ToD; |
| 3439 | else |
| 3440 | return ToD.takeError(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3441 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3442 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 3443 | IndirectFieldDecl *ToIndirectField; |
| 3444 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3445 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3446 | // FIXME here we leak `NamedChain` which is allocated before |
| 3447 | return ToIndirectField; |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3448 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3449 | ToIndirectField->setAccess(D->getAccess()); |
| 3450 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3451 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3452 | return ToIndirectField; |
| 3453 | } |
| 3454 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3455 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3456 | // Import the major distinguishing characteristics of a declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3457 | DeclContext *DC, *LexicalDC; |
| 3458 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 3459 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3460 | |
| 3461 | // Determine whether we've already imported this decl. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3462 | // FriendDecl is not a NamedDecl so we cannot use lookup. |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3463 | auto *RD = cast<CXXRecordDecl>(DC); |
| 3464 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3465 | |
| 3466 | while (ImportedFriend) { |
| 3467 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3468 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 3469 | /*Complain=*/false)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3470 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3471 | |
| 3472 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 3473 | if (Importer.IsStructurallyEquivalent( |
| 3474 | D->getFriendType()->getType(), |
| 3475 | ImportedFriend->getFriendType()->getType(), true)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3476 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3477 | } |
| 3478 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3479 | } |
| 3480 | |
| 3481 | // Not found. Create it. |
| 3482 | FriendDecl::FriendUnion ToFU; |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3483 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3484 | NamedDecl *ToFriendD; |
| 3485 | if (Error Err = importInto(ToFriendD, FriendD)) |
| 3486 | return std::move(Err); |
| 3487 | |
| 3488 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3489 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3490 | ToFriendD->setObjectOfFriendDecl(false); |
| 3491 | |
| 3492 | ToFU = ToFriendD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3493 | } else { // The friend is a type, not a decl. |
| 3494 | if (auto TSIOrErr = import(D->getFriendType())) |
| 3495 | ToFU = *TSIOrErr; |
| 3496 | else |
| 3497 | return TSIOrErr.takeError(); |
| 3498 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3499 | |
| 3500 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3501 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3502 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 3503 | if (auto ListOrErr = import(FromTPLists[I])) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3504 | ToTPLists[I] = *ListOrErr; |
| 3505 | else |
| 3506 | return ListOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3507 | } |
| 3508 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3509 | auto LocationOrErr = import(D->getLocation()); |
| 3510 | if (!LocationOrErr) |
| 3511 | return LocationOrErr.takeError(); |
| 3512 | auto FriendLocOrErr = import(D->getFriendLoc()); |
| 3513 | if (!FriendLocOrErr) |
| 3514 | return FriendLocOrErr.takeError(); |
| 3515 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3516 | FriendDecl *FrD; |
| 3517 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3518 | *LocationOrErr, ToFU, |
| 3519 | *FriendLocOrErr, ToTPLists)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3520 | return FrD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3521 | |
| 3522 | FrD->setAccess(D->getAccess()); |
| 3523 | FrD->setLexicalDeclContext(LexicalDC); |
| 3524 | LexicalDC->addDeclInternal(FrD); |
| 3525 | return FrD; |
| 3526 | } |
| 3527 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3528 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3529 | // Import the major distinguishing characteristics of an ivar. |
| 3530 | DeclContext *DC, *LexicalDC; |
| 3531 | DeclarationName Name; |
| 3532 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3533 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3534 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3535 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3536 | if (ToD) |
| 3537 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3538 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3539 | // Determine whether we've already imported this ivar |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3540 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3541 | for (auto *FoundDecl : FoundDecls) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3542 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3543 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3544 | FoundIvar->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3545 | Importer.MapImported(D, FoundIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3546 | return FoundIvar; |
| 3547 | } |
| 3548 | |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3549 | Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent) |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3550 | << Name << D->getType() << FoundIvar->getType(); |
| 3551 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3552 | << FoundIvar->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3553 | |
| 3554 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3555 | } |
| 3556 | } |
| 3557 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3558 | QualType ToType; |
| 3559 | TypeSourceInfo *ToTypeSourceInfo; |
| 3560 | Expr *ToBitWidth; |
| 3561 | SourceLocation ToInnerLocStart; |
| 3562 | if (auto Imp = importSeq( |
| 3563 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), D->getInnerLocStart())) |
| 3564 | std::tie(ToType, ToTypeSourceInfo, ToBitWidth, ToInnerLocStart) = *Imp; |
| 3565 | else |
| 3566 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3567 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3568 | ObjCIvarDecl *ToIvar; |
| 3569 | if (GetImportedOrCreateDecl( |
| 3570 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3571 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3572 | ToType, ToTypeSourceInfo, |
| 3573 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3574 | return ToIvar; |
| 3575 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3576 | ToIvar->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3577 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3578 | return ToIvar; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3579 | } |
| 3580 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3581 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3582 | |
| 3583 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 3584 | auto RedeclIt = Redecls.begin(); |
| 3585 | // Import the first part of the decl chain. I.e. import all previous |
| 3586 | // declarations starting from the canonical decl. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3587 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3588 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3589 | if (!RedeclOrErr) |
| 3590 | return RedeclOrErr.takeError(); |
| 3591 | } |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3592 | assert(*RedeclIt == D); |
| 3593 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3594 | // Import the major distinguishing characteristics of a variable. |
| 3595 | DeclContext *DC, *LexicalDC; |
| 3596 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3597 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3598 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3599 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3600 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3601 | if (ToD) |
| 3602 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3603 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3604 | // Try to find a variable in our own ("to") context with the same name and |
| 3605 | // in the same context as the variable we're importing. |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3606 | VarDecl *FoundByLookup = nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3607 | if (D->isFileVarDecl()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3608 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3609 | unsigned IDNS = Decl::IDNS_Ordinary; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3610 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3611 | for (auto *FoundDecl : FoundDecls) { |
| 3612 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3613 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3614 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3615 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3616 | if (!hasSameVisibilityContext(FoundVar, D)) |
| 3617 | continue; |
| 3618 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| 3619 | FoundVar->getType())) { |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3620 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3621 | // The VarDecl in the "From" context has a definition, but in the |
| 3622 | // "To" context we already have a definition. |
| 3623 | VarDecl *FoundDef = FoundVar->getDefinition(); |
| 3624 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 3625 | // FIXME Check for ODR error if the two definitions have |
| 3626 | // different initializers? |
| 3627 | return Importer.MapImported(D, FoundDef); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3628 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3629 | // The VarDecl in the "From" context has an initializer, but in the |
| 3630 | // "To" context we already have an initializer. |
| 3631 | const VarDecl *FoundDInit = nullptr; |
| 3632 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) |
| 3633 | // FIXME Diagnose ODR error if the two initializers are different? |
| 3634 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); |
| 3635 | |
| 3636 | FoundByLookup = FoundVar; |
| 3637 | break; |
| 3638 | } |
| 3639 | |
| 3640 | const ArrayType *FoundArray |
| 3641 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3642 | const ArrayType *TArray |
| 3643 | = Importer.getToContext().getAsArrayType(D->getType()); |
| 3644 | if (FoundArray && TArray) { |
| 3645 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3646 | isa<ConstantArrayType>(TArray)) { |
| 3647 | // Import the type. |
| 3648 | if (auto TyOrErr = import(D->getType())) |
| 3649 | FoundVar->setType(*TyOrErr); |
| 3650 | else |
| 3651 | return TyOrErr.takeError(); |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3652 | |
| 3653 | FoundByLookup = FoundVar; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3654 | break; |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3655 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3656 | isa<ConstantArrayType>(FoundArray)) { |
| 3657 | FoundByLookup = FoundVar; |
| 3658 | break; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3659 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3660 | } |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3661 | |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3662 | Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent) |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3663 | << Name << D->getType() << FoundVar->getType(); |
| 3664 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3665 | << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3666 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3667 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3668 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3669 | } |
| 3670 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3671 | if (!ConflictingDecls.empty()) { |
| 3672 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3673 | ConflictingDecls.data(), |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3674 | ConflictingDecls.size()); |
| 3675 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3676 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3677 | } |
| 3678 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3679 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3680 | QualType ToType; |
| 3681 | TypeSourceInfo *ToTypeSourceInfo; |
| 3682 | SourceLocation ToInnerLocStart; |
| 3683 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3684 | if (auto Imp = importSeq( |
| 3685 | D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3686 | D->getQualifierLoc())) |
| 3687 | std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp; |
| 3688 | else |
| 3689 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3690 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3691 | // Create the imported variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3692 | VarDecl *ToVar; |
| 3693 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3694 | ToInnerLocStart, Loc, |
| 3695 | Name.getAsIdentifierInfo(), |
| 3696 | ToType, ToTypeSourceInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3697 | D->getStorageClass())) |
| 3698 | return ToVar; |
| 3699 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3700 | ToVar->setQualifierInfo(ToQualifierLoc); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3701 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3702 | ToVar->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3703 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3704 | if (FoundByLookup) { |
| 3705 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); |
| 3706 | ToVar->setPreviousDecl(Recent); |
| 3707 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3708 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3709 | if (Error Err = ImportInitializer(D, ToVar)) |
| 3710 | return std::move(Err); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3711 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3712 | if (D->isConstexpr()) |
| 3713 | ToVar->setConstexpr(true); |
| 3714 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3715 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3716 | DC->addDeclInternal(ToVar); |
| 3717 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
| 3718 | LexicalDC->addDeclInternal(ToVar); |
| 3719 | |
| 3720 | // Import the rest of the chain. I.e. import all subsequent declarations. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3721 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3722 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3723 | if (!RedeclOrErr) |
| 3724 | return RedeclOrErr.takeError(); |
| 3725 | } |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3726 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3727 | return ToVar; |
| 3728 | } |
| 3729 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3730 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3731 | // Parameters are created in the translation unit's context, then moved |
| 3732 | // into the function declaration's context afterward. |
| 3733 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3734 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3735 | DeclarationName ToDeclName; |
| 3736 | SourceLocation ToLocation; |
| 3737 | QualType ToType; |
| 3738 | if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType())) |
| 3739 | std::tie(ToDeclName, ToLocation, ToType) = *Imp; |
| 3740 | else |
| 3741 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3742 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3743 | // Create the imported parameter. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3744 | ImplicitParamDecl *ToParm = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3745 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3746 | ToLocation, ToDeclName.getAsIdentifierInfo(), |
| 3747 | ToType, D->getParameterKind())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3748 | return ToParm; |
| 3749 | return ToParm; |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3750 | } |
| 3751 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3752 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3753 | // Parameters are created in the translation unit's context, then moved |
| 3754 | // into the function declaration's context afterward. |
| 3755 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3756 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3757 | DeclarationName ToDeclName; |
| 3758 | SourceLocation ToLocation, ToInnerLocStart; |
| 3759 | QualType ToType; |
| 3760 | TypeSourceInfo *ToTypeSourceInfo; |
| 3761 | if (auto Imp = importSeq( |
| 3762 | D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(), |
| 3763 | D->getTypeSourceInfo())) |
| 3764 | std::tie( |
| 3765 | ToDeclName, ToLocation, ToType, ToInnerLocStart, |
| 3766 | ToTypeSourceInfo) = *Imp; |
| 3767 | else |
| 3768 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3769 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3770 | ParmVarDecl *ToParm; |
| 3771 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3772 | ToInnerLocStart, ToLocation, |
| 3773 | ToDeclName.getAsIdentifierInfo(), ToType, |
| 3774 | ToTypeSourceInfo, D->getStorageClass(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3775 | /*DefaultArg*/ nullptr)) |
| 3776 | return ToParm; |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3777 | |
| 3778 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 3779 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3780 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 3781 | |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3782 | if (D->hasUninstantiatedDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3783 | if (auto ToDefArgOrErr = import(D->getUninstantiatedDefaultArg())) |
| 3784 | ToParm->setUninstantiatedDefaultArg(*ToDefArgOrErr); |
| 3785 | else |
| 3786 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3787 | } else if (D->hasUnparsedDefaultArg()) { |
| 3788 | ToParm->setUnparsedDefaultArg(); |
| 3789 | } else if (D->hasDefaultArg()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3790 | if (auto ToDefArgOrErr = import(D->getDefaultArg())) |
| 3791 | ToParm->setDefaultArg(*ToDefArgOrErr); |
| 3792 | else |
| 3793 | return ToDefArgOrErr.takeError(); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3794 | } |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3795 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3796 | if (D->isObjCMethodParameter()) { |
| 3797 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3798 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3799 | } else { |
| 3800 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3801 | D->getFunctionScopeIndex()); |
| 3802 | } |
| 3803 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3804 | return ToParm; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3805 | } |
| 3806 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3807 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3808 | // Import the major distinguishing characteristics of a method. |
| 3809 | DeclContext *DC, *LexicalDC; |
| 3810 | DeclarationName Name; |
| 3811 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3812 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3813 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3814 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3815 | if (ToD) |
| 3816 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3817 | |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3818 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3819 | for (auto *FoundDecl : FoundDecls) { |
| 3820 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3821 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3822 | continue; |
| 3823 | |
| 3824 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3825 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3826 | FoundMethod->getReturnType())) { |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3827 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3828 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3829 | << FoundMethod->getReturnType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3830 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3831 | diag::note_odr_objc_method_here) |
| 3832 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3833 | |
| 3834 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3835 | } |
| 3836 | |
| 3837 | // Check the number of parameters. |
| 3838 | if (D->param_size() != FoundMethod->param_size()) { |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3839 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent) |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3840 | << D->isInstanceMethod() << Name |
| 3841 | << D->param_size() << FoundMethod->param_size(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3842 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3843 | diag::note_odr_objc_method_here) |
| 3844 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3845 | |
| 3846 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3850 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3851 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3852 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3853 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3854 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3855 | Importer.FromDiag((*P)->getLocation(), |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3856 | diag::warn_odr_objc_method_param_type_inconsistent) |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3857 | << D->isInstanceMethod() << Name |
| 3858 | << (*P)->getType() << (*FoundP)->getType(); |
| 3859 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3860 | << (*FoundP)->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3861 | |
| 3862 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3863 | } |
| 3864 | } |
| 3865 | |
| 3866 | // Check variadic/non-variadic. |
| 3867 | // Check the number of parameters. |
| 3868 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3869 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent) |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3870 | << D->isInstanceMethod() << Name; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3871 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3872 | diag::note_odr_objc_method_here) |
| 3873 | << D->isInstanceMethod() << Name; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3874 | |
| 3875 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3876 | } |
| 3877 | |
| 3878 | // FIXME: Any other bits we need to merge? |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3879 | return Importer.MapImported(D, FoundMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3880 | } |
| 3881 | } |
| 3882 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3883 | SourceLocation ToEndLoc; |
| 3884 | QualType ToReturnType; |
| 3885 | TypeSourceInfo *ToReturnTypeSourceInfo; |
| 3886 | if (auto Imp = importSeq( |
| 3887 | D->getEndLoc(), D->getReturnType(), D->getReturnTypeSourceInfo())) |
| 3888 | std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp; |
| 3889 | else |
| 3890 | return Imp.takeError(); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3891 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3892 | ObjCMethodDecl *ToMethod; |
| 3893 | if (GetImportedOrCreateDecl( |
| 3894 | ToMethod, D, Importer.getToContext(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3895 | ToEndLoc, Name.getObjCSelector(), ToReturnType, |
| 3896 | ToReturnTypeSourceInfo, DC, D->isInstanceMethod(), D->isVariadic(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3897 | D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3898 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 3899 | return ToMethod; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3900 | |
| 3901 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3902 | // deal with implicit parameters. |
| 3903 | |
| 3904 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3905 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3906 | for (auto *FromP : D->parameters()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3907 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) |
| 3908 | ToParams.push_back(*ToPOrErr); |
| 3909 | else |
| 3910 | return ToPOrErr.takeError(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3911 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3912 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3913 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3914 | for (auto *ToParam : ToParams) { |
| 3915 | ToParam->setOwningFunction(ToMethod); |
| 3916 | ToMethod->addDeclInternal(ToParam); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3917 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3918 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3919 | SmallVector<SourceLocation, 12> FromSelLocs; |
| 3920 | D->getSelectorLocs(FromSelLocs); |
| 3921 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); |
| 3922 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) |
| 3923 | return std::move(Err); |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3924 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3925 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3926 | |
| 3927 | ToMethod->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3928 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3929 | return ToMethod; |
| 3930 | } |
| 3931 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3932 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3933 | // Import the major distinguishing characteristics of a category. |
| 3934 | DeclContext *DC, *LexicalDC; |
| 3935 | DeclarationName Name; |
| 3936 | SourceLocation Loc; |
| 3937 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3938 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3939 | return std::move(Err); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3940 | if (ToD) |
| 3941 | return ToD; |
| 3942 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3943 | SourceLocation ToVarianceLoc, ToLocation, ToColonLoc; |
| 3944 | TypeSourceInfo *ToTypeSourceInfo; |
| 3945 | if (auto Imp = importSeq( |
| 3946 | D->getVarianceLoc(), D->getLocation(), D->getColonLoc(), |
| 3947 | D->getTypeSourceInfo())) |
| 3948 | std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp; |
| 3949 | else |
| 3950 | return Imp.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3951 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3952 | ObjCTypeParamDecl *Result; |
| 3953 | if (GetImportedOrCreateDecl( |
| 3954 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3955 | ToVarianceLoc, D->getIndex(), |
| 3956 | ToLocation, Name.getAsIdentifierInfo(), |
| 3957 | ToColonLoc, ToTypeSourceInfo)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3958 | return Result; |
| 3959 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3960 | Result->setLexicalDeclContext(LexicalDC); |
| 3961 | return Result; |
| 3962 | } |
| 3963 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3964 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3965 | // Import the major distinguishing characteristics of a category. |
| 3966 | DeclContext *DC, *LexicalDC; |
| 3967 | DeclarationName Name; |
| 3968 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3969 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3970 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3971 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3972 | if (ToD) |
| 3973 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3974 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3975 | ObjCInterfaceDecl *ToInterface; |
| 3976 | if (Error Err = importInto(ToInterface, D->getClassInterface())) |
| 3977 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3978 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3979 | // Determine if we've already encountered this category. |
| 3980 | ObjCCategoryDecl *MergeWithCategory |
| 3981 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3982 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3983 | if (!ToCategory) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3984 | SourceLocation ToAtStartLoc, ToCategoryNameLoc; |
| 3985 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 3986 | if (auto Imp = importSeq( |
| 3987 | D->getAtStartLoc(), D->getCategoryNameLoc(), |
| 3988 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 3989 | std::tie( |
| 3990 | ToAtStartLoc, ToCategoryNameLoc, |
| 3991 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 3992 | else |
| 3993 | return Imp.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3994 | |
| 3995 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3996 | ToAtStartLoc, Loc, |
| 3997 | ToCategoryNameLoc, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3998 | Name.getAsIdentifierInfo(), ToInterface, |
| 3999 | /*TypeParamList=*/nullptr, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4000 | ToIvarLBraceLoc, |
| 4001 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4002 | return ToCategory; |
| 4003 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4004 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4005 | LexicalDC->addDeclInternal(ToCategory); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4006 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4007 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4008 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) |
| 4009 | ToCategory->setTypeParamList(*PListOrErr); |
| 4010 | else |
| 4011 | return PListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4012 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4013 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4014 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4015 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4016 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 4017 | = D->protocol_loc_begin(); |
| 4018 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 4019 | FromProtoEnd = D->protocol_end(); |
| 4020 | FromProto != FromProtoEnd; |
| 4021 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4022 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4023 | Protocols.push_back(*ToProtoOrErr); |
| 4024 | else |
| 4025 | return ToProtoOrErr.takeError(); |
| 4026 | |
| 4027 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4028 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4029 | else |
| 4030 | return ToProtoLocOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4031 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4032 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4033 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4034 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 4035 | ProtocolLocs.data(), Importer.getToContext()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4036 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4037 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4038 | Importer.MapImported(D, ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4039 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4040 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4041 | // Import all of the members of this category. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4042 | if (Error Err = ImportDeclContext(D)) |
| 4043 | return std::move(Err); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4044 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4045 | // If we have an implementation, import it as well. |
| 4046 | if (D->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4047 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = |
| 4048 | import(D->getImplementation())) |
| 4049 | ToCategory->setImplementation(*ToImplOrErr); |
| 4050 | else |
| 4051 | return ToImplOrErr.takeError(); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4052 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4053 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4054 | return ToCategory; |
| 4055 | } |
| 4056 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4057 | Error ASTNodeImporter::ImportDefinition( |
| 4058 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4059 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4060 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4061 | if (Error Err = ImportDeclContext(From)) |
| 4062 | return Err; |
| 4063 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | // Start the protocol definition |
| 4067 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4068 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4069 | // Import protocols |
| 4070 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4071 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4072 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = |
| 4073 | From->protocol_loc_begin(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4074 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4075 | FromProtoEnd = From->protocol_end(); |
| 4076 | FromProto != FromProtoEnd; |
| 4077 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4078 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4079 | Protocols.push_back(*ToProtoOrErr); |
| 4080 | else |
| 4081 | return ToProtoOrErr.takeError(); |
| 4082 | |
| 4083 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4084 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4085 | else |
| 4086 | return ToProtoLocOrErr.takeError(); |
| 4087 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4088 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4089 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4090 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4091 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4092 | ProtocolLocs.data(), Importer.getToContext()); |
| 4093 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4094 | if (shouldForceImportDeclContext(Kind)) { |
| 4095 | // Import all of the members of this protocol. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4096 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4097 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4098 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4099 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4100 | } |
| 4101 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4102 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4103 | // 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] | 4104 | // from, but this particular declaration is not that definition, import the |
| 4105 | // definition and map to that. |
| 4106 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 4107 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4108 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4109 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4110 | else |
| 4111 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4112 | } |
| 4113 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4114 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4115 | DeclContext *DC, *LexicalDC; |
| 4116 | DeclarationName Name; |
| 4117 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4118 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4119 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4120 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4121 | if (ToD) |
| 4122 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4123 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4124 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4125 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4126 | for (auto *FoundDecl : FoundDecls) { |
| 4127 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4128 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4129 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4130 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4131 | break; |
| 4132 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4133 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4134 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4135 | if (!ToProto) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4136 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4137 | if (!ToAtBeginLocOrErr) |
| 4138 | return ToAtBeginLocOrErr.takeError(); |
| 4139 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4140 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 4141 | Name.getAsIdentifierInfo(), Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4142 | *ToAtBeginLocOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4143 | /*PrevDecl=*/nullptr)) |
| 4144 | return ToProto; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4145 | ToProto->setLexicalDeclContext(LexicalDC); |
| 4146 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4147 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4148 | |
| 4149 | Importer.MapImported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4150 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4151 | if (D->isThisDeclarationADefinition()) |
| 4152 | if (Error Err = ImportDefinition(D, ToProto)) |
| 4153 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4154 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4155 | return ToProto; |
| 4156 | } |
| 4157 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4158 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 4159 | DeclContext *DC, *LexicalDC; |
| 4160 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4161 | return std::move(Err); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4162 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4163 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); |
| 4164 | if (!ExternLocOrErr) |
| 4165 | return ExternLocOrErr.takeError(); |
| 4166 | |
| 4167 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); |
| 4168 | if (!LangLocOrErr) |
| 4169 | return LangLocOrErr.takeError(); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4170 | |
| 4171 | bool HasBraces = D->hasBraces(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4172 | |
| 4173 | LinkageSpecDecl *ToLinkageSpec; |
| 4174 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4175 | *ExternLocOrErr, *LangLocOrErr, |
| 4176 | D->getLanguage(), HasBraces)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4177 | return ToLinkageSpec; |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4178 | |
| 4179 | if (HasBraces) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4180 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 4181 | if (!RBraceLocOrErr) |
| 4182 | return RBraceLocOrErr.takeError(); |
| 4183 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4184 | } |
| 4185 | |
| 4186 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 4187 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 4188 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4189 | return ToLinkageSpec; |
| 4190 | } |
| 4191 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4192 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4193 | DeclContext *DC, *LexicalDC; |
| 4194 | DeclarationName Name; |
| 4195 | SourceLocation Loc; |
| 4196 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4197 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4198 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4199 | if (ToD) |
| 4200 | return ToD; |
| 4201 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4202 | SourceLocation ToLoc, ToUsingLoc; |
| 4203 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4204 | if (auto Imp = importSeq( |
| 4205 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc())) |
| 4206 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp; |
| 4207 | else |
| 4208 | return Imp.takeError(); |
| 4209 | |
| 4210 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4211 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4212 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4213 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4214 | UsingDecl *ToUsing; |
| 4215 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4216 | ToUsingLoc, ToQualifierLoc, NameInfo, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4217 | D->hasTypename())) |
| 4218 | return ToUsing; |
| 4219 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4220 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4221 | LexicalDC->addDeclInternal(ToUsing); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4222 | |
| 4223 | if (NamedDecl *FromPattern = |
| 4224 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4225 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) |
| 4226 | Importer.getToContext().setInstantiatedFromUsingDecl( |
| 4227 | ToUsing, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4228 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4229 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4230 | } |
| 4231 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4232 | for (UsingShadowDecl *FromShadow : D->shadows()) { |
| 4233 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) |
| 4234 | ToUsing->addShadowDecl(*ToShadowOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4235 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4236 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4237 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4238 | return ToShadowOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4239 | } |
| 4240 | return ToUsing; |
| 4241 | } |
| 4242 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4243 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4244 | DeclContext *DC, *LexicalDC; |
| 4245 | DeclarationName Name; |
| 4246 | SourceLocation Loc; |
| 4247 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4248 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4249 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4250 | if (ToD) |
| 4251 | return ToD; |
| 4252 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4253 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); |
| 4254 | if (!ToUsingOrErr) |
| 4255 | return ToUsingOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4256 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4257 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); |
| 4258 | if (!ToTargetOrErr) |
| 4259 | return ToTargetOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4260 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4261 | UsingShadowDecl *ToShadow; |
| 4262 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4263 | *ToUsingOrErr, *ToTargetOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4264 | return ToShadow; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4265 | |
| 4266 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 4267 | ToShadow->setAccess(D->getAccess()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4268 | |
| 4269 | if (UsingShadowDecl *FromPattern = |
| 4270 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4271 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) |
| 4272 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( |
| 4273 | ToShadow, *ToPatternOrErr); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4274 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4275 | // FIXME: We return error here but the definition is already created |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4276 | // and available with lookups. How to fix this?.. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4277 | return ToPatternOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4278 | } |
| 4279 | |
| 4280 | LexicalDC->addDeclInternal(ToShadow); |
| 4281 | |
| 4282 | return ToShadow; |
| 4283 | } |
| 4284 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4285 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4286 | DeclContext *DC, *LexicalDC; |
| 4287 | DeclarationName Name; |
| 4288 | SourceLocation Loc; |
| 4289 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4290 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4291 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4292 | if (ToD) |
| 4293 | return ToD; |
| 4294 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4295 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); |
| 4296 | if (!ToComAncestorOrErr) |
| 4297 | return ToComAncestorOrErr.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4298 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4299 | NamespaceDecl *ToNominatedNamespace; |
| 4300 | SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation; |
| 4301 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4302 | if (auto Imp = importSeq( |
| 4303 | D->getNominatedNamespace(), D->getUsingLoc(), |
| 4304 | D->getNamespaceKeyLocation(), D->getQualifierLoc(), |
| 4305 | D->getIdentLocation())) |
| 4306 | std::tie( |
| 4307 | ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation, |
| 4308 | ToQualifierLoc, ToIdentLocation) = *Imp; |
| 4309 | else |
| 4310 | return Imp.takeError(); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4311 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4312 | UsingDirectiveDecl *ToUsingDir; |
| 4313 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4314 | ToUsingLoc, |
| 4315 | ToNamespaceKeyLocation, |
| 4316 | ToQualifierLoc, |
| 4317 | ToIdentLocation, |
| 4318 | ToNominatedNamespace, *ToComAncestorOrErr)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4319 | return ToUsingDir; |
| 4320 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4321 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 4322 | LexicalDC->addDeclInternal(ToUsingDir); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4323 | |
| 4324 | return ToUsingDir; |
| 4325 | } |
| 4326 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4327 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4328 | UnresolvedUsingValueDecl *D) { |
| 4329 | DeclContext *DC, *LexicalDC; |
| 4330 | DeclarationName Name; |
| 4331 | SourceLocation Loc; |
| 4332 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4333 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4334 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4335 | if (ToD) |
| 4336 | return ToD; |
| 4337 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4338 | SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc; |
| 4339 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4340 | if (auto Imp = importSeq( |
| 4341 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(), |
| 4342 | D->getEllipsisLoc())) |
| 4343 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4344 | else |
| 4345 | return Imp.takeError(); |
| 4346 | |
| 4347 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4348 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4349 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4350 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4351 | UnresolvedUsingValueDecl *ToUsingValue; |
| 4352 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4353 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| 4354 | ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4355 | return ToUsingValue; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4356 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4357 | ToUsingValue->setAccess(D->getAccess()); |
| 4358 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 4359 | LexicalDC->addDeclInternal(ToUsingValue); |
| 4360 | |
| 4361 | return ToUsingValue; |
| 4362 | } |
| 4363 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4364 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4365 | UnresolvedUsingTypenameDecl *D) { |
| 4366 | DeclContext *DC, *LexicalDC; |
| 4367 | DeclarationName Name; |
| 4368 | SourceLocation Loc; |
| 4369 | NamedDecl *ToD = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4370 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4371 | return std::move(Err); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4372 | if (ToD) |
| 4373 | return ToD; |
| 4374 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4375 | SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc; |
| 4376 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4377 | if (auto Imp = importSeq( |
| 4378 | D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(), |
| 4379 | D->getEllipsisLoc())) |
| 4380 | std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4381 | else |
| 4382 | return Imp.takeError(); |
| 4383 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4384 | UnresolvedUsingTypenameDecl *ToUsing; |
| 4385 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4386 | ToUsingLoc, ToTypenameLoc, |
| 4387 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4388 | return ToUsing; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4389 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4390 | ToUsing->setAccess(D->getAccess()); |
| 4391 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4392 | LexicalDC->addDeclInternal(ToUsing); |
| 4393 | |
| 4394 | return ToUsing; |
| 4395 | } |
| 4396 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4397 | |
| 4398 | Error ASTNodeImporter::ImportDefinition( |
| 4399 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4400 | if (To->getDefinition()) { |
| 4401 | // Check consistency of superclass. |
| 4402 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 4403 | if (FromSuper) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4404 | if (auto FromSuperOrErr = import(FromSuper)) |
| 4405 | FromSuper = *FromSuperOrErr; |
| 4406 | else |
| 4407 | return FromSuperOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4408 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4409 | |
| 4410 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4411 | if ((bool)FromSuper != (bool)ToSuper || |
| 4412 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4413 | Importer.ToDiag(To->getLocation(), |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4414 | diag::warn_odr_objc_superclass_inconsistent) |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4415 | << To->getDeclName(); |
| 4416 | if (ToSuper) |
| 4417 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 4418 | << To->getSuperClass()->getDeclName(); |
| 4419 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4420 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4421 | diag::note_odr_objc_missing_superclass); |
| 4422 | if (From->getSuperClass()) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4423 | Importer.FromDiag(From->getSuperClassLoc(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4424 | diag::note_odr_objc_superclass) |
| 4425 | << From->getSuperClass()->getDeclName(); |
| 4426 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4427 | Importer.FromDiag(From->getLocation(), |
| 4428 | diag::note_odr_objc_missing_superclass); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4429 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4430 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4431 | if (shouldForceImportDeclContext(Kind)) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4432 | if (Error Err = ImportDeclContext(From)) |
| 4433 | return Err; |
| 4434 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4435 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4436 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4437 | // Start the definition. |
| 4438 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4439 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4440 | // If this class has a superclass, import it. |
| 4441 | if (From->getSuperClass()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4442 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) |
| 4443 | To->setSuperClass(*SuperTInfoOrErr); |
| 4444 | else |
| 4445 | return SuperTInfoOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4446 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4447 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4448 | // Import protocols |
| 4449 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4450 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4451 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = |
| 4452 | From->protocol_loc_begin(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4453 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4454 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4455 | FromProtoEnd = From->protocol_end(); |
| 4456 | FromProto != FromProtoEnd; |
| 4457 | ++FromProto, ++FromProtoLoc) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4458 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4459 | Protocols.push_back(*ToProtoOrErr); |
| 4460 | else |
| 4461 | return ToProtoOrErr.takeError(); |
| 4462 | |
| 4463 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4464 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4465 | else |
| 4466 | return ToProtoLocOrErr.takeError(); |
| 4467 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4468 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4469 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4470 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4471 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4472 | ProtocolLocs.data(), Importer.getToContext()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4473 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4474 | // Import categories. When the categories themselves are imported, they'll |
| 4475 | // hook themselves into this interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4476 | for (auto *Cat : From->known_categories()) { |
| 4477 | auto ToCatOrErr = import(Cat); |
| 4478 | if (!ToCatOrErr) |
| 4479 | return ToCatOrErr.takeError(); |
| 4480 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4481 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4482 | // If we have an @implementation, import it as well. |
| 4483 | if (From->getImplementation()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4484 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = |
| 4485 | import(From->getImplementation())) |
| 4486 | To->setImplementation(*ToImplOrErr); |
| 4487 | else |
| 4488 | return ToImplOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4489 | } |
| 4490 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4491 | if (shouldForceImportDeclContext(Kind)) { |
| 4492 | // Import all of the members of this class. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4493 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4494 | return Err; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4495 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4496 | return Error::success(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4497 | } |
| 4498 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4499 | Expected<ObjCTypeParamList *> |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4500 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 4501 | if (!list) |
| 4502 | return nullptr; |
| 4503 | |
| 4504 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4505 | for (auto *fromTypeParam : *list) { |
| 4506 | if (auto toTypeParamOrErr = import(fromTypeParam)) |
| 4507 | toTypeParams.push_back(*toTypeParamOrErr); |
| 4508 | else |
| 4509 | return toTypeParamOrErr.takeError(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4510 | } |
| 4511 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4512 | auto LAngleLocOrErr = import(list->getLAngleLoc()); |
| 4513 | if (!LAngleLocOrErr) |
| 4514 | return LAngleLocOrErr.takeError(); |
| 4515 | |
| 4516 | auto RAngleLocOrErr = import(list->getRAngleLoc()); |
| 4517 | if (!RAngleLocOrErr) |
| 4518 | return RAngleLocOrErr.takeError(); |
| 4519 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4520 | return ObjCTypeParamList::create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4521 | *LAngleLocOrErr, |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4522 | toTypeParams, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4523 | *RAngleLocOrErr); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4524 | } |
| 4525 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4526 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4527 | // If this class has a definition in the translation unit we're coming from, |
| 4528 | // but this particular declaration is not that definition, import the |
| 4529 | // definition and map to that. |
| 4530 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 4531 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4532 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4533 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4534 | else |
| 4535 | return ImportedDefOrErr.takeError(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4536 | } |
| 4537 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4538 | // Import the major distinguishing characteristics of an @interface. |
| 4539 | DeclContext *DC, *LexicalDC; |
| 4540 | DeclarationName Name; |
| 4541 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4542 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4543 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4544 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4545 | if (ToD) |
| 4546 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4547 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4548 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4549 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4550 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4551 | for (auto *FoundDecl : FoundDecls) { |
| 4552 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4553 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4554 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4555 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4556 | break; |
| 4557 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4558 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4559 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4560 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4561 | if (!ToIface) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4562 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4563 | if (!AtBeginLocOrErr) |
| 4564 | return AtBeginLocOrErr.takeError(); |
| 4565 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4566 | if (GetImportedOrCreateDecl( |
| 4567 | ToIface, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4568 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4569 | /*TypeParamList=*/nullptr, |
| 4570 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 4571 | return ToIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4572 | ToIface->setLexicalDeclContext(LexicalDC); |
| 4573 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4574 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4575 | Importer.MapImported(D, ToIface); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4576 | // Import the type parameter list after MapImported, to avoid |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4577 | // loops when bringing in their DeclContext. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4578 | if (auto ToPListOrErr = |
| 4579 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) |
| 4580 | ToIface->setTypeParamList(*ToPListOrErr); |
| 4581 | else |
| 4582 | return ToPListOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4583 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4584 | if (D->isThisDeclarationADefinition()) |
| 4585 | if (Error Err = ImportDefinition(D, ToIface)) |
| 4586 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4587 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4588 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4589 | } |
| 4590 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4591 | ExpectedDecl |
| 4592 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 4593 | ObjCCategoryDecl *Category; |
| 4594 | if (Error Err = importInto(Category, D->getCategoryDecl())) |
| 4595 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4596 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4597 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4598 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4599 | DeclContext *DC, *LexicalDC; |
| 4600 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4601 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4602 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4603 | SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc; |
| 4604 | if (auto Imp = importSeq( |
| 4605 | D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc())) |
| 4606 | std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp; |
| 4607 | else |
| 4608 | return Imp.takeError(); |
| 4609 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4610 | if (GetImportedOrCreateDecl( |
| 4611 | ToImpl, D, Importer.getToContext(), DC, |
| 4612 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4613 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4614 | return ToImpl; |
| 4615 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4616 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4617 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4618 | Category->setImplementation(ToImpl); |
| 4619 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4620 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4621 | Importer.MapImported(D, ToImpl); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4622 | if (Error Err = ImportDeclContext(D)) |
| 4623 | return std::move(Err); |
| 4624 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4625 | return ToImpl; |
| 4626 | } |
| 4627 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4628 | ExpectedDecl |
| 4629 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4630 | // Find the corresponding interface. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4631 | ObjCInterfaceDecl *Iface; |
| 4632 | if (Error Err = importInto(Iface, D->getClassInterface())) |
| 4633 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4634 | |
| 4635 | // Import the superclass, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4636 | ObjCInterfaceDecl *Super; |
| 4637 | if (Error Err = importInto(Super, D->getSuperClass())) |
| 4638 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4639 | |
| 4640 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4641 | if (!Impl) { |
| 4642 | // We haven't imported an implementation yet. Create a new @implementation |
| 4643 | // now. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4644 | DeclContext *DC, *LexicalDC; |
| 4645 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4646 | return std::move(Err); |
| 4647 | |
| 4648 | SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc; |
| 4649 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 4650 | if (auto Imp = importSeq( |
| 4651 | D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(), |
| 4652 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 4653 | std::tie( |
| 4654 | ToLocation, ToAtStartLoc, ToSuperClassLoc, |
| 4655 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 4656 | else |
| 4657 | return Imp.takeError(); |
| 4658 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4659 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4660 | DC, Iface, Super, |
| 4661 | ToLocation, |
| 4662 | ToAtStartLoc, |
| 4663 | ToSuperClassLoc, |
| 4664 | ToIvarLBraceLoc, |
| 4665 | ToIvarRBraceLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4666 | return Impl; |
| 4667 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4668 | Impl->setLexicalDeclContext(LexicalDC); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4669 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4670 | // Associate the implementation with the class it implements. |
| 4671 | Iface->setImplementation(Impl); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4672 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4673 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4674 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4675 | |
| 4676 | // Verify that the existing @implementation has the same superclass. |
| 4677 | if ((Super && !Impl->getSuperClass()) || |
| 4678 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4679 | (Super && Impl->getSuperClass() && |
| 4680 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4681 | Impl->getSuperClass()))) { |
| 4682 | Importer.ToDiag(Impl->getLocation(), |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4683 | diag::warn_odr_objc_superclass_inconsistent) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4684 | << Iface->getDeclName(); |
| 4685 | // FIXME: It would be nice to have the location of the superclass |
| 4686 | // below. |
| 4687 | if (Impl->getSuperClass()) |
| 4688 | Importer.ToDiag(Impl->getLocation(), |
| 4689 | diag::note_odr_objc_superclass) |
| 4690 | << Impl->getSuperClass()->getDeclName(); |
| 4691 | else |
| 4692 | Importer.ToDiag(Impl->getLocation(), |
| 4693 | diag::note_odr_objc_missing_superclass); |
| 4694 | if (D->getSuperClass()) |
| 4695 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4696 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4697 | << D->getSuperClass()->getDeclName(); |
| 4698 | else |
| 4699 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4700 | diag::note_odr_objc_missing_superclass); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4701 | |
| 4702 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4703 | } |
| 4704 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4705 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4706 | // Import all of the members of this @implementation. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4707 | if (Error Err = ImportDeclContext(D)) |
| 4708 | return std::move(Err); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4709 | |
| 4710 | return Impl; |
| 4711 | } |
| 4712 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4713 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4714 | // Import the major distinguishing characteristics of an @property. |
| 4715 | DeclContext *DC, *LexicalDC; |
| 4716 | DeclarationName Name; |
| 4717 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4718 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4719 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4720 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4721 | if (ToD) |
| 4722 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4723 | |
| 4724 | // Check whether we have already imported this property. |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4725 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4726 | for (auto *FoundDecl : FoundDecls) { |
| 4727 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4728 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4729 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4730 | FoundProp->getType())) { |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4731 | Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent) |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4732 | << Name << D->getType() << FoundProp->getType(); |
| 4733 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4734 | << FoundProp->getType(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4735 | |
| 4736 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4737 | } |
| 4738 | |
| 4739 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4740 | |
| 4741 | // Consider these properties to be equivalent. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4742 | Importer.MapImported(D, FoundProp); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4743 | return FoundProp; |
| 4744 | } |
| 4745 | } |
| 4746 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4747 | QualType ToType; |
| 4748 | TypeSourceInfo *ToTypeSourceInfo; |
| 4749 | SourceLocation ToAtLoc, ToLParenLoc; |
| 4750 | if (auto Imp = importSeq( |
| 4751 | D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc())) |
| 4752 | std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp; |
| 4753 | else |
| 4754 | return Imp.takeError(); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4755 | |
| 4756 | // Create the new property. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4757 | ObjCPropertyDecl *ToProperty; |
| 4758 | if (GetImportedOrCreateDecl( |
| 4759 | ToProperty, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4760 | Name.getAsIdentifierInfo(), ToAtLoc, |
| 4761 | ToLParenLoc, ToType, |
| 4762 | ToTypeSourceInfo, D->getPropertyImplementation())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4763 | return ToProperty; |
| 4764 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4765 | Selector ToGetterName, ToSetterName; |
| 4766 | SourceLocation ToGetterNameLoc, ToSetterNameLoc; |
| 4767 | ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl; |
| 4768 | ObjCIvarDecl *ToPropertyIvarDecl; |
| 4769 | if (auto Imp = importSeq( |
| 4770 | D->getGetterName(), D->getSetterName(), |
| 4771 | D->getGetterNameLoc(), D->getSetterNameLoc(), |
| 4772 | D->getGetterMethodDecl(), D->getSetterMethodDecl(), |
| 4773 | D->getPropertyIvarDecl())) |
| 4774 | std::tie( |
| 4775 | ToGetterName, ToSetterName, |
| 4776 | ToGetterNameLoc, ToSetterNameLoc, |
| 4777 | ToGetterMethodDecl, ToSetterMethodDecl, |
| 4778 | ToPropertyIvarDecl) = *Imp; |
| 4779 | else |
| 4780 | return Imp.takeError(); |
| 4781 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4782 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4783 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4784 | |
| 4785 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4786 | ToProperty->setPropertyAttributesAsWritten( |
| 4787 | D->getPropertyAttributesAsWritten()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4788 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); |
| 4789 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); |
| 4790 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); |
| 4791 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); |
| 4792 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4793 | return ToProperty; |
| 4794 | } |
| 4795 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4796 | ExpectedDecl |
| 4797 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 4798 | ObjCPropertyDecl *Property; |
| 4799 | if (Error Err = importInto(Property, D->getPropertyDecl())) |
| 4800 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4801 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4802 | DeclContext *DC, *LexicalDC; |
| 4803 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4804 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4805 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4806 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4807 | |
| 4808 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4809 | ObjCIvarDecl *Ivar = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4810 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) |
| 4811 | return std::move(Err); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4812 | |
| 4813 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 4814 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 4815 | Property->getQueryKind()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4816 | if (!ToImpl) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4817 | SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc; |
| 4818 | if (auto Imp = importSeq( |
| 4819 | D->getBeginLoc(), D->getLocation(), D->getPropertyIvarDeclLoc())) |
| 4820 | std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp; |
| 4821 | else |
| 4822 | return Imp.takeError(); |
| 4823 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4824 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4825 | ToBeginLoc, |
| 4826 | ToLocation, Property, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4827 | D->getPropertyImplementation(), Ivar, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4828 | ToPropertyIvarDeclLoc)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4829 | return ToImpl; |
| 4830 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4831 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4832 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4833 | } else { |
| 4834 | // Check that we have the same kind of property implementation (@synthesize |
| 4835 | // vs. @dynamic). |
| 4836 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4837 | Importer.ToDiag(ToImpl->getLocation(), |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4838 | diag::warn_odr_objc_property_impl_kind_inconsistent) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4839 | << Property->getDeclName() |
| 4840 | << (ToImpl->getPropertyImplementation() |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4841 | == ObjCPropertyImplDecl::Dynamic); |
| 4842 | Importer.FromDiag(D->getLocation(), |
| 4843 | diag::note_odr_objc_property_impl_kind) |
| 4844 | << D->getPropertyDecl()->getDeclName() |
| 4845 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4846 | |
| 4847 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4848 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4849 | |
| 4850 | // For @synthesize, check that we have the same |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4851 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 4852 | Ivar != ToImpl->getPropertyIvarDecl()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4853 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4854 | diag::warn_odr_objc_synthesize_ivar_inconsistent) |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4855 | << Property->getDeclName() |
| 4856 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 4857 | << Ivar->getDeclName(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4858 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4859 | diag::note_odr_objc_synthesize_ivar_here) |
| 4860 | << D->getPropertyIvarDecl()->getDeclName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4861 | |
| 4862 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4863 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4864 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4865 | // Merge the existing implementation with the new implementation. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4866 | Importer.MapImported(D, ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4867 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4868 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4869 | return ToImpl; |
| 4870 | } |
| 4871 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4872 | ExpectedDecl |
| 4873 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4874 | // For template arguments, we adopt the translation unit as our declaration |
| 4875 | // context. This context will be fixed when the actual template declaration |
| 4876 | // is created. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4877 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4878 | // FIXME: Import default argument. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4879 | |
| 4880 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 4881 | if (!BeginLocOrErr) |
| 4882 | return BeginLocOrErr.takeError(); |
| 4883 | |
| 4884 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4885 | if (!LocationOrErr) |
| 4886 | return LocationOrErr.takeError(); |
| 4887 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4888 | TemplateTypeParmDecl *ToD = nullptr; |
| 4889 | (void)GetImportedOrCreateDecl( |
| 4890 | ToD, D, Importer.getToContext(), |
| 4891 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4892 | *BeginLocOrErr, *LocationOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4893 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| 4894 | D->wasDeclaredWithTypename(), D->isParameterPack()); |
| 4895 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4896 | } |
| 4897 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4898 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4899 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4900 | DeclarationName ToDeclName; |
| 4901 | SourceLocation ToLocation, ToInnerLocStart; |
| 4902 | QualType ToType; |
| 4903 | TypeSourceInfo *ToTypeSourceInfo; |
| 4904 | if (auto Imp = importSeq( |
| 4905 | D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(), |
| 4906 | D->getInnerLocStart())) |
| 4907 | std::tie( |
| 4908 | ToDeclName, ToLocation, ToType, ToTypeSourceInfo, |
| 4909 | ToInnerLocStart) = *Imp; |
| 4910 | else |
| 4911 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4912 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4913 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4914 | |
| 4915 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 4916 | (void)GetImportedOrCreateDecl( |
| 4917 | ToD, D, Importer.getToContext(), |
| 4918 | Importer.getToContext().getTranslationUnitDecl(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4919 | ToInnerLocStart, ToLocation, D->getDepth(), |
| 4920 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, |
| 4921 | D->isParameterPack(), ToTypeSourceInfo); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4922 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4923 | } |
| 4924 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4925 | ExpectedDecl |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4926 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 4927 | // Import the name of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4928 | auto NameOrErr = import(D->getDeclName()); |
| 4929 | if (!NameOrErr) |
| 4930 | return NameOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4931 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4932 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4933 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4934 | if (!LocationOrErr) |
| 4935 | return LocationOrErr.takeError(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4936 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4937 | // Import template parameters. |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 4938 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4939 | if (!TemplateParamsOrErr) |
| 4940 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4941 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4942 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4943 | |
| 4944 | TemplateTemplateParmDecl *ToD = nullptr; |
| 4945 | (void)GetImportedOrCreateDecl( |
| 4946 | ToD, D, Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4947 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, |
| 4948 | D->getDepth(), D->getPosition(), D->isParameterPack(), |
| 4949 | (*NameOrErr).getAsIdentifierInfo(), |
| 4950 | *TemplateParamsOrErr); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4951 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4952 | } |
| 4953 | |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4954 | // Returns the definition for a (forward) declaration of a TemplateDecl, if |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4955 | // it has any definition in the redecl chain. |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4956 | template <typename T> static auto getTemplateDefinition(T *D) -> T * { |
| 4957 | assert(D->getTemplatedDecl() && "Should be called on templates only"); |
| 4958 | auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4959 | if (!ToTemplatedDef) |
| 4960 | return nullptr; |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4961 | auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate(); |
| 4962 | return cast_or_null<T>(TemplateWithDef); |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4963 | } |
| 4964 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4965 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4966 | bool IsFriend = D->getFriendObjectKind() != Decl::FOK_None; |
| 4967 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4968 | // Import the major distinguishing characteristics of this class template. |
| 4969 | DeclContext *DC, *LexicalDC; |
| 4970 | DeclarationName Name; |
| 4971 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4972 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4973 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4974 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4975 | if (ToD) |
| 4976 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4977 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4978 | ClassTemplateDecl *FoundByLookup = nullptr; |
| 4979 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4980 | // We may already have a template of the same name; try to find and match it. |
| 4981 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4982 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4983 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4984 | for (auto *FoundDecl : FoundDecls) { |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4985 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary | |
| 4986 | Decl::IDNS_TagFriend)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4987 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4988 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4989 | Decl *Found = FoundDecl; |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4990 | auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found); |
| 4991 | if (FoundTemplate) { |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4992 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4993 | if (IsStructuralMatch(D, FoundTemplate)) { |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4994 | ClassTemplateDecl *TemplateWithDef = |
| 4995 | getTemplateDefinition(FoundTemplate); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4996 | if (D->isThisDeclarationADefinition() && TemplateWithDef) { |
| 4997 | return Importer.MapImported(D, TemplateWithDef); |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4998 | } |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4999 | FoundByLookup = FoundTemplate; |
| 5000 | break; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5001 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5002 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5003 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5004 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5005 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5006 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5007 | if (!ConflictingDecls.empty()) { |
| 5008 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5009 | ConflictingDecls.data(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5010 | ConflictingDecls.size()); |
| 5011 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5012 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5013 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5014 | return make_error<ImportError>(ImportError::NameConflict); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5015 | } |
| 5016 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5017 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 5018 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5019 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5020 | CXXRecordDecl *ToTemplated; |
| 5021 | if (Error Err = importInto(ToTemplated, FromTemplated)) |
| 5022 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5023 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5024 | // Create the class template declaration itself. |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5025 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5026 | if (!TemplateParamsOrErr) |
| 5027 | return TemplateParamsOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5028 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5029 | ClassTemplateDecl *D2; |
| 5030 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5031 | *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5032 | return D2; |
| 5033 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5034 | ToTemplated->setDescribedClassTemplate(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5035 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5036 | D2->setAccess(D->getAccess()); |
| 5037 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5038 | |
| 5039 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 5040 | DC->addDeclInternal(D2); |
| 5041 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5042 | LexicalDC->addDeclInternal(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5043 | |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5044 | if (FoundByLookup) { |
| 5045 | auto *Recent = |
| 5046 | const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5047 | |
| 5048 | // It is possible that during the import of the class template definition |
| 5049 | // we start the import of a fwd friend decl of the very same class template |
| 5050 | // and we add the fwd friend decl to the lookup table. But the ToTemplated |
| 5051 | // had been created earlier and by that time the lookup could not find |
| 5052 | // anything existing, so it has no previous decl. Later, (still during the |
| 5053 | // import of the fwd friend decl) we start to import the definition again |
| 5054 | // and this time the lookup finds the previous fwd friend class template. |
| 5055 | // In this case we must set up the previous decl for the templated decl. |
| 5056 | if (!ToTemplated->getPreviousDecl()) { |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5057 | assert(FoundByLookup->getTemplatedDecl() && |
| 5058 | "Found decl must have its templated decl set"); |
Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5059 | CXXRecordDecl *PrevTemplated = |
| 5060 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5061 | if (ToTemplated != PrevTemplated) |
| 5062 | ToTemplated->setPreviousDecl(PrevTemplated); |
| 5063 | } |
| 5064 | |
| 5065 | D2->setPreviousDecl(Recent); |
| 5066 | } |
| 5067 | |
| 5068 | if (LexicalDC != DC && IsFriend) |
| 5069 | DC->makeDeclVisibleInContext(D2); |
| 5070 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5071 | if (FromTemplated->isCompleteDefinition() && |
| 5072 | !ToTemplated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5073 | // FIXME: Import definition! |
| 5074 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5075 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5076 | return D2; |
| 5077 | } |
| 5078 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5079 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5080 | ClassTemplateSpecializationDecl *D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5081 | ClassTemplateDecl *ClassTemplate; |
| 5082 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) |
| 5083 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5084 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5085 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5086 | DeclContext *DC, *LexicalDC; |
| 5087 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5088 | return std::move(Err); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5089 | |
| 5090 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5091 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5092 | if (Error Err = ImportTemplateArguments( |
| 5093 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5094 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5095 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5096 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5097 | void *InsertPos = nullptr; |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5098 | ClassTemplateSpecializationDecl *PrevDecl = nullptr; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5099 | ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 5100 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); |
| 5101 | if (PartialSpec) |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5102 | PrevDecl = |
| 5103 | ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5104 | else |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5105 | PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5106 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5107 | if (PrevDecl) { |
| 5108 | if (IsStructuralMatch(D, PrevDecl)) { |
| 5109 | if (D->isThisDeclarationADefinition() && PrevDecl->getDefinition()) { |
| 5110 | Importer.MapImported(D, PrevDecl->getDefinition()); |
| 5111 | // Import those default field initializers which have been |
| 5112 | // instantiated in the "From" context, but not in the "To" context. |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5113 | for (auto *FromField : D->fields()) { |
| 5114 | auto ToOrErr = import(FromField); |
| 5115 | if (!ToOrErr) |
| 5116 | return ToOrErr.takeError(); |
| 5117 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5118 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5119 | // Import those methods which have been instantiated in the |
| 5120 | // "From" context, but not in the "To" context. |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5121 | for (CXXMethodDecl *FromM : D->methods()) { |
| 5122 | auto ToOrErr = import(FromM); |
| 5123 | if (!ToOrErr) |
| 5124 | return ToOrErr.takeError(); |
| 5125 | } |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5126 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5127 | // TODO Import instantiated default arguments. |
| 5128 | // TODO Import instantiated exception specifications. |
| 5129 | // |
| 5130 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint |
| 5131 | // what else could be fused during an AST merge. |
| 5132 | return PrevDecl; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5133 | } |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5134 | } else { // ODR violation. |
| 5135 | // FIXME HandleNameConflict |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 5136 | return make_error<ImportError>(ImportError::NameConflict); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5137 | } |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5138 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5139 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5140 | // Import the location of this declaration. |
| 5141 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5142 | if (!BeginLocOrErr) |
| 5143 | return BeginLocOrErr.takeError(); |
| 5144 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); |
| 5145 | if (!IdLocOrErr) |
| 5146 | return IdLocOrErr.takeError(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5147 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5148 | // Create the specialization. |
| 5149 | ClassTemplateSpecializationDecl *D2 = nullptr; |
| 5150 | if (PartialSpec) { |
| 5151 | // Import TemplateArgumentListInfo. |
| 5152 | TemplateArgumentListInfo ToTAInfo; |
| 5153 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 5154 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
| 5155 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5156 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5157 | QualType CanonInjType; |
| 5158 | if (Error Err = importInto( |
| 5159 | CanonInjType, PartialSpec->getInjectedSpecializationType())) |
| 5160 | return std::move(Err); |
| 5161 | CanonInjType = CanonInjType.getCanonicalType(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5162 | |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5163 | auto ToTPListOrErr = import(PartialSpec->getTemplateParameters()); |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5164 | if (!ToTPListOrErr) |
| 5165 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5166 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5167 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
| 5168 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5169 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, ClassTemplate, |
| 5170 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 5171 | ToTAInfo, CanonInjType, |
| 5172 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) |
| 5173 | return D2; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5174 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5175 | // Update InsertPos, because preceding import calls may have invalidated |
| 5176 | // it by adding new specializations. |
| 5177 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos)) |
| 5178 | // Add this partial specialization to the class template. |
| 5179 | ClassTemplate->AddPartialSpecialization( |
| 5180 | cast<ClassTemplatePartialSpecializationDecl>(D2), InsertPos); |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5181 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5182 | } else { // Not a partial specialization. |
| 5183 | if (GetImportedOrCreateDecl( |
| 5184 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5185 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, |
| 5186 | PrevDecl)) |
| 5187 | return D2; |
Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5188 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5189 | // Update InsertPos, because preceding import calls may have invalidated |
| 5190 | // it by adding new specializations. |
| 5191 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) |
| 5192 | // Add this specialization to the class template. |
| 5193 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 5194 | } |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5195 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5196 | D2->setSpecializationKind(D->getSpecializationKind()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5197 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5198 | // Set the context of this specialization/instantiation. |
| 5199 | D2->setLexicalDeclContext(LexicalDC); |
| 5200 | |
| 5201 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 5202 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 5203 | LexicalDC->addDeclInternal(D2); |
| 5204 | } |
| 5205 | |
| 5206 | // Import the qualifier, if any. |
| 5207 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5208 | D2->setQualifierInfo(*LocOrErr); |
| 5209 | else |
| 5210 | return LocOrErr.takeError(); |
| 5211 | |
| 5212 | if (auto *TSI = D->getTypeAsWritten()) { |
| 5213 | if (auto TInfoOrErr = import(TSI)) |
| 5214 | D2->setTypeAsWritten(*TInfoOrErr); |
| 5215 | else |
| 5216 | return TInfoOrErr.takeError(); |
| 5217 | |
| 5218 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) |
| 5219 | D2->setTemplateKeywordLoc(*LocOrErr); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5220 | else |
| 5221 | return LocOrErr.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5222 | |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5223 | if (auto LocOrErr = import(D->getExternLoc())) |
| 5224 | D2->setExternLoc(*LocOrErr); |
| 5225 | else |
| 5226 | return LocOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5227 | } |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5228 | |
| 5229 | if (D->getPointOfInstantiation().isValid()) { |
| 5230 | if (auto POIOrErr = import(D->getPointOfInstantiation())) |
| 5231 | D2->setPointOfInstantiation(*POIOrErr); |
| 5232 | else |
| 5233 | return POIOrErr.takeError(); |
| 5234 | } |
| 5235 | |
| 5236 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 5237 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5238 | if (D->isCompleteDefinition()) |
| 5239 | if (Error Err = ImportDefinition(D, D2)) |
| 5240 | return std::move(Err); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5241 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5242 | return D2; |
| 5243 | } |
| 5244 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5245 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5246 | // If this variable has a definition in the translation unit we're coming |
| 5247 | // from, |
| 5248 | // but this particular declaration is not that definition, import the |
| 5249 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5250 | auto *Definition = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5251 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 5252 | if (Definition && Definition != D->getTemplatedDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5253 | if (ExpectedDecl ImportedDefOrErr = import( |
| 5254 | Definition->getDescribedVarTemplate())) |
| 5255 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5256 | else |
| 5257 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5258 | } |
| 5259 | |
| 5260 | // Import the major distinguishing characteristics of this variable template. |
| 5261 | DeclContext *DC, *LexicalDC; |
| 5262 | DeclarationName Name; |
| 5263 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5264 | NamedDecl *ToD; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5265 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5266 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5267 | if (ToD) |
| 5268 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5269 | |
| 5270 | // We may already have a template of the same name; try to find and match it. |
| 5271 | assert(!DC->isFunctionOrMethod() && |
| 5272 | "Variable templates cannot be declared at function scope"); |
| 5273 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5274 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5275 | for (auto *FoundDecl : FoundDecls) { |
| 5276 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5277 | continue; |
| 5278 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5279 | Decl *Found = FoundDecl; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5280 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5281 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5282 | // The variable templates structurally match; call it the same template. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5283 | Importer.MapImported(D->getTemplatedDecl(), |
| 5284 | FoundTemplate->getTemplatedDecl()); |
| 5285 | return Importer.MapImported(D, FoundTemplate); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5286 | } |
| 5287 | } |
| 5288 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5289 | ConflictingDecls.push_back(FoundDecl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | if (!ConflictingDecls.empty()) { |
| 5293 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 5294 | ConflictingDecls.data(), |
| 5295 | ConflictingDecls.size()); |
| 5296 | } |
| 5297 | |
| 5298 | if (!Name) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5299 | // FIXME: Is it possible to get other error than name conflict? |
| 5300 | // (Put this `if` into the previous `if`?) |
| 5301 | return make_error<ImportError>(ImportError::NameConflict); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5302 | |
| 5303 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 5304 | |
| 5305 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5306 | // FIXME: Value not used? |
| 5307 | ExpectedType TypeOrErr = import(DTemplated->getType()); |
| 5308 | if (!TypeOrErr) |
| 5309 | return TypeOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5310 | |
| 5311 | // Create the declaration that is being templated. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5312 | VarDecl *ToTemplated; |
| 5313 | if (Error Err = importInto(ToTemplated, DTemplated)) |
| 5314 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5315 | |
| 5316 | // Create the variable template declaration itself. |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5317 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5318 | if (!TemplateParamsOrErr) |
| 5319 | return TemplateParamsOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5320 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5321 | VarTemplateDecl *ToVarTD; |
| 5322 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5323 | Name, *TemplateParamsOrErr, ToTemplated)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5324 | return ToVarTD; |
| 5325 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5326 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5327 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5328 | ToVarTD->setAccess(D->getAccess()); |
| 5329 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 5330 | LexicalDC->addDeclInternal(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5331 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5332 | if (DTemplated->isThisDeclarationADefinition() && |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5333 | !ToTemplated->isThisDeclarationADefinition()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5334 | // FIXME: Import definition! |
| 5335 | } |
| 5336 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5337 | return ToVarTD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5338 | } |
| 5339 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5340 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5341 | VarTemplateSpecializationDecl *D) { |
| 5342 | // If this record has a definition in the translation unit we're coming from, |
| 5343 | // but this particular declaration is not that definition, import the |
| 5344 | // definition and map to that. |
| 5345 | VarDecl *Definition = D->getDefinition(); |
| 5346 | if (Definition && Definition != D) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5347 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5348 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5349 | else |
| 5350 | return ImportedDefOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5351 | } |
| 5352 | |
Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 5353 | VarTemplateDecl *VarTemplate = nullptr; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5354 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) |
| 5355 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5356 | |
| 5357 | // Import the context of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5358 | DeclContext *DC, *LexicalDC; |
| 5359 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5360 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5361 | |
| 5362 | // Import the location of this declaration. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5363 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5364 | if (!BeginLocOrErr) |
| 5365 | return BeginLocOrErr.takeError(); |
| 5366 | |
| 5367 | auto IdLocOrErr = import(D->getLocation()); |
| 5368 | if (!IdLocOrErr) |
| 5369 | return IdLocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5370 | |
| 5371 | // Import template arguments. |
| 5372 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5373 | if (Error Err = ImportTemplateArguments( |
| 5374 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5375 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5376 | |
| 5377 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5378 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5379 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 5380 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5381 | if (D2) { |
| 5382 | // We already have a variable template specialization with these template |
| 5383 | // arguments. |
| 5384 | |
| 5385 | // FIXME: Check for specialization vs. instantiation errors. |
| 5386 | |
| 5387 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 5388 | if (!D->isThisDeclarationADefinition() || |
| 5389 | IsStructuralMatch(D, FoundDef)) { |
| 5390 | // The record types structurally match, or the "from" translation |
| 5391 | // unit only had a forward declaration anyway; call it the same |
| 5392 | // variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5393 | return Importer.MapImported(D, FoundDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5394 | } |
| 5395 | } |
| 5396 | } else { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5397 | // Import the type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5398 | QualType T; |
| 5399 | if (Error Err = importInto(T, D->getType())) |
| 5400 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5401 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5402 | auto TInfoOrErr = import(D->getTypeSourceInfo()); |
| 5403 | if (!TInfoOrErr) |
| 5404 | return TInfoOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5405 | |
| 5406 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5407 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5408 | D->getTemplateArgsInfo(), ToTAInfo)) |
| 5409 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5410 | |
| 5411 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5412 | // Create a new specialization. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5413 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 5414 | // Import TemplateArgumentListInfo |
| 5415 | TemplateArgumentListInfo ArgInfos; |
| 5416 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 5417 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5418 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5419 | *FromTAArgsAsWritten, ArgInfos)) |
| 5420 | return std::move(Err); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5421 | |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5422 | auto ToTPListOrErr = import(FromPartial->getTemplateParameters()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5423 | if (!ToTPListOrErr) |
| 5424 | return ToTPListOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5425 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5426 | PartVarSpecDecl *ToPartial; |
| 5427 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5428 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, |
| 5429 | VarTemplate, T, *TInfoOrErr, |
| 5430 | D->getStorageClass(), TemplateArgs, ArgInfos)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5431 | return ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5432 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5433 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( |
| 5434 | FromPartial->getInstantiatedFromMember())) |
| 5435 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); |
| 5436 | else |
| 5437 | return ToInstOrErr.takeError(); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5438 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5439 | if (FromPartial->isMemberSpecialization()) |
| 5440 | ToPartial->setMemberSpecialization(); |
| 5441 | |
| 5442 | D2 = ToPartial; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5443 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5444 | } else { // Full specialization |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5445 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, |
| 5446 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, |
| 5447 | T, *TInfoOrErr, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5448 | D->getStorageClass(), TemplateArgs)) |
| 5449 | return D2; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5450 | } |
| 5451 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5452 | if (D->getPointOfInstantiation().isValid()) { |
| 5453 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) |
| 5454 | D2->setPointOfInstantiation(*POIOrErr); |
| 5455 | else |
| 5456 | return POIOrErr.takeError(); |
| 5457 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5458 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5459 | D2->setSpecializationKind(D->getSpecializationKind()); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5460 | D2->setTemplateArgsInfo(ToTAInfo); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5461 | |
| 5462 | // Add this specialization to the class template. |
| 5463 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 5464 | |
| 5465 | // Import the qualifier, if any. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5466 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5467 | D2->setQualifierInfo(*LocOrErr); |
| 5468 | else |
| 5469 | return LocOrErr.takeError(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5470 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5471 | if (D->isConstexpr()) |
| 5472 | D2->setConstexpr(true); |
| 5473 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5474 | // Add the specialization to this context. |
| 5475 | D2->setLexicalDeclContext(LexicalDC); |
| 5476 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5477 | |
| 5478 | D2->setAccess(D->getAccess()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5479 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5480 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5481 | if (Error Err = ImportInitializer(D, D2)) |
| 5482 | return std::move(Err); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5483 | |
| 5484 | return D2; |
| 5485 | } |
| 5486 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5487 | ExpectedDecl |
| 5488 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5489 | DeclContext *DC, *LexicalDC; |
| 5490 | DeclarationName Name; |
| 5491 | SourceLocation Loc; |
| 5492 | NamedDecl *ToD; |
| 5493 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5494 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5495 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5496 | |
| 5497 | if (ToD) |
| 5498 | return ToD; |
| 5499 | |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5500 | const FunctionTemplateDecl *FoundByLookup = nullptr; |
| 5501 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5502 | // Try to find a function in our own ("to") context with the same name, same |
| 5503 | // type, and in the same context as the function we're importing. |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5504 | // FIXME Split this into a separate function. |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5505 | if (!LexicalDC->isFunctionOrMethod()) { |
Gabor Marton | e331e63 | 2019-02-18 13:09:27 +0000 | [diff] [blame] | 5506 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5507 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5508 | for (auto *FoundDecl : FoundDecls) { |
| 5509 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5510 | continue; |
| 5511 | |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5512 | if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
| 5513 | if (FoundTemplate->hasExternalFormalLinkage() && |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5514 | D->hasExternalFormalLinkage()) { |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5515 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5516 | FunctionTemplateDecl *TemplateWithDef = |
| 5517 | getTemplateDefinition(FoundTemplate); |
| 5518 | if (D->isThisDeclarationADefinition() && TemplateWithDef) { |
| 5519 | return Importer.MapImported(D, TemplateWithDef); |
| 5520 | } |
| 5521 | FoundByLookup = FoundTemplate; |
| 5522 | break; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5523 | } |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5524 | // TODO: handle conflicting names |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5525 | } |
| 5526 | } |
| 5527 | } |
| 5528 | } |
| 5529 | |
Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5530 | auto ParamsOrErr = import(D->getTemplateParameters()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5531 | if (!ParamsOrErr) |
| 5532 | return ParamsOrErr.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5533 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5534 | FunctionDecl *TemplatedFD; |
| 5535 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) |
| 5536 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5537 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5538 | FunctionTemplateDecl *ToFunc; |
| 5539 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5540 | *ParamsOrErr, TemplatedFD)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5541 | return ToFunc; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5542 | |
| 5543 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5544 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5545 | ToFunc->setAccess(D->getAccess()); |
| 5546 | ToFunc->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5547 | LexicalDC->addDeclInternal(ToFunc); |
Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5548 | |
| 5549 | if (FoundByLookup) { |
| 5550 | auto *Recent = |
| 5551 | const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5552 | if (!TemplatedFD->getPreviousDecl()) { |
| 5553 | assert(FoundByLookup->getTemplatedDecl() && |
| 5554 | "Found decl must have its templated decl set"); |
| 5555 | auto *PrevTemplated = |
| 5556 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5557 | if (TemplatedFD != PrevTemplated) |
| 5558 | TemplatedFD->setPreviousDecl(PrevTemplated); |
| 5559 | } |
| 5560 | ToFunc->setPreviousDecl(Recent); |
| 5561 | } |
| 5562 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5563 | return ToFunc; |
| 5564 | } |
| 5565 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5566 | //---------------------------------------------------------------------------- |
| 5567 | // Import Statements |
| 5568 | //---------------------------------------------------------------------------- |
| 5569 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5570 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5571 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) |
| 5572 | << S->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5573 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5574 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5575 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5576 | |
| 5577 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 5578 | if (Importer.returnWithErrorInTest()) |
| 5579 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5580 | SmallVector<IdentifierInfo *, 4> Names; |
| 5581 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 5582 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5583 | // ToII is nullptr when no symbolic name is given for output operand |
| 5584 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5585 | Names.push_back(ToII); |
| 5586 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5587 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5588 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 5589 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5590 | // ToII is nullptr when no symbolic name is given for input operand |
| 5591 | // see ParseStmtAsm::ParseAsmOperandsOpt |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5592 | Names.push_back(ToII); |
| 5593 | } |
| 5594 | |
| 5595 | SmallVector<StringLiteral *, 4> Clobbers; |
| 5596 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5597 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) |
| 5598 | Clobbers.push_back(*ClobberOrErr); |
| 5599 | else |
| 5600 | return ClobberOrErr.takeError(); |
| 5601 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5602 | } |
| 5603 | |
| 5604 | SmallVector<StringLiteral *, 4> Constraints; |
| 5605 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5606 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) |
| 5607 | Constraints.push_back(*OutputOrErr); |
| 5608 | else |
| 5609 | return OutputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5610 | } |
| 5611 | |
| 5612 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5613 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) |
| 5614 | Constraints.push_back(*InputOrErr); |
| 5615 | else |
| 5616 | return InputOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5617 | } |
| 5618 | |
Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5619 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() + |
| 5620 | S->getNumLabels()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5621 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) |
| 5622 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5623 | |
Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5624 | if (Error Err = |
| 5625 | ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
| 5626 | return std::move(Err); |
| 5627 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5628 | if (Error Err = ImportArrayChecked( |
Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5629 | S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs())) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5630 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5631 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5632 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); |
| 5633 | if (!AsmLocOrErr) |
| 5634 | return AsmLocOrErr.takeError(); |
| 5635 | auto AsmStrOrErr = import(S->getAsmString()); |
| 5636 | if (!AsmStrOrErr) |
| 5637 | return AsmStrOrErr.takeError(); |
| 5638 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); |
| 5639 | if (!RParenLocOrErr) |
| 5640 | return RParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5641 | |
| 5642 | return new (Importer.getToContext()) GCCAsmStmt( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5643 | Importer.getToContext(), |
| 5644 | *AsmLocOrErr, |
| 5645 | S->isSimple(), |
| 5646 | S->isVolatile(), |
| 5647 | S->getNumOutputs(), |
| 5648 | S->getNumInputs(), |
| 5649 | Names.data(), |
| 5650 | Constraints.data(), |
| 5651 | Exprs.data(), |
| 5652 | *AsmStrOrErr, |
| 5653 | S->getNumClobbers(), |
| 5654 | Clobbers.data(), |
Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5655 | S->getNumLabels(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5656 | *RParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5657 | } |
| 5658 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5659 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 5660 | auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc()); |
| 5661 | if (!Imp) |
| 5662 | return Imp.takeError(); |
| 5663 | |
| 5664 | DeclGroupRef ToDG; |
| 5665 | SourceLocation ToBeginLoc, ToEndLoc; |
| 5666 | std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp; |
| 5667 | |
| 5668 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5669 | } |
| 5670 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5671 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5672 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); |
| 5673 | if (!ToSemiLocOrErr) |
| 5674 | return ToSemiLocOrErr.takeError(); |
| 5675 | return new (Importer.getToContext()) NullStmt( |
| 5676 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5677 | } |
| 5678 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5679 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5680 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5681 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5682 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) |
| 5683 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5684 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5685 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); |
| 5686 | if (!ToLBracLocOrErr) |
| 5687 | return ToLBracLocOrErr.takeError(); |
| 5688 | |
| 5689 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); |
| 5690 | if (!ToRBracLocOrErr) |
| 5691 | return ToRBracLocOrErr.takeError(); |
| 5692 | |
| 5693 | return CompoundStmt::Create( |
| 5694 | Importer.getToContext(), ToStmts, |
| 5695 | *ToLBracLocOrErr, *ToRBracLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5696 | } |
| 5697 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5698 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 5699 | auto Imp = importSeq( |
| 5700 | S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(), |
| 5701 | S->getEllipsisLoc(), S->getColonLoc()); |
| 5702 | if (!Imp) |
| 5703 | return Imp.takeError(); |
| 5704 | |
| 5705 | Expr *ToLHS, *ToRHS; |
| 5706 | Stmt *ToSubStmt; |
| 5707 | SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc; |
| 5708 | std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) = |
| 5709 | *Imp; |
| 5710 | |
Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 5711 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, |
| 5712 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5713 | ToStmt->setSubStmt(ToSubStmt); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5714 | |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5715 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5716 | } |
| 5717 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5718 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 5719 | auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt()); |
| 5720 | if (!Imp) |
| 5721 | return Imp.takeError(); |
| 5722 | |
| 5723 | SourceLocation ToDefaultLoc, ToColonLoc; |
| 5724 | Stmt *ToSubStmt; |
| 5725 | std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp; |
| 5726 | |
| 5727 | return new (Importer.getToContext()) DefaultStmt( |
| 5728 | ToDefaultLoc, ToColonLoc, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5729 | } |
| 5730 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5731 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 5732 | auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt()); |
| 5733 | if (!Imp) |
| 5734 | return Imp.takeError(); |
| 5735 | |
| 5736 | SourceLocation ToIdentLoc; |
| 5737 | LabelDecl *ToLabelDecl; |
| 5738 | Stmt *ToSubStmt; |
| 5739 | std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp; |
| 5740 | |
| 5741 | return new (Importer.getToContext()) LabelStmt( |
| 5742 | ToIdentLoc, ToLabelDecl, ToSubStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5743 | } |
| 5744 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5745 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 5746 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); |
| 5747 | if (!ToAttrLocOrErr) |
| 5748 | return ToAttrLocOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5749 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 5750 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5751 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) |
| 5752 | return std::move(Err); |
| 5753 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 5754 | if (!ToSubStmtOrErr) |
| 5755 | return ToSubStmtOrErr.takeError(); |
| 5756 | |
| 5757 | return AttributedStmt::Create( |
| 5758 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5759 | } |
| 5760 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5761 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 5762 | auto Imp = importSeq( |
| 5763 | S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5764 | S->getThen(), S->getElseLoc(), S->getElse()); |
| 5765 | if (!Imp) |
| 5766 | return Imp.takeError(); |
| 5767 | |
| 5768 | SourceLocation ToIfLoc, ToElseLoc; |
| 5769 | Stmt *ToInit, *ToThen, *ToElse; |
| 5770 | VarDecl *ToConditionVariable; |
| 5771 | Expr *ToCond; |
| 5772 | std::tie( |
| 5773 | ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) = |
| 5774 | *Imp; |
| 5775 | |
Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 5776 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), |
| 5777 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, |
| 5778 | ToElse); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5779 | } |
| 5780 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5781 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
| 5782 | auto Imp = importSeq( |
| 5783 | S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5784 | S->getBody(), S->getSwitchLoc()); |
| 5785 | if (!Imp) |
| 5786 | return Imp.takeError(); |
| 5787 | |
| 5788 | Stmt *ToInit, *ToBody; |
| 5789 | VarDecl *ToConditionVariable; |
| 5790 | Expr *ToCond; |
| 5791 | SourceLocation ToSwitchLoc; |
| 5792 | std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp; |
| 5793 | |
Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 5794 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, |
| 5795 | ToConditionVariable, ToCond); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5796 | ToStmt->setBody(ToBody); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5797 | ToStmt->setSwitchLoc(ToSwitchLoc); |
| 5798 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5799 | // Now we have to re-chain the cases. |
| 5800 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 5801 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 5802 | SC = SC->getNextSwitchCase()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5803 | Expected<SwitchCase *> ToSCOrErr = import(SC); |
| 5804 | if (!ToSCOrErr) |
| 5805 | return ToSCOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5806 | if (LastChainedSwitchCase) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5807 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5808 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5809 | ToStmt->setSwitchCaseList(*ToSCOrErr); |
| 5810 | LastChainedSwitchCase = *ToSCOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5811 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5812 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5813 | return ToStmt; |
| 5814 | } |
| 5815 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5816 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 5817 | auto Imp = importSeq( |
| 5818 | S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc()); |
| 5819 | if (!Imp) |
| 5820 | return Imp.takeError(); |
| 5821 | |
| 5822 | VarDecl *ToConditionVariable; |
| 5823 | Expr *ToCond; |
| 5824 | Stmt *ToBody; |
| 5825 | SourceLocation ToWhileLoc; |
| 5826 | std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp; |
| 5827 | |
Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 5828 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, |
| 5829 | ToBody, ToWhileLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5830 | } |
| 5831 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5832 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 5833 | auto Imp = importSeq( |
| 5834 | S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(), |
| 5835 | S->getRParenLoc()); |
| 5836 | if (!Imp) |
| 5837 | return Imp.takeError(); |
| 5838 | |
| 5839 | Stmt *ToBody; |
| 5840 | Expr *ToCond; |
| 5841 | SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc; |
| 5842 | std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp; |
| 5843 | |
| 5844 | return new (Importer.getToContext()) DoStmt( |
| 5845 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5846 | } |
| 5847 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5848 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 5849 | auto Imp = importSeq( |
| 5850 | S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(), |
| 5851 | S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc()); |
| 5852 | if (!Imp) |
| 5853 | return Imp.takeError(); |
| 5854 | |
| 5855 | Stmt *ToInit; |
| 5856 | Expr *ToCond, *ToInc; |
| 5857 | VarDecl *ToConditionVariable; |
| 5858 | Stmt *ToBody; |
| 5859 | SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc; |
| 5860 | std::tie( |
| 5861 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, |
| 5862 | ToLParenLoc, ToRParenLoc) = *Imp; |
| 5863 | |
| 5864 | return new (Importer.getToContext()) ForStmt( |
| 5865 | Importer.getToContext(), |
| 5866 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, |
| 5867 | ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5868 | } |
| 5869 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5870 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 5871 | auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc()); |
| 5872 | if (!Imp) |
| 5873 | return Imp.takeError(); |
| 5874 | |
| 5875 | LabelDecl *ToLabel; |
| 5876 | SourceLocation ToGotoLoc, ToLabelLoc; |
| 5877 | std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp; |
| 5878 | |
| 5879 | return new (Importer.getToContext()) GotoStmt( |
| 5880 | ToLabel, ToGotoLoc, ToLabelLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5881 | } |
| 5882 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5883 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 5884 | auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget()); |
| 5885 | if (!Imp) |
| 5886 | return Imp.takeError(); |
| 5887 | |
| 5888 | SourceLocation ToGotoLoc, ToStarLoc; |
| 5889 | Expr *ToTarget; |
| 5890 | std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp; |
| 5891 | |
| 5892 | return new (Importer.getToContext()) IndirectGotoStmt( |
| 5893 | ToGotoLoc, ToStarLoc, ToTarget); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5894 | } |
| 5895 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5896 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 5897 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); |
| 5898 | if (!ToContinueLocOrErr) |
| 5899 | return ToContinueLocOrErr.takeError(); |
| 5900 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5901 | } |
| 5902 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5903 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 5904 | auto ToBreakLocOrErr = import(S->getBreakLoc()); |
| 5905 | if (!ToBreakLocOrErr) |
| 5906 | return ToBreakLocOrErr.takeError(); |
| 5907 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5908 | } |
| 5909 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5910 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 5911 | auto Imp = importSeq( |
| 5912 | S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate()); |
| 5913 | if (!Imp) |
| 5914 | return Imp.takeError(); |
| 5915 | |
| 5916 | SourceLocation ToReturnLoc; |
| 5917 | Expr *ToRetValue; |
| 5918 | const VarDecl *ToNRVOCandidate; |
| 5919 | std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp; |
| 5920 | |
Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 5921 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, |
| 5922 | ToNRVOCandidate); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5923 | } |
| 5924 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5925 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 5926 | auto Imp = importSeq( |
| 5927 | S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock()); |
| 5928 | if (!Imp) |
| 5929 | return Imp.takeError(); |
| 5930 | |
| 5931 | SourceLocation ToCatchLoc; |
| 5932 | VarDecl *ToExceptionDecl; |
| 5933 | Stmt *ToHandlerBlock; |
| 5934 | std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp; |
| 5935 | |
| 5936 | return new (Importer.getToContext()) CXXCatchStmt ( |
| 5937 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5938 | } |
| 5939 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5940 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 5941 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); |
| 5942 | if (!ToTryLocOrErr) |
| 5943 | return ToTryLocOrErr.takeError(); |
| 5944 | |
| 5945 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); |
| 5946 | if (!ToTryBlockOrErr) |
| 5947 | return ToTryBlockOrErr.takeError(); |
| 5948 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5949 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 5950 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 5951 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5952 | if (auto ToHandlerOrErr = import(FromHandler)) |
| 5953 | ToHandlers[HI] = *ToHandlerOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5954 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5955 | return ToHandlerOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5956 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5957 | |
| 5958 | return CXXTryStmt::Create( |
| 5959 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5960 | } |
| 5961 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5962 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| 5963 | auto Imp1 = importSeq( |
| 5964 | S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(), |
| 5965 | S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody()); |
| 5966 | if (!Imp1) |
| 5967 | return Imp1.takeError(); |
| 5968 | auto Imp2 = importSeq( |
| 5969 | S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc()); |
| 5970 | if (!Imp2) |
| 5971 | return Imp2.takeError(); |
| 5972 | |
| 5973 | DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt; |
| 5974 | Expr *ToCond, *ToInc; |
| 5975 | Stmt *ToInit, *ToBody; |
| 5976 | std::tie( |
| 5977 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5978 | ToBody) = *Imp1; |
| 5979 | SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc; |
| 5980 | std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2; |
| 5981 | |
| 5982 | return new (Importer.getToContext()) CXXForRangeStmt( |
| 5983 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5984 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5985 | } |
| 5986 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5987 | ExpectedStmt |
| 5988 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 5989 | auto Imp = importSeq( |
| 5990 | S->getElement(), S->getCollection(), S->getBody(), |
| 5991 | S->getForLoc(), S->getRParenLoc()); |
| 5992 | if (!Imp) |
| 5993 | return Imp.takeError(); |
| 5994 | |
| 5995 | Stmt *ToElement, *ToBody; |
| 5996 | Expr *ToCollection; |
| 5997 | SourceLocation ToForLoc, ToRParenLoc; |
| 5998 | std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp; |
| 5999 | |
| 6000 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, |
| 6001 | ToCollection, |
| 6002 | ToBody, |
| 6003 | ToForLoc, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6004 | ToRParenLoc); |
| 6005 | } |
| 6006 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6007 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 6008 | auto Imp = importSeq( |
| 6009 | S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(), |
| 6010 | S->getCatchBody()); |
| 6011 | if (!Imp) |
| 6012 | return Imp.takeError(); |
| 6013 | |
| 6014 | SourceLocation ToAtCatchLoc, ToRParenLoc; |
| 6015 | VarDecl *ToCatchParamDecl; |
| 6016 | Stmt *ToCatchBody; |
| 6017 | std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp; |
| 6018 | |
| 6019 | return new (Importer.getToContext()) ObjCAtCatchStmt ( |
| 6020 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6021 | } |
| 6022 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6023 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 6024 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); |
| 6025 | if (!ToAtFinallyLocOrErr) |
| 6026 | return ToAtFinallyLocOrErr.takeError(); |
| 6027 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); |
| 6028 | if (!ToAtFinallyStmtOrErr) |
| 6029 | return ToAtFinallyStmtOrErr.takeError(); |
| 6030 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, |
| 6031 | *ToAtFinallyStmtOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6032 | } |
| 6033 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6034 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 6035 | auto Imp = importSeq( |
| 6036 | S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt()); |
| 6037 | if (!Imp) |
| 6038 | return Imp.takeError(); |
| 6039 | |
| 6040 | SourceLocation ToAtTryLoc; |
| 6041 | Stmt *ToTryBody, *ToFinallyStmt; |
| 6042 | std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp; |
| 6043 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6044 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 6045 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 6046 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6047 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) |
| 6048 | ToCatchStmts[CI] = *ToCatchStmtOrErr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6049 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6050 | return ToCatchStmtOrErr.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6051 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6052 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6053 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6054 | ToAtTryLoc, ToTryBody, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6055 | ToCatchStmts.begin(), ToCatchStmts.size(), |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6056 | ToFinallyStmt); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6057 | } |
| 6058 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6059 | ExpectedStmt ASTNodeImporter::VisitObjCAtSynchronizedStmt |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6060 | (ObjCAtSynchronizedStmt *S) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6061 | auto Imp = importSeq( |
| 6062 | S->getAtSynchronizedLoc(), S->getSynchExpr(), S->getSynchBody()); |
| 6063 | if (!Imp) |
| 6064 | return Imp.takeError(); |
| 6065 | |
| 6066 | SourceLocation ToAtSynchronizedLoc; |
| 6067 | Expr *ToSynchExpr; |
| 6068 | Stmt *ToSynchBody; |
| 6069 | std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp; |
| 6070 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6071 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 6072 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 6073 | } |
| 6074 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6075 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 6076 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); |
| 6077 | if (!ToThrowLocOrErr) |
| 6078 | return ToThrowLocOrErr.takeError(); |
| 6079 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); |
| 6080 | if (!ToThrowExprOrErr) |
| 6081 | return ToThrowExprOrErr.takeError(); |
| 6082 | return new (Importer.getToContext()) ObjCAtThrowStmt( |
| 6083 | *ToThrowLocOrErr, *ToThrowExprOrErr); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6084 | } |
| 6085 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6086 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( |
| 6087 | ObjCAutoreleasePoolStmt *S) { |
| 6088 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); |
| 6089 | if (!ToAtLocOrErr) |
| 6090 | return ToAtLocOrErr.takeError(); |
| 6091 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 6092 | if (!ToSubStmtOrErr) |
| 6093 | return ToSubStmtOrErr.takeError(); |
| 6094 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, |
| 6095 | *ToSubStmtOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6096 | } |
| 6097 | |
| 6098 | //---------------------------------------------------------------------------- |
| 6099 | // Import Expressions |
| 6100 | //---------------------------------------------------------------------------- |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6101 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { |
Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6102 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) |
| 6103 | << E->getStmtClassName(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6104 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6105 | } |
| 6106 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6107 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 6108 | auto Imp = importSeq( |
| 6109 | E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(), |
| 6110 | E->getRParenLoc(), E->getType()); |
| 6111 | if (!Imp) |
| 6112 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6113 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6114 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6115 | Expr *ToSubExpr; |
| 6116 | TypeSourceInfo *ToWrittenTypeInfo; |
| 6117 | QualType ToType; |
| 6118 | std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) = |
| 6119 | *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6120 | |
| 6121 | return new (Importer.getToContext()) VAArgExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6122 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, |
| 6123 | E->isMicrosoftABI()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6124 | } |
| 6125 | |
Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6126 | ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) { |
| 6127 | auto Imp = importSeq(E->getCond(), E->getLHS(), E->getRHS(), |
| 6128 | E->getBuiltinLoc(), E->getRParenLoc(), E->getType()); |
| 6129 | if (!Imp) |
| 6130 | return Imp.takeError(); |
| 6131 | |
| 6132 | Expr *ToCond; |
| 6133 | Expr *ToLHS; |
| 6134 | Expr *ToRHS; |
| 6135 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6136 | QualType ToType; |
| 6137 | std::tie(ToCond, ToLHS, ToRHS, ToBuiltinLoc, ToRParenLoc, ToType) = *Imp; |
| 6138 | |
| 6139 | ExprValueKind VK = E->getValueKind(); |
| 6140 | ExprObjectKind OK = E->getObjectKind(); |
| 6141 | |
| 6142 | bool TypeDependent = ToCond->isTypeDependent(); |
| 6143 | bool ValueDependent = ToCond->isValueDependent(); |
| 6144 | |
| 6145 | // The value of CondIsTrue only matters if the value is not |
| 6146 | // condition-dependent. |
| 6147 | bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue(); |
| 6148 | |
| 6149 | return new (Importer.getToContext()) |
| 6150 | ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK, |
| 6151 | ToRParenLoc, CondIsTrue, TypeDependent, ValueDependent); |
| 6152 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6153 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6154 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 6155 | ExpectedType TypeOrErr = import(E->getType()); |
| 6156 | if (!TypeOrErr) |
| 6157 | return TypeOrErr.takeError(); |
| 6158 | |
| 6159 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); |
| 6160 | if (!BeginLocOrErr) |
| 6161 | return BeginLocOrErr.takeError(); |
| 6162 | |
| 6163 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6164 | } |
| 6165 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6166 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 6167 | auto Imp = importSeq( |
| 6168 | E->getBeginLoc(), E->getType(), E->getFunctionName()); |
| 6169 | if (!Imp) |
| 6170 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6171 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6172 | SourceLocation ToBeginLoc; |
| 6173 | QualType ToType; |
| 6174 | StringLiteral *ToFunctionName; |
| 6175 | std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6176 | |
Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 6177 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, |
| 6178 | E->getIdentKind(), ToFunctionName); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6179 | } |
| 6180 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6181 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
| 6182 | auto Imp = importSeq( |
| 6183 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDecl(), |
| 6184 | E->getLocation(), E->getType()); |
| 6185 | if (!Imp) |
| 6186 | return Imp.takeError(); |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6187 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6188 | NestedNameSpecifierLoc ToQualifierLoc; |
| 6189 | SourceLocation ToTemplateKeywordLoc, ToLocation; |
| 6190 | ValueDecl *ToDecl; |
| 6191 | QualType ToType; |
| 6192 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) = |
| 6193 | *Imp; |
| 6194 | |
| 6195 | NamedDecl *ToFoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6196 | if (E->getDecl() != E->getFoundDecl()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6197 | auto FoundDOrErr = import(E->getFoundDecl()); |
| 6198 | if (!FoundDOrErr) |
| 6199 | return FoundDOrErr.takeError(); |
| 6200 | ToFoundD = *FoundDOrErr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6201 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6202 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6203 | TemplateArgumentListInfo ToTAInfo; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6204 | TemplateArgumentListInfo *ToResInfo = nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6205 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6206 | if (Error Err = |
| 6207 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6208 | return std::move(Err); |
| 6209 | ToResInfo = &ToTAInfo; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6210 | } |
| 6211 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6212 | auto *ToE = DeclRefExpr::Create( |
| 6213 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, |
| 6214 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, |
Richard Smith | 715f7a1 | 2019-06-11 17:50:32 +0000 | [diff] [blame] | 6215 | E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse()); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 6216 | if (E->hadMultipleCandidates()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6217 | ToE->setHadMultipleCandidates(true); |
| 6218 | return ToE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 6219 | } |
| 6220 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6221 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 6222 | ExpectedType TypeOrErr = import(E->getType()); |
| 6223 | if (!TypeOrErr) |
| 6224 | return TypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6225 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6226 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6227 | } |
| 6228 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6229 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 6230 | ExpectedExpr ToInitOrErr = import(E->getInit()); |
| 6231 | if (!ToInitOrErr) |
| 6232 | return ToInitOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6233 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6234 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); |
| 6235 | if (!ToEqualOrColonLocOrErr) |
| 6236 | return ToEqualOrColonLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6237 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6238 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6239 | // List elements from the second, the first is Init itself |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6240 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { |
| 6241 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) |
| 6242 | ToIndexExprs[I - 1] = *ToArgOrErr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6243 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6244 | return ToArgOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6245 | } |
| 6246 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6247 | SmallVector<Designator, 4> ToDesignators(E->size()); |
| 6248 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) |
| 6249 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6250 | |
| 6251 | return DesignatedInitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6252 | Importer.getToContext(), ToDesignators, |
| 6253 | ToIndexExprs, *ToEqualOrColonLocOrErr, |
| 6254 | E->usesGNUSyntax(), *ToInitOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6255 | } |
| 6256 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6257 | ExpectedStmt |
| 6258 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 6259 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6260 | if (!ToTypeOrErr) |
| 6261 | return ToTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6262 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6263 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6264 | if (!ToLocationOrErr) |
| 6265 | return ToLocationOrErr.takeError(); |
| 6266 | |
| 6267 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( |
| 6268 | *ToTypeOrErr, *ToLocationOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6269 | } |
| 6270 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6271 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 6272 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6273 | if (!ToTypeOrErr) |
| 6274 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6275 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6276 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6277 | if (!ToLocationOrErr) |
| 6278 | return ToLocationOrErr.takeError(); |
| 6279 | |
| 6280 | return IntegerLiteral::Create( |
| 6281 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6282 | } |
| 6283 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6284 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6285 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 6286 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6287 | if (!ToTypeOrErr) |
| 6288 | return ToTypeOrErr.takeError(); |
| 6289 | |
| 6290 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6291 | if (!ToLocationOrErr) |
| 6292 | return ToLocationOrErr.takeError(); |
| 6293 | |
| 6294 | return FloatingLiteral::Create( |
| 6295 | Importer.getToContext(), E->getValue(), E->isExact(), |
| 6296 | *ToTypeOrErr, *ToLocationOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6297 | } |
| 6298 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6299 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 6300 | auto ToTypeOrErr = import(E->getType()); |
| 6301 | if (!ToTypeOrErr) |
| 6302 | return ToTypeOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6303 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6304 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6305 | if (!ToSubExprOrErr) |
| 6306 | return ToSubExprOrErr.takeError(); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6307 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6308 | return new (Importer.getToContext()) ImaginaryLiteral( |
| 6309 | *ToSubExprOrErr, *ToTypeOrErr); |
Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6310 | } |
| 6311 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6312 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 6313 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6314 | if (!ToTypeOrErr) |
| 6315 | return ToTypeOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6316 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6317 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6318 | if (!ToLocationOrErr) |
| 6319 | return ToLocationOrErr.takeError(); |
| 6320 | |
| 6321 | return new (Importer.getToContext()) CharacterLiteral( |
| 6322 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 6323 | } |
| 6324 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6325 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 6326 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6327 | if (!ToTypeOrErr) |
| 6328 | return ToTypeOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6329 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6330 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); |
| 6331 | if (Error Err = ImportArrayChecked( |
| 6332 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) |
| 6333 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6334 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6335 | return StringLiteral::Create( |
| 6336 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), |
| 6337 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6338 | } |
| 6339 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6340 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 6341 | auto Imp = importSeq( |
| 6342 | E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(), |
| 6343 | E->getInitializer()); |
| 6344 | if (!Imp) |
| 6345 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6346 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6347 | SourceLocation ToLParenLoc; |
| 6348 | TypeSourceInfo *ToTypeSourceInfo; |
| 6349 | QualType ToType; |
| 6350 | Expr *ToInitializer; |
| 6351 | std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6352 | |
| 6353 | return new (Importer.getToContext()) CompoundLiteralExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6354 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), |
| 6355 | ToInitializer, E->isFileScope()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6356 | } |
| 6357 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6358 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 6359 | auto Imp = importSeq( |
| 6360 | E->getBuiltinLoc(), E->getType(), E->getRParenLoc()); |
| 6361 | if (!Imp) |
| 6362 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6363 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6364 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6365 | QualType ToType; |
| 6366 | std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp; |
| 6367 | |
| 6368 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); |
| 6369 | if (Error Err = ImportArrayChecked( |
| 6370 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 6371 | ToExprs.begin())) |
| 6372 | return std::move(Err); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6373 | |
| 6374 | return new (Importer.getToContext()) AtomicExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6375 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6376 | } |
| 6377 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6378 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 6379 | auto Imp = importSeq( |
| 6380 | E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType()); |
| 6381 | if (!Imp) |
| 6382 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6383 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6384 | SourceLocation ToAmpAmpLoc, ToLabelLoc; |
| 6385 | LabelDecl *ToLabel; |
| 6386 | QualType ToType; |
| 6387 | std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6388 | |
| 6389 | return new (Importer.getToContext()) AddrLabelExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6390 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6391 | } |
| 6392 | |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6393 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { |
| 6394 | auto Imp = importSeq(E->getSubExpr()); |
| 6395 | if (!Imp) |
| 6396 | return Imp.takeError(); |
| 6397 | |
| 6398 | Expr *ToSubExpr; |
| 6399 | std::tie(ToSubExpr) = *Imp; |
| 6400 | |
Gauthier Harnisch | 83c7b61 | 2019-06-15 10:24:47 +0000 | [diff] [blame] | 6401 | // TODO : Handle APValue::ValueKind that require importing. |
| 6402 | APValue::ValueKind Kind = E->getResultAPValueKind(); |
| 6403 | if (Kind == APValue::Int || Kind == APValue::Float || |
| 6404 | Kind == APValue::FixedPoint || Kind == APValue::ComplexFloat || |
| 6405 | Kind == APValue::ComplexInt) |
| 6406 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, |
| 6407 | E->getAPValueResult()); |
Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 6408 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr); |
Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6409 | } |
| 6410 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6411 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 6412 | auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr()); |
| 6413 | if (!Imp) |
| 6414 | return Imp.takeError(); |
| 6415 | |
| 6416 | SourceLocation ToLParen, ToRParen; |
| 6417 | Expr *ToSubExpr; |
| 6418 | std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6419 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6420 | return new (Importer.getToContext()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6421 | ParenExpr(ToLParen, ToRParen, ToSubExpr); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6422 | } |
| 6423 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6424 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 6425 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); |
| 6426 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) |
| 6427 | return std::move(Err); |
| 6428 | |
| 6429 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); |
| 6430 | if (!ToLParenLocOrErr) |
| 6431 | return ToLParenLocOrErr.takeError(); |
| 6432 | |
| 6433 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); |
| 6434 | if (!ToRParenLocOrErr) |
| 6435 | return ToRParenLocOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6436 | |
Bruno Ricci | f49e1ca | 2018-11-20 16:20:40 +0000 | [diff] [blame] | 6437 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, |
| 6438 | ToExprs, *ToRParenLocOrErr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6439 | } |
| 6440 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6441 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 6442 | auto Imp = importSeq( |
| 6443 | E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc()); |
| 6444 | if (!Imp) |
| 6445 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6446 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6447 | CompoundStmt *ToSubStmt; |
| 6448 | QualType ToType; |
| 6449 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 6450 | std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp; |
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 | return new (Importer.getToContext()) StmtExpr( |
| 6453 | ToSubStmt, ToType, ToLParenLoc, ToRParenLoc); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6454 | } |
| 6455 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6456 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 6457 | auto Imp = importSeq( |
| 6458 | E->getSubExpr(), E->getType(), E->getOperatorLoc()); |
| 6459 | if (!Imp) |
| 6460 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6461 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6462 | Expr *ToSubExpr; |
| 6463 | QualType ToType; |
| 6464 | SourceLocation ToOperatorLoc; |
| 6465 | std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6466 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6467 | return new (Importer.getToContext()) UnaryOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6468 | ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), |
| 6469 | ToOperatorLoc, E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6470 | } |
| 6471 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6472 | ExpectedStmt |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6473 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6474 | auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc()); |
| 6475 | if (!Imp) |
| 6476 | return Imp.takeError(); |
| 6477 | |
| 6478 | QualType ToType; |
| 6479 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6480 | std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6481 | |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6482 | if (E->isArgumentType()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6483 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = |
| 6484 | import(E->getArgumentTypeInfo()); |
| 6485 | if (!ToArgumentTypeInfoOrErr) |
| 6486 | return ToArgumentTypeInfoOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6487 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6488 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6489 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, |
| 6490 | ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6491 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6492 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6493 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); |
| 6494 | if (!ToArgumentExprOrErr) |
| 6495 | return ToArgumentExprOrErr.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6496 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6497 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6498 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6499 | } |
| 6500 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6501 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 6502 | auto Imp = importSeq( |
| 6503 | E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc()); |
| 6504 | if (!Imp) |
| 6505 | return Imp.takeError(); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6506 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6507 | Expr *ToLHS, *ToRHS; |
| 6508 | QualType ToType; |
| 6509 | SourceLocation ToOperatorLoc; |
| 6510 | std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6511 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6512 | return new (Importer.getToContext()) BinaryOperator( |
| 6513 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6514 | E->getObjectKind(), ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6515 | } |
| 6516 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6517 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 6518 | auto Imp = importSeq( |
| 6519 | E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(), |
| 6520 | E->getRHS(), E->getType()); |
| 6521 | if (!Imp) |
| 6522 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6523 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6524 | Expr *ToCond, *ToLHS, *ToRHS; |
| 6525 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6526 | QualType ToType; |
| 6527 | std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6528 | |
| 6529 | return new (Importer.getToContext()) ConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6530 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, |
| 6531 | E->getValueKind(), E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6532 | } |
| 6533 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6534 | ExpectedStmt ASTNodeImporter::VisitBinaryConditionalOperator( |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6535 | BinaryConditionalOperator *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6536 | auto Imp = importSeq( |
| 6537 | E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(), |
| 6538 | E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType()); |
| 6539 | if (!Imp) |
| 6540 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6541 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6542 | Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr; |
| 6543 | OpaqueValueExpr *ToOpaqueValue; |
| 6544 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6545 | QualType ToType; |
| 6546 | std::tie( |
| 6547 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc, |
| 6548 | ToColonLoc, ToType) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6549 | |
| 6550 | return new (Importer.getToContext()) BinaryConditionalOperator( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6551 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, |
| 6552 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), |
| 6553 | E->getObjectKind()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6554 | } |
| 6555 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6556 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 6557 | auto Imp = importSeq( |
| 6558 | E->getBeginLoc(), E->getQueriedTypeSourceInfo(), |
| 6559 | E->getDimensionExpression(), E->getEndLoc(), E->getType()); |
| 6560 | if (!Imp) |
| 6561 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6562 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6563 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6564 | TypeSourceInfo *ToQueriedTypeSourceInfo; |
| 6565 | Expr *ToDimensionExpression; |
| 6566 | QualType ToType; |
| 6567 | std::tie( |
| 6568 | ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc, |
| 6569 | ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6570 | |
| 6571 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6572 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), |
| 6573 | ToDimensionExpression, ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6574 | } |
| 6575 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6576 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 6577 | auto Imp = importSeq( |
| 6578 | E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType()); |
| 6579 | if (!Imp) |
| 6580 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6581 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6582 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6583 | Expr *ToQueriedExpression; |
| 6584 | QualType ToType; |
| 6585 | std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6586 | |
| 6587 | return new (Importer.getToContext()) ExpressionTraitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6588 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), |
| 6589 | ToEndLoc, ToType); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6590 | } |
| 6591 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6592 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6593 | auto Imp = importSeq( |
| 6594 | E->getLocation(), E->getType(), E->getSourceExpr()); |
| 6595 | if (!Imp) |
| 6596 | return Imp.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6597 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6598 | SourceLocation ToLocation; |
| 6599 | QualType ToType; |
| 6600 | Expr *ToSourceExpr; |
| 6601 | std::tie(ToLocation, ToType, ToSourceExpr) = *Imp; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6602 | |
| 6603 | return new (Importer.getToContext()) OpaqueValueExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6604 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6605 | } |
| 6606 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6607 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 6608 | auto Imp = importSeq( |
| 6609 | E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc()); |
| 6610 | if (!Imp) |
| 6611 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6612 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6613 | Expr *ToLHS, *ToRHS; |
| 6614 | SourceLocation ToRBracketLoc; |
| 6615 | QualType ToType; |
| 6616 | std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6617 | |
| 6618 | return new (Importer.getToContext()) ArraySubscriptExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6619 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), |
| 6620 | ToRBracketLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6621 | } |
| 6622 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6623 | ExpectedStmt |
| 6624 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 6625 | auto Imp = importSeq( |
| 6626 | E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(), |
| 6627 | E->getComputationResultType(), E->getOperatorLoc()); |
| 6628 | if (!Imp) |
| 6629 | return Imp.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6630 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6631 | Expr *ToLHS, *ToRHS; |
| 6632 | QualType ToType, ToComputationLHSType, ToComputationResultType; |
| 6633 | SourceLocation ToOperatorLoc; |
| 6634 | std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType, |
| 6635 | ToOperatorLoc) = *Imp; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6636 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6637 | return new (Importer.getToContext()) CompoundAssignOperator( |
| 6638 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6639 | E->getObjectKind(), ToComputationLHSType, ToComputationResultType, |
| 6640 | ToOperatorLoc, E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6641 | } |
| 6642 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6643 | Expected<CXXCastPath> |
| 6644 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { |
| 6645 | CXXCastPath Path; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6646 | 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] | 6647 | if (auto SpecOrErr = import(*I)) |
| 6648 | Path.push_back(*SpecOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6649 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6650 | return SpecOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6651 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6652 | return Path; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6653 | } |
| 6654 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6655 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 6656 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6657 | if (!ToTypeOrErr) |
| 6658 | return ToTypeOrErr.takeError(); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6659 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6660 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6661 | if (!ToSubExprOrErr) |
| 6662 | return ToSubExprOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6663 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6664 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6665 | if (!ToBasePathOrErr) |
| 6666 | return ToBasePathOrErr.takeError(); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6667 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6668 | return ImplicitCastExpr::Create( |
| 6669 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, |
| 6670 | &(*ToBasePathOrErr), E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6671 | } |
| 6672 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6673 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 6674 | auto Imp1 = importSeq( |
| 6675 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten()); |
| 6676 | if (!Imp1) |
| 6677 | return Imp1.takeError(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6678 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6679 | QualType ToType; |
| 6680 | Expr *ToSubExpr; |
| 6681 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 6682 | std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6683 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6684 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6685 | if (!ToBasePathOrErr) |
| 6686 | return ToBasePathOrErr.takeError(); |
| 6687 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6688 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6689 | switch (E->getStmtClass()) { |
| 6690 | case Stmt::CStyleCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6691 | auto *CCE = cast<CStyleCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6692 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); |
| 6693 | if (!ToLParenLocOrErr) |
| 6694 | return ToLParenLocOrErr.takeError(); |
| 6695 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); |
| 6696 | if (!ToRParenLocOrErr) |
| 6697 | return ToRParenLocOrErr.takeError(); |
| 6698 | return CStyleCastExpr::Create( |
| 6699 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), |
| 6700 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, |
| 6701 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6702 | } |
| 6703 | |
| 6704 | case Stmt::CXXFunctionalCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6705 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6706 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); |
| 6707 | if (!ToLParenLocOrErr) |
| 6708 | return ToLParenLocOrErr.takeError(); |
| 6709 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); |
| 6710 | if (!ToRParenLocOrErr) |
| 6711 | return ToRParenLocOrErr.takeError(); |
| 6712 | return CXXFunctionalCastExpr::Create( |
| 6713 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, |
| 6714 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, |
| 6715 | *ToRParenLocOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6716 | } |
| 6717 | |
| 6718 | case Stmt::ObjCBridgedCastExprClass: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6719 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
| 6720 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); |
| 6721 | if (!ToLParenLocOrErr) |
| 6722 | return ToLParenLocOrErr.takeError(); |
| 6723 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); |
| 6724 | if (!ToBridgeKeywordLocOrErr) |
| 6725 | return ToBridgeKeywordLocOrErr.takeError(); |
| 6726 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 6727 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), |
| 6728 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6729 | } |
| 6730 | default: |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6731 | llvm_unreachable("Cast expression of unsupported type!"); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6732 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6733 | } |
| 6734 | } |
| 6735 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6736 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { |
| 6737 | SmallVector<OffsetOfNode, 4> ToNodes; |
| 6738 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { |
| 6739 | const OffsetOfNode &FromNode = E->getComponent(I); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6740 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6741 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6742 | if (FromNode.getKind() != OffsetOfNode::Base) { |
| 6743 | auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc()); |
| 6744 | if (!Imp) |
| 6745 | return Imp.takeError(); |
| 6746 | std::tie(ToBeginLoc, ToEndLoc) = *Imp; |
| 6747 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6748 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6749 | switch (FromNode.getKind()) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6750 | case OffsetOfNode::Array: |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6751 | ToNodes.push_back( |
| 6752 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6753 | break; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6754 | case OffsetOfNode::Base: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6755 | auto ToBSOrErr = import(FromNode.getBase()); |
| 6756 | if (!ToBSOrErr) |
| 6757 | return ToBSOrErr.takeError(); |
| 6758 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6759 | break; |
| 6760 | } |
| 6761 | case OffsetOfNode::Field: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6762 | auto ToFieldOrErr = import(FromNode.getField()); |
| 6763 | if (!ToFieldOrErr) |
| 6764 | return ToFieldOrErr.takeError(); |
| 6765 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6766 | break; |
| 6767 | } |
| 6768 | case OffsetOfNode::Identifier: { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6769 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); |
| 6770 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6771 | break; |
| 6772 | } |
| 6773 | } |
| 6774 | } |
| 6775 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6776 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); |
| 6777 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { |
| 6778 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); |
| 6779 | if (!ToIndexExprOrErr) |
| 6780 | return ToIndexExprOrErr.takeError(); |
| 6781 | ToExprs[I] = *ToIndexExprOrErr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6782 | } |
| 6783 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6784 | auto Imp = importSeq( |
| 6785 | E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(), |
| 6786 | E->getRParenLoc()); |
| 6787 | if (!Imp) |
| 6788 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6789 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6790 | QualType ToType; |
| 6791 | TypeSourceInfo *ToTypeSourceInfo; |
| 6792 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6793 | std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp; |
| 6794 | |
| 6795 | return OffsetOfExpr::Create( |
| 6796 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, |
| 6797 | ToExprs, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6798 | } |
| 6799 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6800 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 6801 | auto Imp = importSeq( |
| 6802 | E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc()); |
| 6803 | if (!Imp) |
| 6804 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6805 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6806 | QualType ToType; |
| 6807 | Expr *ToOperand; |
| 6808 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6809 | std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6810 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6811 | CanThrowResult ToCanThrow; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6812 | if (E->isValueDependent()) |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6813 | ToCanThrow = CT_Dependent; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6814 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6815 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6816 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6817 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 6818 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6819 | } |
| 6820 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6821 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 6822 | auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc()); |
| 6823 | if (!Imp) |
| 6824 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6825 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6826 | Expr *ToSubExpr; |
| 6827 | QualType ToType; |
| 6828 | SourceLocation ToThrowLoc; |
| 6829 | std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6830 | |
| 6831 | return new (Importer.getToContext()) CXXThrowExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6832 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6833 | } |
| 6834 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6835 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 6836 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); |
| 6837 | if (!ToUsedLocOrErr) |
| 6838 | return ToUsedLocOrErr.takeError(); |
| 6839 | |
| 6840 | auto ToParamOrErr = import(E->getParam()); |
| 6841 | if (!ToParamOrErr) |
| 6842 | return ToParamOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6843 | |
Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 6844 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); |
| 6845 | if (!UsedContextOrErr) |
| 6846 | return UsedContextOrErr.takeError(); |
| 6847 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6848 | return CXXDefaultArgExpr::Create( |
Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 6849 | Importer.getToContext(), *ToUsedLocOrErr, *ToParamOrErr, *UsedContextOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6850 | } |
| 6851 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6852 | ExpectedStmt |
| 6853 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 6854 | auto Imp = importSeq( |
| 6855 | E->getType(), E->getTypeSourceInfo(), E->getRParenLoc()); |
| 6856 | if (!Imp) |
| 6857 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6858 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6859 | QualType ToType; |
| 6860 | TypeSourceInfo *ToTypeSourceInfo; |
| 6861 | SourceLocation ToRParenLoc; |
| 6862 | std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6863 | |
| 6864 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6865 | ToType, ToTypeSourceInfo, ToRParenLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6866 | } |
| 6867 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6868 | ExpectedStmt |
| 6869 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 6870 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6871 | if (!ToSubExprOrErr) |
| 6872 | return ToSubExprOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6873 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6874 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); |
| 6875 | if (!ToDtorOrErr) |
| 6876 | return ToDtorOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6877 | |
| 6878 | ASTContext &ToCtx = Importer.getToContext(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6879 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); |
| 6880 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6881 | } |
| 6882 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6883 | ExpectedStmt |
| 6884 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { |
| 6885 | auto Imp = importSeq( |
| 6886 | E->getConstructor(), E->getType(), E->getTypeSourceInfo(), |
| 6887 | E->getParenOrBraceRange()); |
| 6888 | if (!Imp) |
| 6889 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6890 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6891 | CXXConstructorDecl *ToConstructor; |
| 6892 | QualType ToType; |
| 6893 | TypeSourceInfo *ToTypeSourceInfo; |
| 6894 | SourceRange ToParenOrBraceRange; |
| 6895 | std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6896 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6897 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); |
| 6898 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 6899 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6900 | |
Bruno Ricci | ddb8f6b | 2018-12-22 14:39:30 +0000 | [diff] [blame] | 6901 | return CXXTemporaryObjectExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6902 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, |
| 6903 | ToParenOrBraceRange, E->hadMultipleCandidates(), |
| 6904 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 6905 | E->requiresZeroInitialization()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6906 | } |
| 6907 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6908 | ExpectedStmt |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6909 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6910 | auto Imp = importSeq( |
| 6911 | E->getType(), E->GetTemporaryExpr(), E->getExtendingDecl()); |
| 6912 | if (!Imp) |
| 6913 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6914 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6915 | QualType ToType; |
| 6916 | Expr *ToTemporaryExpr; |
| 6917 | const ValueDecl *ToExtendingDecl; |
| 6918 | std::tie(ToType, ToTemporaryExpr, ToExtendingDecl) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6919 | |
| 6920 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6921 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6922 | |
| 6923 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6924 | ToMTE->setExtendingDecl(ToExtendingDecl, E->getManglingNumber()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6925 | return ToMTE; |
| 6926 | } |
| 6927 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6928 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 6929 | auto Imp = importSeq( |
| 6930 | E->getType(), E->getPattern(), E->getEllipsisLoc()); |
| 6931 | if (!Imp) |
| 6932 | return Imp.takeError(); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6933 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6934 | QualType ToType; |
| 6935 | Expr *ToPattern; |
| 6936 | SourceLocation ToEllipsisLoc; |
| 6937 | std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6938 | |
| 6939 | return new (Importer.getToContext()) PackExpansionExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6940 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6941 | } |
| 6942 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6943 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 6944 | auto Imp = importSeq( |
| 6945 | E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc()); |
| 6946 | if (!Imp) |
| 6947 | return Imp.takeError(); |
| 6948 | |
| 6949 | SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc; |
| 6950 | NamedDecl *ToPack; |
| 6951 | std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6952 | |
| 6953 | Optional<unsigned> Length; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6954 | if (!E->isValueDependent()) |
| 6955 | Length = E->getPackLength(); |
| 6956 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6957 | SmallVector<TemplateArgument, 8> ToPartialArguments; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6958 | if (E->isPartiallySubstituted()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6959 | if (Error Err = ImportTemplateArguments( |
| 6960 | E->getPartialArguments().data(), |
| 6961 | E->getPartialArguments().size(), |
| 6962 | ToPartialArguments)) |
| 6963 | return std::move(Err); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6964 | } |
| 6965 | |
| 6966 | return SizeOfPackExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6967 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, |
| 6968 | Length, ToPartialArguments); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6969 | } |
| 6970 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6971 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6972 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { |
| 6973 | auto Imp = importSeq( |
| 6974 | E->getOperatorNew(), E->getOperatorDelete(), E->getTypeIdParens(), |
| 6975 | E->getArraySize(), E->getInitializer(), E->getType(), |
| 6976 | E->getAllocatedTypeSourceInfo(), E->getSourceRange(), |
| 6977 | E->getDirectInitRange()); |
| 6978 | if (!Imp) |
| 6979 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6980 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6981 | FunctionDecl *ToOperatorNew, *ToOperatorDelete; |
| 6982 | SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange; |
Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 6983 | Optional<Expr *> ToArraySize; |
| 6984 | Expr *ToInitializer; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6985 | QualType ToType; |
| 6986 | TypeSourceInfo *ToAllocatedTypeSourceInfo; |
| 6987 | std::tie( |
| 6988 | ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer, |
| 6989 | ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6990 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6991 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); |
| 6992 | if (Error Err = |
| 6993 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) |
| 6994 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6995 | |
Bruno Ricci | 9b6dfac | 2019-01-07 15:04:45 +0000 | [diff] [blame] | 6996 | return CXXNewExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6997 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, |
| 6998 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), |
| 6999 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), |
| 7000 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, |
| 7001 | ToDirectInitRange); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7002 | } |
| 7003 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7004 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 7005 | auto Imp = importSeq( |
| 7006 | E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc()); |
| 7007 | if (!Imp) |
| 7008 | return Imp.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7009 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7010 | QualType ToType; |
| 7011 | FunctionDecl *ToOperatorDelete; |
| 7012 | Expr *ToArgument; |
| 7013 | SourceLocation ToBeginLoc; |
| 7014 | std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7015 | |
| 7016 | return new (Importer.getToContext()) CXXDeleteExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7017 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), |
| 7018 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, |
| 7019 | ToBeginLoc); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 7020 | } |
| 7021 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7022 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 7023 | auto Imp = importSeq( |
| 7024 | E->getType(), E->getLocation(), E->getConstructor(), |
| 7025 | E->getParenOrBraceRange()); |
| 7026 | if (!Imp) |
| 7027 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7028 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7029 | QualType ToType; |
| 7030 | SourceLocation ToLocation; |
| 7031 | CXXConstructorDecl *ToConstructor; |
| 7032 | SourceRange ToParenOrBraceRange; |
| 7033 | std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7034 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7035 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7036 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7037 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7038 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7039 | return CXXConstructExpr::Create( |
| 7040 | Importer.getToContext(), ToType, ToLocation, ToConstructor, |
| 7041 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), |
| 7042 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 7043 | E->requiresZeroInitialization(), E->getConstructionKind(), |
| 7044 | ToParenOrBraceRange); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7045 | } |
| 7046 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7047 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { |
| 7048 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7049 | if (!ToSubExprOrErr) |
| 7050 | return ToSubExprOrErr.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7051 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7052 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); |
| 7053 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) |
| 7054 | return std::move(Err); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7055 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7056 | return ExprWithCleanups::Create( |
| 7057 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), |
| 7058 | ToObjects); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7059 | } |
| 7060 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7061 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 7062 | auto Imp = importSeq( |
| 7063 | E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7064 | if (!Imp) |
| 7065 | return Imp.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7066 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7067 | Expr *ToCallee; |
| 7068 | QualType ToType; |
| 7069 | SourceLocation ToRParenLoc; |
| 7070 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7071 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7072 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7073 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7074 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7075 | |
Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7076 | return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, |
| 7077 | ToType, E->getValueKind(), ToRParenLoc); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7078 | } |
| 7079 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7080 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 7081 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7082 | if (!ToTypeOrErr) |
| 7083 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7084 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7085 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7086 | if (!ToLocationOrErr) |
| 7087 | return ToLocationOrErr.takeError(); |
| 7088 | |
| 7089 | return new (Importer.getToContext()) CXXThisExpr( |
| 7090 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7091 | } |
| 7092 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7093 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 7094 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7095 | if (!ToTypeOrErr) |
| 7096 | return ToTypeOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7097 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7098 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 7099 | if (!ToLocationOrErr) |
| 7100 | return ToLocationOrErr.takeError(); |
| 7101 | |
| 7102 | return new (Importer.getToContext()) CXXBoolLiteralExpr( |
| 7103 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7104 | } |
| 7105 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7106 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 7107 | auto Imp1 = importSeq( |
| 7108 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7109 | E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType()); |
| 7110 | if (!Imp1) |
| 7111 | return Imp1.takeError(); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7112 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7113 | Expr *ToBase; |
| 7114 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7115 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7116 | ValueDecl *ToMemberDecl; |
| 7117 | QualType ToType; |
| 7118 | std::tie( |
| 7119 | ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, |
| 7120 | ToType) = *Imp1; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7121 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7122 | auto Imp2 = importSeq( |
| 7123 | E->getFoundDecl().getDecl(), E->getMemberNameInfo().getName(), |
| 7124 | E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7125 | if (!Imp2) |
| 7126 | return Imp2.takeError(); |
| 7127 | NamedDecl *ToDecl; |
| 7128 | DeclarationName ToName; |
| 7129 | SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc; |
| 7130 | std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2; |
Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 7131 | |
| 7132 | DeclAccessPair ToFoundDecl = |
| 7133 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7134 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7135 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7136 | |
Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7137 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7138 | if (E->hasExplicitTemplateArgs()) { |
Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7139 | if (Error Err = |
| 7140 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 7141 | E->template_arguments(), ToTAInfo)) |
| 7142 | return std::move(Err); |
| 7143 | ResInfo = &ToTAInfo; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7144 | } |
| 7145 | |
Richard Smith | 1bbad59 | 2019-06-11 17:50:36 +0000 | [diff] [blame] | 7146 | return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(), |
| 7147 | ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7148 | ToMemberDecl, ToFoundDecl, ToMemberNameInfo, |
| 7149 | ResInfo, ToType, E->getValueKind(), |
| 7150 | E->getObjectKind(), E->isNonOdrUse()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7151 | } |
| 7152 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7153 | ExpectedStmt |
| 7154 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { |
| 7155 | auto Imp = importSeq( |
| 7156 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7157 | E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc()); |
| 7158 | if (!Imp) |
| 7159 | return Imp.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7160 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7161 | Expr *ToBase; |
| 7162 | SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc; |
| 7163 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7164 | TypeSourceInfo *ToScopeTypeInfo; |
| 7165 | std::tie( |
| 7166 | ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, |
| 7167 | ToTildeLoc) = *Imp; |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7168 | |
| 7169 | PseudoDestructorTypeStorage Storage; |
| 7170 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 7171 | IdentifierInfo *ToII = Importer.Import(FromII); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7172 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); |
| 7173 | if (!ToDestroyedTypeLocOrErr) |
| 7174 | return ToDestroyedTypeLocOrErr.takeError(); |
| 7175 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7176 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7177 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) |
| 7178 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); |
| 7179 | else |
| 7180 | return ToTIOrErr.takeError(); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7181 | } |
| 7182 | |
| 7183 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7184 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7185 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7186 | } |
| 7187 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7188 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7189 | CXXDependentScopeMemberExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7190 | auto Imp = importSeq( |
| 7191 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7192 | E->getTemplateKeywordLoc(), E->getFirstQualifierFoundInScope()); |
| 7193 | if (!Imp) |
| 7194 | return Imp.takeError(); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7195 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7196 | QualType ToType; |
| 7197 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7198 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7199 | NamedDecl *ToFirstQualifierFoundInScope; |
| 7200 | std::tie( |
| 7201 | ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7202 | ToFirstQualifierFoundInScope) = *Imp; |
| 7203 | |
| 7204 | Expr *ToBase = nullptr; |
| 7205 | if (!E->isImplicitAccess()) { |
| 7206 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7207 | ToBase = *ToBaseOrErr; |
| 7208 | else |
| 7209 | return ToBaseOrErr.takeError(); |
| 7210 | } |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7211 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7212 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7213 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7214 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7215 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7216 | ToTAInfo)) |
| 7217 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7218 | ResInfo = &ToTAInfo; |
| 7219 | } |
| 7220 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7221 | auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc()); |
| 7222 | if (!ToMemberNameInfoOrErr) |
| 7223 | return ToMemberNameInfoOrErr.takeError(); |
| 7224 | DeclarationNameInfo ToMemberNameInfo( |
| 7225 | std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr)); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7226 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7227 | if (Error Err = ImportDeclarationNameLoc( |
| 7228 | E->getMemberNameInfo(), ToMemberNameInfo)) |
| 7229 | return std::move(Err); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7230 | |
| 7231 | return CXXDependentScopeMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7232 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, |
| 7233 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, |
| 7234 | ToMemberNameInfo, ResInfo); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7235 | } |
| 7236 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7237 | ExpectedStmt |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7238 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7239 | auto Imp = importSeq( |
| 7240 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDeclName(), |
| 7241 | E->getExprLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7242 | if (!Imp) |
| 7243 | return Imp.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7244 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7245 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7246 | SourceLocation ToTemplateKeywordLoc, ToExprLoc, ToLAngleLoc, ToRAngleLoc; |
| 7247 | DeclarationName ToDeclName; |
| 7248 | std::tie( |
| 7249 | ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToExprLoc, |
| 7250 | ToLAngleLoc, ToRAngleLoc) = *Imp; |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7251 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7252 | DeclarationNameInfo ToNameInfo(ToDeclName, ToExprLoc); |
| 7253 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7254 | return std::move(Err); |
| 7255 | |
| 7256 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7257 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7258 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7259 | if (Error Err = |
| 7260 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7261 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7262 | ResInfo = &ToTAInfo; |
| 7263 | } |
| 7264 | |
| 7265 | return DependentScopeDeclRefExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7266 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, |
| 7267 | ToNameInfo, ResInfo); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7268 | } |
| 7269 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7270 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 7271 | CXXUnresolvedConstructExpr *E) { |
| 7272 | auto Imp = importSeq( |
| 7273 | E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo()); |
| 7274 | if (!Imp) |
| 7275 | return Imp.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7276 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7277 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 7278 | TypeSourceInfo *ToTypeSourceInfo; |
| 7279 | std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp; |
| 7280 | |
| 7281 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); |
| 7282 | if (Error Err = |
| 7283 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) |
| 7284 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7285 | |
| 7286 | return CXXUnresolvedConstructExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7287 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, |
| 7288 | llvm::makeArrayRef(ToArgs), ToRParenLoc); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7289 | } |
| 7290 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7291 | ExpectedStmt |
| 7292 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
| 7293 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); |
| 7294 | if (!ToNamingClassOrErr) |
| 7295 | return ToNamingClassOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7296 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7297 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); |
| 7298 | if (!ToQualifierLocOrErr) |
| 7299 | return ToQualifierLocOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7300 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7301 | auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc()); |
| 7302 | if (!ToNameInfoOrErr) |
| 7303 | return ToNameInfoOrErr.takeError(); |
| 7304 | DeclarationNameInfo ToNameInfo( |
| 7305 | std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7306 | // Import additional name location/type info. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7307 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7308 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7309 | |
| 7310 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7311 | for (auto *D : E->decls()) |
| 7312 | if (auto ToDOrErr = import(D)) |
| 7313 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7314 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7315 | return ToDOrErr.takeError(); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7316 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7317 | if (E->hasExplicitTemplateArgs() && E->getTemplateKeywordLoc().isValid()) { |
| 7318 | TemplateArgumentListInfo ToTAInfo; |
| 7319 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7320 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7321 | ToTAInfo)) |
| 7322 | return std::move(Err); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7323 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7324 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); |
| 7325 | if (!ToTemplateKeywordLocOrErr) |
| 7326 | return ToTemplateKeywordLocOrErr.takeError(); |
| 7327 | |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7328 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7329 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7330 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, |
| 7331 | ToDecls.begin(), ToDecls.end()); |
| 7332 | } |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7333 | |
| 7334 | return UnresolvedLookupExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7335 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7336 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), |
| 7337 | ToDecls.end()); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7338 | } |
| 7339 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7340 | ExpectedStmt |
| 7341 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 7342 | auto Imp1 = importSeq( |
| 7343 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7344 | E->getTemplateKeywordLoc()); |
| 7345 | if (!Imp1) |
| 7346 | return Imp1.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7347 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7348 | QualType ToType; |
| 7349 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7350 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7351 | std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1; |
| 7352 | |
| 7353 | auto Imp2 = importSeq(E->getName(), E->getNameLoc()); |
| 7354 | if (!Imp2) |
| 7355 | return Imp2.takeError(); |
| 7356 | DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2)); |
| 7357 | // Import additional name location/type info. |
| 7358 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7359 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7360 | |
| 7361 | UnresolvedSet<8> ToDecls; |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7362 | for (Decl *D : E->decls()) |
| 7363 | if (auto ToDOrErr = import(D)) |
| 7364 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7365 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7366 | return ToDOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7367 | |
| 7368 | TemplateArgumentListInfo ToTAInfo; |
| 7369 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7370 | if (E->hasExplicitTemplateArgs()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7371 | if (Error Err = |
| 7372 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7373 | return std::move(Err); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7374 | ResInfo = &ToTAInfo; |
| 7375 | } |
| 7376 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7377 | Expr *ToBase = nullptr; |
| 7378 | if (!E->isImplicitAccess()) { |
| 7379 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7380 | ToBase = *ToBaseOrErr; |
| 7381 | else |
| 7382 | return ToBaseOrErr.takeError(); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7383 | } |
| 7384 | |
| 7385 | return UnresolvedMemberExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7386 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, |
| 7387 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7388 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7389 | } |
| 7390 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7391 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 7392 | auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7393 | if (!Imp) |
| 7394 | return Imp.takeError(); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7395 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7396 | Expr *ToCallee; |
| 7397 | QualType ToType; |
| 7398 | SourceLocation ToRParenLoc; |
| 7399 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7400 | |
| 7401 | unsigned NumArgs = E->getNumArgs(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7402 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 7403 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7404 | return std::move(Err); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7405 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7406 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7407 | return CXXOperatorCallExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7408 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, |
Eric Fiselier | 5cdc2cd | 2018-12-12 21:50:55 +0000 | [diff] [blame] | 7409 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), |
| 7410 | OCE->getADLCallKind()); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7411 | } |
| 7412 | |
Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7413 | return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType, |
| 7414 | E->getValueKind(), ToRParenLoc, /*MinNumArgs=*/0, |
| 7415 | E->getADLCallKind()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7416 | } |
| 7417 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7418 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { |
| 7419 | CXXRecordDecl *FromClass = E->getLambdaClass(); |
| 7420 | auto ToClassOrErr = import(FromClass); |
| 7421 | if (!ToClassOrErr) |
| 7422 | return ToClassOrErr.takeError(); |
| 7423 | CXXRecordDecl *ToClass = *ToClassOrErr; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7424 | |
| 7425 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 7426 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 7427 | // manually. |
Gabor Marton | 302f300 | 2019-02-15 12:04:05 +0000 | [diff] [blame] | 7428 | if (ToClass->isBeingDefined()) |
| 7429 | if (Error Err = ImportDeclContext(FromClass, /*ForceImport = */ true)) |
| 7430 | return std::move(Err); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7431 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7432 | auto ToCallOpOrErr = import(E->getCallOperator()); |
| 7433 | if (!ToCallOpOrErr) |
| 7434 | return ToCallOpOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7435 | |
| 7436 | ToClass->completeDefinition(); |
| 7437 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7438 | SmallVector<LambdaCapture, 8> ToCaptures; |
| 7439 | ToCaptures.reserve(E->capture_size()); |
| 7440 | for (const auto &FromCapture : E->captures()) { |
| 7441 | if (auto ToCaptureOrErr = import(FromCapture)) |
| 7442 | ToCaptures.push_back(*ToCaptureOrErr); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7443 | else |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7444 | return ToCaptureOrErr.takeError(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7445 | } |
| 7446 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7447 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); |
| 7448 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) |
| 7449 | return std::move(Err); |
| 7450 | |
| 7451 | auto Imp = importSeq( |
| 7452 | E->getIntroducerRange(), E->getCaptureDefaultLoc(), E->getEndLoc()); |
| 7453 | if (!Imp) |
| 7454 | return Imp.takeError(); |
| 7455 | |
| 7456 | SourceRange ToIntroducerRange; |
| 7457 | SourceLocation ToCaptureDefaultLoc, ToEndLoc; |
| 7458 | std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7459 | |
Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7460 | return LambdaExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7461 | Importer.getToContext(), ToClass, ToIntroducerRange, |
| 7462 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, |
| 7463 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, |
| 7464 | ToEndLoc, E->containsUnexpandedParameterPack()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7465 | } |
| 7466 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7467 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7468 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { |
| 7469 | auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType()); |
| 7470 | if (!Imp) |
| 7471 | return Imp.takeError(); |
| 7472 | |
| 7473 | SourceLocation ToLBraceLoc, ToRBraceLoc; |
| 7474 | QualType ToType; |
| 7475 | std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp; |
| 7476 | |
| 7477 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); |
| 7478 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) |
| 7479 | return std::move(Err); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7480 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7481 | ASTContext &ToCtx = Importer.getToContext(); |
| 7482 | InitListExpr *To = new (ToCtx) InitListExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7483 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); |
| 7484 | To->setType(ToType); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7485 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7486 | if (E->hasArrayFiller()) { |
| 7487 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) |
| 7488 | To->setArrayFiller(*ToFillerOrErr); |
| 7489 | else |
| 7490 | return ToFillerOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7491 | } |
| 7492 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7493 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { |
| 7494 | if (auto ToFDOrErr = import(FromFD)) |
| 7495 | To->setInitializedFieldInUnion(*ToFDOrErr); |
| 7496 | else |
| 7497 | return ToFDOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7498 | } |
| 7499 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7500 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { |
| 7501 | if (auto ToSyntFormOrErr = import(SyntForm)) |
| 7502 | To->setSyntacticForm(*ToSyntFormOrErr); |
| 7503 | else |
| 7504 | return ToSyntFormOrErr.takeError(); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7505 | } |
| 7506 | |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7507 | // Copy InitListExprBitfields, which are not handled in the ctor of |
| 7508 | // InitListExpr. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7509 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7510 | |
| 7511 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7512 | } |
| 7513 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7514 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7515 | CXXStdInitializerListExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7516 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7517 | if (!ToTypeOrErr) |
| 7518 | return ToTypeOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7519 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7520 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7521 | if (!ToSubExprOrErr) |
| 7522 | return ToSubExprOrErr.takeError(); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7523 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7524 | return new (Importer.getToContext()) CXXStdInitializerListExpr( |
| 7525 | *ToTypeOrErr, *ToSubExprOrErr); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7526 | } |
| 7527 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7528 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7529 | CXXInheritedCtorInitExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7530 | auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor()); |
| 7531 | if (!Imp) |
| 7532 | return Imp.takeError(); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7533 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7534 | SourceLocation ToLocation; |
| 7535 | QualType ToType; |
| 7536 | CXXConstructorDecl *ToConstructor; |
| 7537 | std::tie(ToLocation, ToType, ToConstructor) = *Imp; |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7538 | |
| 7539 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7540 | ToLocation, ToType, ToConstructor, E->constructsVBase(), |
| 7541 | E->inheritedFromVBase()); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7542 | } |
| 7543 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7544 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 7545 | auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr()); |
| 7546 | if (!Imp) |
| 7547 | return Imp.takeError(); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7548 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7549 | QualType ToType; |
| 7550 | Expr *ToCommonExpr, *ToSubExpr; |
| 7551 | std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp; |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7552 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7553 | return new (Importer.getToContext()) ArrayInitLoopExpr( |
| 7554 | ToType, ToCommonExpr, ToSubExpr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7555 | } |
| 7556 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7557 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 7558 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7559 | if (!ToTypeOrErr) |
| 7560 | return ToTypeOrErr.takeError(); |
| 7561 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7562 | } |
| 7563 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7564 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7565 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); |
| 7566 | if (!ToBeginLocOrErr) |
| 7567 | return ToBeginLocOrErr.takeError(); |
| 7568 | |
| 7569 | auto ToFieldOrErr = import(E->getField()); |
| 7570 | if (!ToFieldOrErr) |
| 7571 | return ToFieldOrErr.takeError(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7572 | |
Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7573 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); |
| 7574 | if (!UsedContextOrErr) |
| 7575 | return UsedContextOrErr.takeError(); |
| 7576 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7577 | return CXXDefaultInitExpr::Create( |
Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7578 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr, *UsedContextOrErr); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7579 | } |
| 7580 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7581 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 7582 | auto Imp = importSeq( |
| 7583 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(), |
| 7584 | E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets()); |
| 7585 | if (!Imp) |
| 7586 | return Imp.takeError(); |
| 7587 | |
| 7588 | QualType ToType; |
| 7589 | Expr *ToSubExpr; |
| 7590 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 7591 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 7592 | SourceRange ToAngleBrackets; |
| 7593 | std::tie( |
| 7594 | ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, |
| 7595 | ToAngleBrackets) = *Imp; |
| 7596 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7597 | ExprValueKind VK = E->getValueKind(); |
| 7598 | CastKind CK = E->getCastKind(); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7599 | auto ToBasePathOrErr = ImportCastPath(E); |
| 7600 | if (!ToBasePathOrErr) |
| 7601 | return ToBasePathOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7602 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7603 | if (isa<CXXStaticCastExpr>(E)) { |
| 7604 | return CXXStaticCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7605 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7606 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7607 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 7608 | return CXXDynamicCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7609 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7610 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7611 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 7612 | return CXXReinterpretCastExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7613 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7614 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 7615 | } else if (isa<CXXConstCastExpr>(E)) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7616 | return CXXConstCastExpr::Create( |
| 7617 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, |
| 7618 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7619 | } else { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7620 | llvm_unreachable("Unknown cast type"); |
| 7621 | return make_error<ImportError>(); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7622 | } |
| 7623 | } |
| 7624 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7625 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7626 | SubstNonTypeTemplateParmExpr *E) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7627 | auto Imp = importSeq( |
| 7628 | E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement()); |
| 7629 | if (!Imp) |
| 7630 | return Imp.takeError(); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7631 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7632 | QualType ToType; |
| 7633 | SourceLocation ToExprLoc; |
| 7634 | NonTypeTemplateParmDecl *ToParameter; |
| 7635 | Expr *ToReplacement; |
| 7636 | std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7637 | |
| 7638 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7639 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7640 | } |
| 7641 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7642 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 7643 | auto Imp = importSeq( |
| 7644 | E->getType(), E->getBeginLoc(), E->getEndLoc()); |
| 7645 | if (!Imp) |
| 7646 | return Imp.takeError(); |
| 7647 | |
| 7648 | QualType ToType; |
| 7649 | SourceLocation ToBeginLoc, ToEndLoc; |
| 7650 | std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp; |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7651 | |
| 7652 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7653 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) |
| 7654 | return std::move(Err); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7655 | |
| 7656 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 7657 | // Value is always false. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7658 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7659 | |
| 7660 | return TypeTraitExpr::Create( |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7661 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, |
| 7662 | ToEndLoc, ToValue); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7663 | } |
| 7664 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7665 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 7666 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7667 | if (!ToTypeOrErr) |
| 7668 | return ToTypeOrErr.takeError(); |
| 7669 | |
| 7670 | auto ToSourceRangeOrErr = import(E->getSourceRange()); |
| 7671 | if (!ToSourceRangeOrErr) |
| 7672 | return ToSourceRangeOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7673 | |
| 7674 | if (E->isTypeOperand()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7675 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) |
| 7676 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7677 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); |
| 7678 | else |
| 7679 | return ToTSIOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7680 | } |
| 7681 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7682 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); |
| 7683 | if (!ToExprOperandOrErr) |
| 7684 | return ToExprOperandOrErr.takeError(); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7685 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7686 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7687 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7688 | } |
| 7689 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7690 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 7691 | CXXMethodDecl *FromMethod) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7692 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { |
| 7693 | if (auto ImportedOrErr = import(FromOverriddenMethod)) |
| 7694 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( |
| 7695 | (*ImportedOrErr)->getCanonicalDecl())); |
| 7696 | else |
| 7697 | consumeError(ImportedOrErr.takeError()); |
| 7698 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7699 | } |
| 7700 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7701 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7702 | ASTContext &FromContext, FileManager &FromFileManager, |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7703 | bool MinimalImport, |
| 7704 | ASTImporterLookupTable *LookupTable) |
| 7705 | : LookupTable(LookupTable), ToContext(ToContext), FromContext(FromContext), |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7706 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| 7707 | Minimal(MinimalImport) { |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7708 | |
| 7709 | ImportedDecls[FromContext.getTranslationUnitDecl()] = |
| 7710 | ToContext.getTranslationUnitDecl(); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7711 | } |
| 7712 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7713 | ASTImporter::~ASTImporter() = default; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7714 | |
Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7715 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { |
| 7716 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && |
| 7717 | "Try to get field index for non-field."); |
| 7718 | |
| 7719 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 7720 | if (!Owner) |
| 7721 | return None; |
| 7722 | |
| 7723 | unsigned Index = 0; |
| 7724 | for (const auto *D : Owner->decls()) { |
| 7725 | if (D == F) |
| 7726 | return Index; |
| 7727 | |
| 7728 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 7729 | ++Index; |
| 7730 | } |
| 7731 | |
| 7732 | llvm_unreachable("Field was not found in its parent context."); |
| 7733 | |
| 7734 | return None; |
| 7735 | } |
| 7736 | |
| 7737 | ASTImporter::FoundDeclsTy |
| 7738 | ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) { |
| 7739 | // We search in the redecl context because of transparent contexts. |
| 7740 | // E.g. a simple C language enum is a transparent context: |
| 7741 | // enum E { A, B }; |
| 7742 | // Now if we had a global variable in the TU |
| 7743 | // int A; |
| 7744 | // then the enum constant 'A' and the variable 'A' violates ODR. |
| 7745 | // We can diagnose this only if we search in the redecl context. |
| 7746 | DeclContext *ReDC = DC->getRedeclContext(); |
| 7747 | if (LookupTable) { |
| 7748 | ASTImporterLookupTable::LookupResult LookupResult = |
| 7749 | LookupTable->lookup(ReDC, Name); |
| 7750 | return FoundDeclsTy(LookupResult.begin(), LookupResult.end()); |
| 7751 | } else { |
| 7752 | // FIXME Can we remove this kind of lookup? |
| 7753 | // Or lldb really needs this C/C++ lookup? |
| 7754 | FoundDeclsTy Result; |
| 7755 | ReDC->localUncachedLookup(Name, Result); |
| 7756 | return Result; |
| 7757 | } |
| 7758 | } |
| 7759 | |
| 7760 | void ASTImporter::AddToLookupTable(Decl *ToD) { |
| 7761 | if (LookupTable) |
| 7762 | if (auto *ToND = dyn_cast<NamedDecl>(ToD)) |
| 7763 | LookupTable->add(ToND); |
| 7764 | } |
| 7765 | |
Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7766 | Expected<Decl *> ASTImporter::ImportImpl(Decl *FromD) { |
| 7767 | // Import the decl using ASTNodeImporter. |
| 7768 | ASTNodeImporter Importer(*this); |
| 7769 | return Importer.Visit(FromD); |
| 7770 | } |
| 7771 | |
| 7772 | void ASTImporter::RegisterImportedDecl(Decl *FromD, Decl *ToD) { |
| 7773 | MapImported(FromD, ToD); |
Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7774 | } |
| 7775 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7776 | Expected<QualType> ASTImporter::Import(QualType FromT) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7777 | if (FromT.isNull()) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7778 | return QualType{}; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7779 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7780 | const Type *FromTy = FromT.getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7781 | |
| 7782 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7783 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7784 | = ImportedTypes.find(FromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7785 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7786 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7787 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7788 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7789 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7790 | ExpectedType ToTOrErr = Importer.Visit(FromTy); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7791 | if (!ToTOrErr) |
| 7792 | return ToTOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7793 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7794 | // Record the imported type. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7795 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7796 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7797 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7798 | } |
| 7799 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7800 | Expected<TypeSourceInfo *> ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7801 | if (!FromTSI) |
| 7802 | return FromTSI; |
| 7803 | |
| 7804 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 7805 | // 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] | 7806 | ExpectedType TOrErr = Import(FromTSI->getType()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7807 | if (!TOrErr) |
| 7808 | return TOrErr.takeError(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7809 | ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7810 | if (!BeginLocOrErr) |
| 7811 | return BeginLocOrErr.takeError(); |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7812 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7813 | return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr); |
| 7814 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7815 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7816 | Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) { |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7817 | Attr *ToAttr = FromAttr->clone(ToContext); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7818 | if (auto ToRangeOrErr = Import(FromAttr->getRange())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7819 | ToAttr->setRange(*ToRangeOrErr); |
| 7820 | else |
| 7821 | return ToRangeOrErr.takeError(); |
| 7822 | |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7823 | return ToAttr; |
Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 7824 | } |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 7825 | |
Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 7826 | Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { |
| 7827 | auto Pos = ImportedDecls.find(FromD); |
| 7828 | if (Pos != ImportedDecls.end()) |
| 7829 | return Pos->second; |
| 7830 | else |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7831 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7832 | } |
| 7833 | |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 7834 | TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) { |
| 7835 | auto FromDPos = ImportedFromDecls.find(ToD); |
| 7836 | if (FromDPos == ImportedFromDecls.end()) |
| 7837 | return nullptr; |
| 7838 | return FromDPos->second->getTranslationUnitDecl(); |
| 7839 | } |
| 7840 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7841 | Expected<Decl *> ASTImporter::Import(Decl *FromD) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7842 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7843 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7844 | |
Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 7845 | // Push FromD to the stack, and remove that when we return. |
| 7846 | ImportPath.push(FromD); |
| 7847 | auto ImportPathBuilder = |
| 7848 | llvm::make_scope_exit([this]() { ImportPath.pop(); }); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7849 | |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 7850 | // Check whether there was a previous failed import. |
| 7851 | // If yes return the existing error. |
| 7852 | if (auto Error = getImportDeclErrorIfAny(FromD)) |
| 7853 | return make_error<ImportError>(*Error); |
| 7854 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7855 | // Check whether we've already imported this declaration. |
| 7856 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 7857 | if (ToD) { |
| 7858 | // If FromD has some updated flags after last import, apply it |
| 7859 | updateFlags(FromD, ToD); |
Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 7860 | // If we encounter a cycle during an import then we save the relevant part |
| 7861 | // of the import path associated to the Decl. |
| 7862 | if (ImportPath.hasCycleAtBack()) |
| 7863 | SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7864 | return ToD; |
| 7865 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7866 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7867 | // Import the declaration. |
Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7868 | ExpectedDecl ToDOrErr = ImportImpl(FromD); |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 7869 | if (!ToDOrErr) { |
| 7870 | // Failed to import. |
| 7871 | |
| 7872 | auto Pos = ImportedDecls.find(FromD); |
| 7873 | if (Pos != ImportedDecls.end()) { |
| 7874 | // Import failed after the object was created. |
| 7875 | // Remove all references to it. |
| 7876 | auto *ToD = Pos->second; |
| 7877 | ImportedDecls.erase(Pos); |
| 7878 | |
| 7879 | // ImportedDecls and ImportedFromDecls are not symmetric. It may happen |
| 7880 | // (e.g. with namespaces) that several decls from the 'from' context are |
| 7881 | // mapped to the same decl in the 'to' context. If we removed entries |
| 7882 | // from the LookupTable here then we may end up removing them multiple |
| 7883 | // times. |
| 7884 | |
| 7885 | // The Lookuptable contains decls only which are in the 'to' context. |
| 7886 | // Remove from the Lookuptable only if it is *imported* into the 'to' |
| 7887 | // context (and do not remove it if it was added during the initial |
| 7888 | // traverse of the 'to' context). |
| 7889 | auto PosF = ImportedFromDecls.find(ToD); |
| 7890 | if (PosF != ImportedFromDecls.end()) { |
| 7891 | if (LookupTable) |
| 7892 | if (auto *ToND = dyn_cast<NamedDecl>(ToD)) |
| 7893 | LookupTable->remove(ToND); |
| 7894 | ImportedFromDecls.erase(PosF); |
| 7895 | } |
| 7896 | |
| 7897 | // FIXME: AST may contain remaining references to the failed object. |
| 7898 | } |
| 7899 | |
Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 7900 | // After takeError the error is not usable anymore in ToDOrErr. |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 7901 | // Get a copy of the error object (any more simple solution for this?). |
| 7902 | ImportError ErrOut; |
| 7903 | handleAllErrors(ToDOrErr.takeError(), |
| 7904 | [&ErrOut](const ImportError &E) { ErrOut = E; }); |
| 7905 | setImportDeclError(FromD, ErrOut); |
Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 7906 | |
| 7907 | // Set the error for all nodes which have been created before we |
| 7908 | // recognized the error. |
| 7909 | for (const auto &Path : SavedImportPaths[FromD]) |
| 7910 | for (Decl *Di : Path) |
| 7911 | setImportDeclError(Di, ErrOut); |
| 7912 | SavedImportPaths[FromD].clear(); |
| 7913 | |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 7914 | // Do not return ToDOrErr, error was taken out of it. |
| 7915 | return make_error<ImportError>(ErrOut); |
| 7916 | } |
| 7917 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7918 | ToD = *ToDOrErr; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7919 | |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 7920 | // FIXME: Handle the "already imported with error" case. We can get here |
| 7921 | // nullptr only if GetImportedOrCreateDecl returned nullptr (after a |
| 7922 | // previously failed create was requested). |
| 7923 | // Later GetImportedOrCreateDecl can be updated to return the error. |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 7924 | if (!ToD) { |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 7925 | auto Err = getImportDeclErrorIfAny(FromD); |
| 7926 | assert(Err); |
| 7927 | return make_error<ImportError>(*Err); |
Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 7928 | } |
| 7929 | |
Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7930 | // Make sure that ImportImpl registered the imported decl. |
| 7931 | assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?"); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7932 | // Notify subclasses. |
| 7933 | Imported(FromD, ToD); |
| 7934 | |
Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 7935 | updateFlags(FromD, ToD); |
Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 7936 | SavedImportPaths[FromD].clear(); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7937 | return ToDOrErr; |
| 7938 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7939 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7940 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7941 | if (!FromDC) |
| 7942 | return FromDC; |
| 7943 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7944 | ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC)); |
Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 7945 | if (!ToDCOrErr) |
| 7946 | return ToDCOrErr.takeError(); |
| 7947 | auto *ToDC = cast<DeclContext>(*ToDCOrErr); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7948 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7949 | // 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] | 7950 | // need it to have a definition. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7951 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 7952 | auto *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7953 | if (ToRecord->isCompleteDefinition()) { |
| 7954 | // Do nothing. |
| 7955 | } else if (FromRecord->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7956 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7957 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) |
| 7958 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7959 | } else { |
| 7960 | CompleteDecl(ToRecord); |
| 7961 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7962 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 7963 | auto *FromEnum = cast<EnumDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7964 | if (ToEnum->isCompleteDefinition()) { |
| 7965 | // Do nothing. |
| 7966 | } else if (FromEnum->isCompleteDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7967 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7968 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) |
| 7969 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7970 | } else { |
| 7971 | CompleteDecl(ToEnum); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7972 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7973 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 7974 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7975 | if (ToClass->getDefinition()) { |
| 7976 | // Do nothing. |
| 7977 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7978 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7979 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) |
| 7980 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7981 | } else { |
| 7982 | CompleteDecl(ToClass); |
| 7983 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7984 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 7985 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7986 | if (ToProto->getDefinition()) { |
| 7987 | // Do nothing. |
| 7988 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7989 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7990 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) |
| 7991 | return std::move(Err); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7992 | } else { |
| 7993 | CompleteDecl(ToProto); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7994 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7995 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7996 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7997 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7998 | } |
| 7999 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8000 | Expected<Expr *> ASTImporter::Import(Expr *FromE) { |
| 8001 | if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE))) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8002 | return cast_or_null<Expr>(*ToSOrErr); |
| 8003 | else |
| 8004 | return ToSOrErr.takeError(); |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8005 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8006 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8007 | Expected<Stmt *> ASTImporter::Import(Stmt *FromS) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8008 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8009 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8010 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8011 | // Check whether we've already imported this statement. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 8012 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 8013 | if (Pos != ImportedStmts.end()) |
| 8014 | return Pos->second; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8015 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8016 | // Import the statement. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 8017 | ASTNodeImporter Importer(*this); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8018 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8019 | if (!ToSOrErr) |
| 8020 | return ToSOrErr; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8021 | |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8022 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { |
Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 8023 | auto *FromE = cast<Expr>(FromS); |
| 8024 | // Copy ExprBitfields, which may not be handled in Expr subclasses |
| 8025 | // constructors. |
| 8026 | ToE->setValueKind(FromE->getValueKind()); |
| 8027 | ToE->setObjectKind(FromE->getObjectKind()); |
| 8028 | ToE->setTypeDependent(FromE->isTypeDependent()); |
| 8029 | ToE->setValueDependent(FromE->isValueDependent()); |
| 8030 | ToE->setInstantiationDependent(FromE->isInstantiationDependent()); |
| 8031 | ToE->setContainsUnexpandedParameterPack( |
| 8032 | FromE->containsUnexpandedParameterPack()); |
| 8033 | } |
| 8034 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8035 | // Record the imported statement object. |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8036 | ImportedStmts[FromS] = *ToSOrErr; |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8037 | return ToSOrErr; |
| 8038 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8039 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8040 | Expected<NestedNameSpecifier *> |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8041 | ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8042 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8043 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8044 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8045 | NestedNameSpecifier *Prefix; |
| 8046 | if (Error Err = importInto(Prefix, FromNNS->getPrefix())) |
| 8047 | return std::move(Err); |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8048 | |
| 8049 | switch (FromNNS->getKind()) { |
| 8050 | case NestedNameSpecifier::Identifier: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8051 | assert(FromNNS->getAsIdentifier() && "NNS should contain identifier."); |
| 8052 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8053 | Import(FromNNS->getAsIdentifier())); |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8054 | |
| 8055 | case NestedNameSpecifier::Namespace: |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8056 | if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8057 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8058 | cast<NamespaceDecl>(*NSOrErr)); |
| 8059 | } else |
| 8060 | return NSOrErr.takeError(); |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8061 | |
| 8062 | case NestedNameSpecifier::NamespaceAlias: |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8063 | if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8064 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 8065 | cast<NamespaceAliasDecl>(*NSADOrErr)); |
| 8066 | else |
| 8067 | return NSADOrErr.takeError(); |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8068 | |
| 8069 | case NestedNameSpecifier::Global: |
| 8070 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 8071 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8072 | case NestedNameSpecifier::Super: |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8073 | if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8074 | return NestedNameSpecifier::SuperSpecifier(ToContext, |
| 8075 | cast<CXXRecordDecl>(*RDOrErr)); |
| 8076 | else |
| 8077 | return RDOrErr.takeError(); |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8078 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8079 | case NestedNameSpecifier::TypeSpec: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8080 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 8081 | if (Expected<QualType> TyOrErr = |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8082 | Import(QualType(FromNNS->getAsType(), 0u))) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8083 | bool TSTemplate = |
| 8084 | FromNNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate; |
| 8085 | return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate, |
| 8086 | TyOrErr->getTypePtr()); |
| 8087 | } else { |
| 8088 | return TyOrErr.takeError(); |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8089 | } |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8090 | } |
| 8091 | |
| 8092 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8093 | } |
| 8094 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8095 | Expected<NestedNameSpecifierLoc> |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8096 | ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8097 | // Copied from NestedNameSpecifier mostly. |
| 8098 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 8099 | NestedNameSpecifierLoc NNS = FromNNS; |
| 8100 | |
| 8101 | // Push each of the nested-name-specifiers's onto a stack for |
| 8102 | // serialization in reverse order. |
| 8103 | while (NNS) { |
| 8104 | NestedNames.push_back(NNS); |
| 8105 | NNS = NNS.getPrefix(); |
| 8106 | } |
| 8107 | |
| 8108 | NestedNameSpecifierLocBuilder Builder; |
| 8109 | |
| 8110 | while (!NestedNames.empty()) { |
| 8111 | NNS = NestedNames.pop_back_val(); |
Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 8112 | NestedNameSpecifier *Spec = nullptr; |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8113 | if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier())) |
| 8114 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8115 | |
| 8116 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8117 | |
| 8118 | SourceLocation ToLocalBeginLoc, ToLocalEndLoc; |
| 8119 | if (Kind != NestedNameSpecifier::Super) { |
| 8120 | if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc())) |
| 8121 | return std::move(Err); |
| 8122 | |
| 8123 | if (Kind != NestedNameSpecifier::Global) |
| 8124 | if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc())) |
| 8125 | return std::move(Err); |
| 8126 | } |
| 8127 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8128 | switch (Kind) { |
| 8129 | case NestedNameSpecifier::Identifier: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8130 | Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc, |
| 8131 | ToLocalEndLoc); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8132 | break; |
| 8133 | |
| 8134 | case NestedNameSpecifier::Namespace: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8135 | Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc, |
| 8136 | ToLocalEndLoc); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8137 | break; |
| 8138 | |
| 8139 | case NestedNameSpecifier::NamespaceAlias: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8140 | Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(), |
| 8141 | ToLocalBeginLoc, ToLocalEndLoc); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8142 | break; |
| 8143 | |
| 8144 | case NestedNameSpecifier::TypeSpec: |
| 8145 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8146 | SourceLocation ToTLoc; |
| 8147 | if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc())) |
| 8148 | return std::move(Err); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8149 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8150 | QualType(Spec->getAsType(), 0), ToTLoc); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8151 | Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(), |
| 8152 | ToLocalEndLoc); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8153 | break; |
| 8154 | } |
| 8155 | |
| 8156 | case NestedNameSpecifier::Global: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8157 | Builder.MakeGlobal(getToContext(), ToLocalBeginLoc); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8158 | break; |
| 8159 | |
| 8160 | case NestedNameSpecifier::Super: { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8161 | auto ToSourceRangeOrErr = Import(NNS.getSourceRange()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8162 | if (!ToSourceRangeOrErr) |
| 8163 | return ToSourceRangeOrErr.takeError(); |
| 8164 | |
| 8165 | Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(), |
| 8166 | ToSourceRangeOrErr->getBegin(), |
| 8167 | ToSourceRangeOrErr->getEnd()); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8168 | } |
| 8169 | } |
| 8170 | } |
| 8171 | |
| 8172 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 8173 | } |
| 8174 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8175 | Expected<TemplateName> ASTImporter::Import(TemplateName From) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8176 | switch (From.getKind()) { |
| 8177 | case TemplateName::Template: |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8178 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8179 | return TemplateName(cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8180 | else |
| 8181 | return ToTemplateOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8182 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8183 | case TemplateName::OverloadedTemplate: { |
| 8184 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 8185 | UnresolvedSet<2> ToTemplates; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8186 | for (auto *I : *FromStorage) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8187 | if (auto ToOrErr = Import(I)) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8188 | ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8189 | else |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8190 | return ToOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8191 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8192 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8193 | ToTemplates.end()); |
| 8194 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8195 | |
Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8196 | case TemplateName::AssumedTemplate: { |
| 8197 | AssumedTemplateStorage *FromStorage = From.getAsAssumedTemplateName(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8198 | auto DeclNameOrErr = Import(FromStorage->getDeclName()); |
Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8199 | if (!DeclNameOrErr) |
| 8200 | return DeclNameOrErr.takeError(); |
| 8201 | return ToContext.getAssumedTemplateName(*DeclNameOrErr); |
| 8202 | } |
| 8203 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8204 | case TemplateName::QualifiedTemplate: { |
| 8205 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8206 | auto QualifierOrErr = Import(QTN->getQualifier()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8207 | if (!QualifierOrErr) |
| 8208 | return QualifierOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8209 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8210 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8211 | return ToContext.getQualifiedTemplateName( |
| 8212 | *QualifierOrErr, QTN->hasTemplateKeyword(), |
| 8213 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8214 | else |
| 8215 | return ToTemplateOrErr.takeError(); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8216 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8217 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8218 | case TemplateName::DependentTemplate: { |
| 8219 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8220 | auto QualifierOrErr = Import(DTN->getQualifier()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8221 | if (!QualifierOrErr) |
| 8222 | return QualifierOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8223 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8224 | if (DTN->isIdentifier()) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8225 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8226 | Import(DTN->getIdentifier())); |
| 8227 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8228 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8229 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
| 8230 | DTN->getOperator()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8231 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8232 | |
| 8233 | case TemplateName::SubstTemplateTemplateParm: { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8234 | SubstTemplateTemplateParmStorage *Subst = |
| 8235 | From.getAsSubstTemplateTemplateParm(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8236 | ExpectedDecl ParamOrErr = Import(Subst->getParameter()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8237 | if (!ParamOrErr) |
| 8238 | return ParamOrErr.takeError(); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8239 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8240 | auto ReplacementOrErr = Import(Subst->getReplacement()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8241 | if (!ReplacementOrErr) |
| 8242 | return ReplacementOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8243 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8244 | return ToContext.getSubstTemplateTemplateParm( |
| 8245 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ReplacementOrErr); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8246 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8247 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8248 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 8249 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 8250 | = From.getAsSubstTemplateTemplateParmPack(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8251 | ExpectedDecl ParamOrErr = Import(SubstPack->getParameterPack()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8252 | if (!ParamOrErr) |
| 8253 | return ParamOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8254 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8255 | ASTNodeImporter Importer(*this); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8256 | auto ArgPackOrErr = |
| 8257 | Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 8258 | if (!ArgPackOrErr) |
| 8259 | return ArgPackOrErr.takeError(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8260 | |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8261 | return ToContext.getSubstTemplateTemplateParmPack( |
| 8262 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ArgPackOrErr); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8263 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8264 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8265 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8266 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8267 | } |
| 8268 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8269 | Expected<SourceLocation> ASTImporter::Import(SourceLocation FromLoc) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8270 | if (FromLoc.isInvalid()) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8271 | return SourceLocation{}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8272 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8273 | SourceManager &FromSM = FromContext.getSourceManager(); |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8274 | bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8275 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8276 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8277 | Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8278 | if (!ToFileIDOrErr) |
| 8279 | return ToFileIDOrErr.takeError(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8280 | SourceManager &ToSM = ToContext.getSourceManager(); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8281 | return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second); |
| 8282 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8283 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8284 | Expected<SourceRange> ASTImporter::Import(SourceRange FromRange) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8285 | SourceLocation ToBegin, ToEnd; |
| 8286 | if (Error Err = importInto(ToBegin, FromRange.getBegin())) |
| 8287 | return std::move(Err); |
| 8288 | if (Error Err = importInto(ToEnd, FromRange.getEnd())) |
| 8289 | return std::move(Err); |
| 8290 | |
| 8291 | return SourceRange(ToBegin, ToEnd); |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8292 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8293 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8294 | Expected<FileID> ASTImporter::Import(FileID FromID, bool IsBuiltin) { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8295 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8296 | if (Pos != ImportedFileIDs.end()) |
| 8297 | return Pos->second; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8298 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8299 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 8300 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8301 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8302 | |
| 8303 | // Map the FromID to the "to" source manager. |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8304 | FileID ToID; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8305 | if (FromSLoc.isExpansion()) { |
| 8306 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8307 | ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8308 | if (!ToSpLoc) |
| 8309 | return ToSpLoc.takeError(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8310 | ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8311 | if (!ToExLocS) |
| 8312 | return ToExLocS.takeError(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8313 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 8314 | SourceLocation MLoc; |
| 8315 | if (FromEx.isMacroArgExpansion()) { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8316 | MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, TokenLen); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8317 | } else { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8318 | if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8319 | MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, TokenLen, |
| 8320 | FromEx.isExpansionTokenRange()); |
| 8321 | else |
| 8322 | return ToExLocE.takeError(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8323 | } |
| 8324 | ToID = ToSM.getFileID(MLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8325 | } else { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8326 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8327 | |
| 8328 | if (!IsBuiltin) { |
| 8329 | // Include location of this file. |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8330 | ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8331 | if (!ToIncludeLoc) |
| 8332 | return ToIncludeLoc.takeError(); |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8333 | |
| 8334 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 8335 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 8336 | // disk again |
| 8337 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 8338 | // than mmap the files several times. |
| 8339 | const FileEntry *Entry = |
| 8340 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 8341 | // FIXME: The filename may be a virtual name that does probably not |
| 8342 | // point to a valid file and we get no Entry here. In this case try with |
| 8343 | // the memory buffer below. |
| 8344 | if (Entry) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8345 | ToID = ToSM.createFileID(Entry, *ToIncludeLoc, |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8346 | FromSLoc.getFile().getFileCharacteristic()); |
| 8347 | } |
Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8348 | } |
Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8349 | |
| 8350 | if (ToID.isInvalid() || IsBuiltin) { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8351 | // FIXME: We want to re-use the existing MemoryBuffer! |
Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8352 | bool Invalid = true; |
| 8353 | const llvm::MemoryBuffer *FromBuf = Cache->getBuffer( |
| 8354 | FromContext.getDiagnostics(), FromSM, SourceLocation{}, &Invalid); |
| 8355 | if (!FromBuf || Invalid) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8356 | // FIXME: Use a new error kind? |
| 8357 | return llvm::make_error<ImportError>(ImportError::Unknown); |
Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8358 | |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8359 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 8360 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 8361 | FromBuf->getBufferIdentifier()); |
| 8362 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 8363 | FromSLoc.getFile().getFileCharacteristic()); |
| 8364 | } |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8365 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8366 | |
Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8367 | assert(ToID.isValid() && "Unexpected invalid fileID was created."); |
| 8368 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 8369 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8370 | return ToID; |
| 8371 | } |
| 8372 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8373 | Expected<CXXCtorInitializer *> ASTImporter::Import(CXXCtorInitializer *From) { |
| 8374 | ExpectedExpr ToExprOrErr = Import(From->getInit()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8375 | if (!ToExprOrErr) |
| 8376 | return ToExprOrErr.takeError(); |
| 8377 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8378 | auto LParenLocOrErr = Import(From->getLParenLoc()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8379 | if (!LParenLocOrErr) |
| 8380 | return LParenLocOrErr.takeError(); |
| 8381 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8382 | auto RParenLocOrErr = Import(From->getRParenLoc()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8383 | if (!RParenLocOrErr) |
| 8384 | return RParenLocOrErr.takeError(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8385 | |
| 8386 | if (From->isBaseInitializer()) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8387 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8388 | if (!ToTInfoOrErr) |
| 8389 | return ToTInfoOrErr.takeError(); |
| 8390 | |
| 8391 | SourceLocation EllipsisLoc; |
| 8392 | if (From->isPackExpansion()) |
| 8393 | if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc())) |
| 8394 | return std::move(Err); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8395 | |
| 8396 | return new (ToContext) CXXCtorInitializer( |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8397 | ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr, |
| 8398 | *ToExprOrErr, *RParenLocOrErr, EllipsisLoc); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8399 | } else if (From->isMemberInitializer()) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8400 | ExpectedDecl ToFieldOrErr = Import(From->getMember()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8401 | if (!ToFieldOrErr) |
| 8402 | return ToFieldOrErr.takeError(); |
| 8403 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8404 | auto MemberLocOrErr = Import(From->getMemberLocation()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8405 | if (!MemberLocOrErr) |
| 8406 | return MemberLocOrErr.takeError(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8407 | |
| 8408 | return new (ToContext) CXXCtorInitializer( |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8409 | ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr, |
| 8410 | *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8411 | } else if (From->isIndirectMemberInitializer()) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8412 | ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8413 | if (!ToIFieldOrErr) |
| 8414 | return ToIFieldOrErr.takeError(); |
| 8415 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8416 | auto MemberLocOrErr = Import(From->getMemberLocation()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8417 | if (!MemberLocOrErr) |
| 8418 | return MemberLocOrErr.takeError(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8419 | |
| 8420 | return new (ToContext) CXXCtorInitializer( |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8421 | ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr), |
| 8422 | *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8423 | } else if (From->isDelegatingInitializer()) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8424 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8425 | if (!ToTInfoOrErr) |
| 8426 | return ToTInfoOrErr.takeError(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8427 | |
| 8428 | return new (ToContext) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8429 | CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr, |
| 8430 | *ToExprOrErr, *RParenLocOrErr); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8431 | } else { |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8432 | // FIXME: assert? |
| 8433 | return make_error<ImportError>(); |
Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8434 | } |
Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8435 | } |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8436 | |
Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8437 | Expected<CXXBaseSpecifier *> |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8438 | ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8439 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 8440 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 8441 | return Pos->second; |
| 8442 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8443 | Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8444 | if (!ToSourceRange) |
| 8445 | return ToSourceRange.takeError(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8446 | Expected<TypeSourceInfo *> ToTSI = Import(BaseSpec->getTypeSourceInfo()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8447 | if (!ToTSI) |
| 8448 | return ToTSI.takeError(); |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8449 | ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc()); |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8450 | if (!ToEllipsisLoc) |
| 8451 | return ToEllipsisLoc.takeError(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8452 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8453 | *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 8454 | BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8455 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 8456 | return Imported; |
| 8457 | } |
| 8458 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8459 | Error ASTImporter::ImportDefinition(Decl *From) { |
| 8460 | ExpectedDecl ToOrErr = Import(From); |
| 8461 | if (!ToOrErr) |
| 8462 | return ToOrErr.takeError(); |
| 8463 | Decl *To = *ToOrErr; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8464 | |
Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8465 | auto *FromDC = cast<DeclContext>(From); |
| 8466 | ASTNodeImporter Importer(*this); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8467 | |
Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8468 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
| 8469 | if (!ToRecord->getDefinition()) { |
| 8470 | return Importer.ImportDefinition( |
| 8471 | cast<RecordDecl>(FromDC), ToRecord, |
| 8472 | ASTNodeImporter::IDK_Everything); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8473 | } |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8474 | } |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8475 | |
Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8476 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
| 8477 | if (!ToEnum->getDefinition()) { |
| 8478 | return Importer.ImportDefinition( |
| 8479 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); |
| 8480 | } |
| 8481 | } |
| 8482 | |
| 8483 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
| 8484 | if (!ToIFace->getDefinition()) { |
| 8485 | return Importer.ImportDefinition( |
| 8486 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
| 8487 | ASTNodeImporter::IDK_Everything); |
| 8488 | } |
| 8489 | } |
| 8490 | |
| 8491 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
| 8492 | if (!ToProto->getDefinition()) { |
| 8493 | return Importer.ImportDefinition( |
| 8494 | cast<ObjCProtocolDecl>(FromDC), ToProto, |
| 8495 | ASTNodeImporter::IDK_Everything); |
| 8496 | } |
| 8497 | } |
| 8498 | |
| 8499 | return Importer.ImportDeclContext(FromDC, true); |
Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8500 | } |
| 8501 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8502 | Expected<DeclarationName> ASTImporter::Import(DeclarationName FromName) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8503 | if (!FromName) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8504 | return DeclarationName{}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8505 | |
| 8506 | switch (FromName.getNameKind()) { |
| 8507 | case DeclarationName::Identifier: |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8508 | return DeclarationName(Import(FromName.getAsIdentifierInfo())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8509 | |
| 8510 | case DeclarationName::ObjCZeroArgSelector: |
| 8511 | case DeclarationName::ObjCOneArgSelector: |
| 8512 | case DeclarationName::ObjCMultiArgSelector: |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8513 | if (auto ToSelOrErr = Import(FromName.getObjCSelector())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8514 | return DeclarationName(*ToSelOrErr); |
| 8515 | else |
| 8516 | return ToSelOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8517 | |
| 8518 | case DeclarationName::CXXConstructorName: { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8519 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8520 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 8521 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8522 | else |
| 8523 | return ToTyOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8524 | } |
| 8525 | |
| 8526 | case DeclarationName::CXXDestructorName: { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8527 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8528 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 8529 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8530 | else |
| 8531 | return ToTyOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8532 | } |
| 8533 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8534 | case DeclarationName::CXXDeductionGuideName: { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8535 | if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8536 | return ToContext.DeclarationNames.getCXXDeductionGuideName( |
| 8537 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8538 | else |
| 8539 | return ToTemplateOrErr.takeError(); |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8540 | } |
| 8541 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8542 | case DeclarationName::CXXConversionFunctionName: { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8543 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8544 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 8545 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8546 | else |
| 8547 | return ToTyOrErr.takeError(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8548 | } |
| 8549 | |
| 8550 | case DeclarationName::CXXOperatorName: |
| 8551 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 8552 | FromName.getCXXOverloadedOperator()); |
| 8553 | |
| 8554 | case DeclarationName::CXXLiteralOperatorName: |
| 8555 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8556 | Import(FromName.getCXXLiteralIdentifier())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8557 | |
| 8558 | case DeclarationName::CXXUsingDirective: |
| 8559 | // FIXME: STATICS! |
| 8560 | return DeclarationName::getUsingDirectiveName(); |
| 8561 | } |
| 8562 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 8563 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8564 | } |
| 8565 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8566 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8567 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8568 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8569 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 8570 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 8571 | |
| 8572 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 8573 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 8574 | |
| 8575 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8576 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8577 | |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8578 | Expected<Selector> ASTImporter::Import(Selector FromSel) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8579 | if (FromSel.isNull()) |
Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8580 | return Selector{}; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8581 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8582 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8583 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 8584 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 8585 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 8586 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 8587 | } |
| 8588 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8589 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 8590 | DeclContext *DC, |
| 8591 | unsigned IDNS, |
| 8592 | NamedDecl **Decls, |
| 8593 | unsigned NumDecls) { |
| 8594 | return Name; |
| 8595 | } |
| 8596 | |
| 8597 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8598 | if (LastDiagFromFrom) |
| 8599 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8600 | FromContext.getDiagnostics()); |
| 8601 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8602 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8603 | } |
| 8604 | |
| 8605 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8606 | if (!LastDiagFromFrom) |
| 8607 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8608 | ToContext.getDiagnostics()); |
| 8609 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8610 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8611 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8612 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8613 | void ASTImporter::CompleteDecl (Decl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8614 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8615 | if (!ID->getDefinition()) |
| 8616 | ID->startDefinition(); |
| 8617 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8618 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8619 | if (!PD->getDefinition()) |
| 8620 | PD->startDefinition(); |
| 8621 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8622 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8623 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 8624 | TD->startDefinition(); |
| 8625 | TD->setCompleteDefinition(true); |
| 8626 | } |
| 8627 | } |
| 8628 | else { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8629 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8630 | } |
| 8631 | } |
| 8632 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8633 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 8634 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 8635 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 8636 | "Try to import an already imported Decl"); |
| 8637 | if (Pos != ImportedDecls.end()) |
| 8638 | return Pos->second; |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8639 | ImportedDecls[From] = To; |
Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 8640 | // This mapping should be maintained only in this function. Therefore do not |
| 8641 | // check for additional consistency. |
| 8642 | ImportedFromDecls[To] = From; |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8643 | AddToLookupTable(To); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8644 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 8645 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8646 | |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8647 | llvm::Optional<ImportError> |
| 8648 | ASTImporter::getImportDeclErrorIfAny(Decl *FromD) const { |
| 8649 | auto Pos = ImportDeclErrors.find(FromD); |
| 8650 | if (Pos != ImportDeclErrors.end()) |
| 8651 | return Pos->second; |
| 8652 | else |
| 8653 | return Optional<ImportError>(); |
| 8654 | } |
| 8655 | |
| 8656 | void ASTImporter::setImportDeclError(Decl *From, ImportError Error) { |
Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8657 | auto InsertRes = ImportDeclErrors.insert({From, Error}); |
Benjamin Kramer | 4f76936 | 2019-07-01 14:33:26 +0000 | [diff] [blame] | 8658 | (void)InsertRes; |
Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8659 | // Either we set the error for the first time, or we already had set one and |
| 8660 | // now we want to set the same error. |
| 8661 | assert(InsertRes.second || InsertRes.first->second.Error == Error.Error); |
Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8662 | } |
| 8663 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8664 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 8665 | bool Complain) { |
Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8666 | llvm::DenseMap<const Type *, const Type *>::iterator Pos = |
| 8667 | ImportedTypes.find(From.getTypePtr()); |
| 8668 | if (Pos != ImportedTypes.end()) { |
Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8669 | if (ExpectedType ToFromOrErr = Import(From)) { |
Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8670 | if (ToContext.hasSameType(*ToFromOrErr, To)) |
| 8671 | return true; |
| 8672 | } else { |
| 8673 | llvm::consumeError(ToFromOrErr.takeError()); |
| 8674 | } |
| 8675 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 8676 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8677 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8678 | getStructuralEquivalenceKind(*this), false, |
| 8679 | Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 8680 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8681 | } |