| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1 | //===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===// | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 2 | // | 
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | 
|  | 4 | // See https://llvm.org/LICENSE.txt for license information. | 
|  | 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6 | // | 
|  | 7 | //===----------------------------------------------------------------------===// | 
|  | 8 | // | 
|  | 9 | //  This file defines the ASTImporter class which imports AST nodes from one | 
|  | 10 | //  context into another context. | 
|  | 11 | // | 
|  | 12 | //===----------------------------------------------------------------------===// | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 13 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTImporter.h" | 
| Ilya Biryukov | abc744d | 2019-07-18 15:43:26 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTImporterSharedState.h" | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTDiagnostic.h" | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTStructuralEquivalence.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 19 | #include "clang/AST/Attr.h" | 
|  | 20 | #include "clang/AST/Decl.h" | 
|  | 21 | #include "clang/AST/DeclAccessPair.h" | 
|  | 22 | #include "clang/AST/DeclBase.h" | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclCXX.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclFriend.h" | 
|  | 25 | #include "clang/AST/DeclGroup.h" | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 26 | #include "clang/AST/DeclObjC.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 27 | #include "clang/AST/DeclTemplate.h" | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 28 | #include "clang/AST/DeclVisitor.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 29 | #include "clang/AST/DeclarationName.h" | 
|  | 30 | #include "clang/AST/Expr.h" | 
|  | 31 | #include "clang/AST/ExprCXX.h" | 
|  | 32 | #include "clang/AST/ExprObjC.h" | 
|  | 33 | #include "clang/AST/ExternalASTSource.h" | 
|  | 34 | #include "clang/AST/LambdaCapture.h" | 
|  | 35 | #include "clang/AST/NestedNameSpecifier.h" | 
|  | 36 | #include "clang/AST/OperationKinds.h" | 
|  | 37 | #include "clang/AST/Stmt.h" | 
|  | 38 | #include "clang/AST/StmtCXX.h" | 
|  | 39 | #include "clang/AST/StmtObjC.h" | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 40 | #include "clang/AST/StmtVisitor.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 41 | #include "clang/AST/TemplateBase.h" | 
|  | 42 | #include "clang/AST/TemplateName.h" | 
|  | 43 | #include "clang/AST/Type.h" | 
|  | 44 | #include "clang/AST/TypeLoc.h" | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 45 | #include "clang/AST/TypeVisitor.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 46 | #include "clang/AST/UnresolvedSet.h" | 
|  | 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" | 
| Balazs Keri | d2c5761 | 2019-07-18 15:23:10 +0000 | [diff] [blame] | 60 | #include "llvm/ADT/ScopeExit.h" | 
| Ilya Biryukov | abc744d | 2019-07-18 15:43:26 +0000 | [diff] [blame] | 61 | #include "llvm/ADT/STLExtras.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 62 | #include "llvm/ADT/SmallVector.h" | 
|  | 63 | #include "llvm/Support/Casting.h" | 
|  | 64 | #include "llvm/Support/ErrorHandling.h" | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 65 | #include "llvm/Support/MemoryBuffer.h" | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 66 | #include <algorithm> | 
|  | 67 | #include <cassert> | 
|  | 68 | #include <cstddef> | 
|  | 69 | #include <memory> | 
|  | 70 | #include <type_traits> | 
|  | 71 | #include <utility> | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 72 |  | 
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 73 | namespace clang { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 74 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 75 | using llvm::make_error; | 
|  | 76 | using llvm::Error; | 
|  | 77 | using llvm::Expected; | 
|  | 78 | using ExpectedType = llvm::Expected<QualType>; | 
|  | 79 | using ExpectedStmt = llvm::Expected<Stmt *>; | 
|  | 80 | using ExpectedExpr = llvm::Expected<Expr *>; | 
|  | 81 | using ExpectedDecl = llvm::Expected<Decl *>; | 
|  | 82 | using ExpectedSLoc = llvm::Expected<SourceLocation>; | 
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 83 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 84 | std::string ImportError::toString() const { | 
|  | 85 | // FIXME: Improve error texts. | 
|  | 86 | switch (Error) { | 
|  | 87 | case NameConflict: | 
|  | 88 | return "NameConflict"; | 
|  | 89 | case UnsupportedConstruct: | 
|  | 90 | return "UnsupportedConstruct"; | 
|  | 91 | case Unknown: | 
|  | 92 | return "Unknown error"; | 
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 93 | } | 
| Balazs Keri | 2a13d66 | 2018-10-19 15:16:51 +0000 | [diff] [blame] | 94 | llvm_unreachable("Invalid error code."); | 
|  | 95 | return "Invalid error code."; | 
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 96 | } | 
|  | 97 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 98 | void ImportError::log(raw_ostream &OS) const { | 
|  | 99 | OS << toString(); | 
|  | 100 | } | 
|  | 101 |  | 
|  | 102 | std::error_code ImportError::convertToErrorCode() const { | 
|  | 103 | llvm_unreachable("Function not implemented."); | 
|  | 104 | } | 
|  | 105 |  | 
|  | 106 | char ImportError::ID; | 
|  | 107 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 108 | template <class T> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 109 | SmallVector<Decl *, 2> | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 110 | getCanonicalForwardRedeclChain(Redeclarable<T>* D) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 111 | SmallVector<Decl *, 2> Redecls; | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 112 | for (auto *R : D->getFirstDecl()->redecls()) { | 
|  | 113 | if (R != D->getFirstDecl()) | 
|  | 114 | Redecls.push_back(R); | 
|  | 115 | } | 
|  | 116 | Redecls.push_back(D->getFirstDecl()); | 
|  | 117 | std::reverse(Redecls.begin(), Redecls.end()); | 
|  | 118 | return Redecls; | 
|  | 119 | } | 
|  | 120 |  | 
|  | 121 | SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D) { | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 122 | if (auto *FD = dyn_cast<FunctionDecl>(D)) | 
|  | 123 | return getCanonicalForwardRedeclChain<FunctionDecl>(FD); | 
|  | 124 | if (auto *VD = dyn_cast<VarDecl>(D)) | 
|  | 125 | return getCanonicalForwardRedeclChain<VarDecl>(VD); | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 126 | if (auto *TD = dyn_cast<TagDecl>(D)) | 
|  | 127 | return getCanonicalForwardRedeclChain<TagDecl>(TD); | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 128 | llvm_unreachable("Bad declaration kind"); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 129 | } | 
|  | 130 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 131 | void updateFlags(const Decl *From, Decl *To) { | 
|  | 132 | // Check if some flags or attrs are new in 'From' and copy into 'To'. | 
|  | 133 | // FIXME: Other flags or attrs? | 
|  | 134 | if (From->isUsed(false) && !To->isUsed(false)) | 
|  | 135 | To->setIsUsed(); | 
|  | 136 | } | 
|  | 137 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 138 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>, | 
|  | 139 | public DeclVisitor<ASTNodeImporter, ExpectedDecl>, | 
|  | 140 | public StmtVisitor<ASTNodeImporter, ExpectedStmt> { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 141 | ASTImporter &Importer; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 142 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 143 | // Use this instead of Importer.importInto . | 
|  | 144 | template <typename ImportT> | 
|  | 145 | LLVM_NODISCARD Error importInto(ImportT &To, const ImportT &From) { | 
|  | 146 | return Importer.importInto(To, From); | 
|  | 147 | } | 
|  | 148 |  | 
|  | 149 | // Use this to import pointers of specific type. | 
|  | 150 | template <typename ImportT> | 
|  | 151 | LLVM_NODISCARD Error importInto(ImportT *&To, ImportT *From) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 152 | auto ToOrErr = Importer.Import(From); | 
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 153 | if (ToOrErr) | 
|  | 154 | To = cast_or_null<ImportT>(*ToOrErr); | 
|  | 155 | return ToOrErr.takeError(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 156 | } | 
|  | 157 |  | 
|  | 158 | // Call the import function of ASTImporter for a baseclass of type `T` and | 
|  | 159 | // cast the return value to `T`. | 
|  | 160 | template <typename T> | 
|  | 161 | Expected<T *> import(T *From) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 162 | auto ToOrErr = Importer.Import(From); | 
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 163 | if (!ToOrErr) | 
|  | 164 | return ToOrErr.takeError(); | 
|  | 165 | return cast_or_null<T>(*ToOrErr); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 166 | } | 
|  | 167 |  | 
|  | 168 | template <typename T> | 
|  | 169 | Expected<T *> import(const T *From) { | 
|  | 170 | return import(const_cast<T *>(From)); | 
|  | 171 | } | 
|  | 172 |  | 
|  | 173 | // Call the import function of ASTImporter for type `T`. | 
|  | 174 | template <typename T> | 
|  | 175 | Expected<T> import(const T &From) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 176 | return Importer.Import(From); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 177 | } | 
|  | 178 |  | 
| Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 179 | // Import an Optional<T> by importing the contained T, if any. | 
|  | 180 | template<typename T> | 
|  | 181 | Expected<Optional<T>> import(Optional<T> From) { | 
|  | 182 | if (!From) | 
|  | 183 | return Optional<T>(); | 
|  | 184 | return import(*From); | 
|  | 185 | } | 
|  | 186 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 187 | template <class T> | 
|  | 188 | Expected<std::tuple<T>> | 
|  | 189 | importSeq(const T &From) { | 
|  | 190 | Expected<T> ToOrErr = import(From); | 
|  | 191 | if (!ToOrErr) | 
|  | 192 | return ToOrErr.takeError(); | 
|  | 193 | return std::make_tuple<T>(std::move(*ToOrErr)); | 
|  | 194 | } | 
|  | 195 |  | 
|  | 196 | // Import multiple objects with a single function call. | 
|  | 197 | // This should work for every type for which a variant of `import` exists. | 
|  | 198 | // The arguments are processed from left to right and import is stopped on | 
|  | 199 | // first error. | 
|  | 200 | template <class THead, class... TTail> | 
|  | 201 | Expected<std::tuple<THead, TTail...>> | 
|  | 202 | importSeq(const THead &FromHead, const TTail &...FromTail) { | 
|  | 203 | Expected<std::tuple<THead>> ToHeadOrErr = importSeq(FromHead); | 
|  | 204 | if (!ToHeadOrErr) | 
|  | 205 | return ToHeadOrErr.takeError(); | 
|  | 206 | Expected<std::tuple<TTail...>> ToTailOrErr = importSeq(FromTail...); | 
|  | 207 | if (!ToTailOrErr) | 
|  | 208 | return ToTailOrErr.takeError(); | 
|  | 209 | return std::tuple_cat(*ToHeadOrErr, *ToTailOrErr); | 
|  | 210 | } | 
|  | 211 |  | 
|  | 212 | // Wrapper for an overload set. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 213 | template <typename ToDeclT> struct CallOverloadedCreateFun { | 
|  | 214 | template <typename... Args> | 
|  | 215 | auto operator()(Args &&... args) | 
|  | 216 | -> decltype(ToDeclT::Create(std::forward<Args>(args)...)) { | 
|  | 217 | return ToDeclT::Create(std::forward<Args>(args)...); | 
|  | 218 | } | 
|  | 219 | }; | 
|  | 220 |  | 
|  | 221 | // Always use these functions to create a Decl during import. There are | 
|  | 222 | // certain tasks which must be done after the Decl was created, e.g. we | 
|  | 223 | // must immediately register that as an imported Decl.  The parameter `ToD` | 
|  | 224 | // will be set to the newly created Decl or if had been imported before | 
|  | 225 | // then to the already imported Decl.  Returns a bool value set to true if | 
|  | 226 | // the `FromD` had been imported before. | 
|  | 227 | template <typename ToDeclT, typename FromDeclT, typename... Args> | 
|  | 228 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, | 
|  | 229 | Args &&... args) { | 
|  | 230 | // There may be several overloads of ToDeclT::Create. We must make sure | 
|  | 231 | // to call the one which would be chosen by the arguments, thus we use a | 
|  | 232 | // wrapper for the overload set. | 
|  | 233 | CallOverloadedCreateFun<ToDeclT> OC; | 
|  | 234 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, | 
|  | 235 | std::forward<Args>(args)...); | 
|  | 236 | } | 
|  | 237 | // Use this overload if a special Type is needed to be created.  E.g if we | 
|  | 238 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` | 
|  | 239 | // then: | 
|  | 240 | // TypedefNameDecl *ToTypedef; | 
|  | 241 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); | 
|  | 242 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, | 
|  | 243 | typename... Args> | 
|  | 244 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, | 
|  | 245 | Args &&... args) { | 
|  | 246 | CallOverloadedCreateFun<NewDeclT> OC; | 
|  | 247 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, | 
|  | 248 | std::forward<Args>(args)...); | 
|  | 249 | } | 
|  | 250 | // Use this version if a special create function must be | 
|  | 251 | // used, e.g. CXXRecordDecl::CreateLambda . | 
|  | 252 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, | 
|  | 253 | typename... Args> | 
|  | 254 | LLVM_NODISCARD bool | 
|  | 255 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, | 
|  | 256 | FromDeclT *FromD, Args &&... args) { | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 257 | if (Importer.getImportDeclErrorIfAny(FromD)) { | 
|  | 258 | ToD = nullptr; | 
|  | 259 | return true; // Already imported but with error. | 
|  | 260 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 261 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); | 
|  | 262 | if (ToD) | 
|  | 263 | return true; // Already imported. | 
|  | 264 | ToD = CreateFun(std::forward<Args>(args)...); | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 265 | // Keep track of imported Decls. | 
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 266 | Importer.RegisterImportedDecl(FromD, ToD); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 267 | InitializeImportedDecl(FromD, ToD); | 
|  | 268 | return false; // A new Decl is created. | 
|  | 269 | } | 
|  | 270 |  | 
|  | 271 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 272 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; | 
|  | 273 | if (FromD->hasAttrs()) | 
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 274 | for (const Attr *FromAttr : FromD->getAttrs()) { | 
|  | 275 | // FIXME: Return of the error here is not possible until store of | 
|  | 276 | // import errors is implemented. | 
|  | 277 | auto ToAttrOrErr = import(FromAttr); | 
|  | 278 | if (ToAttrOrErr) | 
|  | 279 | ToD->addAttr(*ToAttrOrErr); | 
|  | 280 | else | 
|  | 281 | llvm::consumeError(ToAttrOrErr.takeError()); | 
|  | 282 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 283 | if (FromD->isUsed()) | 
|  | 284 | ToD->setIsUsed(); | 
|  | 285 | if (FromD->isImplicit()) | 
|  | 286 | ToD->setImplicit(); | 
|  | 287 | } | 
|  | 288 |  | 
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 289 | // Check if we have found an existing definition.  Returns with that | 
|  | 290 | // definition if yes, otherwise returns null. | 
|  | 291 | Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) { | 
|  | 292 | const FunctionDecl *Definition = nullptr; | 
|  | 293 | if (D->doesThisDeclarationHaveABody() && | 
|  | 294 | FoundFunction->hasBody(Definition)) | 
|  | 295 | return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition)); | 
|  | 296 | return nullptr; | 
|  | 297 | } | 
|  | 298 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 299 | public: | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 300 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} | 
| Gabor Marton | 344b099 | 2018-05-16 11:48:11 +0000 | [diff] [blame] | 301 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 302 | using TypeVisitor<ASTNodeImporter, ExpectedType>::Visit; | 
|  | 303 | using DeclVisitor<ASTNodeImporter, ExpectedDecl>::Visit; | 
|  | 304 | using StmtVisitor<ASTNodeImporter, ExpectedStmt>::Visit; | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 305 |  | 
|  | 306 | // Importing types | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 307 | ExpectedType VisitType(const Type *T); | 
|  | 308 | ExpectedType VisitAtomicType(const AtomicType *T); | 
|  | 309 | ExpectedType VisitBuiltinType(const BuiltinType *T); | 
|  | 310 | ExpectedType VisitDecayedType(const DecayedType *T); | 
|  | 311 | ExpectedType VisitComplexType(const ComplexType *T); | 
|  | 312 | ExpectedType VisitPointerType(const PointerType *T); | 
|  | 313 | ExpectedType VisitBlockPointerType(const BlockPointerType *T); | 
|  | 314 | ExpectedType VisitLValueReferenceType(const LValueReferenceType *T); | 
|  | 315 | ExpectedType VisitRValueReferenceType(const RValueReferenceType *T); | 
|  | 316 | ExpectedType VisitMemberPointerType(const MemberPointerType *T); | 
|  | 317 | ExpectedType VisitConstantArrayType(const ConstantArrayType *T); | 
|  | 318 | ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T); | 
|  | 319 | ExpectedType VisitVariableArrayType(const VariableArrayType *T); | 
|  | 320 | ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 321 | // FIXME: DependentSizedExtVectorType | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 322 | ExpectedType VisitVectorType(const VectorType *T); | 
|  | 323 | ExpectedType VisitExtVectorType(const ExtVectorType *T); | 
|  | 324 | ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T); | 
|  | 325 | ExpectedType VisitFunctionProtoType(const FunctionProtoType *T); | 
|  | 326 | ExpectedType VisitUnresolvedUsingType(const UnresolvedUsingType *T); | 
|  | 327 | ExpectedType VisitParenType(const ParenType *T); | 
|  | 328 | ExpectedType VisitTypedefType(const TypedefType *T); | 
|  | 329 | ExpectedType VisitTypeOfExprType(const TypeOfExprType *T); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 330 | // FIXME: DependentTypeOfExprType | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 331 | ExpectedType VisitTypeOfType(const TypeOfType *T); | 
|  | 332 | ExpectedType VisitDecltypeType(const DecltypeType *T); | 
|  | 333 | ExpectedType VisitUnaryTransformType(const UnaryTransformType *T); | 
|  | 334 | ExpectedType VisitAutoType(const AutoType *T); | 
|  | 335 | ExpectedType VisitInjectedClassNameType(const InjectedClassNameType *T); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 336 | // FIXME: DependentDecltypeType | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 337 | ExpectedType VisitRecordType(const RecordType *T); | 
|  | 338 | ExpectedType VisitEnumType(const EnumType *T); | 
|  | 339 | ExpectedType VisitAttributedType(const AttributedType *T); | 
|  | 340 | ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T); | 
|  | 341 | ExpectedType VisitSubstTemplateTypeParmType( | 
|  | 342 | const SubstTemplateTypeParmType *T); | 
|  | 343 | ExpectedType VisitTemplateSpecializationType( | 
|  | 344 | const TemplateSpecializationType *T); | 
|  | 345 | ExpectedType VisitElaboratedType(const ElaboratedType *T); | 
|  | 346 | ExpectedType VisitDependentNameType(const DependentNameType *T); | 
|  | 347 | ExpectedType VisitPackExpansionType(const PackExpansionType *T); | 
|  | 348 | ExpectedType VisitDependentTemplateSpecializationType( | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 349 | const DependentTemplateSpecializationType *T); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 350 | ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T); | 
|  | 351 | ExpectedType VisitObjCObjectType(const ObjCObjectType *T); | 
|  | 352 | ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); | 
| Rafael Stahl | df55620 | 2018-05-29 08:12:15 +0000 | [diff] [blame] | 353 |  | 
|  | 354 | // Importing declarations | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 355 | Error ImportDeclParts( | 
|  | 356 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, | 
|  | 357 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc); | 
|  | 358 | Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); | 
|  | 359 | Error ImportDeclarationNameLoc( | 
|  | 360 | const DeclarationNameInfo &From, DeclarationNameInfo &To); | 
|  | 361 | Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); | 
|  | 362 | Error ImportDeclContext( | 
|  | 363 | Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC); | 
|  | 364 | Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 365 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 366 | Expected<CXXCastPath> ImportCastPath(CastExpr *E); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 367 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 368 | using Designator = DesignatedInitExpr::Designator; | 
|  | 369 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 370 | /// What we should import from the definition. | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 371 | enum ImportDefinitionKind { | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 372 | /// Import the default subset of the definition, which might be | 
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 373 | /// nothing (if minimal import is set) or might be everything (if minimal | 
|  | 374 | /// import is not set). | 
|  | 375 | IDK_Default, | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 376 | /// Import everything. | 
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 377 | IDK_Everything, | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 378 | /// Import only the bare bones needed to establish a valid | 
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 379 | /// DeclContext. | 
|  | 380 | IDK_Basic | 
|  | 381 | }; | 
|  | 382 |  | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 383 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { | 
|  | 384 | return IDK == IDK_Everything || | 
|  | 385 | (IDK == IDK_Default && !Importer.isMinimalImport()); | 
|  | 386 | } | 
|  | 387 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 388 | Error ImportInitializer(VarDecl *From, VarDecl *To); | 
|  | 389 | Error ImportDefinition( | 
|  | 390 | RecordDecl *From, RecordDecl *To, | 
|  | 391 | ImportDefinitionKind Kind = IDK_Default); | 
|  | 392 | Error ImportDefinition( | 
|  | 393 | EnumDecl *From, EnumDecl *To, | 
|  | 394 | ImportDefinitionKind Kind = IDK_Default); | 
|  | 395 | Error ImportDefinition( | 
|  | 396 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, | 
|  | 397 | ImportDefinitionKind Kind = IDK_Default); | 
|  | 398 | Error ImportDefinition( | 
|  | 399 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, | 
|  | 400 | ImportDefinitionKind Kind = IDK_Default); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 401 | Error ImportTemplateArguments( | 
|  | 402 | const TemplateArgument *FromArgs, unsigned NumFromArgs, | 
|  | 403 | SmallVectorImpl<TemplateArgument> &ToArgs); | 
|  | 404 | Expected<TemplateArgument> | 
|  | 405 | ImportTemplateArgument(const TemplateArgument &From); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 406 |  | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 407 | template <typename InContainerTy> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 408 | Error ImportTemplateArgumentListInfo( | 
|  | 409 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 410 |  | 
|  | 411 | template<typename InContainerTy> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 412 | Error ImportTemplateArgumentListInfo( | 
|  | 413 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, | 
|  | 414 | const InContainerTy &Container, TemplateArgumentListInfo &Result); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 415 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 416 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 417 | using FunctionTemplateAndArgsTy = | 
|  | 418 | std::tuple<FunctionTemplateDecl *, TemplateArgsTy>; | 
|  | 419 | Expected<FunctionTemplateAndArgsTy> | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 420 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( | 
|  | 421 | FunctionDecl *FromFD); | 
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 422 | Error ImportTemplateParameterLists(const DeclaratorDecl *FromD, | 
|  | 423 | DeclaratorDecl *ToD); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 424 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 425 | Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 426 |  | 
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 427 | Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD); | 
|  | 428 |  | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 429 | template <typename T> | 
|  | 430 | bool hasSameVisibilityContext(T *Found, T *From); | 
|  | 431 |  | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 432 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 433 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, | 
|  | 434 | bool Complain = true); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 435 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, | 
|  | 436 | bool Complain = true); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 437 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); | 
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 438 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 439 | bool IsStructuralMatch(FunctionTemplateDecl *From, | 
|  | 440 | FunctionTemplateDecl *To); | 
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 441 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 442 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 443 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 444 | ExpectedDecl VisitDecl(Decl *D); | 
|  | 445 | ExpectedDecl VisitImportDecl(ImportDecl *D); | 
|  | 446 | ExpectedDecl VisitEmptyDecl(EmptyDecl *D); | 
|  | 447 | ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); | 
|  | 448 | ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); | 
|  | 449 | ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); | 
|  | 450 | ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); | 
|  | 451 | ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); | 
|  | 452 | ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); | 
|  | 453 | ExpectedDecl VisitTypedefDecl(TypedefDecl *D); | 
|  | 454 | ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D); | 
|  | 455 | ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); | 
|  | 456 | ExpectedDecl VisitLabelDecl(LabelDecl *D); | 
|  | 457 | ExpectedDecl VisitEnumDecl(EnumDecl *D); | 
|  | 458 | ExpectedDecl VisitRecordDecl(RecordDecl *D); | 
|  | 459 | ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D); | 
|  | 460 | ExpectedDecl VisitFunctionDecl(FunctionDecl *D); | 
|  | 461 | ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D); | 
|  | 462 | ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D); | 
|  | 463 | ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D); | 
|  | 464 | ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D); | 
|  | 465 | ExpectedDecl VisitFieldDecl(FieldDecl *D); | 
|  | 466 | ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D); | 
|  | 467 | ExpectedDecl VisitFriendDecl(FriendDecl *D); | 
|  | 468 | ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D); | 
|  | 469 | ExpectedDecl VisitVarDecl(VarDecl *D); | 
|  | 470 | ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D); | 
|  | 471 | ExpectedDecl VisitParmVarDecl(ParmVarDecl *D); | 
|  | 472 | ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D); | 
|  | 473 | ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); | 
|  | 474 | ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D); | 
|  | 475 | ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D); | 
|  | 476 | ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D); | 
|  | 477 | ExpectedDecl VisitUsingDecl(UsingDecl *D); | 
|  | 478 | ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D); | 
|  | 479 | ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D); | 
|  | 480 | ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); | 
|  | 481 | ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 482 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 483 | Expected<ObjCTypeParamList *> | 
|  | 484 | ImportObjCTypeParamList(ObjCTypeParamList *list); | 
|  | 485 |  | 
|  | 486 | ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); | 
|  | 487 | ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); | 
|  | 488 | ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D); | 
|  | 489 | ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D); | 
|  | 490 | ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); | 
|  | 491 | ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); | 
|  | 492 | ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); | 
|  | 493 | ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); | 
|  | 494 | ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D); | 
|  | 495 | ExpectedDecl VisitClassTemplateSpecializationDecl( | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 496 | ClassTemplateSpecializationDecl *D); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 497 | ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D); | 
|  | 498 | ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); | 
|  | 499 | ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 500 |  | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 501 | // Importing statements | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 502 | ExpectedStmt VisitStmt(Stmt *S); | 
|  | 503 | ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S); | 
|  | 504 | ExpectedStmt VisitDeclStmt(DeclStmt *S); | 
|  | 505 | ExpectedStmt VisitNullStmt(NullStmt *S); | 
|  | 506 | ExpectedStmt VisitCompoundStmt(CompoundStmt *S); | 
|  | 507 | ExpectedStmt VisitCaseStmt(CaseStmt *S); | 
|  | 508 | ExpectedStmt VisitDefaultStmt(DefaultStmt *S); | 
|  | 509 | ExpectedStmt VisitLabelStmt(LabelStmt *S); | 
|  | 510 | ExpectedStmt VisitAttributedStmt(AttributedStmt *S); | 
|  | 511 | ExpectedStmt VisitIfStmt(IfStmt *S); | 
|  | 512 | ExpectedStmt VisitSwitchStmt(SwitchStmt *S); | 
|  | 513 | ExpectedStmt VisitWhileStmt(WhileStmt *S); | 
|  | 514 | ExpectedStmt VisitDoStmt(DoStmt *S); | 
|  | 515 | ExpectedStmt VisitForStmt(ForStmt *S); | 
|  | 516 | ExpectedStmt VisitGotoStmt(GotoStmt *S); | 
|  | 517 | ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S); | 
|  | 518 | ExpectedStmt VisitContinueStmt(ContinueStmt *S); | 
|  | 519 | ExpectedStmt VisitBreakStmt(BreakStmt *S); | 
|  | 520 | ExpectedStmt VisitReturnStmt(ReturnStmt *S); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 521 | // FIXME: MSAsmStmt | 
|  | 522 | // FIXME: SEHExceptStmt | 
|  | 523 | // FIXME: SEHFinallyStmt | 
|  | 524 | // FIXME: SEHTryStmt | 
|  | 525 | // FIXME: SEHLeaveStmt | 
|  | 526 | // FIXME: CapturedStmt | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 527 | ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S); | 
|  | 528 | ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S); | 
|  | 529 | ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 530 | // FIXME: MSDependentExistsStmt | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 531 | ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); | 
|  | 532 | ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); | 
|  | 533 | ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); | 
|  | 534 | ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S); | 
|  | 535 | ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); | 
|  | 536 | ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); | 
|  | 537 | ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 538 |  | 
|  | 539 | // Importing expressions | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 540 | ExpectedStmt VisitExpr(Expr *E); | 
|  | 541 | ExpectedStmt VisitVAArgExpr(VAArgExpr *E); | 
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 542 | ExpectedStmt VisitChooseExpr(ChooseExpr *E); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 543 | ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E); | 
|  | 544 | ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E); | 
|  | 545 | ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E); | 
|  | 546 | ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E); | 
|  | 547 | ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E); | 
|  | 548 | ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); | 
|  | 549 | ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E); | 
|  | 550 | ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E); | 
|  | 551 | ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E); | 
|  | 552 | ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E); | 
|  | 553 | ExpectedStmt VisitStringLiteral(StringLiteral *E); | 
|  | 554 | ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E); | 
|  | 555 | ExpectedStmt VisitAtomicExpr(AtomicExpr *E); | 
|  | 556 | ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E); | 
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 557 | ExpectedStmt VisitConstantExpr(ConstantExpr *E); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 558 | ExpectedStmt VisitParenExpr(ParenExpr *E); | 
|  | 559 | ExpectedStmt VisitParenListExpr(ParenListExpr *E); | 
|  | 560 | ExpectedStmt VisitStmtExpr(StmtExpr *E); | 
|  | 561 | ExpectedStmt VisitUnaryOperator(UnaryOperator *E); | 
|  | 562 | ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); | 
|  | 563 | ExpectedStmt VisitBinaryOperator(BinaryOperator *E); | 
|  | 564 | ExpectedStmt VisitConditionalOperator(ConditionalOperator *E); | 
|  | 565 | ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E); | 
|  | 566 | ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E); | 
|  | 567 | ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); | 
|  | 568 | ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E); | 
|  | 569 | ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E); | 
|  | 570 | ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E); | 
|  | 571 | ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E); | 
|  | 572 | ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E); | 
|  | 573 | ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE); | 
|  | 574 | ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E); | 
|  | 575 | ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E); | 
|  | 576 | ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); | 
|  | 577 | ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); | 
|  | 578 | ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); | 
|  | 579 | ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); | 
|  | 580 | ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); | 
|  | 581 | ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E); | 
|  | 582 | ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E); | 
|  | 583 | ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E); | 
|  | 584 | ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E); | 
|  | 585 | ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E); | 
|  | 586 | ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E); | 
|  | 587 | ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); | 
|  | 588 | ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); | 
|  | 589 | ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E); | 
|  | 590 | ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); | 
|  | 591 | ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); | 
|  | 592 | ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E); | 
|  | 593 | ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E); | 
|  | 594 | ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); | 
|  | 595 | ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); | 
|  | 596 | ExpectedStmt VisitMemberExpr(MemberExpr *E); | 
|  | 597 | ExpectedStmt VisitCallExpr(CallExpr *E); | 
|  | 598 | ExpectedStmt VisitLambdaExpr(LambdaExpr *LE); | 
|  | 599 | ExpectedStmt VisitInitListExpr(InitListExpr *E); | 
|  | 600 | ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); | 
|  | 601 | ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); | 
|  | 602 | ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); | 
|  | 603 | ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); | 
|  | 604 | ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); | 
|  | 605 | ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E); | 
|  | 606 | ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); | 
|  | 607 | ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E); | 
|  | 608 | ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 609 |  | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 610 | template<typename IIter, typename OIter> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 611 | Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 612 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 613 | for (; Ibegin != Iend; ++Ibegin, ++Obegin) { | 
|  | 614 | Expected<ItemT> ToOrErr = import(*Ibegin); | 
|  | 615 | if (!ToOrErr) | 
|  | 616 | return ToOrErr.takeError(); | 
|  | 617 | *Obegin = *ToOrErr; | 
|  | 618 | } | 
|  | 619 | return Error::success(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 620 | } | 
|  | 621 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 622 | // Import every item from a container structure into an output container. | 
|  | 623 | // If error occurs, stops at first error and returns the error. | 
|  | 624 | // The output container should have space for all needed elements (it is not | 
|  | 625 | // expanded, new items are put into from the beginning). | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 626 | template<typename InContainerTy, typename OutContainerTy> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 627 | Error ImportContainerChecked( | 
|  | 628 | const InContainerTy &InContainer, OutContainerTy &OutContainer) { | 
|  | 629 | return ImportArrayChecked( | 
|  | 630 | InContainer.begin(), InContainer.end(), OutContainer.begin()); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 631 | } | 
|  | 632 |  | 
|  | 633 | template<typename InContainerTy, typename OIter> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 634 | Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 635 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); | 
|  | 636 | } | 
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 637 |  | 
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 638 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 639 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 640 | Expected<FunctionDecl *> FindFunctionTemplateSpecialization( | 
|  | 641 | FunctionDecl *FromFD); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 642 | }; | 
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 643 |  | 
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 644 | template <typename InContainerTy> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 645 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( | 
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 646 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, | 
|  | 647 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 648 | auto ToLAngleLocOrErr = import(FromLAngleLoc); | 
|  | 649 | if (!ToLAngleLocOrErr) | 
|  | 650 | return ToLAngleLocOrErr.takeError(); | 
|  | 651 | auto ToRAngleLocOrErr = import(FromRAngleLoc); | 
|  | 652 | if (!ToRAngleLocOrErr) | 
|  | 653 | return ToRAngleLocOrErr.takeError(); | 
|  | 654 |  | 
|  | 655 | TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr); | 
|  | 656 | if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo)) | 
|  | 657 | return Err; | 
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 658 | Result = ToTAInfo; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 659 | return Error::success(); | 
| Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 660 | } | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 661 |  | 
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 662 | template <> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 663 | Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( | 
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 664 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { | 
|  | 665 | return ImportTemplateArgumentListInfo( | 
|  | 666 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); | 
|  | 667 | } | 
|  | 668 |  | 
|  | 669 | template <> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 670 | Error ASTNodeImporter::ImportTemplateArgumentListInfo< | 
|  | 671 | ASTTemplateArgumentListInfo>( | 
|  | 672 | const ASTTemplateArgumentListInfo &From, | 
|  | 673 | TemplateArgumentListInfo &Result) { | 
|  | 674 | return ImportTemplateArgumentListInfo( | 
|  | 675 | From.LAngleLoc, From.RAngleLoc, From.arguments(), Result); | 
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 676 | } | 
|  | 677 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 678 | Expected<ASTNodeImporter::FunctionTemplateAndArgsTy> | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 679 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( | 
|  | 680 | FunctionDecl *FromFD) { | 
|  | 681 | assert(FromFD->getTemplatedKind() == | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 682 | FunctionDecl::TK_FunctionTemplateSpecialization); | 
|  | 683 |  | 
|  | 684 | FunctionTemplateAndArgsTy Result; | 
|  | 685 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 686 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 687 | if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate())) | 
|  | 688 | return std::move(Err); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 689 |  | 
|  | 690 | // Import template arguments. | 
|  | 691 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 692 | if (Error Err = ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), | 
|  | 693 | std::get<1>(Result))) | 
|  | 694 | return std::move(Err); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 695 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 696 | return Result; | 
|  | 697 | } | 
|  | 698 |  | 
|  | 699 | template <> | 
|  | 700 | Expected<TemplateParameterList *> | 
|  | 701 | ASTNodeImporter::import(TemplateParameterList *From) { | 
|  | 702 | SmallVector<NamedDecl *, 4> To(From->size()); | 
|  | 703 | if (Error Err = ImportContainerChecked(*From, To)) | 
|  | 704 | return std::move(Err); | 
|  | 705 |  | 
|  | 706 | ExpectedExpr ToRequiresClause = import(From->getRequiresClause()); | 
|  | 707 | if (!ToRequiresClause) | 
|  | 708 | return ToRequiresClause.takeError(); | 
|  | 709 |  | 
|  | 710 | auto ToTemplateLocOrErr = import(From->getTemplateLoc()); | 
|  | 711 | if (!ToTemplateLocOrErr) | 
|  | 712 | return ToTemplateLocOrErr.takeError(); | 
|  | 713 | auto ToLAngleLocOrErr = import(From->getLAngleLoc()); | 
|  | 714 | if (!ToLAngleLocOrErr) | 
|  | 715 | return ToLAngleLocOrErr.takeError(); | 
|  | 716 | auto ToRAngleLocOrErr = import(From->getRAngleLoc()); | 
|  | 717 | if (!ToRAngleLocOrErr) | 
|  | 718 | return ToRAngleLocOrErr.takeError(); | 
|  | 719 |  | 
|  | 720 | return TemplateParameterList::Create( | 
|  | 721 | Importer.getToContext(), | 
|  | 722 | *ToTemplateLocOrErr, | 
|  | 723 | *ToLAngleLocOrErr, | 
|  | 724 | To, | 
|  | 725 | *ToRAngleLocOrErr, | 
|  | 726 | *ToRequiresClause); | 
|  | 727 | } | 
|  | 728 |  | 
|  | 729 | template <> | 
|  | 730 | Expected<TemplateArgument> | 
|  | 731 | ASTNodeImporter::import(const TemplateArgument &From) { | 
|  | 732 | switch (From.getKind()) { | 
|  | 733 | case TemplateArgument::Null: | 
|  | 734 | return TemplateArgument(); | 
|  | 735 |  | 
|  | 736 | case TemplateArgument::Type: { | 
|  | 737 | ExpectedType ToTypeOrErr = import(From.getAsType()); | 
|  | 738 | if (!ToTypeOrErr) | 
|  | 739 | return ToTypeOrErr.takeError(); | 
|  | 740 | return TemplateArgument(*ToTypeOrErr); | 
|  | 741 | } | 
|  | 742 |  | 
|  | 743 | case TemplateArgument::Integral: { | 
|  | 744 | ExpectedType ToTypeOrErr = import(From.getIntegralType()); | 
|  | 745 | if (!ToTypeOrErr) | 
|  | 746 | return ToTypeOrErr.takeError(); | 
|  | 747 | return TemplateArgument(From, *ToTypeOrErr); | 
|  | 748 | } | 
|  | 749 |  | 
|  | 750 | case TemplateArgument::Declaration: { | 
|  | 751 | Expected<ValueDecl *> ToOrErr = import(From.getAsDecl()); | 
|  | 752 | if (!ToOrErr) | 
|  | 753 | return ToOrErr.takeError(); | 
|  | 754 | ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl()); | 
|  | 755 | if (!ToTypeOrErr) | 
|  | 756 | return ToTypeOrErr.takeError(); | 
|  | 757 | return TemplateArgument(*ToOrErr, *ToTypeOrErr); | 
|  | 758 | } | 
|  | 759 |  | 
|  | 760 | case TemplateArgument::NullPtr: { | 
|  | 761 | ExpectedType ToTypeOrErr = import(From.getNullPtrType()); | 
|  | 762 | if (!ToTypeOrErr) | 
|  | 763 | return ToTypeOrErr.takeError(); | 
|  | 764 | return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/true); | 
|  | 765 | } | 
|  | 766 |  | 
|  | 767 | case TemplateArgument::Template: { | 
|  | 768 | Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate()); | 
|  | 769 | if (!ToTemplateOrErr) | 
|  | 770 | return ToTemplateOrErr.takeError(); | 
|  | 771 |  | 
|  | 772 | return TemplateArgument(*ToTemplateOrErr); | 
|  | 773 | } | 
|  | 774 |  | 
|  | 775 | case TemplateArgument::TemplateExpansion: { | 
|  | 776 | Expected<TemplateName> ToTemplateOrErr = | 
|  | 777 | import(From.getAsTemplateOrTemplatePattern()); | 
|  | 778 | if (!ToTemplateOrErr) | 
|  | 779 | return ToTemplateOrErr.takeError(); | 
|  | 780 |  | 
|  | 781 | return TemplateArgument( | 
|  | 782 | *ToTemplateOrErr, From.getNumTemplateExpansions()); | 
|  | 783 | } | 
|  | 784 |  | 
|  | 785 | case TemplateArgument::Expression: | 
|  | 786 | if (ExpectedExpr ToExpr = import(From.getAsExpr())) | 
|  | 787 | return TemplateArgument(*ToExpr); | 
|  | 788 | else | 
|  | 789 | return ToExpr.takeError(); | 
|  | 790 |  | 
|  | 791 | case TemplateArgument::Pack: { | 
|  | 792 | SmallVector<TemplateArgument, 2> ToPack; | 
|  | 793 | ToPack.reserve(From.pack_size()); | 
|  | 794 | if (Error Err = ImportTemplateArguments( | 
|  | 795 | From.pack_begin(), From.pack_size(), ToPack)) | 
|  | 796 | return std::move(Err); | 
|  | 797 |  | 
|  | 798 | return TemplateArgument( | 
|  | 799 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); | 
|  | 800 | } | 
|  | 801 | } | 
|  | 802 |  | 
|  | 803 | llvm_unreachable("Invalid template argument kind"); | 
|  | 804 | } | 
|  | 805 |  | 
|  | 806 | template <> | 
|  | 807 | Expected<TemplateArgumentLoc> | 
|  | 808 | ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) { | 
|  | 809 | Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument()); | 
|  | 810 | if (!ArgOrErr) | 
|  | 811 | return ArgOrErr.takeError(); | 
|  | 812 | TemplateArgument Arg = *ArgOrErr; | 
|  | 813 |  | 
|  | 814 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); | 
|  | 815 |  | 
|  | 816 | TemplateArgumentLocInfo ToInfo; | 
|  | 817 | if (Arg.getKind() == TemplateArgument::Expression) { | 
|  | 818 | ExpectedExpr E = import(FromInfo.getAsExpr()); | 
|  | 819 | if (!E) | 
|  | 820 | return E.takeError(); | 
|  | 821 | ToInfo = TemplateArgumentLocInfo(*E); | 
|  | 822 | } else if (Arg.getKind() == TemplateArgument::Type) { | 
|  | 823 | if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo())) | 
|  | 824 | ToInfo = TemplateArgumentLocInfo(*TSIOrErr); | 
|  | 825 | else | 
|  | 826 | return TSIOrErr.takeError(); | 
|  | 827 | } else { | 
|  | 828 | auto ToTemplateQualifierLocOrErr = | 
|  | 829 | import(FromInfo.getTemplateQualifierLoc()); | 
|  | 830 | if (!ToTemplateQualifierLocOrErr) | 
|  | 831 | return ToTemplateQualifierLocOrErr.takeError(); | 
|  | 832 | auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc()); | 
|  | 833 | if (!ToTemplateNameLocOrErr) | 
|  | 834 | return ToTemplateNameLocOrErr.takeError(); | 
|  | 835 | auto ToTemplateEllipsisLocOrErr = | 
|  | 836 | import(FromInfo.getTemplateEllipsisLoc()); | 
|  | 837 | if (!ToTemplateEllipsisLocOrErr) | 
|  | 838 | return ToTemplateEllipsisLocOrErr.takeError(); | 
|  | 839 |  | 
|  | 840 | ToInfo = TemplateArgumentLocInfo( | 
|  | 841 | *ToTemplateQualifierLocOrErr, | 
|  | 842 | *ToTemplateNameLocOrErr, | 
|  | 843 | *ToTemplateEllipsisLocOrErr); | 
|  | 844 | } | 
|  | 845 |  | 
|  | 846 | return TemplateArgumentLoc(Arg, ToInfo); | 
|  | 847 | } | 
|  | 848 |  | 
|  | 849 | template <> | 
|  | 850 | Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) { | 
|  | 851 | if (DG.isNull()) | 
|  | 852 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); | 
|  | 853 | size_t NumDecls = DG.end() - DG.begin(); | 
|  | 854 | SmallVector<Decl *, 1> ToDecls; | 
|  | 855 | ToDecls.reserve(NumDecls); | 
|  | 856 | for (Decl *FromD : DG) { | 
|  | 857 | if (auto ToDOrErr = import(FromD)) | 
|  | 858 | ToDecls.push_back(*ToDOrErr); | 
|  | 859 | else | 
|  | 860 | return ToDOrErr.takeError(); | 
|  | 861 | } | 
|  | 862 | return DeclGroupRef::Create(Importer.getToContext(), | 
|  | 863 | ToDecls.begin(), | 
|  | 864 | NumDecls); | 
|  | 865 | } | 
|  | 866 |  | 
|  | 867 | template <> | 
|  | 868 | Expected<ASTNodeImporter::Designator> | 
|  | 869 | ASTNodeImporter::import(const Designator &D) { | 
|  | 870 | if (D.isFieldDesignator()) { | 
|  | 871 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); | 
|  | 872 |  | 
|  | 873 | ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc()); | 
|  | 874 | if (!ToDotLocOrErr) | 
|  | 875 | return ToDotLocOrErr.takeError(); | 
|  | 876 |  | 
|  | 877 | ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc()); | 
|  | 878 | if (!ToFieldLocOrErr) | 
|  | 879 | return ToFieldLocOrErr.takeError(); | 
|  | 880 |  | 
|  | 881 | return Designator(ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr); | 
|  | 882 | } | 
|  | 883 |  | 
|  | 884 | ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc()); | 
|  | 885 | if (!ToLBracketLocOrErr) | 
|  | 886 | return ToLBracketLocOrErr.takeError(); | 
|  | 887 |  | 
|  | 888 | ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc()); | 
|  | 889 | if (!ToRBracketLocOrErr) | 
|  | 890 | return ToRBracketLocOrErr.takeError(); | 
|  | 891 |  | 
|  | 892 | if (D.isArrayDesignator()) | 
|  | 893 | return Designator(D.getFirstExprIndex(), | 
|  | 894 | *ToLBracketLocOrErr, *ToRBracketLocOrErr); | 
|  | 895 |  | 
|  | 896 | ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc()); | 
|  | 897 | if (!ToEllipsisLocOrErr) | 
|  | 898 | return ToEllipsisLocOrErr.takeError(); | 
|  | 899 |  | 
|  | 900 | assert(D.isArrayRangeDesignator()); | 
|  | 901 | return Designator( | 
|  | 902 | D.getFirstExprIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr, | 
|  | 903 | *ToRBracketLocOrErr); | 
|  | 904 | } | 
|  | 905 |  | 
|  | 906 | template <> | 
|  | 907 | Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) { | 
|  | 908 | VarDecl *Var = nullptr; | 
|  | 909 | if (From.capturesVariable()) { | 
|  | 910 | if (auto VarOrErr = import(From.getCapturedVar())) | 
|  | 911 | Var = *VarOrErr; | 
|  | 912 | else | 
|  | 913 | return VarOrErr.takeError(); | 
|  | 914 | } | 
|  | 915 |  | 
|  | 916 | auto LocationOrErr = import(From.getLocation()); | 
|  | 917 | if (!LocationOrErr) | 
|  | 918 | return LocationOrErr.takeError(); | 
|  | 919 |  | 
|  | 920 | SourceLocation EllipsisLoc; | 
|  | 921 | if (From.isPackExpansion()) | 
|  | 922 | if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc())) | 
|  | 923 | return std::move(Err); | 
|  | 924 |  | 
|  | 925 | return LambdaCapture( | 
|  | 926 | *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var, | 
|  | 927 | EllipsisLoc); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 928 | } | 
|  | 929 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 930 | } // namespace clang | 
| Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 931 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 932 | //---------------------------------------------------------------------------- | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 933 | // Import Types | 
|  | 934 | //---------------------------------------------------------------------------- | 
|  | 935 |  | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 936 | using namespace clang; | 
|  | 937 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 938 | ExpectedType ASTNodeImporter::VisitType(const Type *T) { | 
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 939 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) | 
|  | 940 | << T->getTypeClassName(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 941 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | 
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 942 | } | 
|  | 943 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 944 | ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ | 
|  | 945 | ExpectedType UnderlyingTypeOrErr = import(T->getValueType()); | 
|  | 946 | if (!UnderlyingTypeOrErr) | 
|  | 947 | return UnderlyingTypeOrErr.takeError(); | 
| Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 948 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 949 | return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr); | 
| Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 950 | } | 
|  | 951 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 952 | ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 953 | switch (T->getKind()) { | 
| Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 954 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ | 
|  | 955 | case BuiltinType::Id: \ | 
|  | 956 | return Importer.getToContext().SingletonId; | 
| Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 957 | #include "clang/Basic/OpenCLImageTypes.def" | 
| Andrew Savonichev | 3fee351 | 2018-11-08 11:25:41 +0000 | [diff] [blame] | 958 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ | 
|  | 959 | case BuiltinType::Id: \ | 
|  | 960 | return Importer.getToContext().Id##Ty; | 
|  | 961 | #include "clang/Basic/OpenCLExtensionTypes.def" | 
| Richard Sandiford | eb485fb | 2019-08-09 08:52:54 +0000 | [diff] [blame] | 962 | #define SVE_TYPE(Name, Id, SingletonId) \ | 
|  | 963 | case BuiltinType::Id: \ | 
|  | 964 | return Importer.getToContext().SingletonId; | 
|  | 965 | #include "clang/Basic/AArch64SVEACLETypes.def" | 
| John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 966 | #define SHARED_SINGLETON_TYPE(Expansion) | 
|  | 967 | #define BUILTIN_TYPE(Id, SingletonId) \ | 
|  | 968 | case BuiltinType::Id: return Importer.getToContext().SingletonId; | 
|  | 969 | #include "clang/AST/BuiltinTypes.def" | 
|  | 970 |  | 
|  | 971 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" | 
|  | 972 | // context supports C++. | 
|  | 973 |  | 
|  | 974 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" | 
|  | 975 | // context supports ObjC. | 
|  | 976 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 977 | case BuiltinType::Char_U: | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 978 | // The context we're importing from has an unsigned 'char'. If we're | 
|  | 979 | // importing into a context with a signed 'char', translate to | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 980 | // 'unsigned char' instead. | 
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 981 | if (Importer.getToContext().getLangOpts().CharIsSigned) | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 982 | return Importer.getToContext().UnsignedCharTy; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 983 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 984 | return Importer.getToContext().CharTy; | 
|  | 985 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 986 | case BuiltinType::Char_S: | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 987 | // The context we're importing from has an unsigned 'char'. If we're | 
|  | 988 | // importing into a context with a signed 'char', translate to | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 989 | // 'unsigned char' instead. | 
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 990 | if (!Importer.getToContext().getLangOpts().CharIsSigned) | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 991 | return Importer.getToContext().SignedCharTy; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 992 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 993 | return Importer.getToContext().CharTy; | 
|  | 994 |  | 
| Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 995 | case BuiltinType::WChar_S: | 
|  | 996 | case BuiltinType::WChar_U: | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 997 | // FIXME: If not in C++, shall we translate to the C equivalent of | 
|  | 998 | // wchar_t? | 
|  | 999 | return Importer.getToContext().WCharTy; | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1000 | } | 
| David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 1001 |  | 
|  | 1002 | llvm_unreachable("Invalid BuiltinType Kind!"); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1003 | } | 
|  | 1004 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1005 | ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { | 
|  | 1006 | ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType()); | 
|  | 1007 | if (!ToOriginalTypeOrErr) | 
|  | 1008 | return ToOriginalTypeOrErr.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1009 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1010 | return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1011 | } | 
|  | 1012 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1013 | ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) { | 
|  | 1014 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | 
|  | 1015 | if (!ToElementTypeOrErr) | 
|  | 1016 | return ToElementTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1017 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1018 | return Importer.getToContext().getComplexType(*ToElementTypeOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1019 | } | 
|  | 1020 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1021 | ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) { | 
|  | 1022 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | 
|  | 1023 | if (!ToPointeeTypeOrErr) | 
|  | 1024 | return ToPointeeTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1025 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1026 | return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1027 | } | 
|  | 1028 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1029 | ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1030 | // FIXME: Check for blocks support in "to" context. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1031 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | 
|  | 1032 | if (!ToPointeeTypeOrErr) | 
|  | 1033 | return ToPointeeTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1034 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1035 | return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1036 | } | 
|  | 1037 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1038 | ExpectedType | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1039 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1040 | // FIXME: Check for C++ support in "to" context. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1041 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); | 
|  | 1042 | if (!ToPointeeTypeOrErr) | 
|  | 1043 | return ToPointeeTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1044 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1045 | return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1046 | } | 
|  | 1047 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1048 | ExpectedType | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1049 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1050 | // FIXME: Check for C++0x support in "to" context. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1051 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten()); | 
|  | 1052 | if (!ToPointeeTypeOrErr) | 
|  | 1053 | return ToPointeeTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1054 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1055 | return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1056 | } | 
|  | 1057 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1058 | ExpectedType | 
|  | 1059 | ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1060 | // FIXME: Check for C++ support in "to" context. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1061 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | 
|  | 1062 | if (!ToPointeeTypeOrErr) | 
|  | 1063 | return ToPointeeTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1064 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1065 | ExpectedType ClassTypeOrErr = import(QualType(T->getClass(), 0)); | 
|  | 1066 | if (!ClassTypeOrErr) | 
|  | 1067 | return ClassTypeOrErr.takeError(); | 
|  | 1068 |  | 
|  | 1069 | return Importer.getToContext().getMemberPointerType( | 
|  | 1070 | *ToPointeeTypeOrErr, (*ClassTypeOrErr).getTypePtr()); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1071 | } | 
|  | 1072 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1073 | ExpectedType | 
|  | 1074 | ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { | 
|  | 1075 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | 
|  | 1076 | if (!ToElementTypeOrErr) | 
|  | 1077 | return ToElementTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1078 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1079 | return Importer.getToContext().getConstantArrayType(*ToElementTypeOrErr, | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1080 | T->getSize(), | 
|  | 1081 | T->getSizeModifier(), | 
|  | 1082 | T->getIndexTypeCVRQualifiers()); | 
|  | 1083 | } | 
|  | 1084 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1085 | ExpectedType | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1086 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1087 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | 
|  | 1088 | if (!ToElementTypeOrErr) | 
|  | 1089 | return ToElementTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1090 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1091 | return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr, | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1092 | T->getSizeModifier(), | 
|  | 1093 | T->getIndexTypeCVRQualifiers()); | 
|  | 1094 | } | 
|  | 1095 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1096 | ExpectedType | 
|  | 1097 | ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { | 
|  | 1098 | QualType ToElementType; | 
|  | 1099 | Expr *ToSizeExpr; | 
|  | 1100 | SourceRange ToBracketsRange; | 
|  | 1101 | if (auto Imp = importSeq( | 
|  | 1102 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) | 
|  | 1103 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; | 
|  | 1104 | else | 
|  | 1105 | return Imp.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1106 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1107 | return Importer.getToContext().getVariableArrayType( | 
|  | 1108 | ToElementType, ToSizeExpr, T->getSizeModifier(), | 
|  | 1109 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1110 | } | 
|  | 1111 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1112 | ExpectedType ASTNodeImporter::VisitDependentSizedArrayType( | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1113 | const DependentSizedArrayType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1114 | QualType ToElementType; | 
|  | 1115 | Expr *ToSizeExpr; | 
|  | 1116 | SourceRange ToBracketsRange; | 
|  | 1117 | if (auto Imp = importSeq( | 
|  | 1118 | T->getElementType(), T->getSizeExpr(), T->getBracketsRange())) | 
|  | 1119 | std::tie(ToElementType, ToSizeExpr, ToBracketsRange) = *Imp; | 
|  | 1120 | else | 
|  | 1121 | return Imp.takeError(); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1122 | // SizeExpr may be null if size is not specified directly. | 
|  | 1123 | // For example, 'int a[]'. | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1124 |  | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1125 | return Importer.getToContext().getDependentSizedArrayType( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1126 | ToElementType, ToSizeExpr, T->getSizeModifier(), | 
|  | 1127 | T->getIndexTypeCVRQualifiers(), ToBracketsRange); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1128 | } | 
|  | 1129 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1130 | ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) { | 
|  | 1131 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | 
|  | 1132 | if (!ToElementTypeOrErr) | 
|  | 1133 | return ToElementTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1134 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1135 | return Importer.getToContext().getVectorType(*ToElementTypeOrErr, | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1136 | T->getNumElements(), | 
| Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 1137 | T->getVectorKind()); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1138 | } | 
|  | 1139 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1140 | ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { | 
|  | 1141 | ExpectedType ToElementTypeOrErr = import(T->getElementType()); | 
|  | 1142 | if (!ToElementTypeOrErr) | 
|  | 1143 | return ToElementTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1144 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1145 | return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr, | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1146 | T->getNumElements()); | 
|  | 1147 | } | 
|  | 1148 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1149 | ExpectedType | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1150 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1151 | // FIXME: What happens if we're importing a function without a prototype | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1152 | // into C++? Should we make it variadic? | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1153 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); | 
|  | 1154 | if (!ToReturnTypeOrErr) | 
|  | 1155 | return ToReturnTypeOrErr.takeError(); | 
| Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1156 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1157 | return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr, | 
| Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 1158 | T->getExtInfo()); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1159 | } | 
|  | 1160 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1161 | ExpectedType | 
|  | 1162 | ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { | 
|  | 1163 | ExpectedType ToReturnTypeOrErr = import(T->getReturnType()); | 
|  | 1164 | if (!ToReturnTypeOrErr) | 
|  | 1165 | return ToReturnTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1166 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1167 | // Import argument types | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1168 | SmallVector<QualType, 4> ArgTypes; | 
| Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 1169 | for (const auto &A : T->param_types()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1170 | ExpectedType TyOrErr = import(A); | 
|  | 1171 | if (!TyOrErr) | 
|  | 1172 | return TyOrErr.takeError(); | 
|  | 1173 | ArgTypes.push_back(*TyOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1174 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1175 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1176 | // Import exception types | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1177 | SmallVector<QualType, 4> ExceptionTypes; | 
| Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 1178 | for (const auto &E : T->exceptions()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1179 | ExpectedType TyOrErr = import(E); | 
|  | 1180 | if (!TyOrErr) | 
|  | 1181 | return TyOrErr.takeError(); | 
|  | 1182 | ExceptionTypes.push_back(*TyOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1183 | } | 
| John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 1184 |  | 
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1185 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); | 
|  | 1186 | FunctionProtoType::ExtProtoInfo ToEPI; | 
|  | 1187 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1188 | auto Imp = importSeq( | 
|  | 1189 | FromEPI.ExceptionSpec.NoexceptExpr, | 
|  | 1190 | FromEPI.ExceptionSpec.SourceDecl, | 
|  | 1191 | FromEPI.ExceptionSpec.SourceTemplate); | 
|  | 1192 | if (!Imp) | 
|  | 1193 | return Imp.takeError(); | 
|  | 1194 |  | 
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1195 | ToEPI.ExtInfo = FromEPI.ExtInfo; | 
|  | 1196 | ToEPI.Variadic = FromEPI.Variadic; | 
|  | 1197 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; | 
|  | 1198 | ToEPI.TypeQuals = FromEPI.TypeQuals; | 
|  | 1199 | ToEPI.RefQualifier = FromEPI.RefQualifier; | 
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 1200 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; | 
|  | 1201 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1202 | std::tie( | 
|  | 1203 | ToEPI.ExceptionSpec.NoexceptExpr, | 
|  | 1204 | ToEPI.ExceptionSpec.SourceDecl, | 
|  | 1205 | ToEPI.ExceptionSpec.SourceTemplate) = *Imp; | 
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1206 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1207 | return Importer.getToContext().getFunctionType( | 
|  | 1208 | *ToReturnTypeOrErr, ArgTypes, ToEPI); | 
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 1209 | } | 
|  | 1210 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1211 | ExpectedType ASTNodeImporter::VisitUnresolvedUsingType( | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1212 | const UnresolvedUsingType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1213 | UnresolvedUsingTypenameDecl *ToD; | 
|  | 1214 | Decl *ToPrevD; | 
|  | 1215 | if (auto Imp = importSeq(T->getDecl(), T->getDecl()->getPreviousDecl())) | 
|  | 1216 | std::tie(ToD, ToPrevD) = *Imp; | 
|  | 1217 | else | 
|  | 1218 | return Imp.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1219 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1220 | return Importer.getToContext().getTypeDeclType( | 
|  | 1221 | ToD, cast_or_null<TypeDecl>(ToPrevD)); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1222 | } | 
|  | 1223 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1224 | ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) { | 
|  | 1225 | ExpectedType ToInnerTypeOrErr = import(T->getInnerType()); | 
|  | 1226 | if (!ToInnerTypeOrErr) | 
|  | 1227 | return ToInnerTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1228 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1229 | return Importer.getToContext().getParenType(*ToInnerTypeOrErr); | 
| Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 1230 | } | 
|  | 1231 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1232 | ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { | 
|  | 1233 | Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl()); | 
|  | 1234 | if (!ToDeclOrErr) | 
|  | 1235 | return ToDeclOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1236 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1237 | return Importer.getToContext().getTypeDeclType(*ToDeclOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1238 | } | 
|  | 1239 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1240 | ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { | 
|  | 1241 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); | 
|  | 1242 | if (!ToExprOrErr) | 
|  | 1243 | return ToExprOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1244 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1245 | return Importer.getToContext().getTypeOfExprType(*ToExprOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1246 | } | 
|  | 1247 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1248 | ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { | 
|  | 1249 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | 
|  | 1250 | if (!ToUnderlyingTypeOrErr) | 
|  | 1251 | return ToUnderlyingTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1252 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1253 | return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1254 | } | 
|  | 1255 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1256 | ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { | 
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1257 | // FIXME: Make sure that the "to" context supports C++0x! | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1258 | ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr()); | 
|  | 1259 | if (!ToExprOrErr) | 
|  | 1260 | return ToExprOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1261 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1262 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | 
|  | 1263 | if (!ToUnderlyingTypeOrErr) | 
|  | 1264 | return ToUnderlyingTypeOrErr.takeError(); | 
| Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 1265 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1266 | return Importer.getToContext().getDecltypeType( | 
|  | 1267 | *ToExprOrErr, *ToUnderlyingTypeOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1268 | } | 
|  | 1269 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1270 | ExpectedType | 
|  | 1271 | ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { | 
|  | 1272 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); | 
|  | 1273 | if (!ToBaseTypeOrErr) | 
|  | 1274 | return ToBaseTypeOrErr.takeError(); | 
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1275 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1276 | ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType()); | 
|  | 1277 | if (!ToUnderlyingTypeOrErr) | 
|  | 1278 | return ToUnderlyingTypeOrErr.takeError(); | 
|  | 1279 |  | 
|  | 1280 | return Importer.getToContext().getUnaryTransformType( | 
|  | 1281 | *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind()); | 
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1282 | } | 
|  | 1283 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1284 | ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) { | 
| Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 1285 | // FIXME: Make sure that the "to" context supports C++11! | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1286 | ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType()); | 
|  | 1287 | if (!ToDeducedTypeOrErr) | 
|  | 1288 | return ToDeducedTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1289 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1290 | return Importer.getToContext().getAutoType(*ToDeducedTypeOrErr, | 
|  | 1291 | T->getKeyword(), | 
| Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 1292 | /*IsDependent*/false); | 
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1293 | } | 
|  | 1294 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1295 | ExpectedType ASTNodeImporter::VisitInjectedClassNameType( | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1296 | const InjectedClassNameType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1297 | Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl()); | 
|  | 1298 | if (!ToDeclOrErr) | 
|  | 1299 | return ToDeclOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1300 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1301 | ExpectedType ToInjTypeOrErr = import(T->getInjectedSpecializationType()); | 
|  | 1302 | if (!ToInjTypeOrErr) | 
|  | 1303 | return ToInjTypeOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1304 |  | 
|  | 1305 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading | 
|  | 1306 | // See comments in InjectedClassNameType definition for details | 
|  | 1307 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); | 
|  | 1308 | enum { | 
|  | 1309 | TypeAlignmentInBits = 4, | 
|  | 1310 | TypeAlignment = 1 << TypeAlignmentInBits | 
|  | 1311 | }; | 
|  | 1312 |  | 
|  | 1313 | return QualType(new (Importer.getToContext(), TypeAlignment) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1314 | InjectedClassNameType(*ToDeclOrErr, *ToInjTypeOrErr), 0); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1315 | } | 
|  | 1316 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1317 | ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) { | 
|  | 1318 | Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl()); | 
|  | 1319 | if (!ToDeclOrErr) | 
|  | 1320 | return ToDeclOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1321 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1322 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1323 | } | 
|  | 1324 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1325 | ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) { | 
|  | 1326 | Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl()); | 
|  | 1327 | if (!ToDeclOrErr) | 
|  | 1328 | return ToDeclOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1329 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1330 | return Importer.getToContext().getTagDeclType(*ToDeclOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1331 | } | 
|  | 1332 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1333 | ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { | 
|  | 1334 | ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType()); | 
|  | 1335 | if (!ToModifiedTypeOrErr) | 
|  | 1336 | return ToModifiedTypeOrErr.takeError(); | 
|  | 1337 | ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType()); | 
|  | 1338 | if (!ToEquivalentTypeOrErr) | 
|  | 1339 | return ToEquivalentTypeOrErr.takeError(); | 
| Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1340 |  | 
|  | 1341 | return Importer.getToContext().getAttributedType(T->getAttrKind(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1342 | *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr); | 
| Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 1343 | } | 
|  | 1344 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1345 | ExpectedType ASTNodeImporter::VisitTemplateTypeParmType( | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1346 | const TemplateTypeParmType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1347 | Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl()); | 
|  | 1348 | if (!ToDeclOrErr) | 
|  | 1349 | return ToDeclOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1350 |  | 
|  | 1351 | return Importer.getToContext().getTemplateTypeParmType( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1352 | T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1353 | } | 
|  | 1354 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1355 | ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType( | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1356 | const SubstTemplateTypeParmType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1357 | ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0)); | 
|  | 1358 | if (!ReplacedOrErr) | 
|  | 1359 | return ReplacedOrErr.takeError(); | 
|  | 1360 | const TemplateTypeParmType *Replaced = | 
|  | 1361 | cast<TemplateTypeParmType>((*ReplacedOrErr).getTypePtr()); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1362 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1363 | ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType()); | 
|  | 1364 | if (!ToReplacementTypeOrErr) | 
|  | 1365 | return ToReplacementTypeOrErr.takeError(); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1366 |  | 
|  | 1367 | return Importer.getToContext().getSubstTemplateTypeParmType( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1368 | Replaced, (*ToReplacementTypeOrErr).getCanonicalType()); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 1369 | } | 
|  | 1370 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1371 | ExpectedType ASTNodeImporter::VisitTemplateSpecializationType( | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1372 | const TemplateSpecializationType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1373 | auto ToTemplateOrErr = import(T->getTemplateName()); | 
|  | 1374 | if (!ToTemplateOrErr) | 
|  | 1375 | return ToTemplateOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1376 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1377 | SmallVector<TemplateArgument, 2> ToTemplateArgs; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1378 | if (Error Err = ImportTemplateArguments( | 
|  | 1379 | T->getArgs(), T->getNumArgs(), ToTemplateArgs)) | 
|  | 1380 | return std::move(Err); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1381 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1382 | QualType ToCanonType; | 
|  | 1383 | if (!QualType(T, 0).isCanonical()) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1384 | QualType FromCanonType | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1385 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1386 | if (ExpectedType TyOrErr = import(FromCanonType)) | 
|  | 1387 | ToCanonType = *TyOrErr; | 
|  | 1388 | else | 
|  | 1389 | return TyOrErr.takeError(); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1390 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1391 | return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr, | 
| David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 1392 | ToTemplateArgs, | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1393 | ToCanonType); | 
|  | 1394 | } | 
|  | 1395 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1396 | ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { | 
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1397 | // Note: the qualifier in an ElaboratedType is optional. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1398 | auto ToQualifierOrErr = import(T->getQualifier()); | 
|  | 1399 | if (!ToQualifierOrErr) | 
|  | 1400 | return ToQualifierOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1401 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1402 | ExpectedType ToNamedTypeOrErr = import(T->getNamedType()); | 
|  | 1403 | if (!ToNamedTypeOrErr) | 
|  | 1404 | return ToNamedTypeOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1405 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1406 | Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl()); | 
|  | 1407 | if (!ToOwnedTagDeclOrErr) | 
|  | 1408 | return ToOwnedTagDeclOrErr.takeError(); | 
| Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1409 |  | 
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1410 | return Importer.getToContext().getElaboratedType(T->getKeyword(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1411 | *ToQualifierOrErr, | 
|  | 1412 | *ToNamedTypeOrErr, | 
|  | 1413 | *ToOwnedTagDeclOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1414 | } | 
|  | 1415 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1416 | ExpectedType | 
|  | 1417 | ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { | 
|  | 1418 | ExpectedType ToPatternOrErr = import(T->getPattern()); | 
|  | 1419 | if (!ToPatternOrErr) | 
|  | 1420 | return ToPatternOrErr.takeError(); | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1421 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1422 | return Importer.getToContext().getPackExpansionType(*ToPatternOrErr, | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1423 | T->getNumExpansions()); | 
|  | 1424 | } | 
|  | 1425 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1426 | ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType( | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1427 | const DependentTemplateSpecializationType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1428 | auto ToQualifierOrErr = import(T->getQualifier()); | 
|  | 1429 | if (!ToQualifierOrErr) | 
|  | 1430 | return ToQualifierOrErr.takeError(); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1431 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1432 | IdentifierInfo *ToName = Importer.Import(T->getIdentifier()); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1433 |  | 
|  | 1434 | SmallVector<TemplateArgument, 2> ToPack; | 
|  | 1435 | ToPack.reserve(T->getNumArgs()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1436 | if (Error Err = ImportTemplateArguments( | 
|  | 1437 | T->getArgs(), T->getNumArgs(), ToPack)) | 
|  | 1438 | return std::move(Err); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1439 |  | 
|  | 1440 | return Importer.getToContext().getDependentTemplateSpecializationType( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1441 | T->getKeyword(), *ToQualifierOrErr, ToName, ToPack); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1442 | } | 
|  | 1443 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1444 | ExpectedType | 
|  | 1445 | ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { | 
|  | 1446 | auto ToQualifierOrErr = import(T->getQualifier()); | 
|  | 1447 | if (!ToQualifierOrErr) | 
|  | 1448 | return ToQualifierOrErr.takeError(); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1449 |  | 
|  | 1450 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1451 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1452 | QualType Canon; | 
|  | 1453 | if (T != T->getCanonicalTypeInternal().getTypePtr()) { | 
|  | 1454 | if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal())) | 
|  | 1455 | Canon = (*TyOrErr).getCanonicalType(); | 
|  | 1456 | else | 
|  | 1457 | return TyOrErr.takeError(); | 
|  | 1458 | } | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1459 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1460 | return Importer.getToContext().getDependentNameType(T->getKeyword(), | 
|  | 1461 | *ToQualifierOrErr, | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1462 | Name, Canon); | 
|  | 1463 | } | 
|  | 1464 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1465 | ExpectedType | 
|  | 1466 | ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { | 
|  | 1467 | Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl()); | 
|  | 1468 | if (!ToDeclOrErr) | 
|  | 1469 | return ToDeclOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1470 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1471 | return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr); | 
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1472 | } | 
|  | 1473 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1474 | ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { | 
|  | 1475 | ExpectedType ToBaseTypeOrErr = import(T->getBaseType()); | 
|  | 1476 | if (!ToBaseTypeOrErr) | 
|  | 1477 | return ToBaseTypeOrErr.takeError(); | 
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1478 |  | 
| Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1479 | SmallVector<QualType, 4> TypeArgs; | 
| Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1480 | for (auto TypeArg : T->getTypeArgsAsWritten()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1481 | if (ExpectedType TyOrErr = import(TypeArg)) | 
|  | 1482 | TypeArgs.push_back(*TyOrErr); | 
|  | 1483 | else | 
|  | 1484 | return TyOrErr.takeError(); | 
| Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1485 | } | 
|  | 1486 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1487 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | 
| Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1488 | for (auto *P : T->quals()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1489 | if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P)) | 
|  | 1490 | Protocols.push_back(*ProtocolOrErr); | 
|  | 1491 | else | 
|  | 1492 | return ProtocolOrErr.takeError(); | 
|  | 1493 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1494 | } | 
|  | 1495 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1496 | return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs, | 
| Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1497 | Protocols, | 
|  | 1498 | T->isKindOfTypeAsWritten()); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1499 | } | 
|  | 1500 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1501 | ExpectedType | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1502 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1503 | ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType()); | 
|  | 1504 | if (!ToPointeeTypeOrErr) | 
|  | 1505 | return ToPointeeTypeOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1506 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1507 | return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1508 | } | 
|  | 1509 |  | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1510 | //---------------------------------------------------------------------------- | 
|  | 1511 | // Import Declarations | 
|  | 1512 | //---------------------------------------------------------------------------- | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1513 | Error ASTNodeImporter::ImportDeclParts( | 
|  | 1514 | NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC, | 
|  | 1515 | DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc) { | 
| Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1516 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. | 
|  | 1517 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); | 
|  | 1518 | DeclContext *OrigDC = D->getDeclContext(); | 
|  | 1519 | FunctionDecl *FunDecl; | 
|  | 1520 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && | 
|  | 1521 | FunDecl->hasBody()) { | 
| Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1522 | auto getLeafPointeeType = [](const Type *T) { | 
|  | 1523 | while (T->isPointerType() || T->isArrayType()) { | 
|  | 1524 | T = T->getPointeeOrArrayElementType(); | 
|  | 1525 | } | 
|  | 1526 | return T; | 
|  | 1527 | }; | 
|  | 1528 | for (const ParmVarDecl *P : FunDecl->parameters()) { | 
|  | 1529 | const Type *LeafT = | 
|  | 1530 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); | 
|  | 1531 | auto *RT = dyn_cast<RecordType>(LeafT); | 
|  | 1532 | if (RT && RT->getDecl() == D) { | 
|  | 1533 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | 
|  | 1534 | << D->getDeclKindName(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1535 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | 
| Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame] | 1536 | } | 
| Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1537 | } | 
|  | 1538 | } | 
|  | 1539 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1540 | // Import the context of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1541 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 1542 | return Err; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1543 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1544 | // Import the name of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1545 | if (Error Err = importInto(Name, D->getDeclName())) | 
|  | 1546 | return Err; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1547 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1548 | // Import the location of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1549 | if (Error Err = importInto(Loc, D->getLocation())) | 
|  | 1550 | return Err; | 
|  | 1551 |  | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1552 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); | 
| Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 1553 | if (ToD) | 
|  | 1554 | if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD)) | 
|  | 1555 | return Err; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1556 |  | 
|  | 1557 | return Error::success(); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1558 | } | 
|  | 1559 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1560 | Error ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1561 | if (!FromD) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1562 | return Error::success(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1563 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1564 | if (!ToD) | 
|  | 1565 | if (Error Err = importInto(ToD, FromD)) | 
|  | 1566 | return Err; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1567 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1568 | if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) { | 
|  | 1569 | if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) { | 
|  | 1570 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && | 
|  | 1571 | !ToRecord->getDefinition()) { | 
|  | 1572 | if (Error Err = ImportDefinition(FromRecord, ToRecord)) | 
|  | 1573 | return Err; | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1574 | } | 
|  | 1575 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 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 | if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) { | 
|  | 1580 | if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) { | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1581 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1582 | if (Error Err = ImportDefinition(FromEnum, ToEnum)) | 
|  | 1583 | return Err; | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1584 | } | 
|  | 1585 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1586 | return Error::success(); | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1587 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1588 |  | 
|  | 1589 | return Error::success(); | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1590 | } | 
|  | 1591 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1592 | Error | 
|  | 1593 | ASTNodeImporter::ImportDeclarationNameLoc( | 
|  | 1594 | const DeclarationNameInfo &From, DeclarationNameInfo& To) { | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1595 | // NOTE: To.Name and To.Loc are already imported. | 
|  | 1596 | // We only have to import To.LocInfo. | 
|  | 1597 | switch (To.getName().getNameKind()) { | 
|  | 1598 | case DeclarationName::Identifier: | 
|  | 1599 | case DeclarationName::ObjCZeroArgSelector: | 
|  | 1600 | case DeclarationName::ObjCOneArgSelector: | 
|  | 1601 | case DeclarationName::ObjCMultiArgSelector: | 
|  | 1602 | case DeclarationName::CXXUsingDirective: | 
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1603 | case DeclarationName::CXXDeductionGuideName: | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1604 | return Error::success(); | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1605 |  | 
|  | 1606 | case DeclarationName::CXXOperatorName: { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1607 | if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange())) | 
|  | 1608 | To.setCXXOperatorNameRange(*ToRangeOrErr); | 
|  | 1609 | else | 
|  | 1610 | return ToRangeOrErr.takeError(); | 
|  | 1611 | return Error::success(); | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1612 | } | 
|  | 1613 | case DeclarationName::CXXLiteralOperatorName: { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1614 | if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc())) | 
|  | 1615 | To.setCXXLiteralOperatorNameLoc(*LocOrErr); | 
|  | 1616 | else | 
|  | 1617 | return LocOrErr.takeError(); | 
|  | 1618 | return Error::success(); | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1619 | } | 
|  | 1620 | case DeclarationName::CXXConstructorName: | 
|  | 1621 | case DeclarationName::CXXDestructorName: | 
|  | 1622 | case DeclarationName::CXXConversionFunctionName: { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1623 | if (auto ToTInfoOrErr = import(From.getNamedTypeInfo())) | 
|  | 1624 | To.setNamedTypeInfo(*ToTInfoOrErr); | 
|  | 1625 | else | 
|  | 1626 | return ToTInfoOrErr.takeError(); | 
|  | 1627 | return Error::success(); | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1628 | } | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1629 | } | 
| Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1630 | llvm_unreachable("Unknown name kind."); | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1631 | } | 
|  | 1632 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1633 | Error | 
|  | 1634 | ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { | 
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1635 | if (Importer.isMinimalImport() && !ForceImport) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1636 | auto ToDCOrErr = Importer.ImportContext(FromDC); | 
|  | 1637 | return ToDCOrErr.takeError(); | 
|  | 1638 | } | 
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1639 |  | 
|  | 1640 | // We use strict error handling in case of records and enums, but not | 
|  | 1641 | // with e.g. namespaces. | 
|  | 1642 | // | 
|  | 1643 | // FIXME Clients of the ASTImporter should be able to choose an | 
|  | 1644 | // appropriate error handling strategy for their needs.  For instance, | 
|  | 1645 | // they may not want to mark an entire namespace as erroneous merely | 
|  | 1646 | // because there is an ODR error with two typedefs.  As another example, | 
|  | 1647 | // the client may allow EnumConstantDecls with same names but with | 
|  | 1648 | // different values in two distinct translation units. | 
|  | 1649 | bool AccumulateChildErrors = isa<TagDecl>(FromDC); | 
|  | 1650 |  | 
|  | 1651 | Error ChildErrors = Error::success(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1652 | for (auto *From : FromDC->decls()) { | 
|  | 1653 | ExpectedDecl ImportedOrErr = import(From); | 
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1654 | if (!ImportedOrErr) { | 
|  | 1655 | if (AccumulateChildErrors) | 
|  | 1656 | ChildErrors = | 
|  | 1657 | joinErrors(std::move(ChildErrors), ImportedOrErr.takeError()); | 
|  | 1658 | else | 
|  | 1659 | consumeError(ImportedOrErr.takeError()); | 
|  | 1660 | } | 
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1661 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1662 |  | 
| Gabor Marton | 48b16e1 | 2019-07-25 09:07:17 +0000 | [diff] [blame] | 1663 | // We reorder declarations in RecordDecls because they may have another order | 
|  | 1664 | // in the "to" context than they have in the "from" context. This may happen | 
|  | 1665 | // e.g when we import a class like this: | 
|  | 1666 | //    struct declToImport { | 
|  | 1667 | //        int a = c + b; | 
|  | 1668 | //        int b = 1; | 
|  | 1669 | //        int c = 2; | 
|  | 1670 | //    }; | 
|  | 1671 | // During the import of `a` we import first the dependencies in sequence, | 
|  | 1672 | // thus the order would be `c`, `b`, `a`. We will get the normal order by | 
|  | 1673 | // first removing the already imported members and then adding them in the | 
|  | 1674 | // order as they apper in the "from" context. | 
|  | 1675 | // | 
|  | 1676 | // Keeping field order is vital because it determines structure layout. | 
|  | 1677 | // | 
|  | 1678 | // Here and below, we cannot call field_begin() method and its callers on | 
|  | 1679 | // ToDC if it has an external storage. Calling field_begin() will | 
|  | 1680 | // automatically load all the fields by calling | 
|  | 1681 | // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would | 
|  | 1682 | // call ASTImporter::Import(). This is because the ExternalASTSource | 
|  | 1683 | // interface in LLDB is implemented by the means of the ASTImporter. However, | 
|  | 1684 | // calling an import at this point would result in an uncontrolled import, we | 
|  | 1685 | // must avoid that. | 
|  | 1686 | const auto *FromRD = dyn_cast<RecordDecl>(FromDC); | 
|  | 1687 | if (!FromRD) | 
|  | 1688 | return ChildErrors; | 
|  | 1689 |  | 
|  | 1690 | auto ToDCOrErr = Importer.ImportContext(FromDC); | 
|  | 1691 | if (!ToDCOrErr) { | 
|  | 1692 | consumeError(std::move(ChildErrors)); | 
|  | 1693 | return ToDCOrErr.takeError(); | 
|  | 1694 | } | 
|  | 1695 |  | 
|  | 1696 | DeclContext *ToDC = *ToDCOrErr; | 
|  | 1697 | // Remove all declarations, which may be in wrong order in the | 
|  | 1698 | // lexical DeclContext and then add them in the proper order. | 
|  | 1699 | for (auto *D : FromRD->decls()) { | 
|  | 1700 | if (isa<FieldDecl>(D) || isa<FriendDecl>(D)) { | 
|  | 1701 | assert(D && "DC contains a null decl"); | 
|  | 1702 | Decl *ToD = Importer.GetAlreadyImportedOrNull(D); | 
|  | 1703 | // Remove only the decls which we successfully imported. | 
|  | 1704 | if (ToD) { | 
|  | 1705 | assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD)); | 
|  | 1706 | // Remove the decl from its wrong place in the linked list. | 
|  | 1707 | ToDC->removeDecl(ToD); | 
|  | 1708 | // Add the decl to the end of the linked list. | 
|  | 1709 | // This time it will be at the proper place because the enclosing for | 
|  | 1710 | // loop iterates in the original (good) order of the decls. | 
|  | 1711 | ToDC->addDeclInternal(ToD); | 
|  | 1712 | } | 
|  | 1713 | } | 
|  | 1714 | } | 
|  | 1715 |  | 
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1716 | return ChildErrors; | 
| Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1717 | } | 
|  | 1718 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1719 | Error ASTNodeImporter::ImportDeclContext( | 
|  | 1720 | Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) { | 
|  | 1721 | auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext()); | 
|  | 1722 | if (!ToDCOrErr) | 
|  | 1723 | return ToDCOrErr.takeError(); | 
|  | 1724 | ToDC = *ToDCOrErr; | 
|  | 1725 |  | 
|  | 1726 | if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) { | 
|  | 1727 | auto ToLexicalDCOrErr = Importer.ImportContext( | 
|  | 1728 | FromD->getLexicalDeclContext()); | 
|  | 1729 | if (!ToLexicalDCOrErr) | 
|  | 1730 | return ToLexicalDCOrErr.takeError(); | 
|  | 1731 | ToLexicalDC = *ToLexicalDCOrErr; | 
|  | 1732 | } else | 
|  | 1733 | ToLexicalDC = ToDC; | 
|  | 1734 |  | 
|  | 1735 | return Error::success(); | 
|  | 1736 | } | 
|  | 1737 |  | 
|  | 1738 | Error ASTNodeImporter::ImportImplicitMethods( | 
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1739 | const CXXRecordDecl *From, CXXRecordDecl *To) { | 
|  | 1740 | assert(From->isCompleteDefinition() && To->getDefinition() == To && | 
|  | 1741 | "Import implicit methods to or from non-definition"); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1742 |  | 
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1743 | for (CXXMethodDecl *FromM : From->methods()) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1744 | if (FromM->isImplicit()) { | 
|  | 1745 | Expected<CXXMethodDecl *> ToMOrErr = import(FromM); | 
|  | 1746 | if (!ToMOrErr) | 
|  | 1747 | return ToMOrErr.takeError(); | 
|  | 1748 | } | 
|  | 1749 |  | 
|  | 1750 | return Error::success(); | 
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1751 | } | 
|  | 1752 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1753 | static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, | 
|  | 1754 | ASTImporter &Importer) { | 
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1755 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 1756 | if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef)) | 
| Balazs Keri | 57949eb | 2019-03-25 09:16:39 +0000 | [diff] [blame] | 1757 | To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr)); | 
|  | 1758 | else | 
|  | 1759 | return ToTypedefOrErr.takeError(); | 
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1760 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1761 | return Error::success(); | 
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1762 | } | 
|  | 1763 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1764 | Error ASTNodeImporter::ImportDefinition( | 
|  | 1765 | RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { | 
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1766 | auto DefinitionCompleter = [To]() { | 
|  | 1767 | // There are cases in LLDB when we first import a class without its | 
|  | 1768 | // members. The class will have DefinitionData, but no members. Then, | 
|  | 1769 | // importDefinition is called from LLDB, which tries to get the members, so | 
|  | 1770 | // when we get here, the class already has the DefinitionData set, so we | 
|  | 1771 | // must unset the CompleteDefinition here to be able to complete again the | 
|  | 1772 | // definition. | 
|  | 1773 | To->setCompleteDefinition(false); | 
|  | 1774 | To->completeDefinition(); | 
|  | 1775 | }; | 
|  | 1776 |  | 
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1777 | if (To->getDefinition() || To->isBeingDefined()) { | 
| Gabor Marton | e73805f | 2019-07-08 12:49:13 +0000 | [diff] [blame] | 1778 | if (Kind == IDK_Everything || | 
|  | 1779 | // In case of lambdas, the class already has a definition ptr set, but | 
|  | 1780 | // the contained decls are not imported yet. Also, isBeingDefined was | 
|  | 1781 | // set in CXXRecordDecl::CreateLambda.  We must import the contained | 
|  | 1782 | // decls here and finish the definition. | 
|  | 1783 | (To->isLambda() && shouldForceImportDeclContext(Kind))) { | 
|  | 1784 | Error Result = ImportDeclContext(From, /*ForceImport=*/true); | 
|  | 1785 | // Finish the definition of the lambda, set isBeingDefined to false. | 
|  | 1786 | if (To->isLambda()) | 
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1787 | DefinitionCompleter(); | 
| Gabor Marton | e73805f | 2019-07-08 12:49:13 +0000 | [diff] [blame] | 1788 | return Result; | 
|  | 1789 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1790 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1791 | return Error::success(); | 
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1792 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1793 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1794 | To->startDefinition(); | 
| Gabor Marton | 17c3eaf | 2019-07-01 12:44:39 +0000 | [diff] [blame] | 1795 | // Complete the definition even if error is returned. | 
|  | 1796 | // The RecordDecl may be already part of the AST so it is better to | 
|  | 1797 | // have it in complete state even if something is wrong with it. | 
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 1798 | auto DefinitionCompleterScopeExit = | 
|  | 1799 | llvm::make_scope_exit(DefinitionCompleter); | 
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1800 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1801 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) | 
|  | 1802 | return Err; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1803 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1804 | // Add base classes. | 
| Gabor Marton | 17d3967 | 2018-11-26 15:54:08 +0000 | [diff] [blame] | 1805 | auto *ToCXX = dyn_cast<CXXRecordDecl>(To); | 
|  | 1806 | auto *FromCXX = dyn_cast<CXXRecordDecl>(From); | 
|  | 1807 | if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) { | 
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1808 |  | 
|  | 1809 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); | 
|  | 1810 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); | 
|  | 1811 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; | 
| Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1812 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; | 
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1813 | ToData.Aggregate = FromData.Aggregate; | 
|  | 1814 | ToData.PlainOldData = FromData.PlainOldData; | 
|  | 1815 | ToData.Empty = FromData.Empty; | 
|  | 1816 | ToData.Polymorphic = FromData.Polymorphic; | 
|  | 1817 | ToData.Abstract = FromData.Abstract; | 
|  | 1818 | ToData.IsStandardLayout = FromData.IsStandardLayout; | 
| Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1819 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; | 
|  | 1820 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; | 
|  | 1821 | ToData.HasBasesWithNonStaticDataMembers = | 
|  | 1822 | FromData.HasBasesWithNonStaticDataMembers; | 
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1823 | ToData.HasPrivateFields = FromData.HasPrivateFields; | 
|  | 1824 | ToData.HasProtectedFields = FromData.HasProtectedFields; | 
|  | 1825 | ToData.HasPublicFields = FromData.HasPublicFields; | 
|  | 1826 | ToData.HasMutableFields = FromData.HasMutableFields; | 
| Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1827 | ToData.HasVariantMembers = FromData.HasVariantMembers; | 
| Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1828 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; | 
| Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1829 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; | 
| Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1830 | ToData.HasUninitializedReferenceMember | 
|  | 1831 | = FromData.HasUninitializedReferenceMember; | 
| Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1832 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; | 
| Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1833 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; | 
|  | 1834 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; | 
| Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1835 | ToData.NeedOverloadResolutionForCopyConstructor | 
|  | 1836 | = FromData.NeedOverloadResolutionForCopyConstructor; | 
| Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1837 | ToData.NeedOverloadResolutionForMoveConstructor | 
|  | 1838 | = FromData.NeedOverloadResolutionForMoveConstructor; | 
|  | 1839 | ToData.NeedOverloadResolutionForMoveAssignment | 
|  | 1840 | = FromData.NeedOverloadResolutionForMoveAssignment; | 
|  | 1841 | ToData.NeedOverloadResolutionForDestructor | 
|  | 1842 | = FromData.NeedOverloadResolutionForDestructor; | 
| Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1843 | ToData.DefaultedCopyConstructorIsDeleted | 
|  | 1844 | = FromData.DefaultedCopyConstructorIsDeleted; | 
| Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1845 | ToData.DefaultedMoveConstructorIsDeleted | 
|  | 1846 | = FromData.DefaultedMoveConstructorIsDeleted; | 
|  | 1847 | ToData.DefaultedMoveAssignmentIsDeleted | 
|  | 1848 | = FromData.DefaultedMoveAssignmentIsDeleted; | 
|  | 1849 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; | 
| Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1850 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; | 
|  | 1851 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; | 
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1852 | ToData.HasConstexprNonCopyMoveConstructor | 
|  | 1853 | = FromData.HasConstexprNonCopyMoveConstructor; | 
| Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1854 | ToData.HasDefaultedDefaultConstructor | 
|  | 1855 | = FromData.HasDefaultedDefaultConstructor; | 
| Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1856 | ToData.DefaultedDefaultConstructorIsConstexpr | 
|  | 1857 | = FromData.DefaultedDefaultConstructorIsConstexpr; | 
| Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1858 | ToData.HasConstexprDefaultConstructor | 
|  | 1859 | = FromData.HasConstexprDefaultConstructor; | 
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1860 | ToData.HasNonLiteralTypeFieldsOrBases | 
|  | 1861 | = FromData.HasNonLiteralTypeFieldsOrBases; | 
| Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1862 | // ComputedVisibleConversions not imported. | 
| Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1863 | ToData.UserProvidedDefaultConstructor | 
|  | 1864 | = FromData.UserProvidedDefaultConstructor; | 
| Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1865 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; | 
| Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1866 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase | 
|  | 1867 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; | 
|  | 1868 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase | 
|  | 1869 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; | 
| Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1870 | ToData.ImplicitCopyAssignmentHasConstParam | 
|  | 1871 | = FromData.ImplicitCopyAssignmentHasConstParam; | 
|  | 1872 | ToData.HasDeclaredCopyConstructorWithConstParam | 
|  | 1873 | = FromData.HasDeclaredCopyConstructorWithConstParam; | 
|  | 1874 | ToData.HasDeclaredCopyAssignmentWithConstParam | 
|  | 1875 | = FromData.HasDeclaredCopyAssignmentWithConstParam; | 
| Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1876 |  | 
| Shafik Yaghmour | 16b9073 | 2019-04-26 18:51:28 +0000 | [diff] [blame] | 1877 | // Copy over the data stored in RecordDeclBits | 
|  | 1878 | ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions()); | 
|  | 1879 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1880 | SmallVector<CXXBaseSpecifier *, 4> Bases; | 
| Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1881 | for (const auto &Base1 : FromCXX->bases()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1882 | ExpectedType TyOrErr = import(Base1.getType()); | 
|  | 1883 | if (!TyOrErr) | 
|  | 1884 | return TyOrErr.takeError(); | 
| Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1885 |  | 
|  | 1886 | SourceLocation EllipsisLoc; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1887 | if (Base1.isPackExpansion()) { | 
|  | 1888 | if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc())) | 
|  | 1889 | EllipsisLoc = *LocOrErr; | 
|  | 1890 | else | 
|  | 1891 | return LocOrErr.takeError(); | 
|  | 1892 | } | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1893 |  | 
|  | 1894 | // Ensure that we have a definition for the base. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1895 | if (Error Err = | 
|  | 1896 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl())) | 
|  | 1897 | return Err; | 
|  | 1898 |  | 
|  | 1899 | auto RangeOrErr = import(Base1.getSourceRange()); | 
|  | 1900 | if (!RangeOrErr) | 
|  | 1901 | return RangeOrErr.takeError(); | 
|  | 1902 |  | 
|  | 1903 | auto TSIOrErr = import(Base1.getTypeSourceInfo()); | 
|  | 1904 | if (!TSIOrErr) | 
|  | 1905 | return TSIOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1906 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1907 | Bases.push_back( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1908 | new (Importer.getToContext()) CXXBaseSpecifier( | 
|  | 1909 | *RangeOrErr, | 
|  | 1910 | Base1.isVirtual(), | 
|  | 1911 | Base1.isBaseOfClass(), | 
|  | 1912 | Base1.getAccessSpecifierAsWritten(), | 
|  | 1913 | *TSIOrErr, | 
|  | 1914 | EllipsisLoc)); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1915 | } | 
|  | 1916 | if (!Bases.empty()) | 
| Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1917 | ToCXX->setBases(Bases.data(), Bases.size()); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1918 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1919 |  | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1920 | if (shouldForceImportDeclContext(Kind)) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1921 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | 
|  | 1922 | return Err; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1923 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1924 | return Error::success(); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1925 | } | 
|  | 1926 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1927 | Error ASTNodeImporter::ImportInitializer(VarDecl *From, VarDecl *To) { | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1928 | if (To->getAnyInitializer()) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1929 | return Error::success(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1930 |  | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1931 | Expr *FromInit = From->getInit(); | 
|  | 1932 | if (!FromInit) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1933 | return Error::success(); | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1934 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1935 | ExpectedExpr ToInitOrErr = import(FromInit); | 
|  | 1936 | if (!ToInitOrErr) | 
|  | 1937 | return ToInitOrErr.takeError(); | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1938 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1939 | To->setInit(*ToInitOrErr); | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 1940 | if (From->isInitKnownICE()) { | 
|  | 1941 | EvaluatedStmt *Eval = To->ensureEvaluatedStmt(); | 
|  | 1942 | Eval->CheckedICE = true; | 
|  | 1943 | Eval->IsICE = From->isInitICE(); | 
|  | 1944 | } | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1945 |  | 
|  | 1946 | // FIXME: Other bits to merge? | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1947 | return Error::success(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1948 | } | 
|  | 1949 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1950 | Error ASTNodeImporter::ImportDefinition( | 
|  | 1951 | EnumDecl *From, EnumDecl *To, ImportDefinitionKind Kind) { | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1952 | if (To->getDefinition() || To->isBeingDefined()) { | 
|  | 1953 | if (Kind == IDK_Everything) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1954 | return ImportDeclContext(From, /*ForceImport=*/true); | 
|  | 1955 | return Error::success(); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1956 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1957 |  | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1958 | To->startDefinition(); | 
|  | 1959 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1960 | if (Error Err = setTypedefNameForAnonDecl(From, To, Importer)) | 
|  | 1961 | return Err; | 
| Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1962 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1963 | ExpectedType ToTypeOrErr = | 
|  | 1964 | import(Importer.getFromContext().getTypeDeclType(From)); | 
|  | 1965 | if (!ToTypeOrErr) | 
|  | 1966 | return ToTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1967 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1968 | ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType()); | 
|  | 1969 | if (!ToPromotionTypeOrErr) | 
|  | 1970 | return ToPromotionTypeOrErr.takeError(); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1971 |  | 
|  | 1972 | if (shouldForceImportDeclContext(Kind)) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1973 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | 
|  | 1974 | return Err; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1975 |  | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1976 | // FIXME: we might need to merge the number of positive or negative bits | 
|  | 1977 | // if the enumerator lists don't match. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1978 | To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr, | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1979 | From->getNumPositiveBits(), | 
|  | 1980 | From->getNumNegativeBits()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1981 | return Error::success(); | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1982 | } | 
|  | 1983 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1984 | Error ASTNodeImporter::ImportTemplateArguments( | 
|  | 1985 | const TemplateArgument *FromArgs, unsigned NumFromArgs, | 
|  | 1986 | SmallVectorImpl<TemplateArgument> &ToArgs) { | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1987 | for (unsigned I = 0; I != NumFromArgs; ++I) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1988 | if (auto ToOrErr = import(FromArgs[I])) | 
|  | 1989 | ToArgs.push_back(*ToOrErr); | 
|  | 1990 | else | 
|  | 1991 | return ToOrErr.takeError(); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1992 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1993 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1994 | return Error::success(); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1995 | } | 
|  | 1996 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 1997 | // FIXME: Do not forget to remove this and use only 'import'. | 
|  | 1998 | Expected<TemplateArgument> | 
|  | 1999 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { | 
|  | 2000 | return import(From); | 
|  | 2001 | } | 
|  | 2002 |  | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2003 | template <typename InContainerTy> | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2004 | Error ASTNodeImporter::ImportTemplateArgumentListInfo( | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2005 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { | 
|  | 2006 | for (const auto &FromLoc : Container) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2007 | if (auto ToLocOrErr = import(FromLoc)) | 
|  | 2008 | ToTAInfo.addArgument(*ToLocOrErr); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2009 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2010 | return ToLocOrErr.takeError(); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2011 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2012 | return Error::success(); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2013 | } | 
|  | 2014 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2015 | static StructuralEquivalenceKind | 
|  | 2016 | getStructuralEquivalenceKind(const ASTImporter &Importer) { | 
|  | 2017 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal | 
|  | 2018 | : StructuralEquivalenceKind::Default; | 
|  | 2019 | } | 
|  | 2020 |  | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2021 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { | 
|  | 2022 | StructuralEquivalenceContext Ctx( | 
|  | 2023 | Importer.getFromContext(), Importer.getToContext(), | 
|  | 2024 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | 
|  | 2025 | false, Complain); | 
|  | 2026 | return Ctx.IsEquivalent(From, To); | 
|  | 2027 | } | 
|  | 2028 |  | 
|  | 2029 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2030 | RecordDecl *ToRecord, bool Complain) { | 
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2031 | // Eliminate a potential failure point where we attempt to re-import | 
|  | 2032 | // something we're trying to import while completing ToRecord. | 
|  | 2033 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); | 
|  | 2034 | if (ToOrigin) { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2035 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); | 
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2036 | if (ToOriginRecord) | 
|  | 2037 | ToRecord = ToOriginRecord; | 
|  | 2038 | } | 
|  | 2039 |  | 
| Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 2040 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | 
| Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 2041 | ToRecord->getASTContext(), | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2042 | Importer.getNonEquivalentDecls(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2043 | getStructuralEquivalenceKind(Importer), | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2044 | false, Complain); | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2045 | return Ctx.IsEquivalent(FromRecord, ToRecord); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2046 | } | 
|  | 2047 |  | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2048 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, | 
|  | 2049 | bool Complain) { | 
|  | 2050 | StructuralEquivalenceContext Ctx( | 
|  | 2051 | Importer.getFromContext(), Importer.getToContext(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2052 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | 
|  | 2053 | false, Complain); | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2054 | return Ctx.IsEquivalent(FromVar, ToVar); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2055 | } | 
|  | 2056 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2057 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { | 
| Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 2058 | // Eliminate a potential failure point where we attempt to re-import | 
| Raphael Isemann | fa26c20 | 2019-04-09 14:18:23 +0000 | [diff] [blame] | 2059 | // something we're trying to import while completing ToEnum. | 
| Shafik Yaghmour | e5094d6 | 2019-03-27 17:47:36 +0000 | [diff] [blame] | 2060 | if (Decl *ToOrigin = Importer.GetOriginalDecl(ToEnum)) | 
|  | 2061 | if (auto *ToOriginEnum = dyn_cast<EnumDecl>(ToOrigin)) | 
|  | 2062 | ToEnum = ToOriginEnum; | 
|  | 2063 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2064 | StructuralEquivalenceContext Ctx( | 
|  | 2065 | Importer.getFromContext(), Importer.getToContext(), | 
|  | 2066 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2067 | return Ctx.IsEquivalent(FromEnum, ToEnum); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2068 | } | 
|  | 2069 |  | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2070 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, | 
|  | 2071 | FunctionTemplateDecl *To) { | 
|  | 2072 | StructuralEquivalenceContext Ctx( | 
|  | 2073 | Importer.getFromContext(), Importer.getToContext(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2074 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | 
|  | 2075 | false, false); | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2076 | return Ctx.IsEquivalent(From, To); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 2077 | } | 
|  | 2078 |  | 
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2079 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { | 
|  | 2080 | StructuralEquivalenceContext Ctx( | 
|  | 2081 | Importer.getFromContext(), Importer.getToContext(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2082 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), | 
|  | 2083 | false, false); | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2084 | return Ctx.IsEquivalent(From, To); | 
| Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2085 | } | 
|  | 2086 |  | 
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2087 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2088 | EnumConstantDecl *ToEC) { | 
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2089 | const llvm::APSInt &FromVal = FromEC->getInitVal(); | 
|  | 2090 | const llvm::APSInt &ToVal = ToEC->getInitVal(); | 
|  | 2091 |  | 
|  | 2092 | return FromVal.isSigned() == ToVal.isSigned() && | 
|  | 2093 | FromVal.getBitWidth() == ToVal.getBitWidth() && | 
|  | 2094 | FromVal == ToVal; | 
|  | 2095 | } | 
|  | 2096 |  | 
|  | 2097 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2098 | ClassTemplateDecl *To) { | 
|  | 2099 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | 
|  | 2100 | Importer.getToContext(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2101 | Importer.getNonEquivalentDecls(), | 
|  | 2102 | getStructuralEquivalenceKind(Importer)); | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2103 | return Ctx.IsEquivalent(From, To); | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 2104 | } | 
|  | 2105 |  | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2106 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, | 
|  | 2107 | VarTemplateDecl *To) { | 
|  | 2108 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), | 
|  | 2109 | Importer.getToContext(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2110 | Importer.getNonEquivalentDecls(), | 
|  | 2111 | getStructuralEquivalenceKind(Importer)); | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2112 | return Ctx.IsEquivalent(From, To); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2113 | } | 
|  | 2114 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2115 | ExpectedDecl ASTNodeImporter::VisitDecl(Decl *D) { | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 2116 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | 
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2117 | << D->getDeclKindName(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2118 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | 
| Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 2119 | } | 
|  | 2120 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2121 | ExpectedDecl ASTNodeImporter::VisitImportDecl(ImportDecl *D) { | 
|  | 2122 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) | 
|  | 2123 | << D->getDeclKindName(); | 
|  | 2124 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | 
|  | 2125 | } | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2126 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2127 | ExpectedDecl ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { | 
|  | 2128 | // Import the context of this declaration. | 
|  | 2129 | DeclContext *DC, *LexicalDC; | 
|  | 2130 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 2131 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2132 |  | 
|  | 2133 | // Import the location of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2134 | ExpectedSLoc LocOrErr = import(D->getLocation()); | 
|  | 2135 | if (!LocOrErr) | 
|  | 2136 | return LocOrErr.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2137 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2138 | EmptyDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2139 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2140 | return ToD; | 
|  | 2141 |  | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2142 | ToD->setLexicalDeclContext(LexicalDC); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2143 | LexicalDC->addDeclInternal(ToD); | 
|  | 2144 | return ToD; | 
|  | 2145 | } | 
|  | 2146 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2147 | ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2148 | TranslationUnitDecl *ToD = | 
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2149 | Importer.getToContext().getTranslationUnitDecl(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2150 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2151 | Importer.MapImported(D, ToD); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2152 |  | 
| Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 2153 | return ToD; | 
|  | 2154 | } | 
|  | 2155 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2156 | ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { | 
|  | 2157 | ExpectedSLoc LocOrErr = import(D->getLocation()); | 
|  | 2158 | if (!LocOrErr) | 
|  | 2159 | return LocOrErr.takeError(); | 
|  | 2160 | auto ColonLocOrErr = import(D->getColonLoc()); | 
|  | 2161 | if (!ColonLocOrErr) | 
|  | 2162 | return ColonLocOrErr.takeError(); | 
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2163 |  | 
|  | 2164 | // Import the context of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2165 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); | 
|  | 2166 | if (!DCOrErr) | 
|  | 2167 | return DCOrErr.takeError(); | 
|  | 2168 | DeclContext *DC = *DCOrErr; | 
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2169 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2170 | AccessSpecDecl *ToD; | 
|  | 2171 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2172 | DC, *LocOrErr, *ColonLocOrErr)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2173 | return ToD; | 
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2174 |  | 
|  | 2175 | // Lexical DeclContext and Semantic DeclContext | 
|  | 2176 | // is always the same for the accessSpec. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2177 | ToD->setLexicalDeclContext(DC); | 
|  | 2178 | DC->addDeclInternal(ToD); | 
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2179 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2180 | return ToD; | 
| Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 2181 | } | 
|  | 2182 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2183 | ExpectedDecl ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { | 
|  | 2184 | auto DCOrErr = Importer.ImportContext(D->getDeclContext()); | 
|  | 2185 | if (!DCOrErr) | 
|  | 2186 | return DCOrErr.takeError(); | 
|  | 2187 | DeclContext *DC = *DCOrErr; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2188 | DeclContext *LexicalDC = DC; | 
|  | 2189 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2190 | SourceLocation ToLocation, ToRParenLoc; | 
|  | 2191 | Expr *ToAssertExpr; | 
|  | 2192 | StringLiteral *ToMessage; | 
|  | 2193 | if (auto Imp = importSeq( | 
|  | 2194 | D->getLocation(), D->getAssertExpr(), D->getMessage(), D->getRParenLoc())) | 
|  | 2195 | std::tie(ToLocation, ToAssertExpr, ToMessage, ToRParenLoc) = *Imp; | 
|  | 2196 | else | 
|  | 2197 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2198 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2199 | StaticAssertDecl *ToD; | 
|  | 2200 | if (GetImportedOrCreateDecl( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2201 | ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage, | 
|  | 2202 | ToRParenLoc, D->isFailed())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2203 | return ToD; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2204 |  | 
|  | 2205 | ToD->setLexicalDeclContext(LexicalDC); | 
|  | 2206 | LexicalDC->addDeclInternal(ToD); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2207 | return ToD; | 
|  | 2208 | } | 
|  | 2209 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2210 | ExpectedDecl ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2211 | // Import the major distinguishing characteristics of this namespace. | 
|  | 2212 | DeclContext *DC, *LexicalDC; | 
|  | 2213 | DeclarationName Name; | 
|  | 2214 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2215 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2216 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 2217 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2218 | if (ToD) | 
|  | 2219 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2220 |  | 
|  | 2221 | NamespaceDecl *MergeWithNamespace = nullptr; | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2222 | if (!Name) { | 
|  | 2223 | // This is an anonymous namespace. Adopt an existing anonymous | 
|  | 2224 | // namespace if we can. | 
|  | 2225 | // FIXME: Not testable. | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2226 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2227 | MergeWithNamespace = TU->getAnonymousNamespace(); | 
|  | 2228 | else | 
|  | 2229 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); | 
|  | 2230 | } else { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2231 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2232 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2233 | for (auto *FoundDecl : FoundDecls) { | 
|  | 2234 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2235 | continue; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2236 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2237 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2238 | MergeWithNamespace = FoundNS; | 
|  | 2239 | ConflictingDecls.clear(); | 
|  | 2240 | break; | 
|  | 2241 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2242 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2243 | ConflictingDecls.push_back(FoundDecl); | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2244 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2245 |  | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2246 | if (!ConflictingDecls.empty()) { | 
| John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 2247 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2248 | ConflictingDecls.data(), | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2249 | ConflictingDecls.size()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2250 | if (!Name) | 
|  | 2251 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2252 | } | 
|  | 2253 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2254 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2255 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | 
|  | 2256 | if (!BeginLocOrErr) | 
|  | 2257 | return BeginLocOrErr.takeError(); | 
|  | 2258 |  | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2259 | // Create the "to" namespace, if needed. | 
|  | 2260 | NamespaceDecl *ToNamespace = MergeWithNamespace; | 
|  | 2261 | if (!ToNamespace) { | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2262 | if (GetImportedOrCreateDecl( | 
|  | 2263 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2264 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2265 | /*PrevDecl=*/nullptr)) | 
|  | 2266 | return ToNamespace; | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2267 | ToNamespace->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2268 | LexicalDC->addDeclInternal(ToNamespace); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2269 |  | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2270 | // If this is an anonymous namespace, register it as the anonymous | 
|  | 2271 | // namespace within its context. | 
|  | 2272 | if (!Name) { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2273 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2274 | TU->setAnonymousNamespace(ToNamespace); | 
|  | 2275 | else | 
|  | 2276 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); | 
|  | 2277 | } | 
|  | 2278 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2279 | Importer.MapImported(D, ToNamespace); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2280 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2281 | if (Error Err = ImportDeclContext(D)) | 
|  | 2282 | return std::move(Err); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2283 |  | 
| Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 2284 | return ToNamespace; | 
|  | 2285 | } | 
|  | 2286 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2287 | ExpectedDecl ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2288 | // Import the major distinguishing characteristics of this namespace. | 
|  | 2289 | DeclContext *DC, *LexicalDC; | 
|  | 2290 | DeclarationName Name; | 
|  | 2291 | SourceLocation Loc; | 
|  | 2292 | NamedDecl *LookupD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2293 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) | 
|  | 2294 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2295 | if (LookupD) | 
|  | 2296 | return LookupD; | 
|  | 2297 |  | 
|  | 2298 | // NOTE: No conflict resolution is done for namespace aliases now. | 
|  | 2299 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2300 | SourceLocation ToNamespaceLoc, ToAliasLoc, ToTargetNameLoc; | 
|  | 2301 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 2302 | NamespaceDecl *ToNamespace; | 
|  | 2303 | if (auto Imp = importSeq( | 
|  | 2304 | D->getNamespaceLoc(), D->getAliasLoc(), D->getQualifierLoc(), | 
|  | 2305 | D->getTargetNameLoc(), D->getNamespace())) | 
|  | 2306 | std::tie( | 
|  | 2307 | ToNamespaceLoc, ToAliasLoc, ToQualifierLoc, ToTargetNameLoc, | 
|  | 2308 | ToNamespace) = *Imp; | 
|  | 2309 | else | 
|  | 2310 | return Imp.takeError(); | 
|  | 2311 | IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier()); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2312 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2313 | NamespaceAliasDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2314 | if (GetImportedOrCreateDecl( | 
|  | 2315 | ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc, | 
|  | 2316 | ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2317 | return ToD; | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2318 |  | 
|  | 2319 | ToD->setLexicalDeclContext(LexicalDC); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2320 | LexicalDC->addDeclInternal(ToD); | 
|  | 2321 |  | 
|  | 2322 | return ToD; | 
|  | 2323 | } | 
|  | 2324 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2325 | ExpectedDecl | 
|  | 2326 | ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2327 | // Import the major distinguishing characteristics of this typedef. | 
|  | 2328 | DeclContext *DC, *LexicalDC; | 
|  | 2329 | DeclarationName Name; | 
|  | 2330 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2331 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2332 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 2333 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2334 | if (ToD) | 
|  | 2335 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2336 |  | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2337 | // If this typedef is not in block scope, determine whether we've | 
|  | 2338 | // seen a typedef with the same name (that we can merge with) or any | 
|  | 2339 | // other entity by that name (which name lookup could conflict with). | 
|  | 2340 | if (!DC->isFunctionOrMethod()) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2341 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2342 | unsigned IDNS = Decl::IDNS_Ordinary; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2343 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2344 | for (auto *FoundDecl : FoundDecls) { | 
|  | 2345 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2346 | continue; | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2347 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { | 
| Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2348 | QualType FromUT = D->getUnderlyingType(); | 
|  | 2349 | QualType FoundUT = FoundTypedef->getUnderlyingType(); | 
|  | 2350 | if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) { | 
|  | 2351 | // If the "From" context has a complete underlying type but we | 
|  | 2352 | // already have a complete underlying type then return with that. | 
|  | 2353 | if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType()) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2354 | return Importer.MapImported(D, FoundTypedef); | 
| Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2355 | } | 
| Gabor Marton | dd2b76e | 2019-06-11 13:35:25 +0000 | [diff] [blame] | 2356 | // FIXME Handle redecl chain. When you do that make consistent changes | 
|  | 2357 | // in ASTImporterLookupTable too. | 
| Gabor Marton | b93baf6 | 2018-11-27 09:51:36 +0000 | [diff] [blame] | 2358 | break; | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2359 | } | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2360 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2361 | ConflictingDecls.push_back(FoundDecl); | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2362 | } | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2363 |  | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2364 | if (!ConflictingDecls.empty()) { | 
|  | 2365 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2366 | ConflictingDecls.data(), | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2367 | ConflictingDecls.size()); | 
|  | 2368 | if (!Name) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2369 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2370 | } | 
|  | 2371 | } | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2372 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2373 | QualType ToUnderlyingType; | 
|  | 2374 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 2375 | SourceLocation ToBeginLoc; | 
|  | 2376 | if (auto Imp = importSeq( | 
|  | 2377 | D->getUnderlyingType(), D->getTypeSourceInfo(), D->getBeginLoc())) | 
|  | 2378 | std::tie(ToUnderlyingType, ToTypeSourceInfo, ToBeginLoc) = *Imp; | 
|  | 2379 | else | 
|  | 2380 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2381 |  | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2382 | // Create the new typedef node. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2383 | // FIXME: ToUnderlyingType is not used. | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2384 | TypedefNameDecl *ToTypedef; | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2385 | if (IsAlias) { | 
|  | 2386 | if (GetImportedOrCreateDecl<TypeAliasDecl>( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2387 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, | 
|  | 2388 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2389 | return ToTypedef; | 
|  | 2390 | } else if (GetImportedOrCreateDecl<TypedefDecl>( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2391 | ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc, | 
|  | 2392 | Name.getAsIdentifierInfo(), ToTypeSourceInfo)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2393 | return ToTypedef; | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2394 |  | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2395 | ToTypedef->setAccess(D->getAccess()); | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2396 | ToTypedef->setLexicalDeclContext(LexicalDC); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2397 |  | 
|  | 2398 | // Templated declarations should not appear in DeclContext. | 
|  | 2399 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; | 
|  | 2400 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) | 
|  | 2401 | LexicalDC->addDeclInternal(ToTypedef); | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2402 |  | 
| Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 2403 | return ToTypedef; | 
|  | 2404 | } | 
|  | 2405 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2406 | ExpectedDecl ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2407 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); | 
|  | 2408 | } | 
|  | 2409 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2410 | ExpectedDecl ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2411 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); | 
|  | 2412 | } | 
|  | 2413 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2414 | ExpectedDecl | 
|  | 2415 | ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2416 | // Import the major distinguishing characteristics of this typedef. | 
|  | 2417 | DeclContext *DC, *LexicalDC; | 
|  | 2418 | DeclarationName Name; | 
|  | 2419 | SourceLocation Loc; | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2420 | NamedDecl *FoundD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2421 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) | 
|  | 2422 | return std::move(Err); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2423 | if (FoundD) | 
|  | 2424 | return FoundD; | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2425 |  | 
|  | 2426 | // If this typedef is not in block scope, determine whether we've | 
|  | 2427 | // seen a typedef with the same name (that we can merge with) or any | 
|  | 2428 | // other entity by that name (which name lookup could conflict with). | 
|  | 2429 | if (!DC->isFunctionOrMethod()) { | 
|  | 2430 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
|  | 2431 | unsigned IDNS = Decl::IDNS_Ordinary; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2432 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2433 | for (auto *FoundDecl : FoundDecls) { | 
|  | 2434 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2435 | continue; | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2436 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2437 | return Importer.MapImported(D, FoundAlias); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2438 | ConflictingDecls.push_back(FoundDecl); | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2439 | } | 
|  | 2440 |  | 
|  | 2441 | if (!ConflictingDecls.empty()) { | 
|  | 2442 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | 
|  | 2443 | ConflictingDecls.data(), | 
|  | 2444 | ConflictingDecls.size()); | 
|  | 2445 | if (!Name) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2446 | return make_error<ImportError>(ImportError::NameConflict); | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2447 | } | 
|  | 2448 | } | 
|  | 2449 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2450 | TemplateParameterList *ToTemplateParameters; | 
|  | 2451 | TypeAliasDecl *ToTemplatedDecl; | 
|  | 2452 | if (auto Imp = importSeq(D->getTemplateParameters(), D->getTemplatedDecl())) | 
|  | 2453 | std::tie(ToTemplateParameters, ToTemplatedDecl) = *Imp; | 
|  | 2454 | else | 
|  | 2455 | return Imp.takeError(); | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2456 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2457 | TypeAliasTemplateDecl *ToAlias; | 
|  | 2458 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2459 | Name, ToTemplateParameters, ToTemplatedDecl)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2460 | return ToAlias; | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2461 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2462 | ToTemplatedDecl->setDescribedAliasTemplate(ToAlias); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2463 |  | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2464 | ToAlias->setAccess(D->getAccess()); | 
|  | 2465 | ToAlias->setLexicalDeclContext(LexicalDC); | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2466 | LexicalDC->addDeclInternal(ToAlias); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2467 | return ToAlias; | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2468 | } | 
|  | 2469 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2470 | ExpectedDecl ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2471 | // Import the major distinguishing characteristics of this label. | 
|  | 2472 | DeclContext *DC, *LexicalDC; | 
|  | 2473 | DeclarationName Name; | 
|  | 2474 | SourceLocation Loc; | 
|  | 2475 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2476 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 2477 | return std::move(Err); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2478 | if (ToD) | 
|  | 2479 | return ToD; | 
|  | 2480 |  | 
|  | 2481 | assert(LexicalDC->isFunctionOrMethod()); | 
|  | 2482 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2483 | LabelDecl *ToLabel; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2484 | if (D->isGnuLocal()) { | 
|  | 2485 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | 
|  | 2486 | if (!BeginLocOrErr) | 
|  | 2487 | return BeginLocOrErr.takeError(); | 
|  | 2488 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, | 
|  | 2489 | Name.getAsIdentifierInfo(), *BeginLocOrErr)) | 
|  | 2490 | return ToLabel; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2491 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2492 | } else { | 
|  | 2493 | if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc, | 
|  | 2494 | Name.getAsIdentifierInfo())) | 
|  | 2495 | return ToLabel; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2496 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2497 | } | 
|  | 2498 |  | 
|  | 2499 | Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt()); | 
|  | 2500 | if (!ToStmtOrErr) | 
|  | 2501 | return ToStmtOrErr.takeError(); | 
|  | 2502 |  | 
|  | 2503 | ToLabel->setStmt(*ToStmtOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2504 | ToLabel->setLexicalDeclContext(LexicalDC); | 
|  | 2505 | LexicalDC->addDeclInternal(ToLabel); | 
|  | 2506 | return ToLabel; | 
|  | 2507 | } | 
|  | 2508 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2509 | ExpectedDecl ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2510 | // Import the major distinguishing characteristics of this enum. | 
|  | 2511 | DeclContext *DC, *LexicalDC; | 
|  | 2512 | DeclarationName Name; | 
|  | 2513 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2514 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2515 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 2516 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2517 | if (ToD) | 
|  | 2518 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2519 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2520 | // Figure out what enum name we're looking for. | 
|  | 2521 | unsigned IDNS = Decl::IDNS_Tag; | 
|  | 2522 | DeclarationName SearchName = Name; | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2523 | if (!SearchName && D->getTypedefNameForAnonDecl()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2524 | if (Error Err = importInto( | 
|  | 2525 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) | 
|  | 2526 | return std::move(Err); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2527 | IDNS = Decl::IDNS_Ordinary; | 
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2528 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2529 | IDNS |= Decl::IDNS_Ordinary; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2530 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2531 | // We may already have an enum of the same name; try to find and match it. | 
|  | 2532 | if (!DC->isFunctionOrMethod() && SearchName) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2533 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2534 | auto FoundDecls = | 
|  | 2535 | Importer.findDeclsInToCtx(DC, SearchName); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2536 | for (auto *FoundDecl : FoundDecls) { | 
|  | 2537 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2538 | continue; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2539 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2540 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2541 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2542 | FoundDecl = Tag->getDecl(); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2543 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2544 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2545 | if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) { | 
| Balazs Keri | eb79b25 | 2019-07-09 11:08:18 +0000 | [diff] [blame] | 2546 | if (!hasSameVisibilityContext(FoundEnum, D)) | 
|  | 2547 | continue; | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2548 | if (IsStructuralMatch(D, FoundEnum)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2549 | return Importer.MapImported(D, FoundEnum); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2550 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2551 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2552 | ConflictingDecls.push_back(FoundDecl); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2553 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2554 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2555 | if (!ConflictingDecls.empty()) { | 
| Shafik Yaghmour | d426312 | 2019-04-08 20:50:21 +0000 | [diff] [blame] | 2556 | Name = Importer.HandleNameConflict(SearchName, DC, IDNS, | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2557 | ConflictingDecls.data(), | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2558 | ConflictingDecls.size()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2559 | if (!Name) | 
|  | 2560 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2561 | } | 
|  | 2562 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2563 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2564 | SourceLocation ToBeginLoc; | 
|  | 2565 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 2566 | QualType ToIntegerType; | 
|  | 2567 | if (auto Imp = importSeq( | 
|  | 2568 | D->getBeginLoc(), D->getQualifierLoc(), D->getIntegerType())) | 
|  | 2569 | std::tie(ToBeginLoc, ToQualifierLoc, ToIntegerType) = *Imp; | 
|  | 2570 | else | 
|  | 2571 | return Imp.takeError(); | 
|  | 2572 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2573 | // Create the enum declaration. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2574 | EnumDecl *D2; | 
|  | 2575 | if (GetImportedOrCreateDecl( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2576 | D2, D, Importer.getToContext(), DC, ToBeginLoc, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2577 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), | 
|  | 2578 | D->isScopedUsingClassTag(), D->isFixed())) | 
|  | 2579 | return D2; | 
|  | 2580 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2581 | D2->setQualifierInfo(ToQualifierLoc); | 
|  | 2582 | D2->setIntegerType(ToIntegerType); | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2583 | D2->setAccess(D->getAccess()); | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2584 | D2->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2585 | LexicalDC->addDeclInternal(D2); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2586 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2587 | // Import the definition | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2588 | if (D->isCompleteDefinition()) | 
|  | 2589 | if (Error Err = ImportDefinition(D, D2)) | 
|  | 2590 | return std::move(Err); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2591 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2592 | return D2; | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2593 | } | 
|  | 2594 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2595 | ExpectedDecl ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { | 
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 2596 | bool IsFriendTemplate = false; | 
|  | 2597 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | 
|  | 2598 | IsFriendTemplate = | 
|  | 2599 | DCXX->getDescribedClassTemplate() && | 
|  | 2600 | DCXX->getDescribedClassTemplate()->getFriendObjectKind() != | 
|  | 2601 | Decl::FOK_None; | 
|  | 2602 | } | 
|  | 2603 |  | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2604 | // Import the major distinguishing characteristics of this record. | 
|  | 2605 | DeclContext *DC, *LexicalDC; | 
|  | 2606 | DeclarationName Name; | 
|  | 2607 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2608 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2609 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 2610 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2611 | if (ToD) | 
|  | 2612 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2613 |  | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2614 | // Figure out what structure name we're looking for. | 
|  | 2615 | unsigned IDNS = Decl::IDNS_Tag; | 
|  | 2616 | DeclarationName SearchName = Name; | 
| Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2617 | if (!SearchName && D->getTypedefNameForAnonDecl()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2618 | if (Error Err = importInto( | 
|  | 2619 | SearchName, D->getTypedefNameForAnonDecl()->getDeclName())) | 
|  | 2620 | return std::move(Err); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2621 | IDNS = Decl::IDNS_Ordinary; | 
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2622 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2623 | IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend; | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2624 |  | 
|  | 2625 | // 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] | 2626 | RecordDecl *PrevDecl = nullptr; | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2627 | if (!DC->isFunctionOrMethod()) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2628 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2629 | auto FoundDecls = | 
|  | 2630 | Importer.findDeclsInToCtx(DC, SearchName); | 
| Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2631 | if (!FoundDecls.empty()) { | 
| Gabor Marton | 41e3892 | 2019-03-05 11:23:24 +0000 | [diff] [blame] | 2632 | // We're going to have to compare D against potentially conflicting Decls, | 
|  | 2633 | // so complete it. | 
| Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2634 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) | 
|  | 2635 | D->getASTContext().getExternalSource()->CompleteType(D); | 
|  | 2636 | } | 
|  | 2637 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2638 | for (auto *FoundDecl : FoundDecls) { | 
|  | 2639 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2640 | continue; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2641 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2642 | Decl *Found = FoundDecl; | 
|  | 2643 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { | 
|  | 2644 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2645 | Found = Tag->getDecl(); | 
|  | 2646 | } | 
| Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2647 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2648 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2649 | // Do not emit false positive diagnostic in case of unnamed | 
|  | 2650 | // struct/union and in case of anonymous structs.  Would be false | 
|  | 2651 | // because there may be several anonymous/unnamed structs in a class. | 
|  | 2652 | // E.g. these are both valid: | 
|  | 2653 | //  struct A { // unnamed structs | 
|  | 2654 | //    struct { struct A *next; } entry0; | 
|  | 2655 | //    struct { struct A *next; } entry1; | 
|  | 2656 | //  }; | 
|  | 2657 | //  struct X { struct { int a; }; struct { int b; }; }; // anon structs | 
|  | 2658 | if (!SearchName) | 
| Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2659 | if (!IsStructuralMatch(D, FoundRecord, false)) | 
|  | 2660 | continue; | 
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2661 |  | 
| Balazs Keri | c827219 | 2019-05-27 09:36:00 +0000 | [diff] [blame] | 2662 | if (!hasSameVisibilityContext(FoundRecord, D)) | 
|  | 2663 | continue; | 
|  | 2664 |  | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2665 | if (IsStructuralMatch(D, FoundRecord)) { | 
|  | 2666 | RecordDecl *FoundDef = FoundRecord->getDefinition(); | 
|  | 2667 | if (D->isThisDeclarationADefinition() && FoundDef) { | 
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2668 | // FIXME: Structural equivalence check should check for same | 
|  | 2669 | // user-defined methods. | 
|  | 2670 | Importer.MapImported(D, FoundDef); | 
|  | 2671 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | 
|  | 2672 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); | 
|  | 2673 | assert(FoundCXX && "Record type mismatch"); | 
|  | 2674 |  | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2675 | if (!Importer.isMinimalImport()) | 
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2676 | // FoundDef may not have every implicit method that D has | 
|  | 2677 | // because implicit methods are created only if they are used. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2678 | if (Error Err = ImportImplicitMethods(DCXX, FoundCXX)) | 
|  | 2679 | return std::move(Err); | 
| Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2680 | } | 
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2681 | } | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2682 | PrevDecl = FoundRecord->getMostRecentDecl(); | 
|  | 2683 | break; | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2684 | } | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2685 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2686 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2687 | ConflictingDecls.push_back(FoundDecl); | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2688 | } // for | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2689 |  | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2690 | if (!ConflictingDecls.empty() && SearchName) { | 
| Shafik Yaghmour | 468724e | 2019-05-24 16:53:44 +0000 | [diff] [blame] | 2691 | Name = Importer.HandleNameConflict(SearchName, DC, IDNS, | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2692 | ConflictingDecls.data(), | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2693 | ConflictingDecls.size()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2694 | if (!Name) | 
|  | 2695 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2696 | } | 
|  | 2697 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2698 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2699 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | 
|  | 2700 | if (!BeginLocOrErr) | 
|  | 2701 | return BeginLocOrErr.takeError(); | 
|  | 2702 |  | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2703 | // Create the record declaration. | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2704 | RecordDecl *D2 = nullptr; | 
|  | 2705 | CXXRecordDecl *D2CXX = nullptr; | 
|  | 2706 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { | 
|  | 2707 | if (DCXX->isLambda()) { | 
|  | 2708 | auto TInfoOrErr = import(DCXX->getLambdaTypeInfo()); | 
|  | 2709 | if (!TInfoOrErr) | 
|  | 2710 | return TInfoOrErr.takeError(); | 
|  | 2711 | if (GetImportedOrCreateSpecialDecl( | 
|  | 2712 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), | 
|  | 2713 | DC, *TInfoOrErr, Loc, DCXX->isDependentLambda(), | 
|  | 2714 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) | 
|  | 2715 | return D2CXX; | 
|  | 2716 | ExpectedDecl CDeclOrErr = import(DCXX->getLambdaContextDecl()); | 
|  | 2717 | if (!CDeclOrErr) | 
|  | 2718 | return CDeclOrErr.takeError(); | 
|  | 2719 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), *CDeclOrErr); | 
|  | 2720 | } else if (DCXX->isInjectedClassName()) { | 
|  | 2721 | // We have to be careful to do a similar dance to the one in | 
|  | 2722 | // Sema::ActOnStartCXXMemberDeclarations | 
|  | 2723 | const bool DelayTypeCreation = true; | 
|  | 2724 | if (GetImportedOrCreateDecl( | 
|  | 2725 | D2CXX, D, Importer.getToContext(), D->getTagKind(), DC, | 
|  | 2726 | *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(), | 
|  | 2727 | cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation)) | 
|  | 2728 | return D2CXX; | 
|  | 2729 | Importer.getToContext().getTypeDeclType( | 
|  | 2730 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); | 
|  | 2731 | } else { | 
|  | 2732 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), | 
|  | 2733 | D->getTagKind(), DC, *BeginLocOrErr, Loc, | 
|  | 2734 | Name.getAsIdentifierInfo(), | 
|  | 2735 | cast_or_null<CXXRecordDecl>(PrevDecl))) | 
|  | 2736 | return D2CXX; | 
|  | 2737 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2738 |  | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2739 | D2 = D2CXX; | 
|  | 2740 | D2->setAccess(D->getAccess()); | 
|  | 2741 | D2->setLexicalDeclContext(LexicalDC); | 
|  | 2742 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) | 
|  | 2743 | LexicalDC->addDeclInternal(D2); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2744 |  | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2745 | if (LexicalDC != DC && D->isInIdentifierNamespace(Decl::IDNS_TagFriend)) | 
|  | 2746 | DC->makeDeclVisibleInContext(D2); | 
|  | 2747 |  | 
|  | 2748 | if (ClassTemplateDecl *FromDescribed = | 
|  | 2749 | DCXX->getDescribedClassTemplate()) { | 
|  | 2750 | ClassTemplateDecl *ToDescribed; | 
|  | 2751 | if (Error Err = importInto(ToDescribed, FromDescribed)) | 
|  | 2752 | return std::move(Err); | 
|  | 2753 | D2CXX->setDescribedClassTemplate(ToDescribed); | 
|  | 2754 | if (!DCXX->isInjectedClassName() && !IsFriendTemplate) { | 
|  | 2755 | // In a record describing a template the type should be an | 
|  | 2756 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the | 
|  | 2757 | // previously set type to the correct value here (ToDescribed is not | 
|  | 2758 | // available at record create). | 
|  | 2759 | // FIXME: The previous type is cleared but not removed from | 
|  | 2760 | // ASTContext's internal storage. | 
|  | 2761 | CXXRecordDecl *Injected = nullptr; | 
|  | 2762 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { | 
|  | 2763 | auto *Record = dyn_cast<CXXRecordDecl>(Found); | 
|  | 2764 | if (Record && Record->isInjectedClassName()) { | 
|  | 2765 | Injected = Record; | 
|  | 2766 | break; | 
| Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2767 | } | 
|  | 2768 | } | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2769 | // Create an injected type for the whole redecl chain. | 
|  | 2770 | SmallVector<Decl *, 2> Redecls = | 
|  | 2771 | getCanonicalForwardRedeclChain(D2CXX); | 
|  | 2772 | for (auto *R : Redecls) { | 
|  | 2773 | auto *RI = cast<CXXRecordDecl>(R); | 
|  | 2774 | RI->setTypeForDecl(nullptr); | 
|  | 2775 | // Below we create a new injected type and assign that to the | 
|  | 2776 | // canonical decl, subsequent declarations in the chain will reuse | 
|  | 2777 | // that type. | 
|  | 2778 | Importer.getToContext().getInjectedClassNameType( | 
|  | 2779 | RI, ToDescribed->getInjectedClassNameSpecialization()); | 
|  | 2780 | } | 
|  | 2781 | // Set the new type for the previous injected decl too. | 
|  | 2782 | if (Injected) { | 
|  | 2783 | Injected->setTypeForDecl(nullptr); | 
|  | 2784 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); | 
|  | 2785 | } | 
|  | 2786 | } | 
|  | 2787 | } else if (MemberSpecializationInfo *MemberInfo = | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2788 | DCXX->getMemberSpecializationInfo()) { | 
|  | 2789 | TemplateSpecializationKind SK = | 
|  | 2790 | MemberInfo->getTemplateSpecializationKind(); | 
|  | 2791 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2792 |  | 
|  | 2793 | if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst)) | 
|  | 2794 | D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK); | 
|  | 2795 | else | 
|  | 2796 | return ToInstOrErr.takeError(); | 
|  | 2797 |  | 
|  | 2798 | if (ExpectedSLoc POIOrErr = | 
|  | 2799 | import(MemberInfo->getPointOfInstantiation())) | 
|  | 2800 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( | 
|  | 2801 | *POIOrErr); | 
|  | 2802 | else | 
|  | 2803 | return POIOrErr.takeError(); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2804 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2805 |  | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2806 | } else { | 
|  | 2807 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), | 
|  | 2808 | D->getTagKind(), DC, *BeginLocOrErr, Loc, | 
|  | 2809 | Name.getAsIdentifierInfo(), PrevDecl)) | 
|  | 2810 | return D2; | 
|  | 2811 | D2->setLexicalDeclContext(LexicalDC); | 
|  | 2812 | LexicalDC->addDeclInternal(D2); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2813 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2814 |  | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 2815 | if (auto QualifierLocOrErr = import(D->getQualifierLoc())) | 
|  | 2816 | D2->setQualifierInfo(*QualifierLocOrErr); | 
|  | 2817 | else | 
|  | 2818 | return QualifierLocOrErr.takeError(); | 
|  | 2819 |  | 
|  | 2820 | if (D->isAnonymousStructOrUnion()) | 
|  | 2821 | D2->setAnonymousStructOrUnion(true); | 
| Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2822 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2823 | if (D->isCompleteDefinition()) | 
|  | 2824 | if (Error Err = ImportDefinition(D, D2, IDK_Default)) | 
|  | 2825 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2826 |  | 
| Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2827 | return D2; | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2828 | } | 
|  | 2829 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2830 | ExpectedDecl ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2831 | // Import the major distinguishing characteristics of this enumerator. | 
|  | 2832 | DeclContext *DC, *LexicalDC; | 
|  | 2833 | DeclarationName Name; | 
|  | 2834 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2835 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2836 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 2837 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2838 | if (ToD) | 
|  | 2839 | return ToD; | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2840 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2841 | // Determine whether there are any other declarations with the same name and | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2842 | // in the same context. | 
|  | 2843 | if (!LexicalDC->isFunctionOrMethod()) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2844 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2845 | unsigned IDNS = Decl::IDNS_Ordinary; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 2846 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2847 | for (auto *FoundDecl : FoundDecls) { | 
|  | 2848 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2849 | continue; | 
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2850 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2851 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { | 
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2852 | if (IsStructuralMatch(D, FoundEnumConstant)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2853 | return Importer.MapImported(D, FoundEnumConstant); | 
| Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2854 | } | 
|  | 2855 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2856 | ConflictingDecls.push_back(FoundDecl); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2857 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2858 |  | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2859 | if (!ConflictingDecls.empty()) { | 
|  | 2860 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2861 | ConflictingDecls.data(), | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2862 | ConflictingDecls.size()); | 
|  | 2863 | if (!Name) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2864 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2865 | } | 
|  | 2866 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2867 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2868 | ExpectedType TypeOrErr = import(D->getType()); | 
|  | 2869 | if (!TypeOrErr) | 
|  | 2870 | return TypeOrErr.takeError(); | 
|  | 2871 |  | 
|  | 2872 | ExpectedExpr InitOrErr = import(D->getInitExpr()); | 
|  | 2873 | if (!InitOrErr) | 
|  | 2874 | return InitOrErr.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2875 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2876 | EnumConstantDecl *ToEnumerator; | 
|  | 2877 | if (GetImportedOrCreateDecl( | 
|  | 2878 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2879 | Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2880 | return ToEnumerator; | 
|  | 2881 |  | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2882 | ToEnumerator->setAccess(D->getAccess()); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2883 | ToEnumerator->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2884 | LexicalDC->addDeclInternal(ToEnumerator); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2885 | return ToEnumerator; | 
|  | 2886 | } | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2887 |  | 
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 2888 | Error ASTNodeImporter::ImportTemplateParameterLists(const DeclaratorDecl *FromD, | 
|  | 2889 | DeclaratorDecl *ToD) { | 
|  | 2890 | unsigned int Num = FromD->getNumTemplateParameterLists(); | 
|  | 2891 | if (Num == 0) | 
|  | 2892 | return Error::success(); | 
|  | 2893 | SmallVector<TemplateParameterList *, 2> ToTPLists(Num); | 
|  | 2894 | for (unsigned int I = 0; I < Num; ++I) | 
|  | 2895 | if (Expected<TemplateParameterList *> ToTPListOrErr = | 
|  | 2896 | import(FromD->getTemplateParameterList(I))) | 
|  | 2897 | ToTPLists[I] = *ToTPListOrErr; | 
|  | 2898 | else | 
|  | 2899 | return ToTPListOrErr.takeError(); | 
|  | 2900 | ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists); | 
|  | 2901 | return Error::success(); | 
|  | 2902 | } | 
|  | 2903 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2904 | Error ASTNodeImporter::ImportTemplateInformation( | 
|  | 2905 | FunctionDecl *FromFD, FunctionDecl *ToFD) { | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2906 | switch (FromFD->getTemplatedKind()) { | 
|  | 2907 | case FunctionDecl::TK_NonTemplate: | 
|  | 2908 | case FunctionDecl::TK_FunctionTemplate: | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2909 | return Error::success(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2910 |  | 
|  | 2911 | case FunctionDecl::TK_MemberSpecialization: { | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2912 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2913 |  | 
|  | 2914 | if (Expected<FunctionDecl *> InstFDOrErr = | 
|  | 2915 | import(FromFD->getInstantiatedFromMemberFunction())) | 
|  | 2916 | ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK); | 
|  | 2917 | else | 
|  | 2918 | return InstFDOrErr.takeError(); | 
|  | 2919 |  | 
|  | 2920 | if (ExpectedSLoc POIOrErr = import( | 
|  | 2921 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation())) | 
|  | 2922 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr); | 
|  | 2923 | else | 
|  | 2924 | return POIOrErr.takeError(); | 
|  | 2925 |  | 
|  | 2926 | return Error::success(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2927 | } | 
|  | 2928 |  | 
|  | 2929 | case FunctionDecl::TK_FunctionTemplateSpecialization: { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2930 | auto FunctionAndArgsOrErr = | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2931 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2932 | if (!FunctionAndArgsOrErr) | 
|  | 2933 | return FunctionAndArgsOrErr.takeError(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2934 |  | 
|  | 2935 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2936 | Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr)); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2937 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2938 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2939 | TemplateArgumentListInfo ToTAInfo; | 
|  | 2940 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2941 | if (FromTAArgsAsWritten) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2942 | if (Error Err = ImportTemplateArgumentListInfo( | 
|  | 2943 | *FromTAArgsAsWritten, ToTAInfo)) | 
|  | 2944 | return Err; | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2945 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2946 | ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation()); | 
|  | 2947 | if (!POIOrErr) | 
|  | 2948 | return POIOrErr.takeError(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2949 |  | 
| Balazs Keri | 1efc974 | 2019-05-07 10:55:11 +0000 | [diff] [blame] | 2950 | if (Error Err = ImportTemplateParameterLists(FromFD, ToFD)) | 
|  | 2951 | return Err; | 
|  | 2952 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2953 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2954 | ToFD->setFunctionTemplateSpecialization( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2955 | std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr, | 
|  | 2956 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr); | 
|  | 2957 | return Error::success(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2958 | } | 
|  | 2959 |  | 
|  | 2960 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { | 
|  | 2961 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); | 
|  | 2962 | UnresolvedSet<8> TemplDecls; | 
|  | 2963 | unsigned NumTemplates = FromInfo->getNumTemplates(); | 
|  | 2964 | for (unsigned I = 0; I < NumTemplates; I++) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2965 | if (Expected<FunctionTemplateDecl *> ToFTDOrErr = | 
|  | 2966 | import(FromInfo->getTemplate(I))) | 
|  | 2967 | TemplDecls.addDecl(*ToFTDOrErr); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2968 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2969 | return ToFTDOrErr.takeError(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2970 | } | 
|  | 2971 |  | 
|  | 2972 | // Import TemplateArgumentListInfo. | 
|  | 2973 | TemplateArgumentListInfo ToTAInfo; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2974 | if (Error Err = ImportTemplateArgumentListInfo( | 
|  | 2975 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), | 
|  | 2976 | llvm::makeArrayRef( | 
|  | 2977 | FromInfo->getTemplateArgs(), FromInfo->getNumTemplateArgs()), | 
|  | 2978 | ToTAInfo)) | 
|  | 2979 | return Err; | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2980 |  | 
|  | 2981 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), | 
|  | 2982 | TemplDecls, ToTAInfo); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2983 | return Error::success(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2984 | } | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2985 | } | 
| Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2986 | llvm_unreachable("All cases should be covered!"); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2987 | } | 
|  | 2988 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2989 | Expected<FunctionDecl *> | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2990 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2991 | auto FunctionAndArgsOrErr = | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2992 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2993 | if (!FunctionAndArgsOrErr) | 
|  | 2994 | return FunctionAndArgsOrErr.takeError(); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2995 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 2996 | FunctionTemplateDecl *Template; | 
|  | 2997 | TemplateArgsTy ToTemplArgs; | 
|  | 2998 | std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr; | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2999 | void *InsertPos = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3000 | auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3001 | return FoundSpec; | 
|  | 3002 | } | 
|  | 3003 |  | 
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3004 | Error ASTNodeImporter::ImportFunctionDeclBody(FunctionDecl *FromFD, | 
|  | 3005 | FunctionDecl *ToFD) { | 
|  | 3006 | if (Stmt *FromBody = FromFD->getBody()) { | 
|  | 3007 | if (ExpectedStmt ToBodyOrErr = import(FromBody)) | 
|  | 3008 | ToFD->setBody(*ToBodyOrErr); | 
|  | 3009 | else | 
|  | 3010 | return ToBodyOrErr.takeError(); | 
|  | 3011 | } | 
|  | 3012 | return Error::success(); | 
|  | 3013 | } | 
|  | 3014 |  | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3015 | template <typename T> | 
|  | 3016 | bool ASTNodeImporter::hasSameVisibilityContext(T *Found, T *From) { | 
|  | 3017 | if (From->hasExternalFormalLinkage()) | 
|  | 3018 | return Found->hasExternalFormalLinkage(); | 
|  | 3019 | if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl()) | 
|  | 3020 | return false; | 
|  | 3021 | if (From->isInAnonymousNamespace()) | 
|  | 3022 | return Found->isInAnonymousNamespace(); | 
|  | 3023 | else | 
|  | 3024 | return !Found->isInAnonymousNamespace() && | 
|  | 3025 | !Found->hasExternalFormalLinkage(); | 
|  | 3026 | } | 
|  | 3027 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3028 | ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3029 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3030 | SmallVector<Decl *, 2> Redecls = getCanonicalForwardRedeclChain(D); | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3031 | auto RedeclIt = Redecls.begin(); | 
|  | 3032 | // Import the first part of the decl chain. I.e. import all previous | 
|  | 3033 | // declarations starting from the canonical decl. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3034 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { | 
|  | 3035 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); | 
|  | 3036 | if (!ToRedeclOrErr) | 
|  | 3037 | return ToRedeclOrErr.takeError(); | 
|  | 3038 | } | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3039 | assert(*RedeclIt == D); | 
|  | 3040 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3041 | // Import the major distinguishing characteristics of this function. | 
|  | 3042 | DeclContext *DC, *LexicalDC; | 
|  | 3043 | DeclarationName Name; | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3044 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3045 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3046 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 3047 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3048 | if (ToD) | 
|  | 3049 | return ToD; | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3050 |  | 
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3051 | FunctionDecl *FoundByLookup = nullptr; | 
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3052 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); | 
| Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 3053 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3054 | // 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] | 3055 | // existing specialization in the "to" context. The lookup below will not | 
|  | 3056 | // find any specialization, but would find the primary template; thus, we | 
|  | 3057 | // have to skip normal lookup in case of specializations. | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3058 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? | 
|  | 3059 | if (D->getTemplatedKind() == | 
|  | 3060 | FunctionDecl::TK_FunctionTemplateSpecialization) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3061 | auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D); | 
|  | 3062 | if (!FoundFunctionOrErr) | 
|  | 3063 | return FoundFunctionOrErr.takeError(); | 
|  | 3064 | if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) { | 
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 3065 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) | 
|  | 3066 | return Def; | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3067 | FoundByLookup = FoundFunction; | 
|  | 3068 | } | 
|  | 3069 | } | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3070 | // Try to find a function in our own ("to") context with the same name, same | 
|  | 3071 | // type, and in the same context as the function we're importing. | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3072 | else if (!LexicalDC->isFunctionOrMethod()) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3073 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3074 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3075 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3076 | for (auto *FoundDecl : FoundDecls) { | 
|  | 3077 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3078 | continue; | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3079 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3080 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3081 | if (!hasSameVisibilityContext(FoundFunction, D)) | 
|  | 3082 | continue; | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3083 |  | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3084 | if (IsStructuralMatch(D, FoundFunction)) { | 
| Gabor Marton | dd59d27 | 2019-03-19 14:04:50 +0000 | [diff] [blame] | 3085 | if (Decl *Def = FindAndMapDefinition(D, FoundFunction)) | 
|  | 3086 | return Def; | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3087 | FoundByLookup = FoundFunction; | 
|  | 3088 | break; | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3089 | } | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3090 | // FIXME: Check for overloading more carefully, e.g., by boosting | 
|  | 3091 | // Sema::IsOverload out to the AST library. | 
|  | 3092 |  | 
|  | 3093 | // Function overloading is okay in C++. | 
|  | 3094 | if (Importer.getToContext().getLangOpts().CPlusPlus) | 
|  | 3095 | continue; | 
|  | 3096 |  | 
|  | 3097 | // Complain about inconsistent function types. | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3098 | Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent) | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3099 | << Name << D->getType() << FoundFunction->getType(); | 
|  | 3100 | Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here) | 
|  | 3101 | << FoundFunction->getType(); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3102 | } | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3103 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3104 | ConflictingDecls.push_back(FoundDecl); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3105 | } | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3106 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3107 | if (!ConflictingDecls.empty()) { | 
|  | 3108 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3109 | ConflictingDecls.data(), | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3110 | ConflictingDecls.size()); | 
|  | 3111 | if (!Name) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3112 | return make_error<ImportError>(ImportError::NameConflict); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3113 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3114 | } | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3115 |  | 
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3116 | // We do not allow more than one in-class declaration of a function. This is | 
|  | 3117 | // because AST clients like VTableBuilder asserts on this. VTableBuilder | 
|  | 3118 | // assumes there is only one in-class declaration. Building a redecl | 
|  | 3119 | // chain would result in more than one in-class declaration for | 
|  | 3120 | // overrides (even if they are part of the same redecl chain inside the | 
|  | 3121 | // derived class.) | 
|  | 3122 | if (FoundByLookup) { | 
| Mikael Holmen | c1c97aa | 2019-01-29 06:53:31 +0000 | [diff] [blame] | 3123 | if (isa<CXXMethodDecl>(FoundByLookup)) { | 
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3124 | if (D->getLexicalDeclContext() == D->getDeclContext()) { | 
| Balazs Keri | e9719f9 | 2019-08-07 12:40:17 +0000 | [diff] [blame] | 3125 | if (!D->doesThisDeclarationHaveABody()) { | 
|  | 3126 | if (FunctionTemplateDecl *DescribedD = | 
|  | 3127 | D->getDescribedFunctionTemplate()) { | 
|  | 3128 | // Handle a "templated" function together with its described | 
|  | 3129 | // template. This avoids need for a similar check at import of the | 
|  | 3130 | // described template. | 
|  | 3131 | assert(FoundByLookup->getDescribedFunctionTemplate() && | 
|  | 3132 | "Templated function mapped to non-templated?"); | 
|  | 3133 | Importer.MapImported(DescribedD, | 
|  | 3134 | FoundByLookup->getDescribedFunctionTemplate()); | 
|  | 3135 | } | 
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3136 | return Importer.MapImported(D, FoundByLookup); | 
| Balazs Keri | e9719f9 | 2019-08-07 12:40:17 +0000 | [diff] [blame] | 3137 | } else { | 
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3138 | // Let's continue and build up the redecl chain in this case. | 
|  | 3139 | // FIXME Merge the functions into one decl. | 
|  | 3140 | } | 
|  | 3141 | } | 
|  | 3142 | } | 
|  | 3143 | } | 
|  | 3144 |  | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3145 | DeclarationNameInfo NameInfo(Name, Loc); | 
|  | 3146 | // Import additional name location/type info. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3147 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | 
|  | 3148 | return std::move(Err); | 
| Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 3149 |  | 
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3150 | QualType FromTy = D->getType(); | 
|  | 3151 | bool usedDifferentExceptionSpec = false; | 
|  | 3152 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3153 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { | 
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3154 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); | 
|  | 3155 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the | 
|  | 3156 | // FunctionDecl that we are importing the FunctionProtoType for. | 
|  | 3157 | // To avoid an infinite recursion when importing, create the FunctionDecl | 
|  | 3158 | // with a simplified function type and update it afterwards. | 
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 3159 | if (FromEPI.ExceptionSpec.SourceDecl || | 
|  | 3160 | FromEPI.ExceptionSpec.SourceTemplate || | 
|  | 3161 | FromEPI.ExceptionSpec.NoexceptExpr) { | 
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3162 | FunctionProtoType::ExtProtoInfo DefaultEPI; | 
|  | 3163 | FromTy = Importer.getFromContext().getFunctionType( | 
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3164 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); | 
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3165 | usedDifferentExceptionSpec = true; | 
|  | 3166 | } | 
|  | 3167 | } | 
|  | 3168 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3169 | QualType T; | 
|  | 3170 | TypeSourceInfo *TInfo; | 
|  | 3171 | SourceLocation ToInnerLocStart, ToEndLoc; | 
|  | 3172 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 3173 | if (auto Imp = importSeq( | 
|  | 3174 | FromTy, D->getTypeSourceInfo(), D->getInnerLocStart(), | 
|  | 3175 | D->getQualifierLoc(), D->getEndLoc())) | 
|  | 3176 | std::tie(T, TInfo, ToInnerLocStart, ToQualifierLoc, ToEndLoc) = *Imp; | 
|  | 3177 | else | 
|  | 3178 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3179 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3180 | // Import the function parameters. | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3181 | SmallVector<ParmVarDecl *, 8> Parameters; | 
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3182 | for (auto P : D->parameters()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3183 | if (Expected<ParmVarDecl *> ToPOrErr = import(P)) | 
|  | 3184 | Parameters.push_back(*ToPOrErr); | 
|  | 3185 | else | 
|  | 3186 | return ToPOrErr.takeError(); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3187 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3188 |  | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3189 | // Create the imported function. | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3190 | FunctionDecl *ToFunction = nullptr; | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3191 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { | 
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3192 | Expr *ExplicitExpr = nullptr; | 
|  | 3193 | if (FromConstructor->getExplicitSpecifier().getExpr()) { | 
|  | 3194 | auto Imp = importSeq(FromConstructor->getExplicitSpecifier().getExpr()); | 
|  | 3195 | if (!Imp) | 
|  | 3196 | return Imp.takeError(); | 
|  | 3197 | std::tie(ExplicitExpr) = *Imp; | 
|  | 3198 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3199 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( | 
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3200 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | 
|  | 3201 | ToInnerLocStart, NameInfo, T, TInfo, | 
|  | 3202 | ExplicitSpecifier( | 
|  | 3203 | ExplicitExpr, | 
|  | 3204 | FromConstructor->getExplicitSpecifier().getKind()), | 
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3205 | D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3206 | return ToFunction; | 
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3207 | } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) { | 
|  | 3208 |  | 
|  | 3209 | auto Imp = | 
|  | 3210 | importSeq(const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()), | 
|  | 3211 | FromDtor->getOperatorDeleteThisArg()); | 
|  | 3212 |  | 
|  | 3213 | if (!Imp) | 
|  | 3214 | return Imp.takeError(); | 
|  | 3215 |  | 
|  | 3216 | FunctionDecl *ToOperatorDelete; | 
|  | 3217 | Expr *ToThisArg; | 
|  | 3218 | std::tie(ToOperatorDelete, ToThisArg) = *Imp; | 
|  | 3219 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3220 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3221 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | 
|  | 3222 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), | 
|  | 3223 | D->isImplicit())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3224 | return ToFunction; | 
| Raphael Isemann | 1c5d23f | 2019-01-22 17:59:45 +0000 | [diff] [blame] | 3225 |  | 
|  | 3226 | CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction); | 
|  | 3227 |  | 
|  | 3228 | ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3229 | } else if (CXXConversionDecl *FromConversion = | 
|  | 3230 | dyn_cast<CXXConversionDecl>(D)) { | 
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3231 | Expr *ExplicitExpr = nullptr; | 
|  | 3232 | if (FromConversion->getExplicitSpecifier().getExpr()) { | 
|  | 3233 | auto Imp = importSeq(FromConversion->getExplicitSpecifier().getExpr()); | 
|  | 3234 | if (!Imp) | 
|  | 3235 | return Imp.takeError(); | 
|  | 3236 | std::tie(ExplicitExpr) = *Imp; | 
|  | 3237 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3238 | if (GetImportedOrCreateDecl<CXXConversionDecl>( | 
|  | 3239 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3240 | ToInnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), | 
| Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3241 | ExplicitSpecifier(ExplicitExpr, | 
|  | 3242 | FromConversion->getExplicitSpecifier().getKind()), | 
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3243 | D->getConstexprKind(), SourceLocation())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3244 | return ToFunction; | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3245 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3246 | if (GetImportedOrCreateDecl<CXXMethodDecl>( | 
|  | 3247 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3248 | ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), | 
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3249 | Method->isInlineSpecified(), D->getConstexprKind(), | 
|  | 3250 | SourceLocation())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3251 | return ToFunction; | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3252 | } else { | 
| Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 3253 | if (GetImportedOrCreateDecl( | 
|  | 3254 | ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, | 
|  | 3255 | NameInfo, T, TInfo, D->getStorageClass(), D->isInlineSpecified(), | 
|  | 3256 | D->hasWrittenPrototype(), D->getConstexprKind())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3257 | return ToFunction; | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3258 | } | 
| John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 3259 |  | 
| Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3260 | // Connect the redecl chain. | 
|  | 3261 | if (FoundByLookup) { | 
|  | 3262 | auto *Recent = const_cast<FunctionDecl *>( | 
|  | 3263 | FoundByLookup->getMostRecentDecl()); | 
|  | 3264 | ToFunction->setPreviousDecl(Recent); | 
| Gabor Marton | ce6b781 | 2019-05-08 15:23:48 +0000 | [diff] [blame] | 3265 | // FIXME Probably we should merge exception specifications.  E.g. In the | 
|  | 3266 | // "To" context the existing function may have exception specification with | 
|  | 3267 | // noexcept-unevaluated, while the newly imported function may have an | 
|  | 3268 | // evaluated noexcept.  A call to adjustExceptionSpec() on the imported | 
|  | 3269 | // decl and its redeclarations may be required. | 
| Gabor Marton | f5e4f0a | 2018-11-20 14:19:39 +0000 | [diff] [blame] | 3270 | } | 
|  | 3271 |  | 
|  | 3272 | // Import Ctor initializers. | 
|  | 3273 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { | 
|  | 3274 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { | 
|  | 3275 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers); | 
|  | 3276 | // Import first, then allocate memory and copy if there was no error. | 
|  | 3277 | if (Error Err = ImportContainerChecked( | 
|  | 3278 | FromConstructor->inits(), CtorInitializers)) | 
|  | 3279 | return std::move(Err); | 
|  | 3280 | auto **Memory = | 
|  | 3281 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; | 
|  | 3282 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); | 
|  | 3283 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); | 
|  | 3284 | ToCtor->setCtorInitializers(Memory); | 
|  | 3285 | ToCtor->setNumCtorInitializers(NumInitializers); | 
|  | 3286 | } | 
|  | 3287 | } | 
|  | 3288 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3289 | ToFunction->setQualifierInfo(ToQualifierLoc); | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3290 | ToFunction->setAccess(D->getAccess()); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3291 | ToFunction->setLexicalDeclContext(LexicalDC); | 
| John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 3292 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); | 
|  | 3293 | ToFunction->setTrivial(D->isTrivial()); | 
|  | 3294 | ToFunction->setPure(D->isPure()); | 
| Balazs Keri | b427c06 | 2019-08-13 08:04:06 +0000 | [diff] [blame^] | 3295 | ToFunction->setDefaulted(D->isDefaulted()); | 
|  | 3296 | ToFunction->setExplicitlyDefaulted(D->isExplicitlyDefaulted()); | 
|  | 3297 | ToFunction->setDeletedAsWritten(D->isDeletedAsWritten()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3298 | ToFunction->setRangeEnd(ToEndLoc); | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3299 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3300 | // Set the parameters. | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3301 | for (auto *Param : Parameters) { | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3302 | Param->setOwningFunction(ToFunction); | 
|  | 3303 | ToFunction->addDeclInternal(Param); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3304 | } | 
| David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 3305 | ToFunction->setParams(Parameters); | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3306 |  | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3307 | // We need to complete creation of FunctionProtoTypeLoc manually with setting | 
|  | 3308 | // params it refers to. | 
|  | 3309 | if (TInfo) { | 
|  | 3310 | if (auto ProtoLoc = | 
|  | 3311 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { | 
|  | 3312 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) | 
|  | 3313 | ProtoLoc.setParam(I, Parameters[I]); | 
|  | 3314 | } | 
|  | 3315 | } | 
|  | 3316 |  | 
| Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 3317 | if (usedDifferentExceptionSpec) { | 
|  | 3318 | // Update FunctionProtoType::ExtProtoInfo. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3319 | if (ExpectedType TyOrErr = import(D->getType())) | 
|  | 3320 | ToFunction->setType(*TyOrErr); | 
|  | 3321 | else | 
|  | 3322 | return TyOrErr.takeError(); | 
| Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 3323 | } | 
|  | 3324 |  | 
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3325 | // Import the describing template function, if any. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3326 | if (FromFT) { | 
|  | 3327 | auto ToFTOrErr = import(FromFT); | 
|  | 3328 | if (!ToFTOrErr) | 
|  | 3329 | return ToFTOrErr.takeError(); | 
|  | 3330 | } | 
| Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 3331 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3332 | if (D->doesThisDeclarationHaveABody()) { | 
| Shafik Yaghmour | 96b3d20 | 2019-01-28 21:55:33 +0000 | [diff] [blame] | 3333 | Error Err = ImportFunctionDeclBody(D, ToFunction); | 
|  | 3334 |  | 
|  | 3335 | if (Err) | 
|  | 3336 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3337 | } | 
|  | 3338 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3339 | // FIXME: Other bits to merge? | 
| Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3340 |  | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3341 | // If it is a template, import all related things. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3342 | if (Error Err = ImportTemplateInformation(D, ToFunction)) | 
|  | 3343 | return std::move(Err); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3344 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3345 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); | 
|  | 3346 |  | 
|  | 3347 | // TODO Can we generalize this approach to other AST nodes as well? | 
|  | 3348 | if (D->getDeclContext()->containsDeclAndLoad(D)) | 
|  | 3349 | DC->addDeclInternal(ToFunction); | 
|  | 3350 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3351 | LexicalDC->addDeclInternal(ToFunction); | 
| Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 3352 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3353 | // Friend declaration's lexical context is the befriending class, but the | 
|  | 3354 | // semantic context is the enclosing scope of the befriending class. | 
|  | 3355 | // We want the friend functions to be found in the semantic context by lookup. | 
|  | 3356 | // FIXME should we handle this generically in VisitFriendDecl? | 
|  | 3357 | // In Other cases when LexicalDC != DC we don't want it to be added, | 
|  | 3358 | // e.g out-of-class definitions like void B::f() {} . | 
|  | 3359 | if (LexicalDC != DC && IsFriend) { | 
|  | 3360 | DC->makeDeclVisibleInContext(ToFunction); | 
|  | 3361 | } | 
|  | 3362 |  | 
| Gabor Marton | 7a0841e | 2018-10-29 10:18:28 +0000 | [diff] [blame] | 3363 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) | 
|  | 3364 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); | 
|  | 3365 |  | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3366 | // Import the rest of the chain. I.e. import all subsequent declarations. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3367 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { | 
|  | 3368 | ExpectedDecl ToRedeclOrErr = import(*RedeclIt); | 
|  | 3369 | if (!ToRedeclOrErr) | 
|  | 3370 | return ToRedeclOrErr.takeError(); | 
|  | 3371 | } | 
| Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 3372 |  | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3373 | return ToFunction; | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3374 | } | 
|  | 3375 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3376 | ExpectedDecl ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3377 | return VisitFunctionDecl(D); | 
|  | 3378 | } | 
|  | 3379 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3380 | ExpectedDecl ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3381 | return VisitCXXMethodDecl(D); | 
|  | 3382 | } | 
|  | 3383 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3384 | ExpectedDecl ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3385 | return VisitCXXMethodDecl(D); | 
|  | 3386 | } | 
|  | 3387 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3388 | ExpectedDecl ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { | 
| Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 3389 | return VisitCXXMethodDecl(D); | 
|  | 3390 | } | 
|  | 3391 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3392 | ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3393 | // Import the major distinguishing characteristics of a variable. | 
|  | 3394 | DeclContext *DC, *LexicalDC; | 
|  | 3395 | DeclarationName Name; | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3396 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3397 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3398 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 3399 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3400 | if (ToD) | 
|  | 3401 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3402 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3403 | // Determine whether we've already imported this field. | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3404 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3405 | for (auto *FoundDecl : FoundDecls) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3406 | if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { | 
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3407 | // For anonymous fields, match up by index. | 
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3408 | if (!Name && | 
|  | 3409 | ASTImporter::getFieldIndex(D) != | 
|  | 3410 | ASTImporter::getFieldIndex(FoundField)) | 
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3411 | continue; | 
|  | 3412 |  | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3413 | if (Importer.IsStructurallyEquivalent(D->getType(), | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3414 | FoundField->getType())) { | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3415 | Importer.MapImported(D, FoundField); | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3416 | // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the | 
|  | 3417 | // initializer of a FieldDecl might not had been instantiated in the | 
|  | 3418 | // "To" context.  However, the "From" context might instantiated that, | 
|  | 3419 | // thus we have to merge that. | 
|  | 3420 | if (Expr *FromInitializer = D->getInClassInitializer()) { | 
|  | 3421 | // We don't have yet the initializer set. | 
|  | 3422 | if (FoundField->hasInClassInitializer() && | 
|  | 3423 | !FoundField->getInClassInitializer()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3424 | if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) | 
|  | 3425 | FoundField->setInClassInitializer(*ToInitializerOrErr); | 
|  | 3426 | else { | 
|  | 3427 | // We can't return error here, | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3428 | // since we already mapped D as imported. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3429 | // FIXME: warning message? | 
|  | 3430 | consumeError(ToInitializerOrErr.takeError()); | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3431 | return FoundField; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3432 | } | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 3433 | } | 
|  | 3434 | } | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3435 | return FoundField; | 
|  | 3436 | } | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3437 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3438 | // FIXME: Why is this case not handled with calling HandleNameConflict? | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3439 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3440 | << Name << D->getType() << FoundField->getType(); | 
|  | 3441 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) | 
|  | 3442 | << FoundField->getType(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3443 |  | 
|  | 3444 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3445 | } | 
|  | 3446 | } | 
|  | 3447 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3448 | QualType ToType; | 
|  | 3449 | TypeSourceInfo *ToTInfo; | 
|  | 3450 | Expr *ToBitWidth; | 
|  | 3451 | SourceLocation ToInnerLocStart; | 
|  | 3452 | Expr *ToInitializer; | 
|  | 3453 | if (auto Imp = importSeq( | 
|  | 3454 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), | 
|  | 3455 | D->getInnerLocStart(), D->getInClassInitializer())) | 
|  | 3456 | std::tie( | 
|  | 3457 | ToType, ToTInfo, ToBitWidth, ToInnerLocStart, ToInitializer) = *Imp; | 
|  | 3458 | else | 
|  | 3459 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3460 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3461 | FieldDecl *ToField; | 
|  | 3462 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3463 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), | 
|  | 3464 | ToType, ToTInfo, ToBitWidth, D->isMutable(), | 
|  | 3465 | D->getInClassInitStyle())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3466 | return ToField; | 
|  | 3467 |  | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3468 | ToField->setAccess(D->getAccess()); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3469 | ToField->setLexicalDeclContext(LexicalDC); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3470 | if (ToInitializer) | 
|  | 3471 | ToField->setInClassInitializer(ToInitializer); | 
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3472 | ToField->setImplicit(D->isImplicit()); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3473 | LexicalDC->addDeclInternal(ToField); | 
| Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 3474 | return ToField; | 
|  | 3475 | } | 
|  | 3476 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3477 | ExpectedDecl ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3478 | // Import the major distinguishing characteristics of a variable. | 
|  | 3479 | DeclContext *DC, *LexicalDC; | 
|  | 3480 | DeclarationName Name; | 
|  | 3481 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3482 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3483 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 3484 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3485 | if (ToD) | 
|  | 3486 | return ToD; | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3487 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3488 | // Determine whether we've already imported this field. | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3489 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 3490 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3491 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { | 
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3492 | // For anonymous indirect fields, match up by index. | 
| Balazs Keri | 2544b4b | 2018-08-08 09:40:57 +0000 | [diff] [blame] | 3493 | if (!Name && | 
|  | 3494 | ASTImporter::getFieldIndex(D) != | 
|  | 3495 | ASTImporter::getFieldIndex(FoundField)) | 
| Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 3496 | continue; | 
|  | 3497 |  | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3498 | if (Importer.IsStructurallyEquivalent(D->getType(), | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3499 | FoundField->getType(), | 
| David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 3500 | !Name.isEmpty())) { | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3501 | Importer.MapImported(D, FoundField); | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3502 | return FoundField; | 
|  | 3503 | } | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 3504 |  | 
|  | 3505 | // If there are more anonymous fields to check, continue. | 
|  | 3506 | if (!Name && I < N-1) | 
|  | 3507 | continue; | 
|  | 3508 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3509 | // FIXME: Why is this case not handled with calling HandleNameConflict? | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3510 | Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent) | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3511 | << Name << D->getType() << FoundField->getType(); | 
|  | 3512 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) | 
|  | 3513 | << FoundField->getType(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3514 |  | 
|  | 3515 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 3516 | } | 
|  | 3517 | } | 
|  | 3518 |  | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3519 | // Import the type. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3520 | auto TypeOrErr = import(D->getType()); | 
|  | 3521 | if (!TypeOrErr) | 
|  | 3522 | return TypeOrErr.takeError(); | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3523 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3524 | auto **NamedChain = | 
|  | 3525 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3526 |  | 
|  | 3527 | unsigned i = 0; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3528 | for (auto *PI : D->chain()) | 
|  | 3529 | if (Expected<NamedDecl *> ToD = import(PI)) | 
|  | 3530 | NamedChain[i++] = *ToD; | 
|  | 3531 | else | 
|  | 3532 | return ToD.takeError(); | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3533 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3534 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; | 
|  | 3535 | IndirectFieldDecl *ToIndirectField; | 
|  | 3536 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3537 | Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3538 | // FIXME here we leak `NamedChain` which is allocated before | 
|  | 3539 | return ToIndirectField; | 
| Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 3540 |  | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3541 | ToIndirectField->setAccess(D->getAccess()); | 
|  | 3542 | ToIndirectField->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3543 | LexicalDC->addDeclInternal(ToIndirectField); | 
| Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3544 | return ToIndirectField; | 
|  | 3545 | } | 
|  | 3546 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3547 | ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3548 | // Import the major distinguishing characteristics of a declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3549 | DeclContext *DC, *LexicalDC; | 
|  | 3550 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 3551 | return std::move(Err); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3552 |  | 
|  | 3553 | // Determine whether we've already imported this decl. | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3554 | // FriendDecl is not a NamedDecl so we cannot use lookup. | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3555 | auto *RD = cast<CXXRecordDecl>(DC); | 
|  | 3556 | FriendDecl *ImportedFriend = RD->getFirstFriend(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3557 |  | 
|  | 3558 | while (ImportedFriend) { | 
|  | 3559 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3560 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), | 
|  | 3561 | /*Complain=*/false)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3562 | return Importer.MapImported(D, ImportedFriend); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3563 |  | 
|  | 3564 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { | 
|  | 3565 | if (Importer.IsStructurallyEquivalent( | 
|  | 3566 | D->getFriendType()->getType(), | 
|  | 3567 | ImportedFriend->getFriendType()->getType(), true)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3568 | return Importer.MapImported(D, ImportedFriend); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3569 | } | 
|  | 3570 | ImportedFriend = ImportedFriend->getNextFriend(); | 
|  | 3571 | } | 
|  | 3572 |  | 
|  | 3573 | // Not found. Create it. | 
|  | 3574 | FriendDecl::FriendUnion ToFU; | 
| Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3575 | if (NamedDecl *FriendD = D->getFriendDecl()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3576 | NamedDecl *ToFriendD; | 
|  | 3577 | if (Error Err = importInto(ToFriendD, FriendD)) | 
|  | 3578 | return std::move(Err); | 
|  | 3579 |  | 
|  | 3580 | if (FriendD->getFriendObjectKind() != Decl::FOK_None && | 
| Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3581 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) | 
|  | 3582 | ToFriendD->setObjectOfFriendDecl(false); | 
|  | 3583 |  | 
|  | 3584 | ToFU = ToFriendD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3585 | } else { // The friend is a type, not a decl. | 
|  | 3586 | if (auto TSIOrErr = import(D->getFriendType())) | 
|  | 3587 | ToFU = *TSIOrErr; | 
|  | 3588 | else | 
|  | 3589 | return TSIOrErr.takeError(); | 
|  | 3590 | } | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3591 |  | 
|  | 3592 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3593 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3594 | for (unsigned I = 0; I < D->NumTPLists; I++) { | 
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 3595 | if (auto ListOrErr = import(FromTPLists[I])) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3596 | ToTPLists[I] = *ListOrErr; | 
|  | 3597 | else | 
|  | 3598 | return ListOrErr.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3599 | } | 
|  | 3600 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3601 | auto LocationOrErr = import(D->getLocation()); | 
|  | 3602 | if (!LocationOrErr) | 
|  | 3603 | return LocationOrErr.takeError(); | 
|  | 3604 | auto FriendLocOrErr = import(D->getFriendLoc()); | 
|  | 3605 | if (!FriendLocOrErr) | 
|  | 3606 | return FriendLocOrErr.takeError(); | 
|  | 3607 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3608 | FriendDecl *FrD; | 
|  | 3609 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3610 | *LocationOrErr, ToFU, | 
|  | 3611 | *FriendLocOrErr, ToTPLists)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3612 | return FrD; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3613 |  | 
|  | 3614 | FrD->setAccess(D->getAccess()); | 
|  | 3615 | FrD->setLexicalDeclContext(LexicalDC); | 
|  | 3616 | LexicalDC->addDeclInternal(FrD); | 
|  | 3617 | return FrD; | 
|  | 3618 | } | 
|  | 3619 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3620 | ExpectedDecl ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3621 | // Import the major distinguishing characteristics of an ivar. | 
|  | 3622 | DeclContext *DC, *LexicalDC; | 
|  | 3623 | DeclarationName Name; | 
|  | 3624 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3625 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3626 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 3627 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3628 | if (ToD) | 
|  | 3629 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3630 |  | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3631 | // Determine whether we've already imported this ivar | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3632 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3633 | for (auto *FoundDecl : FoundDecls) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3634 | if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3635 | if (Importer.IsStructurallyEquivalent(D->getType(), | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3636 | FoundIvar->getType())) { | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3637 | Importer.MapImported(D, FoundIvar); | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3638 | return FoundIvar; | 
|  | 3639 | } | 
|  | 3640 |  | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3641 | Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent) | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3642 | << Name << D->getType() << FoundIvar->getType(); | 
|  | 3643 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) | 
|  | 3644 | << FoundIvar->getType(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3645 |  | 
|  | 3646 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3647 | } | 
|  | 3648 | } | 
|  | 3649 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3650 | QualType ToType; | 
|  | 3651 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 3652 | Expr *ToBitWidth; | 
|  | 3653 | SourceLocation ToInnerLocStart; | 
|  | 3654 | if (auto Imp = importSeq( | 
|  | 3655 | D->getType(), D->getTypeSourceInfo(), D->getBitWidth(), D->getInnerLocStart())) | 
|  | 3656 | std::tie(ToType, ToTypeSourceInfo, ToBitWidth, ToInnerLocStart) = *Imp; | 
|  | 3657 | else | 
|  | 3658 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3659 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3660 | ObjCIvarDecl *ToIvar; | 
|  | 3661 | if (GetImportedOrCreateDecl( | 
|  | 3662 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3663 | ToInnerLocStart, Loc, Name.getAsIdentifierInfo(), | 
|  | 3664 | ToType, ToTypeSourceInfo, | 
|  | 3665 | D->getAccessControl(),ToBitWidth, D->getSynthesize())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3666 | return ToIvar; | 
|  | 3667 |  | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3668 | ToIvar->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3669 | LexicalDC->addDeclInternal(ToIvar); | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3670 | return ToIvar; | 
| Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3671 | } | 
|  | 3672 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3673 | ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) { | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3674 |  | 
|  | 3675 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); | 
|  | 3676 | auto RedeclIt = Redecls.begin(); | 
|  | 3677 | // Import the first part of the decl chain. I.e. import all previous | 
|  | 3678 | // declarations starting from the canonical decl. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3679 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) { | 
|  | 3680 | ExpectedDecl RedeclOrErr = import(*RedeclIt); | 
|  | 3681 | if (!RedeclOrErr) | 
|  | 3682 | return RedeclOrErr.takeError(); | 
|  | 3683 | } | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3684 | assert(*RedeclIt == D); | 
|  | 3685 |  | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3686 | // Import the major distinguishing characteristics of a variable. | 
|  | 3687 | DeclContext *DC, *LexicalDC; | 
|  | 3688 | DeclarationName Name; | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3689 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3690 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3691 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 3692 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3693 | if (ToD) | 
|  | 3694 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3695 |  | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3696 | // Try to find a variable in our own ("to") context with the same name and | 
|  | 3697 | // in the same context as the variable we're importing. | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3698 | VarDecl *FoundByLookup = nullptr; | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3699 | if (D->isFileVarDecl()) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3700 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3701 | unsigned IDNS = Decl::IDNS_Ordinary; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3702 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3703 | for (auto *FoundDecl : FoundDecls) { | 
|  | 3704 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3705 | continue; | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3706 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3707 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3708 | if (!hasSameVisibilityContext(FoundVar, D)) | 
|  | 3709 | continue; | 
|  | 3710 | if (Importer.IsStructurallyEquivalent(D->getType(), | 
|  | 3711 | FoundVar->getType())) { | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3712 |  | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3713 | // The VarDecl in the "From" context has a definition, but in the | 
|  | 3714 | // "To" context we already have a definition. | 
|  | 3715 | VarDecl *FoundDef = FoundVar->getDefinition(); | 
|  | 3716 | if (D->isThisDeclarationADefinition() && FoundDef) | 
|  | 3717 | // FIXME Check for ODR error if the two definitions have | 
|  | 3718 | // different initializers? | 
|  | 3719 | return Importer.MapImported(D, FoundDef); | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3720 |  | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3721 | // The VarDecl in the "From" context has an initializer, but in the | 
|  | 3722 | // "To" context we already have an initializer. | 
|  | 3723 | const VarDecl *FoundDInit = nullptr; | 
|  | 3724 | if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit)) | 
|  | 3725 | // FIXME Diagnose ODR error if the two initializers are different? | 
|  | 3726 | return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit)); | 
|  | 3727 |  | 
|  | 3728 | FoundByLookup = FoundVar; | 
|  | 3729 | break; | 
|  | 3730 | } | 
|  | 3731 |  | 
|  | 3732 | const ArrayType *FoundArray | 
|  | 3733 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); | 
|  | 3734 | const ArrayType *TArray | 
|  | 3735 | = Importer.getToContext().getAsArrayType(D->getType()); | 
|  | 3736 | if (FoundArray && TArray) { | 
|  | 3737 | if (isa<IncompleteArrayType>(FoundArray) && | 
|  | 3738 | isa<ConstantArrayType>(TArray)) { | 
|  | 3739 | // Import the type. | 
|  | 3740 | if (auto TyOrErr = import(D->getType())) | 
|  | 3741 | FoundVar->setType(*TyOrErr); | 
|  | 3742 | else | 
|  | 3743 | return TyOrErr.takeError(); | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3744 |  | 
|  | 3745 | FoundByLookup = FoundVar; | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3746 | break; | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3747 | } else if (isa<IncompleteArrayType>(TArray) && | 
|  | 3748 | isa<ConstantArrayType>(FoundArray)) { | 
|  | 3749 | FoundByLookup = FoundVar; | 
|  | 3750 | break; | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3751 | } | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3752 | } | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3753 |  | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3754 | Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent) | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 3755 | << Name << D->getType() << FoundVar->getType(); | 
|  | 3756 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) | 
|  | 3757 | << FoundVar->getType(); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3758 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3759 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3760 | ConflictingDecls.push_back(FoundDecl); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3761 | } | 
|  | 3762 |  | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3763 | if (!ConflictingDecls.empty()) { | 
|  | 3764 | Name = Importer.HandleNameConflict(Name, DC, IDNS, | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3765 | ConflictingDecls.data(), | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3766 | ConflictingDecls.size()); | 
|  | 3767 | if (!Name) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3768 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3769 | } | 
|  | 3770 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3771 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3772 | QualType ToType; | 
|  | 3773 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 3774 | SourceLocation ToInnerLocStart; | 
|  | 3775 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 3776 | if (auto Imp = importSeq( | 
|  | 3777 | D->getType(), D->getTypeSourceInfo(), D->getInnerLocStart(), | 
|  | 3778 | D->getQualifierLoc())) | 
|  | 3779 | std::tie(ToType, ToTypeSourceInfo, ToInnerLocStart, ToQualifierLoc) = *Imp; | 
|  | 3780 | else | 
|  | 3781 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3782 |  | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3783 | // Create the imported variable. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3784 | VarDecl *ToVar; | 
|  | 3785 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3786 | ToInnerLocStart, Loc, | 
|  | 3787 | Name.getAsIdentifierInfo(), | 
|  | 3788 | ToType, ToTypeSourceInfo, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3789 | D->getStorageClass())) | 
|  | 3790 | return ToVar; | 
|  | 3791 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3792 | ToVar->setQualifierInfo(ToQualifierLoc); | 
| Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3793 | ToVar->setAccess(D->getAccess()); | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3794 | ToVar->setLexicalDeclContext(LexicalDC); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3795 |  | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3796 | if (FoundByLookup) { | 
|  | 3797 | auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl()); | 
|  | 3798 | ToVar->setPreviousDecl(Recent); | 
|  | 3799 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3800 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3801 | if (Error Err = ImportInitializer(D, ToVar)) | 
|  | 3802 | return std::move(Err); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3803 |  | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3804 | if (D->isConstexpr()) | 
|  | 3805 | ToVar->setConstexpr(true); | 
|  | 3806 |  | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3807 | if (D->getDeclContext()->containsDeclAndLoad(D)) | 
|  | 3808 | DC->addDeclInternal(ToVar); | 
|  | 3809 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) | 
|  | 3810 | LexicalDC->addDeclInternal(ToVar); | 
|  | 3811 |  | 
|  | 3812 | // Import the rest of the chain. I.e. import all subsequent declarations. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3813 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) { | 
|  | 3814 | ExpectedDecl RedeclOrErr = import(*RedeclIt); | 
|  | 3815 | if (!RedeclOrErr) | 
|  | 3816 | return RedeclOrErr.takeError(); | 
|  | 3817 | } | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 3818 |  | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3819 | return ToVar; | 
|  | 3820 | } | 
|  | 3821 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3822 | ExpectedDecl ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { | 
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3823 | // Parameters are created in the translation unit's context, then moved | 
|  | 3824 | // into the function declaration's context afterward. | 
|  | 3825 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3826 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3827 | DeclarationName ToDeclName; | 
|  | 3828 | SourceLocation ToLocation; | 
|  | 3829 | QualType ToType; | 
|  | 3830 | if (auto Imp = importSeq(D->getDeclName(), D->getLocation(), D->getType())) | 
|  | 3831 | std::tie(ToDeclName, ToLocation, ToType) = *Imp; | 
|  | 3832 | else | 
|  | 3833 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3834 |  | 
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3835 | // Create the imported parameter. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3836 | ImplicitParamDecl *ToParm = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3837 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, | 
|  | 3838 | ToLocation, ToDeclName.getAsIdentifierInfo(), | 
|  | 3839 | ToType, D->getParameterKind())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3840 | return ToParm; | 
|  | 3841 | return ToParm; | 
| Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3842 | } | 
|  | 3843 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3844 | ExpectedDecl ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3845 | // Parameters are created in the translation unit's context, then moved | 
|  | 3846 | // into the function declaration's context afterward. | 
|  | 3847 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3848 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3849 | DeclarationName ToDeclName; | 
|  | 3850 | SourceLocation ToLocation, ToInnerLocStart; | 
|  | 3851 | QualType ToType; | 
|  | 3852 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 3853 | if (auto Imp = importSeq( | 
|  | 3854 | D->getDeclName(), D->getLocation(), D->getType(), D->getInnerLocStart(), | 
|  | 3855 | D->getTypeSourceInfo())) | 
|  | 3856 | std::tie( | 
|  | 3857 | ToDeclName, ToLocation, ToType, ToInnerLocStart, | 
|  | 3858 | ToTypeSourceInfo) = *Imp; | 
|  | 3859 | else | 
|  | 3860 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3861 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3862 | ParmVarDecl *ToParm; | 
|  | 3863 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3864 | ToInnerLocStart, ToLocation, | 
|  | 3865 | ToDeclName.getAsIdentifierInfo(), ToType, | 
|  | 3866 | ToTypeSourceInfo, D->getStorageClass(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3867 | /*DefaultArg*/ nullptr)) | 
|  | 3868 | return ToParm; | 
| Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3869 |  | 
|  | 3870 | // Set the default argument. | 
| John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 3871 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); | 
| Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3872 | ToParm->setKNRPromoted(D->isKNRPromoted()); | 
|  | 3873 |  | 
| Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3874 | if (D->hasUninstantiatedDefaultArg()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3875 | if (auto ToDefArgOrErr = import(D->getUninstantiatedDefaultArg())) | 
|  | 3876 | ToParm->setUninstantiatedDefaultArg(*ToDefArgOrErr); | 
|  | 3877 | else | 
|  | 3878 | return ToDefArgOrErr.takeError(); | 
| Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3879 | } else if (D->hasUnparsedDefaultArg()) { | 
|  | 3880 | ToParm->setUnparsedDefaultArg(); | 
|  | 3881 | } else if (D->hasDefaultArg()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3882 | if (auto ToDefArgOrErr = import(D->getDefaultArg())) | 
|  | 3883 | ToParm->setDefaultArg(*ToDefArgOrErr); | 
|  | 3884 | else | 
|  | 3885 | return ToDefArgOrErr.takeError(); | 
| Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3886 | } | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3887 |  | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3888 | if (D->isObjCMethodParameter()) { | 
|  | 3889 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); | 
|  | 3890 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); | 
|  | 3891 | } else { | 
|  | 3892 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), | 
|  | 3893 | D->getFunctionScopeIndex()); | 
|  | 3894 | } | 
|  | 3895 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3896 | return ToParm; | 
| Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3897 | } | 
|  | 3898 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3899 | ExpectedDecl ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3900 | // Import the major distinguishing characteristics of a method. | 
|  | 3901 | DeclContext *DC, *LexicalDC; | 
|  | 3902 | DeclarationName Name; | 
|  | 3903 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3904 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3905 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 3906 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3907 | if (ToD) | 
|  | 3908 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3909 |  | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 3910 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3911 | for (auto *FoundDecl : FoundDecls) { | 
|  | 3912 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3913 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) | 
|  | 3914 | continue; | 
|  | 3915 |  | 
|  | 3916 | // Check return types. | 
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3917 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), | 
|  | 3918 | FoundMethod->getReturnType())) { | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3919 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent) | 
| Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3920 | << D->isInstanceMethod() << Name << D->getReturnType() | 
|  | 3921 | << FoundMethod->getReturnType(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3922 | Importer.ToDiag(FoundMethod->getLocation(), | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3923 | diag::note_odr_objc_method_here) | 
|  | 3924 | << D->isInstanceMethod() << Name; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3925 |  | 
|  | 3926 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3927 | } | 
|  | 3928 |  | 
|  | 3929 | // Check the number of parameters. | 
|  | 3930 | if (D->param_size() != FoundMethod->param_size()) { | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3931 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent) | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3932 | << D->isInstanceMethod() << Name | 
|  | 3933 | << D->param_size() << FoundMethod->param_size(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3934 | Importer.ToDiag(FoundMethod->getLocation(), | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3935 | diag::note_odr_objc_method_here) | 
|  | 3936 | << D->isInstanceMethod() << Name; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3937 |  | 
|  | 3938 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3939 | } | 
|  | 3940 |  | 
|  | 3941 | // Check parameter types. | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3942 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3943 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); | 
|  | 3944 | P != PEnd; ++P, ++FoundP) { | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3945 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3946 | (*FoundP)->getType())) { | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3947 | Importer.FromDiag((*P)->getLocation(), | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3948 | diag::warn_odr_objc_method_param_type_inconsistent) | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3949 | << D->isInstanceMethod() << Name | 
|  | 3950 | << (*P)->getType() << (*FoundP)->getType(); | 
|  | 3951 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) | 
|  | 3952 | << (*FoundP)->getType(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3953 |  | 
|  | 3954 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3955 | } | 
|  | 3956 | } | 
|  | 3957 |  | 
|  | 3958 | // Check variadic/non-variadic. | 
|  | 3959 | // Check the number of parameters. | 
|  | 3960 | if (D->isVariadic() != FoundMethod->isVariadic()) { | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 3961 | Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent) | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3962 | << D->isInstanceMethod() << Name; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3963 | Importer.ToDiag(FoundMethod->getLocation(), | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3964 | diag::note_odr_objc_method_here) | 
|  | 3965 | << D->isInstanceMethod() << Name; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3966 |  | 
|  | 3967 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3968 | } | 
|  | 3969 |  | 
|  | 3970 | // FIXME: Any other bits we need to merge? | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3971 | return Importer.MapImported(D, FoundMethod); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3972 | } | 
|  | 3973 | } | 
|  | 3974 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3975 | SourceLocation ToEndLoc; | 
|  | 3976 | QualType ToReturnType; | 
|  | 3977 | TypeSourceInfo *ToReturnTypeSourceInfo; | 
|  | 3978 | if (auto Imp = importSeq( | 
|  | 3979 | D->getEndLoc(), D->getReturnType(), D->getReturnTypeSourceInfo())) | 
|  | 3980 | std::tie(ToEndLoc, ToReturnType, ToReturnTypeSourceInfo) = *Imp; | 
|  | 3981 | else | 
|  | 3982 | return Imp.takeError(); | 
| Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3983 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3984 | ObjCMethodDecl *ToMethod; | 
|  | 3985 | if (GetImportedOrCreateDecl( | 
|  | 3986 | ToMethod, D, Importer.getToContext(), Loc, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3987 | ToEndLoc, Name.getObjCSelector(), ToReturnType, | 
|  | 3988 | ToReturnTypeSourceInfo, DC, D->isInstanceMethod(), D->isVariadic(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3989 | D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), | 
|  | 3990 | D->getImplementationControl(), D->hasRelatedResultType())) | 
|  | 3991 | return ToMethod; | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3992 |  | 
|  | 3993 | // FIXME: When we decide to merge method definitions, we'll need to | 
|  | 3994 | // deal with implicit parameters. | 
|  | 3995 |  | 
|  | 3996 | // Import the parameters | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3997 | SmallVector<ParmVarDecl *, 5> ToParams; | 
| David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3998 | for (auto *FromP : D->parameters()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 3999 | if (Expected<ParmVarDecl *> ToPOrErr = import(FromP)) | 
|  | 4000 | ToParams.push_back(*ToPOrErr); | 
|  | 4001 | else | 
|  | 4002 | return ToPOrErr.takeError(); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4003 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4004 |  | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4005 | // Set the parameters. | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4006 | for (auto *ToParam : ToParams) { | 
|  | 4007 | ToParam->setOwningFunction(ToMethod); | 
|  | 4008 | ToMethod->addDeclInternal(ToParam); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4009 | } | 
| Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 4010 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4011 | SmallVector<SourceLocation, 12> FromSelLocs; | 
|  | 4012 | D->getSelectorLocs(FromSelLocs); | 
|  | 4013 | SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size()); | 
|  | 4014 | if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs)) | 
|  | 4015 | return std::move(Err); | 
| Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 4016 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4017 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4018 |  | 
|  | 4019 | ToMethod->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4020 | LexicalDC->addDeclInternal(ToMethod); | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 4021 | return ToMethod; | 
|  | 4022 | } | 
|  | 4023 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4024 | ExpectedDecl ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4025 | // Import the major distinguishing characteristics of a category. | 
|  | 4026 | DeclContext *DC, *LexicalDC; | 
|  | 4027 | DeclarationName Name; | 
|  | 4028 | SourceLocation Loc; | 
|  | 4029 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4030 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4031 | return std::move(Err); | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4032 | if (ToD) | 
|  | 4033 | return ToD; | 
|  | 4034 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4035 | SourceLocation ToVarianceLoc, ToLocation, ToColonLoc; | 
|  | 4036 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 4037 | if (auto Imp = importSeq( | 
|  | 4038 | D->getVarianceLoc(), D->getLocation(), D->getColonLoc(), | 
|  | 4039 | D->getTypeSourceInfo())) | 
|  | 4040 | std::tie(ToVarianceLoc, ToLocation, ToColonLoc, ToTypeSourceInfo) = *Imp; | 
|  | 4041 | else | 
|  | 4042 | return Imp.takeError(); | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4043 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4044 | ObjCTypeParamDecl *Result; | 
|  | 4045 | if (GetImportedOrCreateDecl( | 
|  | 4046 | Result, D, Importer.getToContext(), DC, D->getVariance(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4047 | ToVarianceLoc, D->getIndex(), | 
|  | 4048 | ToLocation, Name.getAsIdentifierInfo(), | 
|  | 4049 | ToColonLoc, ToTypeSourceInfo)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4050 | return Result; | 
|  | 4051 |  | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4052 | Result->setLexicalDeclContext(LexicalDC); | 
|  | 4053 | return Result; | 
|  | 4054 | } | 
|  | 4055 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4056 | ExpectedDecl ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4057 | // Import the major distinguishing characteristics of a category. | 
|  | 4058 | DeclContext *DC, *LexicalDC; | 
|  | 4059 | DeclarationName Name; | 
|  | 4060 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4061 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4062 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4063 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4064 | if (ToD) | 
|  | 4065 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4066 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4067 | ObjCInterfaceDecl *ToInterface; | 
|  | 4068 | if (Error Err = importInto(ToInterface, D->getClassInterface())) | 
|  | 4069 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4070 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4071 | // Determine if we've already encountered this category. | 
|  | 4072 | ObjCCategoryDecl *MergeWithCategory | 
|  | 4073 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); | 
|  | 4074 | ObjCCategoryDecl *ToCategory = MergeWithCategory; | 
|  | 4075 | if (!ToCategory) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4076 | SourceLocation ToAtStartLoc, ToCategoryNameLoc; | 
|  | 4077 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; | 
|  | 4078 | if (auto Imp = importSeq( | 
|  | 4079 | D->getAtStartLoc(), D->getCategoryNameLoc(), | 
|  | 4080 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) | 
|  | 4081 | std::tie( | 
|  | 4082 | ToAtStartLoc, ToCategoryNameLoc, | 
|  | 4083 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; | 
|  | 4084 | else | 
|  | 4085 | return Imp.takeError(); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4086 |  | 
|  | 4087 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4088 | ToAtStartLoc, Loc, | 
|  | 4089 | ToCategoryNameLoc, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4090 | Name.getAsIdentifierInfo(), ToInterface, | 
|  | 4091 | /*TypeParamList=*/nullptr, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4092 | ToIvarLBraceLoc, | 
|  | 4093 | ToIvarRBraceLoc)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4094 | return ToCategory; | 
|  | 4095 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4096 | ToCategory->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4097 | LexicalDC->addDeclInternal(ToCategory); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4098 | // Import the type parameter list after MapImported, to avoid | 
| Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4099 | // loops when bringing in their DeclContext. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4100 | if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList())) | 
|  | 4101 | ToCategory->setTypeParamList(*PListOrErr); | 
|  | 4102 | else | 
|  | 4103 | return PListOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4104 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4105 | // Import protocols | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4106 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | 
|  | 4107 | SmallVector<SourceLocation, 4> ProtocolLocs; | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4108 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc | 
|  | 4109 | = D->protocol_loc_begin(); | 
|  | 4110 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), | 
|  | 4111 | FromProtoEnd = D->protocol_end(); | 
|  | 4112 | FromProto != FromProtoEnd; | 
|  | 4113 | ++FromProto, ++FromProtoLoc) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4114 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | 
|  | 4115 | Protocols.push_back(*ToProtoOrErr); | 
|  | 4116 | else | 
|  | 4117 | return ToProtoOrErr.takeError(); | 
|  | 4118 |  | 
|  | 4119 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | 
|  | 4120 | ProtocolLocs.push_back(*ToProtoLocOrErr); | 
|  | 4121 | else | 
|  | 4122 | return ToProtoLocOrErr.takeError(); | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4123 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4124 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4125 | // FIXME: If we're merging, make sure that the protocol list is the same. | 
|  | 4126 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), | 
|  | 4127 | ProtocolLocs.data(), Importer.getToContext()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4128 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4129 | } else { | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4130 | Importer.MapImported(D, ToCategory); | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4131 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4132 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4133 | // Import all of the members of this category. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4134 | if (Error Err = ImportDeclContext(D)) | 
|  | 4135 | return std::move(Err); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4136 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4137 | // If we have an implementation, import it as well. | 
|  | 4138 | if (D->getImplementation()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4139 | if (Expected<ObjCCategoryImplDecl *> ToImplOrErr = | 
|  | 4140 | import(D->getImplementation())) | 
|  | 4141 | ToCategory->setImplementation(*ToImplOrErr); | 
|  | 4142 | else | 
|  | 4143 | return ToImplOrErr.takeError(); | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4144 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4145 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4146 | return ToCategory; | 
|  | 4147 | } | 
|  | 4148 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4149 | Error ASTNodeImporter::ImportDefinition( | 
|  | 4150 | ObjCProtocolDecl *From, ObjCProtocolDecl *To, ImportDefinitionKind Kind) { | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4151 | if (To->getDefinition()) { | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4152 | if (shouldForceImportDeclContext(Kind)) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4153 | if (Error Err = ImportDeclContext(From)) | 
|  | 4154 | return Err; | 
|  | 4155 | return Error::success(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4156 | } | 
|  | 4157 |  | 
|  | 4158 | // Start the protocol definition | 
|  | 4159 | To->startDefinition(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4160 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4161 | // Import protocols | 
|  | 4162 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | 
|  | 4163 | SmallVector<SourceLocation, 4> ProtocolLocs; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4164 | ObjCProtocolDecl::protocol_loc_iterator FromProtoLoc = | 
|  | 4165 | From->protocol_loc_begin(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4166 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), | 
|  | 4167 | FromProtoEnd = From->protocol_end(); | 
|  | 4168 | FromProto != FromProtoEnd; | 
|  | 4169 | ++FromProto, ++FromProtoLoc) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4170 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | 
|  | 4171 | Protocols.push_back(*ToProtoOrErr); | 
|  | 4172 | else | 
|  | 4173 | return ToProtoOrErr.takeError(); | 
|  | 4174 |  | 
|  | 4175 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | 
|  | 4176 | ProtocolLocs.push_back(*ToProtoLocOrErr); | 
|  | 4177 | else | 
|  | 4178 | return ToProtoLocOrErr.takeError(); | 
|  | 4179 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4180 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4181 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4182 | // FIXME: If we're merging, make sure that the protocol list is the same. | 
|  | 4183 | To->setProtocolList(Protocols.data(), Protocols.size(), | 
|  | 4184 | ProtocolLocs.data(), Importer.getToContext()); | 
|  | 4185 |  | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4186 | if (shouldForceImportDeclContext(Kind)) { | 
|  | 4187 | // Import all of the members of this protocol. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4188 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | 
|  | 4189 | return Err; | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4190 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4191 | return Error::success(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4192 | } | 
|  | 4193 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4194 | ExpectedDecl ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4195 | // 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] | 4196 | // from, but this particular declaration is not that definition, import the | 
|  | 4197 | // definition and map to that. | 
|  | 4198 | ObjCProtocolDecl *Definition = D->getDefinition(); | 
|  | 4199 | if (Definition && Definition != D) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4200 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | 
|  | 4201 | return Importer.MapImported(D, *ImportedDefOrErr); | 
|  | 4202 | else | 
|  | 4203 | return ImportedDefOrErr.takeError(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4204 | } | 
|  | 4205 |  | 
| Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 4206 | // Import the major distinguishing characteristics of a protocol. | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4207 | DeclContext *DC, *LexicalDC; | 
|  | 4208 | DeclarationName Name; | 
|  | 4209 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4210 | NamedDecl *ToD; | 
| 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); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4213 | if (ToD) | 
|  | 4214 | return ToD; | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4215 |  | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4216 | ObjCProtocolDecl *MergeWithProtocol = nullptr; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4217 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4218 | for (auto *FoundDecl : FoundDecls) { | 
|  | 4219 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4220 | continue; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4221 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4222 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4223 | break; | 
|  | 4224 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4225 |  | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4226 | ObjCProtocolDecl *ToProto = MergeWithProtocol; | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4227 | if (!ToProto) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4228 | auto ToAtBeginLocOrErr = import(D->getAtStartLoc()); | 
|  | 4229 | if (!ToAtBeginLocOrErr) | 
|  | 4230 | return ToAtBeginLocOrErr.takeError(); | 
|  | 4231 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4232 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, | 
|  | 4233 | Name.getAsIdentifierInfo(), Loc, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4234 | *ToAtBeginLocOrErr, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4235 | /*PrevDecl=*/nullptr)) | 
|  | 4236 | return ToProto; | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4237 | ToProto->setLexicalDeclContext(LexicalDC); | 
|  | 4238 | LexicalDC->addDeclInternal(ToProto); | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4239 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4240 |  | 
|  | 4241 | Importer.MapImported(D, ToProto); | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4242 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4243 | if (D->isThisDeclarationADefinition()) | 
|  | 4244 | if (Error Err = ImportDefinition(D, ToProto)) | 
|  | 4245 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4246 |  | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4247 | return ToProto; | 
|  | 4248 | } | 
|  | 4249 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4250 | ExpectedDecl ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { | 
|  | 4251 | DeclContext *DC, *LexicalDC; | 
|  | 4252 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 4253 | return std::move(Err); | 
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4254 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4255 | ExpectedSLoc ExternLocOrErr = import(D->getExternLoc()); | 
|  | 4256 | if (!ExternLocOrErr) | 
|  | 4257 | return ExternLocOrErr.takeError(); | 
|  | 4258 |  | 
|  | 4259 | ExpectedSLoc LangLocOrErr = import(D->getLocation()); | 
|  | 4260 | if (!LangLocOrErr) | 
|  | 4261 | return LangLocOrErr.takeError(); | 
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4262 |  | 
|  | 4263 | bool HasBraces = D->hasBraces(); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4264 |  | 
|  | 4265 | LinkageSpecDecl *ToLinkageSpec; | 
|  | 4266 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4267 | *ExternLocOrErr, *LangLocOrErr, | 
|  | 4268 | D->getLanguage(), HasBraces)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4269 | return ToLinkageSpec; | 
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4270 |  | 
|  | 4271 | if (HasBraces) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4272 | ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc()); | 
|  | 4273 | if (!RBraceLocOrErr) | 
|  | 4274 | return RBraceLocOrErr.takeError(); | 
|  | 4275 | ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr); | 
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4276 | } | 
|  | 4277 |  | 
|  | 4278 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); | 
|  | 4279 | LexicalDC->addDeclInternal(ToLinkageSpec); | 
|  | 4280 |  | 
| Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 4281 | return ToLinkageSpec; | 
|  | 4282 | } | 
|  | 4283 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4284 | ExpectedDecl ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4285 | DeclContext *DC, *LexicalDC; | 
|  | 4286 | DeclarationName Name; | 
|  | 4287 | SourceLocation Loc; | 
|  | 4288 | NamedDecl *ToD = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4289 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4290 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4291 | if (ToD) | 
|  | 4292 | return ToD; | 
|  | 4293 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4294 | SourceLocation ToLoc, ToUsingLoc; | 
|  | 4295 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 4296 | if (auto Imp = importSeq( | 
|  | 4297 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc())) | 
|  | 4298 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc) = *Imp; | 
|  | 4299 | else | 
|  | 4300 | return Imp.takeError(); | 
|  | 4301 |  | 
|  | 4302 | DeclarationNameInfo NameInfo(Name, ToLoc); | 
|  | 4303 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | 
|  | 4304 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4305 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4306 | UsingDecl *ToUsing; | 
|  | 4307 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4308 | ToUsingLoc, ToQualifierLoc, NameInfo, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4309 | D->hasTypename())) | 
|  | 4310 | return ToUsing; | 
|  | 4311 |  | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4312 | ToUsing->setLexicalDeclContext(LexicalDC); | 
|  | 4313 | LexicalDC->addDeclInternal(ToUsing); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4314 |  | 
|  | 4315 | if (NamedDecl *FromPattern = | 
|  | 4316 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4317 | if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern)) | 
|  | 4318 | Importer.getToContext().setInstantiatedFromUsingDecl( | 
|  | 4319 | ToUsing, *ToPatternOrErr); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4320 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4321 | return ToPatternOrErr.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4322 | } | 
|  | 4323 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4324 | for (UsingShadowDecl *FromShadow : D->shadows()) { | 
|  | 4325 | if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow)) | 
|  | 4326 | ToUsing->addShadowDecl(*ToShadowOrErr); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4327 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4328 | // FIXME: We return error here but the definition is already created | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4329 | // and available with lookups. How to fix this?.. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4330 | return ToShadowOrErr.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4331 | } | 
|  | 4332 | return ToUsing; | 
|  | 4333 | } | 
|  | 4334 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4335 | ExpectedDecl ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4336 | DeclContext *DC, *LexicalDC; | 
|  | 4337 | DeclarationName Name; | 
|  | 4338 | SourceLocation Loc; | 
|  | 4339 | NamedDecl *ToD = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4340 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4341 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4342 | if (ToD) | 
|  | 4343 | return ToD; | 
|  | 4344 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4345 | Expected<UsingDecl *> ToUsingOrErr = import(D->getUsingDecl()); | 
|  | 4346 | if (!ToUsingOrErr) | 
|  | 4347 | return ToUsingOrErr.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4348 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4349 | Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl()); | 
|  | 4350 | if (!ToTargetOrErr) | 
|  | 4351 | return ToTargetOrErr.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4352 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4353 | UsingShadowDecl *ToShadow; | 
|  | 4354 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4355 | *ToUsingOrErr, *ToTargetOrErr)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4356 | return ToShadow; | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4357 |  | 
|  | 4358 | ToShadow->setLexicalDeclContext(LexicalDC); | 
|  | 4359 | ToShadow->setAccess(D->getAccess()); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4360 |  | 
|  | 4361 | if (UsingShadowDecl *FromPattern = | 
|  | 4362 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4363 | if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern)) | 
|  | 4364 | Importer.getToContext().setInstantiatedFromUsingShadowDecl( | 
|  | 4365 | ToShadow, *ToPatternOrErr); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4366 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4367 | // FIXME: We return error here but the definition is already created | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4368 | // and available with lookups. How to fix this?.. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4369 | return ToPatternOrErr.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4370 | } | 
|  | 4371 |  | 
|  | 4372 | LexicalDC->addDeclInternal(ToShadow); | 
|  | 4373 |  | 
|  | 4374 | return ToShadow; | 
|  | 4375 | } | 
|  | 4376 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4377 | ExpectedDecl ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4378 | DeclContext *DC, *LexicalDC; | 
|  | 4379 | DeclarationName Name; | 
|  | 4380 | SourceLocation Loc; | 
|  | 4381 | NamedDecl *ToD = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4382 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4383 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4384 | if (ToD) | 
|  | 4385 | return ToD; | 
|  | 4386 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4387 | auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor()); | 
|  | 4388 | if (!ToComAncestorOrErr) | 
|  | 4389 | return ToComAncestorOrErr.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4390 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4391 | NamespaceDecl *ToNominatedNamespace; | 
|  | 4392 | SourceLocation ToUsingLoc, ToNamespaceKeyLocation, ToIdentLocation; | 
|  | 4393 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 4394 | if (auto Imp = importSeq( | 
|  | 4395 | D->getNominatedNamespace(), D->getUsingLoc(), | 
|  | 4396 | D->getNamespaceKeyLocation(), D->getQualifierLoc(), | 
|  | 4397 | D->getIdentLocation())) | 
|  | 4398 | std::tie( | 
|  | 4399 | ToNominatedNamespace, ToUsingLoc, ToNamespaceKeyLocation, | 
|  | 4400 | ToQualifierLoc, ToIdentLocation) = *Imp; | 
|  | 4401 | else | 
|  | 4402 | return Imp.takeError(); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4403 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4404 | UsingDirectiveDecl *ToUsingDir; | 
|  | 4405 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4406 | ToUsingLoc, | 
|  | 4407 | ToNamespaceKeyLocation, | 
|  | 4408 | ToQualifierLoc, | 
|  | 4409 | ToIdentLocation, | 
|  | 4410 | ToNominatedNamespace, *ToComAncestorOrErr)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4411 | return ToUsingDir; | 
|  | 4412 |  | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4413 | ToUsingDir->setLexicalDeclContext(LexicalDC); | 
|  | 4414 | LexicalDC->addDeclInternal(ToUsingDir); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4415 |  | 
|  | 4416 | return ToUsingDir; | 
|  | 4417 | } | 
|  | 4418 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4419 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingValueDecl( | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4420 | UnresolvedUsingValueDecl *D) { | 
|  | 4421 | DeclContext *DC, *LexicalDC; | 
|  | 4422 | DeclarationName Name; | 
|  | 4423 | SourceLocation Loc; | 
|  | 4424 | NamedDecl *ToD = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4425 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4426 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4427 | if (ToD) | 
|  | 4428 | return ToD; | 
|  | 4429 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4430 | SourceLocation ToLoc, ToUsingLoc, ToEllipsisLoc; | 
|  | 4431 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 4432 | if (auto Imp = importSeq( | 
|  | 4433 | D->getNameInfo().getLoc(), D->getUsingLoc(), D->getQualifierLoc(), | 
|  | 4434 | D->getEllipsisLoc())) | 
|  | 4435 | std::tie(ToLoc, ToUsingLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; | 
|  | 4436 | else | 
|  | 4437 | return Imp.takeError(); | 
|  | 4438 |  | 
|  | 4439 | DeclarationNameInfo NameInfo(Name, ToLoc); | 
|  | 4440 | if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo)) | 
|  | 4441 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4442 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4443 | UnresolvedUsingValueDecl *ToUsingValue; | 
|  | 4444 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4445 | ToUsingLoc, ToQualifierLoc, NameInfo, | 
|  | 4446 | ToEllipsisLoc)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4447 | return ToUsingValue; | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4448 |  | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4449 | ToUsingValue->setAccess(D->getAccess()); | 
|  | 4450 | ToUsingValue->setLexicalDeclContext(LexicalDC); | 
|  | 4451 | LexicalDC->addDeclInternal(ToUsingValue); | 
|  | 4452 |  | 
|  | 4453 | return ToUsingValue; | 
|  | 4454 | } | 
|  | 4455 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4456 | ExpectedDecl ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4457 | UnresolvedUsingTypenameDecl *D) { | 
|  | 4458 | DeclContext *DC, *LexicalDC; | 
|  | 4459 | DeclarationName Name; | 
|  | 4460 | SourceLocation Loc; | 
|  | 4461 | NamedDecl *ToD = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4462 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4463 | return std::move(Err); | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4464 | if (ToD) | 
|  | 4465 | return ToD; | 
|  | 4466 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4467 | SourceLocation ToUsingLoc, ToTypenameLoc, ToEllipsisLoc; | 
|  | 4468 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 4469 | if (auto Imp = importSeq( | 
|  | 4470 | D->getUsingLoc(), D->getTypenameLoc(), D->getQualifierLoc(), | 
|  | 4471 | D->getEllipsisLoc())) | 
|  | 4472 | std::tie(ToUsingLoc, ToTypenameLoc, ToQualifierLoc, ToEllipsisLoc) = *Imp; | 
|  | 4473 | else | 
|  | 4474 | return Imp.takeError(); | 
|  | 4475 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4476 | UnresolvedUsingTypenameDecl *ToUsing; | 
|  | 4477 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4478 | ToUsingLoc, ToTypenameLoc, | 
|  | 4479 | ToQualifierLoc, Loc, Name, ToEllipsisLoc)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4480 | return ToUsing; | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4481 |  | 
| Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 4482 | ToUsing->setAccess(D->getAccess()); | 
|  | 4483 | ToUsing->setLexicalDeclContext(LexicalDC); | 
|  | 4484 | LexicalDC->addDeclInternal(ToUsing); | 
|  | 4485 |  | 
|  | 4486 | return ToUsing; | 
|  | 4487 | } | 
|  | 4488 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4489 |  | 
|  | 4490 | Error ASTNodeImporter::ImportDefinition( | 
|  | 4491 | ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) { | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4492 | if (To->getDefinition()) { | 
|  | 4493 | // Check consistency of superclass. | 
|  | 4494 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); | 
|  | 4495 | if (FromSuper) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4496 | if (auto FromSuperOrErr = import(FromSuper)) | 
|  | 4497 | FromSuper = *FromSuperOrErr; | 
|  | 4498 | else | 
|  | 4499 | return FromSuperOrErr.takeError(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4500 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4501 |  | 
|  | 4502 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4503 | if ((bool)FromSuper != (bool)ToSuper || | 
|  | 4504 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4505 | Importer.ToDiag(To->getLocation(), | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4506 | diag::warn_odr_objc_superclass_inconsistent) | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4507 | << To->getDeclName(); | 
|  | 4508 | if (ToSuper) | 
|  | 4509 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) | 
|  | 4510 | << To->getSuperClass()->getDeclName(); | 
|  | 4511 | else | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4512 | Importer.ToDiag(To->getLocation(), | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4513 | diag::note_odr_objc_missing_superclass); | 
|  | 4514 | if (From->getSuperClass()) | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4515 | Importer.FromDiag(From->getSuperClassLoc(), | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4516 | diag::note_odr_objc_superclass) | 
|  | 4517 | << From->getSuperClass()->getDeclName(); | 
|  | 4518 | else | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4519 | Importer.FromDiag(From->getLocation(), | 
|  | 4520 | diag::note_odr_objc_missing_superclass); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4521 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4522 |  | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4523 | if (shouldForceImportDeclContext(Kind)) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4524 | if (Error Err = ImportDeclContext(From)) | 
|  | 4525 | return Err; | 
|  | 4526 | return Error::success(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4527 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4528 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4529 | // Start the definition. | 
|  | 4530 | To->startDefinition(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4531 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4532 | // If this class has a superclass, import it. | 
|  | 4533 | if (From->getSuperClass()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4534 | if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo())) | 
|  | 4535 | To->setSuperClass(*SuperTInfoOrErr); | 
|  | 4536 | else | 
|  | 4537 | return SuperTInfoOrErr.takeError(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4538 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4539 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4540 | // Import protocols | 
|  | 4541 | SmallVector<ObjCProtocolDecl *, 4> Protocols; | 
|  | 4542 | SmallVector<SourceLocation, 4> ProtocolLocs; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4543 | ObjCInterfaceDecl::protocol_loc_iterator FromProtoLoc = | 
|  | 4544 | From->protocol_loc_begin(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4545 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4546 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), | 
|  | 4547 | FromProtoEnd = From->protocol_end(); | 
|  | 4548 | FromProto != FromProtoEnd; | 
|  | 4549 | ++FromProto, ++FromProtoLoc) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4550 | if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto)) | 
|  | 4551 | Protocols.push_back(*ToProtoOrErr); | 
|  | 4552 | else | 
|  | 4553 | return ToProtoOrErr.takeError(); | 
|  | 4554 |  | 
|  | 4555 | if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc)) | 
|  | 4556 | ProtocolLocs.push_back(*ToProtoLocOrErr); | 
|  | 4557 | else | 
|  | 4558 | return ToProtoLocOrErr.takeError(); | 
|  | 4559 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4560 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4561 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4562 | // FIXME: If we're merging, make sure that the protocol list is the same. | 
|  | 4563 | To->setProtocolList(Protocols.data(), Protocols.size(), | 
|  | 4564 | ProtocolLocs.data(), Importer.getToContext()); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4565 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4566 | // Import categories. When the categories themselves are imported, they'll | 
|  | 4567 | // hook themselves into this interface. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4568 | for (auto *Cat : From->known_categories()) { | 
|  | 4569 | auto ToCatOrErr = import(Cat); | 
|  | 4570 | if (!ToCatOrErr) | 
|  | 4571 | return ToCatOrErr.takeError(); | 
|  | 4572 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4573 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4574 | // If we have an @implementation, import it as well. | 
|  | 4575 | if (From->getImplementation()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4576 | if (Expected<ObjCImplementationDecl *> ToImplOrErr = | 
|  | 4577 | import(From->getImplementation())) | 
|  | 4578 | To->setImplementation(*ToImplOrErr); | 
|  | 4579 | else | 
|  | 4580 | return ToImplOrErr.takeError(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4581 | } | 
|  | 4582 |  | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4583 | if (shouldForceImportDeclContext(Kind)) { | 
|  | 4584 | // Import all of the members of this class. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4585 | if (Error Err = ImportDeclContext(From, /*ForceImport=*/true)) | 
|  | 4586 | return Err; | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 4587 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4588 | return Error::success(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4589 | } | 
|  | 4590 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4591 | Expected<ObjCTypeParamList *> | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4592 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { | 
|  | 4593 | if (!list) | 
|  | 4594 | return nullptr; | 
|  | 4595 |  | 
|  | 4596 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4597 | for (auto *fromTypeParam : *list) { | 
|  | 4598 | if (auto toTypeParamOrErr = import(fromTypeParam)) | 
|  | 4599 | toTypeParams.push_back(*toTypeParamOrErr); | 
|  | 4600 | else | 
|  | 4601 | return toTypeParamOrErr.takeError(); | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4602 | } | 
|  | 4603 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4604 | auto LAngleLocOrErr = import(list->getLAngleLoc()); | 
|  | 4605 | if (!LAngleLocOrErr) | 
|  | 4606 | return LAngleLocOrErr.takeError(); | 
|  | 4607 |  | 
|  | 4608 | auto RAngleLocOrErr = import(list->getRAngleLoc()); | 
|  | 4609 | if (!RAngleLocOrErr) | 
|  | 4610 | return RAngleLocOrErr.takeError(); | 
|  | 4611 |  | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4612 | return ObjCTypeParamList::create(Importer.getToContext(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4613 | *LAngleLocOrErr, | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4614 | toTypeParams, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4615 | *RAngleLocOrErr); | 
| Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 4616 | } | 
|  | 4617 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4618 | ExpectedDecl ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4619 | // If this class has a definition in the translation unit we're coming from, | 
|  | 4620 | // but this particular declaration is not that definition, import the | 
|  | 4621 | // definition and map to that. | 
|  | 4622 | ObjCInterfaceDecl *Definition = D->getDefinition(); | 
|  | 4623 | if (Definition && Definition != D) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4624 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | 
|  | 4625 | return Importer.MapImported(D, *ImportedDefOrErr); | 
|  | 4626 | else | 
|  | 4627 | return ImportedDefOrErr.takeError(); | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4628 | } | 
|  | 4629 |  | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4630 | // Import the major distinguishing characteristics of an @interface. | 
|  | 4631 | DeclContext *DC, *LexicalDC; | 
|  | 4632 | DeclarationName Name; | 
|  | 4633 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4634 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4635 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4636 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4637 | if (ToD) | 
|  | 4638 | return ToD; | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4639 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4640 | // Look for an existing interface with the same name. | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4641 | ObjCInterfaceDecl *MergeWithIface = nullptr; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4642 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4643 | for (auto *FoundDecl : FoundDecls) { | 
|  | 4644 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4645 | continue; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4646 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4647 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4648 | break; | 
|  | 4649 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4650 |  | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4651 | // Create an interface declaration, if one does not already exist. | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4652 | ObjCInterfaceDecl *ToIface = MergeWithIface; | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4653 | if (!ToIface) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4654 | ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc()); | 
|  | 4655 | if (!AtBeginLocOrErr) | 
|  | 4656 | return AtBeginLocOrErr.takeError(); | 
|  | 4657 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4658 | if (GetImportedOrCreateDecl( | 
|  | 4659 | ToIface, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4660 | *AtBeginLocOrErr, Name.getAsIdentifierInfo(), | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4661 | /*TypeParamList=*/nullptr, | 
|  | 4662 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) | 
|  | 4663 | return ToIface; | 
| Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4664 | ToIface->setLexicalDeclContext(LexicalDC); | 
|  | 4665 | LexicalDC->addDeclInternal(ToIface); | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4666 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4667 | Importer.MapImported(D, ToIface); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4668 | // Import the type parameter list after MapImported, to avoid | 
| Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4669 | // loops when bringing in their DeclContext. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4670 | if (auto ToPListOrErr = | 
|  | 4671 | ImportObjCTypeParamList(D->getTypeParamListAsWritten())) | 
|  | 4672 | ToIface->setTypeParamList(*ToPListOrErr); | 
|  | 4673 | else | 
|  | 4674 | return ToPListOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4675 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4676 | if (D->isThisDeclarationADefinition()) | 
|  | 4677 | if (Error Err = ImportDefinition(D, ToIface)) | 
|  | 4678 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4679 |  | 
| Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4680 | return ToIface; | 
| Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4681 | } | 
|  | 4682 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4683 | ExpectedDecl | 
|  | 4684 | ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { | 
|  | 4685 | ObjCCategoryDecl *Category; | 
|  | 4686 | if (Error Err = importInto(Category, D->getCategoryDecl())) | 
|  | 4687 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4688 |  | 
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4689 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); | 
|  | 4690 | if (!ToImpl) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4691 | DeclContext *DC, *LexicalDC; | 
|  | 4692 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 4693 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4694 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4695 | SourceLocation ToLocation, ToAtStartLoc, ToCategoryNameLoc; | 
|  | 4696 | if (auto Imp = importSeq( | 
|  | 4697 | D->getLocation(), D->getAtStartLoc(), D->getCategoryNameLoc())) | 
|  | 4698 | std::tie(ToLocation, ToAtStartLoc, ToCategoryNameLoc) = *Imp; | 
|  | 4699 | else | 
|  | 4700 | return Imp.takeError(); | 
|  | 4701 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4702 | if (GetImportedOrCreateDecl( | 
|  | 4703 | ToImpl, D, Importer.getToContext(), DC, | 
|  | 4704 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4705 | ToLocation, ToAtStartLoc, ToCategoryNameLoc)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4706 | return ToImpl; | 
|  | 4707 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4708 | ToImpl->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4709 | LexicalDC->addDeclInternal(ToImpl); | 
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4710 | Category->setImplementation(ToImpl); | 
|  | 4711 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4712 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4713 | Importer.MapImported(D, ToImpl); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4714 | if (Error Err = ImportDeclContext(D)) | 
|  | 4715 | return std::move(Err); | 
|  | 4716 |  | 
| Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4717 | return ToImpl; | 
|  | 4718 | } | 
|  | 4719 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4720 | ExpectedDecl | 
|  | 4721 | ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4722 | // Find the corresponding interface. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4723 | ObjCInterfaceDecl *Iface; | 
|  | 4724 | if (Error Err = importInto(Iface, D->getClassInterface())) | 
|  | 4725 | return std::move(Err); | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4726 |  | 
|  | 4727 | // Import the superclass, if any. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4728 | ObjCInterfaceDecl *Super; | 
|  | 4729 | if (Error Err = importInto(Super, D->getSuperClass())) | 
|  | 4730 | return std::move(Err); | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4731 |  | 
|  | 4732 | ObjCImplementationDecl *Impl = Iface->getImplementation(); | 
|  | 4733 | if (!Impl) { | 
|  | 4734 | // We haven't imported an implementation yet. Create a new @implementation | 
|  | 4735 | // now. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4736 | DeclContext *DC, *LexicalDC; | 
|  | 4737 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 4738 | return std::move(Err); | 
|  | 4739 |  | 
|  | 4740 | SourceLocation ToLocation, ToAtStartLoc, ToSuperClassLoc; | 
|  | 4741 | SourceLocation ToIvarLBraceLoc, ToIvarRBraceLoc; | 
|  | 4742 | if (auto Imp = importSeq( | 
|  | 4743 | D->getLocation(), D->getAtStartLoc(), D->getSuperClassLoc(), | 
|  | 4744 | D->getIvarLBraceLoc(), D->getIvarRBraceLoc())) | 
|  | 4745 | std::tie( | 
|  | 4746 | ToLocation, ToAtStartLoc, ToSuperClassLoc, | 
|  | 4747 | ToIvarLBraceLoc, ToIvarRBraceLoc) = *Imp; | 
|  | 4748 | else | 
|  | 4749 | return Imp.takeError(); | 
|  | 4750 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4751 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4752 | DC, Iface, Super, | 
|  | 4753 | ToLocation, | 
|  | 4754 | ToAtStartLoc, | 
|  | 4755 | ToSuperClassLoc, | 
|  | 4756 | ToIvarLBraceLoc, | 
|  | 4757 | ToIvarRBraceLoc)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4758 | return Impl; | 
|  | 4759 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4760 | Impl->setLexicalDeclContext(LexicalDC); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4761 |  | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4762 | // Associate the implementation with the class it implements. | 
|  | 4763 | Iface->setImplementation(Impl); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4764 | Importer.MapImported(D, Iface->getImplementation()); | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4765 | } else { | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4766 | Importer.MapImported(D, Iface->getImplementation()); | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4767 |  | 
|  | 4768 | // Verify that the existing @implementation has the same superclass. | 
|  | 4769 | if ((Super && !Impl->getSuperClass()) || | 
|  | 4770 | (!Super && Impl->getSuperClass()) || | 
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4771 | (Super && Impl->getSuperClass() && | 
|  | 4772 | !declaresSameEntity(Super->getCanonicalDecl(), | 
|  | 4773 | Impl->getSuperClass()))) { | 
|  | 4774 | Importer.ToDiag(Impl->getLocation(), | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4775 | diag::warn_odr_objc_superclass_inconsistent) | 
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4776 | << Iface->getDeclName(); | 
|  | 4777 | // FIXME: It would be nice to have the location of the superclass | 
|  | 4778 | // below. | 
|  | 4779 | if (Impl->getSuperClass()) | 
|  | 4780 | Importer.ToDiag(Impl->getLocation(), | 
|  | 4781 | diag::note_odr_objc_superclass) | 
|  | 4782 | << Impl->getSuperClass()->getDeclName(); | 
|  | 4783 | else | 
|  | 4784 | Importer.ToDiag(Impl->getLocation(), | 
|  | 4785 | diag::note_odr_objc_missing_superclass); | 
|  | 4786 | if (D->getSuperClass()) | 
|  | 4787 | Importer.FromDiag(D->getLocation(), | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4788 | diag::note_odr_objc_superclass) | 
| Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4789 | << D->getSuperClass()->getDeclName(); | 
|  | 4790 | else | 
|  | 4791 | Importer.FromDiag(D->getLocation(), | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4792 | diag::note_odr_objc_missing_superclass); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4793 |  | 
|  | 4794 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4795 | } | 
|  | 4796 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4797 |  | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4798 | // Import all of the members of this @implementation. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4799 | if (Error Err = ImportDeclContext(D)) | 
|  | 4800 | return std::move(Err); | 
| Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4801 |  | 
|  | 4802 | return Impl; | 
|  | 4803 | } | 
|  | 4804 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4805 | ExpectedDecl ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4806 | // Import the major distinguishing characteristics of an @property. | 
|  | 4807 | DeclContext *DC, *LexicalDC; | 
|  | 4808 | DeclarationName Name; | 
|  | 4809 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4810 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4811 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 4812 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4813 | if (ToD) | 
|  | 4814 | return ToD; | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4815 |  | 
|  | 4816 | // Check whether we have already imported this property. | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 4817 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4818 | for (auto *FoundDecl : FoundDecls) { | 
|  | 4819 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4820 | // Check property types. | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4821 | if (!Importer.IsStructurallyEquivalent(D->getType(), | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4822 | FoundProp->getType())) { | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4823 | Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent) | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4824 | << Name << D->getType() << FoundProp->getType(); | 
|  | 4825 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) | 
|  | 4826 | << FoundProp->getType(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4827 |  | 
|  | 4828 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4829 | } | 
|  | 4830 |  | 
|  | 4831 | // FIXME: Check property attributes, getters, setters, etc.? | 
|  | 4832 |  | 
|  | 4833 | // Consider these properties to be equivalent. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4834 | Importer.MapImported(D, FoundProp); | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4835 | return FoundProp; | 
|  | 4836 | } | 
|  | 4837 | } | 
|  | 4838 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4839 | QualType ToType; | 
|  | 4840 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 4841 | SourceLocation ToAtLoc, ToLParenLoc; | 
|  | 4842 | if (auto Imp = importSeq( | 
|  | 4843 | D->getType(), D->getTypeSourceInfo(), D->getAtLoc(), D->getLParenLoc())) | 
|  | 4844 | std::tie(ToType, ToTypeSourceInfo, ToAtLoc, ToLParenLoc) = *Imp; | 
|  | 4845 | else | 
|  | 4846 | return Imp.takeError(); | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4847 |  | 
|  | 4848 | // Create the new property. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4849 | ObjCPropertyDecl *ToProperty; | 
|  | 4850 | if (GetImportedOrCreateDecl( | 
|  | 4851 | ToProperty, D, Importer.getToContext(), DC, Loc, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4852 | Name.getAsIdentifierInfo(), ToAtLoc, | 
|  | 4853 | ToLParenLoc, ToType, | 
|  | 4854 | ToTypeSourceInfo, D->getPropertyImplementation())) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4855 | return ToProperty; | 
|  | 4856 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4857 | Selector ToGetterName, ToSetterName; | 
|  | 4858 | SourceLocation ToGetterNameLoc, ToSetterNameLoc; | 
|  | 4859 | ObjCMethodDecl *ToGetterMethodDecl, *ToSetterMethodDecl; | 
|  | 4860 | ObjCIvarDecl *ToPropertyIvarDecl; | 
|  | 4861 | if (auto Imp = importSeq( | 
|  | 4862 | D->getGetterName(), D->getSetterName(), | 
|  | 4863 | D->getGetterNameLoc(), D->getSetterNameLoc(), | 
|  | 4864 | D->getGetterMethodDecl(), D->getSetterMethodDecl(), | 
|  | 4865 | D->getPropertyIvarDecl())) | 
|  | 4866 | std::tie( | 
|  | 4867 | ToGetterName, ToSetterName, | 
|  | 4868 | ToGetterNameLoc, ToSetterNameLoc, | 
|  | 4869 | ToGetterMethodDecl, ToSetterMethodDecl, | 
|  | 4870 | ToPropertyIvarDecl) = *Imp; | 
|  | 4871 | else | 
|  | 4872 | return Imp.takeError(); | 
|  | 4873 |  | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4874 | ToProperty->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4875 | LexicalDC->addDeclInternal(ToProperty); | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4876 |  | 
|  | 4877 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); | 
| Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4878 | ToProperty->setPropertyAttributesAsWritten( | 
|  | 4879 | D->getPropertyAttributesAsWritten()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4880 | ToProperty->setGetterName(ToGetterName, ToGetterNameLoc); | 
|  | 4881 | ToProperty->setSetterName(ToSetterName, ToSetterNameLoc); | 
|  | 4882 | ToProperty->setGetterMethodDecl(ToGetterMethodDecl); | 
|  | 4883 | ToProperty->setSetterMethodDecl(ToSetterMethodDecl); | 
|  | 4884 | ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl); | 
| Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4885 | return ToProperty; | 
|  | 4886 | } | 
|  | 4887 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4888 | ExpectedDecl | 
|  | 4889 | ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { | 
|  | 4890 | ObjCPropertyDecl *Property; | 
|  | 4891 | if (Error Err = importInto(Property, D->getPropertyDecl())) | 
|  | 4892 | return std::move(Err); | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4893 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4894 | DeclContext *DC, *LexicalDC; | 
|  | 4895 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 4896 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4897 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4898 | auto *InImpl = cast<ObjCImplDecl>(LexicalDC); | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4899 |  | 
|  | 4900 | // Import the ivar (for an @synthesize). | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4901 | ObjCIvarDecl *Ivar = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4902 | if (Error Err = importInto(Ivar, D->getPropertyIvarDecl())) | 
|  | 4903 | return std::move(Err); | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4904 |  | 
|  | 4905 | ObjCPropertyImplDecl *ToImpl | 
| Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 4906 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), | 
|  | 4907 | Property->getQueryKind()); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4908 | if (!ToImpl) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4909 | SourceLocation ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc; | 
|  | 4910 | if (auto Imp = importSeq( | 
|  | 4911 | D->getBeginLoc(), D->getLocation(), D->getPropertyIvarDeclLoc())) | 
|  | 4912 | std::tie(ToBeginLoc, ToLocation, ToPropertyIvarDeclLoc) = *Imp; | 
|  | 4913 | else | 
|  | 4914 | return Imp.takeError(); | 
|  | 4915 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4916 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4917 | ToBeginLoc, | 
|  | 4918 | ToLocation, Property, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4919 | D->getPropertyImplementation(), Ivar, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4920 | ToPropertyIvarDeclLoc)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4921 | return ToImpl; | 
|  | 4922 |  | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4923 | ToImpl->setLexicalDeclContext(LexicalDC); | 
| Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4924 | LexicalDC->addDeclInternal(ToImpl); | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4925 | } else { | 
|  | 4926 | // Check that we have the same kind of property implementation (@synthesize | 
|  | 4927 | // vs. @dynamic). | 
|  | 4928 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4929 | Importer.ToDiag(ToImpl->getLocation(), | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4930 | diag::warn_odr_objc_property_impl_kind_inconsistent) | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4931 | << Property->getDeclName() | 
|  | 4932 | << (ToImpl->getPropertyImplementation() | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4933 | == ObjCPropertyImplDecl::Dynamic); | 
|  | 4934 | Importer.FromDiag(D->getLocation(), | 
|  | 4935 | diag::note_odr_objc_property_impl_kind) | 
|  | 4936 | << D->getPropertyDecl()->getDeclName() | 
|  | 4937 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4938 |  | 
|  | 4939 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4940 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4941 |  | 
|  | 4942 | // For @synthesize, check that we have the same | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4943 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && | 
|  | 4944 | Ivar != ToImpl->getPropertyIvarDecl()) { | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4945 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), | 
| Gabor Marton | 410f32c | 2019-04-01 15:29:55 +0000 | [diff] [blame] | 4946 | diag::warn_odr_objc_synthesize_ivar_inconsistent) | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4947 | << Property->getDeclName() | 
|  | 4948 | << ToImpl->getPropertyIvarDecl()->getDeclName() | 
|  | 4949 | << Ivar->getDeclName(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4950 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4951 | diag::note_odr_objc_synthesize_ivar_here) | 
|  | 4952 | << D->getPropertyIvarDecl()->getDeclName(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4953 |  | 
|  | 4954 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4955 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4956 |  | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4957 | // Merge the existing implementation with the new implementation. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4958 | Importer.MapImported(D, ToImpl); | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4959 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4960 |  | 
| Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4961 | return ToImpl; | 
|  | 4962 | } | 
|  | 4963 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4964 | ExpectedDecl | 
|  | 4965 | ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4966 | // For template arguments, we adopt the translation unit as our declaration | 
|  | 4967 | // context. This context will be fixed when the actual template declaration | 
|  | 4968 | // is created. | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4969 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4970 | // FIXME: Import default argument. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4971 |  | 
|  | 4972 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | 
|  | 4973 | if (!BeginLocOrErr) | 
|  | 4974 | return BeginLocOrErr.takeError(); | 
|  | 4975 |  | 
|  | 4976 | ExpectedSLoc LocationOrErr = import(D->getLocation()); | 
|  | 4977 | if (!LocationOrErr) | 
|  | 4978 | return LocationOrErr.takeError(); | 
|  | 4979 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4980 | TemplateTypeParmDecl *ToD = nullptr; | 
|  | 4981 | (void)GetImportedOrCreateDecl( | 
|  | 4982 | ToD, D, Importer.getToContext(), | 
|  | 4983 | Importer.getToContext().getTranslationUnitDecl(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4984 | *BeginLocOrErr, *LocationOrErr, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4985 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), | 
|  | 4986 | D->wasDeclaredWithTypename(), D->isParameterPack()); | 
|  | 4987 | return ToD; | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4988 | } | 
|  | 4989 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4990 | ExpectedDecl | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4991 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 4992 | DeclarationName ToDeclName; | 
|  | 4993 | SourceLocation ToLocation, ToInnerLocStart; | 
|  | 4994 | QualType ToType; | 
|  | 4995 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 4996 | if (auto Imp = importSeq( | 
|  | 4997 | D->getDeclName(), D->getLocation(), D->getType(), D->getTypeSourceInfo(), | 
|  | 4998 | D->getInnerLocStart())) | 
|  | 4999 | std::tie( | 
|  | 5000 | ToDeclName, ToLocation, ToType, ToTypeSourceInfo, | 
|  | 5001 | ToInnerLocStart) = *Imp; | 
|  | 5002 | else | 
|  | 5003 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5004 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5005 | // FIXME: Import default argument. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5006 |  | 
|  | 5007 | NonTypeTemplateParmDecl *ToD = nullptr; | 
|  | 5008 | (void)GetImportedOrCreateDecl( | 
|  | 5009 | ToD, D, Importer.getToContext(), | 
|  | 5010 | Importer.getToContext().getTranslationUnitDecl(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5011 | ToInnerLocStart, ToLocation, D->getDepth(), | 
|  | 5012 | D->getPosition(), ToDeclName.getAsIdentifierInfo(), ToType, | 
|  | 5013 | D->isParameterPack(), ToTypeSourceInfo); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5014 | return ToD; | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5015 | } | 
|  | 5016 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5017 | ExpectedDecl | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5018 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { | 
|  | 5019 | // Import the name of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5020 | auto NameOrErr = import(D->getDeclName()); | 
|  | 5021 | if (!NameOrErr) | 
|  | 5022 | return NameOrErr.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5023 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5024 | // Import the location of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5025 | ExpectedSLoc LocationOrErr = import(D->getLocation()); | 
|  | 5026 | if (!LocationOrErr) | 
|  | 5027 | return LocationOrErr.takeError(); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5028 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5029 | // Import template parameters. | 
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5030 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5031 | if (!TemplateParamsOrErr) | 
|  | 5032 | return TemplateParamsOrErr.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5033 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5034 | // FIXME: Import default argument. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5035 |  | 
|  | 5036 | TemplateTemplateParmDecl *ToD = nullptr; | 
|  | 5037 | (void)GetImportedOrCreateDecl( | 
|  | 5038 | ToD, D, Importer.getToContext(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5039 | Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr, | 
|  | 5040 | D->getDepth(), D->getPosition(), D->isParameterPack(), | 
|  | 5041 | (*NameOrErr).getAsIdentifierInfo(), | 
|  | 5042 | *TemplateParamsOrErr); | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5043 | return ToD; | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5044 | } | 
|  | 5045 |  | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5046 | // Returns the definition for a (forward) declaration of a TemplateDecl, if | 
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5047 | // it has any definition in the redecl chain. | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5048 | template <typename T> static auto getTemplateDefinition(T *D) -> T * { | 
|  | 5049 | assert(D->getTemplatedDecl() && "Should be called on templates only"); | 
|  | 5050 | auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); | 
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5051 | if (!ToTemplatedDef) | 
|  | 5052 | return nullptr; | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5053 | auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate(); | 
|  | 5054 | return cast_or_null<T>(TemplateWithDef); | 
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5055 | } | 
|  | 5056 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5057 | ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { | 
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5058 | bool IsFriend = D->getFriendObjectKind() != Decl::FOK_None; | 
|  | 5059 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5060 | // Import the major distinguishing characteristics of this class template. | 
|  | 5061 | DeclContext *DC, *LexicalDC; | 
|  | 5062 | DeclarationName Name; | 
|  | 5063 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5064 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5065 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 5066 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5067 | if (ToD) | 
|  | 5068 | return ToD; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5069 |  | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5070 | ClassTemplateDecl *FoundByLookup = nullptr; | 
|  | 5071 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5072 | // We may already have a template of the same name; try to find and match it. | 
|  | 5073 | if (!DC->isFunctionOrMethod()) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5074 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5075 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5076 | for (auto *FoundDecl : FoundDecls) { | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5077 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary | | 
|  | 5078 | Decl::IDNS_TagFriend)) | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5079 | continue; | 
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5080 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5081 | Decl *Found = FoundDecl; | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5082 | auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found); | 
|  | 5083 | if (FoundTemplate) { | 
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5084 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5085 | if (IsStructuralMatch(D, FoundTemplate)) { | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5086 | ClassTemplateDecl *TemplateWithDef = | 
|  | 5087 | getTemplateDefinition(FoundTemplate); | 
| Balazs Keri | 2e16060 | 2019-08-12 10:07:38 +0000 | [diff] [blame] | 5088 | if (D->isThisDeclarationADefinition() && TemplateWithDef) | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5089 | return Importer.MapImported(D, TemplateWithDef); | 
| Balazs Keri | 2e16060 | 2019-08-12 10:07:38 +0000 | [diff] [blame] | 5090 | if (!FoundByLookup) | 
|  | 5091 | FoundByLookup = FoundTemplate; | 
|  | 5092 | // Search in all matches because there may be multiple decl chains, | 
|  | 5093 | // see ASTTests test ImportExistingFriendClassTemplateDef. | 
|  | 5094 | continue; | 
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5095 | } | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5096 | } | 
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5097 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5098 | ConflictingDecls.push_back(FoundDecl); | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5099 | } | 
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5100 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5101 | if (!ConflictingDecls.empty()) { | 
|  | 5102 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, | 
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5103 | ConflictingDecls.data(), | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5104 | ConflictingDecls.size()); | 
|  | 5105 | } | 
| Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 5106 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5107 | if (!Name) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5108 | return make_error<ImportError>(ImportError::NameConflict); | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5109 | } | 
|  | 5110 |  | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5111 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); | 
|  | 5112 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5113 | // Create the declaration that is being templated. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5114 | CXXRecordDecl *ToTemplated; | 
|  | 5115 | if (Error Err = importInto(ToTemplated, FromTemplated)) | 
|  | 5116 | return std::move(Err); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5117 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5118 | // Create the class template declaration itself. | 
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5119 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5120 | if (!TemplateParamsOrErr) | 
|  | 5121 | return TemplateParamsOrErr.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5122 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5123 | ClassTemplateDecl *D2; | 
|  | 5124 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5125 | *TemplateParamsOrErr, ToTemplated)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5126 | return D2; | 
|  | 5127 |  | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5128 | ToTemplated->setDescribedClassTemplate(D2); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5129 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5130 | D2->setAccess(D->getAccess()); | 
|  | 5131 | D2->setLexicalDeclContext(LexicalDC); | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5132 |  | 
|  | 5133 | if (D->getDeclContext()->containsDeclAndLoad(D)) | 
|  | 5134 | DC->addDeclInternal(D2); | 
|  | 5135 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) | 
| Balazs Keri | 0c23dc5 | 2018-08-13 13:08:37 +0000 | [diff] [blame] | 5136 | LexicalDC->addDeclInternal(D2); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5137 |  | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5138 | if (FoundByLookup) { | 
|  | 5139 | auto *Recent = | 
|  | 5140 | const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl()); | 
|  | 5141 |  | 
|  | 5142 | // It is possible that during the import of the class template definition | 
|  | 5143 | // we start the import of a fwd friend decl of the very same class template | 
|  | 5144 | // and we add the fwd friend decl to the lookup table. But the ToTemplated | 
|  | 5145 | // had been created earlier and by that time the lookup could not find | 
|  | 5146 | // anything existing, so it has no previous decl. Later, (still during the | 
|  | 5147 | // import of the fwd friend decl) we start to import the definition again | 
|  | 5148 | // and this time the lookup finds the previous fwd friend class template. | 
|  | 5149 | // In this case we must set up the previous decl for the templated decl. | 
|  | 5150 | if (!ToTemplated->getPreviousDecl()) { | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5151 | assert(FoundByLookup->getTemplatedDecl() && | 
|  | 5152 | "Found decl must have its templated decl set"); | 
| Gabor Marton | 7df342a | 2018-12-17 12:42:12 +0000 | [diff] [blame] | 5153 | CXXRecordDecl *PrevTemplated = | 
|  | 5154 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); | 
|  | 5155 | if (ToTemplated != PrevTemplated) | 
|  | 5156 | ToTemplated->setPreviousDecl(PrevTemplated); | 
|  | 5157 | } | 
|  | 5158 |  | 
|  | 5159 | D2->setPreviousDecl(Recent); | 
|  | 5160 | } | 
|  | 5161 |  | 
|  | 5162 | if (LexicalDC != DC && IsFriend) | 
|  | 5163 | DC->makeDeclVisibleInContext(D2); | 
|  | 5164 |  | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5165 | if (FromTemplated->isCompleteDefinition() && | 
|  | 5166 | !ToTemplated->isCompleteDefinition()) { | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5167 | // FIXME: Import definition! | 
|  | 5168 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5169 |  | 
| Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 5170 | return D2; | 
|  | 5171 | } | 
|  | 5172 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5173 | ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl( | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5174 | ClassTemplateSpecializationDecl *D) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5175 | ClassTemplateDecl *ClassTemplate; | 
|  | 5176 | if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate())) | 
|  | 5177 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5178 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5179 | // Import the context of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5180 | DeclContext *DC, *LexicalDC; | 
|  | 5181 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 5182 | return std::move(Err); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5183 |  | 
|  | 5184 | // Import template arguments. | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5185 | SmallVector<TemplateArgument, 2> TemplateArgs; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5186 | if (Error Err = ImportTemplateArguments( | 
|  | 5187 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) | 
|  | 5188 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5189 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5190 | // Try to find an existing specialization with these template arguments. | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5191 | void *InsertPos = nullptr; | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5192 | ClassTemplateSpecializationDecl *PrevDecl = nullptr; | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5193 | ClassTemplatePartialSpecializationDecl *PartialSpec = | 
|  | 5194 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D); | 
|  | 5195 | if (PartialSpec) | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5196 | PrevDecl = | 
|  | 5197 | ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos); | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5198 | else | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5199 | PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5200 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5201 | if (PrevDecl) { | 
|  | 5202 | if (IsStructuralMatch(D, PrevDecl)) { | 
|  | 5203 | if (D->isThisDeclarationADefinition() && PrevDecl->getDefinition()) { | 
|  | 5204 | Importer.MapImported(D, PrevDecl->getDefinition()); | 
|  | 5205 | // Import those default field initializers which have been | 
|  | 5206 | // instantiated in the "From" context, but not in the "To" context. | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5207 | for (auto *FromField : D->fields()) { | 
|  | 5208 | auto ToOrErr = import(FromField); | 
|  | 5209 | if (!ToOrErr) | 
|  | 5210 | return ToOrErr.takeError(); | 
|  | 5211 | } | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5212 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5213 | // Import those methods which have been instantiated in the | 
|  | 5214 | // "From" context, but not in the "To" context. | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 5215 | for (CXXMethodDecl *FromM : D->methods()) { | 
|  | 5216 | auto ToOrErr = import(FromM); | 
|  | 5217 | if (!ToOrErr) | 
|  | 5218 | return ToOrErr.takeError(); | 
|  | 5219 | } | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5220 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5221 | // TODO Import instantiated default arguments. | 
|  | 5222 | // TODO Import instantiated exception specifications. | 
|  | 5223 | // | 
|  | 5224 | // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint | 
|  | 5225 | // what else could be fused during an AST merge. | 
|  | 5226 | return PrevDecl; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5227 | } | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5228 | } else { // ODR violation. | 
|  | 5229 | // FIXME HandleNameConflict | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 5230 | return make_error<ImportError>(ImportError::NameConflict); | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5231 | } | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5232 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5233 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5234 | // Import the location of this declaration. | 
|  | 5235 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | 
|  | 5236 | if (!BeginLocOrErr) | 
|  | 5237 | return BeginLocOrErr.takeError(); | 
|  | 5238 | ExpectedSLoc IdLocOrErr = import(D->getLocation()); | 
|  | 5239 | if (!IdLocOrErr) | 
|  | 5240 | return IdLocOrErr.takeError(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5241 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5242 | // Create the specialization. | 
|  | 5243 | ClassTemplateSpecializationDecl *D2 = nullptr; | 
|  | 5244 | if (PartialSpec) { | 
|  | 5245 | // Import TemplateArgumentListInfo. | 
|  | 5246 | TemplateArgumentListInfo ToTAInfo; | 
|  | 5247 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); | 
|  | 5248 | if (Error Err = ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) | 
|  | 5249 | return std::move(Err); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5250 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5251 | QualType CanonInjType; | 
|  | 5252 | if (Error Err = importInto( | 
|  | 5253 | CanonInjType, PartialSpec->getInjectedSpecializationType())) | 
|  | 5254 | return std::move(Err); | 
|  | 5255 | CanonInjType = CanonInjType.getCanonicalType(); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5256 |  | 
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5257 | auto ToTPListOrErr = import(PartialSpec->getTemplateParameters()); | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5258 | if (!ToTPListOrErr) | 
|  | 5259 | return ToTPListOrErr.takeError(); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5260 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5261 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( | 
|  | 5262 | D2, D, Importer.getToContext(), D->getTagKind(), DC, | 
|  | 5263 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, ClassTemplate, | 
|  | 5264 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), | 
|  | 5265 | ToTAInfo, CanonInjType, | 
|  | 5266 | cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl))) | 
|  | 5267 | return D2; | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5268 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5269 | // Update InsertPos, because preceding import calls may have invalidated | 
|  | 5270 | // it by adding new specializations. | 
|  | 5271 | if (!ClassTemplate->findPartialSpecialization(TemplateArgs, InsertPos)) | 
|  | 5272 | // Add this partial specialization to the class template. | 
|  | 5273 | ClassTemplate->AddPartialSpecialization( | 
|  | 5274 | cast<ClassTemplatePartialSpecializationDecl>(D2), InsertPos); | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5275 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5276 | } else { // Not a partial specialization. | 
|  | 5277 | if (GetImportedOrCreateDecl( | 
|  | 5278 | D2, D, Importer.getToContext(), D->getTagKind(), DC, | 
|  | 5279 | *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs, | 
|  | 5280 | PrevDecl)) | 
|  | 5281 | return D2; | 
| Gabor Marton | 42e15de | 2018-08-22 11:52:14 +0000 | [diff] [blame] | 5282 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5283 | // Update InsertPos, because preceding import calls may have invalidated | 
|  | 5284 | // it by adding new specializations. | 
|  | 5285 | if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos)) | 
|  | 5286 | // Add this specialization to the class template. | 
|  | 5287 | ClassTemplate->AddSpecialization(D2, InsertPos); | 
|  | 5288 | } | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5289 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5290 | D2->setSpecializationKind(D->getSpecializationKind()); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5291 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5292 | // Set the context of this specialization/instantiation. | 
|  | 5293 | D2->setLexicalDeclContext(LexicalDC); | 
|  | 5294 |  | 
|  | 5295 | // Add to the DC only if it was an explicit specialization/instantiation. | 
|  | 5296 | if (D2->isExplicitInstantiationOrSpecialization()) { | 
|  | 5297 | LexicalDC->addDeclInternal(D2); | 
|  | 5298 | } | 
|  | 5299 |  | 
|  | 5300 | // Import the qualifier, if any. | 
|  | 5301 | if (auto LocOrErr = import(D->getQualifierLoc())) | 
|  | 5302 | D2->setQualifierInfo(*LocOrErr); | 
|  | 5303 | else | 
|  | 5304 | return LocOrErr.takeError(); | 
|  | 5305 |  | 
|  | 5306 | if (auto *TSI = D->getTypeAsWritten()) { | 
|  | 5307 | if (auto TInfoOrErr = import(TSI)) | 
|  | 5308 | D2->setTypeAsWritten(*TInfoOrErr); | 
|  | 5309 | else | 
|  | 5310 | return TInfoOrErr.takeError(); | 
|  | 5311 |  | 
|  | 5312 | if (auto LocOrErr = import(D->getTemplateKeywordLoc())) | 
|  | 5313 | D2->setTemplateKeywordLoc(*LocOrErr); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5314 | else | 
|  | 5315 | return LocOrErr.takeError(); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 5316 |  | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5317 | if (auto LocOrErr = import(D->getExternLoc())) | 
|  | 5318 | D2->setExternLoc(*LocOrErr); | 
|  | 5319 | else | 
|  | 5320 | return LocOrErr.takeError(); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5321 | } | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 5322 |  | 
|  | 5323 | if (D->getPointOfInstantiation().isValid()) { | 
|  | 5324 | if (auto POIOrErr = import(D->getPointOfInstantiation())) | 
|  | 5325 | D2->setPointOfInstantiation(*POIOrErr); | 
|  | 5326 | else | 
|  | 5327 | return POIOrErr.takeError(); | 
|  | 5328 | } | 
|  | 5329 |  | 
|  | 5330 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); | 
|  | 5331 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5332 | if (D->isCompleteDefinition()) | 
|  | 5333 | if (Error Err = ImportDefinition(D, D2)) | 
|  | 5334 | return std::move(Err); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5335 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 5336 | return D2; | 
|  | 5337 | } | 
|  | 5338 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5339 | ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5340 | // If this variable has a definition in the translation unit we're coming | 
|  | 5341 | // from, | 
|  | 5342 | // but this particular declaration is not that definition, import the | 
|  | 5343 | // definition and map to that. | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5344 | auto *Definition = | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5345 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); | 
|  | 5346 | if (Definition && Definition != D->getTemplatedDecl()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5347 | if (ExpectedDecl ImportedDefOrErr = import( | 
|  | 5348 | Definition->getDescribedVarTemplate())) | 
|  | 5349 | return Importer.MapImported(D, *ImportedDefOrErr); | 
|  | 5350 | else | 
|  | 5351 | return ImportedDefOrErr.takeError(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5352 | } | 
|  | 5353 |  | 
|  | 5354 | // Import the major distinguishing characteristics of this variable template. | 
|  | 5355 | DeclContext *DC, *LexicalDC; | 
|  | 5356 | DeclarationName Name; | 
|  | 5357 | SourceLocation Loc; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5358 | NamedDecl *ToD; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5359 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 5360 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5361 | if (ToD) | 
|  | 5362 | return ToD; | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5363 |  | 
|  | 5364 | // We may already have a template of the same name; try to find and match it. | 
|  | 5365 | assert(!DC->isFunctionOrMethod() && | 
|  | 5366 | "Variable templates cannot be declared at function scope"); | 
|  | 5367 | SmallVector<NamedDecl *, 4> ConflictingDecls; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5368 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5369 | for (auto *FoundDecl : FoundDecls) { | 
|  | 5370 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5371 | continue; | 
|  | 5372 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5373 | Decl *Found = FoundDecl; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5374 | if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5375 | if (IsStructuralMatch(D, FoundTemplate)) { | 
|  | 5376 | // The variable templates structurally match; call it the same template. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5377 | Importer.MapImported(D->getTemplatedDecl(), | 
|  | 5378 | FoundTemplate->getTemplatedDecl()); | 
|  | 5379 | return Importer.MapImported(D, FoundTemplate); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5380 | } | 
|  | 5381 | } | 
|  | 5382 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5383 | ConflictingDecls.push_back(FoundDecl); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5384 | } | 
|  | 5385 |  | 
|  | 5386 | if (!ConflictingDecls.empty()) { | 
|  | 5387 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, | 
|  | 5388 | ConflictingDecls.data(), | 
|  | 5389 | ConflictingDecls.size()); | 
|  | 5390 | } | 
|  | 5391 |  | 
|  | 5392 | if (!Name) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5393 | // FIXME: Is it possible to get other error than name conflict? | 
|  | 5394 | // (Put this `if` into the previous `if`?) | 
|  | 5395 | return make_error<ImportError>(ImportError::NameConflict); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5396 |  | 
|  | 5397 | VarDecl *DTemplated = D->getTemplatedDecl(); | 
|  | 5398 |  | 
|  | 5399 | // Import the type. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5400 | // FIXME: Value not used? | 
|  | 5401 | ExpectedType TypeOrErr = import(DTemplated->getType()); | 
|  | 5402 | if (!TypeOrErr) | 
|  | 5403 | return TypeOrErr.takeError(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5404 |  | 
|  | 5405 | // Create the declaration that is being templated. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5406 | VarDecl *ToTemplated; | 
|  | 5407 | if (Error Err = importInto(ToTemplated, DTemplated)) | 
|  | 5408 | return std::move(Err); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5409 |  | 
|  | 5410 | // Create the variable template declaration itself. | 
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5411 | auto TemplateParamsOrErr = import(D->getTemplateParameters()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5412 | if (!TemplateParamsOrErr) | 
|  | 5413 | return TemplateParamsOrErr.takeError(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5414 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5415 | VarTemplateDecl *ToVarTD; | 
|  | 5416 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5417 | Name, *TemplateParamsOrErr, ToTemplated)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5418 | return ToVarTD; | 
|  | 5419 |  | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5420 | ToTemplated->setDescribedVarTemplate(ToVarTD); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5421 |  | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5422 | ToVarTD->setAccess(D->getAccess()); | 
|  | 5423 | ToVarTD->setLexicalDeclContext(LexicalDC); | 
|  | 5424 | LexicalDC->addDeclInternal(ToVarTD); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5425 |  | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5426 | if (DTemplated->isThisDeclarationADefinition() && | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5427 | !ToTemplated->isThisDeclarationADefinition()) { | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5428 | // FIXME: Import definition! | 
|  | 5429 | } | 
|  | 5430 |  | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5431 | return ToVarTD; | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5432 | } | 
|  | 5433 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5434 | ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl( | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5435 | VarTemplateSpecializationDecl *D) { | 
|  | 5436 | // If this record has a definition in the translation unit we're coming from, | 
|  | 5437 | // but this particular declaration is not that definition, import the | 
|  | 5438 | // definition and map to that. | 
|  | 5439 | VarDecl *Definition = D->getDefinition(); | 
|  | 5440 | if (Definition && Definition != D) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5441 | if (ExpectedDecl ImportedDefOrErr = import(Definition)) | 
|  | 5442 | return Importer.MapImported(D, *ImportedDefOrErr); | 
|  | 5443 | else | 
|  | 5444 | return ImportedDefOrErr.takeError(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5445 | } | 
|  | 5446 |  | 
| Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 5447 | VarTemplateDecl *VarTemplate = nullptr; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5448 | if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate())) | 
|  | 5449 | return std::move(Err); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5450 |  | 
|  | 5451 | // Import the context of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5452 | DeclContext *DC, *LexicalDC; | 
|  | 5453 | if (Error Err = ImportDeclContext(D, DC, LexicalDC)) | 
|  | 5454 | return std::move(Err); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5455 |  | 
|  | 5456 | // Import the location of this declaration. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5457 | ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc()); | 
|  | 5458 | if (!BeginLocOrErr) | 
|  | 5459 | return BeginLocOrErr.takeError(); | 
|  | 5460 |  | 
|  | 5461 | auto IdLocOrErr = import(D->getLocation()); | 
|  | 5462 | if (!IdLocOrErr) | 
|  | 5463 | return IdLocOrErr.takeError(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5464 |  | 
|  | 5465 | // Import template arguments. | 
|  | 5466 | SmallVector<TemplateArgument, 2> TemplateArgs; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5467 | if (Error Err = ImportTemplateArguments( | 
|  | 5468 | D->getTemplateArgs().data(), D->getTemplateArgs().size(), TemplateArgs)) | 
|  | 5469 | return std::move(Err); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5470 |  | 
|  | 5471 | // Try to find an existing specialization with these template arguments. | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5472 | void *InsertPos = nullptr; | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5473 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( | 
| Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 5474 | TemplateArgs, InsertPos); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5475 | if (D2) { | 
|  | 5476 | // We already have a variable template specialization with these template | 
|  | 5477 | // arguments. | 
|  | 5478 |  | 
|  | 5479 | // FIXME: Check for specialization vs. instantiation errors. | 
|  | 5480 |  | 
|  | 5481 | if (VarDecl *FoundDef = D2->getDefinition()) { | 
|  | 5482 | if (!D->isThisDeclarationADefinition() || | 
|  | 5483 | IsStructuralMatch(D, FoundDef)) { | 
|  | 5484 | // The record types structurally match, or the "from" translation | 
|  | 5485 | // unit only had a forward declaration anyway; call it the same | 
|  | 5486 | // variable. | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5487 | return Importer.MapImported(D, FoundDef); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5488 | } | 
|  | 5489 | } | 
|  | 5490 | } else { | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5491 | // Import the type. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5492 | QualType T; | 
|  | 5493 | if (Error Err = importInto(T, D->getType())) | 
|  | 5494 | return std::move(Err); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5495 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5496 | auto TInfoOrErr = import(D->getTypeSourceInfo()); | 
|  | 5497 | if (!TInfoOrErr) | 
|  | 5498 | return TInfoOrErr.takeError(); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5499 |  | 
|  | 5500 | TemplateArgumentListInfo ToTAInfo; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5501 | if (Error Err = ImportTemplateArgumentListInfo( | 
|  | 5502 | D->getTemplateArgsInfo(), ToTAInfo)) | 
|  | 5503 | return std::move(Err); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5504 |  | 
|  | 5505 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5506 | // Create a new specialization. | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5507 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { | 
|  | 5508 | // Import TemplateArgumentListInfo | 
|  | 5509 | TemplateArgumentListInfo ArgInfos; | 
|  | 5510 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); | 
|  | 5511 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5512 | if (Error Err = ImportTemplateArgumentListInfo( | 
|  | 5513 | *FromTAArgsAsWritten, ArgInfos)) | 
|  | 5514 | return std::move(Err); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5515 |  | 
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5516 | auto ToTPListOrErr = import(FromPartial->getTemplateParameters()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5517 | if (!ToTPListOrErr) | 
|  | 5518 | return ToTPListOrErr.takeError(); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5519 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5520 | PartVarSpecDecl *ToPartial; | 
|  | 5521 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5522 | *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr, | 
|  | 5523 | VarTemplate, T, *TInfoOrErr, | 
|  | 5524 | D->getStorageClass(), TemplateArgs, ArgInfos)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5525 | return ToPartial; | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5526 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5527 | if (Expected<PartVarSpecDecl *> ToInstOrErr = import( | 
|  | 5528 | FromPartial->getInstantiatedFromMember())) | 
|  | 5529 | ToPartial->setInstantiatedFromMember(*ToInstOrErr); | 
|  | 5530 | else | 
|  | 5531 | return ToInstOrErr.takeError(); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5532 |  | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5533 | if (FromPartial->isMemberSpecialization()) | 
|  | 5534 | ToPartial->setMemberSpecialization(); | 
|  | 5535 |  | 
|  | 5536 | D2 = ToPartial; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5537 |  | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5538 | } else { // Full specialization | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5539 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, | 
|  | 5540 | *BeginLocOrErr, *IdLocOrErr, VarTemplate, | 
|  | 5541 | T, *TInfoOrErr, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5542 | D->getStorageClass(), TemplateArgs)) | 
|  | 5543 | return D2; | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5544 | } | 
|  | 5545 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5546 | if (D->getPointOfInstantiation().isValid()) { | 
|  | 5547 | if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation())) | 
|  | 5548 | D2->setPointOfInstantiation(*POIOrErr); | 
|  | 5549 | else | 
|  | 5550 | return POIOrErr.takeError(); | 
|  | 5551 | } | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5552 |  | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5553 | D2->setSpecializationKind(D->getSpecializationKind()); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5554 | D2->setTemplateArgsInfo(ToTAInfo); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5555 |  | 
|  | 5556 | // Add this specialization to the class template. | 
|  | 5557 | VarTemplate->AddSpecialization(D2, InsertPos); | 
|  | 5558 |  | 
|  | 5559 | // Import the qualifier, if any. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5560 | if (auto LocOrErr = import(D->getQualifierLoc())) | 
|  | 5561 | D2->setQualifierInfo(*LocOrErr); | 
|  | 5562 | else | 
|  | 5563 | return LocOrErr.takeError(); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5564 |  | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5565 | if (D->isConstexpr()) | 
|  | 5566 | D2->setConstexpr(true); | 
|  | 5567 |  | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5568 | // Add the specialization to this context. | 
|  | 5569 | D2->setLexicalDeclContext(LexicalDC); | 
|  | 5570 | LexicalDC->addDeclInternal(D2); | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5571 |  | 
|  | 5572 | D2->setAccess(D->getAccess()); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5573 | } | 
| Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 5574 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5575 | if (Error Err = ImportInitializer(D, D2)) | 
|  | 5576 | return std::move(Err); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 5577 |  | 
|  | 5578 | return D2; | 
|  | 5579 | } | 
|  | 5580 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5581 | ExpectedDecl | 
|  | 5582 | ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5583 | DeclContext *DC, *LexicalDC; | 
|  | 5584 | DeclarationName Name; | 
|  | 5585 | SourceLocation Loc; | 
|  | 5586 | NamedDecl *ToD; | 
|  | 5587 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5588 | if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) | 
|  | 5589 | return std::move(Err); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5590 |  | 
|  | 5591 | if (ToD) | 
|  | 5592 | return ToD; | 
|  | 5593 |  | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5594 | const FunctionTemplateDecl *FoundByLookup = nullptr; | 
|  | 5595 |  | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5596 | // Try to find a function in our own ("to") context with the same name, same | 
|  | 5597 | // type, and in the same context as the function we're importing. | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5598 | // FIXME Split this into a separate function. | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5599 | if (!LexicalDC->isFunctionOrMethod()) { | 
| Gabor Marton | e331e63 | 2019-02-18 13:09:27 +0000 | [diff] [blame] | 5600 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 5601 | auto FoundDecls = Importer.findDeclsInToCtx(DC, Name); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5602 | for (auto *FoundDecl : FoundDecls) { | 
|  | 5603 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5604 | continue; | 
|  | 5605 |  | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5606 | if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { | 
|  | 5607 | if (FoundTemplate->hasExternalFormalLinkage() && | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5608 | D->hasExternalFormalLinkage()) { | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5609 | if (IsStructuralMatch(D, FoundTemplate)) { | 
|  | 5610 | FunctionTemplateDecl *TemplateWithDef = | 
|  | 5611 | getTemplateDefinition(FoundTemplate); | 
|  | 5612 | if (D->isThisDeclarationADefinition() && TemplateWithDef) { | 
|  | 5613 | return Importer.MapImported(D, TemplateWithDef); | 
|  | 5614 | } | 
|  | 5615 | FoundByLookup = FoundTemplate; | 
|  | 5616 | break; | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5617 | } | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5618 | // TODO: handle conflicting names | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5619 | } | 
|  | 5620 | } | 
|  | 5621 | } | 
|  | 5622 | } | 
|  | 5623 |  | 
| Balazs Keri | dec0916 | 2019-03-20 15:42:42 +0000 | [diff] [blame] | 5624 | auto ParamsOrErr = import(D->getTemplateParameters()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5625 | if (!ParamsOrErr) | 
|  | 5626 | return ParamsOrErr.takeError(); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5627 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5628 | FunctionDecl *TemplatedFD; | 
|  | 5629 | if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl())) | 
|  | 5630 | return std::move(Err); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5631 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5632 | FunctionTemplateDecl *ToFunc; | 
|  | 5633 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5634 | *ParamsOrErr, TemplatedFD)) | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 5635 | return ToFunc; | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5636 |  | 
|  | 5637 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5638 |  | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5639 | ToFunc->setAccess(D->getAccess()); | 
|  | 5640 | ToFunc->setLexicalDeclContext(LexicalDC); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5641 | LexicalDC->addDeclInternal(ToFunc); | 
| Gabor Marton | 16d98c2 | 2019-03-07 13:01:51 +0000 | [diff] [blame] | 5642 |  | 
|  | 5643 | if (FoundByLookup) { | 
|  | 5644 | auto *Recent = | 
|  | 5645 | const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl()); | 
|  | 5646 | if (!TemplatedFD->getPreviousDecl()) { | 
|  | 5647 | assert(FoundByLookup->getTemplatedDecl() && | 
|  | 5648 | "Found decl must have its templated decl set"); | 
|  | 5649 | auto *PrevTemplated = | 
|  | 5650 | FoundByLookup->getTemplatedDecl()->getMostRecentDecl(); | 
|  | 5651 | if (TemplatedFD != PrevTemplated) | 
|  | 5652 | TemplatedFD->setPreviousDecl(PrevTemplated); | 
|  | 5653 | } | 
|  | 5654 | ToFunc->setPreviousDecl(Recent); | 
|  | 5655 | } | 
|  | 5656 |  | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 5657 | return ToFunc; | 
|  | 5658 | } | 
|  | 5659 |  | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5660 | //---------------------------------------------------------------------------- | 
|  | 5661 | // Import Statements | 
|  | 5662 | //---------------------------------------------------------------------------- | 
|  | 5663 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5664 | ExpectedStmt ASTNodeImporter::VisitStmt(Stmt *S) { | 
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5665 | Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node) | 
|  | 5666 | << S->getStmtClassName(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5667 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5668 | } | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5669 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5670 |  | 
|  | 5671 | ExpectedStmt ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 5672 | if (Importer.returnWithErrorInTest()) | 
|  | 5673 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5674 | SmallVector<IdentifierInfo *, 4> Names; | 
|  | 5675 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { | 
|  | 5676 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); | 
| Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5677 | // ToII is nullptr when no symbolic name is given for output operand | 
|  | 5678 | // see ParseStmtAsm::ParseAsmOperandsOpt | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5679 | Names.push_back(ToII); | 
|  | 5680 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5681 |  | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5682 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { | 
|  | 5683 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); | 
| Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 5684 | // ToII is nullptr when no symbolic name is given for input operand | 
|  | 5685 | // see ParseStmtAsm::ParseAsmOperandsOpt | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5686 | Names.push_back(ToII); | 
|  | 5687 | } | 
|  | 5688 |  | 
|  | 5689 | SmallVector<StringLiteral *, 4> Clobbers; | 
|  | 5690 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5691 | if (auto ClobberOrErr = import(S->getClobberStringLiteral(I))) | 
|  | 5692 | Clobbers.push_back(*ClobberOrErr); | 
|  | 5693 | else | 
|  | 5694 | return ClobberOrErr.takeError(); | 
|  | 5695 |  | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5696 | } | 
|  | 5697 |  | 
|  | 5698 | SmallVector<StringLiteral *, 4> Constraints; | 
|  | 5699 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5700 | if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I))) | 
|  | 5701 | Constraints.push_back(*OutputOrErr); | 
|  | 5702 | else | 
|  | 5703 | return OutputOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5704 | } | 
|  | 5705 |  | 
|  | 5706 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5707 | if (auto InputOrErr = import(S->getInputConstraintLiteral(I))) | 
|  | 5708 | Constraints.push_back(*InputOrErr); | 
|  | 5709 | else | 
|  | 5710 | return InputOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5711 | } | 
|  | 5712 |  | 
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5713 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() + | 
|  | 5714 | S->getNumLabels()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5715 | if (Error Err = ImportContainerChecked(S->outputs(), Exprs)) | 
|  | 5716 | return std::move(Err); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5717 |  | 
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5718 | if (Error Err = | 
|  | 5719 | ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) | 
|  | 5720 | return std::move(Err); | 
|  | 5721 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5722 | if (Error Err = ImportArrayChecked( | 
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5723 | S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs())) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5724 | return std::move(Err); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5725 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5726 | ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc()); | 
|  | 5727 | if (!AsmLocOrErr) | 
|  | 5728 | return AsmLocOrErr.takeError(); | 
|  | 5729 | auto AsmStrOrErr = import(S->getAsmString()); | 
|  | 5730 | if (!AsmStrOrErr) | 
|  | 5731 | return AsmStrOrErr.takeError(); | 
|  | 5732 | ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc()); | 
|  | 5733 | if (!RParenLocOrErr) | 
|  | 5734 | return RParenLocOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5735 |  | 
|  | 5736 | return new (Importer.getToContext()) GCCAsmStmt( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5737 | Importer.getToContext(), | 
|  | 5738 | *AsmLocOrErr, | 
|  | 5739 | S->isSimple(), | 
|  | 5740 | S->isVolatile(), | 
|  | 5741 | S->getNumOutputs(), | 
|  | 5742 | S->getNumInputs(), | 
|  | 5743 | Names.data(), | 
|  | 5744 | Constraints.data(), | 
|  | 5745 | Exprs.data(), | 
|  | 5746 | *AsmStrOrErr, | 
|  | 5747 | S->getNumClobbers(), | 
|  | 5748 | Clobbers.data(), | 
| Jennifer Yu | b8fee67 | 2019-06-03 15:57:25 +0000 | [diff] [blame] | 5749 | S->getNumLabels(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5750 | *RParenLocOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5751 | } | 
|  | 5752 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5753 | ExpectedStmt ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { | 
|  | 5754 | auto Imp = importSeq(S->getDeclGroup(), S->getBeginLoc(), S->getEndLoc()); | 
|  | 5755 | if (!Imp) | 
|  | 5756 | return Imp.takeError(); | 
|  | 5757 |  | 
|  | 5758 | DeclGroupRef ToDG; | 
|  | 5759 | SourceLocation ToBeginLoc, ToEndLoc; | 
|  | 5760 | std::tie(ToDG, ToBeginLoc, ToEndLoc) = *Imp; | 
|  | 5761 |  | 
|  | 5762 | return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5763 | } | 
|  | 5764 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5765 | ExpectedStmt ASTNodeImporter::VisitNullStmt(NullStmt *S) { | 
|  | 5766 | ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc()); | 
|  | 5767 | if (!ToSemiLocOrErr) | 
|  | 5768 | return ToSemiLocOrErr.takeError(); | 
|  | 5769 | return new (Importer.getToContext()) NullStmt( | 
|  | 5770 | *ToSemiLocOrErr, S->hasLeadingEmptyMacro()); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5771 | } | 
|  | 5772 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5773 | ExpectedStmt ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5774 | SmallVector<Stmt *, 8> ToStmts(S->size()); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5775 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5776 | if (Error Err = ImportContainerChecked(S->body(), ToStmts)) | 
|  | 5777 | return std::move(Err); | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5778 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5779 | ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc()); | 
|  | 5780 | if (!ToLBracLocOrErr) | 
|  | 5781 | return ToLBracLocOrErr.takeError(); | 
|  | 5782 |  | 
|  | 5783 | ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc()); | 
|  | 5784 | if (!ToRBracLocOrErr) | 
|  | 5785 | return ToRBracLocOrErr.takeError(); | 
|  | 5786 |  | 
|  | 5787 | return CompoundStmt::Create( | 
|  | 5788 | Importer.getToContext(), ToStmts, | 
|  | 5789 | *ToLBracLocOrErr, *ToRBracLocOrErr); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5790 | } | 
|  | 5791 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5792 | ExpectedStmt ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { | 
|  | 5793 | auto Imp = importSeq( | 
|  | 5794 | S->getLHS(), S->getRHS(), S->getSubStmt(), S->getCaseLoc(), | 
|  | 5795 | S->getEllipsisLoc(), S->getColonLoc()); | 
|  | 5796 | if (!Imp) | 
|  | 5797 | return Imp.takeError(); | 
|  | 5798 |  | 
|  | 5799 | Expr *ToLHS, *ToRHS; | 
|  | 5800 | Stmt *ToSubStmt; | 
|  | 5801 | SourceLocation ToCaseLoc, ToEllipsisLoc, ToColonLoc; | 
|  | 5802 | std::tie(ToLHS, ToRHS, ToSubStmt, ToCaseLoc, ToEllipsisLoc, ToColonLoc) = | 
|  | 5803 | *Imp; | 
|  | 5804 |  | 
| Bruno Ricci | 5b3057175 | 2018-10-28 12:30:53 +0000 | [diff] [blame] | 5805 | auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS, | 
|  | 5806 | ToCaseLoc, ToEllipsisLoc, ToColonLoc); | 
| Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5807 | ToStmt->setSubStmt(ToSubStmt); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5808 |  | 
| Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5809 | return ToStmt; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5810 | } | 
|  | 5811 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5812 | ExpectedStmt ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { | 
|  | 5813 | auto Imp = importSeq(S->getDefaultLoc(), S->getColonLoc(), S->getSubStmt()); | 
|  | 5814 | if (!Imp) | 
|  | 5815 | return Imp.takeError(); | 
|  | 5816 |  | 
|  | 5817 | SourceLocation ToDefaultLoc, ToColonLoc; | 
|  | 5818 | Stmt *ToSubStmt; | 
|  | 5819 | std::tie(ToDefaultLoc, ToColonLoc, ToSubStmt) = *Imp; | 
|  | 5820 |  | 
|  | 5821 | return new (Importer.getToContext()) DefaultStmt( | 
|  | 5822 | ToDefaultLoc, ToColonLoc, ToSubStmt); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5823 | } | 
|  | 5824 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5825 | ExpectedStmt ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { | 
|  | 5826 | auto Imp = importSeq(S->getIdentLoc(), S->getDecl(), S->getSubStmt()); | 
|  | 5827 | if (!Imp) | 
|  | 5828 | return Imp.takeError(); | 
|  | 5829 |  | 
|  | 5830 | SourceLocation ToIdentLoc; | 
|  | 5831 | LabelDecl *ToLabelDecl; | 
|  | 5832 | Stmt *ToSubStmt; | 
|  | 5833 | std::tie(ToIdentLoc, ToLabelDecl, ToSubStmt) = *Imp; | 
|  | 5834 |  | 
|  | 5835 | return new (Importer.getToContext()) LabelStmt( | 
|  | 5836 | ToIdentLoc, ToLabelDecl, ToSubStmt); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5837 | } | 
|  | 5838 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5839 | ExpectedStmt ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { | 
|  | 5840 | ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc()); | 
|  | 5841 | if (!ToAttrLocOrErr) | 
|  | 5842 | return ToAttrLocOrErr.takeError(); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5843 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); | 
|  | 5844 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5845 | if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs)) | 
|  | 5846 | return std::move(Err); | 
|  | 5847 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); | 
|  | 5848 | if (!ToSubStmtOrErr) | 
|  | 5849 | return ToSubStmtOrErr.takeError(); | 
|  | 5850 |  | 
|  | 5851 | return AttributedStmt::Create( | 
|  | 5852 | Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5853 | } | 
|  | 5854 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5855 | ExpectedStmt ASTNodeImporter::VisitIfStmt(IfStmt *S) { | 
|  | 5856 | auto Imp = importSeq( | 
|  | 5857 | S->getIfLoc(), S->getInit(), S->getConditionVariable(), S->getCond(), | 
|  | 5858 | S->getThen(), S->getElseLoc(), S->getElse()); | 
|  | 5859 | if (!Imp) | 
|  | 5860 | return Imp.takeError(); | 
|  | 5861 |  | 
|  | 5862 | SourceLocation ToIfLoc, ToElseLoc; | 
|  | 5863 | Stmt *ToInit, *ToThen, *ToElse; | 
|  | 5864 | VarDecl *ToConditionVariable; | 
|  | 5865 | Expr *ToCond; | 
|  | 5866 | std::tie( | 
|  | 5867 | ToIfLoc, ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, ToElse) = | 
|  | 5868 | *Imp; | 
|  | 5869 |  | 
| Bruno Ricci | b1cc94b | 2018-10-27 21:12:20 +0000 | [diff] [blame] | 5870 | return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->isConstexpr(), | 
|  | 5871 | ToInit, ToConditionVariable, ToCond, ToThen, ToElseLoc, | 
|  | 5872 | ToElse); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5873 | } | 
|  | 5874 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5875 | ExpectedStmt ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { | 
|  | 5876 | auto Imp = importSeq( | 
|  | 5877 | S->getInit(), S->getConditionVariable(), S->getCond(), | 
|  | 5878 | S->getBody(), S->getSwitchLoc()); | 
|  | 5879 | if (!Imp) | 
|  | 5880 | return Imp.takeError(); | 
|  | 5881 |  | 
|  | 5882 | Stmt *ToInit, *ToBody; | 
|  | 5883 | VarDecl *ToConditionVariable; | 
|  | 5884 | Expr *ToCond; | 
|  | 5885 | SourceLocation ToSwitchLoc; | 
|  | 5886 | std::tie(ToInit, ToConditionVariable, ToCond, ToBody, ToSwitchLoc) = *Imp; | 
|  | 5887 |  | 
| Bruno Ricci | e2806f8 | 2018-10-29 16:12:37 +0000 | [diff] [blame] | 5888 | auto *ToStmt = SwitchStmt::Create(Importer.getToContext(), ToInit, | 
|  | 5889 | ToConditionVariable, ToCond); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5890 | ToStmt->setBody(ToBody); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5891 | ToStmt->setSwitchLoc(ToSwitchLoc); | 
|  | 5892 |  | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5893 | // Now we have to re-chain the cases. | 
|  | 5894 | SwitchCase *LastChainedSwitchCase = nullptr; | 
|  | 5895 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; | 
|  | 5896 | SC = SC->getNextSwitchCase()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5897 | Expected<SwitchCase *> ToSCOrErr = import(SC); | 
|  | 5898 | if (!ToSCOrErr) | 
|  | 5899 | return ToSCOrErr.takeError(); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5900 | if (LastChainedSwitchCase) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5901 | LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5902 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5903 | ToStmt->setSwitchCaseList(*ToSCOrErr); | 
|  | 5904 | LastChainedSwitchCase = *ToSCOrErr; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5905 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5906 |  | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5907 | return ToStmt; | 
|  | 5908 | } | 
|  | 5909 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5910 | ExpectedStmt ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { | 
|  | 5911 | auto Imp = importSeq( | 
|  | 5912 | S->getConditionVariable(), S->getCond(), S->getBody(), S->getWhileLoc()); | 
|  | 5913 | if (!Imp) | 
|  | 5914 | return Imp.takeError(); | 
|  | 5915 |  | 
|  | 5916 | VarDecl *ToConditionVariable; | 
|  | 5917 | Expr *ToCond; | 
|  | 5918 | Stmt *ToBody; | 
|  | 5919 | SourceLocation ToWhileLoc; | 
|  | 5920 | std::tie(ToConditionVariable, ToCond, ToBody, ToWhileLoc) = *Imp; | 
|  | 5921 |  | 
| Bruno Ricci | bacf751 | 2018-10-30 13:42:41 +0000 | [diff] [blame] | 5922 | return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond, | 
|  | 5923 | ToBody, ToWhileLoc); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5924 | } | 
|  | 5925 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5926 | ExpectedStmt ASTNodeImporter::VisitDoStmt(DoStmt *S) { | 
|  | 5927 | auto Imp = importSeq( | 
|  | 5928 | S->getBody(), S->getCond(), S->getDoLoc(), S->getWhileLoc(), | 
|  | 5929 | S->getRParenLoc()); | 
|  | 5930 | if (!Imp) | 
|  | 5931 | return Imp.takeError(); | 
|  | 5932 |  | 
|  | 5933 | Stmt *ToBody; | 
|  | 5934 | Expr *ToCond; | 
|  | 5935 | SourceLocation ToDoLoc, ToWhileLoc, ToRParenLoc; | 
|  | 5936 | std::tie(ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc) = *Imp; | 
|  | 5937 |  | 
|  | 5938 | return new (Importer.getToContext()) DoStmt( | 
|  | 5939 | ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5940 | } | 
|  | 5941 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5942 | ExpectedStmt ASTNodeImporter::VisitForStmt(ForStmt *S) { | 
|  | 5943 | auto Imp = importSeq( | 
|  | 5944 | S->getInit(), S->getCond(), S->getConditionVariable(), S->getInc(), | 
|  | 5945 | S->getBody(), S->getForLoc(), S->getLParenLoc(), S->getRParenLoc()); | 
|  | 5946 | if (!Imp) | 
|  | 5947 | return Imp.takeError(); | 
|  | 5948 |  | 
|  | 5949 | Stmt *ToInit; | 
|  | 5950 | Expr *ToCond, *ToInc; | 
|  | 5951 | VarDecl *ToConditionVariable; | 
|  | 5952 | Stmt *ToBody; | 
|  | 5953 | SourceLocation ToForLoc, ToLParenLoc, ToRParenLoc; | 
|  | 5954 | std::tie( | 
|  | 5955 | ToInit, ToCond, ToConditionVariable,  ToInc, ToBody, ToForLoc, | 
|  | 5956 | ToLParenLoc, ToRParenLoc) = *Imp; | 
|  | 5957 |  | 
|  | 5958 | return new (Importer.getToContext()) ForStmt( | 
|  | 5959 | Importer.getToContext(), | 
|  | 5960 | ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc, | 
|  | 5961 | ToRParenLoc); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5962 | } | 
|  | 5963 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5964 | ExpectedStmt ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { | 
|  | 5965 | auto Imp = importSeq(S->getLabel(), S->getGotoLoc(), S->getLabelLoc()); | 
|  | 5966 | if (!Imp) | 
|  | 5967 | return Imp.takeError(); | 
|  | 5968 |  | 
|  | 5969 | LabelDecl *ToLabel; | 
|  | 5970 | SourceLocation ToGotoLoc, ToLabelLoc; | 
|  | 5971 | std::tie(ToLabel, ToGotoLoc, ToLabelLoc) = *Imp; | 
|  | 5972 |  | 
|  | 5973 | return new (Importer.getToContext()) GotoStmt( | 
|  | 5974 | ToLabel, ToGotoLoc, ToLabelLoc); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5975 | } | 
|  | 5976 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5977 | ExpectedStmt ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { | 
|  | 5978 | auto Imp = importSeq(S->getGotoLoc(), S->getStarLoc(), S->getTarget()); | 
|  | 5979 | if (!Imp) | 
|  | 5980 | return Imp.takeError(); | 
|  | 5981 |  | 
|  | 5982 | SourceLocation ToGotoLoc, ToStarLoc; | 
|  | 5983 | Expr *ToTarget; | 
|  | 5984 | std::tie(ToGotoLoc, ToStarLoc, ToTarget) = *Imp; | 
|  | 5985 |  | 
|  | 5986 | return new (Importer.getToContext()) IndirectGotoStmt( | 
|  | 5987 | ToGotoLoc, ToStarLoc, ToTarget); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5988 | } | 
|  | 5989 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5990 | ExpectedStmt ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { | 
|  | 5991 | ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc()); | 
|  | 5992 | if (!ToContinueLocOrErr) | 
|  | 5993 | return ToContinueLocOrErr.takeError(); | 
|  | 5994 | return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5995 | } | 
|  | 5996 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 5997 | ExpectedStmt ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { | 
|  | 5998 | auto ToBreakLocOrErr = import(S->getBreakLoc()); | 
|  | 5999 | if (!ToBreakLocOrErr) | 
|  | 6000 | return ToBreakLocOrErr.takeError(); | 
|  | 6001 | return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6002 | } | 
|  | 6003 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6004 | ExpectedStmt ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { | 
|  | 6005 | auto Imp = importSeq( | 
|  | 6006 | S->getReturnLoc(), S->getRetValue(), S->getNRVOCandidate()); | 
|  | 6007 | if (!Imp) | 
|  | 6008 | return Imp.takeError(); | 
|  | 6009 |  | 
|  | 6010 | SourceLocation ToReturnLoc; | 
|  | 6011 | Expr *ToRetValue; | 
|  | 6012 | const VarDecl *ToNRVOCandidate; | 
|  | 6013 | std::tie(ToReturnLoc, ToRetValue, ToNRVOCandidate) = *Imp; | 
|  | 6014 |  | 
| Bruno Ricci | 023b1d1 | 2018-10-30 14:40:49 +0000 | [diff] [blame] | 6015 | return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue, | 
|  | 6016 | ToNRVOCandidate); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6017 | } | 
|  | 6018 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6019 | ExpectedStmt ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { | 
|  | 6020 | auto Imp = importSeq( | 
|  | 6021 | S->getCatchLoc(), S->getExceptionDecl(), S->getHandlerBlock()); | 
|  | 6022 | if (!Imp) | 
|  | 6023 | return Imp.takeError(); | 
|  | 6024 |  | 
|  | 6025 | SourceLocation ToCatchLoc; | 
|  | 6026 | VarDecl *ToExceptionDecl; | 
|  | 6027 | Stmt *ToHandlerBlock; | 
|  | 6028 | std::tie(ToCatchLoc, ToExceptionDecl, ToHandlerBlock) = *Imp; | 
|  | 6029 |  | 
|  | 6030 | return new (Importer.getToContext()) CXXCatchStmt ( | 
|  | 6031 | ToCatchLoc, ToExceptionDecl, ToHandlerBlock); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6032 | } | 
|  | 6033 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6034 | ExpectedStmt ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { | 
|  | 6035 | ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc()); | 
|  | 6036 | if (!ToTryLocOrErr) | 
|  | 6037 | return ToTryLocOrErr.takeError(); | 
|  | 6038 |  | 
|  | 6039 | ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock()); | 
|  | 6040 | if (!ToTryBlockOrErr) | 
|  | 6041 | return ToTryBlockOrErr.takeError(); | 
|  | 6042 |  | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6043 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); | 
|  | 6044 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { | 
|  | 6045 | CXXCatchStmt *FromHandler = S->getHandler(HI); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6046 | if (auto ToHandlerOrErr = import(FromHandler)) | 
|  | 6047 | ToHandlers[HI] = *ToHandlerOrErr; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6048 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6049 | return ToHandlerOrErr.takeError(); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6050 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6051 |  | 
|  | 6052 | return CXXTryStmt::Create( | 
|  | 6053 | Importer.getToContext(), *ToTryLocOrErr,*ToTryBlockOrErr, ToHandlers); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6054 | } | 
|  | 6055 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6056 | ExpectedStmt ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { | 
|  | 6057 | auto Imp1 = importSeq( | 
|  | 6058 | S->getInit(), S->getRangeStmt(), S->getBeginStmt(), S->getEndStmt(), | 
|  | 6059 | S->getCond(), S->getInc(), S->getLoopVarStmt(), S->getBody()); | 
|  | 6060 | if (!Imp1) | 
|  | 6061 | return Imp1.takeError(); | 
|  | 6062 | auto Imp2 = importSeq( | 
|  | 6063 | S->getForLoc(), S->getCoawaitLoc(), S->getColonLoc(), S->getRParenLoc()); | 
|  | 6064 | if (!Imp2) | 
|  | 6065 | return Imp2.takeError(); | 
|  | 6066 |  | 
|  | 6067 | DeclStmt *ToRangeStmt, *ToBeginStmt, *ToEndStmt, *ToLoopVarStmt; | 
|  | 6068 | Expr *ToCond, *ToInc; | 
|  | 6069 | Stmt *ToInit, *ToBody; | 
|  | 6070 | std::tie( | 
|  | 6071 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, | 
|  | 6072 | ToBody) = *Imp1; | 
|  | 6073 | SourceLocation ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc; | 
|  | 6074 | std::tie(ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc) = *Imp2; | 
|  | 6075 |  | 
|  | 6076 | return new (Importer.getToContext()) CXXForRangeStmt( | 
|  | 6077 | ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt, | 
|  | 6078 | ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6079 | } | 
|  | 6080 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6081 | ExpectedStmt | 
|  | 6082 | ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { | 
|  | 6083 | auto Imp = importSeq( | 
|  | 6084 | S->getElement(), S->getCollection(), S->getBody(), | 
|  | 6085 | S->getForLoc(), S->getRParenLoc()); | 
|  | 6086 | if (!Imp) | 
|  | 6087 | return Imp.takeError(); | 
|  | 6088 |  | 
|  | 6089 | Stmt *ToElement, *ToBody; | 
|  | 6090 | Expr *ToCollection; | 
|  | 6091 | SourceLocation ToForLoc, ToRParenLoc; | 
|  | 6092 | std::tie(ToElement, ToCollection, ToBody, ToForLoc, ToRParenLoc) = *Imp; | 
|  | 6093 |  | 
|  | 6094 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement, | 
|  | 6095 | ToCollection, | 
|  | 6096 | ToBody, | 
|  | 6097 | ToForLoc, | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6098 | ToRParenLoc); | 
|  | 6099 | } | 
|  | 6100 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6101 | ExpectedStmt ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { | 
|  | 6102 | auto Imp = importSeq( | 
|  | 6103 | S->getAtCatchLoc(), S->getRParenLoc(), S->getCatchParamDecl(), | 
|  | 6104 | S->getCatchBody()); | 
|  | 6105 | if (!Imp) | 
|  | 6106 | return Imp.takeError(); | 
|  | 6107 |  | 
|  | 6108 | SourceLocation ToAtCatchLoc, ToRParenLoc; | 
|  | 6109 | VarDecl *ToCatchParamDecl; | 
|  | 6110 | Stmt *ToCatchBody; | 
|  | 6111 | std::tie(ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody) = *Imp; | 
|  | 6112 |  | 
|  | 6113 | return new (Importer.getToContext()) ObjCAtCatchStmt ( | 
|  | 6114 | ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6115 | } | 
|  | 6116 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6117 | ExpectedStmt ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { | 
|  | 6118 | ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc()); | 
|  | 6119 | if (!ToAtFinallyLocOrErr) | 
|  | 6120 | return ToAtFinallyLocOrErr.takeError(); | 
|  | 6121 | ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody()); | 
|  | 6122 | if (!ToAtFinallyStmtOrErr) | 
|  | 6123 | return ToAtFinallyStmtOrErr.takeError(); | 
|  | 6124 | return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr, | 
|  | 6125 | *ToAtFinallyStmtOrErr); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6126 | } | 
|  | 6127 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6128 | ExpectedStmt ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { | 
|  | 6129 | auto Imp = importSeq( | 
|  | 6130 | S->getAtTryLoc(), S->getTryBody(), S->getFinallyStmt()); | 
|  | 6131 | if (!Imp) | 
|  | 6132 | return Imp.takeError(); | 
|  | 6133 |  | 
|  | 6134 | SourceLocation ToAtTryLoc; | 
|  | 6135 | Stmt *ToTryBody, *ToFinallyStmt; | 
|  | 6136 | std::tie(ToAtTryLoc, ToTryBody, ToFinallyStmt) = *Imp; | 
|  | 6137 |  | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6138 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); | 
|  | 6139 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { | 
|  | 6140 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6141 | if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt)) | 
|  | 6142 | ToCatchStmts[CI] = *ToCatchStmtOrErr; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6143 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6144 | return ToCatchStmtOrErr.takeError(); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6145 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6146 |  | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6147 | return ObjCAtTryStmt::Create(Importer.getToContext(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6148 | ToAtTryLoc, ToTryBody, | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6149 | ToCatchStmts.begin(), ToCatchStmts.size(), | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6150 | ToFinallyStmt); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6151 | } | 
|  | 6152 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6153 | ExpectedStmt ASTNodeImporter::VisitObjCAtSynchronizedStmt | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6154 | (ObjCAtSynchronizedStmt *S) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6155 | auto Imp = importSeq( | 
|  | 6156 | S->getAtSynchronizedLoc(), S->getSynchExpr(), S->getSynchBody()); | 
|  | 6157 | if (!Imp) | 
|  | 6158 | return Imp.takeError(); | 
|  | 6159 |  | 
|  | 6160 | SourceLocation ToAtSynchronizedLoc; | 
|  | 6161 | Expr *ToSynchExpr; | 
|  | 6162 | Stmt *ToSynchBody; | 
|  | 6163 | std::tie(ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody) = *Imp; | 
|  | 6164 |  | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6165 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( | 
|  | 6166 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); | 
|  | 6167 | } | 
|  | 6168 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6169 | ExpectedStmt ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { | 
|  | 6170 | ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc()); | 
|  | 6171 | if (!ToThrowLocOrErr) | 
|  | 6172 | return ToThrowLocOrErr.takeError(); | 
|  | 6173 | ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr()); | 
|  | 6174 | if (!ToThrowExprOrErr) | 
|  | 6175 | return ToThrowExprOrErr.takeError(); | 
|  | 6176 | return new (Importer.getToContext()) ObjCAtThrowStmt( | 
|  | 6177 | *ToThrowLocOrErr, *ToThrowExprOrErr); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6178 | } | 
|  | 6179 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6180 | ExpectedStmt ASTNodeImporter::VisitObjCAutoreleasePoolStmt( | 
|  | 6181 | ObjCAutoreleasePoolStmt *S) { | 
|  | 6182 | ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc()); | 
|  | 6183 | if (!ToAtLocOrErr) | 
|  | 6184 | return ToAtLocOrErr.takeError(); | 
|  | 6185 | ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt()); | 
|  | 6186 | if (!ToSubStmtOrErr) | 
|  | 6187 | return ToSubStmtOrErr.takeError(); | 
|  | 6188 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr, | 
|  | 6189 | *ToSubStmtOrErr); | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6190 | } | 
|  | 6191 |  | 
|  | 6192 | //---------------------------------------------------------------------------- | 
|  | 6193 | // Import Expressions | 
|  | 6194 | //---------------------------------------------------------------------------- | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6195 | ExpectedStmt ASTNodeImporter::VisitExpr(Expr *E) { | 
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6196 | Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node) | 
|  | 6197 | << E->getStmtClassName(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6198 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6199 | } | 
|  | 6200 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6201 | ExpectedStmt ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { | 
|  | 6202 | auto Imp = importSeq( | 
|  | 6203 | E->getBuiltinLoc(), E->getSubExpr(), E->getWrittenTypeInfo(), | 
|  | 6204 | E->getRParenLoc(), E->getType()); | 
|  | 6205 | if (!Imp) | 
|  | 6206 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6207 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6208 | SourceLocation ToBuiltinLoc, ToRParenLoc; | 
|  | 6209 | Expr *ToSubExpr; | 
|  | 6210 | TypeSourceInfo *ToWrittenTypeInfo; | 
|  | 6211 | QualType ToType; | 
|  | 6212 | std::tie(ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType) = | 
|  | 6213 | *Imp; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6214 |  | 
|  | 6215 | return new (Importer.getToContext()) VAArgExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6216 | ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType, | 
|  | 6217 | E->isMicrosoftABI()); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6218 | } | 
|  | 6219 |  | 
| Tom Roeder | 521f004 | 2019-02-26 19:26:41 +0000 | [diff] [blame] | 6220 | ExpectedStmt ASTNodeImporter::VisitChooseExpr(ChooseExpr *E) { | 
|  | 6221 | auto Imp = importSeq(E->getCond(), E->getLHS(), E->getRHS(), | 
|  | 6222 | E->getBuiltinLoc(), E->getRParenLoc(), E->getType()); | 
|  | 6223 | if (!Imp) | 
|  | 6224 | return Imp.takeError(); | 
|  | 6225 |  | 
|  | 6226 | Expr *ToCond; | 
|  | 6227 | Expr *ToLHS; | 
|  | 6228 | Expr *ToRHS; | 
|  | 6229 | SourceLocation ToBuiltinLoc, ToRParenLoc; | 
|  | 6230 | QualType ToType; | 
|  | 6231 | std::tie(ToCond, ToLHS, ToRHS, ToBuiltinLoc, ToRParenLoc, ToType) = *Imp; | 
|  | 6232 |  | 
|  | 6233 | ExprValueKind VK = E->getValueKind(); | 
|  | 6234 | ExprObjectKind OK = E->getObjectKind(); | 
|  | 6235 |  | 
|  | 6236 | bool TypeDependent = ToCond->isTypeDependent(); | 
|  | 6237 | bool ValueDependent = ToCond->isValueDependent(); | 
|  | 6238 |  | 
|  | 6239 | // The value of CondIsTrue only matters if the value is not | 
|  | 6240 | // condition-dependent. | 
|  | 6241 | bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue(); | 
|  | 6242 |  | 
|  | 6243 | return new (Importer.getToContext()) | 
|  | 6244 | ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK, | 
|  | 6245 | ToRParenLoc, CondIsTrue, TypeDependent, ValueDependent); | 
|  | 6246 | } | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6247 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6248 | ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { | 
|  | 6249 | ExpectedType TypeOrErr = import(E->getType()); | 
|  | 6250 | if (!TypeOrErr) | 
|  | 6251 | return TypeOrErr.takeError(); | 
|  | 6252 |  | 
|  | 6253 | ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc()); | 
|  | 6254 | if (!BeginLocOrErr) | 
|  | 6255 | return BeginLocOrErr.takeError(); | 
|  | 6256 |  | 
|  | 6257 | return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6258 | } | 
|  | 6259 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6260 | ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { | 
|  | 6261 | auto Imp = importSeq( | 
|  | 6262 | E->getBeginLoc(), E->getType(), E->getFunctionName()); | 
|  | 6263 | if (!Imp) | 
|  | 6264 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6265 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6266 | SourceLocation ToBeginLoc; | 
|  | 6267 | QualType ToType; | 
|  | 6268 | StringLiteral *ToFunctionName; | 
|  | 6269 | std::tie(ToBeginLoc, ToType, ToFunctionName) = *Imp; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6270 |  | 
| Bruno Ricci | 17ff026 | 2018-10-27 19:21:19 +0000 | [diff] [blame] | 6271 | return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType, | 
|  | 6272 | E->getIdentKind(), ToFunctionName); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6273 | } | 
|  | 6274 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6275 | ExpectedStmt ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { | 
|  | 6276 | auto Imp = importSeq( | 
|  | 6277 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDecl(), | 
|  | 6278 | E->getLocation(), E->getType()); | 
|  | 6279 | if (!Imp) | 
|  | 6280 | return Imp.takeError(); | 
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6281 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6282 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 6283 | SourceLocation ToTemplateKeywordLoc, ToLocation; | 
|  | 6284 | ValueDecl *ToDecl; | 
|  | 6285 | QualType ToType; | 
|  | 6286 | std::tie(ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, ToLocation, ToType) = | 
|  | 6287 | *Imp; | 
|  | 6288 |  | 
|  | 6289 | NamedDecl *ToFoundD = nullptr; | 
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6290 | if (E->getDecl() != E->getFoundDecl()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6291 | auto FoundDOrErr = import(E->getFoundDecl()); | 
|  | 6292 | if (!FoundDOrErr) | 
|  | 6293 | return FoundDOrErr.takeError(); | 
|  | 6294 | ToFoundD = *FoundDOrErr; | 
| Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 6295 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6296 |  | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6297 | TemplateArgumentListInfo ToTAInfo; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6298 | TemplateArgumentListInfo *ToResInfo = nullptr; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6299 | if (E->hasExplicitTemplateArgs()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6300 | if (Error Err = | 
|  | 6301 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) | 
|  | 6302 | return std::move(Err); | 
|  | 6303 | ToResInfo = &ToTAInfo; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6304 | } | 
|  | 6305 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6306 | auto *ToE = DeclRefExpr::Create( | 
|  | 6307 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl, | 
|  | 6308 | E->refersToEnclosingVariableOrCapture(), ToLocation, ToType, | 
| Richard Smith | 715f7a1 | 2019-06-11 17:50:32 +0000 | [diff] [blame] | 6309 | E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse()); | 
| Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 6310 | if (E->hadMultipleCandidates()) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6311 | ToE->setHadMultipleCandidates(true); | 
|  | 6312 | return ToE; | 
| Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 6313 | } | 
|  | 6314 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6315 | ExpectedStmt ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { | 
|  | 6316 | ExpectedType TypeOrErr = import(E->getType()); | 
|  | 6317 | if (!TypeOrErr) | 
|  | 6318 | return TypeOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6319 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6320 | return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6321 | } | 
|  | 6322 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6323 | ExpectedStmt ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *E) { | 
|  | 6324 | ExpectedExpr ToInitOrErr = import(E->getInit()); | 
|  | 6325 | if (!ToInitOrErr) | 
|  | 6326 | return ToInitOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6327 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6328 | ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc()); | 
|  | 6329 | if (!ToEqualOrColonLocOrErr) | 
|  | 6330 | return ToEqualOrColonLocOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6331 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6332 | SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6333 | // List elements from the second, the first is Init itself | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6334 | for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) { | 
|  | 6335 | if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I))) | 
|  | 6336 | ToIndexExprs[I - 1] = *ToArgOrErr; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6337 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6338 | return ToArgOrErr.takeError(); | 
| 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 | SmallVector<Designator, 4> ToDesignators(E->size()); | 
|  | 6342 | if (Error Err = ImportContainerChecked(E->designators(), ToDesignators)) | 
|  | 6343 | return std::move(Err); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6344 |  | 
|  | 6345 | return DesignatedInitExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6346 | Importer.getToContext(), ToDesignators, | 
|  | 6347 | ToIndexExprs, *ToEqualOrColonLocOrErr, | 
|  | 6348 | E->usesGNUSyntax(), *ToInitOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6349 | } | 
|  | 6350 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6351 | ExpectedStmt | 
|  | 6352 | ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { | 
|  | 6353 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 6354 | if (!ToTypeOrErr) | 
|  | 6355 | return ToTypeOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6356 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6357 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | 
|  | 6358 | if (!ToLocationOrErr) | 
|  | 6359 | return ToLocationOrErr.takeError(); | 
|  | 6360 |  | 
|  | 6361 | return new (Importer.getToContext()) CXXNullPtrLiteralExpr( | 
|  | 6362 | *ToTypeOrErr, *ToLocationOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6363 | } | 
|  | 6364 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6365 | ExpectedStmt ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { | 
|  | 6366 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 6367 | if (!ToTypeOrErr) | 
|  | 6368 | return ToTypeOrErr.takeError(); | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6369 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6370 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | 
|  | 6371 | if (!ToLocationOrErr) | 
|  | 6372 | return ToLocationOrErr.takeError(); | 
|  | 6373 |  | 
|  | 6374 | return IntegerLiteral::Create( | 
|  | 6375 | Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr); | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6376 | } | 
|  | 6377 |  | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6378 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6379 | ExpectedStmt ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { | 
|  | 6380 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 6381 | if (!ToTypeOrErr) | 
|  | 6382 | return ToTypeOrErr.takeError(); | 
|  | 6383 |  | 
|  | 6384 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | 
|  | 6385 | if (!ToLocationOrErr) | 
|  | 6386 | return ToLocationOrErr.takeError(); | 
|  | 6387 |  | 
|  | 6388 | return FloatingLiteral::Create( | 
|  | 6389 | Importer.getToContext(), E->getValue(), E->isExact(), | 
|  | 6390 | *ToTypeOrErr, *ToLocationOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6391 | } | 
|  | 6392 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6393 | ExpectedStmt ASTNodeImporter::VisitImaginaryLiteral(ImaginaryLiteral *E) { | 
|  | 6394 | auto ToTypeOrErr = import(E->getType()); | 
|  | 6395 | if (!ToTypeOrErr) | 
|  | 6396 | return ToTypeOrErr.takeError(); | 
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6397 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6398 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | 
|  | 6399 | if (!ToSubExprOrErr) | 
|  | 6400 | return ToSubExprOrErr.takeError(); | 
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6401 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6402 | return new (Importer.getToContext()) ImaginaryLiteral( | 
|  | 6403 | *ToSubExprOrErr, *ToTypeOrErr); | 
| Gabor Marton | bf7f18b | 2018-08-09 12:18:07 +0000 | [diff] [blame] | 6404 | } | 
|  | 6405 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6406 | ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { | 
|  | 6407 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 6408 | if (!ToTypeOrErr) | 
|  | 6409 | return ToTypeOrErr.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6410 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6411 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | 
|  | 6412 | if (!ToLocationOrErr) | 
|  | 6413 | return ToLocationOrErr.takeError(); | 
|  | 6414 |  | 
|  | 6415 | return new (Importer.getToContext()) CharacterLiteral( | 
|  | 6416 | E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr); | 
| Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 6417 | } | 
|  | 6418 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6419 | ExpectedStmt ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { | 
|  | 6420 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 6421 | if (!ToTypeOrErr) | 
|  | 6422 | return ToTypeOrErr.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 | SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated()); | 
|  | 6425 | if (Error Err = ImportArrayChecked( | 
|  | 6426 | E->tokloc_begin(), E->tokloc_end(), ToLocations.begin())) | 
|  | 6427 | return std::move(Err); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6428 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6429 | return StringLiteral::Create( | 
|  | 6430 | Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(), | 
|  | 6431 | *ToTypeOrErr, ToLocations.data(), ToLocations.size()); | 
| 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::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { | 
|  | 6435 | auto Imp = importSeq( | 
|  | 6436 | E->getLParenLoc(), E->getTypeSourceInfo(), E->getType(), | 
|  | 6437 | E->getInitializer()); | 
|  | 6438 | if (!Imp) | 
|  | 6439 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6440 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6441 | SourceLocation ToLParenLoc; | 
|  | 6442 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 6443 | QualType ToType; | 
|  | 6444 | Expr *ToInitializer; | 
|  | 6445 | std::tie(ToLParenLoc, ToTypeSourceInfo, ToType, ToInitializer) = *Imp; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6446 |  | 
|  | 6447 | return new (Importer.getToContext()) CompoundLiteralExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6448 | ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(), | 
|  | 6449 | ToInitializer, E->isFileScope()); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6450 | } | 
|  | 6451 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6452 | ExpectedStmt ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { | 
|  | 6453 | auto Imp = importSeq( | 
|  | 6454 | E->getBuiltinLoc(), E->getType(), E->getRParenLoc()); | 
|  | 6455 | if (!Imp) | 
|  | 6456 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6457 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6458 | SourceLocation ToBuiltinLoc, ToRParenLoc; | 
|  | 6459 | QualType ToType; | 
|  | 6460 | std::tie(ToBuiltinLoc, ToType, ToRParenLoc) = *Imp; | 
|  | 6461 |  | 
|  | 6462 | SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs()); | 
|  | 6463 | if (Error Err = ImportArrayChecked( | 
|  | 6464 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), | 
|  | 6465 | ToExprs.begin())) | 
|  | 6466 | return std::move(Err); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6467 |  | 
|  | 6468 | return new (Importer.getToContext()) AtomicExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6469 | ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6470 | } | 
|  | 6471 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6472 | ExpectedStmt ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { | 
|  | 6473 | auto Imp = importSeq( | 
|  | 6474 | E->getAmpAmpLoc(), E->getLabelLoc(), E->getLabel(), E->getType()); | 
|  | 6475 | if (!Imp) | 
|  | 6476 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6477 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6478 | SourceLocation ToAmpAmpLoc, ToLabelLoc; | 
|  | 6479 | LabelDecl *ToLabel; | 
|  | 6480 | QualType ToType; | 
|  | 6481 | std::tie(ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType) = *Imp; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6482 |  | 
|  | 6483 | return new (Importer.getToContext()) AddrLabelExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6484 | ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6485 | } | 
|  | 6486 |  | 
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6487 | ExpectedStmt ASTNodeImporter::VisitConstantExpr(ConstantExpr *E) { | 
|  | 6488 | auto Imp = importSeq(E->getSubExpr()); | 
|  | 6489 | if (!Imp) | 
|  | 6490 | return Imp.takeError(); | 
|  | 6491 |  | 
|  | 6492 | Expr *ToSubExpr; | 
|  | 6493 | std::tie(ToSubExpr) = *Imp; | 
|  | 6494 |  | 
| Gauthier Harnisch | 83c7b61 | 2019-06-15 10:24:47 +0000 | [diff] [blame] | 6495 | // TODO : Handle APValue::ValueKind that require importing. | 
|  | 6496 | APValue::ValueKind Kind = E->getResultAPValueKind(); | 
|  | 6497 | if (Kind == APValue::Int || Kind == APValue::Float || | 
|  | 6498 | Kind == APValue::FixedPoint || Kind == APValue::ComplexFloat || | 
|  | 6499 | Kind == APValue::ComplexInt) | 
|  | 6500 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, | 
|  | 6501 | E->getAPValueResult()); | 
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 6502 | return ConstantExpr::Create(Importer.getToContext(), ToSubExpr); | 
| Bill Wendling | 8003edc | 2018-11-09 00:41:36 +0000 | [diff] [blame] | 6503 | } | 
|  | 6504 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6505 | ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) { | 
|  | 6506 | auto Imp = importSeq(E->getLParen(), E->getRParen(), E->getSubExpr()); | 
|  | 6507 | if (!Imp) | 
|  | 6508 | return Imp.takeError(); | 
|  | 6509 |  | 
|  | 6510 | SourceLocation ToLParen, ToRParen; | 
|  | 6511 | Expr *ToSubExpr; | 
|  | 6512 | std::tie(ToLParen, ToRParen, ToSubExpr) = *Imp; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6513 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6514 | return new (Importer.getToContext()) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6515 | ParenExpr(ToLParen, ToRParen, ToSubExpr); | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6516 | } | 
|  | 6517 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6518 | ExpectedStmt ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { | 
|  | 6519 | SmallVector<Expr *, 4> ToExprs(E->getNumExprs()); | 
|  | 6520 | if (Error Err = ImportContainerChecked(E->exprs(), ToExprs)) | 
|  | 6521 | return std::move(Err); | 
|  | 6522 |  | 
|  | 6523 | ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc()); | 
|  | 6524 | if (!ToLParenLocOrErr) | 
|  | 6525 | return ToLParenLocOrErr.takeError(); | 
|  | 6526 |  | 
|  | 6527 | ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc()); | 
|  | 6528 | if (!ToRParenLocOrErr) | 
|  | 6529 | return ToRParenLocOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6530 |  | 
| Bruno Ricci | f49e1ca | 2018-11-20 16:20:40 +0000 | [diff] [blame] | 6531 | return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr, | 
|  | 6532 | ToExprs, *ToRParenLocOrErr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6533 | } | 
|  | 6534 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6535 | ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { | 
|  | 6536 | auto Imp = importSeq( | 
|  | 6537 | E->getSubStmt(), E->getType(), E->getLParenLoc(), E->getRParenLoc()); | 
|  | 6538 | if (!Imp) | 
|  | 6539 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6540 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6541 | CompoundStmt *ToSubStmt; | 
|  | 6542 | QualType ToType; | 
|  | 6543 | SourceLocation ToLParenLoc, ToRParenLoc; | 
|  | 6544 | std::tie(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc) = *Imp; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6545 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6546 | return new (Importer.getToContext()) StmtExpr( | 
|  | 6547 | ToSubStmt, ToType, ToLParenLoc, ToRParenLoc); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6548 | } | 
|  | 6549 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6550 | ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { | 
|  | 6551 | auto Imp = importSeq( | 
|  | 6552 | E->getSubExpr(), E->getType(), E->getOperatorLoc()); | 
|  | 6553 | if (!Imp) | 
|  | 6554 | return Imp.takeError(); | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6555 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6556 | Expr *ToSubExpr; | 
|  | 6557 | QualType ToType; | 
|  | 6558 | SourceLocation ToOperatorLoc; | 
|  | 6559 | std::tie(ToSubExpr, ToType, ToOperatorLoc) = *Imp; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6560 |  | 
| Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6561 | return new (Importer.getToContext()) UnaryOperator( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6562 | ToSubExpr, E->getOpcode(), ToType, E->getValueKind(), E->getObjectKind(), | 
|  | 6563 | ToOperatorLoc, E->canOverflow()); | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6564 | } | 
|  | 6565 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6566 | ExpectedStmt | 
| Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 6567 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6568 | auto Imp = importSeq(E->getType(), E->getOperatorLoc(), E->getRParenLoc()); | 
|  | 6569 | if (!Imp) | 
|  | 6570 | return Imp.takeError(); | 
|  | 6571 |  | 
|  | 6572 | QualType ToType; | 
|  | 6573 | SourceLocation ToOperatorLoc, ToRParenLoc; | 
|  | 6574 | std::tie(ToType, ToOperatorLoc, ToRParenLoc) = *Imp; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6575 |  | 
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6576 | if (E->isArgumentType()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6577 | Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr = | 
|  | 6578 | import(E->getArgumentTypeInfo()); | 
|  | 6579 | if (!ToArgumentTypeInfoOrErr) | 
|  | 6580 | return ToArgumentTypeInfoOrErr.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6581 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6582 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( | 
|  | 6583 | E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc, | 
|  | 6584 | ToRParenLoc); | 
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6585 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6586 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6587 | ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr()); | 
|  | 6588 | if (!ToArgumentExprOrErr) | 
|  | 6589 | return ToArgumentExprOrErr.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6590 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6591 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr( | 
|  | 6592 | E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc); | 
| Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 6593 | } | 
|  | 6594 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6595 | ExpectedStmt ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { | 
|  | 6596 | auto Imp = importSeq( | 
|  | 6597 | E->getLHS(), E->getRHS(), E->getType(), E->getOperatorLoc()); | 
|  | 6598 | if (!Imp) | 
|  | 6599 | return Imp.takeError(); | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6600 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6601 | Expr *ToLHS, *ToRHS; | 
|  | 6602 | QualType ToType; | 
|  | 6603 | SourceLocation  ToOperatorLoc; | 
|  | 6604 | std::tie(ToLHS, ToRHS, ToType, ToOperatorLoc) = *Imp; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6605 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6606 | return new (Importer.getToContext()) BinaryOperator( | 
|  | 6607 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), | 
|  | 6608 | E->getObjectKind(), ToOperatorLoc, E->getFPFeatures()); | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6609 | } | 
|  | 6610 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6611 | ExpectedStmt ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { | 
|  | 6612 | auto Imp = importSeq( | 
|  | 6613 | E->getCond(), E->getQuestionLoc(), E->getLHS(), E->getColonLoc(), | 
|  | 6614 | E->getRHS(), E->getType()); | 
|  | 6615 | if (!Imp) | 
|  | 6616 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6617 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6618 | Expr *ToCond, *ToLHS, *ToRHS; | 
|  | 6619 | SourceLocation ToQuestionLoc, ToColonLoc; | 
|  | 6620 | QualType ToType; | 
|  | 6621 | std::tie(ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType) = *Imp; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6622 |  | 
|  | 6623 | return new (Importer.getToContext()) ConditionalOperator( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6624 | ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType, | 
|  | 6625 | E->getValueKind(), E->getObjectKind()); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6626 | } | 
|  | 6627 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6628 | ExpectedStmt ASTNodeImporter::VisitBinaryConditionalOperator( | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6629 | BinaryConditionalOperator *E) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6630 | auto Imp = importSeq( | 
|  | 6631 | E->getCommon(), E->getOpaqueValue(), E->getCond(), E->getTrueExpr(), | 
|  | 6632 | E->getFalseExpr(), E->getQuestionLoc(), E->getColonLoc(), E->getType()); | 
|  | 6633 | if (!Imp) | 
|  | 6634 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6635 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6636 | Expr *ToCommon, *ToCond, *ToTrueExpr, *ToFalseExpr; | 
|  | 6637 | OpaqueValueExpr *ToOpaqueValue; | 
|  | 6638 | SourceLocation ToQuestionLoc, ToColonLoc; | 
|  | 6639 | QualType ToType; | 
|  | 6640 | std::tie( | 
|  | 6641 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, ToQuestionLoc, | 
|  | 6642 | ToColonLoc, ToType) = *Imp; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6643 |  | 
|  | 6644 | return new (Importer.getToContext()) BinaryConditionalOperator( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6645 | ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr, | 
|  | 6646 | ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(), | 
|  | 6647 | E->getObjectKind()); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6648 | } | 
|  | 6649 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6650 | ExpectedStmt ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { | 
|  | 6651 | auto Imp = importSeq( | 
|  | 6652 | E->getBeginLoc(), E->getQueriedTypeSourceInfo(), | 
|  | 6653 | E->getDimensionExpression(), E->getEndLoc(), E->getType()); | 
|  | 6654 | if (!Imp) | 
|  | 6655 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6656 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6657 | SourceLocation ToBeginLoc, ToEndLoc; | 
|  | 6658 | TypeSourceInfo *ToQueriedTypeSourceInfo; | 
|  | 6659 | Expr *ToDimensionExpression; | 
|  | 6660 | QualType ToType; | 
|  | 6661 | std::tie( | 
|  | 6662 | ToBeginLoc, ToQueriedTypeSourceInfo, ToDimensionExpression, ToEndLoc, | 
|  | 6663 | ToType) = *Imp; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6664 |  | 
|  | 6665 | return new (Importer.getToContext()) ArrayTypeTraitExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6666 | ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(), | 
|  | 6667 | ToDimensionExpression, ToEndLoc, ToType); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6668 | } | 
|  | 6669 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6670 | ExpectedStmt ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { | 
|  | 6671 | auto Imp = importSeq( | 
|  | 6672 | E->getBeginLoc(), E->getQueriedExpression(), E->getEndLoc(), E->getType()); | 
|  | 6673 | if (!Imp) | 
|  | 6674 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6675 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6676 | SourceLocation ToBeginLoc, ToEndLoc; | 
|  | 6677 | Expr *ToQueriedExpression; | 
|  | 6678 | QualType ToType; | 
|  | 6679 | std::tie(ToBeginLoc, ToQueriedExpression, ToEndLoc, ToType) = *Imp; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6680 |  | 
|  | 6681 | return new (Importer.getToContext()) ExpressionTraitExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6682 | ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(), | 
|  | 6683 | ToEndLoc, ToType); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6684 | } | 
|  | 6685 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6686 | ExpectedStmt ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { | 
|  | 6687 | auto Imp = importSeq( | 
|  | 6688 | E->getLocation(), E->getType(), E->getSourceExpr()); | 
|  | 6689 | if (!Imp) | 
|  | 6690 | return Imp.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6691 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6692 | SourceLocation ToLocation; | 
|  | 6693 | QualType ToType; | 
|  | 6694 | Expr *ToSourceExpr; | 
|  | 6695 | std::tie(ToLocation, ToType, ToSourceExpr) = *Imp; | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6696 |  | 
|  | 6697 | return new (Importer.getToContext()) OpaqueValueExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6698 | ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6699 | } | 
|  | 6700 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6701 | ExpectedStmt ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { | 
|  | 6702 | auto Imp = importSeq( | 
|  | 6703 | E->getLHS(), E->getRHS(), E->getType(), E->getRBracketLoc()); | 
|  | 6704 | if (!Imp) | 
|  | 6705 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6706 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6707 | Expr *ToLHS, *ToRHS; | 
|  | 6708 | SourceLocation ToRBracketLoc; | 
|  | 6709 | QualType ToType; | 
|  | 6710 | std::tie(ToLHS, ToRHS, ToType, ToRBracketLoc) = *Imp; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6711 |  | 
|  | 6712 | return new (Importer.getToContext()) ArraySubscriptExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6713 | ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(), | 
|  | 6714 | ToRBracketLoc); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6715 | } | 
|  | 6716 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6717 | ExpectedStmt | 
|  | 6718 | ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { | 
|  | 6719 | auto Imp = importSeq( | 
|  | 6720 | E->getLHS(), E->getRHS(), E->getType(), E->getComputationLHSType(), | 
|  | 6721 | E->getComputationResultType(), E->getOperatorLoc()); | 
|  | 6722 | if (!Imp) | 
|  | 6723 | return Imp.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6724 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6725 | Expr *ToLHS, *ToRHS; | 
|  | 6726 | QualType ToType, ToComputationLHSType, ToComputationResultType; | 
|  | 6727 | SourceLocation ToOperatorLoc; | 
|  | 6728 | std::tie(ToLHS, ToRHS, ToType, ToComputationLHSType, ToComputationResultType, | 
|  | 6729 | ToOperatorLoc) = *Imp; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6730 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6731 | return new (Importer.getToContext()) CompoundAssignOperator( | 
|  | 6732 | ToLHS, ToRHS, E->getOpcode(), ToType, E->getValueKind(), | 
|  | 6733 | E->getObjectKind(), ToComputationLHSType, ToComputationResultType, | 
|  | 6734 | ToOperatorLoc, E->getFPFeatures()); | 
| Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 6735 | } | 
|  | 6736 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6737 | Expected<CXXCastPath> | 
|  | 6738 | ASTNodeImporter::ImportCastPath(CastExpr *CE) { | 
|  | 6739 | CXXCastPath Path; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6740 | 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] | 6741 | if (auto SpecOrErr = import(*I)) | 
|  | 6742 | Path.push_back(*SpecOrErr); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6743 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6744 | return SpecOrErr.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6745 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6746 | return Path; | 
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6747 | } | 
|  | 6748 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6749 | ExpectedStmt ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { | 
|  | 6750 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 6751 | if (!ToTypeOrErr) | 
|  | 6752 | return ToTypeOrErr.takeError(); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6753 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6754 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | 
|  | 6755 | if (!ToSubExprOrErr) | 
|  | 6756 | return ToSubExprOrErr.takeError(); | 
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6757 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6758 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); | 
|  | 6759 | if (!ToBasePathOrErr) | 
|  | 6760 | return ToBasePathOrErr.takeError(); | 
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6761 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6762 | return ImplicitCastExpr::Create( | 
|  | 6763 | Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr, | 
|  | 6764 | &(*ToBasePathOrErr), E->getValueKind()); | 
| Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 6765 | } | 
|  | 6766 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6767 | ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { | 
|  | 6768 | auto Imp1 = importSeq( | 
|  | 6769 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten()); | 
|  | 6770 | if (!Imp1) | 
|  | 6771 | return Imp1.takeError(); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6772 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6773 | QualType ToType; | 
|  | 6774 | Expr *ToSubExpr; | 
|  | 6775 | TypeSourceInfo *ToTypeInfoAsWritten; | 
|  | 6776 | std::tie(ToType, ToSubExpr, ToTypeInfoAsWritten) = *Imp1; | 
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6777 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6778 | Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E); | 
|  | 6779 | if (!ToBasePathOrErr) | 
|  | 6780 | return ToBasePathOrErr.takeError(); | 
|  | 6781 | CXXCastPath *ToBasePath = &(*ToBasePathOrErr); | 
| John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 6782 |  | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6783 | switch (E->getStmtClass()) { | 
|  | 6784 | case Stmt::CStyleCastExprClass: { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6785 | auto *CCE = cast<CStyleCastExpr>(E); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6786 | ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc()); | 
|  | 6787 | if (!ToLParenLocOrErr) | 
|  | 6788 | return ToLParenLocOrErr.takeError(); | 
|  | 6789 | ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc()); | 
|  | 6790 | if (!ToRParenLocOrErr) | 
|  | 6791 | return ToRParenLocOrErr.takeError(); | 
|  | 6792 | return CStyleCastExpr::Create( | 
|  | 6793 | Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(), | 
|  | 6794 | ToSubExpr, ToBasePath, ToTypeInfoAsWritten, *ToLParenLocOrErr, | 
|  | 6795 | *ToRParenLocOrErr); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6796 | } | 
|  | 6797 |  | 
|  | 6798 | case Stmt::CXXFunctionalCastExprClass: { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6799 | auto *FCE = cast<CXXFunctionalCastExpr>(E); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6800 | ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc()); | 
|  | 6801 | if (!ToLParenLocOrErr) | 
|  | 6802 | return ToLParenLocOrErr.takeError(); | 
|  | 6803 | ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc()); | 
|  | 6804 | if (!ToRParenLocOrErr) | 
|  | 6805 | return ToRParenLocOrErr.takeError(); | 
|  | 6806 | return CXXFunctionalCastExpr::Create( | 
|  | 6807 | Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten, | 
|  | 6808 | E->getCastKind(), ToSubExpr, ToBasePath, *ToLParenLocOrErr, | 
|  | 6809 | *ToRParenLocOrErr); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6810 | } | 
|  | 6811 |  | 
|  | 6812 | case Stmt::ObjCBridgedCastExprClass: { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6813 | auto *OCE = cast<ObjCBridgedCastExpr>(E); | 
|  | 6814 | ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc()); | 
|  | 6815 | if (!ToLParenLocOrErr) | 
|  | 6816 | return ToLParenLocOrErr.takeError(); | 
|  | 6817 | ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc()); | 
|  | 6818 | if (!ToBridgeKeywordLocOrErr) | 
|  | 6819 | return ToBridgeKeywordLocOrErr.takeError(); | 
|  | 6820 | return new (Importer.getToContext()) ObjCBridgedCastExpr( | 
|  | 6821 | *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), | 
|  | 6822 | *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6823 | } | 
|  | 6824 | default: | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6825 | llvm_unreachable("Cast expression of unsupported type!"); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6826 | return make_error<ImportError>(ImportError::UnsupportedConstruct); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6827 | } | 
|  | 6828 | } | 
|  | 6829 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6830 | ExpectedStmt ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *E) { | 
|  | 6831 | SmallVector<OffsetOfNode, 4> ToNodes; | 
|  | 6832 | for (int I = 0, N = E->getNumComponents(); I < N; ++I) { | 
|  | 6833 | const OffsetOfNode &FromNode = E->getComponent(I); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6834 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6835 | SourceLocation ToBeginLoc, ToEndLoc; | 
|  | 6836 | if (FromNode.getKind() != OffsetOfNode::Base) { | 
|  | 6837 | auto Imp = importSeq(FromNode.getBeginLoc(), FromNode.getEndLoc()); | 
|  | 6838 | if (!Imp) | 
|  | 6839 | return Imp.takeError(); | 
|  | 6840 | std::tie(ToBeginLoc, ToEndLoc) = *Imp; | 
|  | 6841 | } | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6842 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6843 | switch (FromNode.getKind()) { | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6844 | case OffsetOfNode::Array: | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6845 | ToNodes.push_back( | 
|  | 6846 | OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc)); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6847 | break; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6848 | case OffsetOfNode::Base: { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6849 | auto ToBSOrErr = import(FromNode.getBase()); | 
|  | 6850 | if (!ToBSOrErr) | 
|  | 6851 | return ToBSOrErr.takeError(); | 
|  | 6852 | ToNodes.push_back(OffsetOfNode(*ToBSOrErr)); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6853 | break; | 
|  | 6854 | } | 
|  | 6855 | case OffsetOfNode::Field: { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6856 | auto ToFieldOrErr = import(FromNode.getField()); | 
|  | 6857 | if (!ToFieldOrErr) | 
|  | 6858 | return ToFieldOrErr.takeError(); | 
|  | 6859 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc)); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6860 | break; | 
|  | 6861 | } | 
|  | 6862 | case OffsetOfNode::Identifier: { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6863 | IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName()); | 
|  | 6864 | ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc)); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6865 | break; | 
|  | 6866 | } | 
|  | 6867 | } | 
|  | 6868 | } | 
|  | 6869 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6870 | SmallVector<Expr *, 4> ToExprs(E->getNumExpressions()); | 
|  | 6871 | for (int I = 0, N = E->getNumExpressions(); I < N; ++I) { | 
|  | 6872 | ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I)); | 
|  | 6873 | if (!ToIndexExprOrErr) | 
|  | 6874 | return ToIndexExprOrErr.takeError(); | 
|  | 6875 | ToExprs[I] = *ToIndexExprOrErr; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6876 | } | 
|  | 6877 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6878 | auto Imp = importSeq( | 
|  | 6879 | E->getType(), E->getTypeSourceInfo(), E->getOperatorLoc(), | 
|  | 6880 | E->getRParenLoc()); | 
|  | 6881 | if (!Imp) | 
|  | 6882 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6883 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6884 | QualType ToType; | 
|  | 6885 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 6886 | SourceLocation ToOperatorLoc, ToRParenLoc; | 
|  | 6887 | std::tie(ToType, ToTypeSourceInfo, ToOperatorLoc, ToRParenLoc) = *Imp; | 
|  | 6888 |  | 
|  | 6889 | return OffsetOfExpr::Create( | 
|  | 6890 | Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes, | 
|  | 6891 | ToExprs, ToRParenLoc); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6892 | } | 
|  | 6893 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6894 | ExpectedStmt ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { | 
|  | 6895 | auto Imp = importSeq( | 
|  | 6896 | E->getType(), E->getOperand(), E->getBeginLoc(), E->getEndLoc()); | 
|  | 6897 | if (!Imp) | 
|  | 6898 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6899 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6900 | QualType ToType; | 
|  | 6901 | Expr *ToOperand; | 
|  | 6902 | SourceLocation ToBeginLoc, ToEndLoc; | 
|  | 6903 | std::tie(ToType, ToOperand, ToBeginLoc, ToEndLoc) = *Imp; | 
| 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 | CanThrowResult ToCanThrow; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6906 | if (E->isValueDependent()) | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6907 | ToCanThrow = CT_Dependent; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6908 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6909 | ToCanThrow = E->getValue() ? CT_Can : CT_Cannot; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6910 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6911 | return new (Importer.getToContext()) CXXNoexceptExpr( | 
|  | 6912 | ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6913 | } | 
|  | 6914 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6915 | ExpectedStmt ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { | 
|  | 6916 | auto Imp = importSeq(E->getSubExpr(), E->getType(), E->getThrowLoc()); | 
|  | 6917 | if (!Imp) | 
|  | 6918 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6919 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6920 | Expr *ToSubExpr; | 
|  | 6921 | QualType ToType; | 
|  | 6922 | SourceLocation ToThrowLoc; | 
|  | 6923 | std::tie(ToSubExpr, ToType, ToThrowLoc) = *Imp; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6924 |  | 
|  | 6925 | return new (Importer.getToContext()) CXXThrowExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6926 | ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope()); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6927 | } | 
|  | 6928 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6929 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { | 
|  | 6930 | ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation()); | 
|  | 6931 | if (!ToUsedLocOrErr) | 
|  | 6932 | return ToUsedLocOrErr.takeError(); | 
|  | 6933 |  | 
|  | 6934 | auto ToParamOrErr = import(E->getParam()); | 
|  | 6935 | if (!ToParamOrErr) | 
|  | 6936 | return ToParamOrErr.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6937 |  | 
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 6938 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); | 
|  | 6939 | if (!UsedContextOrErr) | 
|  | 6940 | return UsedContextOrErr.takeError(); | 
|  | 6941 |  | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6942 | return CXXDefaultArgExpr::Create( | 
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 6943 | Importer.getToContext(), *ToUsedLocOrErr, *ToParamOrErr, *UsedContextOrErr); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6944 | } | 
|  | 6945 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6946 | ExpectedStmt | 
|  | 6947 | ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { | 
|  | 6948 | auto Imp = importSeq( | 
|  | 6949 | E->getType(), E->getTypeSourceInfo(), E->getRParenLoc()); | 
|  | 6950 | if (!Imp) | 
|  | 6951 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6952 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6953 | QualType ToType; | 
|  | 6954 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 6955 | SourceLocation ToRParenLoc; | 
|  | 6956 | std::tie(ToType, ToTypeSourceInfo, ToRParenLoc) = *Imp; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6957 |  | 
|  | 6958 | return new (Importer.getToContext()) CXXScalarValueInitExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6959 | ToType, ToTypeSourceInfo, ToRParenLoc); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6960 | } | 
|  | 6961 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6962 | ExpectedStmt | 
|  | 6963 | ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { | 
|  | 6964 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | 
|  | 6965 | if (!ToSubExprOrErr) | 
|  | 6966 | return ToSubExprOrErr.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6967 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6968 | auto ToDtorOrErr = import(E->getTemporary()->getDestructor()); | 
|  | 6969 | if (!ToDtorOrErr) | 
|  | 6970 | return ToDtorOrErr.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6971 |  | 
|  | 6972 | ASTContext &ToCtx = Importer.getToContext(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6973 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr); | 
|  | 6974 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6975 | } | 
|  | 6976 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6977 | ExpectedStmt | 
|  | 6978 | ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) { | 
|  | 6979 | auto Imp = importSeq( | 
|  | 6980 | E->getConstructor(), E->getType(), E->getTypeSourceInfo(), | 
|  | 6981 | E->getParenOrBraceRange()); | 
|  | 6982 | if (!Imp) | 
|  | 6983 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6984 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6985 | CXXConstructorDecl *ToConstructor; | 
|  | 6986 | QualType ToType; | 
|  | 6987 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 6988 | SourceRange ToParenOrBraceRange; | 
|  | 6989 | std::tie(ToConstructor, ToType, ToTypeSourceInfo, ToParenOrBraceRange) = *Imp; | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6990 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6991 | SmallVector<Expr *, 8> ToArgs(E->getNumArgs()); | 
|  | 6992 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | 
|  | 6993 | return std::move(Err); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6994 |  | 
| Bruno Ricci | ddb8f6b | 2018-12-22 14:39:30 +0000 | [diff] [blame] | 6995 | return CXXTemporaryObjectExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 6996 | Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs, | 
|  | 6997 | ToParenOrBraceRange, E->hadMultipleCandidates(), | 
|  | 6998 | E->isListInitialization(), E->isStdInitListInitialization(), | 
|  | 6999 | E->requiresZeroInitialization()); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7000 | } | 
|  | 7001 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7002 | ExpectedStmt | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7003 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7004 | auto Imp = importSeq( | 
|  | 7005 | E->getType(), E->GetTemporaryExpr(), E->getExtendingDecl()); | 
|  | 7006 | if (!Imp) | 
|  | 7007 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7008 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7009 | QualType ToType; | 
|  | 7010 | Expr *ToTemporaryExpr; | 
|  | 7011 | const ValueDecl *ToExtendingDecl; | 
|  | 7012 | std::tie(ToType, ToTemporaryExpr, ToExtendingDecl) = *Imp; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7013 |  | 
|  | 7014 | auto *ToMTE =  new (Importer.getToContext()) MaterializeTemporaryExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7015 | ToType, ToTemporaryExpr, E->isBoundToLvalueReference()); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7016 |  | 
|  | 7017 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7018 | ToMTE->setExtendingDecl(ToExtendingDecl, E->getManglingNumber()); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7019 | return ToMTE; | 
|  | 7020 | } | 
|  | 7021 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7022 | ExpectedStmt ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { | 
|  | 7023 | auto Imp = importSeq( | 
|  | 7024 | E->getType(), E->getPattern(), E->getEllipsisLoc()); | 
|  | 7025 | if (!Imp) | 
|  | 7026 | return Imp.takeError(); | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7027 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7028 | QualType ToType; | 
|  | 7029 | Expr *ToPattern; | 
|  | 7030 | SourceLocation ToEllipsisLoc; | 
|  | 7031 | std::tie(ToType, ToPattern, ToEllipsisLoc) = *Imp; | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7032 |  | 
|  | 7033 | return new (Importer.getToContext()) PackExpansionExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7034 | ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions()); | 
| Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 7035 | } | 
|  | 7036 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7037 | ExpectedStmt ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { | 
|  | 7038 | auto Imp = importSeq( | 
|  | 7039 | E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc()); | 
|  | 7040 | if (!Imp) | 
|  | 7041 | return Imp.takeError(); | 
|  | 7042 |  | 
|  | 7043 | SourceLocation ToOperatorLoc, ToPackLoc, ToRParenLoc; | 
|  | 7044 | NamedDecl *ToPack; | 
|  | 7045 | std::tie(ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc) = *Imp; | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7046 |  | 
|  | 7047 | Optional<unsigned> Length; | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7048 | if (!E->isValueDependent()) | 
|  | 7049 | Length = E->getPackLength(); | 
|  | 7050 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7051 | SmallVector<TemplateArgument, 8> ToPartialArguments; | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7052 | if (E->isPartiallySubstituted()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7053 | if (Error Err = ImportTemplateArguments( | 
|  | 7054 | E->getPartialArguments().data(), | 
|  | 7055 | E->getPartialArguments().size(), | 
|  | 7056 | ToPartialArguments)) | 
|  | 7057 | return std::move(Err); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7058 | } | 
|  | 7059 |  | 
|  | 7060 | return SizeOfPackExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7061 | Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc, | 
|  | 7062 | Length, ToPartialArguments); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7063 | } | 
|  | 7064 |  | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7065 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7066 | ExpectedStmt ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *E) { | 
|  | 7067 | auto Imp = importSeq( | 
|  | 7068 | E->getOperatorNew(), E->getOperatorDelete(), E->getTypeIdParens(), | 
|  | 7069 | E->getArraySize(), E->getInitializer(), E->getType(), | 
|  | 7070 | E->getAllocatedTypeSourceInfo(), E->getSourceRange(), | 
|  | 7071 | E->getDirectInitRange()); | 
|  | 7072 | if (!Imp) | 
|  | 7073 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7074 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7075 | FunctionDecl *ToOperatorNew, *ToOperatorDelete; | 
|  | 7076 | SourceRange ToTypeIdParens, ToSourceRange, ToDirectInitRange; | 
| Richard Smith | b9fb121 | 2019-05-06 03:47:15 +0000 | [diff] [blame] | 7077 | Optional<Expr *> ToArraySize; | 
|  | 7078 | Expr *ToInitializer; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7079 | QualType ToType; | 
|  | 7080 | TypeSourceInfo *ToAllocatedTypeSourceInfo; | 
|  | 7081 | std::tie( | 
|  | 7082 | ToOperatorNew, ToOperatorDelete, ToTypeIdParens, ToArraySize, ToInitializer, | 
|  | 7083 | ToType, ToAllocatedTypeSourceInfo, ToSourceRange, ToDirectInitRange) = *Imp; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7084 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7085 | SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs()); | 
|  | 7086 | if (Error Err = | 
|  | 7087 | ImportContainerChecked(E->placement_arguments(), ToPlacementArgs)) | 
|  | 7088 | return std::move(Err); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7089 |  | 
| Bruno Ricci | 9b6dfac | 2019-01-07 15:04:45 +0000 | [diff] [blame] | 7090 | return CXXNewExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7091 | Importer.getToContext(), E->isGlobalNew(), ToOperatorNew, | 
|  | 7092 | ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(), | 
|  | 7093 | ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(), | 
|  | 7094 | ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange, | 
|  | 7095 | ToDirectInitRange); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7096 | } | 
|  | 7097 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7098 | ExpectedStmt ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { | 
|  | 7099 | auto Imp = importSeq( | 
|  | 7100 | E->getType(), E->getOperatorDelete(), E->getArgument(), E->getBeginLoc()); | 
|  | 7101 | if (!Imp) | 
|  | 7102 | return Imp.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7103 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7104 | QualType ToType; | 
|  | 7105 | FunctionDecl *ToOperatorDelete; | 
|  | 7106 | Expr *ToArgument; | 
|  | 7107 | SourceLocation ToBeginLoc; | 
|  | 7108 | std::tie(ToType, ToOperatorDelete, ToArgument, ToBeginLoc) = *Imp; | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7109 |  | 
|  | 7110 | return new (Importer.getToContext()) CXXDeleteExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7111 | ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(), | 
|  | 7112 | E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument, | 
|  | 7113 | ToBeginLoc); | 
| Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 7114 | } | 
|  | 7115 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7116 | ExpectedStmt ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { | 
|  | 7117 | auto Imp = importSeq( | 
|  | 7118 | E->getType(), E->getLocation(), E->getConstructor(), | 
|  | 7119 | E->getParenOrBraceRange()); | 
|  | 7120 | if (!Imp) | 
|  | 7121 | return Imp.takeError(); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7122 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7123 | QualType ToType; | 
|  | 7124 | SourceLocation ToLocation; | 
|  | 7125 | CXXConstructorDecl *ToConstructor; | 
|  | 7126 | SourceRange ToParenOrBraceRange; | 
|  | 7127 | std::tie(ToType, ToLocation, ToConstructor, ToParenOrBraceRange) = *Imp; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7128 |  | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7129 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7130 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | 
|  | 7131 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7132 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7133 | return CXXConstructExpr::Create( | 
|  | 7134 | Importer.getToContext(), ToType, ToLocation, ToConstructor, | 
|  | 7135 | E->isElidable(), ToArgs, E->hadMultipleCandidates(), | 
|  | 7136 | E->isListInitialization(), E->isStdInitListInitialization(), | 
|  | 7137 | E->requiresZeroInitialization(), E->getConstructionKind(), | 
|  | 7138 | ToParenOrBraceRange); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7139 | } | 
|  | 7140 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7141 | ExpectedStmt ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *E) { | 
|  | 7142 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | 
|  | 7143 | if (!ToSubExprOrErr) | 
|  | 7144 | return ToSubExprOrErr.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7145 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7146 | SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects()); | 
|  | 7147 | if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects)) | 
|  | 7148 | return std::move(Err); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7149 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7150 | return ExprWithCleanups::Create( | 
|  | 7151 | Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(), | 
|  | 7152 | ToObjects); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7153 | } | 
|  | 7154 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7155 | ExpectedStmt ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { | 
|  | 7156 | auto Imp = importSeq( | 
|  | 7157 | E->getCallee(), E->getType(), E->getRParenLoc()); | 
|  | 7158 | if (!Imp) | 
|  | 7159 | return Imp.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7160 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7161 | Expr *ToCallee; | 
|  | 7162 | QualType ToType; | 
|  | 7163 | SourceLocation ToRParenLoc; | 
|  | 7164 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7165 |  | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7166 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7167 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | 
|  | 7168 | return std::move(Err); | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7169 |  | 
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7170 | return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, | 
|  | 7171 | ToType, E->getValueKind(), ToRParenLoc); | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7172 | } | 
|  | 7173 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7174 | ExpectedStmt ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { | 
|  | 7175 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 7176 | if (!ToTypeOrErr) | 
|  | 7177 | return ToTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7178 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7179 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | 
|  | 7180 | if (!ToLocationOrErr) | 
|  | 7181 | return ToLocationOrErr.takeError(); | 
|  | 7182 |  | 
|  | 7183 | return new (Importer.getToContext()) CXXThisExpr( | 
|  | 7184 | *ToLocationOrErr, *ToTypeOrErr, E->isImplicit()); | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7185 | } | 
|  | 7186 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7187 | ExpectedStmt ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { | 
|  | 7188 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 7189 | if (!ToTypeOrErr) | 
|  | 7190 | return ToTypeOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7191 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7192 | ExpectedSLoc ToLocationOrErr = import(E->getLocation()); | 
|  | 7193 | if (!ToLocationOrErr) | 
|  | 7194 | return ToLocationOrErr.takeError(); | 
|  | 7195 |  | 
|  | 7196 | return new (Importer.getToContext()) CXXBoolLiteralExpr( | 
|  | 7197 | E->getValue(), *ToTypeOrErr, *ToLocationOrErr); | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7198 | } | 
|  | 7199 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7200 | ExpectedStmt ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { | 
|  | 7201 | auto Imp1 = importSeq( | 
|  | 7202 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), | 
|  | 7203 | E->getTemplateKeywordLoc(), E->getMemberDecl(), E->getType()); | 
|  | 7204 | if (!Imp1) | 
|  | 7205 | return Imp1.takeError(); | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7206 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7207 | Expr *ToBase; | 
|  | 7208 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; | 
|  | 7209 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 7210 | ValueDecl *ToMemberDecl; | 
|  | 7211 | QualType ToType; | 
|  | 7212 | std::tie( | 
|  | 7213 | ToBase, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, ToMemberDecl, | 
|  | 7214 | ToType) = *Imp1; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7215 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7216 | auto Imp2 = importSeq( | 
|  | 7217 | E->getFoundDecl().getDecl(), E->getMemberNameInfo().getName(), | 
|  | 7218 | E->getMemberNameInfo().getLoc(), E->getLAngleLoc(), E->getRAngleLoc()); | 
|  | 7219 | if (!Imp2) | 
|  | 7220 | return Imp2.takeError(); | 
|  | 7221 | NamedDecl *ToDecl; | 
|  | 7222 | DeclarationName ToName; | 
|  | 7223 | SourceLocation ToLoc, ToLAngleLoc, ToRAngleLoc; | 
|  | 7224 | std::tie(ToDecl, ToName, ToLoc, ToLAngleLoc, ToRAngleLoc) = *Imp2; | 
| Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 7225 |  | 
|  | 7226 | DeclAccessPair ToFoundDecl = | 
|  | 7227 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7228 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7229 | DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7230 |  | 
| Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7231 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7232 | if (E->hasExplicitTemplateArgs()) { | 
| Gabor Marton | 5caba30 | 2019-03-07 13:38:20 +0000 | [diff] [blame] | 7233 | if (Error Err = | 
|  | 7234 | ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), | 
|  | 7235 | E->template_arguments(), ToTAInfo)) | 
|  | 7236 | return std::move(Err); | 
|  | 7237 | ResInfo = &ToTAInfo; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7238 | } | 
|  | 7239 |  | 
| Richard Smith | 1bbad59 | 2019-06-11 17:50:36 +0000 | [diff] [blame] | 7240 | return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(), | 
|  | 7241 | ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, | 
|  | 7242 | ToMemberDecl, ToFoundDecl, ToMemberNameInfo, | 
|  | 7243 | ResInfo, ToType, E->getValueKind(), | 
|  | 7244 | E->getObjectKind(), E->isNonOdrUse()); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7245 | } | 
|  | 7246 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7247 | ExpectedStmt | 
|  | 7248 | ASTNodeImporter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { | 
|  | 7249 | auto Imp = importSeq( | 
|  | 7250 | E->getBase(), E->getOperatorLoc(), E->getQualifierLoc(), | 
|  | 7251 | E->getScopeTypeInfo(), E->getColonColonLoc(), E->getTildeLoc()); | 
|  | 7252 | if (!Imp) | 
|  | 7253 | return Imp.takeError(); | 
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7254 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7255 | Expr *ToBase; | 
|  | 7256 | SourceLocation ToOperatorLoc, ToColonColonLoc, ToTildeLoc; | 
|  | 7257 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 7258 | TypeSourceInfo *ToScopeTypeInfo; | 
|  | 7259 | std::tie( | 
|  | 7260 | ToBase, ToOperatorLoc, ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, | 
|  | 7261 | ToTildeLoc) = *Imp; | 
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7262 |  | 
|  | 7263 | PseudoDestructorTypeStorage Storage; | 
|  | 7264 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { | 
|  | 7265 | IdentifierInfo *ToII = Importer.Import(FromII); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7266 | ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc()); | 
|  | 7267 | if (!ToDestroyedTypeLocOrErr) | 
|  | 7268 | return ToDestroyedTypeLocOrErr.takeError(); | 
|  | 7269 | Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr); | 
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7270 | } else { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7271 | if (auto ToTIOrErr = import(E->getDestroyedTypeInfo())) | 
|  | 7272 | Storage = PseudoDestructorTypeStorage(*ToTIOrErr); | 
|  | 7273 | else | 
|  | 7274 | return ToTIOrErr.takeError(); | 
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7275 | } | 
|  | 7276 |  | 
|  | 7277 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7278 | Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc, | 
|  | 7279 | ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage); | 
| Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 7280 | } | 
|  | 7281 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7282 | ExpectedStmt ASTNodeImporter::VisitCXXDependentScopeMemberExpr( | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7283 | CXXDependentScopeMemberExpr *E) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7284 | auto Imp = importSeq( | 
|  | 7285 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), | 
|  | 7286 | E->getTemplateKeywordLoc(), E->getFirstQualifierFoundInScope()); | 
|  | 7287 | if (!Imp) | 
|  | 7288 | return Imp.takeError(); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7289 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7290 | QualType ToType; | 
|  | 7291 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; | 
|  | 7292 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 7293 | NamedDecl *ToFirstQualifierFoundInScope; | 
|  | 7294 | std::tie( | 
|  | 7295 | ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, | 
|  | 7296 | ToFirstQualifierFoundInScope) = *Imp; | 
|  | 7297 |  | 
|  | 7298 | Expr *ToBase = nullptr; | 
|  | 7299 | if (!E->isImplicitAccess()) { | 
|  | 7300 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) | 
|  | 7301 | ToBase = *ToBaseOrErr; | 
|  | 7302 | else | 
|  | 7303 | return ToBaseOrErr.takeError(); | 
|  | 7304 | } | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7305 |  | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7306 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7307 | if (E->hasExplicitTemplateArgs()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7308 | if (Error Err = ImportTemplateArgumentListInfo( | 
|  | 7309 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), | 
|  | 7310 | ToTAInfo)) | 
|  | 7311 | return std::move(Err); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7312 | ResInfo = &ToTAInfo; | 
|  | 7313 | } | 
|  | 7314 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7315 | auto ToMemberNameInfoOrErr = importSeq(E->getMember(), E->getMemberLoc()); | 
|  | 7316 | if (!ToMemberNameInfoOrErr) | 
|  | 7317 | return ToMemberNameInfoOrErr.takeError(); | 
|  | 7318 | DeclarationNameInfo ToMemberNameInfo( | 
|  | 7319 | std::get<0>(*ToMemberNameInfoOrErr), std::get<1>(*ToMemberNameInfoOrErr)); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7320 | // Import additional name location/type info. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7321 | if (Error Err = ImportDeclarationNameLoc( | 
|  | 7322 | E->getMemberNameInfo(), ToMemberNameInfo)) | 
|  | 7323 | return std::move(Err); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7324 |  | 
|  | 7325 | return CXXDependentScopeMemberExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7326 | Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc, | 
|  | 7327 | ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope, | 
|  | 7328 | ToMemberNameInfo, ResInfo); | 
| Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 7329 | } | 
|  | 7330 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7331 | ExpectedStmt | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7332 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7333 | auto Imp = importSeq( | 
|  | 7334 | E->getQualifierLoc(), E->getTemplateKeywordLoc(), E->getDeclName(), | 
|  | 7335 | E->getExprLoc(), E->getLAngleLoc(), E->getRAngleLoc()); | 
|  | 7336 | if (!Imp) | 
|  | 7337 | return Imp.takeError(); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7338 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7339 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 7340 | SourceLocation ToTemplateKeywordLoc, ToExprLoc, ToLAngleLoc, ToRAngleLoc; | 
|  | 7341 | DeclarationName ToDeclName; | 
|  | 7342 | std::tie( | 
|  | 7343 | ToQualifierLoc, ToTemplateKeywordLoc, ToDeclName, ToExprLoc, | 
|  | 7344 | ToLAngleLoc, ToRAngleLoc) = *Imp; | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7345 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7346 | DeclarationNameInfo ToNameInfo(ToDeclName, ToExprLoc); | 
|  | 7347 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | 
|  | 7348 | return std::move(Err); | 
|  | 7349 |  | 
|  | 7350 | TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7351 | TemplateArgumentListInfo *ResInfo = nullptr; | 
|  | 7352 | if (E->hasExplicitTemplateArgs()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7353 | if (Error Err = | 
|  | 7354 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) | 
|  | 7355 | return std::move(Err); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7356 | ResInfo = &ToTAInfo; | 
|  | 7357 | } | 
|  | 7358 |  | 
|  | 7359 | return DependentScopeDeclRefExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7360 | Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, | 
|  | 7361 | ToNameInfo, ResInfo); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7362 | } | 
|  | 7363 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7364 | ExpectedStmt ASTNodeImporter::VisitCXXUnresolvedConstructExpr( | 
|  | 7365 | CXXUnresolvedConstructExpr *E) { | 
|  | 7366 | auto Imp = importSeq( | 
|  | 7367 | E->getLParenLoc(), E->getRParenLoc(), E->getTypeSourceInfo()); | 
|  | 7368 | if (!Imp) | 
|  | 7369 | return Imp.takeError(); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7370 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7371 | SourceLocation ToLParenLoc, ToRParenLoc; | 
|  | 7372 | TypeSourceInfo *ToTypeSourceInfo; | 
|  | 7373 | std::tie(ToLParenLoc, ToRParenLoc, ToTypeSourceInfo) = *Imp; | 
|  | 7374 |  | 
|  | 7375 | SmallVector<Expr *, 8> ToArgs(E->arg_size()); | 
|  | 7376 | if (Error Err = | 
|  | 7377 | ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin())) | 
|  | 7378 | return std::move(Err); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7379 |  | 
|  | 7380 | return CXXUnresolvedConstructExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7381 | Importer.getToContext(), ToTypeSourceInfo, ToLParenLoc, | 
|  | 7382 | llvm::makeArrayRef(ToArgs), ToRParenLoc); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7383 | } | 
|  | 7384 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7385 | ExpectedStmt | 
|  | 7386 | ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { | 
|  | 7387 | Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass()); | 
|  | 7388 | if (!ToNamingClassOrErr) | 
|  | 7389 | return ToNamingClassOrErr.takeError(); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7390 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7391 | auto ToQualifierLocOrErr = import(E->getQualifierLoc()); | 
|  | 7392 | if (!ToQualifierLocOrErr) | 
|  | 7393 | return ToQualifierLocOrErr.takeError(); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7394 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7395 | auto ToNameInfoOrErr = importSeq(E->getName(), E->getNameLoc()); | 
|  | 7396 | if (!ToNameInfoOrErr) | 
|  | 7397 | return ToNameInfoOrErr.takeError(); | 
|  | 7398 | DeclarationNameInfo ToNameInfo( | 
|  | 7399 | std::get<0>(*ToNameInfoOrErr), std::get<1>(*ToNameInfoOrErr)); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7400 | // Import additional name location/type info. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7401 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | 
|  | 7402 | return std::move(Err); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7403 |  | 
|  | 7404 | UnresolvedSet<8> ToDecls; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7405 | for (auto *D : E->decls()) | 
|  | 7406 | if (auto ToDOrErr = import(D)) | 
|  | 7407 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7408 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7409 | return ToDOrErr.takeError(); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7410 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7411 | if (E->hasExplicitTemplateArgs() && E->getTemplateKeywordLoc().isValid()) { | 
|  | 7412 | TemplateArgumentListInfo ToTAInfo; | 
|  | 7413 | if (Error Err = ImportTemplateArgumentListInfo( | 
|  | 7414 | E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(), | 
|  | 7415 | ToTAInfo)) | 
|  | 7416 | return std::move(Err); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7417 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7418 | ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc()); | 
|  | 7419 | if (!ToTemplateKeywordLocOrErr) | 
|  | 7420 | return ToTemplateKeywordLocOrErr.takeError(); | 
|  | 7421 |  | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7422 | return UnresolvedLookupExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7423 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, | 
|  | 7424 | *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo, | 
|  | 7425 | ToDecls.begin(), ToDecls.end()); | 
|  | 7426 | } | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7427 |  | 
|  | 7428 | return UnresolvedLookupExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7429 | Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr, | 
|  | 7430 | ToNameInfo, E->requiresADL(), E->isOverloaded(), ToDecls.begin(), | 
|  | 7431 | ToDecls.end()); | 
| Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 7432 | } | 
|  | 7433 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7434 | ExpectedStmt | 
|  | 7435 | ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { | 
|  | 7436 | auto Imp1 = importSeq( | 
|  | 7437 | E->getType(), E->getOperatorLoc(), E->getQualifierLoc(), | 
|  | 7438 | E->getTemplateKeywordLoc()); | 
|  | 7439 | if (!Imp1) | 
|  | 7440 | return Imp1.takeError(); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7441 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7442 | QualType ToType; | 
|  | 7443 | SourceLocation ToOperatorLoc, ToTemplateKeywordLoc; | 
|  | 7444 | NestedNameSpecifierLoc ToQualifierLoc; | 
|  | 7445 | std::tie(ToType, ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc) = *Imp1; | 
|  | 7446 |  | 
|  | 7447 | auto Imp2 = importSeq(E->getName(), E->getNameLoc()); | 
|  | 7448 | if (!Imp2) | 
|  | 7449 | return Imp2.takeError(); | 
|  | 7450 | DeclarationNameInfo ToNameInfo(std::get<0>(*Imp2), std::get<1>(*Imp2)); | 
|  | 7451 | // Import additional name location/type info. | 
|  | 7452 | if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo)) | 
|  | 7453 | return std::move(Err); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7454 |  | 
|  | 7455 | UnresolvedSet<8> ToDecls; | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7456 | for (Decl *D : E->decls()) | 
|  | 7457 | if (auto ToDOrErr = import(D)) | 
|  | 7458 | ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr)); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7459 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7460 | return ToDOrErr.takeError(); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7461 |  | 
|  | 7462 | TemplateArgumentListInfo ToTAInfo; | 
|  | 7463 | TemplateArgumentListInfo *ResInfo = nullptr; | 
|  | 7464 | if (E->hasExplicitTemplateArgs()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7465 | if (Error Err = | 
|  | 7466 | ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) | 
|  | 7467 | return std::move(Err); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7468 | ResInfo = &ToTAInfo; | 
|  | 7469 | } | 
|  | 7470 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7471 | Expr *ToBase = nullptr; | 
|  | 7472 | if (!E->isImplicitAccess()) { | 
|  | 7473 | if (ExpectedExpr ToBaseOrErr = import(E->getBase())) | 
|  | 7474 | ToBase = *ToBaseOrErr; | 
|  | 7475 | else | 
|  | 7476 | return ToBaseOrErr.takeError(); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7477 | } | 
|  | 7478 |  | 
|  | 7479 | return UnresolvedMemberExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7480 | Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType, | 
|  | 7481 | E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc, | 
|  | 7482 | ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end()); | 
| Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 7483 | } | 
|  | 7484 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7485 | ExpectedStmt ASTNodeImporter::VisitCallExpr(CallExpr *E) { | 
|  | 7486 | auto Imp = importSeq(E->getCallee(), E->getType(), E->getRParenLoc()); | 
|  | 7487 | if (!Imp) | 
|  | 7488 | return Imp.takeError(); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7489 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7490 | Expr *ToCallee; | 
|  | 7491 | QualType ToType; | 
|  | 7492 | SourceLocation ToRParenLoc; | 
|  | 7493 | std::tie(ToCallee, ToType, ToRParenLoc) = *Imp; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7494 |  | 
|  | 7495 | unsigned NumArgs = E->getNumArgs(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7496 | llvm::SmallVector<Expr *, 2> ToArgs(NumArgs); | 
|  | 7497 | if (Error Err = ImportContainerChecked(E->arguments(), ToArgs)) | 
|  | 7498 | return std::move(Err); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7499 |  | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7500 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { | 
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7501 | return CXXOperatorCallExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7502 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType, | 
| Eric Fiselier | 5cdc2cd | 2018-12-12 21:50:55 +0000 | [diff] [blame] | 7503 | OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(), | 
|  | 7504 | OCE->getADLCallKind()); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7505 | } | 
|  | 7506 |  | 
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 7507 | return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType, | 
|  | 7508 | E->getValueKind(), ToRParenLoc, /*MinNumArgs=*/0, | 
|  | 7509 | E->getADLCallKind()); | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7510 | } | 
|  | 7511 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7512 | ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { | 
|  | 7513 | CXXRecordDecl *FromClass = E->getLambdaClass(); | 
|  | 7514 | auto ToClassOrErr = import(FromClass); | 
|  | 7515 | if (!ToClassOrErr) | 
|  | 7516 | return ToClassOrErr.takeError(); | 
|  | 7517 | CXXRecordDecl *ToClass = *ToClassOrErr; | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7518 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7519 | auto ToCallOpOrErr = import(E->getCallOperator()); | 
|  | 7520 | if (!ToCallOpOrErr) | 
|  | 7521 | return ToCallOpOrErr.takeError(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7522 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7523 | SmallVector<LambdaCapture, 8> ToCaptures; | 
|  | 7524 | ToCaptures.reserve(E->capture_size()); | 
|  | 7525 | for (const auto &FromCapture : E->captures()) { | 
|  | 7526 | if (auto ToCaptureOrErr = import(FromCapture)) | 
|  | 7527 | ToCaptures.push_back(*ToCaptureOrErr); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7528 | else | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7529 | return ToCaptureOrErr.takeError(); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7530 | } | 
|  | 7531 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7532 | SmallVector<Expr *, 8> ToCaptureInits(E->capture_size()); | 
|  | 7533 | if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits)) | 
|  | 7534 | return std::move(Err); | 
|  | 7535 |  | 
|  | 7536 | auto Imp = importSeq( | 
|  | 7537 | E->getIntroducerRange(), E->getCaptureDefaultLoc(), E->getEndLoc()); | 
|  | 7538 | if (!Imp) | 
|  | 7539 | return Imp.takeError(); | 
|  | 7540 |  | 
|  | 7541 | SourceRange ToIntroducerRange; | 
|  | 7542 | SourceLocation ToCaptureDefaultLoc, ToEndLoc; | 
|  | 7543 | std::tie(ToIntroducerRange, ToCaptureDefaultLoc, ToEndLoc) = *Imp; | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7544 |  | 
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7545 | return LambdaExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7546 | Importer.getToContext(), ToClass, ToIntroducerRange, | 
|  | 7547 | E->getCaptureDefault(), ToCaptureDefaultLoc, ToCaptures, | 
|  | 7548 | E->hasExplicitParameters(), E->hasExplicitResultType(), ToCaptureInits, | 
|  | 7549 | ToEndLoc, E->containsUnexpandedParameterPack()); | 
| Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 7550 | } | 
|  | 7551 |  | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7552 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7553 | ExpectedStmt ASTNodeImporter::VisitInitListExpr(InitListExpr *E) { | 
|  | 7554 | auto Imp = importSeq(E->getLBraceLoc(), E->getRBraceLoc(), E->getType()); | 
|  | 7555 | if (!Imp) | 
|  | 7556 | return Imp.takeError(); | 
|  | 7557 |  | 
|  | 7558 | SourceLocation ToLBraceLoc, ToRBraceLoc; | 
|  | 7559 | QualType ToType; | 
|  | 7560 | std::tie(ToLBraceLoc, ToRBraceLoc, ToType) = *Imp; | 
|  | 7561 |  | 
|  | 7562 | SmallVector<Expr *, 4> ToExprs(E->getNumInits()); | 
|  | 7563 | if (Error Err = ImportContainerChecked(E->inits(), ToExprs)) | 
|  | 7564 | return std::move(Err); | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7565 |  | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7566 | ASTContext &ToCtx = Importer.getToContext(); | 
|  | 7567 | InitListExpr *To = new (ToCtx) InitListExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7568 | ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc); | 
|  | 7569 | To->setType(ToType); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7570 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7571 | if (E->hasArrayFiller()) { | 
|  | 7572 | if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller())) | 
|  | 7573 | To->setArrayFiller(*ToFillerOrErr); | 
|  | 7574 | else | 
|  | 7575 | return ToFillerOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7576 | } | 
|  | 7577 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7578 | if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) { | 
|  | 7579 | if (auto ToFDOrErr = import(FromFD)) | 
|  | 7580 | To->setInitializedFieldInUnion(*ToFDOrErr); | 
|  | 7581 | else | 
|  | 7582 | return ToFDOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7583 | } | 
|  | 7584 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7585 | if (InitListExpr *SyntForm = E->getSyntacticForm()) { | 
|  | 7586 | if (auto ToSyntFormOrErr = import(SyntForm)) | 
|  | 7587 | To->setSyntacticForm(*ToSyntFormOrErr); | 
|  | 7588 | else | 
|  | 7589 | return ToSyntFormOrErr.takeError(); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7590 | } | 
|  | 7591 |  | 
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 7592 | // Copy InitListExprBitfields, which are not handled in the ctor of | 
|  | 7593 | // InitListExpr. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7594 | To->sawArrayRangeDesignator(E->hadArrayRangeDesignator()); | 
| Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 7595 |  | 
|  | 7596 | return To; | 
| Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7597 | } | 
|  | 7598 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7599 | ExpectedStmt ASTNodeImporter::VisitCXXStdInitializerListExpr( | 
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7600 | CXXStdInitializerListExpr *E) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7601 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 7602 | if (!ToTypeOrErr) | 
|  | 7603 | return ToTypeOrErr.takeError(); | 
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7604 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7605 | ExpectedExpr ToSubExprOrErr = import(E->getSubExpr()); | 
|  | 7606 | if (!ToSubExprOrErr) | 
|  | 7607 | return ToSubExprOrErr.takeError(); | 
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7608 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7609 | return new (Importer.getToContext()) CXXStdInitializerListExpr( | 
|  | 7610 | *ToTypeOrErr, *ToSubExprOrErr); | 
| Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 7611 | } | 
|  | 7612 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7613 | ExpectedStmt ASTNodeImporter::VisitCXXInheritedCtorInitExpr( | 
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7614 | CXXInheritedCtorInitExpr *E) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7615 | auto Imp = importSeq(E->getLocation(), E->getType(), E->getConstructor()); | 
|  | 7616 | if (!Imp) | 
|  | 7617 | return Imp.takeError(); | 
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7618 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7619 | SourceLocation ToLocation; | 
|  | 7620 | QualType ToType; | 
|  | 7621 | CXXConstructorDecl *ToConstructor; | 
|  | 7622 | std::tie(ToLocation, ToType, ToConstructor) = *Imp; | 
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7623 |  | 
|  | 7624 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7625 | ToLocation, ToType, ToConstructor, E->constructsVBase(), | 
|  | 7626 | E->inheritedFromVBase()); | 
| Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 7627 | } | 
|  | 7628 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7629 | ExpectedStmt ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { | 
|  | 7630 | auto Imp = importSeq(E->getType(), E->getCommonExpr(), E->getSubExpr()); | 
|  | 7631 | if (!Imp) | 
|  | 7632 | return Imp.takeError(); | 
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7633 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7634 | QualType ToType; | 
|  | 7635 | Expr *ToCommonExpr, *ToSubExpr; | 
|  | 7636 | std::tie(ToType, ToCommonExpr, ToSubExpr) = *Imp; | 
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7637 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7638 | return new (Importer.getToContext()) ArrayInitLoopExpr( | 
|  | 7639 | ToType, ToCommonExpr, ToSubExpr); | 
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7640 | } | 
|  | 7641 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7642 | ExpectedStmt ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { | 
|  | 7643 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 7644 | if (!ToTypeOrErr) | 
|  | 7645 | return ToTypeOrErr.takeError(); | 
|  | 7646 | return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr); | 
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 7647 | } | 
|  | 7648 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7649 | ExpectedStmt ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) { | 
|  | 7650 | ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc()); | 
|  | 7651 | if (!ToBeginLocOrErr) | 
|  | 7652 | return ToBeginLocOrErr.takeError(); | 
|  | 7653 |  | 
|  | 7654 | auto ToFieldOrErr = import(E->getField()); | 
|  | 7655 | if (!ToFieldOrErr) | 
|  | 7656 | return ToFieldOrErr.takeError(); | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7657 |  | 
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7658 | auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext()); | 
|  | 7659 | if (!UsedContextOrErr) | 
|  | 7660 | return UsedContextOrErr.takeError(); | 
|  | 7661 |  | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7662 | return CXXDefaultInitExpr::Create( | 
| Eric Fiselier | 708afb5 | 2019-05-16 21:04:15 +0000 | [diff] [blame] | 7663 | Importer.getToContext(), *ToBeginLocOrErr, *ToFieldOrErr, *UsedContextOrErr); | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7664 | } | 
|  | 7665 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7666 | ExpectedStmt ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { | 
|  | 7667 | auto Imp = importSeq( | 
|  | 7668 | E->getType(), E->getSubExpr(), E->getTypeInfoAsWritten(), | 
|  | 7669 | E->getOperatorLoc(), E->getRParenLoc(), E->getAngleBrackets()); | 
|  | 7670 | if (!Imp) | 
|  | 7671 | return Imp.takeError(); | 
|  | 7672 |  | 
|  | 7673 | QualType ToType; | 
|  | 7674 | Expr *ToSubExpr; | 
|  | 7675 | TypeSourceInfo *ToTypeInfoAsWritten; | 
|  | 7676 | SourceLocation ToOperatorLoc, ToRParenLoc; | 
|  | 7677 | SourceRange ToAngleBrackets; | 
|  | 7678 | std::tie( | 
|  | 7679 | ToType, ToSubExpr, ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, | 
|  | 7680 | ToAngleBrackets) = *Imp; | 
|  | 7681 |  | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7682 | ExprValueKind VK = E->getValueKind(); | 
|  | 7683 | CastKind CK = E->getCastKind(); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7684 | auto ToBasePathOrErr = ImportCastPath(E); | 
|  | 7685 | if (!ToBasePathOrErr) | 
|  | 7686 | return ToBasePathOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7687 |  | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7688 | if (isa<CXXStaticCastExpr>(E)) { | 
|  | 7689 | return CXXStaticCastExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7690 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | 
|  | 7691 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7692 | } else if (isa<CXXDynamicCastExpr>(E)) { | 
|  | 7693 | return CXXDynamicCastExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7694 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | 
|  | 7695 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7696 | } else if (isa<CXXReinterpretCastExpr>(E)) { | 
|  | 7697 | return CXXReinterpretCastExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7698 | Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr), | 
|  | 7699 | ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | 
| Raphael Isemann | c705bb8 | 2018-08-20 16:20:01 +0000 | [diff] [blame] | 7700 | } else if (isa<CXXConstCastExpr>(E)) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7701 | return CXXConstCastExpr::Create( | 
|  | 7702 | Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten, | 
|  | 7703 | ToOperatorLoc, ToRParenLoc, ToAngleBrackets); | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7704 | } else { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7705 | llvm_unreachable("Unknown cast type"); | 
|  | 7706 | return make_error<ImportError>(); | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7707 | } | 
|  | 7708 | } | 
|  | 7709 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7710 | ExpectedStmt ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7711 | SubstNonTypeTemplateParmExpr *E) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7712 | auto Imp = importSeq( | 
|  | 7713 | E->getType(), E->getExprLoc(), E->getParameter(), E->getReplacement()); | 
|  | 7714 | if (!Imp) | 
|  | 7715 | return Imp.takeError(); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7716 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7717 | QualType ToType; | 
|  | 7718 | SourceLocation ToExprLoc; | 
|  | 7719 | NonTypeTemplateParmDecl *ToParameter; | 
|  | 7720 | Expr *ToReplacement; | 
|  | 7721 | std::tie(ToType, ToExprLoc, ToParameter, ToReplacement) = *Imp; | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7722 |  | 
|  | 7723 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7724 | ToType, E->getValueKind(), ToExprLoc, ToParameter, ToReplacement); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7725 | } | 
|  | 7726 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7727 | ExpectedStmt ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { | 
|  | 7728 | auto Imp = importSeq( | 
|  | 7729 | E->getType(), E->getBeginLoc(), E->getEndLoc()); | 
|  | 7730 | if (!Imp) | 
|  | 7731 | return Imp.takeError(); | 
|  | 7732 |  | 
|  | 7733 | QualType ToType; | 
|  | 7734 | SourceLocation ToBeginLoc, ToEndLoc; | 
|  | 7735 | std::tie(ToType, ToBeginLoc, ToEndLoc) = *Imp; | 
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7736 |  | 
|  | 7737 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7738 | if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs)) | 
|  | 7739 | return std::move(Err); | 
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7740 |  | 
|  | 7741 | // According to Sema::BuildTypeTrait(), if E is value-dependent, | 
|  | 7742 | // Value is always false. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7743 | bool ToValue = (E->isValueDependent() ? false : E->getValue()); | 
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7744 |  | 
|  | 7745 | return TypeTraitExpr::Create( | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7746 | Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs, | 
|  | 7747 | ToEndLoc, ToValue); | 
| Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 7748 | } | 
|  | 7749 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7750 | ExpectedStmt ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { | 
|  | 7751 | ExpectedType ToTypeOrErr = import(E->getType()); | 
|  | 7752 | if (!ToTypeOrErr) | 
|  | 7753 | return ToTypeOrErr.takeError(); | 
|  | 7754 |  | 
|  | 7755 | auto ToSourceRangeOrErr = import(E->getSourceRange()); | 
|  | 7756 | if (!ToSourceRangeOrErr) | 
|  | 7757 | return ToSourceRangeOrErr.takeError(); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7758 |  | 
|  | 7759 | if (E->isTypeOperand()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7760 | if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo())) | 
|  | 7761 | return new (Importer.getToContext()) CXXTypeidExpr( | 
|  | 7762 | *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr); | 
|  | 7763 | else | 
|  | 7764 | return ToTSIOrErr.takeError(); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7765 | } | 
|  | 7766 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7767 | ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand()); | 
|  | 7768 | if (!ToExprOperandOrErr) | 
|  | 7769 | return ToExprOperandOrErr.takeError(); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7770 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7771 | return new (Importer.getToContext()) CXXTypeidExpr( | 
|  | 7772 | *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr); | 
| Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 7773 | } | 
|  | 7774 |  | 
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7775 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, | 
|  | 7776 | CXXMethodDecl *FromMethod) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7777 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) { | 
|  | 7778 | if (auto ImportedOrErr = import(FromOverriddenMethod)) | 
|  | 7779 | ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>( | 
|  | 7780 | (*ImportedOrErr)->getCanonicalDecl())); | 
|  | 7781 | else | 
|  | 7782 | consumeError(ImportedOrErr.takeError()); | 
|  | 7783 | } | 
| Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 7784 | } | 
|  | 7785 |  | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7786 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, | 
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7787 | ASTContext &FromContext, FileManager &FromFileManager, | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7788 | bool MinimalImport, | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7789 | std::shared_ptr<ASTImporterSharedState> SharedState) | 
|  | 7790 | : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext), | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7791 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), | 
| Ilya Biryukov | abc744d | 2019-07-18 15:43:26 +0000 | [diff] [blame] | 7792 | Minimal(MinimalImport) { | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7793 |  | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7794 | // Create a default state without the lookup table: LLDB case. | 
|  | 7795 | if (!SharedState) { | 
|  | 7796 | this->SharedState = std::make_shared<ASTImporterSharedState>(); | 
|  | 7797 | } | 
|  | 7798 |  | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7799 | ImportedDecls[FromContext.getTranslationUnitDecl()] = | 
|  | 7800 | ToContext.getTranslationUnitDecl(); | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7801 | } | 
|  | 7802 |  | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7803 | ASTImporter::~ASTImporter() = default; | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7804 |  | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7805 | Optional<unsigned> ASTImporter::getFieldIndex(Decl *F) { | 
|  | 7806 | assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) && | 
|  | 7807 | "Try to get field index for non-field."); | 
|  | 7808 |  | 
|  | 7809 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); | 
|  | 7810 | if (!Owner) | 
|  | 7811 | return None; | 
|  | 7812 |  | 
|  | 7813 | unsigned Index = 0; | 
|  | 7814 | for (const auto *D : Owner->decls()) { | 
|  | 7815 | if (D == F) | 
|  | 7816 | return Index; | 
|  | 7817 |  | 
|  | 7818 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) | 
|  | 7819 | ++Index; | 
|  | 7820 | } | 
|  | 7821 |  | 
|  | 7822 | llvm_unreachable("Field was not found in its parent context."); | 
|  | 7823 |  | 
|  | 7824 | return None; | 
|  | 7825 | } | 
|  | 7826 |  | 
|  | 7827 | ASTImporter::FoundDeclsTy | 
|  | 7828 | ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) { | 
|  | 7829 | // We search in the redecl context because of transparent contexts. | 
|  | 7830 | // E.g. a simple C language enum is a transparent context: | 
|  | 7831 | //   enum E { A, B }; | 
|  | 7832 | // Now if we had a global variable in the TU | 
|  | 7833 | //   int A; | 
|  | 7834 | // then the enum constant 'A' and the variable 'A' violates ODR. | 
|  | 7835 | // We can diagnose this only if we search in the redecl context. | 
|  | 7836 | DeclContext *ReDC = DC->getRedeclContext(); | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7837 | if (SharedState->getLookupTable()) { | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7838 | ASTImporterLookupTable::LookupResult LookupResult = | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7839 | SharedState->getLookupTable()->lookup(ReDC, Name); | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7840 | return FoundDeclsTy(LookupResult.begin(), LookupResult.end()); | 
|  | 7841 | } else { | 
| Gabor Marton | aefcf51 | 2019-07-17 13:47:46 +0000 | [diff] [blame] | 7842 | DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name); | 
|  | 7843 | FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end()); | 
|  | 7844 | // We must search by the slow case of localUncachedLookup because that is | 
|  | 7845 | // working even if there is no LookupPtr for the DC. We could use | 
|  | 7846 | // DC::buildLookup() to create the LookupPtr, but that would load external | 
|  | 7847 | // decls again, we must avoid that case. | 
|  | 7848 | // Also, even if we had the LookupPtr, we must find Decls which are not | 
|  | 7849 | // in the LookupPtr, so we need the slow case. | 
|  | 7850 | // These cases are handled in ASTImporterLookupTable, but we cannot use | 
|  | 7851 | // that with LLDB since that traverses through the AST which initiates the | 
|  | 7852 | // load of external decls again via DC::decls().  And again, we must avoid | 
|  | 7853 | // loading external decls during the import. | 
|  | 7854 | if (Result.empty()) | 
|  | 7855 | ReDC->localUncachedLookup(Name, Result); | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7856 | return Result; | 
|  | 7857 | } | 
|  | 7858 | } | 
|  | 7859 |  | 
|  | 7860 | void ASTImporter::AddToLookupTable(Decl *ToD) { | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7861 | SharedState->addDeclToLookup(ToD); | 
| Gabor Marton | 54058b5 | 2018-12-17 13:53:12 +0000 | [diff] [blame] | 7862 | } | 
|  | 7863 |  | 
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7864 | Expected<Decl *> ASTImporter::ImportImpl(Decl *FromD) { | 
|  | 7865 | // Import the decl using ASTNodeImporter. | 
|  | 7866 | ASTNodeImporter Importer(*this); | 
|  | 7867 | return Importer.Visit(FromD); | 
|  | 7868 | } | 
|  | 7869 |  | 
|  | 7870 | void ASTImporter::RegisterImportedDecl(Decl *FromD, Decl *ToD) { | 
|  | 7871 | MapImported(FromD, ToD); | 
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7872 | } | 
|  | 7873 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7874 | Expected<QualType> ASTImporter::Import(QualType FromT) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7875 | if (FromT.isNull()) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7876 | return QualType{}; | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7877 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7878 | const Type *FromTy = FromT.getTypePtr(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7879 |  | 
|  | 7880 | // Check whether we've already imported this type. | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7881 | llvm::DenseMap<const Type *, const Type *>::iterator Pos | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7882 | = ImportedTypes.find(FromTy); | 
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7883 | if (Pos != ImportedTypes.end()) | 
| John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7884 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7885 |  | 
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7886 | // Import the type | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7887 | ASTNodeImporter Importer(*this); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7888 | ExpectedType ToTOrErr = Importer.Visit(FromTy); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7889 | if (!ToTOrErr) | 
|  | 7890 | return ToTOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7891 |  | 
| Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 7892 | // Record the imported type. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7893 | ImportedTypes[FromTy] = (*ToTOrErr).getTypePtr(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7894 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 7895 | return ToContext.getQualifiedType(*ToTOrErr, FromT.getLocalQualifiers()); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7896 | } | 
|  | 7897 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7898 | Expected<TypeSourceInfo *> ASTImporter::Import(TypeSourceInfo *FromTSI) { | 
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7899 | if (!FromTSI) | 
|  | 7900 | return FromTSI; | 
|  | 7901 |  | 
|  | 7902 | // FIXME: For now we just create a "trivial" type source info based | 
| Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 7903 | // on the type and a single location. Implement a real version of this. | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7904 | ExpectedType TOrErr = Import(FromTSI->getType()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7905 | if (!TOrErr) | 
|  | 7906 | return TOrErr.takeError(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7907 | ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7908 | if (!BeginLocOrErr) | 
|  | 7909 | return BeginLocOrErr.takeError(); | 
| Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 7910 |  | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7911 | return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr); | 
|  | 7912 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7913 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7914 | Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) { | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7915 | Attr *ToAttr = FromAttr->clone(ToContext); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7916 | if (auto ToRangeOrErr = Import(FromAttr->getRange())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7917 | ToAttr->setRange(*ToRangeOrErr); | 
|  | 7918 | else | 
|  | 7919 | return ToRangeOrErr.takeError(); | 
|  | 7920 |  | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 7921 | return ToAttr; | 
| Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 7922 | } | 
| Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 7923 |  | 
| Gabor Marton | be77a98 | 2018-12-12 11:22:55 +0000 | [diff] [blame] | 7924 | Decl *ASTImporter::GetAlreadyImportedOrNull(const Decl *FromD) const { | 
|  | 7925 | auto Pos = ImportedDecls.find(FromD); | 
|  | 7926 | if (Pos != ImportedDecls.end()) | 
|  | 7927 | return Pos->second; | 
|  | 7928 | else | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7929 | return nullptr; | 
| Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7930 | } | 
|  | 7931 |  | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 7932 | TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) { | 
|  | 7933 | auto FromDPos = ImportedFromDecls.find(ToD); | 
|  | 7934 | if (FromDPos == ImportedFromDecls.end()) | 
|  | 7935 | return nullptr; | 
|  | 7936 | return FromDPos->second->getTranslationUnitDecl(); | 
|  | 7937 | } | 
|  | 7938 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 7939 | Expected<Decl *> ASTImporter::Import(Decl *FromD) { | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7940 | if (!FromD) | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7941 | return nullptr; | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7942 |  | 
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 7943 | // Push FromD to the stack, and remove that when we return. | 
|  | 7944 | ImportPath.push(FromD); | 
|  | 7945 | auto ImportPathBuilder = | 
|  | 7946 | llvm::make_scope_exit([this]() { ImportPath.pop(); }); | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7947 |  | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 7948 | // Check whether there was a previous failed import. | 
|  | 7949 | // If yes return the existing error. | 
|  | 7950 | if (auto Error = getImportDeclErrorIfAny(FromD)) | 
|  | 7951 | return make_error<ImportError>(*Error); | 
|  | 7952 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7953 | // Check whether we've already imported this declaration. | 
|  | 7954 | Decl *ToD = GetAlreadyImportedOrNull(FromD); | 
|  | 7955 | if (ToD) { | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7956 | // Already imported (possibly from another TU) and with an error. | 
|  | 7957 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { | 
|  | 7958 | setImportDeclError(FromD, *Error); | 
|  | 7959 | return make_error<ImportError>(*Error); | 
|  | 7960 | } | 
|  | 7961 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7962 | // If FromD has some updated flags after last import, apply it | 
|  | 7963 | updateFlags(FromD, ToD); | 
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 7964 | // If we encounter a cycle during an import then we save the relevant part | 
|  | 7965 | // of the import path associated to the Decl. | 
|  | 7966 | if (ImportPath.hasCycleAtBack()) | 
|  | 7967 | SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack()); | 
| Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7968 | return ToD; | 
|  | 7969 | } | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7970 |  | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 7971 | // Import the declaration. | 
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 7972 | ExpectedDecl ToDOrErr = ImportImpl(FromD); | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 7973 | if (!ToDOrErr) { | 
|  | 7974 | // Failed to import. | 
|  | 7975 |  | 
|  | 7976 | auto Pos = ImportedDecls.find(FromD); | 
|  | 7977 | if (Pos != ImportedDecls.end()) { | 
|  | 7978 | // Import failed after the object was created. | 
|  | 7979 | // Remove all references to it. | 
|  | 7980 | auto *ToD = Pos->second; | 
|  | 7981 | ImportedDecls.erase(Pos); | 
|  | 7982 |  | 
|  | 7983 | // ImportedDecls and ImportedFromDecls are not symmetric.  It may happen | 
|  | 7984 | // (e.g. with namespaces) that several decls from the 'from' context are | 
|  | 7985 | // mapped to the same decl in the 'to' context.  If we removed entries | 
|  | 7986 | // from the LookupTable here then we may end up removing them multiple | 
|  | 7987 | // times. | 
|  | 7988 |  | 
|  | 7989 | // The Lookuptable contains decls only which are in the 'to' context. | 
|  | 7990 | // Remove from the Lookuptable only if it is *imported* into the 'to' | 
|  | 7991 | // context (and do not remove it if it was added during the initial | 
|  | 7992 | // traverse of the 'to' context). | 
|  | 7993 | auto PosF = ImportedFromDecls.find(ToD); | 
|  | 7994 | if (PosF != ImportedFromDecls.end()) { | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 7995 | SharedState->removeDeclFromLookup(ToD); | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 7996 | ImportedFromDecls.erase(PosF); | 
|  | 7997 | } | 
|  | 7998 |  | 
|  | 7999 | // FIXME: AST may contain remaining references to the failed object. | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8000 | // However, the ImportDeclErrors in the shared state contains all the | 
|  | 8001 | // failed objects together with their error. | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8002 | } | 
|  | 8003 |  | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8004 | // Error encountered for the first time. | 
|  | 8005 | // After takeError the error is not usable any more in ToDOrErr. | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8006 | // Get a copy of the error object (any more simple solution for this?). | 
|  | 8007 | ImportError ErrOut; | 
|  | 8008 | handleAllErrors(ToDOrErr.takeError(), | 
|  | 8009 | [&ErrOut](const ImportError &E) { ErrOut = E; }); | 
|  | 8010 | setImportDeclError(FromD, ErrOut); | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8011 | // Set the error for the mapped to Decl, which is in the "to" context. | 
|  | 8012 | if (Pos != ImportedDecls.end()) | 
|  | 8013 | SharedState->setImportDeclError(Pos->second, ErrOut); | 
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8014 |  | 
|  | 8015 | // Set the error for all nodes which have been created before we | 
|  | 8016 | // recognized the error. | 
|  | 8017 | for (const auto &Path : SavedImportPaths[FromD]) | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8018 | for (Decl *FromDi : Path) { | 
|  | 8019 | setImportDeclError(FromDi, ErrOut); | 
|  | 8020 | //FIXME Should we remove these Decls from ImportedDecls? | 
|  | 8021 | // Set the error for the mapped to Decl, which is in the "to" context. | 
|  | 8022 | auto Ii = ImportedDecls.find(FromDi); | 
|  | 8023 | if (Ii != ImportedDecls.end()) | 
|  | 8024 | SharedState->setImportDeclError(Ii->second, ErrOut); | 
|  | 8025 | // FIXME Should we remove these Decls from the LookupTable, | 
|  | 8026 | // and from ImportedFromDecls? | 
|  | 8027 | } | 
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8028 | SavedImportPaths[FromD].clear(); | 
|  | 8029 |  | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8030 | // Do not return ToDOrErr, error was taken out of it. | 
|  | 8031 | return make_error<ImportError>(ErrOut); | 
|  | 8032 | } | 
|  | 8033 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8034 | ToD = *ToDOrErr; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8035 |  | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8036 | // FIXME: Handle the "already imported with error" case. We can get here | 
|  | 8037 | // nullptr only if GetImportedOrCreateDecl returned nullptr (after a | 
|  | 8038 | // previously failed create was requested). | 
|  | 8039 | // Later GetImportedOrCreateDecl can be updated to return the error. | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 8040 | if (!ToD) { | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8041 | auto Err = getImportDeclErrorIfAny(FromD); | 
|  | 8042 | assert(Err); | 
|  | 8043 | return make_error<ImportError>(*Err); | 
| Gabor Marton | 7f8c400 | 2019-03-19 13:34:10 +0000 | [diff] [blame] | 8044 | } | 
|  | 8045 |  | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8046 | // We could import from the current TU without error.  But previously we | 
|  | 8047 | // already had imported a Decl as `ToD` from another TU (with another | 
|  | 8048 | // ASTImporter object) and with an error. | 
|  | 8049 | if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) { | 
|  | 8050 | setImportDeclError(FromD, *Error); | 
|  | 8051 | return make_error<ImportError>(*Error); | 
|  | 8052 | } | 
|  | 8053 |  | 
| Raphael Isemann | e9bc35f | 2019-04-29 21:02:35 +0000 | [diff] [blame] | 8054 | // Make sure that ImportImpl registered the imported decl. | 
|  | 8055 | assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?"); | 
| Gabor Marton | 2afbfb6 | 2019-07-01 15:37:07 +0000 | [diff] [blame] | 8056 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8057 | // Notify subclasses. | 
|  | 8058 | Imported(FromD, ToD); | 
|  | 8059 |  | 
| Gabor Marton | ac3a5d6 | 2018-09-17 12:04:52 +0000 | [diff] [blame] | 8060 | updateFlags(FromD, ToD); | 
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8061 | SavedImportPaths[FromD].clear(); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8062 | return ToDOrErr; | 
|  | 8063 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8064 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8065 | Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) { | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8066 | if (!FromDC) | 
|  | 8067 | return FromDC; | 
|  | 8068 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8069 | ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC)); | 
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8070 | if (!ToDCOrErr) | 
|  | 8071 | return ToDCOrErr.takeError(); | 
|  | 8072 | auto *ToDC = cast<DeclContext>(*ToDCOrErr); | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8073 |  | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8074 | // 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] | 8075 | // need it to have a definition. | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8076 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { | 
|  | 8077 | auto *FromRecord = cast<RecordDecl>(FromDC); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8078 | if (ToRecord->isCompleteDefinition()) { | 
|  | 8079 | // Do nothing. | 
|  | 8080 | } else if (FromRecord->isCompleteDefinition()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8081 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | 
|  | 8082 | FromRecord, ToRecord, ASTNodeImporter::IDK_Basic)) | 
|  | 8083 | return std::move(Err); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8084 | } else { | 
|  | 8085 | CompleteDecl(ToRecord); | 
|  | 8086 | } | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8087 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { | 
|  | 8088 | auto *FromEnum = cast<EnumDecl>(FromDC); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8089 | if (ToEnum->isCompleteDefinition()) { | 
|  | 8090 | // Do nothing. | 
|  | 8091 | } else if (FromEnum->isCompleteDefinition()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8092 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | 
|  | 8093 | FromEnum, ToEnum, ASTNodeImporter::IDK_Basic)) | 
|  | 8094 | return std::move(Err); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8095 | } else { | 
|  | 8096 | CompleteDecl(ToEnum); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8097 | } | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8098 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { | 
|  | 8099 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8100 | if (ToClass->getDefinition()) { | 
|  | 8101 | // Do nothing. | 
|  | 8102 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8103 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | 
|  | 8104 | FromDef, ToClass, ASTNodeImporter::IDK_Basic)) | 
|  | 8105 | return std::move(Err); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8106 | } else { | 
|  | 8107 | CompleteDecl(ToClass); | 
|  | 8108 | } | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8109 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { | 
|  | 8110 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8111 | if (ToProto->getDefinition()) { | 
|  | 8112 | // Do nothing. | 
|  | 8113 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8114 | if (Error Err = ASTNodeImporter(*this).ImportDefinition( | 
|  | 8115 | FromDef, ToProto, ASTNodeImporter::IDK_Basic)) | 
|  | 8116 | return std::move(Err); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8117 | } else { | 
|  | 8118 | CompleteDecl(ToProto); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8119 | } | 
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 8120 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8121 |  | 
| Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 8122 | return ToDC; | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8123 | } | 
|  | 8124 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8125 | Expected<Expr *> ASTImporter::Import(Expr *FromE) { | 
|  | 8126 | if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE))) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8127 | return cast_or_null<Expr>(*ToSOrErr); | 
|  | 8128 | else | 
|  | 8129 | return ToSOrErr.takeError(); | 
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8130 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8131 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8132 | Expected<Stmt *> ASTImporter::Import(Stmt *FromS) { | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8133 | if (!FromS) | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8134 | return nullptr; | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8135 |  | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8136 | // Check whether we've already imported this statement. | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 8137 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); | 
|  | 8138 | if (Pos != ImportedStmts.end()) | 
|  | 8139 | return Pos->second; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8140 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8141 | // Import the statement. | 
| Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 8142 | ASTNodeImporter Importer(*this); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8143 | ExpectedStmt ToSOrErr = Importer.Visit(FromS); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8144 | if (!ToSOrErr) | 
|  | 8145 | return ToSOrErr; | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8146 |  | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8147 | if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) { | 
| Gabor Marton | a20ce60 | 2018-09-03 13:10:53 +0000 | [diff] [blame] | 8148 | auto *FromE = cast<Expr>(FromS); | 
|  | 8149 | // Copy ExprBitfields, which may not be handled in Expr subclasses | 
|  | 8150 | // constructors. | 
|  | 8151 | ToE->setValueKind(FromE->getValueKind()); | 
|  | 8152 | ToE->setObjectKind(FromE->getObjectKind()); | 
|  | 8153 | ToE->setTypeDependent(FromE->isTypeDependent()); | 
|  | 8154 | ToE->setValueDependent(FromE->isValueDependent()); | 
|  | 8155 | ToE->setInstantiationDependent(FromE->isInstantiationDependent()); | 
|  | 8156 | ToE->setContainsUnexpandedParameterPack( | 
|  | 8157 | FromE->containsUnexpandedParameterPack()); | 
|  | 8158 | } | 
|  | 8159 |  | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8160 | // Record the imported statement object. | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8161 | ImportedStmts[FromS] = *ToSOrErr; | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8162 | return ToSOrErr; | 
|  | 8163 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8164 |  | 
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8165 | Expected<NestedNameSpecifier *> | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8166 | ASTImporter::Import(NestedNameSpecifier *FromNNS) { | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8167 | if (!FromNNS) | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8168 | return nullptr; | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8169 |  | 
| Simon Pilgrim | 130df2c | 2019-07-15 13:00:43 +0000 | [diff] [blame] | 8170 | NestedNameSpecifier *Prefix = nullptr; | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8171 | if (Error Err = importInto(Prefix, FromNNS->getPrefix())) | 
|  | 8172 | return std::move(Err); | 
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8173 |  | 
|  | 8174 | switch (FromNNS->getKind()) { | 
|  | 8175 | case NestedNameSpecifier::Identifier: | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8176 | assert(FromNNS->getAsIdentifier() && "NNS should contain identifier."); | 
|  | 8177 | return NestedNameSpecifier::Create(ToContext, Prefix, | 
|  | 8178 | Import(FromNNS->getAsIdentifier())); | 
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8179 |  | 
|  | 8180 | case NestedNameSpecifier::Namespace: | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8181 | if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) { | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8182 | return NestedNameSpecifier::Create(ToContext, Prefix, | 
|  | 8183 | cast<NamespaceDecl>(*NSOrErr)); | 
|  | 8184 | } else | 
|  | 8185 | return NSOrErr.takeError(); | 
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8186 |  | 
|  | 8187 | case NestedNameSpecifier::NamespaceAlias: | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8188 | if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8189 | return NestedNameSpecifier::Create(ToContext, Prefix, | 
|  | 8190 | cast<NamespaceAliasDecl>(*NSADOrErr)); | 
|  | 8191 | else | 
|  | 8192 | return NSADOrErr.takeError(); | 
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8193 |  | 
|  | 8194 | case NestedNameSpecifier::Global: | 
|  | 8195 | return NestedNameSpecifier::GlobalSpecifier(ToContext); | 
|  | 8196 |  | 
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8197 | case NestedNameSpecifier::Super: | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8198 | if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8199 | return NestedNameSpecifier::SuperSpecifier(ToContext, | 
|  | 8200 | cast<CXXRecordDecl>(*RDOrErr)); | 
|  | 8201 | else | 
|  | 8202 | return RDOrErr.takeError(); | 
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8203 |  | 
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8204 | case NestedNameSpecifier::TypeSpec: | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8205 | case NestedNameSpecifier::TypeSpecWithTemplate: | 
|  | 8206 | if (Expected<QualType> TyOrErr = | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8207 | Import(QualType(FromNNS->getAsType(), 0u))) { | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8208 | bool TSTemplate = | 
|  | 8209 | FromNNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate; | 
|  | 8210 | return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate, | 
|  | 8211 | TyOrErr->getTypePtr()); | 
|  | 8212 | } else { | 
|  | 8213 | return TyOrErr.takeError(); | 
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8214 | } | 
| Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 8215 | } | 
|  | 8216 |  | 
|  | 8217 | llvm_unreachable("Invalid nested name specifier kind"); | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8218 | } | 
|  | 8219 |  | 
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8220 | Expected<NestedNameSpecifierLoc> | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8221 | ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8222 | // Copied from NestedNameSpecifier mostly. | 
|  | 8223 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; | 
|  | 8224 | NestedNameSpecifierLoc NNS = FromNNS; | 
|  | 8225 |  | 
|  | 8226 | // Push each of the nested-name-specifiers's onto a stack for | 
|  | 8227 | // serialization in reverse order. | 
|  | 8228 | while (NNS) { | 
|  | 8229 | NestedNames.push_back(NNS); | 
|  | 8230 | NNS = NNS.getPrefix(); | 
|  | 8231 | } | 
|  | 8232 |  | 
|  | 8233 | NestedNameSpecifierLocBuilder Builder; | 
|  | 8234 |  | 
|  | 8235 | while (!NestedNames.empty()) { | 
|  | 8236 | NNS = NestedNames.pop_back_val(); | 
| Simon Pilgrim | 4c146ab | 2019-05-18 11:33:27 +0000 | [diff] [blame] | 8237 | NestedNameSpecifier *Spec = nullptr; | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8238 | if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier())) | 
|  | 8239 | return std::move(Err); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8240 |  | 
|  | 8241 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8242 |  | 
|  | 8243 | SourceLocation ToLocalBeginLoc, ToLocalEndLoc; | 
|  | 8244 | if (Kind != NestedNameSpecifier::Super) { | 
|  | 8245 | if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc())) | 
|  | 8246 | return std::move(Err); | 
|  | 8247 |  | 
|  | 8248 | if (Kind != NestedNameSpecifier::Global) | 
|  | 8249 | if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc())) | 
|  | 8250 | return std::move(Err); | 
|  | 8251 | } | 
|  | 8252 |  | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8253 | switch (Kind) { | 
|  | 8254 | case NestedNameSpecifier::Identifier: | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8255 | Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc, | 
|  | 8256 | ToLocalEndLoc); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8257 | break; | 
|  | 8258 |  | 
|  | 8259 | case NestedNameSpecifier::Namespace: | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8260 | Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc, | 
|  | 8261 | ToLocalEndLoc); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8262 | break; | 
|  | 8263 |  | 
|  | 8264 | case NestedNameSpecifier::NamespaceAlias: | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8265 | Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(), | 
|  | 8266 | ToLocalBeginLoc, ToLocalEndLoc); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8267 | break; | 
|  | 8268 |  | 
|  | 8269 | case NestedNameSpecifier::TypeSpec: | 
|  | 8270 | case NestedNameSpecifier::TypeSpecWithTemplate: { | 
| Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8271 | SourceLocation ToTLoc; | 
|  | 8272 | if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc())) | 
|  | 8273 | return std::move(Err); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8274 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( | 
| Balazs Keri | 5f4fd8b | 2019-03-14 14:20:23 +0000 | [diff] [blame] | 8275 | QualType(Spec->getAsType(), 0), ToTLoc); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8276 | Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(), | 
|  | 8277 | ToLocalEndLoc); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8278 | break; | 
|  | 8279 | } | 
|  | 8280 |  | 
|  | 8281 | case NestedNameSpecifier::Global: | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8282 | Builder.MakeGlobal(getToContext(), ToLocalBeginLoc); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8283 | break; | 
|  | 8284 |  | 
|  | 8285 | case NestedNameSpecifier::Super: { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8286 | auto ToSourceRangeOrErr = Import(NNS.getSourceRange()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8287 | if (!ToSourceRangeOrErr) | 
|  | 8288 | return ToSourceRangeOrErr.takeError(); | 
|  | 8289 |  | 
|  | 8290 | Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(), | 
|  | 8291 | ToSourceRangeOrErr->getBegin(), | 
|  | 8292 | ToSourceRangeOrErr->getEnd()); | 
| Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 8293 | } | 
|  | 8294 | } | 
|  | 8295 | } | 
|  | 8296 |  | 
|  | 8297 | return Builder.getWithLocInContext(getToContext()); | 
| Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 8298 | } | 
|  | 8299 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8300 | Expected<TemplateName> ASTImporter::Import(TemplateName From) { | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8301 | switch (From.getKind()) { | 
|  | 8302 | case TemplateName::Template: | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8303 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8304 | return TemplateName(cast<TemplateDecl>(*ToTemplateOrErr)); | 
|  | 8305 | else | 
|  | 8306 | return ToTemplateOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8307 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8308 | case TemplateName::OverloadedTemplate: { | 
|  | 8309 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); | 
|  | 8310 | UnresolvedSet<2> ToTemplates; | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8311 | for (auto *I : *FromStorage) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8312 | if (auto ToOrErr = Import(I)) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8313 | ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr)); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8314 | else | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8315 | return ToOrErr.takeError(); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8316 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8317 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8318 | ToTemplates.end()); | 
|  | 8319 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8320 |  | 
| Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8321 | case TemplateName::AssumedTemplate: { | 
|  | 8322 | AssumedTemplateStorage *FromStorage = From.getAsAssumedTemplateName(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8323 | auto DeclNameOrErr = Import(FromStorage->getDeclName()); | 
| Richard Smith | b23c5e8 | 2019-05-09 03:31:27 +0000 | [diff] [blame] | 8324 | if (!DeclNameOrErr) | 
|  | 8325 | return DeclNameOrErr.takeError(); | 
|  | 8326 | return ToContext.getAssumedTemplateName(*DeclNameOrErr); | 
|  | 8327 | } | 
|  | 8328 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8329 | case TemplateName::QualifiedTemplate: { | 
|  | 8330 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8331 | auto QualifierOrErr = Import(QTN->getQualifier()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8332 | if (!QualifierOrErr) | 
|  | 8333 | return QualifierOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8334 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8335 | if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8336 | return ToContext.getQualifiedTemplateName( | 
|  | 8337 | *QualifierOrErr, QTN->hasTemplateKeyword(), | 
|  | 8338 | cast<TemplateDecl>(*ToTemplateOrErr)); | 
|  | 8339 | else | 
|  | 8340 | return ToTemplateOrErr.takeError(); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8341 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8342 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8343 | case TemplateName::DependentTemplate: { | 
|  | 8344 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8345 | auto QualifierOrErr = Import(DTN->getQualifier()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8346 | if (!QualifierOrErr) | 
|  | 8347 | return QualifierOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8348 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8349 | if (DTN->isIdentifier()) { | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8350 | return ToContext.getDependentTemplateName(*QualifierOrErr, | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8351 | Import(DTN->getIdentifier())); | 
|  | 8352 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8353 |  | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8354 | return ToContext.getDependentTemplateName(*QualifierOrErr, | 
|  | 8355 | DTN->getOperator()); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8356 | } | 
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8357 |  | 
|  | 8358 | case TemplateName::SubstTemplateTemplateParm: { | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8359 | SubstTemplateTemplateParmStorage *Subst = | 
|  | 8360 | From.getAsSubstTemplateTemplateParm(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8361 | ExpectedDecl ParamOrErr = Import(Subst->getParameter()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8362 | if (!ParamOrErr) | 
|  | 8363 | return ParamOrErr.takeError(); | 
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8364 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8365 | auto ReplacementOrErr = Import(Subst->getReplacement()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8366 | if (!ReplacementOrErr) | 
|  | 8367 | return ReplacementOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8368 |  | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8369 | return ToContext.getSubstTemplateTemplateParm( | 
|  | 8370 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ReplacementOrErr); | 
| John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 8371 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8372 |  | 
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8373 | case TemplateName::SubstTemplateTemplateParmPack: { | 
|  | 8374 | SubstTemplateTemplateParmPackStorage *SubstPack | 
|  | 8375 | = From.getAsSubstTemplateTemplateParmPack(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8376 | ExpectedDecl ParamOrErr = Import(SubstPack->getParameterPack()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8377 | if (!ParamOrErr) | 
|  | 8378 | return ParamOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8379 |  | 
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8380 | ASTNodeImporter Importer(*this); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8381 | auto ArgPackOrErr = | 
|  | 8382 | Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); | 
|  | 8383 | if (!ArgPackOrErr) | 
|  | 8384 | return ArgPackOrErr.takeError(); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8385 |  | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8386 | return ToContext.getSubstTemplateTemplateParmPack( | 
|  | 8387 | cast<TemplateTemplateParmDecl>(*ParamOrErr), *ArgPackOrErr); | 
| Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 8388 | } | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8389 | } | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8390 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8391 | llvm_unreachable("Invalid template name kind"); | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8392 | } | 
|  | 8393 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8394 | Expected<SourceLocation> ASTImporter::Import(SourceLocation FromLoc) { | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8395 | if (FromLoc.isInvalid()) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8396 | return SourceLocation{}; | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8397 |  | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8398 | SourceManager &FromSM = FromContext.getSourceManager(); | 
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8399 | bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc); | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8400 |  | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8401 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8402 | Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8403 | if (!ToFileIDOrErr) | 
|  | 8404 | return ToFileIDOrErr.takeError(); | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8405 | SourceManager &ToSM = ToContext.getSourceManager(); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8406 | return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second); | 
|  | 8407 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8408 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8409 | Expected<SourceRange> ASTImporter::Import(SourceRange FromRange) { | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8410 | SourceLocation ToBegin, ToEnd; | 
|  | 8411 | if (Error Err = importInto(ToBegin, FromRange.getBegin())) | 
|  | 8412 | return std::move(Err); | 
|  | 8413 | if (Error Err = importInto(ToEnd, FromRange.getEnd())) | 
|  | 8414 | return std::move(Err); | 
|  | 8415 |  | 
|  | 8416 | return SourceRange(ToBegin, ToEnd); | 
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8417 | } | 
| Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 8418 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8419 | Expected<FileID> ASTImporter::Import(FileID FromID, bool IsBuiltin) { | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8420 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8421 | if (Pos != ImportedFileIDs.end()) | 
|  | 8422 | return Pos->second; | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8423 |  | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8424 | SourceManager &FromSM = FromContext.getSourceManager(); | 
|  | 8425 | SourceManager &ToSM = ToContext.getSourceManager(); | 
|  | 8426 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8427 |  | 
|  | 8428 | // Map the FromID to the "to" source manager. | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8429 | FileID ToID; | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8430 | if (FromSLoc.isExpansion()) { | 
|  | 8431 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8432 | ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8433 | if (!ToSpLoc) | 
|  | 8434 | return ToSpLoc.takeError(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8435 | ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8436 | if (!ToExLocS) | 
|  | 8437 | return ToExLocS.takeError(); | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8438 | unsigned TokenLen = FromSM.getFileIDSize(FromID); | 
|  | 8439 | SourceLocation MLoc; | 
|  | 8440 | if (FromEx.isMacroArgExpansion()) { | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8441 | MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, TokenLen); | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8442 | } else { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8443 | if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8444 | MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, TokenLen, | 
|  | 8445 | FromEx.isExpansionTokenRange()); | 
|  | 8446 | else | 
|  | 8447 | return ToExLocE.takeError(); | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8448 | } | 
|  | 8449 | ToID = ToSM.getFileID(MLoc); | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8450 | } else { | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8451 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); | 
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8452 |  | 
|  | 8453 | if (!IsBuiltin) { | 
|  | 8454 | // Include location of this file. | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8455 | ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8456 | if (!ToIncludeLoc) | 
|  | 8457 | return ToIncludeLoc.takeError(); | 
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8458 |  | 
|  | 8459 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { | 
|  | 8460 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the | 
|  | 8461 | // disk again | 
|  | 8462 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather | 
|  | 8463 | // than mmap the files several times. | 
| Harlan Haskins | 8d323d1 | 2019-08-01 21:31:56 +0000 | [diff] [blame] | 8464 | auto Entry = | 
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8465 | ToFileManager.getFile(Cache->OrigEntry->getName()); | 
|  | 8466 | // FIXME: The filename may be a virtual name that does probably not | 
|  | 8467 | // point to a valid file and we get no Entry here. In this case try with | 
|  | 8468 | // the memory buffer below. | 
|  | 8469 | if (Entry) | 
| Harlan Haskins | 8d323d1 | 2019-08-01 21:31:56 +0000 | [diff] [blame] | 8470 | ToID = ToSM.createFileID(*Entry, *ToIncludeLoc, | 
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8471 | FromSLoc.getFile().getFileCharacteristic()); | 
|  | 8472 | } | 
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8473 | } | 
| Shafik Yaghmour | 9adbbcb | 2019-03-04 20:25:54 +0000 | [diff] [blame] | 8474 |  | 
|  | 8475 | if (ToID.isInvalid() || IsBuiltin) { | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8476 | // FIXME: We want to re-use the existing MemoryBuffer! | 
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8477 | bool Invalid = true; | 
|  | 8478 | const llvm::MemoryBuffer *FromBuf = Cache->getBuffer( | 
|  | 8479 | FromContext.getDiagnostics(), FromSM, SourceLocation{}, &Invalid); | 
|  | 8480 | if (!FromBuf || Invalid) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8481 | // FIXME: Use a new error kind? | 
|  | 8482 | return llvm::make_error<ImportError>(ImportError::Unknown); | 
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8483 |  | 
| Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 8484 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = | 
|  | 8485 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), | 
|  | 8486 | FromBuf->getBufferIdentifier()); | 
|  | 8487 | ToID = ToSM.createFileID(std::move(ToBuf), | 
|  | 8488 | FromSLoc.getFile().getFileCharacteristic()); | 
|  | 8489 | } | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8490 | } | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8491 |  | 
| Balazs Keri | 9cf39df | 2019-02-27 16:31:48 +0000 | [diff] [blame] | 8492 | assert(ToID.isValid() && "Unexpected invalid fileID was created."); | 
|  | 8493 |  | 
| Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 8494 | ImportedFileIDs[FromID] = ToID; | 
| Balazs Keri | d22f877 | 2019-07-24 10:16:37 +0000 | [diff] [blame] | 8495 |  | 
|  | 8496 | if (FileIDImportHandler) | 
|  | 8497 | FileIDImportHandler(ToID, FromID); | 
|  | 8498 |  | 
| Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 8499 | return ToID; | 
|  | 8500 | } | 
|  | 8501 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8502 | Expected<CXXCtorInitializer *> ASTImporter::Import(CXXCtorInitializer *From) { | 
|  | 8503 | ExpectedExpr ToExprOrErr = Import(From->getInit()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8504 | if (!ToExprOrErr) | 
|  | 8505 | return ToExprOrErr.takeError(); | 
|  | 8506 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8507 | auto LParenLocOrErr = Import(From->getLParenLoc()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8508 | if (!LParenLocOrErr) | 
|  | 8509 | return LParenLocOrErr.takeError(); | 
|  | 8510 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8511 | auto RParenLocOrErr = Import(From->getRParenLoc()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8512 | if (!RParenLocOrErr) | 
|  | 8513 | return RParenLocOrErr.takeError(); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8514 |  | 
|  | 8515 | if (From->isBaseInitializer()) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8516 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8517 | if (!ToTInfoOrErr) | 
|  | 8518 | return ToTInfoOrErr.takeError(); | 
|  | 8519 |  | 
|  | 8520 | SourceLocation EllipsisLoc; | 
|  | 8521 | if (From->isPackExpansion()) | 
|  | 8522 | if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc())) | 
|  | 8523 | return std::move(Err); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8524 |  | 
|  | 8525 | return new (ToContext) CXXCtorInitializer( | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8526 | ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr, | 
|  | 8527 | *ToExprOrErr, *RParenLocOrErr, EllipsisLoc); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8528 | } else if (From->isMemberInitializer()) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8529 | ExpectedDecl ToFieldOrErr = Import(From->getMember()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8530 | if (!ToFieldOrErr) | 
|  | 8531 | return ToFieldOrErr.takeError(); | 
|  | 8532 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8533 | auto MemberLocOrErr = Import(From->getMemberLocation()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8534 | if (!MemberLocOrErr) | 
|  | 8535 | return MemberLocOrErr.takeError(); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8536 |  | 
|  | 8537 | return new (ToContext) CXXCtorInitializer( | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8538 | ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr, | 
|  | 8539 | *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8540 | } else if (From->isIndirectMemberInitializer()) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8541 | ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8542 | if (!ToIFieldOrErr) | 
|  | 8543 | return ToIFieldOrErr.takeError(); | 
|  | 8544 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8545 | auto MemberLocOrErr = Import(From->getMemberLocation()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8546 | if (!MemberLocOrErr) | 
|  | 8547 | return MemberLocOrErr.takeError(); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8548 |  | 
|  | 8549 | return new (ToContext) CXXCtorInitializer( | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8550 | ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr), | 
|  | 8551 | *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8552 | } else if (From->isDelegatingInitializer()) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8553 | auto ToTInfoOrErr = Import(From->getTypeSourceInfo()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8554 | if (!ToTInfoOrErr) | 
|  | 8555 | return ToTInfoOrErr.takeError(); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8556 |  | 
|  | 8557 | return new (ToContext) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8558 | CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr, | 
|  | 8559 | *ToExprOrErr, *RParenLocOrErr); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8560 | } else { | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8561 | // FIXME: assert? | 
|  | 8562 | return make_error<ImportError>(); | 
| Davide Italiano | faee83d | 2018-11-28 19:15:23 +0000 | [diff] [blame] | 8563 | } | 
| Balazs Keri | deaf7ab | 2018-11-28 13:21:26 +0000 | [diff] [blame] | 8564 | } | 
| Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 8565 |  | 
| Balazs Keri | 4a3d758 | 2018-11-27 18:36:31 +0000 | [diff] [blame] | 8566 | Expected<CXXBaseSpecifier *> | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8567 | ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8568 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); | 
|  | 8569 | if (Pos != ImportedCXXBaseSpecifiers.end()) | 
|  | 8570 | return Pos->second; | 
|  | 8571 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8572 | Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8573 | if (!ToSourceRange) | 
|  | 8574 | return ToSourceRange.takeError(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8575 | Expected<TypeSourceInfo *> ToTSI = Import(BaseSpec->getTypeSourceInfo()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8576 | if (!ToTSI) | 
|  | 8577 | return ToTSI.takeError(); | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8578 | ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc()); | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8579 | if (!ToEllipsisLoc) | 
|  | 8580 | return ToEllipsisLoc.takeError(); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8581 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8582 | *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), | 
|  | 8583 | BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc); | 
| Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 8584 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; | 
|  | 8585 | return Imported; | 
|  | 8586 | } | 
|  | 8587 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8588 | Error ASTImporter::ImportDefinition(Decl *From) { | 
|  | 8589 | ExpectedDecl ToOrErr = Import(From); | 
|  | 8590 | if (!ToOrErr) | 
|  | 8591 | return ToOrErr.takeError(); | 
|  | 8592 | Decl *To = *ToOrErr; | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8593 |  | 
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8594 | auto *FromDC = cast<DeclContext>(From); | 
|  | 8595 | ASTNodeImporter Importer(*this); | 
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 8596 |  | 
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8597 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { | 
|  | 8598 | if (!ToRecord->getDefinition()) { | 
|  | 8599 | return Importer.ImportDefinition( | 
|  | 8600 | cast<RecordDecl>(FromDC), ToRecord, | 
|  | 8601 | ASTNodeImporter::IDK_Everything); | 
| Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 8602 | } | 
| Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 8603 | } | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8604 |  | 
| Don Hinton | f170dff | 2019-03-19 06:14:14 +0000 | [diff] [blame] | 8605 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { | 
|  | 8606 | if (!ToEnum->getDefinition()) { | 
|  | 8607 | return Importer.ImportDefinition( | 
|  | 8608 | cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); | 
|  | 8609 | } | 
|  | 8610 | } | 
|  | 8611 |  | 
|  | 8612 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { | 
|  | 8613 | if (!ToIFace->getDefinition()) { | 
|  | 8614 | return Importer.ImportDefinition( | 
|  | 8615 | cast<ObjCInterfaceDecl>(FromDC), ToIFace, | 
|  | 8616 | ASTNodeImporter::IDK_Everything); | 
|  | 8617 | } | 
|  | 8618 | } | 
|  | 8619 |  | 
|  | 8620 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { | 
|  | 8621 | if (!ToProto->getDefinition()) { | 
|  | 8622 | return Importer.ImportDefinition( | 
|  | 8623 | cast<ObjCProtocolDecl>(FromDC), ToProto, | 
|  | 8624 | ASTNodeImporter::IDK_Everything); | 
|  | 8625 | } | 
|  | 8626 | } | 
|  | 8627 |  | 
|  | 8628 | return Importer.ImportDeclContext(FromDC, true); | 
| Balazs Keri | 3b30d65 | 2018-10-19 13:32:20 +0000 | [diff] [blame] | 8629 | } | 
|  | 8630 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8631 | Expected<DeclarationName> ASTImporter::Import(DeclarationName FromName) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8632 | if (!FromName) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8633 | return DeclarationName{}; | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8634 |  | 
|  | 8635 | switch (FromName.getNameKind()) { | 
|  | 8636 | case DeclarationName::Identifier: | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8637 | return DeclarationName(Import(FromName.getAsIdentifierInfo())); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8638 |  | 
|  | 8639 | case DeclarationName::ObjCZeroArgSelector: | 
|  | 8640 | case DeclarationName::ObjCOneArgSelector: | 
|  | 8641 | case DeclarationName::ObjCMultiArgSelector: | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8642 | if (auto ToSelOrErr = Import(FromName.getObjCSelector())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8643 | return DeclarationName(*ToSelOrErr); | 
|  | 8644 | else | 
|  | 8645 | return ToSelOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8646 |  | 
|  | 8647 | case DeclarationName::CXXConstructorName: { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8648 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8649 | return ToContext.DeclarationNames.getCXXConstructorName( | 
|  | 8650 | ToContext.getCanonicalType(*ToTyOrErr)); | 
|  | 8651 | else | 
|  | 8652 | return ToTyOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8653 | } | 
|  | 8654 |  | 
|  | 8655 | case DeclarationName::CXXDestructorName: { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8656 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8657 | return ToContext.DeclarationNames.getCXXDestructorName( | 
|  | 8658 | ToContext.getCanonicalType(*ToTyOrErr)); | 
|  | 8659 | else | 
|  | 8660 | return ToTyOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8661 | } | 
|  | 8662 |  | 
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8663 | case DeclarationName::CXXDeductionGuideName: { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8664 | if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8665 | return ToContext.DeclarationNames.getCXXDeductionGuideName( | 
|  | 8666 | cast<TemplateDecl>(*ToTemplateOrErr)); | 
|  | 8667 | else | 
|  | 8668 | return ToTemplateOrErr.takeError(); | 
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8669 | } | 
|  | 8670 |  | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8671 | case DeclarationName::CXXConversionFunctionName: { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8672 | if (auto ToTyOrErr = Import(FromName.getCXXNameType())) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8673 | return ToContext.DeclarationNames.getCXXConversionFunctionName( | 
|  | 8674 | ToContext.getCanonicalType(*ToTyOrErr)); | 
|  | 8675 | else | 
|  | 8676 | return ToTyOrErr.takeError(); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8677 | } | 
|  | 8678 |  | 
|  | 8679 | case DeclarationName::CXXOperatorName: | 
|  | 8680 | return ToContext.DeclarationNames.getCXXOperatorName( | 
|  | 8681 | FromName.getCXXOverloadedOperator()); | 
|  | 8682 |  | 
|  | 8683 | case DeclarationName::CXXLiteralOperatorName: | 
|  | 8684 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8685 | Import(FromName.getCXXLiteralIdentifier())); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8686 |  | 
|  | 8687 | case DeclarationName::CXXUsingDirective: | 
|  | 8688 | // FIXME: STATICS! | 
|  | 8689 | return DeclarationName::getUsingDirectiveName(); | 
|  | 8690 | } | 
|  | 8691 |  | 
| David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 8692 | llvm_unreachable("Invalid DeclarationName Kind!"); | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8693 | } | 
|  | 8694 |  | 
| Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 8695 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8696 | if (!FromId) | 
| Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 8697 | return nullptr; | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8698 |  | 
| Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 8699 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); | 
|  | 8700 |  | 
|  | 8701 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) | 
|  | 8702 | ToId->setBuiltinID(FromId->getBuiltinID()); | 
|  | 8703 |  | 
|  | 8704 | return ToId; | 
| Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 8705 | } | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8706 |  | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8707 | Expected<Selector> ASTImporter::Import(Selector FromSel) { | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8708 | if (FromSel.isNull()) | 
| Balazs Keri | e2ddb2a | 2019-03-07 14:09:18 +0000 | [diff] [blame] | 8709 | return Selector{}; | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8710 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 8711 | SmallVector<IdentifierInfo *, 4> Idents; | 
| Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 8712 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); | 
|  | 8713 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) | 
|  | 8714 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); | 
|  | 8715 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); | 
|  | 8716 | } | 
|  | 8717 |  | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8718 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, | 
|  | 8719 | DeclContext *DC, | 
|  | 8720 | unsigned IDNS, | 
|  | 8721 | NamedDecl **Decls, | 
|  | 8722 | unsigned NumDecls) { | 
|  | 8723 | return Name; | 
|  | 8724 | } | 
|  | 8725 |  | 
|  | 8726 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { | 
| Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8727 | if (LastDiagFromFrom) | 
|  | 8728 | ToContext.getDiagnostics().notePriorDiagnosticFrom( | 
|  | 8729 | FromContext.getDiagnostics()); | 
|  | 8730 | LastDiagFromFrom = false; | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8731 | return ToContext.getDiagnostics().Report(Loc, DiagID); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8732 | } | 
|  | 8733 |  | 
|  | 8734 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { | 
| Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 8735 | if (!LastDiagFromFrom) | 
|  | 8736 | FromContext.getDiagnostics().notePriorDiagnosticFrom( | 
|  | 8737 | ToContext.getDiagnostics()); | 
|  | 8738 | LastDiagFromFrom = true; | 
| Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 8739 | return FromContext.getDiagnostics().Report(Loc, DiagID); | 
| Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 8740 | } | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8741 |  | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8742 | void ASTImporter::CompleteDecl (Decl *D) { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8743 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8744 | if (!ID->getDefinition()) | 
|  | 8745 | ID->startDefinition(); | 
|  | 8746 | } | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8747 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8748 | if (!PD->getDefinition()) | 
|  | 8749 | PD->startDefinition(); | 
|  | 8750 | } | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8751 | else if (auto *TD = dyn_cast<TagDecl>(D)) { | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8752 | if (!TD->getDefinition() && !TD->isBeingDefined()) { | 
|  | 8753 | TD->startDefinition(); | 
|  | 8754 | TD->setCompleteDefinition(true); | 
|  | 8755 | } | 
|  | 8756 | } | 
|  | 8757 | else { | 
| Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 8758 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); | 
| Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 8759 | } | 
|  | 8760 | } | 
|  | 8761 |  | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8762 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { | 
|  | 8763 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); | 
|  | 8764 | assert((Pos == ImportedDecls.end() || Pos->second == To) && | 
|  | 8765 | "Try to import an already imported Decl"); | 
|  | 8766 | if (Pos != ImportedDecls.end()) | 
|  | 8767 | return Pos->second; | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8768 | ImportedDecls[From] = To; | 
| Gabor Marton | 458d145 | 2019-02-14 13:07:03 +0000 | [diff] [blame] | 8769 | // This mapping should be maintained only in this function. Therefore do not | 
|  | 8770 | // check for additional consistency. | 
|  | 8771 | ImportedFromDecls[To] = From; | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8772 | AddToLookupTable(To); | 
| Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 8773 | return To; | 
| Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 8774 | } | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8775 |  | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8776 | llvm::Optional<ImportError> | 
|  | 8777 | ASTImporter::getImportDeclErrorIfAny(Decl *FromD) const { | 
|  | 8778 | auto Pos = ImportDeclErrors.find(FromD); | 
|  | 8779 | if (Pos != ImportDeclErrors.end()) | 
|  | 8780 | return Pos->second; | 
|  | 8781 | else | 
|  | 8782 | return Optional<ImportError>(); | 
|  | 8783 | } | 
|  | 8784 |  | 
|  | 8785 | void ASTImporter::setImportDeclError(Decl *From, ImportError Error) { | 
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8786 | auto InsertRes = ImportDeclErrors.insert({From, Error}); | 
| Benjamin Kramer | 4f76936 | 2019-07-01 14:33:26 +0000 | [diff] [blame] | 8787 | (void)InsertRes; | 
| Gabor Marton | 1ad4b99 | 2019-07-01 14:19:53 +0000 | [diff] [blame] | 8788 | // Either we set the error for the first time, or we already had set one and | 
|  | 8789 | // now we want to set the same error. | 
|  | 8790 | assert(InsertRes.second || InsertRes.first->second.Error == Error.Error); | 
| Gabor Marton | 303c9861 | 2019-06-25 08:00:51 +0000 | [diff] [blame] | 8791 | } | 
|  | 8792 |  | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8793 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, | 
|  | 8794 | bool Complain) { | 
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8795 | llvm::DenseMap<const Type *, const Type *>::iterator Pos = | 
|  | 8796 | ImportedTypes.find(From.getTypePtr()); | 
|  | 8797 | if (Pos != ImportedTypes.end()) { | 
| Gabor Marton | 5ac6d49 | 2019-05-15 10:29:48 +0000 | [diff] [blame] | 8798 | if (ExpectedType ToFromOrErr = Import(From)) { | 
| Balazs Keri | a1f6b10 | 2019-04-08 13:59:15 +0000 | [diff] [blame] | 8799 | if (ToContext.hasSameType(*ToFromOrErr, To)) | 
|  | 8800 | return true; | 
|  | 8801 | } else { | 
|  | 8802 | llvm::consumeError(ToFromOrErr.takeError()); | 
|  | 8803 | } | 
|  | 8804 | } | 
| Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 8805 |  | 
| Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 8806 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, | 
| Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 8807 | getStructuralEquivalenceKind(*this), false, | 
|  | 8808 | Complain); | 
| Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 8809 | return Ctx.IsEquivalent(From, To); | 
| Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 8810 | } |