| 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" |
| 60 | #include "llvm/ADT/STLExtras.h" |
| 61 | #include "llvm/ADT/SmallVector.h" |
| 62 | #include "llvm/Support/Casting.h" |
| 63 | #include "llvm/Support/ErrorHandling.h" |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 64 | #include "llvm/Support/MemoryBuffer.h" |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 65 | #include <algorithm> |
| 66 | #include <cassert> |
| 67 | #include <cstddef> |
| 68 | #include <memory> |
| 69 | #include <type_traits> |
| 70 | #include <utility> |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 71 | |
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 72 | namespace clang { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 73 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 74 | using llvm::make_error; |
| 75 | using llvm::Error; |
| 76 | using llvm::Expected; |
| 77 | using ExpectedType = llvm::Expected<QualType>; |
| 78 | using ExpectedStmt = llvm::Expected<Stmt *>; |
| 79 | using ExpectedExpr = llvm::Expected<Expr *>; |
| 80 | using ExpectedDecl = llvm::Expected<Decl *>; |
| 81 | using ExpectedSLoc = llvm::Expected<SourceLocation>; |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 82 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 83 | std::string ImportError::toString() const { |
| 84 | // FIXME: Improve error texts. |
| 85 | switch (Error) { |
| 86 | case NameConflict: |
| 87 | return "NameConflict"; |
| 88 | case UnsupportedConstruct: |
| 89 | return "UnsupportedConstruct"; |
| 90 | case Unknown: |
| 91 | return "Unknown error"; |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 92 | } |
| Balazs Keri | 2a13d66 | 2018-10-19 15:16:51 +0000 | [diff] [blame] | 93 | llvm_unreachable("Invalid error code."); |
| 94 | return "Invalid error code."; |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 97 | void ImportError::log(raw_ostream &OS) const { |
| 98 | OS << toString(); |
| 99 | } |
| 100 | |
| 101 | std::error_code ImportError::convertToErrorCode() const { |
| 102 | llvm_unreachable("Function not implemented."); |
| 103 | } |
| 104 | |
| 105 | char ImportError::ID; |
| 106 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 107 | template <class T> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 108 | SmallVector<Decl *, 2> |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 109 | getCanonicalForwardRedeclChain(Redeclarable<T>* D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 110 | SmallVector<Decl *, 2> Redecls; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 111 | for (auto *R : D->getFirstDecl()->redecls()) { |
| 112 | if (R != D->getFirstDecl()) |
| 113 | Redecls.push_back(R); |
| 114 | } |
| 115 | Redecls.push_back(D->getFirstDecl()); |
| 116 | std::reverse(Redecls.begin(), Redecls.end()); |
| 117 | return Redecls; |
| 118 | } |
| 119 | |
| 120 | SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D) { |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 121 | if (auto *FD = dyn_cast<FunctionDecl>(D)) |
| 122 | return getCanonicalForwardRedeclChain<FunctionDecl>(FD); |
| 123 | if (auto *VD = dyn_cast<VarDecl>(D)) |
| 124 | return getCanonicalForwardRedeclChain<VarDecl>(VD); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 125 | if (auto *TD = dyn_cast<TagDecl>(D)) |
| 126 | return getCanonicalForwardRedeclChain<TagDecl>(TD); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 127 | llvm_unreachable("Bad declaration kind"); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 130 | void updateFlags(const Decl *From, Decl *To) { |
| 131 | // Check if some flags or attrs are new in 'From' and copy into 'To'. |
| 132 | // FIXME: Other flags or attrs? |
| 133 | if (From->isUsed(false) && !To->isUsed(false)) |
| 134 | To->setIsUsed(); |
| 135 | } |
| 136 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 137 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>, |
| 138 | public DeclVisitor<ASTNodeImporter, ExpectedDecl>, |
| 139 | public StmtVisitor<ASTNodeImporter, ExpectedStmt> { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 140 | ASTImporter &Importer; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 141 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 142 | // Use this instead of Importer.importInto . |
| 143 | template <typename ImportT> |
| 144 | LLVM_NODISCARD Error importInto(ImportT &To, const ImportT &From) { |
| 145 | return Importer.importInto(To, From); |
| 146 | } |
| 147 | |
| 148 | // Use this to import pointers of specific type. |
| 149 | template <typename ImportT> |
| 150 | LLVM_NODISCARD Error importInto(ImportT *&To, ImportT *From) { |
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 151 | auto ToOrErr = Importer.Import_New(From); |
| 152 | if (ToOrErr) |
| 153 | To = cast_or_null<ImportT>(*ToOrErr); |
| 154 | return ToOrErr.takeError(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | // Call the import function of ASTImporter for a baseclass of type `T` and |
| 158 | // cast the return value to `T`. |
| 159 | template <typename T> |
| 160 | Expected<T *> import(T *From) { |
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 161 | auto ToOrErr = Importer.Import_New(From); |
| 162 | if (!ToOrErr) |
| 163 | return ToOrErr.takeError(); |
| 164 | return cast_or_null<T>(*ToOrErr); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | template <typename T> |
| 168 | Expected<T *> import(const T *From) { |
| 169 | return import(const_cast<T *>(From)); |
| 170 | } |
| 171 | |
| 172 | // Call the import function of ASTImporter for type `T`. |
| 173 | template <typename T> |
| 174 | Expected<T> import(const T &From) { |
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 175 | return Importer.Import_New(From); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | template <class T> |
| 179 | Expected<std::tuple<T>> |
| 180 | importSeq(const T &From) { |
| 181 | Expected<T> ToOrErr = import(From); |
| 182 | if (!ToOrErr) |
| 183 | return ToOrErr.takeError(); |
| 184 | return std::make_tuple<T>(std::move(*ToOrErr)); |
| 185 | } |
| 186 | |
| 187 | // Import multiple objects with a single function call. |
| 188 | // This should work for every type for which a variant of `import` exists. |
| 189 | // The arguments are processed from left to right and import is stopped on |
| 190 | // first error. |
| 191 | template <class THead, class... TTail> |
| 192 | Expected<std::tuple<THead, TTail...>> |
| 193 | importSeq(const THead &FromHead, const TTail &...FromTail) { |
| 194 | Expected<std::tuple<THead>> ToHeadOrErr = importSeq(FromHead); |
| 195 | if (!ToHeadOrErr) |
| 196 | return ToHeadOrErr.takeError(); |
| 197 | Expected<std::tuple<TTail...>> ToTailOrErr = importSeq(FromTail...); |
| 198 | if (!ToTailOrErr) |
| 199 | return ToTailOrErr.takeError(); |
| 200 | return std::tuple_cat(*ToHeadOrErr, *ToTailOrErr); |
| 201 | } |
| 202 | |
| 203 | // Wrapper for an overload set. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 204 | template <typename ToDeclT> struct CallOverloadedCreateFun { |
| 205 | template <typename... Args> |
| 206 | auto operator()(Args &&... args) |
| 207 | -> decltype(ToDeclT::Create(std::forward<Args>(args)...)) { |
| 208 | return ToDeclT::Create(std::forward<Args>(args)...); |
| 209 | } |
| 210 | }; |
| 211 | |
| 212 | // Always use these functions to create a Decl during import. There are |
| 213 | // certain tasks which must be done after the Decl was created, e.g. we |
| 214 | // must immediately register that as an imported Decl. The parameter `ToD` |
| 215 | // will be set to the newly created Decl or if had been imported before |
| 216 | // then to the already imported Decl. Returns a bool value set to true if |
| 217 | // the `FromD` had been imported before. |
| 218 | template <typename ToDeclT, typename FromDeclT, typename... Args> |
| 219 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 220 | Args &&... args) { |
| 221 | // There may be several overloads of ToDeclT::Create. We must make sure |
| 222 | // to call the one which would be chosen by the arguments, thus we use a |
| 223 | // wrapper for the overload set. |
| 224 | CallOverloadedCreateFun<ToDeclT> OC; |
| 225 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 226 | std::forward<Args>(args)...); |
| 227 | } |
| 228 | // Use this overload if a special Type is needed to be created. E.g if we |
| 229 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` |
| 230 | // then: |
| 231 | // TypedefNameDecl *ToTypedef; |
| 232 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); |
| 233 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, |
| 234 | typename... Args> |
| 235 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 236 | Args &&... args) { |
| 237 | CallOverloadedCreateFun<NewDeclT> OC; |
| 238 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 239 | std::forward<Args>(args)...); |
| 240 | } |
| 241 | // Use this version if a special create function must be |
| 242 | // used, e.g. CXXRecordDecl::CreateLambda . |
| 243 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, |
| 244 | typename... Args> |
| 245 | LLVM_NODISCARD bool |
| 246 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, |
| 247 | FromDeclT *FromD, Args &&... args) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 248 | // FIXME: This code is needed later. |
| 249 | //if (Importer.getImportDeclErrorIfAny(FromD)) { |
| 250 | // ToD = nullptr; |
| 251 | // return true; // Already imported but with error. |
| 252 | //} |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 253 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); |
| 254 | if (ToD) |
| 255 | return true; // Already imported. |
| 256 | ToD = CreateFun(std::forward<Args>(args)...); |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 257 | // Keep track of imported Decls. |
| 258 | Importer.MapImported(FromD, ToD); |
| 259 | Importer.AddToLookupTable(ToD); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 260 | InitializeImportedDecl(FromD, ToD); |
| 261 | return false; // A new Decl is created. |
| 262 | } |
| 263 | |
| 264 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 265 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; |
| 266 | if (FromD->hasAttrs()) |
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 267 | for (const Attr *FromAttr : FromD->getAttrs()) { |
| 268 | // FIXME: Return of the error here is not possible until store of |
| 269 | // import errors is implemented. |
| 270 | auto ToAttrOrErr = import(FromAttr); |
| 271 | if (ToAttrOrErr) |
| 272 | ToD->addAttr(*ToAttrOrErr); |
| 273 | else |
| 274 | llvm::consumeError(ToAttrOrErr.takeError()); |
| 275 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 276 | if (FromD->isUsed()) |
| 277 | ToD->setIsUsed(); |
| 278 | if (FromD->isImplicit()) |
| 279 | ToD->setImplicit(); |
| 280 | } |
| 281 | |
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 282 | // Check if we have found an existing definition. Returns with that |
| 283 | // definition if yes, otherwise returns null. |
| 284 | Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) { |
| 285 | const FunctionDecl *Definition = nullptr; |
| 286 | if (D->doesThisDeclarationHaveABody() && |
| 287 | FoundFunction->hasBody(Definition)) |
| 288 | return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition)); |
| 289 | return nullptr; |
| 290 | } |
| 291 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 292 | public: |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 293 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} |
| Gabor Marton | 344b099 | 2018-05-16 11:48:11 +0000 | [diff] [blame] | 294 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 295 | using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit; |
| 296 | using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit; |
| 297 | using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 298 | |
| 299 | // Importing types |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 300 | ExpectedType VisitType(const Type *T); |
| 301 | ExpectedType VisitAtomicType(const AtomicType *T); |
| 302 | ExpectedType VisitBuiltinType(const BuiltinType *T); |
| 303 | ExpectedType VisitDecayedType(const DecayedType *T); |
| 304 | ExpectedType VisitComplexType(const ComplexType *T); |
| 305 | ExpectedType VisitPointerType(const PointerType *T); |
| 306 | ExpectedType VisitBlockPointerType(const BlockPointerType *T); |
| 307 | ExpectedType VisitLValueReferenceType(const LValueReferenceType *T); |
| 308 | ExpectedType VisitRValueReferenceType(const RValueReferenceType *T); |
| 309 | ExpectedType VisitMemberPointerType(const MemberPointerType *T); |
| 310 | ExpectedType VisitConstantArrayType(const ConstantArrayType *T); |
| 311 | ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T); |
| 312 | ExpectedType VisitVariableArrayType(const VariableArrayType *T); |
| 313 | ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 314 | // FIXME: DependentSizedExtVectorType |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 315 | ExpectedType VisitVectorType(const VectorType *T); |
| 316 | ExpectedType VisitExtVectorType(const ExtVectorType *T); |
| 317 | ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T); |
| 318 | ExpectedType VisitFunctionProtoType(const FunctionProtoType *T); |
| 319 | ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T); |
| 320 | ExpectedType VisitParenType(const ParenType *T); |
| 321 | ExpectedType VisitTypedefType(const TypedefType *T); |
| 322 | ExpectedType VisitTypeOfExprType(const TypeOfExprType *T); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 323 | // FIXME: DependentTypeOfExprType |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 324 | ExpectedType VisitTypeOfType(const TypeOfType *T); |
| 325 | ExpectedType VisitDecltypeType(const DecltypeType *T); |
| 326 | ExpectedType VisitUnaryTransformType(const UnaryTransformType *T); |
| 327 | ExpectedType VisitAutoType(const AutoType *T); |
| 328 | ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 329 | // FIXME: DependentDecltypeType |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 330 | ExpectedType VisitRecordType(const RecordType *T); |
| 331 | ExpectedType VisitEnumType(const EnumType *T); |
| 332 | ExpectedType VisitAttributedType(const AttributedType *T); |
| 333 | ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T); |
| 334 | ExpectedType VisitSubstTemplateTypeParmType( |
| 335 | const SubstTemplateTypeParmType *T); |
| 336 | ExpectedType VisitTemplateSpecializationType( |
| 337 | const TemplateSpecializationType *T); |
| 338 | ExpectedType VisitElaboratedType(const ElaboratedType *T); |
| 339 | ExpectedType VisitDependentNameType(const DependentNameType *T); |
| 340 | ExpectedType VisitPackExpansionType(const PackExpansionType *T); |
| 341 | ExpectedType VisitDependentTemplateSpecializationType( |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 342 | const DependentTemplateSpecializationType *T); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 343 | ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T); |
| 344 | ExpectedType VisitObjCObjectType(const ObjCObjectType *T); |
| 345 | ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); |
| Rafael Stahl | df55620 | 2018-05-29 08:12:15 +0000 | [diff] [blame] | 346 | |
| 347 | // Importing declarations |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 348 | Error ImportDeclParts( |
| 349 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 350 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc); |
| 351 | Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); |
| 352 | Error ImportDeclarationNameLoc( |
| 353 | const DeclarationNameInfo &From, DeclarationNameInfo &To); |
| 354 | Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); |
| 355 | Error ImportDeclContext( |
| 356 | Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC); |
| 357 | Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 358 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 359 | Expected<CXXCastPath> ImportCastPath(CastExpr *E); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 360 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 361 | using Designator = DesignatedInitExpr::Designator; |
| 362 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 363 | /// What we should import from the definition. |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 364 | enum ImportDefinitionKind { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 365 | /// Import the default subset of the definition, which might be |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 366 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 367 | /// import is not set). |
| 368 | IDK_Default, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 369 | /// Import everything. |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 370 | IDK_Everything, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 371 | /// Import only the bare bones needed to establish a valid |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 372 | /// DeclContext. |
| 373 | IDK_Basic |
| 374 | }; |
| 375 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 376 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 377 | return IDK == IDK_Everything || |
| 378 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 379 | } |
| 380 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 381 | Error ImportInitializer(VarDecl *From, VarDecl *To); |
| 382 | Error ImportDefinition( |
| 383 | RecordDecl *From, RecordDecl *To, |
| 384 | ImportDefinitionKind Kind = IDK_Default); |
| 385 | Error ImportDefinition( |
| 386 | EnumDecl *From, EnumDecl *To, |
| 387 | ImportDefinitionKind Kind = IDK_Default); |
| 388 | Error ImportDefinition( |
| 389 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
| 390 | ImportDefinitionKind Kind = IDK_Default); |
| 391 | Error ImportDefinition( |
| 392 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
| 393 | ImportDefinitionKind Kind = IDK_Default); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 394 | Error ImportTemplateArguments( |
| 395 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 396 | SmallVectorImpl<TemplateArgument> &ToArgs); |
| 397 | Expected<TemplateArgument> |
| 398 | ImportTemplateArgument(const TemplateArgument &From); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 399 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 400 | template <typename InContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 401 | Error ImportTemplateArgumentListInfo( |
| 402 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 403 | |
| 404 | template<typename InContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 405 | Error ImportTemplateArgumentListInfo( |
| 406 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 407 | const InContainerTy &Container, TemplateArgumentListInfo &Result); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 408 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 409 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 410 | using FunctionTemplateAndArgsTy = |
| 411 | std::tuple<FunctionTemplateDecl *, TemplateArgsTy>; |
| 412 | Expected<FunctionTemplateAndArgsTy> |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 413 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 414 | FunctionDecl *FromFD); |
| 415 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 416 | Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 417 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 418 | Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD); |
| 419 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 420 | template <typename T> |
| 421 | bool hasSameVisibilityContext(T *Found, T *From); |
| 422 | |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 423 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 424 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 425 | bool Complain = true); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 426 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 427 | bool Complain = true); |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 428 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 429 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 430 | bool IsStructuralMatch(FunctionTemplateDecl *From, |
| 431 | FunctionTemplateDecl *To); |
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 432 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 433 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 434 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 435 | ExpectedDecl VisitDecl(Decl *D); |
| 436 | ExpectedDecl VisitImportDecl(ImportDecl *D); |
| 437 | ExpectedDecl VisitEmptyDecl(EmptyDecl *D); |
| 438 | ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); |
| 439 | ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); |
| 440 | ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); |
| 441 | ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); |
| 442 | ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
| 443 | ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
| 444 | ExpectedDecl VisitTypedefDecl(TypedefDecl *D); |
| 445 | ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D); |
| 446 | ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
| 447 | ExpectedDecl VisitLabelDecl(LabelDecl *D); |
| 448 | ExpectedDecl VisitEnumDecl(EnumDecl *D); |
| 449 | ExpectedDecl VisitRecordDecl(RecordDecl *D); |
| 450 | ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D); |
| 451 | ExpectedDecl VisitFunctionDecl(FunctionDecl *D); |
| 452 | ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D); |
| 453 | ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 454 | ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 455 | ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); |
| 456 | ExpectedDecl VisitFieldDecl(FieldDecl *D); |
| 457 | ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); |
| 458 | ExpectedDecl VisitFriendDecl(FriendDecl *D); |
| 459 | ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 460 | ExpectedDecl VisitVarDecl(VarDecl *D); |
| 461 | ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D); |
| 462 | ExpectedDecl VisitParmVarDecl(ParmVarDecl *D); |
| 463 | ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D); |
| 464 | ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
| 465 | ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 466 | ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 467 | ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D); |
| 468 | ExpectedDecl VisitUsingDecl(UsingDecl *D); |
| 469 | ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); |
| 470 | ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 471 | ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 472 | ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 473 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 474 | Expected<ObjCTypeParamList *> |
| 475 | ImportObjCTypeParamList(ObjCTypeParamList *list); |
| 476 | |
| 477 | ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 478 | ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 479 | ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 480 | ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 481 | ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
| 482 | ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 483 | ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 484 | ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 485 | ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D); |
| 486 | ExpectedDecl VisitClassTemplateSpecializationDecl( |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 487 | ClassTemplateSpecializationDecl *D); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 488 | ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); |
| 489 | ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
| 490 | ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 491 | |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 492 | // Importing statements |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 493 | ExpectedStmt VisitStmt(Stmt *S); |
| 494 | ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S); |
| 495 | ExpectedStmt VisitDeclStmt(DeclStmt *S); |
| 496 | ExpectedStmt VisitNullStmt(NullStmt *S); |
| 497 | ExpectedStmt VisitCompoundStmt(CompoundStmt *S); |
| 498 | ExpectedStmt VisitCaseStmt(CaseStmt *S); |
| 499 | ExpectedStmt VisitDefaultStmt(DefaultStmt *S); |
| 500 | ExpectedStmt VisitLabelStmt(LabelStmt *S); |
| 501 | ExpectedStmt VisitAttributedStmt(AttributedStmt *S); |
| 502 | ExpectedStmt VisitIfStmt(IfStmt *S); |
| 503 | ExpectedStmt VisitSwitchStmt(SwitchStmt *S); |
| 504 | ExpectedStmt VisitWhileStmt(WhileStmt *S); |
| 505 | ExpectedStmt VisitDoStmt(DoStmt *S); |
| 506 | ExpectedStmt VisitForStmt(ForStmt *S); |
| 507 | ExpectedStmt VisitGotoStmt(GotoStmt *S); |
| 508 | ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 509 | ExpectedStmt VisitContinueStmt(ContinueStmt *S); |
| 510 | ExpectedStmt VisitBreakStmt(BreakStmt *S); |
| 511 | ExpectedStmt VisitReturnStmt(ReturnStmt *S); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 512 | // FIXME: MSAsmStmt |
| 513 | // FIXME: SEHExceptStmt |
| 514 | // FIXME: SEHFinallyStmt |
| 515 | // FIXME: SEHTryStmt |
| 516 | // FIXME: SEHLeaveStmt |
| 517 | // FIXME: CapturedStmt |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 518 | ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S); |
| 519 | ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S); |
| 520 | ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 521 | // FIXME: MSDependentExistsStmt |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 522 | ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 523 | ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 524 | ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 525 | ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 526 | ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 527 | ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 528 | ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 529 | |
| 530 | // Importing expressions |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 531 | ExpectedStmt VisitExpr(Expr *E); |
| 532 | ExpectedStmt VisitVAArgExpr(VAArgExpr *E); |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 533 | ExpectedStmt VisitChooseExpr(ChooseExpr *E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 534 | ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); |
| 535 | ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E); |
| 536 | ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E); |
| 537 | ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); |
| 538 | ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 539 | ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
| 540 | ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E); |
| 541 | ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E); |
| 542 | ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E); |
| 543 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); |
| 544 | ExpectedStmt VisitStringLiteral(StringLiteral *E); |
| 545 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 546 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); |
| 547 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 548 | ExpectedStmt VisitConstantExpr(ConstantExpr *E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 549 | ExpectedStmt VisitParenExpr(ParenExpr *E); |
| 550 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); |
| 551 | ExpectedStmt VisitStmtExpr(StmtExpr *E); |
| 552 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); |
| 553 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
| 554 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); |
| 555 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); |
| 556 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 557 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); |
| 558 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 559 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 560 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
| 561 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); |
| 562 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); |
| 563 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 564 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 565 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); |
| 566 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 567 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 568 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 569 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 570 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); |
| 571 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
| 572 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); |
| 573 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); |
| 574 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); |
| 575 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); |
| 576 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); |
| 577 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
| 578 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
| 579 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); |
| 580 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); |
| 581 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
| 582 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
| 583 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); |
| 584 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); |
| 585 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
| 586 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
| 587 | ExpectedStmt VisitMemberExpr(MemberExpr *E); |
| 588 | ExpectedStmt VisitCallExpr(CallExpr *E); |
| 589 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); |
| 590 | ExpectedStmt VisitInitListExpr(InitListExpr *E); |
| 591 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); |
| 592 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); |
| 593 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 594 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
| 595 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 596 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
| 597 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
| 598 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); |
| 599 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 600 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 601 | template<typename IIter, typename OIter> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 602 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 603 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 604 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { |
| 605 | Expected<ItemT> ToOrErr = import(*Ibegin); |
| 606 | if (!ToOrErr) |
| 607 | return ToOrErr.takeError(); |
| 608 | *Obegin = *ToOrErr; |
| 609 | } |
| 610 | return Error::success(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 613 | // Import every item from a container structure into an output container. |
| 614 | // If error occurs, stops at first error and returns the error. |
| 615 | // The output container should have space for all needed elements (it is not |
| 616 | // expanded, new items are put into from the beginning). |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 617 | template<typename InContainerTy, typename OutContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 618 | Error ImportContainerChecked( |
| 619 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { |
| 620 | return ImportArrayChecked( |
| 621 | InContainer.begin(), InContainer.end(), OutContainer.begin()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | template<typename InContainerTy, typename OIter> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 625 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 626 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 627 | } |
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 628 | |
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 629 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 630 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 631 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( |
| 632 | FunctionDecl *FromFD); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 633 | }; |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 634 | |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 635 | template <typename InContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 636 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 637 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 638 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 639 | auto ToLAngleLocOrErr = import(FromLAngleLoc); |
| 640 | if (!ToLAngleLocOrErr) |
| 641 | return ToLAngleLocOrErr.takeError(); |
| 642 | auto ToRAngleLocOrErr = import(FromRAngleLoc); |
| 643 | if (!ToRAngleLocOrErr) |
| 644 | return ToRAngleLocOrErr.takeError(); |
| 645 | |
| 646 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); |
| 647 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 648 | return Err; |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 649 | Result = ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 650 | return Error::success(); |
| Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 651 | } |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 652 | |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 653 | template <> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 654 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 655 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 656 | return ImportTemplateArgumentListInfo( |
| 657 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 658 | } |
| 659 | |
| 660 | template <> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 661 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 662 | ASTTemplateArgumentListInfo>( |
| 663 | const ASTTemplateArgumentListInfo &From, |
| 664 | TemplateArgumentListInfo &Result) { |
| 665 | return ImportTemplateArgumentListInfo( |
| 666 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 667 | } |
| 668 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 669 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 670 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 671 | FunctionDecl *FromFD) { |
| 672 | assert(FromFD->getTemplatedKind() == |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 673 | FunctionDecl::TK_FunctionTemplateSpecialization); |
| 674 | |
| 675 | FunctionTemplateAndArgsTy Result; |
| 676 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 677 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 678 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) |
| 679 | return std::move(Err); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 680 | |
| 681 | // Import template arguments. |
| 682 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 683 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 684 | std::get<1>(Result))) |
| 685 | return std::move(Err); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 686 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 687 | return Result; |
| 688 | } |
| 689 | |
| 690 | template <> |
| 691 | Expected<TemplateParameterList *> |
| 692 | ASTNodeImporter::import(TemplateParameterList *From) { |
| 693 | SmallVector<NamedDecl *, 4> To(From->size()); |
| 694 | if (Error Err = ImportContainerChecked(*From, To)) |
| 695 | return std::move(Err); |
| 696 | |
| 697 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); |
| 698 | if (!ToRequiresClause) |
| 699 | return ToRequiresClause.takeError(); |
| 700 | |
| 701 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); |
| 702 | if (!ToTemplateLocOrErr) |
| 703 | return ToTemplateLocOrErr.takeError(); |
| 704 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); |
| 705 | if (!ToLAngleLocOrErr) |
| 706 | return ToLAngleLocOrErr.takeError(); |
| 707 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); |
| 708 | if (!ToRAngleLocOrErr) |
| 709 | return ToRAngleLocOrErr.takeError(); |
| 710 | |
| 711 | return TemplateParameterList::Create( |
| 712 | Importer.getToContext(), |
| 713 | *ToTemplateLocOrErr, |
| 714 | *ToLAngleLocOrErr, |
| 715 | To, |
| 716 | *ToRAngleLocOrErr, |
| 717 | *ToRequiresClause); |
| 718 | } |
| 719 | |
| 720 | template <> |
| 721 | Expected<TemplateArgument> |
| 722 | ASTNodeImporter::import(const TemplateArgument &From) { |
| 723 | switch (From.getKind()) { |
| 724 | case TemplateArgument::Null: |
| 725 | return TemplateArgument(); |
| 726 | |
| 727 | case TemplateArgument::Type: { |
| 728 | ExpectedType ToTypeOrErr = import(From.getAsType()); |
| 729 | if (!ToTypeOrErr) |
| 730 | return ToTypeOrErr.takeError(); |
| 731 | return TemplateArgument(*ToTypeOrErr); |
| 732 | } |
| 733 | |
| 734 | case TemplateArgument::Integral: { |
| 735 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); |
| 736 | if (!ToTypeOrErr) |
| 737 | return ToTypeOrErr.takeError(); |
| 738 | return TemplateArgument(From, *ToTypeOrErr); |
| 739 | } |
| 740 | |
| 741 | case TemplateArgument::Declaration: { |
| 742 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); |
| 743 | if (!ToOrErr) |
| 744 | return ToOrErr.takeError(); |
| 745 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); |
| 746 | if (!ToTypeOrErr) |
| 747 | return ToTypeOrErr.takeError(); |
| 748 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); |
| 749 | } |
| 750 | |
| 751 | case TemplateArgument::NullPtr: { |
| 752 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); |
| 753 | if (!ToTypeOrErr) |
| 754 | return ToTypeOrErr.takeError(); |
| 755 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); |
| 756 | } |
| 757 | |
| 758 | case TemplateArgument::Template: { |
| 759 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); |
| 760 | if (!ToTemplateOrErr) |
| 761 | return ToTemplateOrErr.takeError(); |
| 762 | |
| 763 | return TemplateArgument(*ToTemplateOrErr); |
| 764 | } |
| 765 | |
| 766 | case TemplateArgument::TemplateExpansion: { |
| 767 | Expected<TemplateName> ToTemplateOrErr = |
| 768 | import(From.getAsTemplateOrTemplatePattern()); |
| 769 | if (!ToTemplateOrErr) |
| 770 | return ToTemplateOrErr.takeError(); |
| 771 | |
| 772 | return TemplateArgument( |
| 773 | *ToTemplateOrErr, From.getNumTemplateExpansions()); |
| 774 | } |
| 775 | |
| 776 | case TemplateArgument::Expression: |
| 777 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) |
| 778 | return TemplateArgument(*ToExpr); |
| 779 | else |
| 780 | return ToExpr.takeError(); |
| 781 | |
| 782 | case TemplateArgument::Pack: { |
| 783 | SmallVector<TemplateArgument, 2> ToPack; |
| 784 | ToPack.reserve(From.pack_size()); |
| 785 | if (Error Err = ImportTemplateArguments( |
| 786 | From.pack_begin(), From.pack_size(), ToPack)) |
| 787 | return std::move(Err); |
| 788 | |
| 789 | return TemplateArgument( |
| 790 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | llvm_unreachable("Invalid template argument kind"); |
| 795 | } |
| 796 | |
| 797 | template <> |
| 798 | Expected<TemplateArgumentLoc> |
| 799 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { |
| 800 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); |
| 801 | if (!ArgOrErr) |
| 802 | return ArgOrErr.takeError(); |
| 803 | TemplateArgument Arg = *ArgOrErr; |
| 804 | |
| 805 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 806 | |
| 807 | TemplateArgumentLocInfo ToInfo; |
| 808 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 809 | ExpectedExpr E = import(FromInfo.getAsExpr()); |
| 810 | if (!E) |
| 811 | return E.takeError(); |
| 812 | ToInfo = TemplateArgumentLocInfo(*E); |
| 813 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 814 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) |
| 815 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); |
| 816 | else |
| 817 | return TSIOrErr.takeError(); |
| 818 | } else { |
| 819 | auto ToTemplateQualifierLocOrErr = |
| 820 | import(FromInfo.getTemplateQualifierLoc()); |
| 821 | if (!ToTemplateQualifierLocOrErr) |
| 822 | return ToTemplateQualifierLocOrErr.takeError(); |
| 823 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); |
| 824 | if (!ToTemplateNameLocOrErr) |
| 825 | return ToTemplateNameLocOrErr.takeError(); |
| 826 | auto ToTemplateEllipsisLocOrErr = |
| 827 | import(FromInfo.getTemplateEllipsisLoc()); |
| 828 | if (!ToTemplateEllipsisLocOrErr) |
| 829 | return ToTemplateEllipsisLocOrErr.takeError(); |
| 830 | |
| 831 | ToInfo = TemplateArgumentLocInfo( |
| 832 | *ToTemplateQualifierLocOrErr, |
| 833 | *ToTemplateNameLocOrErr, |
| 834 | *ToTemplateEllipsisLocOrErr); |
| 835 | } |
| 836 | |
| 837 | return TemplateArgumentLoc(Arg, ToInfo); |
| 838 | } |
| 839 | |
| 840 | template <> |
| 841 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { |
| 842 | if (DG.isNull()) |
| 843 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 844 | size_t NumDecls = DG.end() - DG.begin(); |
| 845 | SmallVector<Decl *, 1> ToDecls; |
| 846 | ToDecls.reserve(NumDecls); |
| 847 | for (Decl *FromD : DG) { |
| 848 | if (auto ToDOrErr = import(FromD)) |
| 849 | ToDecls.push_back(*ToDOrErr); |
| 850 | else |
| 851 | return ToDOrErr.takeError(); |
| 852 | } |
| 853 | return DeclGroupRef::Create(Importer.getToContext(), |
| 854 | ToDecls.begin(), |
| 855 | NumDecls); |
| 856 | } |
| 857 | |
| 858 | template <> |
| 859 | Expected<ASTNodeImporter::Designator> |
| 860 | ASTNodeImporter::import(const Designator &D) { |
| 861 | if (D.isFieldDesignator()) { |
| 862 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 863 | |
| 864 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); |
| 865 | if (!ToDotLocOrErr) |
| 866 | return ToDotLocOrErr.takeError(); |
| 867 | |
| 868 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); |
| 869 | if (!ToFieldLocOrErr) |
| 870 | return ToFieldLocOrErr.takeError(); |
| 871 | |
| 872 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); |
| 873 | } |
| 874 | |
| 875 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); |
| 876 | if (!ToLBracketLocOrErr) |
| 877 | return ToLBracketLocOrErr.takeError(); |
| 878 | |
| 879 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); |
| 880 | if (!ToRBracketLocOrErr) |
| 881 | return ToRBracketLocOrErr.takeError(); |
| 882 | |
| 883 | if (D.isArrayDesignator()) |
| 884 | return Designator(D.getFirstExprIndex(), |
| 885 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); |
| 886 | |
| 887 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); |
| 888 | if (!ToEllipsisLocOrErr) |
| 889 | return ToEllipsisLocOrErr.takeError(); |
| 890 | |
| 891 | assert(D.isArrayRangeDesignator()); |
| 892 | return Designator( |
| 893 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, |
| 894 | *ToRBracketLocOrErr); |
| 895 | } |
| 896 | |
| 897 | template <> |
| 898 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { |
| 899 | VarDecl *Var = nullptr; |
| 900 | if (From.capturesVariable()) { |
| 901 | if (auto VarOrErr = import(From.getCapturedVar())) |
| 902 | Var = *VarOrErr; |
| 903 | else |
| 904 | return VarOrErr.takeError(); |
| 905 | } |
| 906 | |
| 907 | auto LocationOrErr = import(From.getLocation()); |
| 908 | if (!LocationOrErr) |
| 909 | return LocationOrErr.takeError(); |
| 910 | |
| 911 | SourceLocation EllipsisLoc; |
| 912 | if (From.isPackExpansion()) |
| 913 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) |
| 914 | return std::move(Err); |
| 915 | |
| 916 | return LambdaCapture( |
| 917 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, |
| 918 | EllipsisLoc); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 919 | } |
| 920 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 921 | } // namespace clang |
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 922 | |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 923 | //---------------------------------------------------------------------------- |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 924 | // Import Types |
| 925 | //---------------------------------------------------------------------------- |
| 926 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 927 | using namespace clang; |
| 928 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 929 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 930 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 931 | << T->getTypeClassName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 932 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 933 | } |
| 934 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 935 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 936 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); |
| 937 | if (!UnderlyingTypeOrErr) |
| 938 | return UnderlyingTypeOrErr.takeError(); |
| Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 939 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 940 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); |
| Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 941 | } |
| 942 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 943 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 944 | switch (T->getKind()) { |
| Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 945 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 946 | case BuiltinType::Id: \ |
| 947 | return Importer.getToContext().SingletonId; |
| Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 948 | #include "clang/Basic/OpenCLImageTypes.def" |
| Andrew Savonichev | 3fee351 | 2018-11-08 11:25:41 +0000 | [diff] [blame] | 949 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
| 950 | case BuiltinType::Id: \ |
| 951 | return Importer.getToContext().Id##Ty; |
| 952 | #include "clang/Basic/OpenCLExtensionTypes.def" |
| John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 953 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 954 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 955 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 956 | #include "clang/AST/BuiltinTypes.def" |
| 957 | |
| 958 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 959 | // context supports C++. |
| 960 | |
| 961 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 962 | // context supports ObjC. |
| 963 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 964 | case BuiltinType::Char_U: |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 965 | // The context we're importing from has an unsigned 'char'. If we're |
| 966 | // importing into a context with a signed 'char', translate to |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 967 | // 'unsigned char' instead. |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 968 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 969 | return Importer.getToContext().UnsignedCharTy; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 970 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 971 | return Importer.getToContext().CharTy; |
| 972 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 973 | case BuiltinType::Char_S: |
| 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().SignedCharTy; |
| 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 | |
| Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 982 | case BuiltinType::WChar_S: |
| 983 | case BuiltinType::WChar_U: |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 984 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 985 | // wchar_t? |
| 986 | return Importer.getToContext().WCharTy; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 987 | } |
| David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 988 | |
| 989 | llvm_unreachable("Invalid BuiltinType Kind!"); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 990 | } |
| 991 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 992 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 993 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); |
| 994 | if (!ToOriginalTypeOrErr) |
| 995 | return ToOriginalTypeOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 996 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 997 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 998 | } |
| 999 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1000 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
| 1001 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1002 | if (!ToElementTypeOrErr) |
| 1003 | return ToElementTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1004 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1005 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1008 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
| 1009 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1010 | if (!ToPointeeTypeOrErr) |
| 1011 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1012 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1013 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1016 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1017 | // FIXME: Check for blocks support in "to" context. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 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().getBlockPointerType(*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 |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1026 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1027 | // FIXME: Check for C++ support in "to" context. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1028 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1029 | if (!ToPointeeTypeOrErr) |
| 1030 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1031 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1032 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1035 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1036 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1037 | // FIXME: Check for C++0x support in "to" context. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1038 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); |
| 1039 | if (!ToPointeeTypeOrErr) |
| 1040 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1041 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1042 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1043 | } |
| 1044 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1045 | ExpectedType |
| 1046 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1047 | // FIXME: Check for C++ support in "to" context. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1048 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1049 | if (!ToPointeeTypeOrErr) |
| 1050 | return ToPointeeTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1051 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1052 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); |
| 1053 | if (!ClassTypeOrErr) |
| 1054 | return ClassTypeOrErr.takeError(); |
| 1055 | |
| 1056 | return Importer.getToContext().getMemberPointerType( |
| 1057 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1060 | ExpectedType |
| 1061 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
| 1062 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1063 | if (!ToElementTypeOrErr) |
| 1064 | return ToElementTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1065 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1066 | return Importer.getToContext().getConstantArrayType(*ToElementTypeOrErr, |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1067 | T->getSize(), |
| 1068 | T->getSizeModifier(), |
| 1069 | T->getIndexTypeCVRQualifiers()); |
| 1070 | } |
| 1071 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1072 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1073 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1074 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1075 | if (!ToElementTypeOrErr) |
| 1076 | return ToElementTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1077 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1078 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1079 | T->getSizeModifier(), |
| 1080 | T->getIndexTypeCVRQualifiers()); |
| 1081 | } |
| 1082 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1083 | ExpectedType |
| 1084 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
| 1085 | QualType ToElementType; |
| 1086 | Expr *ToSizeExpr; |
| 1087 | SourceRange ToBracketsRange; |
| 1088 | if (auto Imp = importSeq( |
| 1089 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1090 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1091 | else |
| 1092 | return Imp.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1093 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1094 | return Importer.getToContext().getVariableArrayType( |
| 1095 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1096 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1099 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1100 | const DependentSizedArrayType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1101 | QualType ToElementType; |
| 1102 | Expr *ToSizeExpr; |
| 1103 | SourceRange ToBracketsRange; |
| 1104 | if (auto Imp = importSeq( |
| 1105 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) |
| 1106 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; |
| 1107 | else |
| 1108 | return Imp.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1109 | // SizeExpr may be null if size is not specified directly. |
| 1110 | // For example, 'int a[]'. |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1111 | |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1112 | return Importer.getToContext().getDependentSizedArrayType( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1113 | ToElementType, ToSizeExpr, T->getSizeModifier(), |
| 1114 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1117 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
| 1118 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1119 | if (!ToElementTypeOrErr) |
| 1120 | return ToElementTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1121 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1122 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1123 | T->getNumElements(), |
| Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 1124 | T->getVectorKind()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1127 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
| 1128 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); |
| 1129 | if (!ToElementTypeOrErr) |
| 1130 | return ToElementTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1131 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1132 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1133 | T->getNumElements()); |
| 1134 | } |
| 1135 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1136 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1137 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1138 | // FIXME: What happens if we're importing a function without a prototype |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1139 | // into C++? Should we make it variadic? |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1140 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1141 | if (!ToReturnTypeOrErr) |
| 1142 | return ToReturnTypeOrErr.takeError(); |
| Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1143 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1144 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, |
| Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1145 | T->getExtInfo()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1148 | ExpectedType |
| 1149 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
| 1150 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); |
| 1151 | if (!ToReturnTypeOrErr) |
| 1152 | return ToReturnTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1153 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1154 | // Import argument types |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1155 | SmallVector<QualType, 4> ArgTypes; |
| Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 1156 | for (const auto &A : T->param_types()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1157 | ExpectedType TyOrErr = import(A); |
| 1158 | if (!TyOrErr) |
| 1159 | return TyOrErr.takeError(); |
| 1160 | ArgTypes.push_back(*TyOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1161 | } |
| 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 exception types |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1164 | SmallVector<QualType, 4> ExceptionTypes; |
| Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 1165 | for (const auto &E : T->exceptions()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1166 | ExpectedType TyOrErr = import(E); |
| 1167 | if (!TyOrErr) |
| 1168 | return TyOrErr.takeError(); |
| 1169 | ExceptionTypes.push_back(*TyOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1170 | } |
| John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 1171 | |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1172 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 1173 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 1174 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1175 | auto Imp = importSeq( |
| 1176 | FromEPI.ExceptionSpec.NoexceptExpr, |
| 1177 | FromEPI.ExceptionSpec.SourceDecl, |
| 1178 | FromEPI.ExceptionSpec.SourceTemplate); |
| 1179 | if (!Imp) |
| 1180 | return Imp.takeError(); |
| 1181 | |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1182 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 1183 | ToEPI.Variadic = FromEPI.Variadic; |
| 1184 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 1185 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 1186 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1187 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 1188 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1189 | std::tie( |
| 1190 | ToEPI.ExceptionSpec.NoexceptExpr, |
| 1191 | ToEPI.ExceptionSpec.SourceDecl, |
| 1192 | ToEPI.ExceptionSpec.SourceTemplate) = *Imp; |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1193 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1194 | return Importer.getToContext().getFunctionType( |
| 1195 | *ToReturnTypeOrErr, ArgTypes, ToEPI); |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1198 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1199 | const UnresolvedUsingType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1200 | UnresolvedUsingTypenameDecl *ToD; |
| 1201 | Decl *ToPrevD; |
| 1202 | if (auto Imp = importSeq(T->getDecl(), T->getDecl()->getPreviousDecl())) |
| 1203 | std::tie(ToD, ToPrevD) = *Imp; |
| 1204 | else |
| 1205 | return Imp.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1206 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1207 | return Importer.getToContext().getTypeDeclType( |
| 1208 | ToD, cast_or_null<TypeDecl>(ToPrevD)); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1211 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 1212 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); |
| 1213 | if (!ToInnerTypeOrErr) |
| 1214 | return ToInnerTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1215 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1216 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); |
| Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1219 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
| 1220 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1221 | if (!ToDeclOrErr) |
| 1222 | return ToDeclOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1223 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1224 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1227 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
| 1228 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1229 | if (!ToExprOrErr) |
| 1230 | return ToExprOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1231 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1232 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1235 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
| 1236 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1237 | if (!ToUnderlyingTypeOrErr) |
| 1238 | return ToUnderlyingTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1239 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1240 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1243 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1244 | // FIXME: Make sure that the "to" context supports C++0x! |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1245 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); |
| 1246 | if (!ToExprOrErr) |
| 1247 | return ToExprOrErr.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 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1250 | if (!ToUnderlyingTypeOrErr) |
| 1251 | return ToUnderlyingTypeOrErr.takeError(); |
| Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 1252 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1253 | return Importer.getToContext().getDecltypeType( |
| 1254 | *ToExprOrErr, *ToUnderlyingTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1257 | ExpectedType |
| 1258 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 1259 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1260 | if (!ToBaseTypeOrErr) |
| 1261 | return ToBaseTypeOrErr.takeError(); |
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1262 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1263 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); |
| 1264 | if (!ToUnderlyingTypeOrErr) |
| 1265 | return ToUnderlyingTypeOrErr.takeError(); |
| 1266 | |
| 1267 | return Importer.getToContext().getUnaryTransformType( |
| 1268 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); |
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1271 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
| Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 1272 | // FIXME: Make sure that the "to" context supports C++11! |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1273 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); |
| 1274 | if (!ToDeducedTypeOrErr) |
| 1275 | return ToDeducedTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1276 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1277 | return Importer.getToContext().getAutoType(*ToDeducedTypeOrErr, |
| 1278 | T->getKeyword(), |
| Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 1279 | /*IsDependent*/false); |
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1282 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1283 | const InjectedClassNameType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1284 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1285 | if (!ToDeclOrErr) |
| 1286 | return ToDeclOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1287 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1288 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); |
| 1289 | if (!ToInjTypeOrErr) |
| 1290 | return ToInjTypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1291 | |
| 1292 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 1293 | // See comments in InjectedClassNameType definition for details |
| 1294 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 1295 | enum { |
| 1296 | TypeAlignmentInBits = 4, |
| 1297 | TypeAlignment = 1 << TypeAlignmentInBits |
| 1298 | }; |
| 1299 | |
| 1300 | return QualType(new (Importer.getToContext(), TypeAlignment) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1301 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1302 | } |
| 1303 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1304 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
| 1305 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1306 | if (!ToDeclOrErr) |
| 1307 | return ToDeclOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1308 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1309 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1312 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
| 1313 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1314 | if (!ToDeclOrErr) |
| 1315 | return ToDeclOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1316 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1317 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1320 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 1321 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); |
| 1322 | if (!ToModifiedTypeOrErr) |
| 1323 | return ToModifiedTypeOrErr.takeError(); |
| 1324 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); |
| 1325 | if (!ToEquivalentTypeOrErr) |
| 1326 | return ToEquivalentTypeOrErr.takeError(); |
| Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1327 | |
| 1328 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1329 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); |
| Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1332 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1333 | const TemplateTypeParmType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1334 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1335 | if (!ToDeclOrErr) |
| 1336 | return ToDeclOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1337 | |
| 1338 | return Importer.getToContext().getTemplateTypeParmType( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1339 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1340 | } |
| 1341 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1342 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1343 | const SubstTemplateTypeParmType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1344 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); |
| 1345 | if (!ReplacedOrErr) |
| 1346 | return ReplacedOrErr.takeError(); |
| 1347 | const TemplateTypeParmType *Replaced = |
| 1348 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1349 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1350 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); |
| 1351 | if (!ToReplacementTypeOrErr) |
| 1352 | return ToReplacementTypeOrErr.takeError(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1353 | |
| 1354 | return Importer.getToContext().getSubstTemplateTypeParmType( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1355 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1356 | } |
| 1357 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1358 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1359 | const TemplateSpecializationType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1360 | auto ToTemplateOrErr = import(T->getTemplateName()); |
| 1361 | if (!ToTemplateOrErr) |
| 1362 | return ToTemplateOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1363 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1364 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1365 | if (Error Err = ImportTemplateArguments( |
| 1366 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
| 1367 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1368 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1369 | QualType ToCanonType; |
| 1370 | if (!QualType(T, 0).isCanonical()) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1371 | QualType FromCanonType |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1372 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1373 | if (ExpectedType TyOrErr = import(FromCanonType)) |
| 1374 | ToCanonType = *TyOrErr; |
| 1375 | else |
| 1376 | return TyOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1377 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1378 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, |
| David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 1379 | ToTemplateArgs, |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1380 | ToCanonType); |
| 1381 | } |
| 1382 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1383 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1384 | // Note: the qualifier in an ElaboratedType is optional. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1385 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1386 | if (!ToQualifierOrErr) |
| 1387 | return ToQualifierOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1388 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1389 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); |
| 1390 | if (!ToNamedTypeOrErr) |
| 1391 | return ToNamedTypeOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1392 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1393 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); |
| 1394 | if (!ToOwnedTagDeclOrErr) |
| 1395 | return ToOwnedTagDeclOrErr.takeError(); |
| Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1396 | |
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1397 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1398 | *ToQualifierOrErr, |
| 1399 | *ToNamedTypeOrErr, |
| 1400 | *ToOwnedTagDeclOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1403 | ExpectedType |
| 1404 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 1405 | ExpectedType ToPatternOrErr = import(T->getPattern()); |
| 1406 | if (!ToPatternOrErr) |
| 1407 | return ToPatternOrErr.takeError(); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1408 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1409 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1410 | T->getNumExpansions()); |
| 1411 | } |
| 1412 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1413 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1414 | const DependentTemplateSpecializationType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1415 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1416 | if (!ToQualifierOrErr) |
| 1417 | return ToQualifierOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1418 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1419 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1420 | |
| 1421 | SmallVector<TemplateArgument, 2> ToPack; |
| 1422 | ToPack.reserve(T->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1423 | if (Error Err = ImportTemplateArguments( |
| 1424 | T->getArgs(), T->getNumArgs(), ToPack)) |
| 1425 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1426 | |
| 1427 | return Importer.getToContext().getDependentTemplateSpecializationType( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1428 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1431 | ExpectedType |
| 1432 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { |
| 1433 | auto ToQualifierOrErr = import(T->getQualifier()); |
| 1434 | if (!ToQualifierOrErr) |
| 1435 | return ToQualifierOrErr.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1436 | |
| 1437 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1438 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1439 | QualType Canon; |
| 1440 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { |
| 1441 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) |
| 1442 | Canon = (*TyOrErr).getCanonicalType(); |
| 1443 | else |
| 1444 | return TyOrErr.takeError(); |
| 1445 | } |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1446 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1447 | return Importer.getToContext().getDependentNameType(T->getKeyword(), |
| 1448 | *ToQualifierOrErr, |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1449 | Name, Canon); |
| 1450 | } |
| 1451 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1452 | ExpectedType |
| 1453 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
| 1454 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); |
| 1455 | if (!ToDeclOrErr) |
| 1456 | return ToDeclOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1457 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1458 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1461 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
| 1462 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); |
| 1463 | if (!ToBaseTypeOrErr) |
| 1464 | return ToBaseTypeOrErr.takeError(); |
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1465 | |
| Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1466 | SmallVector<QualType, 4> TypeArgs; |
| Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1467 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1468 | if (ExpectedType TyOrErr = import(TypeArg)) |
| 1469 | TypeArgs.push_back(*TyOrErr); |
| 1470 | else |
| 1471 | return TyOrErr.takeError(); |
| Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1474 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1475 | for (auto *P : T->quals()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1476 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) |
| 1477 | Protocols.push_back(*ProtocolOrErr); |
| 1478 | else |
| 1479 | return ProtocolOrErr.takeError(); |
| 1480 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1483 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, |
| Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1484 | Protocols, |
| 1485 | T->isKindOfTypeAsWritten()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1486 | } |
| 1487 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1488 | ExpectedType |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1489 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1490 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); |
| 1491 | if (!ToPointeeTypeOrErr) |
| 1492 | return ToPointeeTypeOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1493 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1494 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1497 | //---------------------------------------------------------------------------- |
| 1498 | // Import Declarations |
| 1499 | //---------------------------------------------------------------------------- |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1500 | Error ASTNodeImporter::ImportDeclParts( |
| 1501 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, |
| 1502 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { |
| Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1503 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. |
| 1504 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); |
| 1505 | DeclContext *OrigDC = D->getDeclContext(); |
| 1506 | FunctionDecl *FunDecl; |
| 1507 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && |
| 1508 | FunDecl->hasBody()) { |
| Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1509 | auto getLeafPointeeType = [](const Type *T) { |
| 1510 | while (T->isPointerType() || T->isArrayType()) { |
| 1511 | T = T->getPointeeOrArrayElementType(); |
| 1512 | } |
| 1513 | return T; |
| 1514 | }; |
| 1515 | for (const ParmVarDecl *P : FunDecl->parameters()) { |
| 1516 | const Type *LeafT = |
| 1517 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); |
| 1518 | auto *RT = dyn_cast<RecordType>(LeafT); |
| 1519 | if (RT && RT->getDecl() == D) { |
| 1520 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 1521 | << D->getDeclKindName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1522 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1523 | } |
| Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1524 | } |
| 1525 | } |
| 1526 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1527 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1528 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 1529 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1530 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1531 | // Import the name of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1532 | if (Error Err = importInto(Name, D->getDeclName())) |
| 1533 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1534 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1535 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1536 | if (Error Err = importInto(Loc, D->getLocation())) |
| 1537 | return Err; |
| 1538 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1539 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
| Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 1540 | if (ToD) |
| 1541 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD)) |
| 1542 | return Err; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1543 | |
| 1544 | return Error::success(); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1547 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1548 | if (!FromD) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1549 | return Error::success(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1550 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1551 | if (!ToD) |
| 1552 | if (Error Err = importInto(ToD, FromD)) |
| 1553 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1554 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1555 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1556 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { |
| 1557 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && |
| 1558 | !ToRecord->getDefinition()) { |
| 1559 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) |
| 1560 | return Err; |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1561 | } |
| 1562 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1563 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1566 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1567 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1568 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1569 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) |
| 1570 | return Err; |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1571 | } |
| 1572 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1573 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1574 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1575 | |
| 1576 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1579 | Error |
| 1580 | ASTNodeImporter::ImportDeclarationNameLoc( |
| 1581 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1582 | // NOTE: To.Name and To.Loc are already imported. |
| 1583 | // We only have to import To.LocInfo. |
| 1584 | switch (To.getName().getNameKind()) { |
| 1585 | case DeclarationName::Identifier: |
| 1586 | case DeclarationName::ObjCZeroArgSelector: |
| 1587 | case DeclarationName::ObjCOneArgSelector: |
| 1588 | case DeclarationName::ObjCMultiArgSelector: |
| 1589 | case DeclarationName::CXXUsingDirective: |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1590 | case DeclarationName::CXXDeductionGuideName: |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1591 | return Error::success(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1592 | |
| 1593 | case DeclarationName::CXXOperatorName: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1594 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) |
| 1595 | To.setCXXOperatorNameRange(*ToRangeOrErr); |
| 1596 | else |
| 1597 | return ToRangeOrErr.takeError(); |
| 1598 | return Error::success(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1599 | } |
| 1600 | case DeclarationName::CXXLiteralOperatorName: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1601 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) |
| 1602 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); |
| 1603 | else |
| 1604 | return LocOrErr.takeError(); |
| 1605 | return Error::success(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1606 | } |
| 1607 | case DeclarationName::CXXConstructorName: |
| 1608 | case DeclarationName::CXXDestructorName: |
| 1609 | case DeclarationName::CXXConversionFunctionName: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1610 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) |
| 1611 | To.setNamedTypeInfo(*ToTInfoOrErr); |
| 1612 | else |
| 1613 | return ToTInfoOrErr.takeError(); |
| 1614 | return Error::success(); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1615 | } |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1616 | } |
| Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1617 | llvm_unreachable("Unknown name kind."); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1620 | Error |
| 1621 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1622 | if (Importer.isMinimalImport() && !ForceImport) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1623 | auto ToDCOrErr = Importer.ImportContext(FromDC); |
| 1624 | return ToDCOrErr.takeError(); |
| 1625 | } |
| Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1626 | llvm::SmallVector<Decl *, 8> ImportedDecls; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1627 | for (auto *From : FromDC->decls()) { |
| 1628 | ExpectedDecl ImportedOrErr = import(From); |
| Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1629 | if (!ImportedOrErr) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1630 | // Ignore the error, continue with next Decl. |
| 1631 | // FIXME: Handle this case somehow better. |
| Davide Italiano | 93a64ef | 2018-10-30 20:46:29 +0000 | [diff] [blame] | 1632 | consumeError(ImportedOrErr.takeError()); |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1633 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1634 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1635 | return Error::success(); |
| Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1638 | Error ASTNodeImporter::ImportDeclContext( |
| 1639 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { |
| 1640 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); |
| 1641 | if (!ToDCOrErr) |
| 1642 | return ToDCOrErr.takeError(); |
| 1643 | ToDC = *ToDCOrErr; |
| 1644 | |
| 1645 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { |
| 1646 | auto ToLexicalDCOrErr = Importer.ImportContext( |
| 1647 | FromD->getLexicalDeclContext()); |
| 1648 | if (!ToLexicalDCOrErr) |
| 1649 | return ToLexicalDCOrErr.takeError(); |
| 1650 | ToLexicalDC = *ToLexicalDCOrErr; |
| 1651 | } else |
| 1652 | ToLexicalDC = ToDC; |
| 1653 | |
| 1654 | return Error::success(); |
| 1655 | } |
| 1656 | |
| 1657 | Error ASTNodeImporter::ImportImplicitMethods( |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1658 | const CXXRecordDecl *From, CXXRecordDecl *To) { |
| 1659 | assert(From->isCompleteDefinition() && To->getDefinition() == To && |
| 1660 | "Import implicit methods to or from non-definition"); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1661 | |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1662 | for (CXXMethodDecl *FromM : From->methods()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1663 | if (FromM->isImplicit()) { |
| 1664 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); |
| 1665 | if (!ToMOrErr) |
| 1666 | return ToMOrErr.takeError(); |
| 1667 | } |
| 1668 | |
| 1669 | return Error::success(); |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1672 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1673 | ASTImporter &Importer) { |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1674 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 1675 | if (ExpectedDecl ToTypedefOrErr = Importer.Import_New(FromTypedef)) |
| 1676 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); |
| 1677 | else |
| 1678 | return ToTypedefOrErr.takeError(); |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1679 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1680 | return Error::success(); |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1681 | } |
| 1682 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1683 | Error ASTNodeImporter::ImportDefinition( |
| 1684 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1685 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1686 | if (Kind == IDK_Everything) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1687 | return ImportDeclContext(From, /*ForceImport=*/true); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1688 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1689 | return Error::success(); |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1690 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1691 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1692 | To->startDefinition(); |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1693 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1694 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1695 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1696 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1697 | // Add base classes. |
| Gabor Marton | 17d3967 | 2018-11-26 15:54:08 +0000 | [diff] [blame] | 1698 | auto *ToCXX = dyn_cast<CXXRecordDecl>(To); |
| 1699 | auto *FromCXX = dyn_cast<CXXRecordDecl>(From); |
| 1700 | if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) { |
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1701 | |
| 1702 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1703 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 1704 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
| Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1705 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1706 | ToData.Aggregate = FromData.Aggregate; |
| 1707 | ToData.PlainOldData = FromData.PlainOldData; |
| 1708 | ToData.Empty = FromData.Empty; |
| 1709 | ToData.Polymorphic = FromData.Polymorphic; |
| 1710 | ToData.Abstract = FromData.Abstract; |
| 1711 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
| Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1712 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; |
| 1713 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; |
| 1714 | ToData.HasBasesWithNonStaticDataMembers = |
| 1715 | FromData.HasBasesWithNonStaticDataMembers; |
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1716 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 1717 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 1718 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 1719 | ToData.HasMutableFields = FromData.HasMutableFields; |
| Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1720 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
| Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1721 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
| Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1722 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
| Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1723 | ToData.HasUninitializedReferenceMember |
| 1724 | = FromData.HasUninitializedReferenceMember; |
| Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1725 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
| Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1726 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1727 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
| Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1728 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1729 | = FromData.NeedOverloadResolutionForCopyConstructor; |
| Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1730 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1731 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1732 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1733 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1734 | ToData.NeedOverloadResolutionForDestructor |
| 1735 | = FromData.NeedOverloadResolutionForDestructor; |
| Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1736 | ToData.DefaultedCopyConstructorIsDeleted |
| 1737 | = FromData.DefaultedCopyConstructorIsDeleted; |
| Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1738 | ToData.DefaultedMoveConstructorIsDeleted |
| 1739 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1740 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1741 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1742 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
| Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1743 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1744 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1745 | ToData.HasConstexprNonCopyMoveConstructor |
| 1746 | = FromData.HasConstexprNonCopyMoveConstructor; |
| Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1747 | ToData.HasDefaultedDefaultConstructor |
| 1748 | = FromData.HasDefaultedDefaultConstructor; |
| Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1749 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1750 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
| Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1751 | ToData.HasConstexprDefaultConstructor |
| 1752 | = FromData.HasConstexprDefaultConstructor; |
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1753 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1754 | = FromData.HasNonLiteralTypeFieldsOrBases; |
| Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1755 | // ComputedVisibleConversions not imported. |
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1756 | ToData.UserProvidedDefaultConstructor |
| 1757 | = FromData.UserProvidedDefaultConstructor; |
| Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1758 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
| Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1759 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1760 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1761 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1762 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
| Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1763 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1764 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1765 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1766 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1767 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1768 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
| Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1769 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1770 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1771 | for (const auto &Base1 : FromCXX->bases()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1772 | ExpectedType TyOrErr = import(Base1.getType()); |
| 1773 | if (!TyOrErr) |
| 1774 | return TyOrErr.takeError(); |
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1775 | |
| 1776 | SourceLocation EllipsisLoc; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1777 | if (Base1.isPackExpansion()) { |
| 1778 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) |
| 1779 | EllipsisLoc = *LocOrErr; |
| 1780 | else |
| 1781 | return LocOrErr.takeError(); |
| 1782 | } |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1783 | |
| 1784 | // Ensure that we have a definition for the base. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1785 | if (Error Err = |
| 1786 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) |
| 1787 | return Err; |
| 1788 | |
| 1789 | auto RangeOrErr = import(Base1.getSourceRange()); |
| 1790 | if (!RangeOrErr) |
| 1791 | return RangeOrErr.takeError(); |
| 1792 | |
| 1793 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); |
| 1794 | if (!TSIOrErr) |
| 1795 | return TSIOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1796 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1797 | Bases.push_back( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1798 | new (Importer.getToContext()) CXXBaseSpecifier( |
| 1799 | *RangeOrErr, |
| 1800 | Base1.isVirtual(), |
| 1801 | Base1.isBaseOfClass(), |
| 1802 | Base1.getAccessSpecifierAsWritten(), |
| 1803 | *TSIOrErr, |
| 1804 | EllipsisLoc)); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1805 | } |
| 1806 | if (!Bases.empty()) |
| Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1807 | ToCXX->setBases(Bases.data(), Bases.size()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1808 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1809 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1810 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1811 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1812 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1813 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1814 | To->completeDefinition(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1815 | return Error::success(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1816 | } |
| 1817 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1818 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1819 | if (To->getAnyInitializer()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1820 | return Error::success(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1821 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1822 | Expr *FromInit = From->getInit(); |
| 1823 | if (!FromInit) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1824 | return Error::success(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1825 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1826 | ExpectedExpr ToInitOrErr = import(FromInit); |
| 1827 | if (!ToInitOrErr) |
| 1828 | return ToInitOrErr.takeError(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1829 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1830 | To->setInit(*ToInitOrErr); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1831 | if (From->isInitKnownICE()) { |
| 1832 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); |
| 1833 | Eval->CheckedICE = true; |
| 1834 | Eval->IsICE = From->isInitICE(); |
| 1835 | } |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1836 | |
| 1837 | // FIXME: Other bits to merge? |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1838 | return Error::success(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1841 | Error ASTNodeImporter::ImportDefinition( |
| 1842 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1843 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1844 | if (Kind == IDK_Everything) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1845 | return ImportDeclContext(From, /*ForceImport=*/true); |
| 1846 | return Error::success(); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1847 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1848 | |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1849 | To->startDefinition(); |
| 1850 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1851 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) |
| 1852 | return Err; |
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1853 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1854 | ExpectedType ToTypeOrErr = |
| 1855 | import(Importer.getFromContext().getTypeDeclType(From)); |
| 1856 | if (!ToTypeOrErr) |
| 1857 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1858 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1859 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); |
| 1860 | if (!ToPromotionTypeOrErr) |
| 1861 | return ToPromotionTypeOrErr.takeError(); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1862 | |
| 1863 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1864 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 1865 | return Err; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1866 | |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1867 | // FIXME: we might need to merge the number of positive or negative bits |
| 1868 | // if the enumerator lists don't match. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1869 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1870 | From->getNumPositiveBits(), |
| 1871 | From->getNumNegativeBits()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1872 | return Error::success(); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1873 | } |
| 1874 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1875 | Error ASTNodeImporter::ImportTemplateArguments( |
| 1876 | const TemplateArgument *FromArgs, unsigned NumFromArgs, |
| 1877 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1878 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1879 | if (auto ToOrErr = import(FromArgs[I])) |
| 1880 | ToArgs.push_back(*ToOrErr); |
| 1881 | else |
| 1882 | return ToOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1883 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1884 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1885 | return Error::success(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1888 | // FIXME: Do not forget to remove this and use only 'import'. |
| 1889 | Expected<TemplateArgument> |
| 1890 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1891 | return import(From); |
| 1892 | } |
| 1893 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1894 | template <typename InContainerTy> |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1895 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1896 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1897 | for (const auto &FromLoc : Container) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1898 | if (auto ToLocOrErr = import(FromLoc)) |
| 1899 | ToTAInfo.addArgument(*ToLocOrErr); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1900 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1901 | return ToLocOrErr.takeError(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1902 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1903 | return Error::success(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1904 | } |
| 1905 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1906 | static StructuralEquivalenceKind |
| 1907 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 1908 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 1909 | : StructuralEquivalenceKind::Default; |
| 1910 | } |
| 1911 | |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1912 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { |
| 1913 | StructuralEquivalenceContext Ctx( |
| 1914 | Importer.getFromContext(), Importer.getToContext(), |
| 1915 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1916 | false, Complain); |
| 1917 | return Ctx.IsEquivalent(From, To); |
| 1918 | } |
| 1919 | |
| 1920 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1921 | RecordDecl *ToRecord, bool Complain) { |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1922 | // Eliminate a potential failure point where we attempt to re-import |
| 1923 | // something we're trying to import while completing ToRecord. |
| 1924 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1925 | if (ToOrigin) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1926 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1927 | if (ToOriginRecord) |
| 1928 | ToRecord = ToOriginRecord; |
| 1929 | } |
| 1930 | |
| Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1931 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1932 | ToRecord->getASTContext(), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1933 | Importer.getNonEquivalentDecls(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1934 | getStructuralEquivalenceKind(Importer), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1935 | false, Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1936 | return Ctx.IsEquivalent(FromRecord, ToRecord); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1937 | } |
| 1938 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1939 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 1940 | bool Complain) { |
| 1941 | StructuralEquivalenceContext Ctx( |
| 1942 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1943 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1944 | false, Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1945 | return Ctx.IsEquivalent(FromVar, ToVar); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1946 | } |
| 1947 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1948 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
| Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 1949 | // Eliminate a potential failure point where we attempt to re-import |
| 1950 | // something we're trying to import while completin ToEnum |
| 1951 | if (Decl *ToOrigin = Importer.GetOriginalDecl(ToEnum)) |
| 1952 | if (auto *ToOriginEnum = dyn_cast<EnumDecl>(ToOrigin)) |
| 1953 | ToEnum = ToOriginEnum; |
| 1954 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1955 | StructuralEquivalenceContext Ctx( |
| 1956 | Importer.getFromContext(), Importer.getToContext(), |
| 1957 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1958 | return Ctx.IsEquivalent(FromEnum, ToEnum); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1961 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 1962 | FunctionTemplateDecl *To) { |
| 1963 | StructuralEquivalenceContext Ctx( |
| 1964 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1965 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1966 | false, false); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1967 | return Ctx.IsEquivalent(From, To); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1968 | } |
| 1969 | |
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 1970 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 1971 | StructuralEquivalenceContext Ctx( |
| 1972 | Importer.getFromContext(), Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1973 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1974 | false, false); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1975 | return Ctx.IsEquivalent(From, To); |
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 1976 | } |
| 1977 | |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1978 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1979 | EnumConstantDecl *ToEC) { |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1980 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 1981 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 1982 | |
| 1983 | return FromVal.isSigned() == ToVal.isSigned() && |
| 1984 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 1985 | FromVal == ToVal; |
| 1986 | } |
| 1987 | |
| 1988 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1989 | ClassTemplateDecl *To) { |
| 1990 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1991 | Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1992 | Importer.getNonEquivalentDecls(), |
| 1993 | getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1994 | return Ctx.IsEquivalent(From, To); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1995 | } |
| 1996 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1997 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 1998 | VarTemplateDecl *To) { |
| 1999 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 2000 | Importer.getToContext(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2001 | Importer.getNonEquivalentDecls(), |
| 2002 | getStructuralEquivalenceKind(Importer)); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2003 | return Ctx.IsEquivalent(From, To); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2004 | } |
| 2005 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2006 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 2007 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2008 | << D->getDeclKindName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2009 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2010 | } |
| 2011 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2012 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { |
| 2013 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 2014 | << D->getDeclKindName(); |
| 2015 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| 2016 | } |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2017 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2018 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 2019 | // Import the context of this declaration. |
| 2020 | DeclContext *DC, *LexicalDC; |
| 2021 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 2022 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2023 | |
| 2024 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2025 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2026 | if (!LocOrErr) |
| 2027 | return LocOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2028 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2029 | EmptyDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2030 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2031 | return ToD; |
| 2032 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2033 | ToD->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2034 | LexicalDC->addDeclInternal(ToD); |
| 2035 | return ToD; |
| 2036 | } |
| 2037 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2038 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2039 | TranslationUnitDecl *ToD = |
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2040 | Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2041 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2042 | Importer.MapImported(D, ToD); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2043 | |
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2044 | return ToD; |
| 2045 | } |
| 2046 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2047 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
| 2048 | ExpectedSLoc LocOrErr = import(D->getLocation()); |
| 2049 | if (!LocOrErr) |
| 2050 | return LocOrErr.takeError(); |
| 2051 | auto ColonLocOrErr = import(D->getColonLoc()); |
| 2052 | if (!ColonLocOrErr) |
| 2053 | return ColonLocOrErr.takeError(); |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2054 | |
| 2055 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2056 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2057 | if (!DCOrErr) |
| 2058 | return DCOrErr.takeError(); |
| 2059 | DeclContext *DC = *DCOrErr; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2060 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2061 | AccessSpecDecl *ToD; |
| 2062 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2063 | DC, *LocOrErr, *ColonLocOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2064 | return ToD; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2065 | |
| 2066 | // Lexical DeclContext and Semantic DeclContext |
| 2067 | // is always the same for the accessSpec. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2068 | ToD->setLexicalDeclContext(DC); |
| 2069 | DC->addDeclInternal(ToD); |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2070 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2071 | return ToD; |
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2072 | } |
| 2073 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2074 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 2075 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); |
| 2076 | if (!DCOrErr) |
| 2077 | return DCOrErr.takeError(); |
| 2078 | DeclContext *DC = *DCOrErr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2079 | DeclContext *LexicalDC = DC; |
| 2080 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2081 | SourceLocation ToLocation, ToRParenLoc; |
| 2082 | Expr *ToAssertExpr; |
| 2083 | StringLiteral *ToMessage; |
| 2084 | if (auto Imp = importSeq( |
| 2085 | D->getLocation(), D->getAssertExpr(), D->getMessage(), D->getRParenLoc())) |
| 2086 | std::tie(ToLocation, ToAssertExpr, ToMessage, ToRParenLoc) = *Imp; |
| 2087 | else |
| 2088 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2089 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2090 | StaticAssertDecl *ToD; |
| 2091 | if (GetImportedOrCreateDecl( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2092 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, |
| 2093 | ToRParenLoc, D->isFailed())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2094 | return ToD; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2095 | |
| 2096 | ToD->setLexicalDeclContext(LexicalDC); |
| 2097 | LexicalDC->addDeclInternal(ToD); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2098 | return ToD; |
| 2099 | } |
| 2100 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2101 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2102 | // Import the major distinguishing characteristics of this namespace. |
| 2103 | DeclContext *DC, *LexicalDC; |
| 2104 | DeclarationName Name; |
| 2105 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2106 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2107 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2108 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2109 | if (ToD) |
| 2110 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2111 | |
| 2112 | NamespaceDecl *MergeWithNamespace = nullptr; |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2113 | if (!Name) { |
| 2114 | // This is an anonymous namespace. Adopt an existing anonymous |
| 2115 | // namespace if we can. |
| 2116 | // FIXME: Not testable. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2117 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2118 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 2119 | else |
| 2120 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 2121 | } else { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2122 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2123 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2124 | for (auto *FoundDecl : FoundDecls) { |
| 2125 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2126 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2127 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2128 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2129 | MergeWithNamespace = FoundNS; |
| 2130 | ConflictingDecls.clear(); |
| 2131 | break; |
| 2132 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2133 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2134 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2135 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2136 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2137 | if (!ConflictingDecls.empty()) { |
| John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 2138 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2139 | ConflictingDecls.data(), |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2140 | ConflictingDecls.size()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2141 | if (!Name) |
| 2142 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2143 | } |
| 2144 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2145 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2146 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2147 | if (!BeginLocOrErr) |
| 2148 | return BeginLocOrErr.takeError(); |
| 2149 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2150 | // Create the "to" namespace, if needed. |
| 2151 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 2152 | if (!ToNamespace) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2153 | if (GetImportedOrCreateDecl( |
| 2154 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2155 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2156 | /*PrevDecl=*/nullptr)) |
| 2157 | return ToNamespace; |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2158 | ToNamespace->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2159 | LexicalDC->addDeclInternal(ToNamespace); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2160 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2161 | // If this is an anonymous namespace, register it as the anonymous |
| 2162 | // namespace within its context. |
| 2163 | if (!Name) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2164 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2165 | TU->setAnonymousNamespace(ToNamespace); |
| 2166 | else |
| 2167 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 2168 | } |
| 2169 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2170 | Importer.MapImported(D, ToNamespace); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2171 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2172 | if (Error Err = ImportDeclContext(D)) |
| 2173 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2174 | |
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2175 | return ToNamespace; |
| 2176 | } |
| 2177 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2178 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2179 | // Import the major distinguishing characteristics of this namespace. |
| 2180 | DeclContext *DC, *LexicalDC; |
| 2181 | DeclarationName Name; |
| 2182 | SourceLocation Loc; |
| 2183 | NamedDecl *LookupD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2184 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 2185 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2186 | if (LookupD) |
| 2187 | return LookupD; |
| 2188 | |
| 2189 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 2190 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2191 | SourceLocation ToNamespaceLoc, ToAliasLoc, ToTargetNameLoc; |
| 2192 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2193 | NamespaceDecl *ToNamespace; |
| 2194 | if (auto Imp = importSeq( |
| 2195 | D->getNamespaceLoc(), D->getAliasLoc(), D->getQualifierLoc(), |
| 2196 | D->getTargetNameLoc(), D->getNamespace())) |
| 2197 | std::tie( |
| 2198 | ToNamespaceLoc, ToAliasLoc, ToQualifierLoc, ToTargetNameLoc, |
| 2199 | ToNamespace) = *Imp; |
| 2200 | else |
| 2201 | return Imp.takeError(); |
| 2202 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2203 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2204 | NamespaceAliasDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2205 | if (GetImportedOrCreateDecl( |
| 2206 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, |
| 2207 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2208 | return ToD; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2209 | |
| 2210 | ToD->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2211 | LexicalDC->addDeclInternal(ToD); |
| 2212 | |
| 2213 | return ToD; |
| 2214 | } |
| 2215 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2216 | ExpectedDecl |
| 2217 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2218 | // Import the major distinguishing characteristics of this typedef. |
| 2219 | DeclContext *DC, *LexicalDC; |
| 2220 | DeclarationName Name; |
| 2221 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2222 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2223 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2224 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2225 | if (ToD) |
| 2226 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2227 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2228 | // If this typedef is not in block scope, determine whether we've |
| 2229 | // seen a typedef with the same name (that we can merge with) or any |
| 2230 | // other entity by that name (which name lookup could conflict with). |
| 2231 | if (!DC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2232 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2233 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2234 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2235 | for (auto *FoundDecl : FoundDecls) { |
| 2236 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2237 | continue; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2238 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
| Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2239 | QualType FromUT = D->getUnderlyingType(); |
| 2240 | QualType FoundUT = FoundTypedef->getUnderlyingType(); |
| 2241 | if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) { |
| 2242 | // If the "From" context has a complete underlying type but we |
| 2243 | // already have a complete underlying type then return with that. |
| 2244 | if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2245 | return Importer.MapImported(D, FoundTypedef); |
| Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2246 | } |
| 2247 | // FIXME Handle redecl chain. |
| 2248 | break; |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2249 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2250 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2251 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2252 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2253 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2254 | if (!ConflictingDecls.empty()) { |
| 2255 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2256 | ConflictingDecls.data(), |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2257 | ConflictingDecls.size()); |
| 2258 | if (!Name) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2259 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2260 | } |
| 2261 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2262 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2263 | QualType ToUnderlyingType; |
| 2264 | TypeSourceInfo *ToTypeSourceInfo; |
| 2265 | SourceLocation ToBeginLoc; |
| 2266 | if (auto Imp = importSeq( |
| 2267 | D->getUnderlyingType(), D->getTypeSourceInfo(), D->getBeginLoc())) |
| 2268 | std::tie(ToUnderlyingType, ToTypeSourceInfo, ToBeginLoc) = *Imp; |
| 2269 | else |
| 2270 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2271 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2272 | // Create the new typedef node. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2273 | // FIXME: ToUnderlyingType is not used. |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2274 | TypedefNameDecl *ToTypedef; |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2275 | if (IsAlias) { |
| 2276 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2277 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2278 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2279 | return ToTypedef; |
| 2280 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2281 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, |
| 2282 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2283 | return ToTypedef; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2284 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2285 | ToTypedef->setAccess(D->getAccess()); |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2286 | ToTypedef->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2287 | |
| 2288 | // Templated declarations should not appear in DeclContext. |
| 2289 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 2290 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 2291 | LexicalDC->addDeclInternal(ToTypedef); |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2292 | |
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2293 | return ToTypedef; |
| 2294 | } |
| 2295 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2296 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2297 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 2298 | } |
| 2299 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2300 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2301 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 2302 | } |
| 2303 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2304 | ExpectedDecl |
| 2305 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2306 | // Import the major distinguishing characteristics of this typedef. |
| 2307 | DeclContext *DC, *LexicalDC; |
| 2308 | DeclarationName Name; |
| 2309 | SourceLocation Loc; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2310 | NamedDecl *FoundD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2311 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
| 2312 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2313 | if (FoundD) |
| 2314 | return FoundD; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2315 | |
| 2316 | // If this typedef is not in block scope, determine whether we've |
| 2317 | // seen a typedef with the same name (that we can merge with) or any |
| 2318 | // other entity by that name (which name lookup could conflict with). |
| 2319 | if (!DC->isFunctionOrMethod()) { |
| 2320 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 2321 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2322 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2323 | for (auto *FoundDecl : FoundDecls) { |
| 2324 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2325 | continue; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2326 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2327 | return Importer.MapImported(D, FoundAlias); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2328 | ConflictingDecls.push_back(FoundDecl); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | if (!ConflictingDecls.empty()) { |
| 2332 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2333 | ConflictingDecls.data(), |
| 2334 | ConflictingDecls.size()); |
| 2335 | if (!Name) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2336 | return make_error<ImportError>(ImportError::NameConflict); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2337 | } |
| 2338 | } |
| 2339 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2340 | TemplateParameterList *ToTemplateParameters; |
| 2341 | TypeAliasDecl *ToTemplatedDecl; |
| 2342 | if (auto Imp = importSeq(D->getTemplateParameters(), D->getTemplatedDecl())) |
| 2343 | std::tie(ToTemplateParameters, ToTemplatedDecl) = *Imp; |
| 2344 | else |
| 2345 | return Imp.takeError(); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2346 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2347 | TypeAliasTemplateDecl *ToAlias; |
| 2348 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2349 | Name, ToTemplateParameters, ToTemplatedDecl)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2350 | return ToAlias; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2351 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2352 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2353 | |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2354 | ToAlias->setAccess(D->getAccess()); |
| 2355 | ToAlias->setLexicalDeclContext(LexicalDC); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2356 | LexicalDC->addDeclInternal(ToAlias); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2357 | return ToAlias; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2358 | } |
| 2359 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2360 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2361 | // Import the major distinguishing characteristics of this label. |
| 2362 | DeclContext *DC, *LexicalDC; |
| 2363 | DeclarationName Name; |
| 2364 | SourceLocation Loc; |
| 2365 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2366 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2367 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2368 | if (ToD) |
| 2369 | return ToD; |
| 2370 | |
| 2371 | assert(LexicalDC->isFunctionOrMethod()); |
| 2372 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2373 | LabelDecl *ToLabel; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2374 | if (D->isGnuLocal()) { |
| 2375 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2376 | if (!BeginLocOrErr) |
| 2377 | return BeginLocOrErr.takeError(); |
| 2378 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2379 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) |
| 2380 | return ToLabel; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2381 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2382 | } else { |
| 2383 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, |
| 2384 | Name.getAsIdentifierInfo())) |
| 2385 | return ToLabel; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2386 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2387 | } |
| 2388 | |
| 2389 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); |
| 2390 | if (!ToStmtOrErr) |
| 2391 | return ToStmtOrErr.takeError(); |
| 2392 | |
| 2393 | ToLabel->setStmt(*ToStmtOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2394 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2395 | LexicalDC->addDeclInternal(ToLabel); |
| 2396 | return ToLabel; |
| 2397 | } |
| 2398 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2399 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2400 | // Import the major distinguishing characteristics of this enum. |
| 2401 | DeclContext *DC, *LexicalDC; |
| 2402 | DeclarationName Name; |
| 2403 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2404 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2405 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2406 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2407 | if (ToD) |
| 2408 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2409 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2410 | // Figure out what enum name we're looking for. |
| 2411 | unsigned IDNS = Decl::IDNS_Tag; |
| 2412 | DeclarationName SearchName = Name; |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2413 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2414 | if (Error Err = importInto( |
| 2415 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2416 | return std::move(Err); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2417 | IDNS = Decl::IDNS_Ordinary; |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2418 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2419 | IDNS |= Decl::IDNS_Ordinary; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2420 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2421 | // We may already have an enum of the same name; try to find and match it. |
| 2422 | if (!DC->isFunctionOrMethod() && SearchName) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2423 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2424 | auto FoundDecls = |
| 2425 | Importer.findDeclsInToCtx(DC, SearchName); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2426 | for (auto *FoundDecl : FoundDecls) { |
| 2427 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2428 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2429 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2430 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2431 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2432 | FoundDecl = Tag->getDecl(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2433 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2434 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2435 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2436 | if (IsStructuralMatch(D, FoundEnum)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2437 | return Importer.MapImported(D, FoundEnum); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2438 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2439 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2440 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2441 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2442 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2443 | if (!ConflictingDecls.empty()) { |
| Shafik Yaghmour | d426312 | 2019-04-08 20:50:21 +0000 | [diff] [blame] | 2444 | Name = Importer.HandleNameConflict(SearchName, DC, IDNS, |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2445 | ConflictingDecls.data(), |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2446 | ConflictingDecls.size()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2447 | if (!Name) |
| 2448 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2449 | } |
| 2450 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2451 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2452 | SourceLocation ToBeginLoc; |
| 2453 | NestedNameSpecifierLoc ToQualifierLoc; |
| 2454 | QualType ToIntegerType; |
| 2455 | if (auto Imp = importSeq( |
| 2456 | D->getBeginLoc(), D->getQualifierLoc(), D->getIntegerType())) |
| 2457 | std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType) = *Imp; |
| 2458 | else |
| 2459 | return Imp.takeError(); |
| 2460 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2461 | // Create the enum declaration. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2462 | EnumDecl *D2; |
| 2463 | if (GetImportedOrCreateDecl( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2464 | D2, D, Importer.getToContext(), DC, ToBeginLoc, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2465 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), |
| 2466 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2467 | return D2; |
| 2468 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2469 | D2->setQualifierInfo(ToQualifierLoc); |
| 2470 | D2->setIntegerType(ToIntegerType); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2471 | D2->setAccess(D->getAccess()); |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2472 | D2->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2473 | LexicalDC->addDeclInternal(D2); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2474 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2475 | // Import the definition |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2476 | if (D->isCompleteDefinition()) |
| 2477 | if (Error Err = ImportDefinition(D, D2)) |
| 2478 | return std::move(Err); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2479 | |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2480 | return D2; |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2481 | } |
| 2482 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2483 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2484 | bool IsFriendTemplate = false; |
| 2485 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2486 | IsFriendTemplate = |
| 2487 | DCXX->getDescribedClassTemplate() && |
| 2488 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != |
| 2489 | Decl::FOK_None; |
| 2490 | } |
| 2491 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2492 | // Import the major distinguishing characteristics of this record. |
| 2493 | DeclContext *DC, *LexicalDC; |
| 2494 | DeclarationName Name; |
| 2495 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2496 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2497 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2498 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2499 | if (ToD) |
| 2500 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2501 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2502 | // Figure out what structure name we're looking for. |
| 2503 | unsigned IDNS = Decl::IDNS_Tag; |
| 2504 | DeclarationName SearchName = Name; |
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2505 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2506 | if (Error Err = importInto( |
| 2507 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) |
| 2508 | return std::move(Err); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2509 | IDNS = Decl::IDNS_Ordinary; |
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2510 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2511 | IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2512 | |
| 2513 | // 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] | 2514 | RecordDecl *PrevDecl = nullptr; |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2515 | if (!DC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2516 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2517 | auto FoundDecls = |
| 2518 | Importer.findDeclsInToCtx(DC, SearchName); |
| Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2519 | if (!FoundDecls.empty()) { |
| Gabor Marton | 41e3892 | 2019-03-05 11:23:24 +0000 | [diff] [blame] | 2520 | // We're going to have to compare D against potentially conflicting Decls, |
| 2521 | // so complete it. |
| Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2522 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2523 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2524 | } |
| 2525 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2526 | for (auto *FoundDecl : FoundDecls) { |
| 2527 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2528 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2529 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2530 | Decl *Found = FoundDecl; |
| 2531 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2532 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2533 | Found = Tag->getDecl(); |
| 2534 | } |
| Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2535 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2536 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2537 | // Do not emit false positive diagnostic in case of unnamed |
| 2538 | // struct/union and in case of anonymous structs. Would be false |
| 2539 | // because there may be several anonymous/unnamed structs in a class. |
| 2540 | // E.g. these are both valid: |
| 2541 | // struct A { // unnamed structs |
| 2542 | // struct { struct A *next; } entry0; |
| 2543 | // struct { struct A *next; } entry1; |
| 2544 | // }; |
| 2545 | // struct X { struct { int a; }; struct { int b; }; }; // anon structs |
| 2546 | if (!SearchName) |
| Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2547 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2548 | continue; |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2549 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2550 | if (IsStructuralMatch(D, FoundRecord)) { |
| 2551 | RecordDecl *FoundDef = FoundRecord->getDefinition(); |
| 2552 | if (D->isThisDeclarationADefinition() && FoundDef) { |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2553 | // FIXME: Structural equivalence check should check for same |
| 2554 | // user-defined methods. |
| 2555 | Importer.MapImported(D, FoundDef); |
| 2556 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2557 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); |
| 2558 | assert(FoundCXX && "Record type mismatch"); |
| 2559 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2560 | if (!Importer.isMinimalImport()) |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2561 | // FoundDef may not have every implicit method that D has |
| 2562 | // because implicit methods are created only if they are used. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2563 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) |
| 2564 | return std::move(Err); |
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2565 | } |
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2566 | } |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2567 | PrevDecl = FoundRecord->getMostRecentDecl(); |
| 2568 | break; |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2569 | } |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2570 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2571 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2572 | ConflictingDecls.push_back(FoundDecl); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2573 | } // for |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2574 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2575 | if (!ConflictingDecls.empty() && SearchName) { |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2576 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2577 | ConflictingDecls.data(), |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2578 | ConflictingDecls.size()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2579 | if (!Name) |
| 2580 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2581 | } |
| 2582 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2583 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2584 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 2585 | if (!BeginLocOrErr) |
| 2586 | return BeginLocOrErr.takeError(); |
| 2587 | |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2588 | // Create the record declaration. |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2589 | RecordDecl *D2 = nullptr; |
| 2590 | CXXRecordDecl *D2CXX = nullptr; |
| 2591 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2592 | if (DCXX->isLambda()) { |
| 2593 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); |
| 2594 | if (!TInfoOrErr) |
| 2595 | return TInfoOrErr.takeError(); |
| 2596 | if (GetImportedOrCreateSpecialDecl( |
| 2597 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
| 2598 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), |
| 2599 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2600 | return D2CXX; |
| 2601 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); |
| 2602 | if (!CDeclOrErr) |
| 2603 | return CDeclOrErr.takeError(); |
| 2604 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr); |
| 2605 | } else if (DCXX->isInjectedClassName()) { |
| 2606 | // We have to be careful to do a similar dance to the one in |
| 2607 | // Sema::ActOnStartCXXMemberDeclarations |
| 2608 | const bool DelayTypeCreation = true; |
| 2609 | if (GetImportedOrCreateDecl( |
| 2610 | D2CXX, D, Importer.getToContext(), D->getTagKind(), DC, |
| 2611 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), |
| 2612 | cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation)) |
| 2613 | return D2CXX; |
| 2614 | Importer.getToContext().getTypeDeclType( |
| 2615 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
| 2616 | } else { |
| 2617 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2618 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2619 | Name.getAsIdentifierInfo(), |
| 2620 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2621 | return D2CXX; |
| 2622 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2623 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2624 | D2 = D2CXX; |
| 2625 | D2->setAccess(D->getAccess()); |
| 2626 | D2->setLexicalDeclContext(LexicalDC); |
| 2627 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) |
| 2628 | LexicalDC->addDeclInternal(D2); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2629 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2630 | if (LexicalDC != DC && D->isInIdentifierNamespace(Decl::IDNS_TagFriend)) |
| 2631 | DC->makeDeclVisibleInContext(D2); |
| 2632 | |
| 2633 | if (ClassTemplateDecl *FromDescribed = |
| 2634 | DCXX->getDescribedClassTemplate()) { |
| 2635 | ClassTemplateDecl *ToDescribed; |
| 2636 | if (Error Err = importInto(ToDescribed, FromDescribed)) |
| 2637 | return std::move(Err); |
| 2638 | D2CXX->setDescribedClassTemplate(ToDescribed); |
| 2639 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { |
| 2640 | // In a record describing a template the type should be an |
| 2641 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2642 | // previously set type to the correct value here (ToDescribed is not |
| 2643 | // available at record create). |
| 2644 | // FIXME: The previous type is cleared but not removed from |
| 2645 | // ASTContext's internal storage. |
| 2646 | CXXRecordDecl *Injected = nullptr; |
| 2647 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2648 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2649 | if (Record && Record->isInjectedClassName()) { |
| 2650 | Injected = Record; |
| 2651 | break; |
| Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2652 | } |
| 2653 | } |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2654 | // Create an injected type for the whole redecl chain. |
| 2655 | SmallVector<Decl *, 2> Redecls = |
| 2656 | getCanonicalForwardRedeclChain(D2CXX); |
| 2657 | for (auto *R : Redecls) { |
| 2658 | auto *RI = cast<CXXRecordDecl>(R); |
| 2659 | RI->setTypeForDecl(nullptr); |
| 2660 | // Below we create a new injected type and assign that to the |
| 2661 | // canonical decl, subsequent declarations in the chain will reuse |
| 2662 | // that type. |
| 2663 | Importer.getToContext().getInjectedClassNameType( |
| 2664 | RI, ToDescribed->getInjectedClassNameSpecialization()); |
| 2665 | } |
| 2666 | // Set the new type for the previous injected decl too. |
| 2667 | if (Injected) { |
| 2668 | Injected->setTypeForDecl(nullptr); |
| 2669 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2670 | } |
| 2671 | } |
| 2672 | } else if (MemberSpecializationInfo *MemberInfo = |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2673 | DCXX->getMemberSpecializationInfo()) { |
| 2674 | TemplateSpecializationKind SK = |
| 2675 | MemberInfo->getTemplateSpecializationKind(); |
| 2676 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2677 | |
| 2678 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) |
| 2679 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); |
| 2680 | else |
| 2681 | return ToInstOrErr.takeError(); |
| 2682 | |
| 2683 | if (ExpectedSLoc POIOrErr = |
| 2684 | import(MemberInfo->getPointOfInstantiation())) |
| 2685 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2686 | *POIOrErr); |
| 2687 | else |
| 2688 | return POIOrErr.takeError(); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2689 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2690 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2691 | } else { |
| 2692 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
| 2693 | D->getTagKind(), DC, *BeginLocOrErr, Loc, |
| 2694 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2695 | return D2; |
| 2696 | D2->setLexicalDeclContext(LexicalDC); |
| 2697 | LexicalDC->addDeclInternal(D2); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2698 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2699 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2700 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) |
| 2701 | D2->setQualifierInfo(*QualifierLocOrErr); |
| 2702 | else |
| 2703 | return QualifierLocOrErr.takeError(); |
| 2704 | |
| 2705 | if (D->isAnonymousStructOrUnion()) |
| 2706 | D2->setAnonymousStructOrUnion(true); |
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2707 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2708 | if (D->isCompleteDefinition()) |
| 2709 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) |
| 2710 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2711 | |
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2712 | return D2; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2713 | } |
| 2714 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2715 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2716 | // Import the major distinguishing characteristics of this enumerator. |
| 2717 | DeclContext *DC, *LexicalDC; |
| 2718 | DeclarationName Name; |
| 2719 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2720 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2721 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2722 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2723 | if (ToD) |
| 2724 | return ToD; |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2725 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2726 | // Determine whether there are any other declarations with the same name and |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2727 | // in the same context. |
| 2728 | if (!LexicalDC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2729 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2730 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2731 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2732 | for (auto *FoundDecl : FoundDecls) { |
| 2733 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2734 | continue; |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2735 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2736 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2737 | if (IsStructuralMatch(D, FoundEnumConstant)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2738 | return Importer.MapImported(D, FoundEnumConstant); |
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2739 | } |
| 2740 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2741 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2742 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2743 | |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2744 | if (!ConflictingDecls.empty()) { |
| 2745 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2746 | ConflictingDecls.data(), |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2747 | ConflictingDecls.size()); |
| 2748 | if (!Name) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2749 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2750 | } |
| 2751 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2752 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2753 | ExpectedType TypeOrErr = import(D->getType()); |
| 2754 | if (!TypeOrErr) |
| 2755 | return TypeOrErr.takeError(); |
| 2756 | |
| 2757 | ExpectedExpr InitOrErr = import(D->getInitExpr()); |
| 2758 | if (!InitOrErr) |
| 2759 | return InitOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2760 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2761 | EnumConstantDecl *ToEnumerator; |
| 2762 | if (GetImportedOrCreateDecl( |
| 2763 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2764 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2765 | return ToEnumerator; |
| 2766 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2767 | ToEnumerator->setAccess(D->getAccess()); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2768 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2769 | LexicalDC->addDeclInternal(ToEnumerator); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2770 | return ToEnumerator; |
| 2771 | } |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2772 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2773 | Error ASTNodeImporter::ImportTemplateInformation( |
| 2774 | FunctionDecl *FromFD, FunctionDecl *ToFD) { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2775 | switch (FromFD->getTemplatedKind()) { |
| 2776 | case FunctionDecl::TK_NonTemplate: |
| 2777 | case FunctionDecl::TK_FunctionTemplate: |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2778 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2779 | |
| 2780 | case FunctionDecl::TK_MemberSpecialization: { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2781 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2782 | |
| 2783 | if (Expected<FunctionDecl *> InstFDOrErr = |
| 2784 | import(FromFD->getInstantiatedFromMemberFunction())) |
| 2785 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); |
| 2786 | else |
| 2787 | return InstFDOrErr.takeError(); |
| 2788 | |
| 2789 | if (ExpectedSLoc POIOrErr = import( |
| 2790 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) |
| 2791 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); |
| 2792 | else |
| 2793 | return POIOrErr.takeError(); |
| 2794 | |
| 2795 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2796 | } |
| 2797 | |
| 2798 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2799 | auto FunctionAndArgsOrErr = |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2800 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2801 | if (!FunctionAndArgsOrErr) |
| 2802 | return FunctionAndArgsOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2803 | |
| 2804 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2805 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2806 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2807 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2808 | TemplateArgumentListInfo ToTAInfo; |
| 2809 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2810 | if (FromTAArgsAsWritten) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2811 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2812 | *FromTAArgsAsWritten, ToTAInfo)) |
| 2813 | return Err; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2814 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2815 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); |
| 2816 | if (!POIOrErr) |
| 2817 | return POIOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2818 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2819 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2820 | ToFD->setFunctionTemplateSpecialization( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2821 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, |
| 2822 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); |
| 2823 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 2827 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 2828 | UnresolvedSet<8> TemplDecls; |
| 2829 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 2830 | for (unsigned I = 0; I < NumTemplates; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2831 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = |
| 2832 | import(FromInfo->getTemplate(I))) |
| 2833 | TemplDecls.addDecl(*ToFTDOrErr); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2834 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2835 | return ToFTDOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | // Import TemplateArgumentListInfo. |
| 2839 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2840 | if (Error Err = ImportTemplateArgumentListInfo( |
| 2841 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 2842 | llvm::makeArrayRef( |
| 2843 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), |
| 2844 | ToTAInfo)) |
| 2845 | return Err; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2846 | |
| 2847 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 2848 | TemplDecls, ToTAInfo); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2849 | return Error::success(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2850 | } |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2851 | } |
| Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2852 | llvm_unreachable("All cases should be covered!"); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2853 | } |
| 2854 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2855 | Expected<FunctionDecl *> |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2856 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2857 | auto FunctionAndArgsOrErr = |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2858 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2859 | if (!FunctionAndArgsOrErr) |
| 2860 | return FunctionAndArgsOrErr.takeError(); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2861 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2862 | FunctionTemplateDecl *Template; |
| 2863 | TemplateArgsTy ToTemplArgs; |
| 2864 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2865 | void *InsertPos = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2866 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2867 | return FoundSpec; |
| 2868 | } |
| 2869 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 2870 | Error ASTNodeImporter::ImportFunctionDeclBody(FunctionDecl *FromFD, |
| 2871 | FunctionDecl *ToFD) { |
| 2872 | if (Stmt *FromBody = FromFD->getBody()) { |
| 2873 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) |
| 2874 | ToFD->setBody(*ToBodyOrErr); |
| 2875 | else |
| 2876 | return ToBodyOrErr.takeError(); |
| 2877 | } |
| 2878 | return Error::success(); |
| 2879 | } |
| 2880 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2881 | template <typename T> |
| 2882 | bool ASTNodeImporter::hasSameVisibilityContext(T *Found, T *From) { |
| 2883 | if (From->hasExternalFormalLinkage()) |
| 2884 | return Found->hasExternalFormalLinkage(); |
| 2885 | if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl()) |
| 2886 | return false; |
| 2887 | if (From->isInAnonymousNamespace()) |
| 2888 | return Found->isInAnonymousNamespace(); |
| 2889 | else |
| 2890 | return !Found->isInAnonymousNamespace() && |
| 2891 | !Found->hasExternalFormalLinkage(); |
| 2892 | } |
| 2893 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2894 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2895 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2896 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2897 | auto RedeclIt = Redecls.begin(); |
| 2898 | // Import the first part of the decl chain. I.e. import all previous |
| 2899 | // declarations starting from the canonical decl. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2900 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 2901 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 2902 | if (!ToRedeclOrErr) |
| 2903 | return ToRedeclOrErr.takeError(); |
| 2904 | } |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2905 | assert(*RedeclIt == D); |
| 2906 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2907 | // Import the major distinguishing characteristics of this function. |
| 2908 | DeclContext *DC, *LexicalDC; |
| 2909 | DeclarationName Name; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2910 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2911 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2912 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2913 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2914 | if (ToD) |
| 2915 | return ToD; |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2916 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 2917 | FunctionDecl *FoundByLookup = nullptr; |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 2918 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); |
| Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2919 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2920 | // 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] | 2921 | // existing specialization in the "to" context. The lookup below will not |
| 2922 | // find any specialization, but would find the primary template; thus, we |
| 2923 | // have to skip normal lookup in case of specializations. |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2924 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 2925 | if (D->getTemplatedKind() == |
| 2926 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2927 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); |
| 2928 | if (!FoundFunctionOrErr) |
| 2929 | return FoundFunctionOrErr.takeError(); |
| 2930 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { |
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 2931 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 2932 | return Def; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2933 | FoundByLookup = FoundFunction; |
| 2934 | } |
| 2935 | } |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2936 | // Try to find a function in our own ("to") context with the same name, same |
| 2937 | // type, and in the same context as the function we're importing. |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2938 | else if (!LexicalDC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2939 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2940 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2941 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2942 | for (auto *FoundDecl : FoundDecls) { |
| 2943 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2944 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2945 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2946 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2947 | if (!hasSameVisibilityContext(FoundFunction, D)) |
| 2948 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2949 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2950 | if (IsStructuralMatch(D, FoundFunction)) { |
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 2951 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) |
| 2952 | return Def; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2953 | FoundByLookup = FoundFunction; |
| 2954 | break; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2955 | } |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2956 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 2957 | // Sema::IsOverload out to the AST library. |
| 2958 | |
| 2959 | // Function overloading is okay in C++. |
| 2960 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
| 2961 | continue; |
| 2962 | |
| 2963 | // Complain about inconsistent function types. |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 2964 | Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 2965 | << Name << D->getType() << FoundFunction->getType(); |
| 2966 | Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here) |
| 2967 | << FoundFunction->getType(); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2968 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2969 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2970 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2971 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2972 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2973 | if (!ConflictingDecls.empty()) { |
| 2974 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2975 | ConflictingDecls.data(), |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2976 | ConflictingDecls.size()); |
| 2977 | if (!Name) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2978 | return make_error<ImportError>(ImportError::NameConflict); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2979 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2980 | } |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2981 | |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 2982 | // We do not allow more than one in-class declaration of a function. This is |
| 2983 | // because AST clients like VTableBuilder asserts on this. VTableBuilder |
| 2984 | // assumes there is only one in-class declaration. Building a redecl |
| 2985 | // chain would result in more than one in-class declaration for |
| 2986 | // overrides (even if they are part of the same redecl chain inside the |
| 2987 | // derived class.) |
| 2988 | if (FoundByLookup) { |
| Mikael Holmen | c1c97aa | 2019-01-29 06:53:31 +0000 | [diff] [blame] | 2989 | if (isa<CXXMethodDecl>(FoundByLookup)) { |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 2990 | if (D->getLexicalDeclContext() == D->getDeclContext()) { |
| 2991 | if (!D->doesThisDeclarationHaveABody()) |
| 2992 | return Importer.MapImported(D, FoundByLookup); |
| 2993 | else { |
| 2994 | // Let's continue and build up the redecl chain in this case. |
| 2995 | // FIXME Merge the functions into one decl. |
| 2996 | } |
| 2997 | } |
| 2998 | } |
| 2999 | } |
| 3000 | |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3001 | DeclarationNameInfo NameInfo(Name, Loc); |
| 3002 | // Import additional name location/type info. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3003 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 3004 | return std::move(Err); |
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3005 | |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3006 | QualType FromTy = D->getType(); |
| 3007 | bool usedDifferentExceptionSpec = false; |
| 3008 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3009 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3010 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 3011 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 3012 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 3013 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 3014 | // with a simplified function type and update it afterwards. |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 3015 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 3016 | FromEPI.ExceptionSpec.SourceTemplate || |
| 3017 | FromEPI.ExceptionSpec.NoexceptExpr) { |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3018 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 3019 | FromTy = Importer.getFromContext().getFunctionType( |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3020 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3021 | usedDifferentExceptionSpec = true; |
| 3022 | } |
| 3023 | } |
| 3024 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3025 | QualType T; |
| 3026 | TypeSourceInfo *TInfo; |
| 3027 | SourceLocation ToInnerLocStart, ToEndLoc; |
| 3028 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3029 | if (auto Imp = importSeq( |
| 3030 | FromTy, D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3031 | D->getQualifierLoc(), D->getEndLoc())) |
| 3032 | std::tie(T, TInfo, ToInnerLocStart, ToQualifierLoc, ToEndLoc) = *Imp; |
| 3033 | else |
| 3034 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3035 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3036 | // Import the function parameters. |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3037 | SmallVector<ParmVarDecl *, 8> Parameters; |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3038 | for (auto P : D->parameters()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3039 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) |
| 3040 | Parameters.push_back(*ToPOrErr); |
| 3041 | else |
| 3042 | return ToPOrErr.takeError(); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3043 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3044 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3045 | // Create the imported function. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3046 | FunctionDecl *ToFunction = nullptr; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3047 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3048 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3049 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3050 | ToInnerLocStart, NameInfo, T, TInfo, |
| 3051 | FromConstructor->isExplicit(), |
| 3052 | D->isInlineSpecified(), D->isImplicit(), D->isConstexpr())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3053 | return ToFunction; |
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3054 | } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { |
| 3055 | |
| 3056 | auto Imp = |
| 3057 | importSeq(const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()), |
| 3058 | FromDtor->getOperatorDeleteThisArg()); |
| 3059 | |
| 3060 | if (!Imp) |
| 3061 | return Imp.takeError(); |
| 3062 | |
| 3063 | FunctionDecl *ToOperatorDelete; |
| 3064 | Expr *ToThisArg; |
| 3065 | std::tie(ToOperatorDelete, ToThisArg) = *Imp; |
| 3066 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3067 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3068 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 3069 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 3070 | D->isImplicit())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3071 | return ToFunction; |
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3072 | |
| 3073 | CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction); |
| 3074 | |
| 3075 | ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3076 | } else if (CXXConversionDecl *FromConversion = |
| 3077 | dyn_cast<CXXConversionDecl>(D)) { |
| 3078 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 3079 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3080 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3081 | FromConversion->isExplicit(), D->isConstexpr(), SourceLocation())) |
| 3082 | return ToFunction; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3083 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3084 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 3085 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3086 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3087 | Method->isInlineSpecified(), D->isConstexpr(), SourceLocation())) |
| 3088 | return ToFunction; |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3089 | } else { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3090 | if (GetImportedOrCreateDecl(ToFunction, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3091 | ToInnerLocStart, NameInfo, T, TInfo, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3092 | D->getStorageClass(), D->isInlineSpecified(), |
| 3093 | D->hasWrittenPrototype(), D->isConstexpr())) |
| 3094 | return ToFunction; |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3095 | } |
| John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3096 | |
| Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3097 | // Connect the redecl chain. |
| 3098 | if (FoundByLookup) { |
| 3099 | auto *Recent = const_cast<FunctionDecl *>( |
| 3100 | FoundByLookup->getMostRecentDecl()); |
| 3101 | ToFunction->setPreviousDecl(Recent); |
| 3102 | } |
| 3103 | |
| 3104 | // Import Ctor initializers. |
| 3105 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
| 3106 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 3107 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); |
| 3108 | // Import first, then allocate memory and copy if there was no error. |
| 3109 | if (Error Err = ImportContainerChecked( |
| 3110 | FromConstructor->inits(), CtorInitializers)) |
| 3111 | return std::move(Err); |
| 3112 | auto **Memory = |
| 3113 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 3114 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
| 3115 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
| 3116 | ToCtor->setCtorInitializers(Memory); |
| 3117 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 3118 | } |
| 3119 | } |
| 3120 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3121 | ToFunction->setQualifierInfo(ToQualifierLoc); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3122 | ToFunction->setAccess(D->getAccess()); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3123 | ToFunction->setLexicalDeclContext(LexicalDC); |
| John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 3124 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 3125 | ToFunction->setTrivial(D->isTrivial()); |
| 3126 | ToFunction->setPure(D->isPure()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3127 | ToFunction->setRangeEnd(ToEndLoc); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3128 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3129 | // Set the parameters. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3130 | for (auto *Param : Parameters) { |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3131 | Param->setOwningFunction(ToFunction); |
| 3132 | ToFunction->addDeclInternal(Param); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3133 | } |
| David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 3134 | ToFunction->setParams(Parameters); |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3135 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3136 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 3137 | // params it refers to. |
| 3138 | if (TInfo) { |
| 3139 | if (auto ProtoLoc = |
| 3140 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 3141 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 3142 | ProtoLoc.setParam(I, Parameters[I]); |
| 3143 | } |
| 3144 | } |
| 3145 | |
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3146 | if (usedDifferentExceptionSpec) { |
| 3147 | // Update FunctionProtoType::ExtProtoInfo. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3148 | if (ExpectedType TyOrErr = import(D->getType())) |
| 3149 | ToFunction->setType(*TyOrErr); |
| 3150 | else |
| 3151 | return TyOrErr.takeError(); |
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 3152 | } |
| 3153 | |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3154 | // Import the describing template function, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3155 | if (FromFT) { |
| 3156 | auto ToFTOrErr = import(FromFT); |
| 3157 | if (!ToFTOrErr) |
| 3158 | return ToFTOrErr.takeError(); |
| 3159 | } |
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3160 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3161 | if (D->doesThisDeclarationHaveABody()) { |
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3162 | Error Err = ImportFunctionDeclBody(D, ToFunction); |
| 3163 | |
| 3164 | if (Err) |
| 3165 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3166 | } |
| 3167 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3168 | // FIXME: Other bits to merge? |
| Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3169 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3170 | // If it is a template, import all related things. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3171 | if (Error Err = ImportTemplateInformation(D, ToFunction)) |
| 3172 | return std::move(Err); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3173 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3174 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); |
| 3175 | |
| 3176 | // TODO Can we generalize this approach to other AST nodes as well? |
| 3177 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3178 | DC->addDeclInternal(ToFunction); |
| 3179 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3180 | LexicalDC->addDeclInternal(ToFunction); |
| Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3181 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3182 | // Friend declaration's lexical context is the befriending class, but the |
| 3183 | // semantic context is the enclosing scope of the befriending class. |
| 3184 | // We want the friend functions to be found in the semantic context by lookup. |
| 3185 | // FIXME should we handle this generically in VisitFriendDecl? |
| 3186 | // In Other cases when LexicalDC != DC we don't want it to be added, |
| 3187 | // e.g out-of-class definitions like void B::f() {} . |
| 3188 | if (LexicalDC != DC && IsFriend) { |
| 3189 | DC->makeDeclVisibleInContext(ToFunction); |
| 3190 | } |
| 3191 | |
| Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3192 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 3193 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 3194 | |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3195 | // Import the rest of the chain. I.e. import all subsequent declarations. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3196 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3197 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); |
| 3198 | if (!ToRedeclOrErr) |
| 3199 | return ToRedeclOrErr.takeError(); |
| 3200 | } |
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3201 | |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3202 | return ToFunction; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3203 | } |
| 3204 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3205 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3206 | return VisitFunctionDecl(D); |
| 3207 | } |
| 3208 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3209 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3210 | return VisitCXXMethodDecl(D); |
| 3211 | } |
| 3212 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3213 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3214 | return VisitCXXMethodDecl(D); |
| 3215 | } |
| 3216 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3217 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3218 | return VisitCXXMethodDecl(D); |
| 3219 | } |
| 3220 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3221 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3222 | // Import the major distinguishing characteristics of a variable. |
| 3223 | DeclContext *DC, *LexicalDC; |
| 3224 | DeclarationName Name; |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3225 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3226 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3227 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3228 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3229 | if (ToD) |
| 3230 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3231 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3232 | // Determine whether we've already imported this field. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3233 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3234 | for (auto *FoundDecl : FoundDecls) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3235 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3236 | // For anonymous fields, match up by index. |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3237 | if (!Name && |
| 3238 | ASTImporter::getFieldIndex(D) != |
| 3239 | ASTImporter::getFieldIndex(FoundField)) |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3240 | continue; |
| 3241 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3242 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3243 | FoundField->getType())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3244 | Importer.MapImported(D, FoundField); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3245 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the |
| 3246 | // initializer of a FieldDecl might not had been instantiated in the |
| 3247 | // "To" context. However, the "From" context might instantiated that, |
| 3248 | // thus we have to merge that. |
| 3249 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
| 3250 | // We don't have yet the initializer set. |
| 3251 | if (FoundField->hasInClassInitializer() && |
| 3252 | !FoundField->getInClassInitializer()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3253 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) |
| 3254 | FoundField->setInClassInitializer(*ToInitializerOrErr); |
| 3255 | else { |
| 3256 | // We can't return error here, |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3257 | // since we already mapped D as imported. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3258 | // FIXME: warning message? |
| 3259 | consumeError(ToInitializerOrErr.takeError()); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3260 | return FoundField; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3261 | } |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3262 | } |
| 3263 | } |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3264 | return FoundField; |
| 3265 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3266 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3267 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3268 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3269 | << Name << D->getType() << FoundField->getType(); |
| 3270 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3271 | << FoundField->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3272 | |
| 3273 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3274 | } |
| 3275 | } |
| 3276 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3277 | QualType ToType; |
| 3278 | TypeSourceInfo *ToTInfo; |
| 3279 | Expr *ToBitWidth; |
| 3280 | SourceLocation ToInnerLocStart; |
| 3281 | Expr *ToInitializer; |
| 3282 | if (auto Imp = importSeq( |
| 3283 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), |
| 3284 | D->getInnerLocStart(), D->getInClassInitializer())) |
| 3285 | std::tie( |
| 3286 | ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp; |
| 3287 | else |
| 3288 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3289 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3290 | FieldDecl *ToField; |
| 3291 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3292 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3293 | ToType, ToTInfo, ToBitWidth, D->isMutable(), |
| 3294 | D->getInClassInitStyle())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3295 | return ToField; |
| 3296 | |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3297 | ToField->setAccess(D->getAccess()); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3298 | ToField->setLexicalDeclContext(LexicalDC); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3299 | if (ToInitializer) |
| 3300 | ToField->setInClassInitializer(ToInitializer); |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3301 | ToField->setImplicit(D->isImplicit()); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3302 | LexicalDC->addDeclInternal(ToField); |
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3303 | return ToField; |
| 3304 | } |
| 3305 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3306 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3307 | // Import the major distinguishing characteristics of a variable. |
| 3308 | DeclContext *DC, *LexicalDC; |
| 3309 | DeclarationName Name; |
| 3310 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3311 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3312 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3313 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3314 | if (ToD) |
| 3315 | return ToD; |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3316 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3317 | // Determine whether we've already imported this field. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3318 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3319 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3320 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3321 | // For anonymous indirect fields, match up by index. |
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3322 | if (!Name && |
| 3323 | ASTImporter::getFieldIndex(D) != |
| 3324 | ASTImporter::getFieldIndex(FoundField)) |
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3325 | continue; |
| 3326 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3327 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3328 | FoundField->getType(), |
| David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 3329 | !Name.isEmpty())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3330 | Importer.MapImported(D, FoundField); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3331 | return FoundField; |
| 3332 | } |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3333 | |
| 3334 | // If there are more anonymous fields to check, continue. |
| 3335 | if (!Name && I < N-1) |
| 3336 | continue; |
| 3337 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3338 | // FIXME: Why is this case not handled with calling HandleNameConflict? |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3339 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3340 | << Name << D->getType() << FoundField->getType(); |
| 3341 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 3342 | << FoundField->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3343 | |
| 3344 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3345 | } |
| 3346 | } |
| 3347 | |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3348 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3349 | auto TypeOrErr = import(D->getType()); |
| 3350 | if (!TypeOrErr) |
| 3351 | return TypeOrErr.takeError(); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3352 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3353 | auto **NamedChain = |
| 3354 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3355 | |
| 3356 | unsigned i = 0; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3357 | for (auto *PI : D->chain()) |
| 3358 | if (Expected<NamedDecl *> ToD = import(PI)) |
| 3359 | NamedChain[i++] = *ToD; |
| 3360 | else |
| 3361 | return ToD.takeError(); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3362 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3363 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 3364 | IndirectFieldDecl *ToIndirectField; |
| 3365 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3366 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3367 | // FIXME here we leak `NamedChain` which is allocated before |
| 3368 | return ToIndirectField; |
| Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3369 | |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3370 | ToIndirectField->setAccess(D->getAccess()); |
| 3371 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3372 | LexicalDC->addDeclInternal(ToIndirectField); |
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3373 | return ToIndirectField; |
| 3374 | } |
| 3375 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3376 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3377 | // Import the major distinguishing characteristics of a declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3378 | DeclContext *DC, *LexicalDC; |
| 3379 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 3380 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3381 | |
| 3382 | // Determine whether we've already imported this decl. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3383 | // FriendDecl is not a NamedDecl so we cannot use lookup. |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3384 | auto *RD = cast<CXXRecordDecl>(DC); |
| 3385 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3386 | |
| 3387 | while (ImportedFriend) { |
| 3388 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3389 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 3390 | /*Complain=*/false)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3391 | return Importer.MapImported(D, ImportedFriend); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3392 | |
| 3393 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 3394 | if (Importer.IsStructurallyEquivalent( |
| 3395 | D->getFriendType()->getType(), |
| 3396 | ImportedFriend->getFriendType()->getType(), true)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3397 | return Importer.MapImported(D, ImportedFriend); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3398 | } |
| 3399 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3400 | } |
| 3401 | |
| 3402 | // Not found. Create it. |
| 3403 | FriendDecl::FriendUnion ToFU; |
| Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3404 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3405 | NamedDecl *ToFriendD; |
| 3406 | if (Error Err = importInto(ToFriendD, FriendD)) |
| 3407 | return std::move(Err); |
| 3408 | |
| 3409 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && |
| Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3410 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3411 | ToFriendD->setObjectOfFriendDecl(false); |
| 3412 | |
| 3413 | ToFU = ToFriendD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3414 | } else { // The friend is a type, not a decl. |
| 3415 | if (auto TSIOrErr = import(D->getFriendType())) |
| 3416 | ToFU = *TSIOrErr; |
| 3417 | else |
| 3418 | return TSIOrErr.takeError(); |
| 3419 | } |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3420 | |
| 3421 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3422 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3423 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 3424 | if (auto ListOrErr = import(FromTPLists[I])) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3425 | ToTPLists[I] = *ListOrErr; |
| 3426 | else |
| 3427 | return ListOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3428 | } |
| 3429 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3430 | auto LocationOrErr = import(D->getLocation()); |
| 3431 | if (!LocationOrErr) |
| 3432 | return LocationOrErr.takeError(); |
| 3433 | auto FriendLocOrErr = import(D->getFriendLoc()); |
| 3434 | if (!FriendLocOrErr) |
| 3435 | return FriendLocOrErr.takeError(); |
| 3436 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3437 | FriendDecl *FrD; |
| 3438 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3439 | *LocationOrErr, ToFU, |
| 3440 | *FriendLocOrErr, ToTPLists)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3441 | return FrD; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3442 | |
| 3443 | FrD->setAccess(D->getAccess()); |
| 3444 | FrD->setLexicalDeclContext(LexicalDC); |
| 3445 | LexicalDC->addDeclInternal(FrD); |
| 3446 | return FrD; |
| 3447 | } |
| 3448 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3449 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3450 | // Import the major distinguishing characteristics of an ivar. |
| 3451 | DeclContext *DC, *LexicalDC; |
| 3452 | DeclarationName Name; |
| 3453 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3454 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3455 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3456 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3457 | if (ToD) |
| 3458 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3459 | |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3460 | // Determine whether we've already imported this ivar |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3461 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3462 | for (auto *FoundDecl : FoundDecls) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3463 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3464 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3465 | FoundIvar->getType())) { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3466 | Importer.MapImported(D, FoundIvar); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3467 | return FoundIvar; |
| 3468 | } |
| 3469 | |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3470 | Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent) |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3471 | << Name << D->getType() << FoundIvar->getType(); |
| 3472 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3473 | << FoundIvar->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3474 | |
| 3475 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3476 | } |
| 3477 | } |
| 3478 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3479 | QualType ToType; |
| 3480 | TypeSourceInfo *ToTypeSourceInfo; |
| 3481 | Expr *ToBitWidth; |
| 3482 | SourceLocation ToInnerLocStart; |
| 3483 | if (auto Imp = importSeq( |
| 3484 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), D->getInnerLocStart())) |
| 3485 | std::tie(ToType, ToTypeSourceInfo, ToBitWidth, ToInnerLocStart) = *Imp; |
| 3486 | else |
| 3487 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3488 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3489 | ObjCIvarDecl *ToIvar; |
| 3490 | if (GetImportedOrCreateDecl( |
| 3491 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3492 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), |
| 3493 | ToType, ToTypeSourceInfo, |
| 3494 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3495 | return ToIvar; |
| 3496 | |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3497 | ToIvar->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3498 | LexicalDC->addDeclInternal(ToIvar); |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3499 | return ToIvar; |
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3500 | } |
| 3501 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3502 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3503 | |
| 3504 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 3505 | auto RedeclIt = Redecls.begin(); |
| 3506 | // Import the first part of the decl chain. I.e. import all previous |
| 3507 | // declarations starting from the canonical decl. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3508 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { |
| 3509 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3510 | if (!RedeclOrErr) |
| 3511 | return RedeclOrErr.takeError(); |
| 3512 | } |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3513 | assert(*RedeclIt == D); |
| 3514 | |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3515 | // Import the major distinguishing characteristics of a variable. |
| 3516 | DeclContext *DC, *LexicalDC; |
| 3517 | DeclarationName Name; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3518 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3519 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3520 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3521 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3522 | if (ToD) |
| 3523 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3524 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3525 | // Try to find a variable in our own ("to") context with the same name and |
| 3526 | // in the same context as the variable we're importing. |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3527 | VarDecl *FoundByLookup = nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3528 | if (D->isFileVarDecl()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3529 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3530 | unsigned IDNS = Decl::IDNS_Ordinary; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3531 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3532 | for (auto *FoundDecl : FoundDecls) { |
| 3533 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3534 | continue; |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3535 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3536 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3537 | if (!hasSameVisibilityContext(FoundVar, D)) |
| 3538 | continue; |
| 3539 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| 3540 | FoundVar->getType())) { |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3541 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3542 | // The VarDecl in the "From" context has a definition, but in the |
| 3543 | // "To" context we already have a definition. |
| 3544 | VarDecl *FoundDef = FoundVar->getDefinition(); |
| 3545 | if (D->isThisDeclarationADefinition() && FoundDef) |
| 3546 | // FIXME Check for ODR error if the two definitions have |
| 3547 | // different initializers? |
| 3548 | return Importer.MapImported(D, FoundDef); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3549 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3550 | // The VarDecl in the "From" context has an initializer, but in the |
| 3551 | // "To" context we already have an initializer. |
| 3552 | const VarDecl *FoundDInit = nullptr; |
| 3553 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) |
| 3554 | // FIXME Diagnose ODR error if the two initializers are different? |
| 3555 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); |
| 3556 | |
| 3557 | FoundByLookup = FoundVar; |
| 3558 | break; |
| 3559 | } |
| 3560 | |
| 3561 | const ArrayType *FoundArray |
| 3562 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3563 | const ArrayType *TArray |
| 3564 | = Importer.getToContext().getAsArrayType(D->getType()); |
| 3565 | if (FoundArray && TArray) { |
| 3566 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3567 | isa<ConstantArrayType>(TArray)) { |
| 3568 | // Import the type. |
| 3569 | if (auto TyOrErr = import(D->getType())) |
| 3570 | FoundVar->setType(*TyOrErr); |
| 3571 | else |
| 3572 | return TyOrErr.takeError(); |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3573 | |
| 3574 | FoundByLookup = FoundVar; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3575 | break; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3576 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3577 | isa<ConstantArrayType>(FoundArray)) { |
| 3578 | FoundByLookup = FoundVar; |
| 3579 | break; |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3580 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3581 | } |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3582 | |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3583 | Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent) |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3584 | << Name << D->getType() << FoundVar->getType(); |
| 3585 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3586 | << FoundVar->getType(); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3587 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3588 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3589 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3590 | } |
| 3591 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3592 | if (!ConflictingDecls.empty()) { |
| 3593 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3594 | ConflictingDecls.data(), |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3595 | ConflictingDecls.size()); |
| 3596 | if (!Name) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3597 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3598 | } |
| 3599 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3600 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3601 | QualType ToType; |
| 3602 | TypeSourceInfo *ToTypeSourceInfo; |
| 3603 | SourceLocation ToInnerLocStart; |
| 3604 | NestedNameSpecifierLoc ToQualifierLoc; |
| 3605 | if (auto Imp = importSeq( |
| 3606 | D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(), |
| 3607 | D->getQualifierLoc())) |
| 3608 | std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp; |
| 3609 | else |
| 3610 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3611 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3612 | // Create the imported variable. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3613 | VarDecl *ToVar; |
| 3614 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3615 | ToInnerLocStart, Loc, |
| 3616 | Name.getAsIdentifierInfo(), |
| 3617 | ToType, ToTypeSourceInfo, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3618 | D->getStorageClass())) |
| 3619 | return ToVar; |
| 3620 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3621 | ToVar->setQualifierInfo(ToQualifierLoc); |
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3622 | ToVar->setAccess(D->getAccess()); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3623 | ToVar->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3624 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3625 | if (FoundByLookup) { |
| 3626 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); |
| 3627 | ToVar->setPreviousDecl(Recent); |
| 3628 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3629 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3630 | if (Error Err = ImportInitializer(D, ToVar)) |
| 3631 | return std::move(Err); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3632 | |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3633 | if (D->isConstexpr()) |
| 3634 | ToVar->setConstexpr(true); |
| 3635 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3636 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 3637 | DC->addDeclInternal(ToVar); |
| 3638 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
| 3639 | LexicalDC->addDeclInternal(ToVar); |
| 3640 | |
| 3641 | // Import the rest of the chain. I.e. import all subsequent declarations. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3642 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { |
| 3643 | ExpectedDecl RedeclOrErr = import(*RedeclIt); |
| 3644 | if (!RedeclOrErr) |
| 3645 | return RedeclOrErr.takeError(); |
| 3646 | } |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3647 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3648 | return ToVar; |
| 3649 | } |
| 3650 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3651 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3652 | // Parameters are created in the translation unit's context, then moved |
| 3653 | // into the function declaration's context afterward. |
| 3654 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3655 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3656 | DeclarationName ToDeclName; |
| 3657 | SourceLocation ToLocation; |
| 3658 | QualType ToType; |
| 3659 | if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType())) |
| 3660 | std::tie(ToDeclName, ToLocation, ToType) = *Imp; |
| 3661 | else |
| 3662 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3663 | |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3664 | // Create the imported parameter. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3665 | ImplicitParamDecl *ToParm = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3666 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3667 | ToLocation, ToDeclName.getAsIdentifierInfo(), |
| 3668 | ToType, D->getParameterKind())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3669 | return ToParm; |
| 3670 | return ToParm; |
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3671 | } |
| 3672 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3673 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3674 | // Parameters are created in the translation unit's context, then moved |
| 3675 | // into the function declaration's context afterward. |
| 3676 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3677 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3678 | DeclarationName ToDeclName; |
| 3679 | SourceLocation ToLocation, ToInnerLocStart; |
| 3680 | QualType ToType; |
| 3681 | TypeSourceInfo *ToTypeSourceInfo; |
| 3682 | if (auto Imp = importSeq( |
| 3683 | D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(), |
| 3684 | D->getTypeSourceInfo())) |
| 3685 | std::tie( |
| 3686 | ToDeclName, ToLocation, ToType, ToInnerLocStart, |
| 3687 | ToTypeSourceInfo) = *Imp; |
| 3688 | else |
| 3689 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3690 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3691 | ParmVarDecl *ToParm; |
| 3692 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3693 | ToInnerLocStart, ToLocation, |
| 3694 | ToDeclName.getAsIdentifierInfo(), ToType, |
| 3695 | ToTypeSourceInfo, D->getStorageClass(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3696 | /*DefaultArg*/ nullptr)) |
| 3697 | return ToParm; |
| Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3698 | |
| 3699 | // Set the default argument. |
| John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 3700 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
| Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3701 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 3702 | |
| Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3703 | if (D->hasUninstantiatedDefaultArg()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3704 | if (auto ToDefArgOrErr = import(D->getUninstantiatedDefaultArg())) |
| 3705 | ToParm->setUninstantiatedDefaultArg(*ToDefArgOrErr); |
| 3706 | else |
| 3707 | return ToDefArgOrErr.takeError(); |
| Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3708 | } else if (D->hasUnparsedDefaultArg()) { |
| 3709 | ToParm->setUnparsedDefaultArg(); |
| 3710 | } else if (D->hasDefaultArg()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3711 | if (auto ToDefArgOrErr = import(D->getDefaultArg())) |
| 3712 | ToParm->setDefaultArg(*ToDefArgOrErr); |
| 3713 | else |
| 3714 | return ToDefArgOrErr.takeError(); |
| Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3715 | } |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3716 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3717 | if (D->isObjCMethodParameter()) { |
| 3718 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3719 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3720 | } else { |
| 3721 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3722 | D->getFunctionScopeIndex()); |
| 3723 | } |
| 3724 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3725 | return ToParm; |
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3726 | } |
| 3727 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3728 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3729 | // Import the major distinguishing characteristics of a method. |
| 3730 | DeclContext *DC, *LexicalDC; |
| 3731 | DeclarationName Name; |
| 3732 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3733 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3734 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3735 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3736 | if (ToD) |
| 3737 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3738 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3739 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3740 | for (auto *FoundDecl : FoundDecls) { |
| 3741 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3742 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3743 | continue; |
| 3744 | |
| 3745 | // Check return types. |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3746 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3747 | FoundMethod->getReturnType())) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3748 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent) |
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3749 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3750 | << FoundMethod->getReturnType(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3751 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3752 | diag::note_odr_objc_method_here) |
| 3753 | << D->isInstanceMethod() << Name; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3754 | |
| 3755 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3756 | } |
| 3757 | |
| 3758 | // Check the number of parameters. |
| 3759 | if (D->param_size() != FoundMethod->param_size()) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3760 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3761 | << D->isInstanceMethod() << Name |
| 3762 | << D->param_size() << FoundMethod->param_size(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3763 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3764 | diag::note_odr_objc_method_here) |
| 3765 | << D->isInstanceMethod() << Name; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3766 | |
| 3767 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3768 | } |
| 3769 | |
| 3770 | // Check parameter types. |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3771 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3772 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3773 | P != PEnd; ++P, ++FoundP) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3774 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3775 | (*FoundP)->getType())) { |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3776 | Importer.FromDiag((*P)->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3777 | diag::warn_odr_objc_method_param_type_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3778 | << D->isInstanceMethod() << Name |
| 3779 | << (*P)->getType() << (*FoundP)->getType(); |
| 3780 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3781 | << (*FoundP)->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3782 | |
| 3783 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3784 | } |
| 3785 | } |
| 3786 | |
| 3787 | // Check variadic/non-variadic. |
| 3788 | // Check the number of parameters. |
| 3789 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3790 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent) |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3791 | << D->isInstanceMethod() << Name; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3792 | Importer.ToDiag(FoundMethod->getLocation(), |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3793 | diag::note_odr_objc_method_here) |
| 3794 | << D->isInstanceMethod() << Name; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3795 | |
| 3796 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3797 | } |
| 3798 | |
| 3799 | // FIXME: Any other bits we need to merge? |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3800 | return Importer.MapImported(D, FoundMethod); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3801 | } |
| 3802 | } |
| 3803 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3804 | SourceLocation ToEndLoc; |
| 3805 | QualType ToReturnType; |
| 3806 | TypeSourceInfo *ToReturnTypeSourceInfo; |
| 3807 | if (auto Imp = importSeq( |
| 3808 | D->getEndLoc(), D->getReturnType(), D->getReturnTypeSourceInfo())) |
| 3809 | std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp; |
| 3810 | else |
| 3811 | return Imp.takeError(); |
| Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3812 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3813 | ObjCMethodDecl *ToMethod; |
| 3814 | if (GetImportedOrCreateDecl( |
| 3815 | ToMethod, D, Importer.getToContext(), Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3816 | ToEndLoc, Name.getObjCSelector(), ToReturnType, |
| 3817 | ToReturnTypeSourceInfo, DC, D->isInstanceMethod(), D->isVariadic(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3818 | D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3819 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 3820 | return ToMethod; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3821 | |
| 3822 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3823 | // deal with implicit parameters. |
| 3824 | |
| 3825 | // Import the parameters |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3826 | SmallVector<ParmVarDecl *, 5> ToParams; |
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3827 | for (auto *FromP : D->parameters()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3828 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) |
| 3829 | ToParams.push_back(*ToPOrErr); |
| 3830 | else |
| 3831 | return ToPOrErr.takeError(); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3832 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3833 | |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3834 | // Set the parameters. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3835 | for (auto *ToParam : ToParams) { |
| 3836 | ToParam->setOwningFunction(ToMethod); |
| 3837 | ToMethod->addDeclInternal(ToParam); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3838 | } |
| Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3839 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3840 | SmallVector<SourceLocation, 12> FromSelLocs; |
| 3841 | D->getSelectorLocs(FromSelLocs); |
| 3842 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); |
| 3843 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) |
| 3844 | return std::move(Err); |
| Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3845 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3846 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3847 | |
| 3848 | ToMethod->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3849 | LexicalDC->addDeclInternal(ToMethod); |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3850 | return ToMethod; |
| 3851 | } |
| 3852 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3853 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3854 | // Import the major distinguishing characteristics of a category. |
| 3855 | DeclContext *DC, *LexicalDC; |
| 3856 | DeclarationName Name; |
| 3857 | SourceLocation Loc; |
| 3858 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3859 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3860 | return std::move(Err); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3861 | if (ToD) |
| 3862 | return ToD; |
| 3863 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3864 | SourceLocation ToVarianceLoc, ToLocation, ToColonLoc; |
| 3865 | TypeSourceInfo *ToTypeSourceInfo; |
| 3866 | if (auto Imp = importSeq( |
| 3867 | D->getVarianceLoc(), D->getLocation(), D->getColonLoc(), |
| 3868 | D->getTypeSourceInfo())) |
| 3869 | std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp; |
| 3870 | else |
| 3871 | return Imp.takeError(); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3872 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3873 | ObjCTypeParamDecl *Result; |
| 3874 | if (GetImportedOrCreateDecl( |
| 3875 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3876 | ToVarianceLoc, D->getIndex(), |
| 3877 | ToLocation, Name.getAsIdentifierInfo(), |
| 3878 | ToColonLoc, ToTypeSourceInfo)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3879 | return Result; |
| 3880 | |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3881 | Result->setLexicalDeclContext(LexicalDC); |
| 3882 | return Result; |
| 3883 | } |
| 3884 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3885 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3886 | // Import the major distinguishing characteristics of a category. |
| 3887 | DeclContext *DC, *LexicalDC; |
| 3888 | DeclarationName Name; |
| 3889 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3890 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3891 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3892 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3893 | if (ToD) |
| 3894 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3895 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3896 | ObjCInterfaceDecl *ToInterface; |
| 3897 | if (Error Err = importInto(ToInterface, D->getClassInterface())) |
| 3898 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3899 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3900 | // Determine if we've already encountered this category. |
| 3901 | ObjCCategoryDecl *MergeWithCategory |
| 3902 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3903 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3904 | if (!ToCategory) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3905 | SourceLocation ToAtStartLoc, ToCategoryNameLoc; |
| 3906 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 3907 | if (auto Imp = importSeq( |
| 3908 | D->getAtStartLoc(), D->getCategoryNameLoc(), |
| 3909 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 3910 | std::tie( |
| 3911 | ToAtStartLoc, ToCategoryNameLoc, |
| 3912 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 3913 | else |
| 3914 | return Imp.takeError(); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3915 | |
| 3916 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3917 | ToAtStartLoc, Loc, |
| 3918 | ToCategoryNameLoc, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3919 | Name.getAsIdentifierInfo(), ToInterface, |
| 3920 | /*TypeParamList=*/nullptr, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3921 | ToIvarLBraceLoc, |
| 3922 | ToIvarRBraceLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3923 | return ToCategory; |
| 3924 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3925 | ToCategory->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3926 | LexicalDC->addDeclInternal(ToCategory); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3927 | // Import the type parameter list after MapImported, to avoid |
| Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3928 | // loops when bringing in their DeclContext. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3929 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) |
| 3930 | ToCategory->setTypeParamList(*PListOrErr); |
| 3931 | else |
| 3932 | return PListOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3933 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3934 | // Import protocols |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3935 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3936 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3937 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 3938 | = D->protocol_loc_begin(); |
| 3939 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 3940 | FromProtoEnd = D->protocol_end(); |
| 3941 | FromProto != FromProtoEnd; |
| 3942 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3943 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 3944 | Protocols.push_back(*ToProtoOrErr); |
| 3945 | else |
| 3946 | return ToProtoOrErr.takeError(); |
| 3947 | |
| 3948 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 3949 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 3950 | else |
| 3951 | return ToProtoLocOrErr.takeError(); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3952 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3953 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3954 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3955 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 3956 | ProtocolLocs.data(), Importer.getToContext()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3957 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3958 | } else { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3959 | Importer.MapImported(D, ToCategory); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3960 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3961 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3962 | // Import all of the members of this category. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3963 | if (Error Err = ImportDeclContext(D)) |
| 3964 | return std::move(Err); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3965 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3966 | // If we have an implementation, import it as well. |
| 3967 | if (D->getImplementation()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3968 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = |
| 3969 | import(D->getImplementation())) |
| 3970 | ToCategory->setImplementation(*ToImplOrErr); |
| 3971 | else |
| 3972 | return ToImplOrErr.takeError(); |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3973 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3974 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3975 | return ToCategory; |
| 3976 | } |
| 3977 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3978 | Error ASTNodeImporter::ImportDefinition( |
| 3979 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3980 | if (To->getDefinition()) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3981 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3982 | if (Error Err = ImportDeclContext(From)) |
| 3983 | return Err; |
| 3984 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3985 | } |
| 3986 | |
| 3987 | // Start the protocol definition |
| 3988 | To->startDefinition(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3989 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3990 | // Import protocols |
| 3991 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3992 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3993 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = |
| 3994 | From->protocol_loc_begin(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3995 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3996 | FromProtoEnd = From->protocol_end(); |
| 3997 | FromProto != FromProtoEnd; |
| 3998 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3999 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4000 | Protocols.push_back(*ToProtoOrErr); |
| 4001 | else |
| 4002 | return ToProtoOrErr.takeError(); |
| 4003 | |
| 4004 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4005 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4006 | else |
| 4007 | return ToProtoLocOrErr.takeError(); |
| 4008 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4009 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4010 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4011 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4012 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4013 | ProtocolLocs.data(), Importer.getToContext()); |
| 4014 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4015 | if (shouldForceImportDeclContext(Kind)) { |
| 4016 | // Import all of the members of this protocol. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4017 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4018 | return Err; |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4019 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4020 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4021 | } |
| 4022 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4023 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4024 | // 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] | 4025 | // from, but this particular declaration is not that definition, import the |
| 4026 | // definition and map to that. |
| 4027 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 4028 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4029 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4030 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4031 | else |
| 4032 | return ImportedDefOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4033 | } |
| 4034 | |
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4035 | // Import the major distinguishing characteristics of a protocol. |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4036 | DeclContext *DC, *LexicalDC; |
| 4037 | DeclarationName Name; |
| 4038 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4039 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4040 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4041 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4042 | if (ToD) |
| 4043 | return ToD; |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4044 | |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4045 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4046 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4047 | for (auto *FoundDecl : FoundDecls) { |
| 4048 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4049 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4050 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4051 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4052 | break; |
| 4053 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4054 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4055 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4056 | if (!ToProto) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4057 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4058 | if (!ToAtBeginLocOrErr) |
| 4059 | return ToAtBeginLocOrErr.takeError(); |
| 4060 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4061 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 4062 | Name.getAsIdentifierInfo(), Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4063 | *ToAtBeginLocOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4064 | /*PrevDecl=*/nullptr)) |
| 4065 | return ToProto; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4066 | ToProto->setLexicalDeclContext(LexicalDC); |
| 4067 | LexicalDC->addDeclInternal(ToProto); |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4068 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4069 | |
| 4070 | Importer.MapImported(D, ToProto); |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4071 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4072 | if (D->isThisDeclarationADefinition()) |
| 4073 | if (Error Err = ImportDefinition(D, ToProto)) |
| 4074 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4075 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4076 | return ToProto; |
| 4077 | } |
| 4078 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4079 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 4080 | DeclContext *DC, *LexicalDC; |
| 4081 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4082 | return std::move(Err); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4083 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4084 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); |
| 4085 | if (!ExternLocOrErr) |
| 4086 | return ExternLocOrErr.takeError(); |
| 4087 | |
| 4088 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); |
| 4089 | if (!LangLocOrErr) |
| 4090 | return LangLocOrErr.takeError(); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4091 | |
| 4092 | bool HasBraces = D->hasBraces(); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4093 | |
| 4094 | LinkageSpecDecl *ToLinkageSpec; |
| 4095 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4096 | *ExternLocOrErr, *LangLocOrErr, |
| 4097 | D->getLanguage(), HasBraces)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4098 | return ToLinkageSpec; |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4099 | |
| 4100 | if (HasBraces) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4101 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); |
| 4102 | if (!RBraceLocOrErr) |
| 4103 | return RBraceLocOrErr.takeError(); |
| 4104 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4105 | } |
| 4106 | |
| 4107 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 4108 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 4109 | |
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4110 | return ToLinkageSpec; |
| 4111 | } |
| 4112 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4113 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4114 | DeclContext *DC, *LexicalDC; |
| 4115 | DeclarationName Name; |
| 4116 | SourceLocation Loc; |
| 4117 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4118 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4119 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4120 | if (ToD) |
| 4121 | return ToD; |
| 4122 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4123 | SourceLocation ToLoc, ToUsingLoc; |
| 4124 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4125 | if (auto Imp = importSeq( |
| 4126 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc())) |
| 4127 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp; |
| 4128 | else |
| 4129 | return Imp.takeError(); |
| 4130 | |
| 4131 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4132 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4133 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4134 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4135 | UsingDecl *ToUsing; |
| 4136 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4137 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4138 | D->hasTypename())) |
| 4139 | return ToUsing; |
| 4140 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4141 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4142 | LexicalDC->addDeclInternal(ToUsing); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4143 | |
| 4144 | if (NamedDecl *FromPattern = |
| 4145 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4146 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) |
| 4147 | Importer.getToContext().setInstantiatedFromUsingDecl( |
| 4148 | ToUsing, *ToPatternOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4149 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4150 | return ToPatternOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4151 | } |
| 4152 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4153 | for (UsingShadowDecl *FromShadow : D->shadows()) { |
| 4154 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) |
| 4155 | ToUsing->addShadowDecl(*ToShadowOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4156 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4157 | // FIXME: We return error here but the definition is already created |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4158 | // and available with lookups. How to fix this?.. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4159 | return ToShadowOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4160 | } |
| 4161 | return ToUsing; |
| 4162 | } |
| 4163 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4164 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4165 | DeclContext *DC, *LexicalDC; |
| 4166 | DeclarationName Name; |
| 4167 | SourceLocation Loc; |
| 4168 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4169 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4170 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4171 | if (ToD) |
| 4172 | return ToD; |
| 4173 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4174 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); |
| 4175 | if (!ToUsingOrErr) |
| 4176 | return ToUsingOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4177 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4178 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); |
| 4179 | if (!ToTargetOrErr) |
| 4180 | return ToTargetOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4181 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4182 | UsingShadowDecl *ToShadow; |
| 4183 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4184 | *ToUsingOrErr, *ToTargetOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4185 | return ToShadow; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4186 | |
| 4187 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 4188 | ToShadow->setAccess(D->getAccess()); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4189 | |
| 4190 | if (UsingShadowDecl *FromPattern = |
| 4191 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4192 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) |
| 4193 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( |
| 4194 | ToShadow, *ToPatternOrErr); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4195 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4196 | // FIXME: We return error here but the definition is already created |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4197 | // and available with lookups. How to fix this?.. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4198 | return ToPatternOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4199 | } |
| 4200 | |
| 4201 | LexicalDC->addDeclInternal(ToShadow); |
| 4202 | |
| 4203 | return ToShadow; |
| 4204 | } |
| 4205 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4206 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4207 | DeclContext *DC, *LexicalDC; |
| 4208 | DeclarationName Name; |
| 4209 | SourceLocation Loc; |
| 4210 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4211 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4212 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4213 | if (ToD) |
| 4214 | return ToD; |
| 4215 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4216 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); |
| 4217 | if (!ToComAncestorOrErr) |
| 4218 | return ToComAncestorOrErr.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4219 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4220 | NamespaceDecl *ToNominatedNamespace; |
| 4221 | SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation; |
| 4222 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4223 | if (auto Imp = importSeq( |
| 4224 | D->getNominatedNamespace(), D->getUsingLoc(), |
| 4225 | D->getNamespaceKeyLocation(), D->getQualifierLoc(), |
| 4226 | D->getIdentLocation())) |
| 4227 | std::tie( |
| 4228 | ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation, |
| 4229 | ToQualifierLoc, ToIdentLocation) = *Imp; |
| 4230 | else |
| 4231 | return Imp.takeError(); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4232 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4233 | UsingDirectiveDecl *ToUsingDir; |
| 4234 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4235 | ToUsingLoc, |
| 4236 | ToNamespaceKeyLocation, |
| 4237 | ToQualifierLoc, |
| 4238 | ToIdentLocation, |
| 4239 | ToNominatedNamespace, *ToComAncestorOrErr)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4240 | return ToUsingDir; |
| 4241 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4242 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 4243 | LexicalDC->addDeclInternal(ToUsingDir); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4244 | |
| 4245 | return ToUsingDir; |
| 4246 | } |
| 4247 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4248 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4249 | UnresolvedUsingValueDecl *D) { |
| 4250 | DeclContext *DC, *LexicalDC; |
| 4251 | DeclarationName Name; |
| 4252 | SourceLocation Loc; |
| 4253 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4254 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4255 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4256 | if (ToD) |
| 4257 | return ToD; |
| 4258 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4259 | SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc; |
| 4260 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4261 | if (auto Imp = importSeq( |
| 4262 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(), |
| 4263 | D->getEllipsisLoc())) |
| 4264 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4265 | else |
| 4266 | return Imp.takeError(); |
| 4267 | |
| 4268 | DeclarationNameInfo NameInfo(Name, ToLoc); |
| 4269 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) |
| 4270 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4271 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4272 | UnresolvedUsingValueDecl *ToUsingValue; |
| 4273 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4274 | ToUsingLoc, ToQualifierLoc, NameInfo, |
| 4275 | ToEllipsisLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4276 | return ToUsingValue; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4277 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4278 | ToUsingValue->setAccess(D->getAccess()); |
| 4279 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 4280 | LexicalDC->addDeclInternal(ToUsingValue); |
| 4281 | |
| 4282 | return ToUsingValue; |
| 4283 | } |
| 4284 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4285 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4286 | UnresolvedUsingTypenameDecl *D) { |
| 4287 | DeclContext *DC, *LexicalDC; |
| 4288 | DeclarationName Name; |
| 4289 | SourceLocation Loc; |
| 4290 | NamedDecl *ToD = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4291 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4292 | return std::move(Err); |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4293 | if (ToD) |
| 4294 | return ToD; |
| 4295 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4296 | SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc; |
| 4297 | NestedNameSpecifierLoc ToQualifierLoc; |
| 4298 | if (auto Imp = importSeq( |
| 4299 | D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(), |
| 4300 | D->getEllipsisLoc())) |
| 4301 | std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; |
| 4302 | else |
| 4303 | return Imp.takeError(); |
| 4304 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4305 | UnresolvedUsingTypenameDecl *ToUsing; |
| 4306 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4307 | ToUsingLoc, ToTypenameLoc, |
| 4308 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4309 | return ToUsing; |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4310 | |
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4311 | ToUsing->setAccess(D->getAccess()); |
| 4312 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 4313 | LexicalDC->addDeclInternal(ToUsing); |
| 4314 | |
| 4315 | return ToUsing; |
| 4316 | } |
| 4317 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4318 | |
| 4319 | Error ASTNodeImporter::ImportDefinition( |
| 4320 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4321 | if (To->getDefinition()) { |
| 4322 | // Check consistency of superclass. |
| 4323 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 4324 | if (FromSuper) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4325 | if (auto FromSuperOrErr = import(FromSuper)) |
| 4326 | FromSuper = *FromSuperOrErr; |
| 4327 | else |
| 4328 | return FromSuperOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4329 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4330 | |
| 4331 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4332 | if ((bool)FromSuper != (bool)ToSuper || |
| 4333 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4334 | Importer.ToDiag(To->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4335 | diag::warn_odr_objc_superclass_inconsistent) |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4336 | << To->getDeclName(); |
| 4337 | if (ToSuper) |
| 4338 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 4339 | << To->getSuperClass()->getDeclName(); |
| 4340 | else |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4341 | Importer.ToDiag(To->getLocation(), |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4342 | diag::note_odr_objc_missing_superclass); |
| 4343 | if (From->getSuperClass()) |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4344 | Importer.FromDiag(From->getSuperClassLoc(), |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4345 | diag::note_odr_objc_superclass) |
| 4346 | << From->getSuperClass()->getDeclName(); |
| 4347 | else |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4348 | Importer.FromDiag(From->getLocation(), |
| 4349 | diag::note_odr_objc_missing_superclass); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4350 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4351 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4352 | if (shouldForceImportDeclContext(Kind)) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4353 | if (Error Err = ImportDeclContext(From)) |
| 4354 | return Err; |
| 4355 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4356 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4357 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4358 | // Start the definition. |
| 4359 | To->startDefinition(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4360 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4361 | // If this class has a superclass, import it. |
| 4362 | if (From->getSuperClass()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4363 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) |
| 4364 | To->setSuperClass(*SuperTInfoOrErr); |
| 4365 | else |
| 4366 | return SuperTInfoOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4367 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4368 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4369 | // Import protocols |
| 4370 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 4371 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4372 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = |
| 4373 | From->protocol_loc_begin(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4374 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4375 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 4376 | FromProtoEnd = From->protocol_end(); |
| 4377 | FromProto != FromProtoEnd; |
| 4378 | ++FromProto, ++FromProtoLoc) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4379 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) |
| 4380 | Protocols.push_back(*ToProtoOrErr); |
| 4381 | else |
| 4382 | return ToProtoOrErr.takeError(); |
| 4383 | |
| 4384 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) |
| 4385 | ProtocolLocs.push_back(*ToProtoLocOrErr); |
| 4386 | else |
| 4387 | return ToProtoLocOrErr.takeError(); |
| 4388 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4389 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4390 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4391 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 4392 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 4393 | ProtocolLocs.data(), Importer.getToContext()); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4394 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4395 | // Import categories. When the categories themselves are imported, they'll |
| 4396 | // hook themselves into this interface. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4397 | for (auto *Cat : From->known_categories()) { |
| 4398 | auto ToCatOrErr = import(Cat); |
| 4399 | if (!ToCatOrErr) |
| 4400 | return ToCatOrErr.takeError(); |
| 4401 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4402 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4403 | // If we have an @implementation, import it as well. |
| 4404 | if (From->getImplementation()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4405 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = |
| 4406 | import(From->getImplementation())) |
| 4407 | To->setImplementation(*ToImplOrErr); |
| 4408 | else |
| 4409 | return ToImplOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4410 | } |
| 4411 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4412 | if (shouldForceImportDeclContext(Kind)) { |
| 4413 | // Import all of the members of this class. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4414 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) |
| 4415 | return Err; |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4416 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4417 | return Error::success(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4418 | } |
| 4419 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4420 | Expected<ObjCTypeParamList *> |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4421 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 4422 | if (!list) |
| 4423 | return nullptr; |
| 4424 | |
| 4425 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4426 | for (auto *fromTypeParam : *list) { |
| 4427 | if (auto toTypeParamOrErr = import(fromTypeParam)) |
| 4428 | toTypeParams.push_back(*toTypeParamOrErr); |
| 4429 | else |
| 4430 | return toTypeParamOrErr.takeError(); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4431 | } |
| 4432 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4433 | auto LAngleLocOrErr = import(list->getLAngleLoc()); |
| 4434 | if (!LAngleLocOrErr) |
| 4435 | return LAngleLocOrErr.takeError(); |
| 4436 | |
| 4437 | auto RAngleLocOrErr = import(list->getRAngleLoc()); |
| 4438 | if (!RAngleLocOrErr) |
| 4439 | return RAngleLocOrErr.takeError(); |
| 4440 | |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4441 | return ObjCTypeParamList::create(Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4442 | *LAngleLocOrErr, |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4443 | toTypeParams, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4444 | *RAngleLocOrErr); |
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4445 | } |
| 4446 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4447 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4448 | // If this class has a definition in the translation unit we're coming from, |
| 4449 | // but this particular declaration is not that definition, import the |
| 4450 | // definition and map to that. |
| 4451 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 4452 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4453 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 4454 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 4455 | else |
| 4456 | return ImportedDefOrErr.takeError(); |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4457 | } |
| 4458 | |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4459 | // Import the major distinguishing characteristics of an @interface. |
| 4460 | DeclContext *DC, *LexicalDC; |
| 4461 | DeclarationName Name; |
| 4462 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4463 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4464 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4465 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4466 | if (ToD) |
| 4467 | return ToD; |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4468 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4469 | // Look for an existing interface with the same name. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4470 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4471 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4472 | for (auto *FoundDecl : FoundDecls) { |
| 4473 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4474 | continue; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4475 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4476 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4477 | break; |
| 4478 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4479 | |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4480 | // Create an interface declaration, if one does not already exist. |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4481 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4482 | if (!ToIface) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4483 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); |
| 4484 | if (!AtBeginLocOrErr) |
| 4485 | return AtBeginLocOrErr.takeError(); |
| 4486 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4487 | if (GetImportedOrCreateDecl( |
| 4488 | ToIface, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4489 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4490 | /*TypeParamList=*/nullptr, |
| 4491 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 4492 | return ToIface; |
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4493 | ToIface->setLexicalDeclContext(LexicalDC); |
| 4494 | LexicalDC->addDeclInternal(ToIface); |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4495 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4496 | Importer.MapImported(D, ToIface); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4497 | // Import the type parameter list after MapImported, to avoid |
| Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4498 | // loops when bringing in their DeclContext. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4499 | if (auto ToPListOrErr = |
| 4500 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) |
| 4501 | ToIface->setTypeParamList(*ToPListOrErr); |
| 4502 | else |
| 4503 | return ToPListOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4504 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4505 | if (D->isThisDeclarationADefinition()) |
| 4506 | if (Error Err = ImportDefinition(D, ToIface)) |
| 4507 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4508 | |
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4509 | return ToIface; |
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4510 | } |
| 4511 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4512 | ExpectedDecl |
| 4513 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
| 4514 | ObjCCategoryDecl *Category; |
| 4515 | if (Error Err = importInto(Category, D->getCategoryDecl())) |
| 4516 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4517 | |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4518 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4519 | if (!ToImpl) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4520 | DeclContext *DC, *LexicalDC; |
| 4521 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4522 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4523 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4524 | SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc; |
| 4525 | if (auto Imp = importSeq( |
| 4526 | D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc())) |
| 4527 | std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp; |
| 4528 | else |
| 4529 | return Imp.takeError(); |
| 4530 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4531 | if (GetImportedOrCreateDecl( |
| 4532 | ToImpl, D, Importer.getToContext(), DC, |
| 4533 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4534 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4535 | return ToImpl; |
| 4536 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4537 | ToImpl->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4538 | LexicalDC->addDeclInternal(ToImpl); |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4539 | Category->setImplementation(ToImpl); |
| 4540 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4541 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4542 | Importer.MapImported(D, ToImpl); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4543 | if (Error Err = ImportDeclContext(D)) |
| 4544 | return std::move(Err); |
| 4545 | |
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4546 | return ToImpl; |
| 4547 | } |
| 4548 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4549 | ExpectedDecl |
| 4550 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4551 | // Find the corresponding interface. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4552 | ObjCInterfaceDecl *Iface; |
| 4553 | if (Error Err = importInto(Iface, D->getClassInterface())) |
| 4554 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4555 | |
| 4556 | // Import the superclass, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4557 | ObjCInterfaceDecl *Super; |
| 4558 | if (Error Err = importInto(Super, D->getSuperClass())) |
| 4559 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4560 | |
| 4561 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4562 | if (!Impl) { |
| 4563 | // We haven't imported an implementation yet. Create a new @implementation |
| 4564 | // now. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4565 | DeclContext *DC, *LexicalDC; |
| 4566 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4567 | return std::move(Err); |
| 4568 | |
| 4569 | SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc; |
| 4570 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; |
| 4571 | if (auto Imp = importSeq( |
| 4572 | D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(), |
| 4573 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) |
| 4574 | std::tie( |
| 4575 | ToLocation, ToAtStartLoc, ToSuperClassLoc, |
| 4576 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; |
| 4577 | else |
| 4578 | return Imp.takeError(); |
| 4579 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4580 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4581 | DC, Iface, Super, |
| 4582 | ToLocation, |
| 4583 | ToAtStartLoc, |
| 4584 | ToSuperClassLoc, |
| 4585 | ToIvarLBraceLoc, |
| 4586 | ToIvarRBraceLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4587 | return Impl; |
| 4588 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4589 | Impl->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4590 | |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4591 | // Associate the implementation with the class it implements. |
| 4592 | Iface->setImplementation(Impl); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4593 | Importer.MapImported(D, Iface->getImplementation()); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4594 | } else { |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4595 | Importer.MapImported(D, Iface->getImplementation()); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4596 | |
| 4597 | // Verify that the existing @implementation has the same superclass. |
| 4598 | if ((Super && !Impl->getSuperClass()) || |
| 4599 | (!Super && Impl->getSuperClass()) || |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4600 | (Super && Impl->getSuperClass() && |
| 4601 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4602 | Impl->getSuperClass()))) { |
| 4603 | Importer.ToDiag(Impl->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4604 | diag::warn_odr_objc_superclass_inconsistent) |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4605 | << Iface->getDeclName(); |
| 4606 | // FIXME: It would be nice to have the location of the superclass |
| 4607 | // below. |
| 4608 | if (Impl->getSuperClass()) |
| 4609 | Importer.ToDiag(Impl->getLocation(), |
| 4610 | diag::note_odr_objc_superclass) |
| 4611 | << Impl->getSuperClass()->getDeclName(); |
| 4612 | else |
| 4613 | Importer.ToDiag(Impl->getLocation(), |
| 4614 | diag::note_odr_objc_missing_superclass); |
| 4615 | if (D->getSuperClass()) |
| 4616 | Importer.FromDiag(D->getLocation(), |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4617 | diag::note_odr_objc_superclass) |
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4618 | << D->getSuperClass()->getDeclName(); |
| 4619 | else |
| 4620 | Importer.FromDiag(D->getLocation(), |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4621 | diag::note_odr_objc_missing_superclass); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4622 | |
| 4623 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4624 | } |
| 4625 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4626 | |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4627 | // Import all of the members of this @implementation. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4628 | if (Error Err = ImportDeclContext(D)) |
| 4629 | return std::move(Err); |
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4630 | |
| 4631 | return Impl; |
| 4632 | } |
| 4633 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4634 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4635 | // Import the major distinguishing characteristics of an @property. |
| 4636 | DeclContext *DC, *LexicalDC; |
| 4637 | DeclarationName Name; |
| 4638 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4639 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4640 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4641 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4642 | if (ToD) |
| 4643 | return ToD; |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4644 | |
| 4645 | // Check whether we have already imported this property. |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4646 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4647 | for (auto *FoundDecl : FoundDecls) { |
| 4648 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4649 | // Check property types. |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4650 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4651 | FoundProp->getType())) { |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4652 | Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent) |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4653 | << Name << D->getType() << FoundProp->getType(); |
| 4654 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4655 | << FoundProp->getType(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4656 | |
| 4657 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4658 | } |
| 4659 | |
| 4660 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4661 | |
| 4662 | // Consider these properties to be equivalent. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4663 | Importer.MapImported(D, FoundProp); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4664 | return FoundProp; |
| 4665 | } |
| 4666 | } |
| 4667 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4668 | QualType ToType; |
| 4669 | TypeSourceInfo *ToTypeSourceInfo; |
| 4670 | SourceLocation ToAtLoc, ToLParenLoc; |
| 4671 | if (auto Imp = importSeq( |
| 4672 | D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc())) |
| 4673 | std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp; |
| 4674 | else |
| 4675 | return Imp.takeError(); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4676 | |
| 4677 | // Create the new property. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4678 | ObjCPropertyDecl *ToProperty; |
| 4679 | if (GetImportedOrCreateDecl( |
| 4680 | ToProperty, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4681 | Name.getAsIdentifierInfo(), ToAtLoc, |
| 4682 | ToLParenLoc, ToType, |
| 4683 | ToTypeSourceInfo, D->getPropertyImplementation())) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4684 | return ToProperty; |
| 4685 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4686 | Selector ToGetterName, ToSetterName; |
| 4687 | SourceLocation ToGetterNameLoc, ToSetterNameLoc; |
| 4688 | ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl; |
| 4689 | ObjCIvarDecl *ToPropertyIvarDecl; |
| 4690 | if (auto Imp = importSeq( |
| 4691 | D->getGetterName(), D->getSetterName(), |
| 4692 | D->getGetterNameLoc(), D->getSetterNameLoc(), |
| 4693 | D->getGetterMethodDecl(), D->getSetterMethodDecl(), |
| 4694 | D->getPropertyIvarDecl())) |
| 4695 | std::tie( |
| 4696 | ToGetterName, ToSetterName, |
| 4697 | ToGetterNameLoc, ToSetterNameLoc, |
| 4698 | ToGetterMethodDecl, ToSetterMethodDecl, |
| 4699 | ToPropertyIvarDecl) = *Imp; |
| 4700 | else |
| 4701 | return Imp.takeError(); |
| 4702 | |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4703 | ToProperty->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4704 | LexicalDC->addDeclInternal(ToProperty); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4705 | |
| 4706 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
| Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4707 | ToProperty->setPropertyAttributesAsWritten( |
| 4708 | D->getPropertyAttributesAsWritten()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4709 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); |
| 4710 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); |
| 4711 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); |
| 4712 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); |
| 4713 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); |
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4714 | return ToProperty; |
| 4715 | } |
| 4716 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4717 | ExpectedDecl |
| 4718 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 4719 | ObjCPropertyDecl *Property; |
| 4720 | if (Error Err = importInto(Property, D->getPropertyDecl())) |
| 4721 | return std::move(Err); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4722 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4723 | DeclContext *DC, *LexicalDC; |
| 4724 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 4725 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4726 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4727 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4728 | |
| 4729 | // Import the ivar (for an @synthesize). |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4730 | ObjCIvarDecl *Ivar = nullptr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4731 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) |
| 4732 | return std::move(Err); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4733 | |
| 4734 | ObjCPropertyImplDecl *ToImpl |
| Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 4735 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 4736 | Property->getQueryKind()); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4737 | if (!ToImpl) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4738 | SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc; |
| 4739 | if (auto Imp = importSeq( |
| 4740 | D->getBeginLoc(), D->getLocation(), D->getPropertyIvarDeclLoc())) |
| 4741 | std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp; |
| 4742 | else |
| 4743 | return Imp.takeError(); |
| 4744 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4745 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4746 | ToBeginLoc, |
| 4747 | ToLocation, Property, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4748 | D->getPropertyImplementation(), Ivar, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4749 | ToPropertyIvarDeclLoc)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4750 | return ToImpl; |
| 4751 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4752 | ToImpl->setLexicalDeclContext(LexicalDC); |
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4753 | LexicalDC->addDeclInternal(ToImpl); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4754 | } else { |
| 4755 | // Check that we have the same kind of property implementation (@synthesize |
| 4756 | // vs. @dynamic). |
| 4757 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4758 | Importer.ToDiag(ToImpl->getLocation(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4759 | diag::warn_odr_objc_property_impl_kind_inconsistent) |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4760 | << Property->getDeclName() |
| 4761 | << (ToImpl->getPropertyImplementation() |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4762 | == ObjCPropertyImplDecl::Dynamic); |
| 4763 | Importer.FromDiag(D->getLocation(), |
| 4764 | diag::note_odr_objc_property_impl_kind) |
| 4765 | << D->getPropertyDecl()->getDeclName() |
| 4766 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4767 | |
| 4768 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4769 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4770 | |
| 4771 | // For @synthesize, check that we have the same |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4772 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 4773 | Ivar != ToImpl->getPropertyIvarDecl()) { |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4774 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4775 | diag::warn_odr_objc_synthesize_ivar_inconsistent) |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4776 | << Property->getDeclName() |
| 4777 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 4778 | << Ivar->getDeclName(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4779 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4780 | diag::note_odr_objc_synthesize_ivar_here) |
| 4781 | << D->getPropertyIvarDecl()->getDeclName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4782 | |
| 4783 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4784 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4785 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4786 | // Merge the existing implementation with the new implementation. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4787 | Importer.MapImported(D, ToImpl); |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4788 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4789 | |
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4790 | return ToImpl; |
| 4791 | } |
| 4792 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4793 | ExpectedDecl |
| 4794 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4795 | // For template arguments, we adopt the translation unit as our declaration |
| 4796 | // context. This context will be fixed when the actual template declaration |
| 4797 | // is created. |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4798 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4799 | // FIXME: Import default argument. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4800 | |
| 4801 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 4802 | if (!BeginLocOrErr) |
| 4803 | return BeginLocOrErr.takeError(); |
| 4804 | |
| 4805 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4806 | if (!LocationOrErr) |
| 4807 | return LocationOrErr.takeError(); |
| 4808 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4809 | TemplateTypeParmDecl *ToD = nullptr; |
| 4810 | (void)GetImportedOrCreateDecl( |
| 4811 | ToD, D, Importer.getToContext(), |
| 4812 | Importer.getToContext().getTranslationUnitDecl(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4813 | *BeginLocOrErr, *LocationOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4814 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| 4815 | D->wasDeclaredWithTypename(), D->isParameterPack()); |
| 4816 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4817 | } |
| 4818 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4819 | ExpectedDecl |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4820 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4821 | DeclarationName ToDeclName; |
| 4822 | SourceLocation ToLocation, ToInnerLocStart; |
| 4823 | QualType ToType; |
| 4824 | TypeSourceInfo *ToTypeSourceInfo; |
| 4825 | if (auto Imp = importSeq( |
| 4826 | D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(), |
| 4827 | D->getInnerLocStart())) |
| 4828 | std::tie( |
| 4829 | ToDeclName, ToLocation, ToType, ToTypeSourceInfo, |
| 4830 | ToInnerLocStart) = *Imp; |
| 4831 | else |
| 4832 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4833 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4834 | // FIXME: Import default argument. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4835 | |
| 4836 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 4837 | (void)GetImportedOrCreateDecl( |
| 4838 | ToD, D, Importer.getToContext(), |
| 4839 | Importer.getToContext().getTranslationUnitDecl(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4840 | ToInnerLocStart, ToLocation, D->getDepth(), |
| 4841 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, |
| 4842 | D->isParameterPack(), ToTypeSourceInfo); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4843 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4844 | } |
| 4845 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4846 | ExpectedDecl |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4847 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 4848 | // Import the name of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4849 | auto NameOrErr = import(D->getDeclName()); |
| 4850 | if (!NameOrErr) |
| 4851 | return NameOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4852 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4853 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4854 | ExpectedSLoc LocationOrErr = import(D->getLocation()); |
| 4855 | if (!LocationOrErr) |
| 4856 | return LocationOrErr.takeError(); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4857 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4858 | // Import template parameters. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 4859 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4860 | if (!TemplateParamsOrErr) |
| 4861 | return TemplateParamsOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4862 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4863 | // FIXME: Import default argument. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4864 | |
| 4865 | TemplateTemplateParmDecl *ToD = nullptr; |
| 4866 | (void)GetImportedOrCreateDecl( |
| 4867 | ToD, D, Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4868 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, |
| 4869 | D->getDepth(), D->getPosition(), D->isParameterPack(), |
| 4870 | (*NameOrErr).getAsIdentifierInfo(), |
| 4871 | *TemplateParamsOrErr); |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4872 | return ToD; |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4873 | } |
| 4874 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4875 | // Returns the definition for a (forward) declaration of a TemplateDecl, if |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4876 | // it has any definition in the redecl chain. |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4877 | template <typename T> static auto getTemplateDefinition(T *D) -> T * { |
| 4878 | assert(D->getTemplatedDecl() && "Should be called on templates only"); |
| 4879 | auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4880 | if (!ToTemplatedDef) |
| 4881 | return nullptr; |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4882 | auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate(); |
| 4883 | return cast_or_null<T>(TemplateWithDef); |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4884 | } |
| 4885 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4886 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4887 | bool IsFriend = D->getFriendObjectKind() != Decl::FOK_None; |
| 4888 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4889 | // Import the major distinguishing characteristics of this class template. |
| 4890 | DeclContext *DC, *LexicalDC; |
| 4891 | DeclarationName Name; |
| 4892 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4893 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4894 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4895 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4896 | if (ToD) |
| 4897 | return ToD; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4898 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4899 | ClassTemplateDecl *FoundByLookup = nullptr; |
| 4900 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4901 | // We may already have a template of the same name; try to find and match it. |
| 4902 | if (!DC->isFunctionOrMethod()) { |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4903 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4904 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4905 | for (auto *FoundDecl : FoundDecls) { |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4906 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary | |
| 4907 | Decl::IDNS_TagFriend)) |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4908 | continue; |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4909 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4910 | Decl *Found = FoundDecl; |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4911 | auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found); |
| 4912 | if (FoundTemplate) { |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4913 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4914 | if (IsStructuralMatch(D, FoundTemplate)) { |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4915 | ClassTemplateDecl *TemplateWithDef = |
| 4916 | getTemplateDefinition(FoundTemplate); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4917 | if (D->isThisDeclarationADefinition() && TemplateWithDef) { |
| 4918 | return Importer.MapImported(D, TemplateWithDef); |
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4919 | } |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4920 | FoundByLookup = FoundTemplate; |
| 4921 | break; |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4922 | } |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4923 | } |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4924 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4925 | ConflictingDecls.push_back(FoundDecl); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4926 | } |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4927 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4928 | if (!ConflictingDecls.empty()) { |
| 4929 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4930 | ConflictingDecls.data(), |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4931 | ConflictingDecls.size()); |
| 4932 | } |
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4933 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4934 | if (!Name) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4935 | return make_error<ImportError>(ImportError::NameConflict); |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4936 | } |
| 4937 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4938 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 4939 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4940 | // Create the declaration that is being templated. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4941 | CXXRecordDecl *ToTemplated; |
| 4942 | if (Error Err = importInto(ToTemplated, FromTemplated)) |
| 4943 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4944 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4945 | // Create the class template declaration itself. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 4946 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4947 | if (!TemplateParamsOrErr) |
| 4948 | return TemplateParamsOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4949 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4950 | ClassTemplateDecl *D2; |
| 4951 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4952 | *TemplateParamsOrErr, ToTemplated)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4953 | return D2; |
| 4954 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4955 | ToTemplated->setDescribedClassTemplate(D2); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4956 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4957 | D2->setAccess(D->getAccess()); |
| 4958 | D2->setLexicalDeclContext(LexicalDC); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4959 | |
| 4960 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 4961 | DC->addDeclInternal(D2); |
| 4962 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 4963 | LexicalDC->addDeclInternal(D2); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4964 | |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4965 | if (FoundByLookup) { |
| 4966 | auto *Recent = |
| 4967 | const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 4968 | |
| 4969 | // It is possible that during the import of the class template definition |
| 4970 | // we start the import of a fwd friend decl of the very same class template |
| 4971 | // and we add the fwd friend decl to the lookup table. But the ToTemplated |
| 4972 | // had been created earlier and by that time the lookup could not find |
| 4973 | // anything existing, so it has no previous decl. Later, (still during the |
| 4974 | // import of the fwd friend decl) we start to import the definition again |
| 4975 | // and this time the lookup finds the previous fwd friend class template. |
| 4976 | // In this case we must set up the previous decl for the templated decl. |
| 4977 | if (!ToTemplated->getPreviousDecl()) { |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 4978 | assert(FoundByLookup->getTemplatedDecl() && |
| 4979 | "Found decl must have its templated decl set"); |
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 4980 | CXXRecordDecl *PrevTemplated = |
| 4981 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 4982 | if (ToTemplated != PrevTemplated) |
| 4983 | ToTemplated->setPreviousDecl(PrevTemplated); |
| 4984 | } |
| 4985 | |
| 4986 | D2->setPreviousDecl(Recent); |
| 4987 | } |
| 4988 | |
| 4989 | if (LexicalDC != DC && IsFriend) |
| 4990 | DC->makeDeclVisibleInContext(D2); |
| 4991 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4992 | if (FromTemplated->isCompleteDefinition() && |
| 4993 | !ToTemplated->isCompleteDefinition()) { |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4994 | // FIXME: Import definition! |
| 4995 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4996 | |
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4997 | return D2; |
| 4998 | } |
| 4999 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5000 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5001 | ClassTemplateSpecializationDecl *D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5002 | ClassTemplateDecl *ClassTemplate; |
| 5003 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) |
| 5004 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5005 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5006 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5007 | DeclContext *DC, *LexicalDC; |
| 5008 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5009 | return std::move(Err); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5010 | |
| 5011 | // Import template arguments. |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5012 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5013 | if (Error Err = ImportTemplateArguments( |
| 5014 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5015 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5016 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5017 | // Try to find an existing specialization with these template arguments. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5018 | void *InsertPos = nullptr; |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5019 | ClassTemplateSpecializationDecl *PrevDecl = nullptr; |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5020 | ClassTemplatePartialSpecializationDecl *PartialSpec = |
| 5021 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); |
| 5022 | if (PartialSpec) |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5023 | PrevDecl = |
| 5024 | ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5025 | else |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5026 | PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5027 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5028 | if (PrevDecl) { |
| 5029 | if (IsStructuralMatch(D, PrevDecl)) { |
| 5030 | if (D->isThisDeclarationADefinition() && PrevDecl->getDefinition()) { |
| 5031 | Importer.MapImported(D, PrevDecl->getDefinition()); |
| 5032 | // Import those default field initializers which have been |
| 5033 | // instantiated in the "From" context, but not in the "To" context. |
| 5034 | for (auto *FromField : D->fields()) |
| 5035 | Importer.Import(FromField); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5036 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5037 | // Import those methods which have been instantiated in the |
| 5038 | // "From" context, but not in the "To" context. |
| 5039 | for (CXXMethodDecl *FromM : D->methods()) |
| 5040 | Importer.Import(FromM); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5041 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5042 | // TODO Import instantiated default arguments. |
| 5043 | // TODO Import instantiated exception specifications. |
| 5044 | // |
| 5045 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint |
| 5046 | // what else could be fused during an AST merge. |
| 5047 | return PrevDecl; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5048 | } |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5049 | } else { // ODR violation. |
| 5050 | // FIXME HandleNameConflict |
| 5051 | return nullptr; |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5052 | } |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5053 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5054 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5055 | // Import the location of this declaration. |
| 5056 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5057 | if (!BeginLocOrErr) |
| 5058 | return BeginLocOrErr.takeError(); |
| 5059 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); |
| 5060 | if (!IdLocOrErr) |
| 5061 | return IdLocOrErr.takeError(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5062 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5063 | // Create the specialization. |
| 5064 | ClassTemplateSpecializationDecl *D2 = nullptr; |
| 5065 | if (PartialSpec) { |
| 5066 | // Import TemplateArgumentListInfo. |
| 5067 | TemplateArgumentListInfo ToTAInfo; |
| 5068 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 5069 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
| 5070 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5071 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5072 | QualType CanonInjType; |
| 5073 | if (Error Err = importInto( |
| 5074 | CanonInjType, PartialSpec->getInjectedSpecializationType())) |
| 5075 | return std::move(Err); |
| 5076 | CanonInjType = CanonInjType.getCanonicalType(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5077 | |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5078 | auto ToTPListOrErr = import(PartialSpec->getTemplateParameters()); |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5079 | if (!ToTPListOrErr) |
| 5080 | return ToTPListOrErr.takeError(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5081 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5082 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
| 5083 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5084 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, ClassTemplate, |
| 5085 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 5086 | ToTAInfo, CanonInjType, |
| 5087 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) |
| 5088 | return D2; |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5089 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5090 | // Update InsertPos, because preceding import calls may have invalidated |
| 5091 | // it by adding new specializations. |
| 5092 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos)) |
| 5093 | // Add this partial specialization to the class template. |
| 5094 | ClassTemplate->AddPartialSpecialization( |
| 5095 | cast<ClassTemplatePartialSpecializationDecl>(D2), InsertPos); |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5096 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5097 | } else { // Not a partial specialization. |
| 5098 | if (GetImportedOrCreateDecl( |
| 5099 | D2, D, Importer.getToContext(), D->getTagKind(), DC, |
| 5100 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, |
| 5101 | PrevDecl)) |
| 5102 | return D2; |
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5103 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5104 | // Update InsertPos, because preceding import calls may have invalidated |
| 5105 | // it by adding new specializations. |
| 5106 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) |
| 5107 | // Add this specialization to the class template. |
| 5108 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 5109 | } |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5110 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5111 | D2->setSpecializationKind(D->getSpecializationKind()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5112 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5113 | // Set the context of this specialization/instantiation. |
| 5114 | D2->setLexicalDeclContext(LexicalDC); |
| 5115 | |
| 5116 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 5117 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 5118 | LexicalDC->addDeclInternal(D2); |
| 5119 | } |
| 5120 | |
| 5121 | // Import the qualifier, if any. |
| 5122 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5123 | D2->setQualifierInfo(*LocOrErr); |
| 5124 | else |
| 5125 | return LocOrErr.takeError(); |
| 5126 | |
| 5127 | if (auto *TSI = D->getTypeAsWritten()) { |
| 5128 | if (auto TInfoOrErr = import(TSI)) |
| 5129 | D2->setTypeAsWritten(*TInfoOrErr); |
| 5130 | else |
| 5131 | return TInfoOrErr.takeError(); |
| 5132 | |
| 5133 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) |
| 5134 | D2->setTemplateKeywordLoc(*LocOrErr); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5135 | else |
| 5136 | return LocOrErr.takeError(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5137 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5138 | if (auto LocOrErr = import(D->getExternLoc())) |
| 5139 | D2->setExternLoc(*LocOrErr); |
| 5140 | else |
| 5141 | return LocOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5142 | } |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5143 | |
| 5144 | if (D->getPointOfInstantiation().isValid()) { |
| 5145 | if (auto POIOrErr = import(D->getPointOfInstantiation())) |
| 5146 | D2->setPointOfInstantiation(*POIOrErr); |
| 5147 | else |
| 5148 | return POIOrErr.takeError(); |
| 5149 | } |
| 5150 | |
| 5151 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 5152 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5153 | if (D->isCompleteDefinition()) |
| 5154 | if (Error Err = ImportDefinition(D, D2)) |
| 5155 | return std::move(Err); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5156 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5157 | return D2; |
| 5158 | } |
| 5159 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5160 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5161 | // If this variable has a definition in the translation unit we're coming |
| 5162 | // from, |
| 5163 | // but this particular declaration is not that definition, import the |
| 5164 | // definition and map to that. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5165 | auto *Definition = |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5166 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 5167 | if (Definition && Definition != D->getTemplatedDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5168 | if (ExpectedDecl ImportedDefOrErr = import( |
| 5169 | Definition->getDescribedVarTemplate())) |
| 5170 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5171 | else |
| 5172 | return ImportedDefOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5173 | } |
| 5174 | |
| 5175 | // Import the major distinguishing characteristics of this variable template. |
| 5176 | DeclContext *DC, *LexicalDC; |
| 5177 | DeclarationName Name; |
| 5178 | SourceLocation Loc; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5179 | NamedDecl *ToD; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5180 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5181 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5182 | if (ToD) |
| 5183 | return ToD; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5184 | |
| 5185 | // We may already have a template of the same name; try to find and match it. |
| 5186 | assert(!DC->isFunctionOrMethod() && |
| 5187 | "Variable templates cannot be declared at function scope"); |
| 5188 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5189 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5190 | for (auto *FoundDecl : FoundDecls) { |
| 5191 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5192 | continue; |
| 5193 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5194 | Decl *Found = FoundDecl; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5195 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5196 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5197 | // The variable templates structurally match; call it the same template. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5198 | Importer.MapImported(D->getTemplatedDecl(), |
| 5199 | FoundTemplate->getTemplatedDecl()); |
| 5200 | return Importer.MapImported(D, FoundTemplate); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5201 | } |
| 5202 | } |
| 5203 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5204 | ConflictingDecls.push_back(FoundDecl); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5205 | } |
| 5206 | |
| 5207 | if (!ConflictingDecls.empty()) { |
| 5208 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 5209 | ConflictingDecls.data(), |
| 5210 | ConflictingDecls.size()); |
| 5211 | } |
| 5212 | |
| 5213 | if (!Name) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5214 | // FIXME: Is it possible to get other error than name conflict? |
| 5215 | // (Put this `if` into the previous `if`?) |
| 5216 | return make_error<ImportError>(ImportError::NameConflict); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5217 | |
| 5218 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 5219 | |
| 5220 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5221 | // FIXME: Value not used? |
| 5222 | ExpectedType TypeOrErr = import(DTemplated->getType()); |
| 5223 | if (!TypeOrErr) |
| 5224 | return TypeOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5225 | |
| 5226 | // Create the declaration that is being templated. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5227 | VarDecl *ToTemplated; |
| 5228 | if (Error Err = importInto(ToTemplated, DTemplated)) |
| 5229 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5230 | |
| 5231 | // Create the variable template declaration itself. |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5232 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5233 | if (!TemplateParamsOrErr) |
| 5234 | return TemplateParamsOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5235 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5236 | VarTemplateDecl *ToVarTD; |
| 5237 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5238 | Name, *TemplateParamsOrErr, ToTemplated)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5239 | return ToVarTD; |
| 5240 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5241 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5242 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5243 | ToVarTD->setAccess(D->getAccess()); |
| 5244 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 5245 | LexicalDC->addDeclInternal(ToVarTD); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5246 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5247 | if (DTemplated->isThisDeclarationADefinition() && |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5248 | !ToTemplated->isThisDeclarationADefinition()) { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5249 | // FIXME: Import definition! |
| 5250 | } |
| 5251 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5252 | return ToVarTD; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5253 | } |
| 5254 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5255 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5256 | VarTemplateSpecializationDecl *D) { |
| 5257 | // If this record has a definition in the translation unit we're coming from, |
| 5258 | // but this particular declaration is not that definition, import the |
| 5259 | // definition and map to that. |
| 5260 | VarDecl *Definition = D->getDefinition(); |
| 5261 | if (Definition && Definition != D) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5262 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) |
| 5263 | return Importer.MapImported(D, *ImportedDefOrErr); |
| 5264 | else |
| 5265 | return ImportedDefOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5266 | } |
| 5267 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5268 | VarTemplateDecl *VarTemplate; |
| 5269 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) |
| 5270 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5271 | |
| 5272 | // Import the context of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5273 | DeclContext *DC, *LexicalDC; |
| 5274 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) |
| 5275 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5276 | |
| 5277 | // Import the location of this declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5278 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); |
| 5279 | if (!BeginLocOrErr) |
| 5280 | return BeginLocOrErr.takeError(); |
| 5281 | |
| 5282 | auto IdLocOrErr = import(D->getLocation()); |
| 5283 | if (!IdLocOrErr) |
| 5284 | return IdLocOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5285 | |
| 5286 | // Import template arguments. |
| 5287 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5288 | if (Error Err = ImportTemplateArguments( |
| 5289 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) |
| 5290 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5291 | |
| 5292 | // Try to find an existing specialization with these template arguments. |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5293 | void *InsertPos = nullptr; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5294 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
| Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 5295 | TemplateArgs, InsertPos); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5296 | if (D2) { |
| 5297 | // We already have a variable template specialization with these template |
| 5298 | // arguments. |
| 5299 | |
| 5300 | // FIXME: Check for specialization vs. instantiation errors. |
| 5301 | |
| 5302 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 5303 | if (!D->isThisDeclarationADefinition() || |
| 5304 | IsStructuralMatch(D, FoundDef)) { |
| 5305 | // The record types structurally match, or the "from" translation |
| 5306 | // unit only had a forward declaration anyway; call it the same |
| 5307 | // variable. |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5308 | return Importer.MapImported(D, FoundDef); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5309 | } |
| 5310 | } |
| 5311 | } else { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5312 | // Import the type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5313 | QualType T; |
| 5314 | if (Error Err = importInto(T, D->getType())) |
| 5315 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5316 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5317 | auto TInfoOrErr = import(D->getTypeSourceInfo()); |
| 5318 | if (!TInfoOrErr) |
| 5319 | return TInfoOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5320 | |
| 5321 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5322 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5323 | D->getTemplateArgsInfo(), ToTAInfo)) |
| 5324 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5325 | |
| 5326 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5327 | // Create a new specialization. |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5328 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 5329 | // Import TemplateArgumentListInfo |
| 5330 | TemplateArgumentListInfo ArgInfos; |
| 5331 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 5332 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5333 | if (Error Err = ImportTemplateArgumentListInfo( |
| 5334 | *FromTAArgsAsWritten, ArgInfos)) |
| 5335 | return std::move(Err); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5336 | |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5337 | auto ToTPListOrErr = import(FromPartial->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5338 | if (!ToTPListOrErr) |
| 5339 | return ToTPListOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5340 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5341 | PartVarSpecDecl *ToPartial; |
| 5342 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5343 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, |
| 5344 | VarTemplate, T, *TInfoOrErr, |
| 5345 | D->getStorageClass(), TemplateArgs, ArgInfos)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5346 | return ToPartial; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5347 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5348 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( |
| 5349 | FromPartial->getInstantiatedFromMember())) |
| 5350 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); |
| 5351 | else |
| 5352 | return ToInstOrErr.takeError(); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5353 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5354 | if (FromPartial->isMemberSpecialization()) |
| 5355 | ToPartial->setMemberSpecialization(); |
| 5356 | |
| 5357 | D2 = ToPartial; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5358 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5359 | } else { // Full specialization |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5360 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, |
| 5361 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, |
| 5362 | T, *TInfoOrErr, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5363 | D->getStorageClass(), TemplateArgs)) |
| 5364 | return D2; |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5365 | } |
| 5366 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5367 | if (D->getPointOfInstantiation().isValid()) { |
| 5368 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) |
| 5369 | D2->setPointOfInstantiation(*POIOrErr); |
| 5370 | else |
| 5371 | return POIOrErr.takeError(); |
| 5372 | } |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5373 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5374 | D2->setSpecializationKind(D->getSpecializationKind()); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5375 | D2->setTemplateArgsInfo(ToTAInfo); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5376 | |
| 5377 | // Add this specialization to the class template. |
| 5378 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 5379 | |
| 5380 | // Import the qualifier, if any. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5381 | if (auto LocOrErr = import(D->getQualifierLoc())) |
| 5382 | D2->setQualifierInfo(*LocOrErr); |
| 5383 | else |
| 5384 | return LocOrErr.takeError(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5385 | |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5386 | if (D->isConstexpr()) |
| 5387 | D2->setConstexpr(true); |
| 5388 | |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5389 | // Add the specialization to this context. |
| 5390 | D2->setLexicalDeclContext(LexicalDC); |
| 5391 | LexicalDC->addDeclInternal(D2); |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5392 | |
| 5393 | D2->setAccess(D->getAccess()); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5394 | } |
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5395 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5396 | if (Error Err = ImportInitializer(D, D2)) |
| 5397 | return std::move(Err); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5398 | |
| 5399 | return D2; |
| 5400 | } |
| 5401 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5402 | ExpectedDecl |
| 5403 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5404 | DeclContext *DC, *LexicalDC; |
| 5405 | DeclarationName Name; |
| 5406 | SourceLocation Loc; |
| 5407 | NamedDecl *ToD; |
| 5408 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5409 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 5410 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5411 | |
| 5412 | if (ToD) |
| 5413 | return ToD; |
| 5414 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5415 | const FunctionTemplateDecl *FoundByLookup = nullptr; |
| 5416 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5417 | // Try to find a function in our own ("to") context with the same name, same |
| 5418 | // type, and in the same context as the function we're importing. |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5419 | // FIXME Split this into a separate function. |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5420 | if (!LexicalDC->isFunctionOrMethod()) { |
| Gabor Marton | e331e63 | 2019-02-18 13:09:27 +0000 | [diff] [blame] | 5421 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5422 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5423 | for (auto *FoundDecl : FoundDecls) { |
| 5424 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5425 | continue; |
| 5426 | |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5427 | if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
| 5428 | if (FoundTemplate->hasExternalFormalLinkage() && |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5429 | D->hasExternalFormalLinkage()) { |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5430 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 5431 | FunctionTemplateDecl *TemplateWithDef = |
| 5432 | getTemplateDefinition(FoundTemplate); |
| 5433 | if (D->isThisDeclarationADefinition() && TemplateWithDef) { |
| 5434 | return Importer.MapImported(D, TemplateWithDef); |
| 5435 | } |
| 5436 | FoundByLookup = FoundTemplate; |
| 5437 | break; |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5438 | } |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5439 | // TODO: handle conflicting names |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5440 | } |
| 5441 | } |
| 5442 | } |
| 5443 | } |
| 5444 | |
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5445 | auto ParamsOrErr = import(D->getTemplateParameters()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5446 | if (!ParamsOrErr) |
| 5447 | return ParamsOrErr.takeError(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5448 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5449 | FunctionDecl *TemplatedFD; |
| 5450 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) |
| 5451 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5452 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5453 | FunctionTemplateDecl *ToFunc; |
| 5454 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5455 | *ParamsOrErr, TemplatedFD)) |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5456 | return ToFunc; |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5457 | |
| 5458 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5459 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5460 | ToFunc->setAccess(D->getAccess()); |
| 5461 | ToFunc->setLexicalDeclContext(LexicalDC); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5462 | LexicalDC->addDeclInternal(ToFunc); |
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5463 | |
| 5464 | if (FoundByLookup) { |
| 5465 | auto *Recent = |
| 5466 | const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl()); |
| 5467 | if (!TemplatedFD->getPreviousDecl()) { |
| 5468 | assert(FoundByLookup->getTemplatedDecl() && |
| 5469 | "Found decl must have its templated decl set"); |
| 5470 | auto *PrevTemplated = |
| 5471 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); |
| 5472 | if (TemplatedFD != PrevTemplated) |
| 5473 | TemplatedFD->setPreviousDecl(PrevTemplated); |
| 5474 | } |
| 5475 | ToFunc->setPreviousDecl(Recent); |
| 5476 | } |
| 5477 | |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5478 | return ToFunc; |
| 5479 | } |
| 5480 | |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5481 | //---------------------------------------------------------------------------- |
| 5482 | // Import Statements |
| 5483 | //---------------------------------------------------------------------------- |
| 5484 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5485 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5486 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) |
| 5487 | << S->getStmtClassName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5488 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5489 | } |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5490 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5491 | |
| 5492 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5493 | SmallVector<IdentifierInfo *, 4> Names; |
| 5494 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 5495 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
| Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5496 | // ToII is nullptr when no symbolic name is given for output operand |
| 5497 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5498 | Names.push_back(ToII); |
| 5499 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5500 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5501 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 5502 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
| Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5503 | // ToII is nullptr when no symbolic name is given for input operand |
| 5504 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5505 | Names.push_back(ToII); |
| 5506 | } |
| 5507 | |
| 5508 | SmallVector<StringLiteral *, 4> Clobbers; |
| 5509 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5510 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) |
| 5511 | Clobbers.push_back(*ClobberOrErr); |
| 5512 | else |
| 5513 | return ClobberOrErr.takeError(); |
| 5514 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5515 | } |
| 5516 | |
| 5517 | SmallVector<StringLiteral *, 4> Constraints; |
| 5518 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5519 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) |
| 5520 | Constraints.push_back(*OutputOrErr); |
| 5521 | else |
| 5522 | return OutputOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5523 | } |
| 5524 | |
| 5525 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5526 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) |
| 5527 | Constraints.push_back(*InputOrErr); |
| 5528 | else |
| 5529 | return InputOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5530 | } |
| 5531 | |
| 5532 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5533 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) |
| 5534 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5535 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5536 | if (Error Err = ImportArrayChecked( |
| 5537 | S->inputs(), Exprs.begin() + S->getNumOutputs())) |
| 5538 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5539 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5540 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); |
| 5541 | if (!AsmLocOrErr) |
| 5542 | return AsmLocOrErr.takeError(); |
| 5543 | auto AsmStrOrErr = import(S->getAsmString()); |
| 5544 | if (!AsmStrOrErr) |
| 5545 | return AsmStrOrErr.takeError(); |
| 5546 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); |
| 5547 | if (!RParenLocOrErr) |
| 5548 | return RParenLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5549 | |
| 5550 | return new (Importer.getToContext()) GCCAsmStmt( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5551 | Importer.getToContext(), |
| 5552 | *AsmLocOrErr, |
| 5553 | S->isSimple(), |
| 5554 | S->isVolatile(), |
| 5555 | S->getNumOutputs(), |
| 5556 | S->getNumInputs(), |
| 5557 | Names.data(), |
| 5558 | Constraints.data(), |
| 5559 | Exprs.data(), |
| 5560 | *AsmStrOrErr, |
| 5561 | S->getNumClobbers(), |
| 5562 | Clobbers.data(), |
| 5563 | *RParenLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5564 | } |
| 5565 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5566 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 5567 | auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc()); |
| 5568 | if (!Imp) |
| 5569 | return Imp.takeError(); |
| 5570 | |
| 5571 | DeclGroupRef ToDG; |
| 5572 | SourceLocation ToBeginLoc, ToEndLoc; |
| 5573 | std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp; |
| 5574 | |
| 5575 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5576 | } |
| 5577 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5578 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5579 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); |
| 5580 | if (!ToSemiLocOrErr) |
| 5581 | return ToSemiLocOrErr.takeError(); |
| 5582 | return new (Importer.getToContext()) NullStmt( |
| 5583 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5584 | } |
| 5585 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5586 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5587 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5588 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5589 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) |
| 5590 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5591 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5592 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); |
| 5593 | if (!ToLBracLocOrErr) |
| 5594 | return ToLBracLocOrErr.takeError(); |
| 5595 | |
| 5596 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); |
| 5597 | if (!ToRBracLocOrErr) |
| 5598 | return ToRBracLocOrErr.takeError(); |
| 5599 | |
| 5600 | return CompoundStmt::Create( |
| 5601 | Importer.getToContext(), ToStmts, |
| 5602 | *ToLBracLocOrErr, *ToRBracLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5603 | } |
| 5604 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5605 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 5606 | auto Imp = importSeq( |
| 5607 | S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(), |
| 5608 | S->getEllipsisLoc(), S->getColonLoc()); |
| 5609 | if (!Imp) |
| 5610 | return Imp.takeError(); |
| 5611 | |
| 5612 | Expr *ToLHS, *ToRHS; |
| 5613 | Stmt *ToSubStmt; |
| 5614 | SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc; |
| 5615 | std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) = |
| 5616 | *Imp; |
| 5617 | |
| Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 5618 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, |
| 5619 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
| Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5620 | ToStmt->setSubStmt(ToSubStmt); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5621 | |
| Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5622 | return ToStmt; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5623 | } |
| 5624 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5625 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 5626 | auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt()); |
| 5627 | if (!Imp) |
| 5628 | return Imp.takeError(); |
| 5629 | |
| 5630 | SourceLocation ToDefaultLoc, ToColonLoc; |
| 5631 | Stmt *ToSubStmt; |
| 5632 | std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp; |
| 5633 | |
| 5634 | return new (Importer.getToContext()) DefaultStmt( |
| 5635 | ToDefaultLoc, ToColonLoc, ToSubStmt); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5636 | } |
| 5637 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5638 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 5639 | auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt()); |
| 5640 | if (!Imp) |
| 5641 | return Imp.takeError(); |
| 5642 | |
| 5643 | SourceLocation ToIdentLoc; |
| 5644 | LabelDecl *ToLabelDecl; |
| 5645 | Stmt *ToSubStmt; |
| 5646 | std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp; |
| 5647 | |
| 5648 | return new (Importer.getToContext()) LabelStmt( |
| 5649 | ToIdentLoc, ToLabelDecl, ToSubStmt); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5650 | } |
| 5651 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5652 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 5653 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); |
| 5654 | if (!ToAttrLocOrErr) |
| 5655 | return ToAttrLocOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5656 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 5657 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5658 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) |
| 5659 | return std::move(Err); |
| 5660 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 5661 | if (!ToSubStmtOrErr) |
| 5662 | return ToSubStmtOrErr.takeError(); |
| 5663 | |
| 5664 | return AttributedStmt::Create( |
| 5665 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5666 | } |
| 5667 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5668 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 5669 | auto Imp = importSeq( |
| 5670 | S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5671 | S->getThen(), S->getElseLoc(), S->getElse()); |
| 5672 | if (!Imp) |
| 5673 | return Imp.takeError(); |
| 5674 | |
| 5675 | SourceLocation ToIfLoc, ToElseLoc; |
| 5676 | Stmt *ToInit, *ToThen, *ToElse; |
| 5677 | VarDecl *ToConditionVariable; |
| 5678 | Expr *ToCond; |
| 5679 | std::tie( |
| 5680 | ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) = |
| 5681 | *Imp; |
| 5682 | |
| Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 5683 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), |
| 5684 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, |
| 5685 | ToElse); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5686 | } |
| 5687 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5688 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
| 5689 | auto Imp = importSeq( |
| 5690 | S->getInit(), S->getConditionVariable(), S->getCond(), |
| 5691 | S->getBody(), S->getSwitchLoc()); |
| 5692 | if (!Imp) |
| 5693 | return Imp.takeError(); |
| 5694 | |
| 5695 | Stmt *ToInit, *ToBody; |
| 5696 | VarDecl *ToConditionVariable; |
| 5697 | Expr *ToCond; |
| 5698 | SourceLocation ToSwitchLoc; |
| 5699 | std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp; |
| 5700 | |
| Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 5701 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, |
| 5702 | ToConditionVariable, ToCond); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5703 | ToStmt->setBody(ToBody); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5704 | ToStmt->setSwitchLoc(ToSwitchLoc); |
| 5705 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5706 | // Now we have to re-chain the cases. |
| 5707 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 5708 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 5709 | SC = SC->getNextSwitchCase()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5710 | Expected<SwitchCase *> ToSCOrErr = import(SC); |
| 5711 | if (!ToSCOrErr) |
| 5712 | return ToSCOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5713 | if (LastChainedSwitchCase) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5714 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5715 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5716 | ToStmt->setSwitchCaseList(*ToSCOrErr); |
| 5717 | LastChainedSwitchCase = *ToSCOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5718 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5719 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5720 | return ToStmt; |
| 5721 | } |
| 5722 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5723 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 5724 | auto Imp = importSeq( |
| 5725 | S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc()); |
| 5726 | if (!Imp) |
| 5727 | return Imp.takeError(); |
| 5728 | |
| 5729 | VarDecl *ToConditionVariable; |
| 5730 | Expr *ToCond; |
| 5731 | Stmt *ToBody; |
| 5732 | SourceLocation ToWhileLoc; |
| 5733 | std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp; |
| 5734 | |
| Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 5735 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, |
| 5736 | ToBody, ToWhileLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5737 | } |
| 5738 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5739 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 5740 | auto Imp = importSeq( |
| 5741 | S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(), |
| 5742 | S->getRParenLoc()); |
| 5743 | if (!Imp) |
| 5744 | return Imp.takeError(); |
| 5745 | |
| 5746 | Stmt *ToBody; |
| 5747 | Expr *ToCond; |
| 5748 | SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc; |
| 5749 | std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp; |
| 5750 | |
| 5751 | return new (Importer.getToContext()) DoStmt( |
| 5752 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5753 | } |
| 5754 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5755 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 5756 | auto Imp = importSeq( |
| 5757 | S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(), |
| 5758 | S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc()); |
| 5759 | if (!Imp) |
| 5760 | return Imp.takeError(); |
| 5761 | |
| 5762 | Stmt *ToInit; |
| 5763 | Expr *ToCond, *ToInc; |
| 5764 | VarDecl *ToConditionVariable; |
| 5765 | Stmt *ToBody; |
| 5766 | SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc; |
| 5767 | std::tie( |
| 5768 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, |
| 5769 | ToLParenLoc, ToRParenLoc) = *Imp; |
| 5770 | |
| 5771 | return new (Importer.getToContext()) ForStmt( |
| 5772 | Importer.getToContext(), |
| 5773 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, |
| 5774 | ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5775 | } |
| 5776 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5777 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 5778 | auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc()); |
| 5779 | if (!Imp) |
| 5780 | return Imp.takeError(); |
| 5781 | |
| 5782 | LabelDecl *ToLabel; |
| 5783 | SourceLocation ToGotoLoc, ToLabelLoc; |
| 5784 | std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp; |
| 5785 | |
| 5786 | return new (Importer.getToContext()) GotoStmt( |
| 5787 | ToLabel, ToGotoLoc, ToLabelLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5788 | } |
| 5789 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5790 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 5791 | auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget()); |
| 5792 | if (!Imp) |
| 5793 | return Imp.takeError(); |
| 5794 | |
| 5795 | SourceLocation ToGotoLoc, ToStarLoc; |
| 5796 | Expr *ToTarget; |
| 5797 | std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp; |
| 5798 | |
| 5799 | return new (Importer.getToContext()) IndirectGotoStmt( |
| 5800 | ToGotoLoc, ToStarLoc, ToTarget); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5801 | } |
| 5802 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5803 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 5804 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); |
| 5805 | if (!ToContinueLocOrErr) |
| 5806 | return ToContinueLocOrErr.takeError(); |
| 5807 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5808 | } |
| 5809 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5810 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 5811 | auto ToBreakLocOrErr = import(S->getBreakLoc()); |
| 5812 | if (!ToBreakLocOrErr) |
| 5813 | return ToBreakLocOrErr.takeError(); |
| 5814 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5815 | } |
| 5816 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5817 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 5818 | auto Imp = importSeq( |
| 5819 | S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate()); |
| 5820 | if (!Imp) |
| 5821 | return Imp.takeError(); |
| 5822 | |
| 5823 | SourceLocation ToReturnLoc; |
| 5824 | Expr *ToRetValue; |
| 5825 | const VarDecl *ToNRVOCandidate; |
| 5826 | std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp; |
| 5827 | |
| Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 5828 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, |
| 5829 | ToNRVOCandidate); |
| 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::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 5833 | auto Imp = importSeq( |
| 5834 | S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock()); |
| 5835 | if (!Imp) |
| 5836 | return Imp.takeError(); |
| 5837 | |
| 5838 | SourceLocation ToCatchLoc; |
| 5839 | VarDecl *ToExceptionDecl; |
| 5840 | Stmt *ToHandlerBlock; |
| 5841 | std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp; |
| 5842 | |
| 5843 | return new (Importer.getToContext()) CXXCatchStmt ( |
| 5844 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5845 | } |
| 5846 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5847 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 5848 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); |
| 5849 | if (!ToTryLocOrErr) |
| 5850 | return ToTryLocOrErr.takeError(); |
| 5851 | |
| 5852 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); |
| 5853 | if (!ToTryBlockOrErr) |
| 5854 | return ToTryBlockOrErr.takeError(); |
| 5855 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5856 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 5857 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 5858 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5859 | if (auto ToHandlerOrErr = import(FromHandler)) |
| 5860 | ToHandlers[HI] = *ToHandlerOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5861 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5862 | return ToHandlerOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5863 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5864 | |
| 5865 | return CXXTryStmt::Create( |
| 5866 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5867 | } |
| 5868 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5869 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
| 5870 | auto Imp1 = importSeq( |
| 5871 | S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(), |
| 5872 | S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody()); |
| 5873 | if (!Imp1) |
| 5874 | return Imp1.takeError(); |
| 5875 | auto Imp2 = importSeq( |
| 5876 | S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc()); |
| 5877 | if (!Imp2) |
| 5878 | return Imp2.takeError(); |
| 5879 | |
| 5880 | DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt; |
| 5881 | Expr *ToCond, *ToInc; |
| 5882 | Stmt *ToInit, *ToBody; |
| 5883 | std::tie( |
| 5884 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5885 | ToBody) = *Imp1; |
| 5886 | SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc; |
| 5887 | std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2; |
| 5888 | |
| 5889 | return new (Importer.getToContext()) CXXForRangeStmt( |
| 5890 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, |
| 5891 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5892 | } |
| 5893 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5894 | ExpectedStmt |
| 5895 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 5896 | auto Imp = importSeq( |
| 5897 | S->getElement(), S->getCollection(), S->getBody(), |
| 5898 | S->getForLoc(), S->getRParenLoc()); |
| 5899 | if (!Imp) |
| 5900 | return Imp.takeError(); |
| 5901 | |
| 5902 | Stmt *ToElement, *ToBody; |
| 5903 | Expr *ToCollection; |
| 5904 | SourceLocation ToForLoc, ToRParenLoc; |
| 5905 | std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp; |
| 5906 | |
| 5907 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, |
| 5908 | ToCollection, |
| 5909 | ToBody, |
| 5910 | ToForLoc, |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5911 | ToRParenLoc); |
| 5912 | } |
| 5913 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5914 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 5915 | auto Imp = importSeq( |
| 5916 | S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(), |
| 5917 | S->getCatchBody()); |
| 5918 | if (!Imp) |
| 5919 | return Imp.takeError(); |
| 5920 | |
| 5921 | SourceLocation ToAtCatchLoc, ToRParenLoc; |
| 5922 | VarDecl *ToCatchParamDecl; |
| 5923 | Stmt *ToCatchBody; |
| 5924 | std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp; |
| 5925 | |
| 5926 | return new (Importer.getToContext()) ObjCAtCatchStmt ( |
| 5927 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5928 | } |
| 5929 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5930 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 5931 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); |
| 5932 | if (!ToAtFinallyLocOrErr) |
| 5933 | return ToAtFinallyLocOrErr.takeError(); |
| 5934 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); |
| 5935 | if (!ToAtFinallyStmtOrErr) |
| 5936 | return ToAtFinallyStmtOrErr.takeError(); |
| 5937 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, |
| 5938 | *ToAtFinallyStmtOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5939 | } |
| 5940 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5941 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 5942 | auto Imp = importSeq( |
| 5943 | S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt()); |
| 5944 | if (!Imp) |
| 5945 | return Imp.takeError(); |
| 5946 | |
| 5947 | SourceLocation ToAtTryLoc; |
| 5948 | Stmt *ToTryBody, *ToFinallyStmt; |
| 5949 | std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp; |
| 5950 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5951 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 5952 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 5953 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5954 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) |
| 5955 | ToCatchStmts[CI] = *ToCatchStmtOrErr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5956 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5957 | return ToCatchStmtOrErr.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5958 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5959 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5960 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5961 | ToAtTryLoc, ToTryBody, |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5962 | ToCatchStmts.begin(), ToCatchStmts.size(), |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5963 | ToFinallyStmt); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5964 | } |
| 5965 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5966 | ExpectedStmt ASTNodeImporter::VisitObjCAtSynchronizedStmt |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5967 | (ObjCAtSynchronizedStmt *S) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5968 | auto Imp = importSeq( |
| 5969 | S->getAtSynchronizedLoc(), S->getSynchExpr(), S->getSynchBody()); |
| 5970 | if (!Imp) |
| 5971 | return Imp.takeError(); |
| 5972 | |
| 5973 | SourceLocation ToAtSynchronizedLoc; |
| 5974 | Expr *ToSynchExpr; |
| 5975 | Stmt *ToSynchBody; |
| 5976 | std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp; |
| 5977 | |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5978 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 5979 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 5980 | } |
| 5981 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5982 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 5983 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); |
| 5984 | if (!ToThrowLocOrErr) |
| 5985 | return ToThrowLocOrErr.takeError(); |
| 5986 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); |
| 5987 | if (!ToThrowExprOrErr) |
| 5988 | return ToThrowExprOrErr.takeError(); |
| 5989 | return new (Importer.getToContext()) ObjCAtThrowStmt( |
| 5990 | *ToThrowLocOrErr, *ToThrowExprOrErr); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5991 | } |
| 5992 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5993 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( |
| 5994 | ObjCAutoreleasePoolStmt *S) { |
| 5995 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); |
| 5996 | if (!ToAtLocOrErr) |
| 5997 | return ToAtLocOrErr.takeError(); |
| 5998 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); |
| 5999 | if (!ToSubStmtOrErr) |
| 6000 | return ToSubStmtOrErr.takeError(); |
| 6001 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, |
| 6002 | *ToSubStmtOrErr); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6003 | } |
| 6004 | |
| 6005 | //---------------------------------------------------------------------------- |
| 6006 | // Import Expressions |
| 6007 | //---------------------------------------------------------------------------- |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6008 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6009 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) |
| 6010 | << E->getStmtClassName(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6011 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6012 | } |
| 6013 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6014 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 6015 | auto Imp = importSeq( |
| 6016 | E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(), |
| 6017 | E->getRParenLoc(), E->getType()); |
| 6018 | if (!Imp) |
| 6019 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6020 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6021 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6022 | Expr *ToSubExpr; |
| 6023 | TypeSourceInfo *ToWrittenTypeInfo; |
| 6024 | QualType ToType; |
| 6025 | std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) = |
| 6026 | *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6027 | |
| 6028 | return new (Importer.getToContext()) VAArgExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6029 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, |
| 6030 | E->isMicrosoftABI()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6031 | } |
| 6032 | |
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6033 | ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) { |
| 6034 | auto Imp = importSeq(E->getCond(), E->getLHS(), E->getRHS(), |
| 6035 | E->getBuiltinLoc(), E->getRParenLoc(), E->getType()); |
| 6036 | if (!Imp) |
| 6037 | return Imp.takeError(); |
| 6038 | |
| 6039 | Expr *ToCond; |
| 6040 | Expr *ToLHS; |
| 6041 | Expr *ToRHS; |
| 6042 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6043 | QualType ToType; |
| 6044 | std::tie(ToCond, ToLHS, ToRHS, ToBuiltinLoc, ToRParenLoc, ToType) = *Imp; |
| 6045 | |
| 6046 | ExprValueKind VK = E->getValueKind(); |
| 6047 | ExprObjectKind OK = E->getObjectKind(); |
| 6048 | |
| 6049 | bool TypeDependent = ToCond->isTypeDependent(); |
| 6050 | bool ValueDependent = ToCond->isValueDependent(); |
| 6051 | |
| 6052 | // The value of CondIsTrue only matters if the value is not |
| 6053 | // condition-dependent. |
| 6054 | bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue(); |
| 6055 | |
| 6056 | return new (Importer.getToContext()) |
| 6057 | ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK, |
| 6058 | ToRParenLoc, CondIsTrue, TypeDependent, ValueDependent); |
| 6059 | } |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6060 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6061 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 6062 | ExpectedType TypeOrErr = import(E->getType()); |
| 6063 | if (!TypeOrErr) |
| 6064 | return TypeOrErr.takeError(); |
| 6065 | |
| 6066 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); |
| 6067 | if (!BeginLocOrErr) |
| 6068 | return BeginLocOrErr.takeError(); |
| 6069 | |
| 6070 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6071 | } |
| 6072 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6073 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 6074 | auto Imp = importSeq( |
| 6075 | E->getBeginLoc(), E->getType(), E->getFunctionName()); |
| 6076 | if (!Imp) |
| 6077 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6078 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6079 | SourceLocation ToBeginLoc; |
| 6080 | QualType ToType; |
| 6081 | StringLiteral *ToFunctionName; |
| 6082 | std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6083 | |
| Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 6084 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, |
| 6085 | E->getIdentKind(), ToFunctionName); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6086 | } |
| 6087 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6088 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
| 6089 | auto Imp = importSeq( |
| 6090 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDecl(), |
| 6091 | E->getLocation(), E->getType()); |
| 6092 | if (!Imp) |
| 6093 | return Imp.takeError(); |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6094 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6095 | NestedNameSpecifierLoc ToQualifierLoc; |
| 6096 | SourceLocation ToTemplateKeywordLoc, ToLocation; |
| 6097 | ValueDecl *ToDecl; |
| 6098 | QualType ToType; |
| 6099 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) = |
| 6100 | *Imp; |
| 6101 | |
| 6102 | NamedDecl *ToFoundD = nullptr; |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6103 | if (E->getDecl() != E->getFoundDecl()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6104 | auto FoundDOrErr = import(E->getFoundDecl()); |
| 6105 | if (!FoundDOrErr) |
| 6106 | return FoundDOrErr.takeError(); |
| 6107 | ToFoundD = *FoundDOrErr; |
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6108 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6109 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6110 | TemplateArgumentListInfo ToTAInfo; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6111 | TemplateArgumentListInfo *ToResInfo = nullptr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6112 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6113 | if (Error Err = |
| 6114 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6115 | return std::move(Err); |
| 6116 | ToResInfo = &ToTAInfo; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6117 | } |
| 6118 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6119 | auto *ToE = DeclRefExpr::Create( |
| 6120 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, |
| 6121 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, |
| 6122 | E->getValueKind(), ToFoundD, ToResInfo); |
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 6123 | if (E->hadMultipleCandidates()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6124 | ToE->setHadMultipleCandidates(true); |
| 6125 | return ToE; |
| Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 6126 | } |
| 6127 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6128 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 6129 | ExpectedType TypeOrErr = import(E->getType()); |
| 6130 | if (!TypeOrErr) |
| 6131 | return TypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6132 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6133 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6134 | } |
| 6135 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6136 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { |
| 6137 | ExpectedExpr ToInitOrErr = import(E->getInit()); |
| 6138 | if (!ToInitOrErr) |
| 6139 | return ToInitOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6140 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6141 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); |
| 6142 | if (!ToEqualOrColonLocOrErr) |
| 6143 | return ToEqualOrColonLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6144 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6145 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6146 | // List elements from the second, the first is Init itself |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6147 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { |
| 6148 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) |
| 6149 | ToIndexExprs[I - 1] = *ToArgOrErr; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6150 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6151 | return ToArgOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6152 | } |
| 6153 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6154 | SmallVector<Designator, 4> ToDesignators(E->size()); |
| 6155 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) |
| 6156 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6157 | |
| 6158 | return DesignatedInitExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6159 | Importer.getToContext(), ToDesignators, |
| 6160 | ToIndexExprs, *ToEqualOrColonLocOrErr, |
| 6161 | E->usesGNUSyntax(), *ToInitOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6162 | } |
| 6163 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6164 | ExpectedStmt |
| 6165 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 6166 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6167 | if (!ToTypeOrErr) |
| 6168 | return ToTypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6169 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6170 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6171 | if (!ToLocationOrErr) |
| 6172 | return ToLocationOrErr.takeError(); |
| 6173 | |
| 6174 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( |
| 6175 | *ToTypeOrErr, *ToLocationOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6176 | } |
| 6177 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6178 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 6179 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6180 | if (!ToTypeOrErr) |
| 6181 | return ToTypeOrErr.takeError(); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6182 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6183 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6184 | if (!ToLocationOrErr) |
| 6185 | return ToLocationOrErr.takeError(); |
| 6186 | |
| 6187 | return IntegerLiteral::Create( |
| 6188 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6189 | } |
| 6190 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6191 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6192 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 6193 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6194 | if (!ToTypeOrErr) |
| 6195 | return ToTypeOrErr.takeError(); |
| 6196 | |
| 6197 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6198 | if (!ToLocationOrErr) |
| 6199 | return ToLocationOrErr.takeError(); |
| 6200 | |
| 6201 | return FloatingLiteral::Create( |
| 6202 | Importer.getToContext(), E->getValue(), E->isExact(), |
| 6203 | *ToTypeOrErr, *ToLocationOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6204 | } |
| 6205 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6206 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { |
| 6207 | auto ToTypeOrErr = import(E->getType()); |
| 6208 | if (!ToTypeOrErr) |
| 6209 | return ToTypeOrErr.takeError(); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6210 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6211 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6212 | if (!ToSubExprOrErr) |
| 6213 | return ToSubExprOrErr.takeError(); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6214 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6215 | return new (Importer.getToContext()) ImaginaryLiteral( |
| 6216 | *ToSubExprOrErr, *ToTypeOrErr); |
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6217 | } |
| 6218 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6219 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 6220 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6221 | if (!ToTypeOrErr) |
| 6222 | return ToTypeOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6223 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6224 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6225 | if (!ToLocationOrErr) |
| 6226 | return ToLocationOrErr.takeError(); |
| 6227 | |
| 6228 | return new (Importer.getToContext()) CharacterLiteral( |
| 6229 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); |
| Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 6230 | } |
| 6231 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6232 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 6233 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6234 | if (!ToTypeOrErr) |
| 6235 | return ToTypeOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6236 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6237 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); |
| 6238 | if (Error Err = ImportArrayChecked( |
| 6239 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) |
| 6240 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6241 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6242 | return StringLiteral::Create( |
| 6243 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), |
| 6244 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); |
| 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 | ExpectedStmt ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 6248 | auto Imp = importSeq( |
| 6249 | E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(), |
| 6250 | E->getInitializer()); |
| 6251 | if (!Imp) |
| 6252 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6253 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6254 | SourceLocation ToLParenLoc; |
| 6255 | TypeSourceInfo *ToTypeSourceInfo; |
| 6256 | QualType ToType; |
| 6257 | Expr *ToInitializer; |
| 6258 | std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6259 | |
| 6260 | return new (Importer.getToContext()) CompoundLiteralExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6261 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), |
| 6262 | ToInitializer, E->isFileScope()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6263 | } |
| 6264 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6265 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 6266 | auto Imp = importSeq( |
| 6267 | E->getBuiltinLoc(), E->getType(), E->getRParenLoc()); |
| 6268 | if (!Imp) |
| 6269 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6270 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6271 | SourceLocation ToBuiltinLoc, ToRParenLoc; |
| 6272 | QualType ToType; |
| 6273 | std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp; |
| 6274 | |
| 6275 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); |
| 6276 | if (Error Err = ImportArrayChecked( |
| 6277 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 6278 | ToExprs.begin())) |
| 6279 | return std::move(Err); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6280 | |
| 6281 | return new (Importer.getToContext()) AtomicExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6282 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6283 | } |
| 6284 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6285 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 6286 | auto Imp = importSeq( |
| 6287 | E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType()); |
| 6288 | if (!Imp) |
| 6289 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6290 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6291 | SourceLocation ToAmpAmpLoc, ToLabelLoc; |
| 6292 | LabelDecl *ToLabel; |
| 6293 | QualType ToType; |
| 6294 | std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6295 | |
| 6296 | return new (Importer.getToContext()) AddrLabelExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6297 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6298 | } |
| 6299 | |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6300 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { |
| 6301 | auto Imp = importSeq(E->getSubExpr()); |
| 6302 | if (!Imp) |
| 6303 | return Imp.takeError(); |
| 6304 | |
| 6305 | Expr *ToSubExpr; |
| 6306 | std::tie(ToSubExpr) = *Imp; |
| 6307 | |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 6308 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr); |
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6309 | } |
| 6310 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6311 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 6312 | auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr()); |
| 6313 | if (!Imp) |
| 6314 | return Imp.takeError(); |
| 6315 | |
| 6316 | SourceLocation ToLParen, ToRParen; |
| 6317 | Expr *ToSubExpr; |
| 6318 | std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6319 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6320 | return new (Importer.getToContext()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6321 | ParenExpr(ToLParen, ToRParen, ToSubExpr); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6322 | } |
| 6323 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6324 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 6325 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); |
| 6326 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) |
| 6327 | return std::move(Err); |
| 6328 | |
| 6329 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); |
| 6330 | if (!ToLParenLocOrErr) |
| 6331 | return ToLParenLocOrErr.takeError(); |
| 6332 | |
| 6333 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); |
| 6334 | if (!ToRParenLocOrErr) |
| 6335 | return ToRParenLocOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6336 | |
| Bruno Ricci | f49e1ca | 2018-11-20 16:20:40 +0000 | [diff] [blame] | 6337 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, |
| 6338 | ToExprs, *ToRParenLocOrErr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6339 | } |
| 6340 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6341 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 6342 | auto Imp = importSeq( |
| 6343 | E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc()); |
| 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 | CompoundStmt *ToSubStmt; |
| 6348 | QualType ToType; |
| 6349 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 6350 | std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6351 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6352 | return new (Importer.getToContext()) StmtExpr( |
| 6353 | ToSubStmt, ToType, ToLParenLoc, ToRParenLoc); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6354 | } |
| 6355 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6356 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 6357 | auto Imp = importSeq( |
| 6358 | E->getSubExpr(), E->getType(), E->getOperatorLoc()); |
| 6359 | if (!Imp) |
| 6360 | return Imp.takeError(); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6361 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6362 | Expr *ToSubExpr; |
| 6363 | QualType ToType; |
| 6364 | SourceLocation ToOperatorLoc; |
| 6365 | std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6366 | |
| Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6367 | return new (Importer.getToContext()) UnaryOperator( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6368 | ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), |
| 6369 | ToOperatorLoc, E->canOverflow()); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6370 | } |
| 6371 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6372 | ExpectedStmt |
| Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6373 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6374 | auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc()); |
| 6375 | if (!Imp) |
| 6376 | return Imp.takeError(); |
| 6377 | |
| 6378 | QualType ToType; |
| 6379 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6380 | std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6381 | |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6382 | if (E->isArgumentType()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6383 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = |
| 6384 | import(E->getArgumentTypeInfo()); |
| 6385 | if (!ToArgumentTypeInfoOrErr) |
| 6386 | return ToArgumentTypeInfoOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6387 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6388 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6389 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, |
| 6390 | ToRParenLoc); |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6391 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6392 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6393 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); |
| 6394 | if (!ToArgumentExprOrErr) |
| 6395 | return ToArgumentExprOrErr.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6396 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6397 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( |
| 6398 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); |
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6399 | } |
| 6400 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6401 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 6402 | auto Imp = importSeq( |
| 6403 | E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc()); |
| 6404 | if (!Imp) |
| 6405 | return Imp.takeError(); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6406 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6407 | Expr *ToLHS, *ToRHS; |
| 6408 | QualType ToType; |
| 6409 | SourceLocation ToOperatorLoc; |
| 6410 | std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6411 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6412 | return new (Importer.getToContext()) BinaryOperator( |
| 6413 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6414 | E->getObjectKind(), ToOperatorLoc, E->getFPFeatures()); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6415 | } |
| 6416 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6417 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 6418 | auto Imp = importSeq( |
| 6419 | E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(), |
| 6420 | E->getRHS(), E->getType()); |
| 6421 | if (!Imp) |
| 6422 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6423 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6424 | Expr *ToCond, *ToLHS, *ToRHS; |
| 6425 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6426 | QualType ToType; |
| 6427 | std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6428 | |
| 6429 | return new (Importer.getToContext()) ConditionalOperator( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6430 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, |
| 6431 | E->getValueKind(), E->getObjectKind()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6432 | } |
| 6433 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6434 | ExpectedStmt ASTNodeImporter::VisitBinaryConditionalOperator( |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6435 | BinaryConditionalOperator *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6436 | auto Imp = importSeq( |
| 6437 | E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(), |
| 6438 | E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType()); |
| 6439 | if (!Imp) |
| 6440 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6441 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6442 | Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr; |
| 6443 | OpaqueValueExpr *ToOpaqueValue; |
| 6444 | SourceLocation ToQuestionLoc, ToColonLoc; |
| 6445 | QualType ToType; |
| 6446 | std::tie( |
| 6447 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc, |
| 6448 | ToColonLoc, ToType) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6449 | |
| 6450 | return new (Importer.getToContext()) BinaryConditionalOperator( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6451 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, |
| 6452 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), |
| 6453 | E->getObjectKind()); |
| 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::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 6457 | auto Imp = importSeq( |
| 6458 | E->getBeginLoc(), E->getQueriedTypeSourceInfo(), |
| 6459 | E->getDimensionExpression(), E->getEndLoc(), E->getType()); |
| 6460 | if (!Imp) |
| 6461 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6462 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6463 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6464 | TypeSourceInfo *ToQueriedTypeSourceInfo; |
| 6465 | Expr *ToDimensionExpression; |
| 6466 | QualType ToType; |
| 6467 | std::tie( |
| 6468 | ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc, |
| 6469 | ToType) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6470 | |
| 6471 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6472 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), |
| 6473 | ToDimensionExpression, ToEndLoc, ToType); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6474 | } |
| 6475 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6476 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 6477 | auto Imp = importSeq( |
| 6478 | E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType()); |
| 6479 | if (!Imp) |
| 6480 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6481 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6482 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6483 | Expr *ToQueriedExpression; |
| 6484 | QualType ToType; |
| 6485 | std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6486 | |
| 6487 | return new (Importer.getToContext()) ExpressionTraitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6488 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), |
| 6489 | ToEndLoc, ToType); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6490 | } |
| 6491 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6492 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 6493 | auto Imp = importSeq( |
| 6494 | E->getLocation(), E->getType(), E->getSourceExpr()); |
| 6495 | if (!Imp) |
| 6496 | return Imp.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6497 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6498 | SourceLocation ToLocation; |
| 6499 | QualType ToType; |
| 6500 | Expr *ToSourceExpr; |
| 6501 | std::tie(ToLocation, ToType, ToSourceExpr) = *Imp; |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6502 | |
| 6503 | return new (Importer.getToContext()) OpaqueValueExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6504 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6505 | } |
| 6506 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6507 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 6508 | auto Imp = importSeq( |
| 6509 | E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc()); |
| 6510 | if (!Imp) |
| 6511 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6512 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6513 | Expr *ToLHS, *ToRHS; |
| 6514 | SourceLocation ToRBracketLoc; |
| 6515 | QualType ToType; |
| 6516 | std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6517 | |
| 6518 | return new (Importer.getToContext()) ArraySubscriptExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6519 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), |
| 6520 | ToRBracketLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6521 | } |
| 6522 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6523 | ExpectedStmt |
| 6524 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 6525 | auto Imp = importSeq( |
| 6526 | E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(), |
| 6527 | E->getComputationResultType(), E->getOperatorLoc()); |
| 6528 | if (!Imp) |
| 6529 | return Imp.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6530 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6531 | Expr *ToLHS, *ToRHS; |
| 6532 | QualType ToType, ToComputationLHSType, ToComputationResultType; |
| 6533 | SourceLocation ToOperatorLoc; |
| 6534 | std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType, |
| 6535 | ToOperatorLoc) = *Imp; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6536 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6537 | return new (Importer.getToContext()) CompoundAssignOperator( |
| 6538 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), |
| 6539 | E->getObjectKind(), ToComputationLHSType, ToComputationResultType, |
| 6540 | ToOperatorLoc, E->getFPFeatures()); |
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6541 | } |
| 6542 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6543 | Expected<CXXCastPath> |
| 6544 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { |
| 6545 | CXXCastPath Path; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6546 | 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] | 6547 | if (auto SpecOrErr = import(*I)) |
| 6548 | Path.push_back(*SpecOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6549 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6550 | return SpecOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6551 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6552 | return Path; |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6553 | } |
| 6554 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6555 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 6556 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6557 | if (!ToTypeOrErr) |
| 6558 | return ToTypeOrErr.takeError(); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6559 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6560 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6561 | if (!ToSubExprOrErr) |
| 6562 | return ToSubExprOrErr.takeError(); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6563 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6564 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6565 | if (!ToBasePathOrErr) |
| 6566 | return ToBasePathOrErr.takeError(); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6567 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6568 | return ImplicitCastExpr::Create( |
| 6569 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, |
| 6570 | &(*ToBasePathOrErr), E->getValueKind()); |
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6571 | } |
| 6572 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6573 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
| 6574 | auto Imp1 = importSeq( |
| 6575 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten()); |
| 6576 | if (!Imp1) |
| 6577 | return Imp1.takeError(); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6578 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6579 | QualType ToType; |
| 6580 | Expr *ToSubExpr; |
| 6581 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 6582 | std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1; |
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6583 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6584 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); |
| 6585 | if (!ToBasePathOrErr) |
| 6586 | return ToBasePathOrErr.takeError(); |
| 6587 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); |
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6588 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6589 | switch (E->getStmtClass()) { |
| 6590 | case Stmt::CStyleCastExprClass: { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6591 | auto *CCE = cast<CStyleCastExpr>(E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6592 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); |
| 6593 | if (!ToLParenLocOrErr) |
| 6594 | return ToLParenLocOrErr.takeError(); |
| 6595 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); |
| 6596 | if (!ToRParenLocOrErr) |
| 6597 | return ToRParenLocOrErr.takeError(); |
| 6598 | return CStyleCastExpr::Create( |
| 6599 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), |
| 6600 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, |
| 6601 | *ToRParenLocOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6602 | } |
| 6603 | |
| 6604 | case Stmt::CXXFunctionalCastExprClass: { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6605 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6606 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); |
| 6607 | if (!ToLParenLocOrErr) |
| 6608 | return ToLParenLocOrErr.takeError(); |
| 6609 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); |
| 6610 | if (!ToRParenLocOrErr) |
| 6611 | return ToRParenLocOrErr.takeError(); |
| 6612 | return CXXFunctionalCastExpr::Create( |
| 6613 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, |
| 6614 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, |
| 6615 | *ToRParenLocOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6616 | } |
| 6617 | |
| 6618 | case Stmt::ObjCBridgedCastExprClass: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6619 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
| 6620 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); |
| 6621 | if (!ToLParenLocOrErr) |
| 6622 | return ToLParenLocOrErr.takeError(); |
| 6623 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); |
| 6624 | if (!ToBridgeKeywordLocOrErr) |
| 6625 | return ToBridgeKeywordLocOrErr.takeError(); |
| 6626 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 6627 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), |
| 6628 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6629 | } |
| 6630 | default: |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6631 | llvm_unreachable("Cast expression of unsupported type!"); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6632 | return make_error<ImportError>(ImportError::UnsupportedConstruct); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6633 | } |
| 6634 | } |
| 6635 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6636 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { |
| 6637 | SmallVector<OffsetOfNode, 4> ToNodes; |
| 6638 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { |
| 6639 | const OffsetOfNode &FromNode = E->getComponent(I); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6640 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6641 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6642 | if (FromNode.getKind() != OffsetOfNode::Base) { |
| 6643 | auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc()); |
| 6644 | if (!Imp) |
| 6645 | return Imp.takeError(); |
| 6646 | std::tie(ToBeginLoc, ToEndLoc) = *Imp; |
| 6647 | } |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6648 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6649 | switch (FromNode.getKind()) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6650 | case OffsetOfNode::Array: |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6651 | ToNodes.push_back( |
| 6652 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6653 | break; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6654 | case OffsetOfNode::Base: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6655 | auto ToBSOrErr = import(FromNode.getBase()); |
| 6656 | if (!ToBSOrErr) |
| 6657 | return ToBSOrErr.takeError(); |
| 6658 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6659 | break; |
| 6660 | } |
| 6661 | case OffsetOfNode::Field: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6662 | auto ToFieldOrErr = import(FromNode.getField()); |
| 6663 | if (!ToFieldOrErr) |
| 6664 | return ToFieldOrErr.takeError(); |
| 6665 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6666 | break; |
| 6667 | } |
| 6668 | case OffsetOfNode::Identifier: { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6669 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); |
| 6670 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6671 | break; |
| 6672 | } |
| 6673 | } |
| 6674 | } |
| 6675 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6676 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); |
| 6677 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { |
| 6678 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); |
| 6679 | if (!ToIndexExprOrErr) |
| 6680 | return ToIndexExprOrErr.takeError(); |
| 6681 | ToExprs[I] = *ToIndexExprOrErr; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6682 | } |
| 6683 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6684 | auto Imp = importSeq( |
| 6685 | E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(), |
| 6686 | E->getRParenLoc()); |
| 6687 | if (!Imp) |
| 6688 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6689 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6690 | QualType ToType; |
| 6691 | TypeSourceInfo *ToTypeSourceInfo; |
| 6692 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 6693 | std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp; |
| 6694 | |
| 6695 | return OffsetOfExpr::Create( |
| 6696 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, |
| 6697 | ToExprs, ToRParenLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6698 | } |
| 6699 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6700 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 6701 | auto Imp = importSeq( |
| 6702 | E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc()); |
| 6703 | if (!Imp) |
| 6704 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6705 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6706 | QualType ToType; |
| 6707 | Expr *ToOperand; |
| 6708 | SourceLocation ToBeginLoc, ToEndLoc; |
| 6709 | std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6710 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6711 | CanThrowResult ToCanThrow; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6712 | if (E->isValueDependent()) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6713 | ToCanThrow = CT_Dependent; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6714 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6715 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6716 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6717 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 6718 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6719 | } |
| 6720 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6721 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 6722 | auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc()); |
| 6723 | if (!Imp) |
| 6724 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6725 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6726 | Expr *ToSubExpr; |
| 6727 | QualType ToType; |
| 6728 | SourceLocation ToThrowLoc; |
| 6729 | std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6730 | |
| 6731 | return new (Importer.getToContext()) CXXThrowExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6732 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6733 | } |
| 6734 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6735 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 6736 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); |
| 6737 | if (!ToUsedLocOrErr) |
| 6738 | return ToUsedLocOrErr.takeError(); |
| 6739 | |
| 6740 | auto ToParamOrErr = import(E->getParam()); |
| 6741 | if (!ToParamOrErr) |
| 6742 | return ToParamOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6743 | |
| 6744 | return CXXDefaultArgExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6745 | Importer.getToContext(), *ToUsedLocOrErr, *ToParamOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6746 | } |
| 6747 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6748 | ExpectedStmt |
| 6749 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 6750 | auto Imp = importSeq( |
| 6751 | E->getType(), E->getTypeSourceInfo(), E->getRParenLoc()); |
| 6752 | if (!Imp) |
| 6753 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6754 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6755 | QualType ToType; |
| 6756 | TypeSourceInfo *ToTypeSourceInfo; |
| 6757 | SourceLocation ToRParenLoc; |
| 6758 | std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6759 | |
| 6760 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6761 | ToType, ToTypeSourceInfo, ToRParenLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6762 | } |
| 6763 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6764 | ExpectedStmt |
| 6765 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 6766 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6767 | if (!ToSubExprOrErr) |
| 6768 | return ToSubExprOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6769 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6770 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); |
| 6771 | if (!ToDtorOrErr) |
| 6772 | return ToDtorOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6773 | |
| 6774 | ASTContext &ToCtx = Importer.getToContext(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6775 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); |
| 6776 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6777 | } |
| 6778 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6779 | ExpectedStmt |
| 6780 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { |
| 6781 | auto Imp = importSeq( |
| 6782 | E->getConstructor(), E->getType(), E->getTypeSourceInfo(), |
| 6783 | E->getParenOrBraceRange()); |
| 6784 | if (!Imp) |
| 6785 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6786 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6787 | CXXConstructorDecl *ToConstructor; |
| 6788 | QualType ToType; |
| 6789 | TypeSourceInfo *ToTypeSourceInfo; |
| 6790 | SourceRange ToParenOrBraceRange; |
| 6791 | std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6792 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6793 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); |
| 6794 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 6795 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6796 | |
| Bruno Ricci | ddb8f6b | 2018-12-22 14:39:30 +0000 | [diff] [blame] | 6797 | return CXXTemporaryObjectExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6798 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, |
| 6799 | ToParenOrBraceRange, E->hadMultipleCandidates(), |
| 6800 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 6801 | E->requiresZeroInitialization()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6802 | } |
| 6803 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6804 | ExpectedStmt |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6805 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6806 | auto Imp = importSeq( |
| 6807 | E->getType(), E->GetTemporaryExpr(), E->getExtendingDecl()); |
| 6808 | if (!Imp) |
| 6809 | return Imp.takeError(); |
| 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 | QualType ToType; |
| 6812 | Expr *ToTemporaryExpr; |
| 6813 | const ValueDecl *ToExtendingDecl; |
| 6814 | std::tie(ToType, ToTemporaryExpr, ToExtendingDecl) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6815 | |
| 6816 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6817 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6818 | |
| 6819 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6820 | ToMTE->setExtendingDecl(ToExtendingDecl, E->getManglingNumber()); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6821 | return ToMTE; |
| 6822 | } |
| 6823 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6824 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 6825 | auto Imp = importSeq( |
| 6826 | E->getType(), E->getPattern(), E->getEllipsisLoc()); |
| 6827 | if (!Imp) |
| 6828 | return Imp.takeError(); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6829 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6830 | QualType ToType; |
| 6831 | Expr *ToPattern; |
| 6832 | SourceLocation ToEllipsisLoc; |
| 6833 | std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp; |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6834 | |
| 6835 | return new (Importer.getToContext()) PackExpansionExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6836 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); |
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6837 | } |
| 6838 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6839 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 6840 | auto Imp = importSeq( |
| 6841 | E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc()); |
| 6842 | if (!Imp) |
| 6843 | return Imp.takeError(); |
| 6844 | |
| 6845 | SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc; |
| 6846 | NamedDecl *ToPack; |
| 6847 | std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6848 | |
| 6849 | Optional<unsigned> Length; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6850 | if (!E->isValueDependent()) |
| 6851 | Length = E->getPackLength(); |
| 6852 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6853 | SmallVector<TemplateArgument, 8> ToPartialArguments; |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6854 | if (E->isPartiallySubstituted()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6855 | if (Error Err = ImportTemplateArguments( |
| 6856 | E->getPartialArguments().data(), |
| 6857 | E->getPartialArguments().size(), |
| 6858 | ToPartialArguments)) |
| 6859 | return std::move(Err); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6860 | } |
| 6861 | |
| 6862 | return SizeOfPackExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6863 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, |
| 6864 | Length, ToPartialArguments); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6865 | } |
| 6866 | |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6867 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6868 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { |
| 6869 | auto Imp = importSeq( |
| 6870 | E->getOperatorNew(), E->getOperatorDelete(), E->getTypeIdParens(), |
| 6871 | E->getArraySize(), E->getInitializer(), E->getType(), |
| 6872 | E->getAllocatedTypeSourceInfo(), E->getSourceRange(), |
| 6873 | E->getDirectInitRange()); |
| 6874 | if (!Imp) |
| 6875 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6876 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6877 | FunctionDecl *ToOperatorNew, *ToOperatorDelete; |
| 6878 | SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange; |
| 6879 | Expr *ToArraySize, *ToInitializer; |
| 6880 | QualType ToType; |
| 6881 | TypeSourceInfo *ToAllocatedTypeSourceInfo; |
| 6882 | std::tie( |
| 6883 | ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer, |
| 6884 | ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6885 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6886 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); |
| 6887 | if (Error Err = |
| 6888 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) |
| 6889 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6890 | |
| Bruno Ricci | 9b6dfac | 2019-01-07 15:04:45 +0000 | [diff] [blame] | 6891 | return CXXNewExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6892 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, |
| 6893 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), |
| 6894 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), |
| 6895 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, |
| 6896 | ToDirectInitRange); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6897 | } |
| 6898 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6899 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 6900 | auto Imp = importSeq( |
| 6901 | E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc()); |
| 6902 | if (!Imp) |
| 6903 | return Imp.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6904 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6905 | QualType ToType; |
| 6906 | FunctionDecl *ToOperatorDelete; |
| 6907 | Expr *ToArgument; |
| 6908 | SourceLocation ToBeginLoc; |
| 6909 | std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp; |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6910 | |
| 6911 | return new (Importer.getToContext()) CXXDeleteExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6912 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), |
| 6913 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, |
| 6914 | ToBeginLoc); |
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6915 | } |
| 6916 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6917 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 6918 | auto Imp = importSeq( |
| 6919 | E->getType(), E->getLocation(), E->getConstructor(), |
| 6920 | E->getParenOrBraceRange()); |
| 6921 | if (!Imp) |
| 6922 | return Imp.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6923 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6924 | QualType ToType; |
| 6925 | SourceLocation ToLocation; |
| 6926 | CXXConstructorDecl *ToConstructor; |
| 6927 | SourceRange ToParenOrBraceRange; |
| 6928 | std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6929 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6930 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6931 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 6932 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6933 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6934 | return CXXConstructExpr::Create( |
| 6935 | Importer.getToContext(), ToType, ToLocation, ToConstructor, |
| 6936 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), |
| 6937 | E->isListInitialization(), E->isStdInitListInitialization(), |
| 6938 | E->requiresZeroInitialization(), E->getConstructionKind(), |
| 6939 | ToParenOrBraceRange); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6940 | } |
| 6941 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6942 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { |
| 6943 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 6944 | if (!ToSubExprOrErr) |
| 6945 | return ToSubExprOrErr.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6946 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6947 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); |
| 6948 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) |
| 6949 | return std::move(Err); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6950 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6951 | return ExprWithCleanups::Create( |
| 6952 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), |
| 6953 | ToObjects); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6954 | } |
| 6955 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6956 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6957 | auto Imp = importSeq( |
| 6958 | E->getCallee(), E->getType(), E->getRParenLoc()); |
| 6959 | if (!Imp) |
| 6960 | return Imp.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6961 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6962 | Expr *ToCallee; |
| 6963 | QualType ToType; |
| 6964 | SourceLocation ToRParenLoc; |
| 6965 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6966 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6967 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6968 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 6969 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6970 | |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 6971 | return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, |
| 6972 | ToType, E->getValueKind(), ToRParenLoc); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6973 | } |
| 6974 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6975 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 6976 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6977 | if (!ToTypeOrErr) |
| 6978 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6979 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6980 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6981 | if (!ToLocationOrErr) |
| 6982 | return ToLocationOrErr.takeError(); |
| 6983 | |
| 6984 | return new (Importer.getToContext()) CXXThisExpr( |
| 6985 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6986 | } |
| 6987 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6988 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 6989 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 6990 | if (!ToTypeOrErr) |
| 6991 | return ToTypeOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6992 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6993 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); |
| 6994 | if (!ToLocationOrErr) |
| 6995 | return ToLocationOrErr.takeError(); |
| 6996 | |
| 6997 | return new (Importer.getToContext()) CXXBoolLiteralExpr( |
| 6998 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6999 | } |
| 7000 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7001 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 7002 | auto Imp1 = importSeq( |
| 7003 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7004 | E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType()); |
| 7005 | if (!Imp1) |
| 7006 | return Imp1.takeError(); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7007 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7008 | Expr *ToBase; |
| 7009 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7010 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7011 | ValueDecl *ToMemberDecl; |
| 7012 | QualType ToType; |
| 7013 | std::tie( |
| 7014 | ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, |
| 7015 | ToType) = *Imp1; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7016 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7017 | auto Imp2 = importSeq( |
| 7018 | E->getFoundDecl().getDecl(), E->getMemberNameInfo().getName(), |
| 7019 | E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7020 | if (!Imp2) |
| 7021 | return Imp2.takeError(); |
| 7022 | NamedDecl *ToDecl; |
| 7023 | DeclarationName ToName; |
| 7024 | SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc; |
| 7025 | std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2; |
| Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 7026 | |
| 7027 | DeclAccessPair ToFoundDecl = |
| 7028 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7029 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7030 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7031 | |
| Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7032 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7033 | if (E->hasExplicitTemplateArgs()) { |
| Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7034 | if (Error Err = |
| 7035 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 7036 | E->template_arguments(), ToTAInfo)) |
| 7037 | return std::move(Err); |
| 7038 | ResInfo = &ToTAInfo; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7039 | } |
| 7040 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7041 | return MemberExpr::Create( |
| 7042 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7043 | ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, ToFoundDecl, |
| Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7044 | ToMemberNameInfo, ResInfo, ToType, E->getValueKind(), E->getObjectKind()); |
| 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 |
| 7048 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { |
| 7049 | auto Imp = importSeq( |
| 7050 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7051 | E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc()); |
| 7052 | if (!Imp) |
| 7053 | return Imp.takeError(); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7054 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7055 | Expr *ToBase; |
| 7056 | SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc; |
| 7057 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7058 | TypeSourceInfo *ToScopeTypeInfo; |
| 7059 | std::tie( |
| 7060 | ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, |
| 7061 | ToTildeLoc) = *Imp; |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7062 | |
| 7063 | PseudoDestructorTypeStorage Storage; |
| 7064 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 7065 | IdentifierInfo *ToII = Importer.Import(FromII); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7066 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); |
| 7067 | if (!ToDestroyedTypeLocOrErr) |
| 7068 | return ToDestroyedTypeLocOrErr.takeError(); |
| 7069 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7070 | } else { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7071 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) |
| 7072 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); |
| 7073 | else |
| 7074 | return ToTIOrErr.takeError(); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7075 | } |
| 7076 | |
| 7077 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7078 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, |
| 7079 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); |
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7080 | } |
| 7081 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7082 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7083 | CXXDependentScopeMemberExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7084 | auto Imp = importSeq( |
| 7085 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7086 | E->getTemplateKeywordLoc(), E->getFirstQualifierFoundInScope()); |
| 7087 | if (!Imp) |
| 7088 | return Imp.takeError(); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7089 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7090 | QualType ToType; |
| 7091 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7092 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7093 | NamedDecl *ToFirstQualifierFoundInScope; |
| 7094 | std::tie( |
| 7095 | ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7096 | ToFirstQualifierFoundInScope) = *Imp; |
| 7097 | |
| 7098 | Expr *ToBase = nullptr; |
| 7099 | if (!E->isImplicitAccess()) { |
| 7100 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7101 | ToBase = *ToBaseOrErr; |
| 7102 | else |
| 7103 | return ToBaseOrErr.takeError(); |
| 7104 | } |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7105 | |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7106 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7107 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7108 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7109 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7110 | ToTAInfo)) |
| 7111 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7112 | ResInfo = &ToTAInfo; |
| 7113 | } |
| 7114 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7115 | auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc()); |
| 7116 | if (!ToMemberNameInfoOrErr) |
| 7117 | return ToMemberNameInfoOrErr.takeError(); |
| 7118 | DeclarationNameInfo ToMemberNameInfo( |
| 7119 | std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr)); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7120 | // Import additional name location/type info. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7121 | if (Error Err = ImportDeclarationNameLoc( |
| 7122 | E->getMemberNameInfo(), ToMemberNameInfo)) |
| 7123 | return std::move(Err); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7124 | |
| 7125 | return CXXDependentScopeMemberExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7126 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, |
| 7127 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, |
| 7128 | ToMemberNameInfo, ResInfo); |
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7129 | } |
| 7130 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7131 | ExpectedStmt |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7132 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7133 | auto Imp = importSeq( |
| 7134 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDeclName(), |
| 7135 | E->getExprLoc(), E->getLAngleLoc(), E->getRAngleLoc()); |
| 7136 | if (!Imp) |
| 7137 | return Imp.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7138 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7139 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7140 | SourceLocation ToTemplateKeywordLoc, ToExprLoc, ToLAngleLoc, ToRAngleLoc; |
| 7141 | DeclarationName ToDeclName; |
| 7142 | std::tie( |
| 7143 | ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToExprLoc, |
| 7144 | ToLAngleLoc, ToRAngleLoc) = *Imp; |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7145 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7146 | DeclarationNameInfo ToNameInfo(ToDeclName, ToExprLoc); |
| 7147 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7148 | return std::move(Err); |
| 7149 | |
| 7150 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7151 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7152 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7153 | if (Error Err = |
| 7154 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7155 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7156 | ResInfo = &ToTAInfo; |
| 7157 | } |
| 7158 | |
| 7159 | return DependentScopeDeclRefExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7160 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, |
| 7161 | ToNameInfo, ResInfo); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7162 | } |
| 7163 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7164 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 7165 | CXXUnresolvedConstructExpr *E) { |
| 7166 | auto Imp = importSeq( |
| 7167 | E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo()); |
| 7168 | if (!Imp) |
| 7169 | return Imp.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7170 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7171 | SourceLocation ToLParenLoc, ToRParenLoc; |
| 7172 | TypeSourceInfo *ToTypeSourceInfo; |
| 7173 | std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp; |
| 7174 | |
| 7175 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); |
| 7176 | if (Error Err = |
| 7177 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) |
| 7178 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7179 | |
| 7180 | return CXXUnresolvedConstructExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7181 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, |
| 7182 | llvm::makeArrayRef(ToArgs), ToRParenLoc); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7183 | } |
| 7184 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7185 | ExpectedStmt |
| 7186 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
| 7187 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); |
| 7188 | if (!ToNamingClassOrErr) |
| 7189 | return ToNamingClassOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7190 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7191 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); |
| 7192 | if (!ToQualifierLocOrErr) |
| 7193 | return ToQualifierLocOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7194 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7195 | auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc()); |
| 7196 | if (!ToNameInfoOrErr) |
| 7197 | return ToNameInfoOrErr.takeError(); |
| 7198 | DeclarationNameInfo ToNameInfo( |
| 7199 | std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr)); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7200 | // Import additional name location/type info. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7201 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7202 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7203 | |
| 7204 | UnresolvedSet<8> ToDecls; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7205 | for (auto *D : E->decls()) |
| 7206 | if (auto ToDOrErr = import(D)) |
| 7207 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7208 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7209 | return ToDOrErr.takeError(); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7210 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7211 | if (E->hasExplicitTemplateArgs() && E->getTemplateKeywordLoc().isValid()) { |
| 7212 | TemplateArgumentListInfo ToTAInfo; |
| 7213 | if (Error Err = ImportTemplateArgumentListInfo( |
| 7214 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), |
| 7215 | ToTAInfo)) |
| 7216 | return std::move(Err); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7217 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7218 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); |
| 7219 | if (!ToTemplateKeywordLocOrErr) |
| 7220 | return ToTemplateKeywordLocOrErr.takeError(); |
| 7221 | |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7222 | return UnresolvedLookupExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7223 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7224 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, |
| 7225 | ToDecls.begin(), ToDecls.end()); |
| 7226 | } |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7227 | |
| 7228 | return UnresolvedLookupExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7229 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, |
| 7230 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), |
| 7231 | ToDecls.end()); |
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7232 | } |
| 7233 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7234 | ExpectedStmt |
| 7235 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 7236 | auto Imp1 = importSeq( |
| 7237 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), |
| 7238 | E->getTemplateKeywordLoc()); |
| 7239 | if (!Imp1) |
| 7240 | return Imp1.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7241 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7242 | QualType ToType; |
| 7243 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; |
| 7244 | NestedNameSpecifierLoc ToQualifierLoc; |
| 7245 | std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1; |
| 7246 | |
| 7247 | auto Imp2 = importSeq(E->getName(), E->getNameLoc()); |
| 7248 | if (!Imp2) |
| 7249 | return Imp2.takeError(); |
| 7250 | DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2)); |
| 7251 | // Import additional name location/type info. |
| 7252 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) |
| 7253 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7254 | |
| 7255 | UnresolvedSet<8> ToDecls; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7256 | for (Decl *D : E->decls()) |
| 7257 | if (auto ToDOrErr = import(D)) |
| 7258 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7259 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7260 | return ToDOrErr.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7261 | |
| 7262 | TemplateArgumentListInfo ToTAInfo; |
| 7263 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 7264 | if (E->hasExplicitTemplateArgs()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7265 | if (Error Err = |
| 7266 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 7267 | return std::move(Err); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7268 | ResInfo = &ToTAInfo; |
| 7269 | } |
| 7270 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7271 | Expr *ToBase = nullptr; |
| 7272 | if (!E->isImplicitAccess()) { |
| 7273 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) |
| 7274 | ToBase = *ToBaseOrErr; |
| 7275 | else |
| 7276 | return ToBaseOrErr.takeError(); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7277 | } |
| 7278 | |
| 7279 | return UnresolvedMemberExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7280 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, |
| 7281 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, |
| 7282 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); |
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7283 | } |
| 7284 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7285 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 7286 | auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc()); |
| 7287 | if (!Imp) |
| 7288 | return Imp.takeError(); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7289 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7290 | Expr *ToCallee; |
| 7291 | QualType ToType; |
| 7292 | SourceLocation ToRParenLoc; |
| 7293 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7294 | |
| 7295 | unsigned NumArgs = E->getNumArgs(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7296 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); |
| 7297 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) |
| 7298 | return std::move(Err); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7299 | |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7300 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7301 | return CXXOperatorCallExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7302 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, |
| Eric Fiselier | 5cdc2cd | 2018-12-12 21:50:55 +0000 | [diff] [blame] | 7303 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), |
| 7304 | OCE->getADLCallKind()); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7305 | } |
| 7306 | |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7307 | return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType, |
| 7308 | E->getValueKind(), ToRParenLoc, /*MinNumArgs=*/0, |
| 7309 | E->getADLCallKind()); |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7310 | } |
| 7311 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7312 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { |
| 7313 | CXXRecordDecl *FromClass = E->getLambdaClass(); |
| 7314 | auto ToClassOrErr = import(FromClass); |
| 7315 | if (!ToClassOrErr) |
| 7316 | return ToClassOrErr.takeError(); |
| 7317 | CXXRecordDecl *ToClass = *ToClassOrErr; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7318 | |
| 7319 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 7320 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 7321 | // manually. |
| Gabor Marton | 302f300 | 2019-02-15 12:04:05 +0000 | [diff] [blame] | 7322 | if (ToClass->isBeingDefined()) |
| 7323 | if (Error Err = ImportDeclContext(FromClass, /*ForceImport = */ true)) |
| 7324 | return std::move(Err); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7325 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7326 | auto ToCallOpOrErr = import(E->getCallOperator()); |
| 7327 | if (!ToCallOpOrErr) |
| 7328 | return ToCallOpOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7329 | |
| 7330 | ToClass->completeDefinition(); |
| 7331 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7332 | SmallVector<LambdaCapture, 8> ToCaptures; |
| 7333 | ToCaptures.reserve(E->capture_size()); |
| 7334 | for (const auto &FromCapture : E->captures()) { |
| 7335 | if (auto ToCaptureOrErr = import(FromCapture)) |
| 7336 | ToCaptures.push_back(*ToCaptureOrErr); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7337 | else |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7338 | return ToCaptureOrErr.takeError(); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7339 | } |
| 7340 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7341 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); |
| 7342 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) |
| 7343 | return std::move(Err); |
| 7344 | |
| 7345 | auto Imp = importSeq( |
| 7346 | E->getIntroducerRange(), E->getCaptureDefaultLoc(), E->getEndLoc()); |
| 7347 | if (!Imp) |
| 7348 | return Imp.takeError(); |
| 7349 | |
| 7350 | SourceRange ToIntroducerRange; |
| 7351 | SourceLocation ToCaptureDefaultLoc, ToEndLoc; |
| 7352 | std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp; |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7353 | |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7354 | return LambdaExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7355 | Importer.getToContext(), ToClass, ToIntroducerRange, |
| 7356 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, |
| 7357 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, |
| 7358 | ToEndLoc, E->containsUnexpandedParameterPack()); |
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7359 | } |
| 7360 | |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7361 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7362 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { |
| 7363 | auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType()); |
| 7364 | if (!Imp) |
| 7365 | return Imp.takeError(); |
| 7366 | |
| 7367 | SourceLocation ToLBraceLoc, ToRBraceLoc; |
| 7368 | QualType ToType; |
| 7369 | std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp; |
| 7370 | |
| 7371 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); |
| 7372 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) |
| 7373 | return std::move(Err); |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7374 | |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7375 | ASTContext &ToCtx = Importer.getToContext(); |
| 7376 | InitListExpr *To = new (ToCtx) InitListExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7377 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); |
| 7378 | To->setType(ToType); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7379 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7380 | if (E->hasArrayFiller()) { |
| 7381 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) |
| 7382 | To->setArrayFiller(*ToFillerOrErr); |
| 7383 | else |
| 7384 | return ToFillerOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7385 | } |
| 7386 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7387 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { |
| 7388 | if (auto ToFDOrErr = import(FromFD)) |
| 7389 | To->setInitializedFieldInUnion(*ToFDOrErr); |
| 7390 | else |
| 7391 | return ToFDOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7392 | } |
| 7393 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7394 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { |
| 7395 | if (auto ToSyntFormOrErr = import(SyntForm)) |
| 7396 | To->setSyntacticForm(*ToSyntFormOrErr); |
| 7397 | else |
| 7398 | return ToSyntFormOrErr.takeError(); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7399 | } |
| 7400 | |
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7401 | // Copy InitListExprBitfields, which are not handled in the ctor of |
| 7402 | // InitListExpr. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7403 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); |
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7404 | |
| 7405 | return To; |
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7406 | } |
| 7407 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7408 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7409 | CXXStdInitializerListExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7410 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7411 | if (!ToTypeOrErr) |
| 7412 | return ToTypeOrErr.takeError(); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7413 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7414 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); |
| 7415 | if (!ToSubExprOrErr) |
| 7416 | return ToSubExprOrErr.takeError(); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7417 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7418 | return new (Importer.getToContext()) CXXStdInitializerListExpr( |
| 7419 | *ToTypeOrErr, *ToSubExprOrErr); |
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7420 | } |
| 7421 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7422 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7423 | CXXInheritedCtorInitExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7424 | auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor()); |
| 7425 | if (!Imp) |
| 7426 | return Imp.takeError(); |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7427 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7428 | SourceLocation ToLocation; |
| 7429 | QualType ToType; |
| 7430 | CXXConstructorDecl *ToConstructor; |
| 7431 | std::tie(ToLocation, ToType, ToConstructor) = *Imp; |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7432 | |
| 7433 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7434 | ToLocation, ToType, ToConstructor, E->constructsVBase(), |
| 7435 | E->inheritedFromVBase()); |
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7436 | } |
| 7437 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7438 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 7439 | auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr()); |
| 7440 | if (!Imp) |
| 7441 | return Imp.takeError(); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7442 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7443 | QualType ToType; |
| 7444 | Expr *ToCommonExpr, *ToSubExpr; |
| 7445 | std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp; |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7446 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7447 | return new (Importer.getToContext()) ArrayInitLoopExpr( |
| 7448 | ToType, ToCommonExpr, ToSubExpr); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7449 | } |
| 7450 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7451 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 7452 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7453 | if (!ToTypeOrErr) |
| 7454 | return ToTypeOrErr.takeError(); |
| 7455 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7456 | } |
| 7457 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7458 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 7459 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); |
| 7460 | if (!ToBeginLocOrErr) |
| 7461 | return ToBeginLocOrErr.takeError(); |
| 7462 | |
| 7463 | auto ToFieldOrErr = import(E->getField()); |
| 7464 | if (!ToFieldOrErr) |
| 7465 | return ToFieldOrErr.takeError(); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7466 | |
| 7467 | return CXXDefaultInitExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7468 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7469 | } |
| 7470 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7471 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 7472 | auto Imp = importSeq( |
| 7473 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(), |
| 7474 | E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets()); |
| 7475 | if (!Imp) |
| 7476 | return Imp.takeError(); |
| 7477 | |
| 7478 | QualType ToType; |
| 7479 | Expr *ToSubExpr; |
| 7480 | TypeSourceInfo *ToTypeInfoAsWritten; |
| 7481 | SourceLocation ToOperatorLoc, ToRParenLoc; |
| 7482 | SourceRange ToAngleBrackets; |
| 7483 | std::tie( |
| 7484 | ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, |
| 7485 | ToAngleBrackets) = *Imp; |
| 7486 | |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7487 | ExprValueKind VK = E->getValueKind(); |
| 7488 | CastKind CK = E->getCastKind(); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7489 | auto ToBasePathOrErr = ImportCastPath(E); |
| 7490 | if (!ToBasePathOrErr) |
| 7491 | return ToBasePathOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7492 | |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7493 | if (isa<CXXStaticCastExpr>(E)) { |
| 7494 | return CXXStaticCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7495 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7496 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7497 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 7498 | return CXXDynamicCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7499 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7500 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7501 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 7502 | return CXXReinterpretCastExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7503 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), |
| 7504 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 7505 | } else if (isa<CXXConstCastExpr>(E)) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7506 | return CXXConstCastExpr::Create( |
| 7507 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, |
| 7508 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7509 | } else { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7510 | llvm_unreachable("Unknown cast type"); |
| 7511 | return make_error<ImportError>(); |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7512 | } |
| 7513 | } |
| 7514 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7515 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7516 | SubstNonTypeTemplateParmExpr *E) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7517 | auto Imp = importSeq( |
| 7518 | E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement()); |
| 7519 | if (!Imp) |
| 7520 | return Imp.takeError(); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7521 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7522 | QualType ToType; |
| 7523 | SourceLocation ToExprLoc; |
| 7524 | NonTypeTemplateParmDecl *ToParameter; |
| 7525 | Expr *ToReplacement; |
| 7526 | std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp; |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7527 | |
| 7528 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7529 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7530 | } |
| 7531 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7532 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 7533 | auto Imp = importSeq( |
| 7534 | E->getType(), E->getBeginLoc(), E->getEndLoc()); |
| 7535 | if (!Imp) |
| 7536 | return Imp.takeError(); |
| 7537 | |
| 7538 | QualType ToType; |
| 7539 | SourceLocation ToBeginLoc, ToEndLoc; |
| 7540 | std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp; |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7541 | |
| 7542 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7543 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) |
| 7544 | return std::move(Err); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7545 | |
| 7546 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 7547 | // Value is always false. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7548 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7549 | |
| 7550 | return TypeTraitExpr::Create( |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7551 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, |
| 7552 | ToEndLoc, ToValue); |
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7553 | } |
| 7554 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7555 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 7556 | ExpectedType ToTypeOrErr = import(E->getType()); |
| 7557 | if (!ToTypeOrErr) |
| 7558 | return ToTypeOrErr.takeError(); |
| 7559 | |
| 7560 | auto ToSourceRangeOrErr = import(E->getSourceRange()); |
| 7561 | if (!ToSourceRangeOrErr) |
| 7562 | return ToSourceRangeOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7563 | |
| 7564 | if (E->isTypeOperand()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7565 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) |
| 7566 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7567 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); |
| 7568 | else |
| 7569 | return ToTSIOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7570 | } |
| 7571 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7572 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); |
| 7573 | if (!ToExprOperandOrErr) |
| 7574 | return ToExprOperandOrErr.takeError(); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7575 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7576 | return new (Importer.getToContext()) CXXTypeidExpr( |
| 7577 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); |
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7578 | } |
| 7579 | |
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7580 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 7581 | CXXMethodDecl *FromMethod) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7582 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { |
| 7583 | if (auto ImportedOrErr = import(FromOverriddenMethod)) |
| 7584 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( |
| 7585 | (*ImportedOrErr)->getCanonicalDecl())); |
| 7586 | else |
| 7587 | consumeError(ImportedOrErr.takeError()); |
| 7588 | } |
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7589 | } |
| 7590 | |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7591 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7592 | ASTContext &FromContext, FileManager &FromFileManager, |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7593 | bool MinimalImport, |
| 7594 | ASTImporterLookupTable *LookupTable) |
| 7595 | : LookupTable(LookupTable), ToContext(ToContext), FromContext(FromContext), |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7596 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| 7597 | Minimal(MinimalImport) { |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7598 | |
| 7599 | ImportedDecls[FromContext.getTranslationUnitDecl()] = |
| 7600 | ToContext.getTranslationUnitDecl(); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7601 | } |
| 7602 | |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7603 | ASTImporter::~ASTImporter() = default; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7604 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7605 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { |
| 7606 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && |
| 7607 | "Try to get field index for non-field."); |
| 7608 | |
| 7609 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
| 7610 | if (!Owner) |
| 7611 | return None; |
| 7612 | |
| 7613 | unsigned Index = 0; |
| 7614 | for (const auto *D : Owner->decls()) { |
| 7615 | if (D == F) |
| 7616 | return Index; |
| 7617 | |
| 7618 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 7619 | ++Index; |
| 7620 | } |
| 7621 | |
| 7622 | llvm_unreachable("Field was not found in its parent context."); |
| 7623 | |
| 7624 | return None; |
| 7625 | } |
| 7626 | |
| 7627 | ASTImporter::FoundDeclsTy |
| 7628 | ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) { |
| 7629 | // We search in the redecl context because of transparent contexts. |
| 7630 | // E.g. a simple C language enum is a transparent context: |
| 7631 | // enum E { A, B }; |
| 7632 | // Now if we had a global variable in the TU |
| 7633 | // int A; |
| 7634 | // then the enum constant 'A' and the variable 'A' violates ODR. |
| 7635 | // We can diagnose this only if we search in the redecl context. |
| 7636 | DeclContext *ReDC = DC->getRedeclContext(); |
| 7637 | if (LookupTable) { |
| 7638 | ASTImporterLookupTable::LookupResult LookupResult = |
| 7639 | LookupTable->lookup(ReDC, Name); |
| 7640 | return FoundDeclsTy(LookupResult.begin(), LookupResult.end()); |
| 7641 | } else { |
| 7642 | // FIXME Can we remove this kind of lookup? |
| 7643 | // Or lldb really needs this C/C++ lookup? |
| 7644 | FoundDeclsTy Result; |
| 7645 | ReDC->localUncachedLookup(Name, Result); |
| 7646 | return Result; |
| 7647 | } |
| 7648 | } |
| 7649 | |
| 7650 | void ASTImporter::AddToLookupTable(Decl *ToD) { |
| 7651 | if (LookupTable) |
| 7652 | if (auto *ToND = dyn_cast<NamedDecl>(ToD)) |
| 7653 | LookupTable->add(ToND); |
| 7654 | } |
| 7655 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7656 | Expected<QualType> ASTImporter::Import_New(QualType FromT) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7657 | if (FromT.isNull()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7658 | return QualType{}; |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7659 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7660 | const Type *FromTy = FromT.getTypePtr(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7661 | |
| 7662 | // Check whether we've already imported this type. |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7663 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7664 | = ImportedTypes.find(FromTy); |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7665 | if (Pos != ImportedTypes.end()) |
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7666 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7667 | |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7668 | // Import the type |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7669 | ASTNodeImporter Importer(*this); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7670 | ExpectedType ToTOrErr = Importer.Visit(FromTy); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7671 | if (!ToTOrErr) |
| 7672 | return ToTOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7673 | |
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7674 | // Record the imported type. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7675 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7676 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7677 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7678 | } |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7679 | QualType ASTImporter::Import(QualType From) { |
| 7680 | llvm::Expected<QualType> To = Import_New(From); |
| 7681 | if (To) |
| 7682 | return *To; |
| 7683 | else |
| 7684 | llvm::consumeError(To.takeError()); |
| 7685 | return {}; |
| 7686 | } |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7687 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7688 | Expected<TypeSourceInfo *> ASTImporter::Import_New(TypeSourceInfo *FromTSI) { |
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7689 | if (!FromTSI) |
| 7690 | return FromTSI; |
| 7691 | |
| 7692 | // FIXME: For now we just create a "trivial" type source info based |
| Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 7693 | // on the type and a single location. Implement a real version of this. |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7694 | ExpectedType TOrErr = Import_New(FromTSI->getType()); |
| 7695 | if (!TOrErr) |
| 7696 | return TOrErr.takeError(); |
| 7697 | ExpectedSLoc BeginLocOrErr = Import_New(FromTSI->getTypeLoc().getBeginLoc()); |
| 7698 | if (!BeginLocOrErr) |
| 7699 | return BeginLocOrErr.takeError(); |
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7700 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7701 | return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr); |
| 7702 | } |
| 7703 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *From) { |
| 7704 | llvm::Expected<TypeSourceInfo *> To = Import_New(From); |
| 7705 | if (To) |
| 7706 | return *To; |
| 7707 | else |
| 7708 | llvm::consumeError(To.takeError()); |
| 7709 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7710 | } |
| 7711 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7712 | Expected<Attr *> ASTImporter::Import_New(const Attr *FromAttr) { |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7713 | Attr *ToAttr = FromAttr->clone(ToContext); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7714 | if (auto ToRangeOrErr = Import_New(FromAttr->getRange())) |
| 7715 | ToAttr->setRange(*ToRangeOrErr); |
| 7716 | else |
| 7717 | return ToRangeOrErr.takeError(); |
| 7718 | |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7719 | return ToAttr; |
| Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 7720 | } |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7721 | Attr *ASTImporter::Import(const Attr *From) { |
| 7722 | llvm::Expected<Attr *> To = Import_New(From); |
| 7723 | if (To) |
| 7724 | return *To; |
| 7725 | else |
| 7726 | llvm::consumeError(To.takeError()); |
| 7727 | return nullptr; |
| 7728 | } |
| Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 7729 | |
| Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 7730 | Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { |
| 7731 | auto Pos = ImportedDecls.find(FromD); |
| 7732 | if (Pos != ImportedDecls.end()) |
| 7733 | return Pos->second; |
| 7734 | else |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7735 | return nullptr; |
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7736 | } |
| 7737 | |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 7738 | TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) { |
| 7739 | auto FromDPos = ImportedFromDecls.find(ToD); |
| 7740 | if (FromDPos == ImportedFromDecls.end()) |
| 7741 | return nullptr; |
| 7742 | return FromDPos->second->getTranslationUnitDecl(); |
| 7743 | } |
| 7744 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7745 | Expected<Decl *> ASTImporter::Import_New(Decl *FromD) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7746 | if (!FromD) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7747 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7748 | |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7749 | ASTNodeImporter Importer(*this); |
| 7750 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7751 | // Check whether we've already imported this declaration. |
| 7752 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 7753 | if (ToD) { |
| 7754 | // If FromD has some updated flags after last import, apply it |
| 7755 | updateFlags(FromD, ToD); |
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7756 | return ToD; |
| 7757 | } |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7758 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7759 | // Import the declaration. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7760 | ExpectedDecl ToDOrErr = Importer.Visit(FromD); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7761 | if (!ToDOrErr) |
| 7762 | return ToDOrErr; |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7763 | ToD = *ToDOrErr; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7764 | |
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 7765 | // FIXME Use getImportDeclErrorIfAny() here (and return with the error) once |
| 7766 | // the error handling is finished in GetImportedOrCreateSpecialDecl(). |
| 7767 | if (!ToD) { |
| 7768 | return nullptr; |
| 7769 | } |
| 7770 | |
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7771 | // Once the decl is connected to the existing declarations, i.e. when the |
| 7772 | // redecl chain is properly set then we populate the lookup again. |
| 7773 | // This way the primary context will be able to find all decls. |
| 7774 | AddToLookupTable(ToD); |
| 7775 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7776 | // Notify subclasses. |
| 7777 | Imported(FromD, ToD); |
| 7778 | |
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 7779 | updateFlags(FromD, ToD); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7780 | return ToDOrErr; |
| 7781 | } |
| 7782 | Decl *ASTImporter::Import(Decl *From) { |
| 7783 | llvm::Expected<Decl *> To = Import_New(From); |
| 7784 | if (To) |
| 7785 | return *To; |
| 7786 | else |
| 7787 | llvm::consumeError(To.takeError()); |
| 7788 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7789 | } |
| 7790 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7791 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7792 | if (!FromDC) |
| 7793 | return FromDC; |
| 7794 | |
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 7795 | ExpectedDecl ToDCOrErr = Import_New(cast<Decl>(FromDC)); |
| 7796 | if (!ToDCOrErr) |
| 7797 | return ToDCOrErr.takeError(); |
| 7798 | auto *ToDC = cast<DeclContext>(*ToDCOrErr); |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7799 | |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7800 | // 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] | 7801 | // need it to have a definition. |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7802 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 7803 | auto *FromRecord = cast<RecordDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7804 | if (ToRecord->isCompleteDefinition()) { |
| 7805 | // Do nothing. |
| 7806 | } else if (FromRecord->isCompleteDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7807 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7808 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) |
| 7809 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7810 | } else { |
| 7811 | CompleteDecl(ToRecord); |
| 7812 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7813 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 7814 | auto *FromEnum = cast<EnumDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7815 | if (ToEnum->isCompleteDefinition()) { |
| 7816 | // Do nothing. |
| 7817 | } else if (FromEnum->isCompleteDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7818 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7819 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) |
| 7820 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7821 | } else { |
| 7822 | CompleteDecl(ToEnum); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7823 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7824 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 7825 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7826 | if (ToClass->getDefinition()) { |
| 7827 | // Do nothing. |
| 7828 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7829 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7830 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) |
| 7831 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7832 | } else { |
| 7833 | CompleteDecl(ToClass); |
| 7834 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7835 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 7836 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7837 | if (ToProto->getDefinition()) { |
| 7838 | // Do nothing. |
| 7839 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7840 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( |
| 7841 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) |
| 7842 | return std::move(Err); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7843 | } else { |
| 7844 | CompleteDecl(ToProto); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7845 | } |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7846 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7847 | |
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7848 | return ToDC; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7849 | } |
| 7850 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7851 | Expected<Expr *> ASTImporter::Import_New(Expr *FromE) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7852 | if (ExpectedStmt ToSOrErr = Import_New(cast_or_null<Stmt>(FromE))) |
| 7853 | return cast_or_null<Expr>(*ToSOrErr); |
| 7854 | else |
| 7855 | return ToSOrErr.takeError(); |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7856 | } |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7857 | Expr *ASTImporter::Import(Expr *From) { |
| 7858 | llvm::Expected<Expr *> To = Import_New(From); |
| 7859 | if (To) |
| 7860 | return *To; |
| 7861 | else |
| 7862 | llvm::consumeError(To.takeError()); |
| 7863 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7864 | } |
| 7865 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7866 | Expected<Stmt *> ASTImporter::Import_New(Stmt *FromS) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7867 | if (!FromS) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7868 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7869 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7870 | // Check whether we've already imported this statement. |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7871 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 7872 | if (Pos != ImportedStmts.end()) |
| 7873 | return Pos->second; |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7874 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7875 | // Import the statement. |
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7876 | ASTNodeImporter Importer(*this); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7877 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7878 | if (!ToSOrErr) |
| 7879 | return ToSOrErr; |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7880 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7881 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { |
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7882 | auto *FromE = cast<Expr>(FromS); |
| 7883 | // Copy ExprBitfields, which may not be handled in Expr subclasses |
| 7884 | // constructors. |
| 7885 | ToE->setValueKind(FromE->getValueKind()); |
| 7886 | ToE->setObjectKind(FromE->getObjectKind()); |
| 7887 | ToE->setTypeDependent(FromE->isTypeDependent()); |
| 7888 | ToE->setValueDependent(FromE->isValueDependent()); |
| 7889 | ToE->setInstantiationDependent(FromE->isInstantiationDependent()); |
| 7890 | ToE->setContainsUnexpandedParameterPack( |
| 7891 | FromE->containsUnexpandedParameterPack()); |
| 7892 | } |
| 7893 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7894 | // Record the imported statement object. |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7895 | ImportedStmts[FromS] = *ToSOrErr; |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7896 | return ToSOrErr; |
| 7897 | } |
| 7898 | Stmt *ASTImporter::Import(Stmt *From) { |
| 7899 | llvm::Expected<Stmt *> To = Import_New(From); |
| 7900 | if (To) |
| 7901 | return *To; |
| 7902 | else |
| 7903 | llvm::consumeError(To.takeError()); |
| 7904 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7905 | } |
| 7906 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7907 | Expected<NestedNameSpecifier *> |
| 7908 | ASTImporter::Import_New(NestedNameSpecifier *FromNNS) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7909 | if (!FromNNS) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7910 | return nullptr; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7911 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7912 | NestedNameSpecifier *Prefix; |
| 7913 | if (Error Err = importInto(Prefix, FromNNS->getPrefix())) |
| 7914 | return std::move(Err); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7915 | |
| 7916 | switch (FromNNS->getKind()) { |
| 7917 | case NestedNameSpecifier::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7918 | assert(FromNNS->getAsIdentifier() && "NNS should contain identifier."); |
| 7919 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 7920 | Import(FromNNS->getAsIdentifier())); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7921 | |
| 7922 | case NestedNameSpecifier::Namespace: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7923 | if (ExpectedDecl NSOrErr = Import_New(FromNNS->getAsNamespace())) { |
| 7924 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 7925 | cast<NamespaceDecl>(*NSOrErr)); |
| 7926 | } else |
| 7927 | return NSOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7928 | |
| 7929 | case NestedNameSpecifier::NamespaceAlias: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7930 | if (ExpectedDecl NSADOrErr = Import_New(FromNNS->getAsNamespaceAlias())) |
| 7931 | return NestedNameSpecifier::Create(ToContext, Prefix, |
| 7932 | cast<NamespaceAliasDecl>(*NSADOrErr)); |
| 7933 | else |
| 7934 | return NSADOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7935 | |
| 7936 | case NestedNameSpecifier::Global: |
| 7937 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 7938 | |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7939 | case NestedNameSpecifier::Super: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7940 | if (ExpectedDecl RDOrErr = Import_New(FromNNS->getAsRecordDecl())) |
| 7941 | return NestedNameSpecifier::SuperSpecifier(ToContext, |
| 7942 | cast<CXXRecordDecl>(*RDOrErr)); |
| 7943 | else |
| 7944 | return RDOrErr.takeError(); |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7945 | |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7946 | case NestedNameSpecifier::TypeSpec: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7947 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 7948 | if (Expected<QualType> TyOrErr = |
| 7949 | Import_New(QualType(FromNNS->getAsType(), 0u))) { |
| 7950 | bool TSTemplate = |
| 7951 | FromNNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate; |
| 7952 | return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate, |
| 7953 | TyOrErr->getTypePtr()); |
| 7954 | } else { |
| 7955 | return TyOrErr.takeError(); |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7956 | } |
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7957 | } |
| 7958 | |
| 7959 | llvm_unreachable("Invalid nested name specifier kind"); |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7960 | } |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7961 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *From) { |
| 7962 | llvm::Expected<NestedNameSpecifier *> To = Import_New(From); |
| 7963 | if (To) |
| 7964 | return *To; |
| 7965 | else |
| 7966 | llvm::consumeError(To.takeError()); |
| 7967 | return nullptr; |
| 7968 | } |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7969 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 7970 | Expected<NestedNameSpecifierLoc> |
| 7971 | ASTImporter::Import_New(NestedNameSpecifierLoc FromNNS) { |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7972 | // Copied from NestedNameSpecifier mostly. |
| 7973 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 7974 | NestedNameSpecifierLoc NNS = FromNNS; |
| 7975 | |
| 7976 | // Push each of the nested-name-specifiers's onto a stack for |
| 7977 | // serialization in reverse order. |
| 7978 | while (NNS) { |
| 7979 | NestedNames.push_back(NNS); |
| 7980 | NNS = NNS.getPrefix(); |
| 7981 | } |
| 7982 | |
| 7983 | NestedNameSpecifierLocBuilder Builder; |
| 7984 | |
| 7985 | while (!NestedNames.empty()) { |
| 7986 | NNS = NestedNames.pop_back_val(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7987 | NestedNameSpecifier *Spec; |
| 7988 | if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier())) |
| 7989 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7990 | |
| 7991 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7992 | |
| 7993 | SourceLocation ToLocalBeginLoc, ToLocalEndLoc; |
| 7994 | if (Kind != NestedNameSpecifier::Super) { |
| 7995 | if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc())) |
| 7996 | return std::move(Err); |
| 7997 | |
| 7998 | if (Kind != NestedNameSpecifier::Global) |
| 7999 | if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc())) |
| 8000 | return std::move(Err); |
| 8001 | } |
| 8002 | |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8003 | switch (Kind) { |
| 8004 | case NestedNameSpecifier::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8005 | Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc, |
| 8006 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8007 | break; |
| 8008 | |
| 8009 | case NestedNameSpecifier::Namespace: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8010 | Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc, |
| 8011 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8012 | break; |
| 8013 | |
| 8014 | case NestedNameSpecifier::NamespaceAlias: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8015 | Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(), |
| 8016 | ToLocalBeginLoc, ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8017 | break; |
| 8018 | |
| 8019 | case NestedNameSpecifier::TypeSpec: |
| 8020 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8021 | SourceLocation ToTLoc; |
| 8022 | if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc())) |
| 8023 | return std::move(Err); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8024 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8025 | QualType(Spec->getAsType(), 0), ToTLoc); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8026 | Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(), |
| 8027 | ToLocalEndLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8028 | break; |
| 8029 | } |
| 8030 | |
| 8031 | case NestedNameSpecifier::Global: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8032 | Builder.MakeGlobal(getToContext(), ToLocalBeginLoc); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8033 | break; |
| 8034 | |
| 8035 | case NestedNameSpecifier::Super: { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8036 | auto ToSourceRangeOrErr = Import_New(NNS.getSourceRange()); |
| 8037 | if (!ToSourceRangeOrErr) |
| 8038 | return ToSourceRangeOrErr.takeError(); |
| 8039 | |
| 8040 | Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(), |
| 8041 | ToSourceRangeOrErr->getBegin(), |
| 8042 | ToSourceRangeOrErr->getEnd()); |
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8043 | } |
| 8044 | } |
| 8045 | } |
| 8046 | |
| 8047 | return Builder.getWithLocInContext(getToContext()); |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 8048 | } |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8049 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc From) { |
| 8050 | llvm::Expected<NestedNameSpecifierLoc> To = Import_New(From); |
| 8051 | if (To) |
| 8052 | return *To; |
| 8053 | else |
| 8054 | llvm::consumeError(To.takeError()); |
| 8055 | return {}; |
| 8056 | } |
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 8057 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8058 | Expected<TemplateName> ASTImporter::Import_New(TemplateName From) { |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8059 | switch (From.getKind()) { |
| 8060 | case TemplateName::Template: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8061 | if (ExpectedDecl ToTemplateOrErr = Import_New(From.getAsTemplateDecl())) |
| 8062 | return TemplateName(cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8063 | else |
| 8064 | return ToTemplateOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8065 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8066 | case TemplateName::OverloadedTemplate: { |
| 8067 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 8068 | UnresolvedSet<2> ToTemplates; |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8069 | for (auto *I : *FromStorage) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8070 | if (auto ToOrErr = Import_New(I)) |
| 8071 | ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr)); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8072 | else |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8073 | return ToOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8074 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8075 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8076 | ToTemplates.end()); |
| 8077 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8078 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8079 | case TemplateName::QualifiedTemplate: { |
| 8080 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8081 | auto QualifierOrErr = Import_New(QTN->getQualifier()); |
| 8082 | if (!QualifierOrErr) |
| 8083 | return QualifierOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8084 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8085 | if (ExpectedDecl ToTemplateOrErr = Import_New(From.getAsTemplateDecl())) |
| 8086 | return ToContext.getQualifiedTemplateName( |
| 8087 | *QualifierOrErr, QTN->hasTemplateKeyword(), |
| 8088 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8089 | else |
| 8090 | return ToTemplateOrErr.takeError(); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8091 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8092 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8093 | case TemplateName::DependentTemplate: { |
| 8094 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8095 | auto QualifierOrErr = Import_New(DTN->getQualifier()); |
| 8096 | if (!QualifierOrErr) |
| 8097 | return QualifierOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8098 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8099 | if (DTN->isIdentifier()) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8100 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8101 | Import(DTN->getIdentifier())); |
| 8102 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8103 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8104 | return ToContext.getDependentTemplateName(*QualifierOrErr, |
| 8105 | DTN->getOperator()); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8106 | } |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8107 | |
| 8108 | case TemplateName::SubstTemplateTemplateParm: { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8109 | SubstTemplateTemplateParmStorage *Subst = |
| 8110 | From.getAsSubstTemplateTemplateParm(); |
| 8111 | ExpectedDecl ParamOrErr = Import_New(Subst->getParameter()); |
| 8112 | if (!ParamOrErr) |
| 8113 | return ParamOrErr.takeError(); |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8114 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8115 | auto ReplacementOrErr = Import_New(Subst->getReplacement()); |
| 8116 | if (!ReplacementOrErr) |
| 8117 | return ReplacementOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8118 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8119 | return ToContext.getSubstTemplateTemplateParm( |
| 8120 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ReplacementOrErr); |
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8121 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8122 | |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8123 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 8124 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 8125 | = From.getAsSubstTemplateTemplateParmPack(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8126 | ExpectedDecl ParamOrErr = Import_New(SubstPack->getParameterPack()); |
| 8127 | if (!ParamOrErr) |
| 8128 | return ParamOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8129 | |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8130 | ASTNodeImporter Importer(*this); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8131 | auto ArgPackOrErr = |
| 8132 | Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 8133 | if (!ArgPackOrErr) |
| 8134 | return ArgPackOrErr.takeError(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8135 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8136 | return ToContext.getSubstTemplateTemplateParmPack( |
| 8137 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ArgPackOrErr); |
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8138 | } |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8139 | } |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8140 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8141 | llvm_unreachable("Invalid template name kind"); |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8142 | } |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8143 | TemplateName ASTImporter::Import(TemplateName From) { |
| 8144 | llvm::Expected<TemplateName> To = Import_New(From); |
| 8145 | if (To) |
| 8146 | return *To; |
| 8147 | else |
| 8148 | llvm::consumeError(To.takeError()); |
| 8149 | return {}; |
| 8150 | } |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8151 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8152 | Expected<SourceLocation> ASTImporter::Import_New(SourceLocation FromLoc) { |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8153 | if (FromLoc.isInvalid()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8154 | return SourceLocation{}; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8155 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8156 | SourceManager &FromSM = FromContext.getSourceManager(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8157 | bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8158 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8159 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8160 | Expected<FileID> ToFileIDOrErr = Import_New(Decomposed.first, IsBuiltin); |
| 8161 | if (!ToFileIDOrErr) |
| 8162 | return ToFileIDOrErr.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8163 | SourceManager &ToSM = ToContext.getSourceManager(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8164 | return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second); |
| 8165 | } |
| 8166 | SourceLocation ASTImporter::Import(SourceLocation From) { |
| 8167 | llvm::Expected<SourceLocation> To = Import_New(From); |
| 8168 | if (To) |
| 8169 | return *To; |
| 8170 | else |
| 8171 | llvm::consumeError(To.takeError()); |
| 8172 | return {}; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8173 | } |
| 8174 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8175 | Expected<SourceRange> ASTImporter::Import_New(SourceRange FromRange) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8176 | SourceLocation ToBegin, ToEnd; |
| 8177 | if (Error Err = importInto(ToBegin, FromRange.getBegin())) |
| 8178 | return std::move(Err); |
| 8179 | if (Error Err = importInto(ToEnd, FromRange.getEnd())) |
| 8180 | return std::move(Err); |
| 8181 | |
| 8182 | return SourceRange(ToBegin, ToEnd); |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8183 | } |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8184 | SourceRange ASTImporter::Import(SourceRange From) { |
| 8185 | llvm::Expected<SourceRange> To = Import_New(From); |
| 8186 | if (To) |
| 8187 | return *To; |
| 8188 | else |
| 8189 | llvm::consumeError(To.takeError()); |
| 8190 | return {}; |
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8191 | } |
| 8192 | |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8193 | Expected<FileID> ASTImporter::Import_New(FileID FromID, bool IsBuiltin) { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8194 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8195 | if (Pos != ImportedFileIDs.end()) |
| 8196 | return Pos->second; |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8197 | |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8198 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 8199 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 8200 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8201 | |
| 8202 | // Map the FromID to the "to" source manager. |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8203 | FileID ToID; |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8204 | if (FromSLoc.isExpansion()) { |
| 8205 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8206 | ExpectedSLoc ToSpLoc = Import_New(FromEx.getSpellingLoc()); |
| 8207 | if (!ToSpLoc) |
| 8208 | return ToSpLoc.takeError(); |
| 8209 | ExpectedSLoc ToExLocS = Import_New(FromEx.getExpansionLocStart()); |
| 8210 | if (!ToExLocS) |
| 8211 | return ToExLocS.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8212 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 8213 | SourceLocation MLoc; |
| 8214 | if (FromEx.isMacroArgExpansion()) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8215 | MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, TokenLen); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8216 | } else { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8217 | if (ExpectedSLoc ToExLocE = Import_New(FromEx.getExpansionLocEnd())) |
| 8218 | MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, TokenLen, |
| 8219 | FromEx.isExpansionTokenRange()); |
| 8220 | else |
| 8221 | return ToExLocE.takeError(); |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8222 | } |
| 8223 | ToID = ToSM.getFileID(MLoc); |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8224 | } else { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8225 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8226 | |
| 8227 | if (!IsBuiltin) { |
| 8228 | // Include location of this file. |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8229 | ExpectedSLoc ToIncludeLoc = |
| 8230 | Import_New(FromSLoc.getFile().getIncludeLoc()); |
| 8231 | if (!ToIncludeLoc) |
| 8232 | return ToIncludeLoc.takeError(); |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8233 | |
| 8234 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 8235 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 8236 | // disk again |
| 8237 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 8238 | // than mmap the files several times. |
| 8239 | const FileEntry *Entry = |
| 8240 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 8241 | // FIXME: The filename may be a virtual name that does probably not |
| 8242 | // point to a valid file and we get no Entry here. In this case try with |
| 8243 | // the memory buffer below. |
| 8244 | if (Entry) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8245 | ToID = ToSM.createFileID(Entry, *ToIncludeLoc, |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8246 | FromSLoc.getFile().getFileCharacteristic()); |
| 8247 | } |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8248 | } |
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8249 | |
| 8250 | if (ToID.isInvalid() || IsBuiltin) { |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8251 | // FIXME: We want to re-use the existing MemoryBuffer! |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8252 | bool Invalid = true; |
| 8253 | const llvm::MemoryBuffer *FromBuf = Cache->getBuffer( |
| 8254 | FromContext.getDiagnostics(), FromSM, SourceLocation{}, &Invalid); |
| 8255 | if (!FromBuf || Invalid) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8256 | // FIXME: Use a new error kind? |
| 8257 | return llvm::make_error<ImportError>(ImportError::Unknown); |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8258 | |
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8259 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 8260 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 8261 | FromBuf->getBufferIdentifier()); |
| 8262 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 8263 | FromSLoc.getFile().getFileCharacteristic()); |
| 8264 | } |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8265 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8266 | |
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8267 | assert(ToID.isValid() && "Unexpected invalid fileID was created."); |
| 8268 | |
| Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 8269 | ImportedFileIDs[FromID] = ToID; |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8270 | return ToID; |
| 8271 | } |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8272 | FileID ASTImporter::Import(FileID From, bool IsBuiltin) { |
| 8273 | llvm::Expected<FileID> To = Import_New(From, IsBuiltin); |
| 8274 | if (To) |
| 8275 | return *To; |
| 8276 | else |
| 8277 | llvm::consumeError(To.takeError()); |
| 8278 | return {}; |
| 8279 | } |
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8280 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8281 | Expected<CXXCtorInitializer *> |
| 8282 | ASTImporter::Import_New(CXXCtorInitializer *From) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8283 | ExpectedExpr ToExprOrErr = Import_New(From->getInit()); |
| 8284 | if (!ToExprOrErr) |
| 8285 | return ToExprOrErr.takeError(); |
| 8286 | |
| 8287 | auto LParenLocOrErr = Import_New(From->getLParenLoc()); |
| 8288 | if (!LParenLocOrErr) |
| 8289 | return LParenLocOrErr.takeError(); |
| 8290 | |
| 8291 | auto RParenLocOrErr = Import_New(From->getRParenLoc()); |
| 8292 | if (!RParenLocOrErr) |
| 8293 | return RParenLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8294 | |
| 8295 | if (From->isBaseInitializer()) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8296 | auto ToTInfoOrErr = Import_New(From->getTypeSourceInfo()); |
| 8297 | if (!ToTInfoOrErr) |
| 8298 | return ToTInfoOrErr.takeError(); |
| 8299 | |
| 8300 | SourceLocation EllipsisLoc; |
| 8301 | if (From->isPackExpansion()) |
| 8302 | if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc())) |
| 8303 | return std::move(Err); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8304 | |
| 8305 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8306 | ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr, |
| 8307 | *ToExprOrErr, *RParenLocOrErr, EllipsisLoc); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8308 | } else if (From->isMemberInitializer()) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8309 | ExpectedDecl ToFieldOrErr = Import_New(From->getMember()); |
| 8310 | if (!ToFieldOrErr) |
| 8311 | return ToFieldOrErr.takeError(); |
| 8312 | |
| 8313 | auto MemberLocOrErr = Import_New(From->getMemberLocation()); |
| 8314 | if (!MemberLocOrErr) |
| 8315 | return MemberLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8316 | |
| 8317 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8318 | ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr, |
| 8319 | *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8320 | } else if (From->isIndirectMemberInitializer()) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8321 | ExpectedDecl ToIFieldOrErr = Import_New(From->getIndirectMember()); |
| 8322 | if (!ToIFieldOrErr) |
| 8323 | return ToIFieldOrErr.takeError(); |
| 8324 | |
| 8325 | auto MemberLocOrErr = Import_New(From->getMemberLocation()); |
| 8326 | if (!MemberLocOrErr) |
| 8327 | return MemberLocOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8328 | |
| 8329 | return new (ToContext) CXXCtorInitializer( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8330 | ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr), |
| 8331 | *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8332 | } else if (From->isDelegatingInitializer()) { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8333 | auto ToTInfoOrErr = Import_New(From->getTypeSourceInfo()); |
| 8334 | if (!ToTInfoOrErr) |
| 8335 | return ToTInfoOrErr.takeError(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8336 | |
| 8337 | return new (ToContext) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8338 | CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr, |
| 8339 | *ToExprOrErr, *RParenLocOrErr); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8340 | } else { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8341 | // FIXME: assert? |
| 8342 | return make_error<ImportError>(); |
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8343 | } |
| Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8344 | } |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8345 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
| 8346 | llvm::Expected<CXXCtorInitializer *> To = Import_New(From); |
| 8347 | if (To) |
| 8348 | return *To; |
| 8349 | else |
| 8350 | llvm::consumeError(To.takeError()); |
| 8351 | return nullptr; |
| 8352 | } |
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8353 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8354 | Expected<CXXBaseSpecifier *> |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8355 | ASTImporter::Import_New(const CXXBaseSpecifier *BaseSpec) { |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8356 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 8357 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 8358 | return Pos->second; |
| 8359 | |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8360 | Expected<SourceRange> ToSourceRange = Import_New(BaseSpec->getSourceRange()); |
| 8361 | if (!ToSourceRange) |
| 8362 | return ToSourceRange.takeError(); |
| 8363 | Expected<TypeSourceInfo *> ToTSI = Import_New(BaseSpec->getTypeSourceInfo()); |
| 8364 | if (!ToTSI) |
| 8365 | return ToTSI.takeError(); |
| 8366 | ExpectedSLoc ToEllipsisLoc = Import_New(BaseSpec->getEllipsisLoc()); |
| 8367 | if (!ToEllipsisLoc) |
| 8368 | return ToEllipsisLoc.takeError(); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8369 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8370 | *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 8371 | BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc); |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8372 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 8373 | return Imported; |
| 8374 | } |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8375 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *From) { |
| 8376 | llvm::Expected<CXXBaseSpecifier *> To = Import_New(From); |
| 8377 | if (To) |
| 8378 | return *To; |
| 8379 | else |
| 8380 | llvm::consumeError(To.takeError()); |
| 8381 | return nullptr; |
| 8382 | } |
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8383 | |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8384 | Error ASTImporter::ImportDefinition_New(Decl *From) { |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8385 | Decl *To = Import(From); |
| 8386 | if (!To) |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8387 | return llvm::make_error<ImportError>(); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8388 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8389 | auto *FromDC = cast<DeclContext>(From); |
| 8390 | ASTNodeImporter Importer(*this); |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8391 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8392 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
| 8393 | if (!ToRecord->getDefinition()) { |
| 8394 | return Importer.ImportDefinition( |
| 8395 | cast<RecordDecl>(FromDC), ToRecord, |
| 8396 | ASTNodeImporter::IDK_Everything); |
| Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8397 | } |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8398 | } |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8399 | |
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8400 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
| 8401 | if (!ToEnum->getDefinition()) { |
| 8402 | return Importer.ImportDefinition( |
| 8403 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); |
| 8404 | } |
| 8405 | } |
| 8406 | |
| 8407 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
| 8408 | if (!ToIFace->getDefinition()) { |
| 8409 | return Importer.ImportDefinition( |
| 8410 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
| 8411 | ASTNodeImporter::IDK_Everything); |
| 8412 | } |
| 8413 | } |
| 8414 | |
| 8415 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
| 8416 | if (!ToProto->getDefinition()) { |
| 8417 | return Importer.ImportDefinition( |
| 8418 | cast<ObjCProtocolDecl>(FromDC), ToProto, |
| 8419 | ASTNodeImporter::IDK_Everything); |
| 8420 | } |
| 8421 | } |
| 8422 | |
| 8423 | return Importer.ImportDeclContext(FromDC, true); |
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8424 | } |
| 8425 | |
| 8426 | void ASTImporter::ImportDefinition(Decl *From) { |
| 8427 | Error Err = ImportDefinition_New(From); |
| 8428 | llvm::consumeError(std::move(Err)); |
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8429 | } |
| 8430 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8431 | Expected<DeclarationName> ASTImporter::Import_New(DeclarationName FromName) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8432 | if (!FromName) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8433 | return DeclarationName{}; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8434 | |
| 8435 | switch (FromName.getNameKind()) { |
| 8436 | case DeclarationName::Identifier: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8437 | return DeclarationName(Import(FromName.getAsIdentifierInfo())); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8438 | |
| 8439 | case DeclarationName::ObjCZeroArgSelector: |
| 8440 | case DeclarationName::ObjCOneArgSelector: |
| 8441 | case DeclarationName::ObjCMultiArgSelector: |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8442 | if (auto ToSelOrErr = Import_New(FromName.getObjCSelector())) |
| 8443 | return DeclarationName(*ToSelOrErr); |
| 8444 | else |
| 8445 | return ToSelOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8446 | |
| 8447 | case DeclarationName::CXXConstructorName: { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8448 | if (auto ToTyOrErr = Import_New(FromName.getCXXNameType())) |
| 8449 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 8450 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8451 | else |
| 8452 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8453 | } |
| 8454 | |
| 8455 | case DeclarationName::CXXDestructorName: { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8456 | if (auto ToTyOrErr = Import_New(FromName.getCXXNameType())) |
| 8457 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 8458 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8459 | else |
| 8460 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8461 | } |
| 8462 | |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8463 | case DeclarationName::CXXDeductionGuideName: { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8464 | if (auto ToTemplateOrErr = |
| 8465 | Import_New(FromName.getCXXDeductionGuideTemplate())) |
| 8466 | return ToContext.DeclarationNames.getCXXDeductionGuideName( |
| 8467 | cast<TemplateDecl>(*ToTemplateOrErr)); |
| 8468 | else |
| 8469 | return ToTemplateOrErr.takeError(); |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8470 | } |
| 8471 | |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8472 | case DeclarationName::CXXConversionFunctionName: { |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8473 | if (auto ToTyOrErr = Import_New(FromName.getCXXNameType())) |
| 8474 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 8475 | ToContext.getCanonicalType(*ToTyOrErr)); |
| 8476 | else |
| 8477 | return ToTyOrErr.takeError(); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8478 | } |
| 8479 | |
| 8480 | case DeclarationName::CXXOperatorName: |
| 8481 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 8482 | FromName.getCXXOverloadedOperator()); |
| 8483 | |
| 8484 | case DeclarationName::CXXLiteralOperatorName: |
| 8485 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8486 | Import(FromName.getCXXLiteralIdentifier())); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8487 | |
| 8488 | case DeclarationName::CXXUsingDirective: |
| 8489 | // FIXME: STATICS! |
| 8490 | return DeclarationName::getUsingDirectiveName(); |
| 8491 | } |
| 8492 | |
| David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 8493 | llvm_unreachable("Invalid DeclarationName Kind!"); |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8494 | } |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8495 | DeclarationName ASTImporter::Import(DeclarationName From) { |
| 8496 | llvm::Expected<DeclarationName> To = Import_New(From); |
| 8497 | if (To) |
| 8498 | return *To; |
| 8499 | else |
| 8500 | llvm::consumeError(To.takeError()); |
| 8501 | return {}; |
| 8502 | } |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8503 | |
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8504 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8505 | if (!FromId) |
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8506 | return nullptr; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8507 | |
| Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 8508 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 8509 | |
| 8510 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 8511 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 8512 | |
| 8513 | return ToId; |
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8514 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8515 | |
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8516 | Expected<Selector> ASTImporter::Import_New(Selector FromSel) { |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8517 | if (FromSel.isNull()) |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8518 | return Selector{}; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8519 | |
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8520 | SmallVector<IdentifierInfo *, 4> Idents; |
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8521 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 8522 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 8523 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 8524 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 8525 | } |
| 8526 | |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8527 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 8528 | DeclContext *DC, |
| 8529 | unsigned IDNS, |
| 8530 | NamedDecl **Decls, |
| 8531 | unsigned NumDecls) { |
| 8532 | return Name; |
| 8533 | } |
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8534 | Selector ASTImporter::Import(Selector From) { |
| 8535 | llvm::Expected<Selector> To = Import_New(From); |
| 8536 | if (To) |
| 8537 | return *To; |
| 8538 | else |
| 8539 | llvm::consumeError(To.takeError()); |
| 8540 | return {}; |
| 8541 | } |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8542 | |
| 8543 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
| Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8544 | if (LastDiagFromFrom) |
| 8545 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8546 | FromContext.getDiagnostics()); |
| 8547 | LastDiagFromFrom = false; |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8548 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8549 | } |
| 8550 | |
| 8551 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
| Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8552 | if (!LastDiagFromFrom) |
| 8553 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 8554 | ToContext.getDiagnostics()); |
| 8555 | LastDiagFromFrom = true; |
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8556 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8557 | } |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8558 | |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8559 | void ASTImporter::CompleteDecl (Decl *D) { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8560 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8561 | if (!ID->getDefinition()) |
| 8562 | ID->startDefinition(); |
| 8563 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8564 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8565 | if (!PD->getDefinition()) |
| 8566 | PD->startDefinition(); |
| 8567 | } |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8568 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8569 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 8570 | TD->startDefinition(); |
| 8571 | TD->setCompleteDefinition(true); |
| 8572 | } |
| 8573 | } |
| 8574 | else { |
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8575 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8576 | } |
| 8577 | } |
| 8578 | |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8579 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 8580 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 8581 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 8582 | "Try to import an already imported Decl"); |
| 8583 | if (Pos != ImportedDecls.end()) |
| 8584 | return Pos->second; |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8585 | ImportedDecls[From] = To; |
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 8586 | // This mapping should be maintained only in this function. Therefore do not |
| 8587 | // check for additional consistency. |
| 8588 | ImportedFromDecls[To] = From; |
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8589 | return To; |
| Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 8590 | } |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8591 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8592 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 8593 | bool Complain) { |
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8594 | llvm::DenseMap<const Type *, const Type *>::iterator Pos = |
| 8595 | ImportedTypes.find(From.getTypePtr()); |
| 8596 | if (Pos != ImportedTypes.end()) { |
| 8597 | if (ExpectedType ToFromOrErr = Import_New(From)) { |
| 8598 | if (ToContext.hasSameType(*ToFromOrErr, To)) |
| 8599 | return true; |
| 8600 | } else { |
| 8601 | llvm::consumeError(ToFromOrErr.takeError()); |
| 8602 | } |
| 8603 | } |
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 8604 | |
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8605 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8606 | getStructuralEquivalenceKind(*this), false, |
| 8607 | Complain); |
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 8608 | return Ctx.IsEquivalent(From, To); |
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8609 | } |