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 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the ASTImporter class which imports AST nodes from one |
| 11 | // context into another context. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 14 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTImporter.h" |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTDiagnostic.h" |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTStructuralEquivalence.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 19 | #include "clang/AST/Attr.h" |
| 20 | #include "clang/AST/Decl.h" |
| 21 | #include "clang/AST/DeclAccessPair.h" |
| 22 | #include "clang/AST/DeclBase.h" |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclCXX.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclFriend.h" |
| 25 | #include "clang/AST/DeclGroup.h" |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 26 | #include "clang/AST/DeclObjC.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 27 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 28 | #include "clang/AST/DeclVisitor.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 29 | #include "clang/AST/DeclarationName.h" |
| 30 | #include "clang/AST/Expr.h" |
| 31 | #include "clang/AST/ExprCXX.h" |
| 32 | #include "clang/AST/ExprObjC.h" |
| 33 | #include "clang/AST/ExternalASTSource.h" |
| 34 | #include "clang/AST/LambdaCapture.h" |
| 35 | #include "clang/AST/NestedNameSpecifier.h" |
| 36 | #include "clang/AST/OperationKinds.h" |
| 37 | #include "clang/AST/Stmt.h" |
| 38 | #include "clang/AST/StmtCXX.h" |
| 39 | #include "clang/AST/StmtObjC.h" |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 40 | #include "clang/AST/StmtVisitor.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 41 | #include "clang/AST/TemplateBase.h" |
| 42 | #include "clang/AST/TemplateName.h" |
| 43 | #include "clang/AST/Type.h" |
| 44 | #include "clang/AST/TypeLoc.h" |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 45 | #include "clang/AST/TypeVisitor.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 46 | #include "clang/AST/UnresolvedSet.h" |
| 47 | #include "clang/Basic/ExceptionSpecificationType.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 48 | #include "clang/Basic/FileManager.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 49 | #include "clang/Basic/IdentifierTable.h" |
| 50 | #include "clang/Basic/LLVM.h" |
| 51 | #include "clang/Basic/LangOptions.h" |
| 52 | #include "clang/Basic/SourceLocation.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 53 | #include "clang/Basic/SourceManager.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 54 | #include "clang/Basic/Specifiers.h" |
| 55 | #include "llvm/ADT/APSInt.h" |
| 56 | #include "llvm/ADT/ArrayRef.h" |
| 57 | #include "llvm/ADT/DenseMap.h" |
| 58 | #include "llvm/ADT/None.h" |
| 59 | #include "llvm/ADT/Optional.h" |
| 60 | #include "llvm/ADT/STLExtras.h" |
| 61 | #include "llvm/ADT/SmallVector.h" |
| 62 | #include "llvm/Support/Casting.h" |
| 63 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 64 | #include "llvm/Support/MemoryBuffer.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 65 | #include <algorithm> |
| 66 | #include <cassert> |
| 67 | #include <cstddef> |
| 68 | #include <memory> |
| 69 | #include <type_traits> |
| 70 | #include <utility> |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 71 | |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 72 | namespace clang { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 73 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 74 | template <class T> |
| 75 | SmallVector<Decl*, 2> |
| 76 | getCanonicalForwardRedeclChain(Redeclarable<T>* D) { |
| 77 | SmallVector<Decl*, 2> Redecls; |
| 78 | for (auto *R : D->getFirstDecl()->redecls()) { |
| 79 | if (R != D->getFirstDecl()) |
| 80 | Redecls.push_back(R); |
| 81 | } |
| 82 | Redecls.push_back(D->getFirstDecl()); |
| 83 | std::reverse(Redecls.begin(), Redecls.end()); |
| 84 | return Redecls; |
| 85 | } |
| 86 | |
| 87 | SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D) { |
| 88 | // Currently only FunctionDecl is supported |
| 89 | auto FD = cast<FunctionDecl>(D); |
| 90 | return getCanonicalForwardRedeclChain<FunctionDecl>(FD); |
| 91 | } |
| 92 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 93 | void updateFlags(const Decl *From, Decl *To) { |
| 94 | // Check if some flags or attrs are new in 'From' and copy into 'To'. |
| 95 | // FIXME: Other flags or attrs? |
| 96 | if (From->isUsed(false) && !To->isUsed(false)) |
| 97 | To->setIsUsed(); |
| 98 | } |
| 99 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 100 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, QualType>, |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 101 | public DeclVisitor<ASTNodeImporter, Decl *>, |
| 102 | public StmtVisitor<ASTNodeImporter, Stmt *> { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 103 | ASTImporter &Importer; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 104 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 105 | // Wrapper for an overload set. |
| 106 | template <typename ToDeclT> struct CallOverloadedCreateFun { |
| 107 | template <typename... Args> |
| 108 | auto operator()(Args &&... args) |
| 109 | -> decltype(ToDeclT::Create(std::forward<Args>(args)...)) { |
| 110 | return ToDeclT::Create(std::forward<Args>(args)...); |
| 111 | } |
| 112 | }; |
| 113 | |
| 114 | // Always use these functions to create a Decl during import. There are |
| 115 | // certain tasks which must be done after the Decl was created, e.g. we |
| 116 | // must immediately register that as an imported Decl. The parameter `ToD` |
| 117 | // will be set to the newly created Decl or if had been imported before |
| 118 | // then to the already imported Decl. Returns a bool value set to true if |
| 119 | // the `FromD` had been imported before. |
| 120 | template <typename ToDeclT, typename FromDeclT, typename... Args> |
| 121 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 122 | Args &&... args) { |
| 123 | // There may be several overloads of ToDeclT::Create. We must make sure |
| 124 | // to call the one which would be chosen by the arguments, thus we use a |
| 125 | // wrapper for the overload set. |
| 126 | CallOverloadedCreateFun<ToDeclT> OC; |
| 127 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 128 | std::forward<Args>(args)...); |
| 129 | } |
| 130 | // Use this overload if a special Type is needed to be created. E.g if we |
| 131 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` |
| 132 | // then: |
| 133 | // TypedefNameDecl *ToTypedef; |
| 134 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); |
| 135 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, |
| 136 | typename... Args> |
| 137 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 138 | Args &&... args) { |
| 139 | CallOverloadedCreateFun<NewDeclT> OC; |
| 140 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 141 | std::forward<Args>(args)...); |
| 142 | } |
| 143 | // Use this version if a special create function must be |
| 144 | // used, e.g. CXXRecordDecl::CreateLambda . |
| 145 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, |
| 146 | typename... Args> |
| 147 | LLVM_NODISCARD bool |
| 148 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, |
| 149 | FromDeclT *FromD, Args &&... args) { |
| 150 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); |
| 151 | if (ToD) |
| 152 | return true; // Already imported. |
| 153 | ToD = CreateFun(std::forward<Args>(args)...); |
| 154 | InitializeImportedDecl(FromD, ToD); |
| 155 | return false; // A new Decl is created. |
| 156 | } |
| 157 | |
| 158 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { |
| 159 | Importer.MapImported(FromD, ToD); |
| 160 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; |
| 161 | if (FromD->hasAttrs()) |
| 162 | for (const Attr *FromAttr : FromD->getAttrs()) |
| 163 | ToD->addAttr(Importer.Import(FromAttr)); |
| 164 | if (FromD->isUsed()) |
| 165 | ToD->setIsUsed(); |
| 166 | if (FromD->isImplicit()) |
| 167 | ToD->setImplicit(); |
| 168 | } |
| 169 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 170 | public: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 171 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} |
Gabor Marton | 344b099 | 2018-05-16 11:48:11 +0000 | [diff] [blame] | 172 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 173 | using TypeVisitor<ASTNodeImporter, QualType>::Visit; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 174 | using DeclVisitor<ASTNodeImporter, Decl *>::Visit; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 175 | using StmtVisitor<ASTNodeImporter, Stmt *>::Visit; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 176 | |
| 177 | // Importing types |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 178 | QualType VisitType(const Type *T); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 179 | QualType VisitAtomicType(const AtomicType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 180 | QualType VisitBuiltinType(const BuiltinType *T); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 181 | QualType VisitDecayedType(const DecayedType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 182 | QualType VisitComplexType(const ComplexType *T); |
| 183 | QualType VisitPointerType(const PointerType *T); |
| 184 | QualType VisitBlockPointerType(const BlockPointerType *T); |
| 185 | QualType VisitLValueReferenceType(const LValueReferenceType *T); |
| 186 | QualType VisitRValueReferenceType(const RValueReferenceType *T); |
| 187 | QualType VisitMemberPointerType(const MemberPointerType *T); |
| 188 | QualType VisitConstantArrayType(const ConstantArrayType *T); |
| 189 | QualType VisitIncompleteArrayType(const IncompleteArrayType *T); |
| 190 | QualType VisitVariableArrayType(const VariableArrayType *T); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 191 | QualType VisitDependentSizedArrayType(const DependentSizedArrayType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 192 | // FIXME: DependentSizedExtVectorType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 193 | QualType VisitVectorType(const VectorType *T); |
| 194 | QualType VisitExtVectorType(const ExtVectorType *T); |
| 195 | QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T); |
| 196 | QualType VisitFunctionProtoType(const FunctionProtoType *T); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 197 | QualType VisitUnresolvedUsingType(const UnresolvedUsingType *T); |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 198 | QualType VisitParenType(const ParenType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 199 | QualType VisitTypedefType(const TypedefType *T); |
| 200 | QualType VisitTypeOfExprType(const TypeOfExprType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 201 | // FIXME: DependentTypeOfExprType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 202 | QualType VisitTypeOfType(const TypeOfType *T); |
| 203 | QualType VisitDecltypeType(const DecltypeType *T); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 204 | QualType VisitUnaryTransformType(const UnaryTransformType *T); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 205 | QualType VisitAutoType(const AutoType *T); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 206 | QualType VisitInjectedClassNameType(const InjectedClassNameType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 207 | // FIXME: DependentDecltypeType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 208 | QualType VisitRecordType(const RecordType *T); |
| 209 | QualType VisitEnumType(const EnumType *T); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 210 | QualType VisitAttributedType(const AttributedType *T); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 211 | QualType VisitTemplateTypeParmType(const TemplateTypeParmType *T); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 212 | QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 213 | QualType VisitTemplateSpecializationType(const TemplateSpecializationType *T); |
| 214 | QualType VisitElaboratedType(const ElaboratedType *T); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 215 | QualType VisitDependentNameType(const DependentNameType *T); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 216 | QualType VisitPackExpansionType(const PackExpansionType *T); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 217 | QualType VisitDependentTemplateSpecializationType( |
| 218 | const DependentTemplateSpecializationType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 219 | QualType VisitObjCInterfaceType(const ObjCInterfaceType *T); |
| 220 | QualType VisitObjCObjectType(const ObjCObjectType *T); |
| 221 | QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); |
Rafael Stahl | df55620 | 2018-05-29 08:12:15 +0000 | [diff] [blame] | 222 | |
| 223 | // Importing declarations |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 224 | bool ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 225 | DeclContext *&LexicalDC, DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 226 | NamedDecl *&ToD, SourceLocation &Loc); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 227 | void ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 228 | void ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 229 | DeclarationNameInfo& To); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 230 | void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 231 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 232 | bool ImportCastPath(CastExpr *E, CXXCastPath &Path); |
| 233 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 234 | using Designator = DesignatedInitExpr::Designator; |
| 235 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 236 | Designator ImportDesignator(const Designator &D); |
| 237 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 238 | Optional<LambdaCapture> ImportLambdaCapture(const LambdaCapture &From); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 239 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 240 | /// What we should import from the definition. |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 241 | enum ImportDefinitionKind { |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 242 | /// Import the default subset of the definition, which might be |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 243 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 244 | /// import is not set). |
| 245 | IDK_Default, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 246 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 247 | /// Import everything. |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 248 | IDK_Everything, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 249 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 250 | /// Import only the bare bones needed to establish a valid |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 251 | /// DeclContext. |
| 252 | IDK_Basic |
| 253 | }; |
| 254 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 255 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 256 | return IDK == IDK_Everything || |
| 257 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 258 | } |
| 259 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 260 | bool ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 261 | ImportDefinitionKind Kind = IDK_Default); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 262 | bool ImportDefinition(VarDecl *From, VarDecl *To, |
| 263 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 264 | bool ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 265 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 266 | bool ImportDefinition(ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 267 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 268 | bool ImportDefinition(ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 269 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 270 | TemplateParameterList *ImportTemplateParameterList( |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 271 | TemplateParameterList *Params); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 272 | TemplateArgument ImportTemplateArgument(const TemplateArgument &From); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 273 | Optional<TemplateArgumentLoc> ImportTemplateArgumentLoc( |
| 274 | const TemplateArgumentLoc &TALoc); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 275 | bool ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 276 | unsigned NumFromArgs, |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 277 | SmallVectorImpl<TemplateArgument> &ToArgs); |
| 278 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 279 | template <typename InContainerTy> |
| 280 | bool ImportTemplateArgumentListInfo(const InContainerTy &Container, |
| 281 | TemplateArgumentListInfo &ToTAInfo); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 282 | |
| 283 | template<typename InContainerTy> |
| 284 | bool ImportTemplateArgumentListInfo(SourceLocation FromLAngleLoc, |
| 285 | SourceLocation FromRAngleLoc, |
| 286 | const InContainerTy &Container, |
| 287 | TemplateArgumentListInfo &Result); |
| 288 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 289 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; |
| 290 | using OptionalTemplateArgsTy = Optional<TemplateArgsTy>; |
| 291 | std::tuple<FunctionTemplateDecl *, OptionalTemplateArgsTy> |
| 292 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 293 | FunctionDecl *FromFD); |
| 294 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 295 | bool ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); |
| 296 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 297 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 298 | bool Complain = true); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 299 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 300 | bool Complain = true); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 301 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 302 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 303 | bool IsStructuralMatch(FunctionTemplateDecl *From, |
| 304 | FunctionTemplateDecl *To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 305 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 306 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 307 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 308 | Decl *VisitDecl(Decl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 309 | Decl *VisitEmptyDecl(EmptyDecl *D); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 310 | Decl *VisitAccessSpecDecl(AccessSpecDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 311 | Decl *VisitStaticAssertDecl(StaticAssertDecl *D); |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 312 | Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 313 | Decl *VisitNamespaceDecl(NamespaceDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 314 | Decl *VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 315 | Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 316 | Decl *VisitTypedefDecl(TypedefDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 317 | Decl *VisitTypeAliasDecl(TypeAliasDecl *D); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 318 | Decl *VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 319 | Decl *VisitLabelDecl(LabelDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 320 | Decl *VisitEnumDecl(EnumDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 321 | Decl *VisitRecordDecl(RecordDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 322 | Decl *VisitEnumConstantDecl(EnumConstantDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 323 | Decl *VisitFunctionDecl(FunctionDecl *D); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 324 | Decl *VisitCXXMethodDecl(CXXMethodDecl *D); |
| 325 | Decl *VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 326 | Decl *VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 327 | Decl *VisitCXXConversionDecl(CXXConversionDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 328 | Decl *VisitFieldDecl(FieldDecl *D); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 329 | Decl *VisitIndirectFieldDecl(IndirectFieldDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 330 | Decl *VisitFriendDecl(FriendDecl *D); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 331 | Decl *VisitObjCIvarDecl(ObjCIvarDecl *D); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 332 | Decl *VisitVarDecl(VarDecl *D); |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 333 | Decl *VisitImplicitParamDecl(ImplicitParamDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 334 | Decl *VisitParmVarDecl(ParmVarDecl *D); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 335 | Decl *VisitObjCMethodDecl(ObjCMethodDecl *D); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 336 | Decl *VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 337 | Decl *VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 338 | Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 339 | Decl *VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 340 | Decl *VisitUsingDecl(UsingDecl *D); |
| 341 | Decl *VisitUsingShadowDecl(UsingShadowDecl *D); |
| 342 | Decl *VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 343 | Decl *VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 344 | Decl *VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
| 345 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 346 | ObjCTypeParamList *ImportObjCTypeParamList(ObjCTypeParamList *list); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 347 | Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 348 | Decl *VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 349 | Decl *VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 350 | Decl *VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 351 | Decl *VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 352 | Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 353 | Decl *VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 354 | Decl *VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 355 | Decl *VisitClassTemplateDecl(ClassTemplateDecl *D); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 356 | Decl *VisitClassTemplateSpecializationDecl( |
| 357 | ClassTemplateSpecializationDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 358 | Decl *VisitVarTemplateDecl(VarTemplateDecl *D); |
| 359 | Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 360 | Decl *VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 361 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 362 | // Importing statements |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 363 | DeclGroupRef ImportDeclGroup(DeclGroupRef DG); |
| 364 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 365 | Stmt *VisitStmt(Stmt *S); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 366 | Stmt *VisitGCCAsmStmt(GCCAsmStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 367 | Stmt *VisitDeclStmt(DeclStmt *S); |
| 368 | Stmt *VisitNullStmt(NullStmt *S); |
| 369 | Stmt *VisitCompoundStmt(CompoundStmt *S); |
| 370 | Stmt *VisitCaseStmt(CaseStmt *S); |
| 371 | Stmt *VisitDefaultStmt(DefaultStmt *S); |
| 372 | Stmt *VisitLabelStmt(LabelStmt *S); |
| 373 | Stmt *VisitAttributedStmt(AttributedStmt *S); |
| 374 | Stmt *VisitIfStmt(IfStmt *S); |
| 375 | Stmt *VisitSwitchStmt(SwitchStmt *S); |
| 376 | Stmt *VisitWhileStmt(WhileStmt *S); |
| 377 | Stmt *VisitDoStmt(DoStmt *S); |
| 378 | Stmt *VisitForStmt(ForStmt *S); |
| 379 | Stmt *VisitGotoStmt(GotoStmt *S); |
| 380 | Stmt *VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 381 | Stmt *VisitContinueStmt(ContinueStmt *S); |
| 382 | Stmt *VisitBreakStmt(BreakStmt *S); |
| 383 | Stmt *VisitReturnStmt(ReturnStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 384 | // FIXME: MSAsmStmt |
| 385 | // FIXME: SEHExceptStmt |
| 386 | // FIXME: SEHFinallyStmt |
| 387 | // FIXME: SEHTryStmt |
| 388 | // FIXME: SEHLeaveStmt |
| 389 | // FIXME: CapturedStmt |
| 390 | Stmt *VisitCXXCatchStmt(CXXCatchStmt *S); |
| 391 | Stmt *VisitCXXTryStmt(CXXTryStmt *S); |
| 392 | Stmt *VisitCXXForRangeStmt(CXXForRangeStmt *S); |
| 393 | // FIXME: MSDependentExistsStmt |
| 394 | Stmt *VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 395 | Stmt *VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 396 | Stmt *VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 397 | Stmt *VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 398 | Stmt *VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 399 | Stmt *VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 400 | Stmt *VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 401 | |
| 402 | // Importing expressions |
| 403 | Expr *VisitExpr(Expr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 404 | Expr *VisitVAArgExpr(VAArgExpr *E); |
| 405 | Expr *VisitGNUNullExpr(GNUNullExpr *E); |
| 406 | Expr *VisitPredefinedExpr(PredefinedExpr *E); |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 407 | Expr *VisitDeclRefExpr(DeclRefExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 408 | Expr *VisitImplicitValueInitExpr(ImplicitValueInitExpr *ILE); |
| 409 | Expr *VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 410 | Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 411 | Expr *VisitIntegerLiteral(IntegerLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 412 | Expr *VisitFloatingLiteral(FloatingLiteral *E); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 413 | Expr *VisitCharacterLiteral(CharacterLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 414 | Expr *VisitStringLiteral(StringLiteral *E); |
| 415 | Expr *VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 416 | Expr *VisitAtomicExpr(AtomicExpr *E); |
| 417 | Expr *VisitAddrLabelExpr(AddrLabelExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 418 | Expr *VisitParenExpr(ParenExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 419 | Expr *VisitParenListExpr(ParenListExpr *E); |
| 420 | Expr *VisitStmtExpr(StmtExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 421 | Expr *VisitUnaryOperator(UnaryOperator *E); |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 422 | Expr *VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 423 | Expr *VisitBinaryOperator(BinaryOperator *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 424 | Expr *VisitConditionalOperator(ConditionalOperator *E); |
| 425 | Expr *VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 426 | Expr *VisitOpaqueValueExpr(OpaqueValueExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 427 | Expr *VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 428 | Expr *VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 429 | Expr *VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 430 | Expr *VisitCompoundAssignOperator(CompoundAssignOperator *E); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 431 | Expr *VisitImplicitCastExpr(ImplicitCastExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 432 | Expr *VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 433 | Expr *VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 434 | Expr *VisitCXXThrowExpr(CXXThrowExpr *E); |
| 435 | Expr *VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 436 | Expr *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 437 | Expr *VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 438 | Expr *VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 439 | Expr *VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE); |
| 440 | Expr *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 441 | Expr *VisitPackExpansionExpr(PackExpansionExpr *E); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 442 | Expr *VisitSizeOfPackExpr(SizeOfPackExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 443 | Expr *VisitCXXNewExpr(CXXNewExpr *CE); |
| 444 | Expr *VisitCXXDeleteExpr(CXXDeleteExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 445 | Expr *VisitCXXConstructExpr(CXXConstructExpr *E); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 446 | Expr *VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 447 | Expr *VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 448 | Expr *VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 449 | Expr *VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *CE); |
| 450 | Expr *VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 451 | Expr *VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 452 | Expr *VisitExprWithCleanups(ExprWithCleanups *EWC); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 453 | Expr *VisitCXXThisExpr(CXXThisExpr *E); |
| 454 | Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 455 | Expr *VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 456 | Expr *VisitMemberExpr(MemberExpr *E); |
| 457 | Expr *VisitCallExpr(CallExpr *E); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 458 | Expr *VisitLambdaExpr(LambdaExpr *LE); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 459 | Expr *VisitInitListExpr(InitListExpr *E); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 460 | Expr *VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 461 | Expr *VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 462 | Expr *VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 463 | Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 464 | Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 465 | Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 466 | Expr *VisitTypeTraitExpr(TypeTraitExpr *E); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 467 | Expr *VisitCXXTypeidExpr(CXXTypeidExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 468 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 469 | template<typename IIter, typename OIter> |
| 470 | void ImportArray(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 471 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; |
| 472 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 473 | ASTImporter &ImporterRef = Importer; |
| 474 | std::transform(Ibegin, Iend, Obegin, |
| 475 | [&ImporterRef](ItemT From) -> ItemT { |
| 476 | return ImporterRef.Import(From); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 477 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | template<typename IIter, typename OIter> |
| 481 | bool ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 482 | using ItemT = typename std::remove_reference<decltype(**Obegin)>::type; |
| 483 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 484 | ASTImporter &ImporterRef = Importer; |
| 485 | bool Failed = false; |
| 486 | std::transform(Ibegin, Iend, Obegin, |
| 487 | [&ImporterRef, &Failed](ItemT *From) -> ItemT * { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 488 | auto *To = cast_or_null<ItemT>(ImporterRef.Import(From)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 489 | if (!To && From) |
| 490 | Failed = true; |
| 491 | return To; |
| 492 | }); |
| 493 | return Failed; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 494 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 495 | |
| 496 | template<typename InContainerTy, typename OutContainerTy> |
| 497 | bool ImportContainerChecked(const InContainerTy &InContainer, |
| 498 | OutContainerTy &OutContainer) { |
| 499 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), |
| 500 | OutContainer.begin()); |
| 501 | } |
| 502 | |
| 503 | template<typename InContainerTy, typename OIter> |
| 504 | bool ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
| 505 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 506 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 507 | |
| 508 | // Importing overrides. |
| 509 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 510 | |
| 511 | FunctionDecl *FindFunctionTemplateSpecialization(FunctionDecl *FromFD); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 512 | }; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 513 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 514 | template <typename InContainerTy> |
| 515 | bool ASTNodeImporter::ImportTemplateArgumentListInfo( |
| 516 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 517 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
| 518 | TemplateArgumentListInfo ToTAInfo(Importer.Import(FromLAngleLoc), |
| 519 | Importer.Import(FromRAngleLoc)); |
| 520 | if (ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 521 | return true; |
| 522 | Result = ToTAInfo; |
| 523 | return false; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 524 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 525 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 526 | template <> |
| 527 | bool ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
| 528 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 529 | return ImportTemplateArgumentListInfo( |
| 530 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 531 | } |
| 532 | |
| 533 | template <> |
| 534 | bool ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 535 | ASTTemplateArgumentListInfo>(const ASTTemplateArgumentListInfo &From, |
| 536 | TemplateArgumentListInfo &Result) { |
| 537 | return ImportTemplateArgumentListInfo(From.LAngleLoc, From.RAngleLoc, |
| 538 | From.arguments(), Result); |
| 539 | } |
| 540 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 541 | std::tuple<FunctionTemplateDecl *, ASTNodeImporter::OptionalTemplateArgsTy> |
| 542 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 543 | FunctionDecl *FromFD) { |
| 544 | assert(FromFD->getTemplatedKind() == |
| 545 | FunctionDecl::TK_FunctionTemplateSpecialization); |
| 546 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
| 547 | auto *Template = cast_or_null<FunctionTemplateDecl>( |
| 548 | Importer.Import(FTSInfo->getTemplate())); |
| 549 | |
| 550 | // Import template arguments. |
| 551 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
| 552 | TemplateArgsTy ToTemplArgs; |
| 553 | if (ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 554 | ToTemplArgs)) // Error during import. |
| 555 | return std::make_tuple(Template, OptionalTemplateArgsTy()); |
| 556 | |
| 557 | return std::make_tuple(Template, ToTemplArgs); |
| 558 | } |
| 559 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 560 | } // namespace clang |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 561 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 562 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 563 | // Import Types |
| 564 | //---------------------------------------------------------------------------- |
| 565 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 566 | using namespace clang; |
| 567 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 568 | QualType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 569 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 570 | << T->getTypeClassName(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 571 | return {}; |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 574 | QualType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 575 | QualType UnderlyingType = Importer.Import(T->getValueType()); |
| 576 | if(UnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 577 | return {}; |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 578 | |
| 579 | return Importer.getToContext().getAtomicType(UnderlyingType); |
| 580 | } |
| 581 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 582 | QualType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 583 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 584 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 585 | case BuiltinType::Id: \ |
| 586 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 587 | #include "clang/Basic/OpenCLImageTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 588 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 589 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 590 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 591 | #include "clang/AST/BuiltinTypes.def" |
| 592 | |
| 593 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 594 | // context supports C++. |
| 595 | |
| 596 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 597 | // context supports ObjC. |
| 598 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 599 | case BuiltinType::Char_U: |
| 600 | // The context we're importing from has an unsigned 'char'. If we're |
| 601 | // importing into a context with a signed 'char', translate to |
| 602 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 603 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 604 | return Importer.getToContext().UnsignedCharTy; |
| 605 | |
| 606 | return Importer.getToContext().CharTy; |
| 607 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 608 | case BuiltinType::Char_S: |
| 609 | // The context we're importing from has an unsigned 'char'. If we're |
| 610 | // importing into a context with a signed 'char', translate to |
| 611 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 612 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 613 | return Importer.getToContext().SignedCharTy; |
| 614 | |
| 615 | return Importer.getToContext().CharTy; |
| 616 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 617 | case BuiltinType::WChar_S: |
| 618 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 619 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 620 | // wchar_t? |
| 621 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 622 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 623 | |
| 624 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 625 | } |
| 626 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 627 | QualType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 628 | QualType OrigT = Importer.Import(T->getOriginalType()); |
| 629 | if (OrigT.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 630 | return {}; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 631 | |
| 632 | return Importer.getToContext().getDecayedType(OrigT); |
| 633 | } |
| 634 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 635 | QualType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 636 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 637 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 638 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 639 | |
| 640 | return Importer.getToContext().getComplexType(ToElementType); |
| 641 | } |
| 642 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 643 | QualType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 644 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 645 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 646 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 647 | |
| 648 | return Importer.getToContext().getPointerType(ToPointeeType); |
| 649 | } |
| 650 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 651 | QualType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 652 | // FIXME: Check for blocks support in "to" context. |
| 653 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 654 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 655 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 656 | |
| 657 | return Importer.getToContext().getBlockPointerType(ToPointeeType); |
| 658 | } |
| 659 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 660 | QualType |
| 661 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 662 | // FIXME: Check for C++ support in "to" context. |
| 663 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 664 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 665 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 666 | |
| 667 | return Importer.getToContext().getLValueReferenceType(ToPointeeType); |
| 668 | } |
| 669 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 670 | QualType |
| 671 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 672 | // FIXME: Check for C++0x support in "to" context. |
| 673 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 674 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 675 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 676 | |
| 677 | return Importer.getToContext().getRValueReferenceType(ToPointeeType); |
| 678 | } |
| 679 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 680 | QualType ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 681 | // FIXME: Check for C++ support in "to" context. |
| 682 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 683 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 684 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 685 | |
| 686 | QualType ClassType = Importer.Import(QualType(T->getClass(), 0)); |
| 687 | return Importer.getToContext().getMemberPointerType(ToPointeeType, |
| 688 | ClassType.getTypePtr()); |
| 689 | } |
| 690 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 691 | QualType ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 692 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 693 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 694 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 695 | |
| 696 | return Importer.getToContext().getConstantArrayType(ToElementType, |
| 697 | T->getSize(), |
| 698 | T->getSizeModifier(), |
| 699 | T->getIndexTypeCVRQualifiers()); |
| 700 | } |
| 701 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 702 | QualType |
| 703 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 704 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 705 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 706 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 707 | |
| 708 | return Importer.getToContext().getIncompleteArrayType(ToElementType, |
| 709 | T->getSizeModifier(), |
| 710 | T->getIndexTypeCVRQualifiers()); |
| 711 | } |
| 712 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 713 | QualType ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 714 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 715 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 716 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 717 | |
| 718 | Expr *Size = Importer.Import(T->getSizeExpr()); |
| 719 | if (!Size) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 720 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 721 | |
| 722 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); |
| 723 | return Importer.getToContext().getVariableArrayType(ToElementType, Size, |
| 724 | T->getSizeModifier(), |
| 725 | T->getIndexTypeCVRQualifiers(), |
| 726 | Brackets); |
| 727 | } |
| 728 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 729 | QualType ASTNodeImporter::VisitDependentSizedArrayType( |
| 730 | const DependentSizedArrayType *T) { |
| 731 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 732 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 733 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 734 | |
| 735 | // SizeExpr may be null if size is not specified directly. |
| 736 | // For example, 'int a[]'. |
| 737 | Expr *Size = Importer.Import(T->getSizeExpr()); |
| 738 | if (!Size && T->getSizeExpr()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 739 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 740 | |
| 741 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); |
| 742 | return Importer.getToContext().getDependentSizedArrayType( |
| 743 | ToElementType, Size, T->getSizeModifier(), T->getIndexTypeCVRQualifiers(), |
| 744 | Brackets); |
| 745 | } |
| 746 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 747 | QualType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 748 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 749 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 750 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 751 | |
| 752 | return Importer.getToContext().getVectorType(ToElementType, |
| 753 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 754 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 755 | } |
| 756 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 757 | QualType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 758 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 759 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 760 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 761 | |
| 762 | return Importer.getToContext().getExtVectorType(ToElementType, |
| 763 | T->getNumElements()); |
| 764 | } |
| 765 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 766 | QualType |
| 767 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 768 | // FIXME: What happens if we're importing a function without a prototype |
| 769 | // into C++? Should we make it variadic? |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 770 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 771 | if (ToResultType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 772 | return {}; |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 773 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 774 | return Importer.getToContext().getFunctionNoProtoType(ToResultType, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 775 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 776 | } |
| 777 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 778 | QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 779 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 780 | if (ToResultType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 781 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 782 | |
| 783 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 784 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 785 | for (const auto &A : T->param_types()) { |
| 786 | QualType ArgType = Importer.Import(A); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 787 | if (ArgType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 788 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 789 | ArgTypes.push_back(ArgType); |
| 790 | } |
| 791 | |
| 792 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 793 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 794 | for (const auto &E : T->exceptions()) { |
| 795 | QualType ExceptionType = Importer.Import(E); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 796 | if (ExceptionType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 797 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 798 | ExceptionTypes.push_back(ExceptionType); |
| 799 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 800 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 801 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 802 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 803 | |
| 804 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 805 | ToEPI.Variadic = FromEPI.Variadic; |
| 806 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 807 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 808 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 809 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 810 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
| 811 | ToEPI.ExceptionSpec.NoexceptExpr = |
| 812 | Importer.Import(FromEPI.ExceptionSpec.NoexceptExpr); |
| 813 | ToEPI.ExceptionSpec.SourceDecl = cast_or_null<FunctionDecl>( |
| 814 | Importer.Import(FromEPI.ExceptionSpec.SourceDecl)); |
| 815 | ToEPI.ExceptionSpec.SourceTemplate = cast_or_null<FunctionDecl>( |
| 816 | Importer.Import(FromEPI.ExceptionSpec.SourceTemplate)); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 817 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 818 | return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 819 | } |
| 820 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 821 | QualType ASTNodeImporter::VisitUnresolvedUsingType( |
| 822 | const UnresolvedUsingType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 823 | const auto *ToD = |
| 824 | cast_or_null<UnresolvedUsingTypenameDecl>(Importer.Import(T->getDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 825 | if (!ToD) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 826 | return {}; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 827 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 828 | auto *ToPrevD = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 829 | cast_or_null<UnresolvedUsingTypenameDecl>( |
| 830 | Importer.Import(T->getDecl()->getPreviousDecl())); |
| 831 | if (!ToPrevD && T->getDecl()->getPreviousDecl()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 832 | return {}; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 833 | |
| 834 | return Importer.getToContext().getTypeDeclType(ToD, ToPrevD); |
| 835 | } |
| 836 | |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 837 | QualType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 838 | QualType ToInnerType = Importer.Import(T->getInnerType()); |
| 839 | if (ToInnerType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 840 | return {}; |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 841 | |
| 842 | return Importer.getToContext().getParenType(ToInnerType); |
| 843 | } |
| 844 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 845 | QualType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 846 | auto *ToDecl = |
| 847 | dyn_cast_or_null<TypedefNameDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 848 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 849 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 850 | |
| 851 | return Importer.getToContext().getTypeDeclType(ToDecl); |
| 852 | } |
| 853 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 854 | QualType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 855 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 856 | if (!ToExpr) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 857 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 858 | |
| 859 | return Importer.getToContext().getTypeOfExprType(ToExpr); |
| 860 | } |
| 861 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 862 | QualType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 863 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 864 | if (ToUnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 865 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 866 | |
| 867 | return Importer.getToContext().getTypeOfType(ToUnderlyingType); |
| 868 | } |
| 869 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 870 | QualType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 871 | // FIXME: Make sure that the "to" context supports C++0x! |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 872 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 873 | if (!ToExpr) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 874 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 875 | |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 876 | QualType UnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 877 | if (UnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 878 | return {}; |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 879 | |
| 880 | return Importer.getToContext().getDecltypeType(ToExpr, UnderlyingType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 881 | } |
| 882 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 883 | QualType ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 884 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 885 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 886 | if (ToBaseType.isNull() || ToUnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 887 | return {}; |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 888 | |
| 889 | return Importer.getToContext().getUnaryTransformType(ToBaseType, |
| 890 | ToUnderlyingType, |
| 891 | T->getUTTKind()); |
| 892 | } |
| 893 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 894 | QualType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 895 | // FIXME: Make sure that the "to" context supports C++11! |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 896 | QualType FromDeduced = T->getDeducedType(); |
| 897 | QualType ToDeduced; |
| 898 | if (!FromDeduced.isNull()) { |
| 899 | ToDeduced = Importer.Import(FromDeduced); |
| 900 | if (ToDeduced.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 901 | return {}; |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 902 | } |
| 903 | |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 904 | return Importer.getToContext().getAutoType(ToDeduced, T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 905 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 906 | } |
| 907 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 908 | QualType ASTNodeImporter::VisitInjectedClassNameType( |
| 909 | const InjectedClassNameType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 910 | auto *D = cast_or_null<CXXRecordDecl>(Importer.Import(T->getDecl())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 911 | if (!D) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 912 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 913 | |
| 914 | QualType InjType = Importer.Import(T->getInjectedSpecializationType()); |
| 915 | if (InjType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 916 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 917 | |
| 918 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 919 | // See comments in InjectedClassNameType definition for details |
| 920 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 921 | enum { |
| 922 | TypeAlignmentInBits = 4, |
| 923 | TypeAlignment = 1 << TypeAlignmentInBits |
| 924 | }; |
| 925 | |
| 926 | return QualType(new (Importer.getToContext(), TypeAlignment) |
| 927 | InjectedClassNameType(D, InjType), 0); |
| 928 | } |
| 929 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 930 | QualType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 931 | auto *ToDecl = dyn_cast_or_null<RecordDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 932 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 933 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 934 | |
| 935 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 936 | } |
| 937 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 938 | QualType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 939 | auto *ToDecl = dyn_cast_or_null<EnumDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 940 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 941 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 942 | |
| 943 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 944 | } |
| 945 | |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 946 | QualType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 947 | QualType FromModifiedType = T->getModifiedType(); |
| 948 | QualType FromEquivalentType = T->getEquivalentType(); |
| 949 | QualType ToModifiedType; |
| 950 | QualType ToEquivalentType; |
| 951 | |
| 952 | if (!FromModifiedType.isNull()) { |
| 953 | ToModifiedType = Importer.Import(FromModifiedType); |
| 954 | if (ToModifiedType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 955 | return {}; |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 956 | } |
| 957 | if (!FromEquivalentType.isNull()) { |
| 958 | ToEquivalentType = Importer.Import(FromEquivalentType); |
| 959 | if (ToEquivalentType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 960 | return {}; |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
| 964 | ToModifiedType, ToEquivalentType); |
| 965 | } |
| 966 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 967 | QualType ASTNodeImporter::VisitTemplateTypeParmType( |
| 968 | const TemplateTypeParmType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 969 | auto *ParmDecl = |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 970 | cast_or_null<TemplateTypeParmDecl>(Importer.Import(T->getDecl())); |
| 971 | if (!ParmDecl && T->getDecl()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 972 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 973 | |
| 974 | return Importer.getToContext().getTemplateTypeParmType( |
| 975 | T->getDepth(), T->getIndex(), T->isParameterPack(), ParmDecl); |
| 976 | } |
| 977 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 978 | QualType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
| 979 | const SubstTemplateTypeParmType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 980 | const auto *Replaced = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 981 | cast_or_null<TemplateTypeParmType>(Importer.Import( |
| 982 | QualType(T->getReplacedParameter(), 0)).getTypePtr()); |
| 983 | if (!Replaced) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 984 | return {}; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 985 | |
| 986 | QualType Replacement = Importer.Import(T->getReplacementType()); |
| 987 | if (Replacement.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 988 | return {}; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 989 | Replacement = Replacement.getCanonicalType(); |
| 990 | |
| 991 | return Importer.getToContext().getSubstTemplateTypeParmType( |
| 992 | Replaced, Replacement); |
| 993 | } |
| 994 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 995 | QualType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 996 | const TemplateSpecializationType *T) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 997 | TemplateName ToTemplate = Importer.Import(T->getTemplateName()); |
| 998 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 999 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1000 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1001 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1002 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1003 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1004 | |
| 1005 | QualType ToCanonType; |
| 1006 | if (!QualType(T, 0).isCanonical()) { |
| 1007 | QualType FromCanonType |
| 1008 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
| 1009 | ToCanonType =Importer.Import(FromCanonType); |
| 1010 | if (ToCanonType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1011 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1012 | } |
| 1013 | return Importer.getToContext().getTemplateSpecializationType(ToTemplate, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 1014 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1015 | ToCanonType); |
| 1016 | } |
| 1017 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1018 | QualType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1019 | NestedNameSpecifier *ToQualifier = nullptr; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1020 | // Note: the qualifier in an ElaboratedType is optional. |
| 1021 | if (T->getQualifier()) { |
| 1022 | ToQualifier = Importer.Import(T->getQualifier()); |
| 1023 | if (!ToQualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1024 | return {}; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1025 | } |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1026 | |
| 1027 | QualType ToNamedType = Importer.Import(T->getNamedType()); |
| 1028 | if (ToNamedType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1029 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1030 | |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1031 | TagDecl *OwnedTagDecl = |
| 1032 | cast_or_null<TagDecl>(Importer.Import(T->getOwnedTagDecl())); |
| 1033 | if (!OwnedTagDecl && T->getOwnedTagDecl()) |
| 1034 | return {}; |
| 1035 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1036 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1037 | ToQualifier, ToNamedType, |
| 1038 | OwnedTagDecl); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1041 | QualType ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 1042 | QualType Pattern = Importer.Import(T->getPattern()); |
| 1043 | if (Pattern.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1044 | return {}; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1045 | |
| 1046 | return Importer.getToContext().getPackExpansionType(Pattern, |
| 1047 | T->getNumExpansions()); |
| 1048 | } |
| 1049 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1050 | QualType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
| 1051 | const DependentTemplateSpecializationType *T) { |
| 1052 | NestedNameSpecifier *Qualifier = Importer.Import(T->getQualifier()); |
| 1053 | if (!Qualifier && T->getQualifier()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1054 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1055 | |
| 1056 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
| 1057 | if (!Name && T->getIdentifier()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1058 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1059 | |
| 1060 | SmallVector<TemplateArgument, 2> ToPack; |
| 1061 | ToPack.reserve(T->getNumArgs()); |
| 1062 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToPack)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1063 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1064 | |
| 1065 | return Importer.getToContext().getDependentTemplateSpecializationType( |
| 1066 | T->getKeyword(), Qualifier, Name, ToPack); |
| 1067 | } |
| 1068 | |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1069 | QualType ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { |
| 1070 | NestedNameSpecifier *NNS = Importer.Import(T->getQualifier()); |
| 1071 | if (!NNS && T->getQualifier()) |
| 1072 | return QualType(); |
| 1073 | |
| 1074 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
| 1075 | if (!Name && T->getIdentifier()) |
| 1076 | return QualType(); |
| 1077 | |
| 1078 | QualType Canon = (T == T->getCanonicalTypeInternal().getTypePtr()) |
| 1079 | ? QualType() |
| 1080 | : Importer.Import(T->getCanonicalTypeInternal()); |
| 1081 | if (!Canon.isNull()) |
| 1082 | Canon = Canon.getCanonicalType(); |
| 1083 | |
| 1084 | return Importer.getToContext().getDependentNameType(T->getKeyword(), NNS, |
| 1085 | Name, Canon); |
| 1086 | } |
| 1087 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1088 | QualType ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1089 | auto *Class = |
| 1090 | dyn_cast_or_null<ObjCInterfaceDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1091 | if (!Class) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1092 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1093 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1094 | return Importer.getToContext().getObjCInterfaceType(Class); |
| 1095 | } |
| 1096 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1097 | QualType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1098 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 1099 | if (ToBaseType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1100 | return {}; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1101 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1102 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1103 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1104 | QualType ImportedTypeArg = Importer.Import(TypeArg); |
| 1105 | if (ImportedTypeArg.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1106 | return {}; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1107 | |
| 1108 | TypeArgs.push_back(ImportedTypeArg); |
| 1109 | } |
| 1110 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1111 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1112 | for (auto *P : T->quals()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1113 | auto *Protocol = dyn_cast_or_null<ObjCProtocolDecl>(Importer.Import(P)); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1114 | if (!Protocol) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1115 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1116 | Protocols.push_back(Protocol); |
| 1117 | } |
| 1118 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1119 | return Importer.getToContext().getObjCObjectType(ToBaseType, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1120 | Protocols, |
| 1121 | T->isKindOfTypeAsWritten()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1124 | QualType |
| 1125 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1126 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 1127 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1128 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1129 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1130 | return Importer.getToContext().getObjCObjectPointerType(ToPointeeType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1133 | //---------------------------------------------------------------------------- |
| 1134 | // Import Declarations |
| 1135 | //---------------------------------------------------------------------------- |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1136 | bool ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 1137 | DeclContext *&LexicalDC, |
| 1138 | DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1139 | NamedDecl *&ToD, |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1140 | SourceLocation &Loc) { |
| 1141 | // Import the context of this declaration. |
| 1142 | DC = Importer.ImportContext(D->getDeclContext()); |
| 1143 | if (!DC) |
| 1144 | return true; |
| 1145 | |
| 1146 | LexicalDC = DC; |
| 1147 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 1148 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 1149 | if (!LexicalDC) |
| 1150 | return true; |
| 1151 | } |
| 1152 | |
| 1153 | // Import the name of this declaration. |
| 1154 | Name = Importer.Import(D->getDeclName()); |
| 1155 | if (D->getDeclName() && !Name) |
| 1156 | return true; |
| 1157 | |
| 1158 | // Import the location of this declaration. |
| 1159 | Loc = Importer.Import(D->getLocation()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1160 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1161 | return false; |
| 1162 | } |
| 1163 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1164 | void ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
| 1165 | if (!FromD) |
| 1166 | return; |
| 1167 | |
| 1168 | if (!ToD) { |
| 1169 | ToD = Importer.Import(FromD); |
| 1170 | if (!ToD) |
| 1171 | return; |
| 1172 | } |
| 1173 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1174 | if (auto *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1175 | if (auto *ToRecord = cast_or_null<RecordDecl>(ToD)) { |
Sean Callanan | 19dfc93 | 2013-01-11 23:17:47 +0000 | [diff] [blame] | 1176 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && !ToRecord->getDefinition()) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1177 | ImportDefinition(FromRecord, ToRecord); |
| 1178 | } |
| 1179 | } |
| 1180 | return; |
| 1181 | } |
| 1182 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1183 | if (auto *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1184 | if (auto *ToEnum = cast_or_null<EnumDecl>(ToD)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1185 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
| 1186 | ImportDefinition(FromEnum, ToEnum); |
| 1187 | } |
| 1188 | } |
| 1189 | return; |
| 1190 | } |
| 1191 | } |
| 1192 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1193 | void |
| 1194 | ASTNodeImporter::ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 1195 | DeclarationNameInfo& To) { |
| 1196 | // NOTE: To.Name and To.Loc are already imported. |
| 1197 | // We only have to import To.LocInfo. |
| 1198 | switch (To.getName().getNameKind()) { |
| 1199 | case DeclarationName::Identifier: |
| 1200 | case DeclarationName::ObjCZeroArgSelector: |
| 1201 | case DeclarationName::ObjCOneArgSelector: |
| 1202 | case DeclarationName::ObjCMultiArgSelector: |
| 1203 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1204 | case DeclarationName::CXXDeductionGuideName: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1205 | return; |
| 1206 | |
| 1207 | case DeclarationName::CXXOperatorName: { |
| 1208 | SourceRange Range = From.getCXXOperatorNameRange(); |
| 1209 | To.setCXXOperatorNameRange(Importer.Import(Range)); |
| 1210 | return; |
| 1211 | } |
| 1212 | case DeclarationName::CXXLiteralOperatorName: { |
| 1213 | SourceLocation Loc = From.getCXXLiteralOperatorNameLoc(); |
| 1214 | To.setCXXLiteralOperatorNameLoc(Importer.Import(Loc)); |
| 1215 | return; |
| 1216 | } |
| 1217 | case DeclarationName::CXXConstructorName: |
| 1218 | case DeclarationName::CXXDestructorName: |
| 1219 | case DeclarationName::CXXConversionFunctionName: { |
| 1220 | TypeSourceInfo *FromTInfo = From.getNamedTypeInfo(); |
| 1221 | To.setNamedTypeInfo(Importer.Import(FromTInfo)); |
| 1222 | return; |
| 1223 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1224 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1225 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1228 | void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1229 | if (Importer.isMinimalImport() && !ForceImport) { |
Sean Callanan | 81d577c | 2011-07-22 23:46:03 +0000 | [diff] [blame] | 1230 | Importer.ImportContext(FromDC); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1231 | return; |
| 1232 | } |
| 1233 | |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 1234 | for (auto *From : FromDC->decls()) |
| 1235 | Importer.Import(From); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1238 | static void setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1239 | ASTImporter &Importer) { |
| 1240 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
| 1241 | auto *ToTypedef = |
| 1242 | cast_or_null<TypedefNameDecl>(Importer.Import(FromTypedef)); |
| 1243 | assert (ToTypedef && "Failed to import typedef of an anonymous structure"); |
| 1244 | |
| 1245 | To->setTypedefNameForAnonDecl(ToTypedef); |
| 1246 | } |
| 1247 | } |
| 1248 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1249 | bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1250 | ImportDefinitionKind Kind) { |
| 1251 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1252 | if (Kind == IDK_Everything) |
| 1253 | ImportDeclContext(From, /*ForceImport=*/true); |
| 1254 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1255 | return false; |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1256 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1257 | |
| 1258 | To->startDefinition(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1259 | |
| 1260 | setTypedefNameForAnonDecl(From, To, Importer); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1261 | |
| 1262 | // Add base classes. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1263 | if (auto *ToCXX = dyn_cast<CXXRecordDecl>(To)) { |
| 1264 | auto *FromCXX = cast<CXXRecordDecl>(From); |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1265 | |
| 1266 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1267 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 1268 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1269 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1270 | ToData.Aggregate = FromData.Aggregate; |
| 1271 | ToData.PlainOldData = FromData.PlainOldData; |
| 1272 | ToData.Empty = FromData.Empty; |
| 1273 | ToData.Polymorphic = FromData.Polymorphic; |
| 1274 | ToData.Abstract = FromData.Abstract; |
| 1275 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1276 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; |
| 1277 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; |
| 1278 | ToData.HasBasesWithNonStaticDataMembers = |
| 1279 | FromData.HasBasesWithNonStaticDataMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1280 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 1281 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 1282 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 1283 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1284 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1285 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1286 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1287 | ToData.HasUninitializedReferenceMember |
| 1288 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1289 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1290 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1291 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1292 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1293 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1294 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1295 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1296 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1297 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1298 | ToData.NeedOverloadResolutionForDestructor |
| 1299 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1300 | ToData.DefaultedCopyConstructorIsDeleted |
| 1301 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1302 | ToData.DefaultedMoveConstructorIsDeleted |
| 1303 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1304 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1305 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1306 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1307 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1308 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1309 | ToData.HasConstexprNonCopyMoveConstructor |
| 1310 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1311 | ToData.HasDefaultedDefaultConstructor |
| 1312 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1313 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1314 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1315 | ToData.HasConstexprDefaultConstructor |
| 1316 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1317 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1318 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1319 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1320 | ToData.UserProvidedDefaultConstructor |
| 1321 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1322 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1323 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1324 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1325 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1326 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1327 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1328 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1329 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1330 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1331 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1332 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1333 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1334 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1335 | for (const auto &Base1 : FromCXX->bases()) { |
| 1336 | QualType T = Importer.Import(Base1.getType()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1337 | if (T.isNull()) |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1338 | return true; |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1339 | |
| 1340 | SourceLocation EllipsisLoc; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1341 | if (Base1.isPackExpansion()) |
| 1342 | EllipsisLoc = Importer.Import(Base1.getEllipsisLoc()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1343 | |
| 1344 | // Ensure that we have a definition for the base. |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1345 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1346 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1347 | Bases.push_back( |
| 1348 | new (Importer.getToContext()) |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1349 | CXXBaseSpecifier(Importer.Import(Base1.getSourceRange()), |
| 1350 | Base1.isVirtual(), |
| 1351 | Base1.isBaseOfClass(), |
| 1352 | Base1.getAccessSpecifierAsWritten(), |
| 1353 | Importer.Import(Base1.getTypeSourceInfo()), |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1354 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1355 | } |
| 1356 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1357 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1358 | } |
| 1359 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1360 | if (shouldForceImportDeclContext(Kind)) |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1361 | ImportDeclContext(From, /*ForceImport=*/true); |
| 1362 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1363 | To->completeDefinition(); |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1364 | return false; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1367 | bool ASTNodeImporter::ImportDefinition(VarDecl *From, VarDecl *To, |
| 1368 | ImportDefinitionKind Kind) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1369 | if (To->getAnyInitializer()) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1370 | return false; |
| 1371 | |
| 1372 | // FIXME: Can we really import any initializer? Alternatively, we could force |
| 1373 | // ourselves to import every declaration of a variable and then only use |
| 1374 | // getInit() here. |
| 1375 | To->setInit(Importer.Import(const_cast<Expr *>(From->getAnyInitializer()))); |
| 1376 | |
| 1377 | // FIXME: Other bits to merge? |
| 1378 | |
| 1379 | return false; |
| 1380 | } |
| 1381 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1382 | bool ASTNodeImporter::ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1383 | ImportDefinitionKind Kind) { |
| 1384 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1385 | if (Kind == IDK_Everything) |
| 1386 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1387 | return false; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1388 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1389 | |
| 1390 | To->startDefinition(); |
| 1391 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1392 | setTypedefNameForAnonDecl(From, To, Importer); |
| 1393 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1394 | QualType T = Importer.Import(Importer.getFromContext().getTypeDeclType(From)); |
| 1395 | if (T.isNull()) |
| 1396 | return true; |
| 1397 | |
| 1398 | QualType ToPromotionType = Importer.Import(From->getPromotionType()); |
| 1399 | if (ToPromotionType.isNull()) |
| 1400 | return true; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1401 | |
| 1402 | if (shouldForceImportDeclContext(Kind)) |
| 1403 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1404 | |
| 1405 | // FIXME: we might need to merge the number of positive or negative bits |
| 1406 | // if the enumerator lists don't match. |
| 1407 | To->completeDefinition(T, ToPromotionType, |
| 1408 | From->getNumPositiveBits(), |
| 1409 | From->getNumNegativeBits()); |
| 1410 | return false; |
| 1411 | } |
| 1412 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1413 | TemplateParameterList *ASTNodeImporter::ImportTemplateParameterList( |
| 1414 | TemplateParameterList *Params) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1415 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); |
| 1416 | if (ImportContainerChecked(*Params, ToParams)) |
| 1417 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1418 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1419 | Expr *ToRequiresClause; |
| 1420 | if (Expr *const R = Params->getRequiresClause()) { |
| 1421 | ToRequiresClause = Importer.Import(R); |
| 1422 | if (!ToRequiresClause) |
| 1423 | return nullptr; |
| 1424 | } else { |
| 1425 | ToRequiresClause = nullptr; |
| 1426 | } |
| 1427 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1428 | return TemplateParameterList::Create(Importer.getToContext(), |
| 1429 | Importer.Import(Params->getTemplateLoc()), |
| 1430 | Importer.Import(Params->getLAngleLoc()), |
David Majnemer | 902f8c6 | 2015-12-27 07:16:27 +0000 | [diff] [blame] | 1431 | ToParams, |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1432 | Importer.Import(Params->getRAngleLoc()), |
| 1433 | ToRequiresClause); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1434 | } |
| 1435 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1436 | TemplateArgument |
| 1437 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1438 | switch (From.getKind()) { |
| 1439 | case TemplateArgument::Null: |
| 1440 | return TemplateArgument(); |
| 1441 | |
| 1442 | case TemplateArgument::Type: { |
| 1443 | QualType ToType = Importer.Import(From.getAsType()); |
| 1444 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1445 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1446 | return TemplateArgument(ToType); |
| 1447 | } |
| 1448 | |
| 1449 | case TemplateArgument::Integral: { |
| 1450 | QualType ToType = Importer.Import(From.getIntegralType()); |
| 1451 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1452 | return {}; |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 1453 | return TemplateArgument(From, ToType); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1454 | } |
| 1455 | |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1456 | case TemplateArgument::Declaration: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1457 | auto *To = cast_or_null<ValueDecl>(Importer.Import(From.getAsDecl())); |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1458 | QualType ToType = Importer.Import(From.getParamTypeForDecl()); |
| 1459 | if (!To || ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1460 | return {}; |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1461 | return TemplateArgument(To, ToType); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | case TemplateArgument::NullPtr: { |
| 1465 | QualType ToType = Importer.Import(From.getNullPtrType()); |
| 1466 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1467 | return {}; |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1468 | return TemplateArgument(ToType, /*isNullPtr*/true); |
| 1469 | } |
| 1470 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1471 | case TemplateArgument::Template: { |
| 1472 | TemplateName ToTemplate = Importer.Import(From.getAsTemplate()); |
| 1473 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1474 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1475 | |
| 1476 | return TemplateArgument(ToTemplate); |
| 1477 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1478 | |
| 1479 | case TemplateArgument::TemplateExpansion: { |
| 1480 | TemplateName ToTemplate |
| 1481 | = Importer.Import(From.getAsTemplateOrTemplatePattern()); |
| 1482 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1483 | return {}; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1484 | |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 1485 | return TemplateArgument(ToTemplate, From.getNumTemplateExpansions()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1486 | } |
| 1487 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1488 | case TemplateArgument::Expression: |
| 1489 | if (Expr *ToExpr = Importer.Import(From.getAsExpr())) |
| 1490 | return TemplateArgument(ToExpr); |
| 1491 | return TemplateArgument(); |
| 1492 | |
| 1493 | case TemplateArgument::Pack: { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1494 | SmallVector<TemplateArgument, 2> ToPack; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1495 | ToPack.reserve(From.pack_size()); |
| 1496 | if (ImportTemplateArguments(From.pack_begin(), From.pack_size(), ToPack)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1497 | return {}; |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 1498 | |
| 1499 | return TemplateArgument( |
| 1500 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1501 | } |
| 1502 | } |
| 1503 | |
| 1504 | llvm_unreachable("Invalid template argument kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1505 | } |
| 1506 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1507 | Optional<TemplateArgumentLoc> |
| 1508 | ASTNodeImporter::ImportTemplateArgumentLoc(const TemplateArgumentLoc &TALoc) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1509 | TemplateArgument Arg = ImportTemplateArgument(TALoc.getArgument()); |
| 1510 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 1511 | TemplateArgumentLocInfo ToInfo; |
| 1512 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 1513 | Expr *E = Importer.Import(FromInfo.getAsExpr()); |
| 1514 | ToInfo = TemplateArgumentLocInfo(E); |
| 1515 | if (!E) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1516 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1517 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 1518 | if (TypeSourceInfo *TSI = Importer.Import(FromInfo.getAsTypeSourceInfo())) |
| 1519 | ToInfo = TemplateArgumentLocInfo(TSI); |
| 1520 | else |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1521 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1522 | } else { |
| 1523 | ToInfo = TemplateArgumentLocInfo( |
| 1524 | Importer.Import(FromInfo.getTemplateQualifierLoc()), |
| 1525 | Importer.Import(FromInfo.getTemplateNameLoc()), |
| 1526 | Importer.Import(FromInfo.getTemplateEllipsisLoc())); |
| 1527 | } |
| 1528 | return TemplateArgumentLoc(Arg, ToInfo); |
| 1529 | } |
| 1530 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1531 | bool ASTNodeImporter::ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 1532 | unsigned NumFromArgs, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1533 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1534 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
| 1535 | TemplateArgument To = ImportTemplateArgument(FromArgs[I]); |
| 1536 | if (To.isNull() && !FromArgs[I].isNull()) |
| 1537 | return true; |
| 1538 | |
| 1539 | ToArgs.push_back(To); |
| 1540 | } |
| 1541 | |
| 1542 | return false; |
| 1543 | } |
| 1544 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 1545 | // We cannot use Optional<> pattern here and below because |
| 1546 | // TemplateArgumentListInfo's operator new is declared as deleted so it cannot |
| 1547 | // be stored in Optional. |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1548 | template <typename InContainerTy> |
| 1549 | bool ASTNodeImporter::ImportTemplateArgumentListInfo( |
| 1550 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1551 | for (const auto &FromLoc : Container) { |
| 1552 | if (auto ToLoc = ImportTemplateArgumentLoc(FromLoc)) |
| 1553 | ToTAInfo.addArgument(*ToLoc); |
| 1554 | else |
| 1555 | return true; |
| 1556 | } |
| 1557 | return false; |
| 1558 | } |
| 1559 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1560 | static StructuralEquivalenceKind |
| 1561 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 1562 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 1563 | : StructuralEquivalenceKind::Default; |
| 1564 | } |
| 1565 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1566 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1567 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1568 | // Eliminate a potential failure point where we attempt to re-import |
| 1569 | // something we're trying to import while completing ToRecord. |
| 1570 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1571 | if (ToOrigin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1572 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1573 | if (ToOriginRecord) |
| 1574 | ToRecord = ToOriginRecord; |
| 1575 | } |
| 1576 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1577 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1578 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1579 | Importer.getNonEquivalentDecls(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1580 | getStructuralEquivalenceKind(Importer), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1581 | false, Complain); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1582 | return Ctx.IsStructurallyEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1585 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 1586 | bool Complain) { |
| 1587 | StructuralEquivalenceContext Ctx( |
| 1588 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1589 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1590 | false, Complain); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1591 | return Ctx.IsStructurallyEquivalent(FromVar, ToVar); |
| 1592 | } |
| 1593 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1594 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1595 | StructuralEquivalenceContext Ctx( |
| 1596 | Importer.getFromContext(), Importer.getToContext(), |
| 1597 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1598 | return Ctx.IsStructurallyEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1601 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 1602 | FunctionTemplateDecl *To) { |
| 1603 | StructuralEquivalenceContext Ctx( |
| 1604 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1605 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1606 | false, false); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1607 | return Ctx.IsStructurallyEquivalent(From, To); |
| 1608 | } |
| 1609 | |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 1610 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 1611 | StructuralEquivalenceContext Ctx( |
| 1612 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1613 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1614 | false, false); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 1615 | return Ctx.IsStructurallyEquivalent(From, To); |
| 1616 | } |
| 1617 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1618 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1619 | EnumConstantDecl *ToEC) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1620 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 1621 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 1622 | |
| 1623 | return FromVal.isSigned() == ToVal.isSigned() && |
| 1624 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 1625 | FromVal == ToVal; |
| 1626 | } |
| 1627 | |
| 1628 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1629 | ClassTemplateDecl *To) { |
| 1630 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1631 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1632 | Importer.getNonEquivalentDecls(), |
| 1633 | getStructuralEquivalenceKind(Importer)); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1634 | return Ctx.IsStructurallyEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1635 | } |
| 1636 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1637 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 1638 | VarTemplateDecl *To) { |
| 1639 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1640 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1641 | Importer.getNonEquivalentDecls(), |
| 1642 | getStructuralEquivalenceKind(Importer)); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1643 | return Ctx.IsStructurallyEquivalent(From, To); |
| 1644 | } |
| 1645 | |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1646 | Decl *ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 1647 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1648 | << D->getDeclKindName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1649 | return nullptr; |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1650 | } |
| 1651 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1652 | Decl *ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 1653 | // Import the context of this declaration. |
| 1654 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1655 | if (!DC) |
| 1656 | return nullptr; |
| 1657 | |
| 1658 | DeclContext *LexicalDC = DC; |
| 1659 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 1660 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 1661 | if (!LexicalDC) |
| 1662 | return nullptr; |
| 1663 | } |
| 1664 | |
| 1665 | // Import the location of this declaration. |
| 1666 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1667 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1668 | EmptyDecl *ToD; |
| 1669 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc)) |
| 1670 | return ToD; |
| 1671 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1672 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1673 | LexicalDC->addDeclInternal(ToD); |
| 1674 | return ToD; |
| 1675 | } |
| 1676 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 1677 | Decl *ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 1678 | TranslationUnitDecl *ToD = |
| 1679 | Importer.getToContext().getTranslationUnitDecl(); |
| 1680 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1681 | Importer.MapImported(D, ToD); |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 1682 | |
| 1683 | return ToD; |
| 1684 | } |
| 1685 | |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1686 | Decl *ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1687 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1688 | SourceLocation ColonLoc = Importer.Import(D->getColonLoc()); |
| 1689 | |
| 1690 | // Import the context of this declaration. |
| 1691 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1692 | if (!DC) |
| 1693 | return nullptr; |
| 1694 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1695 | AccessSpecDecl *ToD; |
| 1696 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
| 1697 | DC, Loc, ColonLoc)) |
| 1698 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1699 | |
| 1700 | // Lexical DeclContext and Semantic DeclContext |
| 1701 | // is always the same for the accessSpec. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1702 | ToD->setLexicalDeclContext(DC); |
| 1703 | DC->addDeclInternal(ToD); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1704 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1705 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1706 | } |
| 1707 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1708 | Decl *ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 1709 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1710 | if (!DC) |
| 1711 | return nullptr; |
| 1712 | |
| 1713 | DeclContext *LexicalDC = DC; |
| 1714 | |
| 1715 | // Import the location of this declaration. |
| 1716 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1717 | |
| 1718 | Expr *AssertExpr = Importer.Import(D->getAssertExpr()); |
| 1719 | if (!AssertExpr) |
| 1720 | return nullptr; |
| 1721 | |
| 1722 | StringLiteral *FromMsg = D->getMessage(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1723 | auto *ToMsg = cast_or_null<StringLiteral>(Importer.Import(FromMsg)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1724 | if (!ToMsg && FromMsg) |
| 1725 | return nullptr; |
| 1726 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1727 | StaticAssertDecl *ToD; |
| 1728 | if (GetImportedOrCreateDecl( |
| 1729 | ToD, D, Importer.getToContext(), DC, Loc, AssertExpr, ToMsg, |
| 1730 | Importer.Import(D->getRParenLoc()), D->isFailed())) |
| 1731 | return ToD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1732 | |
| 1733 | ToD->setLexicalDeclContext(LexicalDC); |
| 1734 | LexicalDC->addDeclInternal(ToD); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1735 | return ToD; |
| 1736 | } |
| 1737 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1738 | Decl *ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
| 1739 | // Import the major distinguishing characteristics of this namespace. |
| 1740 | DeclContext *DC, *LexicalDC; |
| 1741 | DeclarationName Name; |
| 1742 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1743 | NamedDecl *ToD; |
| 1744 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1745 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1746 | if (ToD) |
| 1747 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1748 | |
| 1749 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1750 | if (!Name) { |
| 1751 | // This is an anonymous namespace. Adopt an existing anonymous |
| 1752 | // namespace if we can. |
| 1753 | // FIXME: Not testable. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1754 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1755 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 1756 | else |
| 1757 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 1758 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1759 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1760 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1761 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1762 | for (auto *FoundDecl : FoundDecls) { |
| 1763 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1764 | continue; |
| 1765 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1766 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1767 | MergeWithNamespace = FoundNS; |
| 1768 | ConflictingDecls.clear(); |
| 1769 | break; |
| 1770 | } |
| 1771 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1772 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 1776 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1777 | ConflictingDecls.data(), |
| 1778 | ConflictingDecls.size()); |
| 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | // Create the "to" namespace, if needed. |
| 1783 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 1784 | if (!ToNamespace) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1785 | if (GetImportedOrCreateDecl( |
| 1786 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
| 1787 | Importer.Import(D->getLocStart()), Loc, Name.getAsIdentifierInfo(), |
| 1788 | /*PrevDecl=*/nullptr)) |
| 1789 | return ToNamespace; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1790 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1791 | LexicalDC->addDeclInternal(ToNamespace); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1792 | |
| 1793 | // If this is an anonymous namespace, register it as the anonymous |
| 1794 | // namespace within its context. |
| 1795 | if (!Name) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1796 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1797 | TU->setAnonymousNamespace(ToNamespace); |
| 1798 | else |
| 1799 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 1800 | } |
| 1801 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1802 | Importer.MapImported(D, ToNamespace); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1803 | |
| 1804 | ImportDeclContext(D); |
| 1805 | |
| 1806 | return ToNamespace; |
| 1807 | } |
| 1808 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1809 | Decl *ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 1810 | // Import the major distinguishing characteristics of this namespace. |
| 1811 | DeclContext *DC, *LexicalDC; |
| 1812 | DeclarationName Name; |
| 1813 | SourceLocation Loc; |
| 1814 | NamedDecl *LookupD; |
| 1815 | if (ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 1816 | return nullptr; |
| 1817 | if (LookupD) |
| 1818 | return LookupD; |
| 1819 | |
| 1820 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 1821 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1822 | auto *TargetDecl = cast_or_null<NamespaceDecl>( |
| 1823 | Importer.Import(D->getNamespace())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1824 | if (!TargetDecl) |
| 1825 | return nullptr; |
| 1826 | |
| 1827 | IdentifierInfo *ToII = Importer.Import(D->getIdentifier()); |
| 1828 | if (!ToII) |
| 1829 | return nullptr; |
| 1830 | |
| 1831 | NestedNameSpecifierLoc ToQLoc = Importer.Import(D->getQualifierLoc()); |
| 1832 | if (D->getQualifierLoc() && !ToQLoc) |
| 1833 | return nullptr; |
| 1834 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1835 | NamespaceAliasDecl *ToD; |
| 1836 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, |
| 1837 | Importer.Import(D->getNamespaceLoc()), |
| 1838 | Importer.Import(D->getAliasLoc()), ToII, ToQLoc, |
| 1839 | Importer.Import(D->getTargetNameLoc()), |
| 1840 | TargetDecl)) |
| 1841 | return ToD; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1842 | |
| 1843 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1844 | LexicalDC->addDeclInternal(ToD); |
| 1845 | |
| 1846 | return ToD; |
| 1847 | } |
| 1848 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1849 | Decl *ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1850 | // Import the major distinguishing characteristics of this typedef. |
| 1851 | DeclContext *DC, *LexicalDC; |
| 1852 | DeclarationName Name; |
| 1853 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1854 | NamedDecl *ToD; |
| 1855 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1856 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1857 | if (ToD) |
| 1858 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1859 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1860 | // If this typedef is not in block scope, determine whether we've |
| 1861 | // seen a typedef with the same name (that we can merge with) or any |
| 1862 | // other entity by that name (which name lookup could conflict with). |
| 1863 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1864 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1865 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1866 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1867 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1868 | for (auto *FoundDecl : FoundDecls) { |
| 1869 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1870 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1871 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1872 | if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(), |
| 1873 | FoundTypedef->getUnderlyingType())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1874 | return Importer.MapImported(D, FoundTypedef); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1875 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1876 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1877 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1878 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1879 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1880 | if (!ConflictingDecls.empty()) { |
| 1881 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1882 | ConflictingDecls.data(), |
| 1883 | ConflictingDecls.size()); |
| 1884 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1885 | return nullptr; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1886 | } |
| 1887 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1888 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1889 | // Import the underlying type of this typedef; |
| 1890 | QualType T = Importer.Import(D->getUnderlyingType()); |
| 1891 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1892 | return nullptr; |
| 1893 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1894 | // Create the new typedef node. |
| 1895 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 1896 | SourceLocation StartL = Importer.Import(D->getLocStart()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1897 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1898 | TypedefNameDecl *ToTypedef; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1899 | if (IsAlias) { |
| 1900 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
| 1901 | ToTypedef, D, Importer.getToContext(), DC, StartL, Loc, |
| 1902 | Name.getAsIdentifierInfo(), TInfo)) |
| 1903 | return ToTypedef; |
| 1904 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
| 1905 | ToTypedef, D, Importer.getToContext(), DC, StartL, Loc, |
| 1906 | Name.getAsIdentifierInfo(), TInfo)) |
| 1907 | return ToTypedef; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1908 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1909 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1910 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1911 | |
| 1912 | // Templated declarations should not appear in DeclContext. |
| 1913 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 1914 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 1915 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1916 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1917 | return ToTypedef; |
| 1918 | } |
| 1919 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1920 | Decl *ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
| 1921 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 1922 | } |
| 1923 | |
| 1924 | Decl *ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| 1925 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 1926 | } |
| 1927 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1928 | Decl *ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| 1929 | // Import the major distinguishing characteristics of this typedef. |
| 1930 | DeclContext *DC, *LexicalDC; |
| 1931 | DeclarationName Name; |
| 1932 | SourceLocation Loc; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1933 | NamedDecl *FoundD; |
| 1934 | if (ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1935 | return nullptr; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1936 | if (FoundD) |
| 1937 | return FoundD; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1938 | |
| 1939 | // If this typedef is not in block scope, determine whether we've |
| 1940 | // seen a typedef with the same name (that we can merge with) or any |
| 1941 | // other entity by that name (which name lookup could conflict with). |
| 1942 | if (!DC->isFunctionOrMethod()) { |
| 1943 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 1944 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 1945 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 1946 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1947 | for (auto *FoundDecl : FoundDecls) { |
| 1948 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1949 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1950 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1951 | return Importer.MapImported(D, FoundAlias); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1952 | ConflictingDecls.push_back(FoundDecl); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | if (!ConflictingDecls.empty()) { |
| 1956 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1957 | ConflictingDecls.data(), |
| 1958 | ConflictingDecls.size()); |
| 1959 | if (!Name) |
| 1960 | return nullptr; |
| 1961 | } |
| 1962 | } |
| 1963 | |
| 1964 | TemplateParameterList *Params = ImportTemplateParameterList( |
| 1965 | D->getTemplateParameters()); |
| 1966 | if (!Params) |
| 1967 | return nullptr; |
| 1968 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1969 | auto *TemplDecl = cast_or_null<TypeAliasDecl>( |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1970 | Importer.Import(D->getTemplatedDecl())); |
| 1971 | if (!TemplDecl) |
| 1972 | return nullptr; |
| 1973 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 1974 | TypeAliasTemplateDecl *ToAlias; |
| 1975 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
| 1976 | Name, Params, TemplDecl)) |
| 1977 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1978 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1979 | TemplDecl->setDescribedAliasTemplate(ToAlias); |
| 1980 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1981 | ToAlias->setAccess(D->getAccess()); |
| 1982 | ToAlias->setLexicalDeclContext(LexicalDC); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1983 | LexicalDC->addDeclInternal(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1984 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1985 | } |
| 1986 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1987 | Decl *ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
| 1988 | // Import the major distinguishing characteristics of this label. |
| 1989 | DeclContext *DC, *LexicalDC; |
| 1990 | DeclarationName Name; |
| 1991 | SourceLocation Loc; |
| 1992 | NamedDecl *ToD; |
| 1993 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 1994 | return nullptr; |
| 1995 | if (ToD) |
| 1996 | return ToD; |
| 1997 | |
| 1998 | assert(LexicalDC->isFunctionOrMethod()); |
| 1999 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2000 | LabelDecl *ToLabel; |
| 2001 | if (D->isGnuLocal() |
| 2002 | ? GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, |
| 2003 | Importer.Import(D->getLocation()), |
| 2004 | Name.getAsIdentifierInfo(), |
| 2005 | Importer.Import(D->getLocStart())) |
| 2006 | : GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, |
| 2007 | Importer.Import(D->getLocation()), |
| 2008 | Name.getAsIdentifierInfo())) |
| 2009 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2010 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2011 | auto *Label = cast_or_null<LabelStmt>(Importer.Import(D->getStmt())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2012 | if (!Label) |
| 2013 | return nullptr; |
| 2014 | |
| 2015 | ToLabel->setStmt(Label); |
| 2016 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2017 | LexicalDC->addDeclInternal(ToLabel); |
| 2018 | return ToLabel; |
| 2019 | } |
| 2020 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2021 | Decl *ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
| 2022 | // Import the major distinguishing characteristics of this enum. |
| 2023 | DeclContext *DC, *LexicalDC; |
| 2024 | DeclarationName Name; |
| 2025 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2026 | NamedDecl *ToD; |
| 2027 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2028 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2029 | if (ToD) |
| 2030 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2031 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2032 | // Figure out what enum name we're looking for. |
| 2033 | unsigned IDNS = Decl::IDNS_Tag; |
| 2034 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2035 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 2036 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2037 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2038 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2039 | IDNS |= Decl::IDNS_Ordinary; |
| 2040 | |
| 2041 | // We may already have an enum of the same name; try to find and match it. |
| 2042 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2043 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2044 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 2045 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2046 | for (auto *FoundDecl : FoundDecls) { |
| 2047 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2048 | continue; |
| 2049 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2050 | Decl *Found = FoundDecl; |
| 2051 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2052 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2053 | Found = Tag->getDecl(); |
| 2054 | } |
| 2055 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2056 | if (auto *FoundEnum = dyn_cast<EnumDecl>(Found)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2057 | if (IsStructuralMatch(D, FoundEnum)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2058 | return Importer.MapImported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2059 | } |
| 2060 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2061 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | if (!ConflictingDecls.empty()) { |
| 2065 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2066 | ConflictingDecls.data(), |
| 2067 | ConflictingDecls.size()); |
| 2068 | } |
| 2069 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2070 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2071 | // Create the enum declaration. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2072 | EnumDecl *D2; |
| 2073 | if (GetImportedOrCreateDecl( |
| 2074 | D2, D, Importer.getToContext(), DC, Importer.Import(D->getLocStart()), |
| 2075 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), |
| 2076 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2077 | return D2; |
| 2078 | |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 2079 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2080 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2081 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2082 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2083 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2084 | |
| 2085 | // Import the integer type. |
| 2086 | QualType ToIntegerType = Importer.Import(D->getIntegerType()); |
| 2087 | if (ToIntegerType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2088 | return nullptr; |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2089 | D2->setIntegerType(ToIntegerType); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2090 | |
| 2091 | // Import the definition |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 2092 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2093 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2094 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2095 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2096 | } |
| 2097 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2098 | Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
| 2099 | // If this record has a definition in the translation unit we're coming from, |
| 2100 | // but this particular declaration is not that definition, import the |
| 2101 | // definition and map to that. |
Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 2102 | TagDecl *Definition = D->getDefinition(); |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2103 | if (Definition && Definition != D && |
| 2104 | // In contrast to a normal CXXRecordDecl, the implicit |
| 2105 | // CXXRecordDecl of ClassTemplateSpecializationDecl is its redeclaration. |
| 2106 | // The definition of the implicit CXXRecordDecl in this case is the |
| 2107 | // ClassTemplateSpecializationDecl itself. Thus, we start with an extra |
| 2108 | // condition in order to be able to import the implict Decl. |
| 2109 | !D->isImplicit()) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2110 | Decl *ImportedDef = Importer.Import(Definition); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2111 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2112 | return nullptr; |
| 2113 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2114 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2115 | } |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2116 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2117 | // Import the major distinguishing characteristics of this record. |
| 2118 | DeclContext *DC, *LexicalDC; |
| 2119 | DeclarationName Name; |
| 2120 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2121 | NamedDecl *ToD; |
| 2122 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2123 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2124 | if (ToD) |
| 2125 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2126 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2127 | // Figure out what structure name we're looking for. |
| 2128 | unsigned IDNS = Decl::IDNS_Tag; |
| 2129 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2130 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 2131 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2132 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2133 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2134 | IDNS |= Decl::IDNS_Ordinary; |
| 2135 | |
| 2136 | // We may already have a record of the same name; try to find and match it. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2137 | RecordDecl *AdoptDecl = nullptr; |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2138 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2139 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2140 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2141 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 2142 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2143 | |
| 2144 | if (!FoundDecls.empty()) { |
| 2145 | // We're going to have to compare D against potentially conflicting Decls, so complete it. |
| 2146 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2147 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2148 | } |
| 2149 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2150 | for (auto *FoundDecl : FoundDecls) { |
| 2151 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2152 | continue; |
| 2153 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2154 | Decl *Found = FoundDecl; |
| 2155 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2156 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2157 | Found = Tag->getDecl(); |
| 2158 | } |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2159 | |
| 2160 | if (D->getDescribedTemplate()) { |
| 2161 | if (auto *Template = dyn_cast<ClassTemplateDecl>(Found)) |
| 2162 | Found = Template->getTemplatedDecl(); |
| 2163 | else |
| 2164 | continue; |
| 2165 | } |
| 2166 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2167 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Aleksei Sidorin | 499de6c | 2018-04-05 15:31:49 +0000 | [diff] [blame] | 2168 | if (!SearchName) { |
Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2169 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2170 | continue; |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2171 | } |
| 2172 | |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2173 | PrevDecl = FoundRecord; |
| 2174 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2175 | if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2176 | if ((SearchName && !D->isCompleteDefinition()) |
| 2177 | || (D->isCompleteDefinition() && |
| 2178 | D->isAnonymousStructOrUnion() |
| 2179 | == FoundDef->isAnonymousStructOrUnion() && |
| 2180 | IsStructuralMatch(D, FoundDef))) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2181 | // The record types structurally match, or the "from" translation |
| 2182 | // unit only had a forward declaration anyway; call it the same |
| 2183 | // function. |
| 2184 | // FIXME: For C++, we should also merge methods here. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2185 | return Importer.MapImported(D, FoundDef); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2186 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2187 | } else if (!D->isCompleteDefinition()) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2188 | // We have a forward declaration of this type, so adopt that forward |
| 2189 | // declaration rather than building a new one. |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2190 | |
| 2191 | // If one or both can be completed from external storage then try one |
| 2192 | // last time to complete and compare them before doing this. |
| 2193 | |
| 2194 | if (FoundRecord->hasExternalLexicalStorage() && |
| 2195 | !FoundRecord->isCompleteDefinition()) |
| 2196 | FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord); |
| 2197 | if (D->hasExternalLexicalStorage()) |
| 2198 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2199 | |
| 2200 | if (FoundRecord->isCompleteDefinition() && |
| 2201 | D->isCompleteDefinition() && |
| 2202 | !IsStructuralMatch(D, FoundRecord)) |
| 2203 | continue; |
| 2204 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2205 | AdoptDecl = FoundRecord; |
| 2206 | continue; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2207 | } else if (!SearchName) { |
| 2208 | continue; |
| 2209 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2210 | } |
| 2211 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2212 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2213 | } |
| 2214 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2215 | if (!ConflictingDecls.empty() && SearchName) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2216 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2217 | ConflictingDecls.data(), |
| 2218 | ConflictingDecls.size()); |
| 2219 | } |
| 2220 | } |
| 2221 | |
| 2222 | // Create the record declaration. |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2223 | RecordDecl *D2 = AdoptDecl; |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 2224 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2225 | if (!D2) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2226 | CXXRecordDecl *D2CXX = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2227 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2228 | if (DCXX->isLambda()) { |
| 2229 | TypeSourceInfo *TInfo = Importer.Import(DCXX->getLambdaTypeInfo()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2230 | if (GetImportedOrCreateSpecialDecl( |
| 2231 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
| 2232 | DC, TInfo, Loc, DCXX->isDependentLambda(), |
| 2233 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2234 | return D2CXX; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2235 | Decl *CDecl = Importer.Import(DCXX->getLambdaContextDecl()); |
| 2236 | if (DCXX->getLambdaContextDecl() && !CDecl) |
| 2237 | return nullptr; |
Sean Callanan | 041cceb | 2016-05-14 05:43:57 +0000 | [diff] [blame] | 2238 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), CDecl); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2239 | } else if (DCXX->isInjectedClassName()) { |
| 2240 | // We have to be careful to do a similar dance to the one in |
| 2241 | // Sema::ActOnStartCXXMemberDeclarations |
| 2242 | CXXRecordDecl *const PrevDecl = nullptr; |
| 2243 | const bool DelayTypeCreation = true; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2244 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2245 | D->getTagKind(), DC, StartLoc, Loc, |
| 2246 | Name.getAsIdentifierInfo(), PrevDecl, |
| 2247 | DelayTypeCreation)) |
| 2248 | return D2CXX; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2249 | Importer.getToContext().getTypeDeclType( |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2250 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2251 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2252 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2253 | D->getTagKind(), DC, StartLoc, Loc, |
| 2254 | Name.getAsIdentifierInfo(), |
| 2255 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2256 | return D2CXX; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2257 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2258 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2259 | D2 = D2CXX; |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2260 | D2->setAccess(D->getAccess()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2261 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | de8bf26 | 2018-05-17 09:46:07 +0000 | [diff] [blame] | 2262 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2263 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2264 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2265 | if (ClassTemplateDecl *FromDescribed = |
| 2266 | DCXX->getDescribedClassTemplate()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2267 | auto *ToDescribed = cast_or_null<ClassTemplateDecl>( |
| 2268 | Importer.Import(FromDescribed)); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2269 | if (!ToDescribed) |
| 2270 | return nullptr; |
| 2271 | D2CXX->setDescribedClassTemplate(ToDescribed); |
Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2272 | if (!DCXX->isInjectedClassName()) { |
| 2273 | // In a record describing a template the type should be an |
| 2274 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2275 | // previously set type to the correct value here (ToDescribed is not |
| 2276 | // available at record create). |
| 2277 | // FIXME: The previous type is cleared but not removed from |
| 2278 | // ASTContext's internal storage. |
| 2279 | CXXRecordDecl *Injected = nullptr; |
| 2280 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2281 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2282 | if (Record && Record->isInjectedClassName()) { |
| 2283 | Injected = Record; |
| 2284 | break; |
| 2285 | } |
| 2286 | } |
| 2287 | D2CXX->setTypeForDecl(nullptr); |
| 2288 | Importer.getToContext().getInjectedClassNameType(D2CXX, |
| 2289 | ToDescribed->getInjectedClassNameSpecialization()); |
| 2290 | if (Injected) { |
| 2291 | Injected->setTypeForDecl(nullptr); |
| 2292 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2293 | } |
| 2294 | } |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2295 | } else if (MemberSpecializationInfo *MemberInfo = |
| 2296 | DCXX->getMemberSpecializationInfo()) { |
| 2297 | TemplateSpecializationKind SK = |
| 2298 | MemberInfo->getTemplateSpecializationKind(); |
| 2299 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2300 | auto *ToInst = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2301 | cast_or_null<CXXRecordDecl>(Importer.Import(FromInst)); |
| 2302 | if (FromInst && !ToInst) |
| 2303 | return nullptr; |
| 2304 | D2CXX->setInstantiationOfMemberClass(ToInst, SK); |
| 2305 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2306 | Importer.Import(MemberInfo->getPointOfInstantiation())); |
| 2307 | } |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2308 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2309 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
| 2310 | D->getTagKind(), DC, StartLoc, Loc, |
| 2311 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2312 | return D2; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2313 | D2->setLexicalDeclContext(LexicalDC); |
| 2314 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2315 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2316 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2317 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2318 | if (D->isAnonymousStructOrUnion()) |
| 2319 | D2->setAnonymousStructOrUnion(true); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2320 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2321 | |
| 2322 | Importer.MapImported(D, D2); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2323 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 2324 | if (D->isCompleteDefinition() && ImportDefinition(D, D2, IDK_Default)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2325 | return nullptr; |
| 2326 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2327 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2328 | } |
| 2329 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2330 | Decl *ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| 2331 | // Import the major distinguishing characteristics of this enumerator. |
| 2332 | DeclContext *DC, *LexicalDC; |
| 2333 | DeclarationName Name; |
| 2334 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2335 | NamedDecl *ToD; |
| 2336 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2337 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2338 | if (ToD) |
| 2339 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2340 | |
| 2341 | QualType T = Importer.Import(D->getType()); |
| 2342 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2343 | return nullptr; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2344 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2345 | // Determine whether there are any other declarations with the same name and |
| 2346 | // in the same context. |
| 2347 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2348 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2349 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2350 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2351 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2352 | for (auto *FoundDecl : FoundDecls) { |
| 2353 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2354 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2355 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2356 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2357 | if (IsStructuralMatch(D, FoundEnumConstant)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2358 | return Importer.MapImported(D, FoundEnumConstant); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2359 | } |
| 2360 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2361 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | if (!ConflictingDecls.empty()) { |
| 2365 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2366 | ConflictingDecls.data(), |
| 2367 | ConflictingDecls.size()); |
| 2368 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2369 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2370 | } |
| 2371 | } |
| 2372 | |
| 2373 | Expr *Init = Importer.Import(D->getInitExpr()); |
| 2374 | if (D->getInitExpr() && !Init) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2375 | return nullptr; |
| 2376 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2377 | EnumConstantDecl *ToEnumerator; |
| 2378 | if (GetImportedOrCreateDecl( |
| 2379 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
| 2380 | Name.getAsIdentifierInfo(), T, Init, D->getInitVal())) |
| 2381 | return ToEnumerator; |
| 2382 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2383 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2384 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2385 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2386 | return ToEnumerator; |
| 2387 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2388 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2389 | bool ASTNodeImporter::ImportTemplateInformation(FunctionDecl *FromFD, |
| 2390 | FunctionDecl *ToFD) { |
| 2391 | switch (FromFD->getTemplatedKind()) { |
| 2392 | case FunctionDecl::TK_NonTemplate: |
| 2393 | case FunctionDecl::TK_FunctionTemplate: |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2394 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2395 | |
| 2396 | case FunctionDecl::TK_MemberSpecialization: { |
| 2397 | auto *InstFD = cast_or_null<FunctionDecl>( |
| 2398 | Importer.Import(FromFD->getInstantiatedFromMemberFunction())); |
| 2399 | if (!InstFD) |
| 2400 | return true; |
| 2401 | |
| 2402 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
| 2403 | SourceLocation POI = Importer.Import( |
| 2404 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation()); |
| 2405 | ToFD->setInstantiationOfMemberFunction(InstFD, TSK); |
| 2406 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2407 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2411 | FunctionTemplateDecl* Template; |
| 2412 | OptionalTemplateArgsTy ToTemplArgs; |
| 2413 | std::tie(Template, ToTemplArgs) = |
| 2414 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| 2415 | if (!Template || !ToTemplArgs) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2416 | return true; |
| 2417 | |
| 2418 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2419 | Importer.getToContext(), *ToTemplArgs); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2420 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2421 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2422 | TemplateArgumentListInfo ToTAInfo; |
| 2423 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2424 | if (FromTAArgsAsWritten) |
| 2425 | if (ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2426 | return true; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2427 | |
| 2428 | SourceLocation POI = Importer.Import(FTSInfo->getPointOfInstantiation()); |
| 2429 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2430 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2431 | ToFD->setFunctionTemplateSpecialization( |
| 2432 | Template, ToTAList, /* InsertPos= */ nullptr, |
| 2433 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, POI); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2434 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 2438 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 2439 | UnresolvedSet<8> TemplDecls; |
| 2440 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 2441 | for (unsigned I = 0; I < NumTemplates; I++) { |
| 2442 | if (auto *ToFTD = cast_or_null<FunctionTemplateDecl>( |
| 2443 | Importer.Import(FromInfo->getTemplate(I)))) |
| 2444 | TemplDecls.addDecl(ToFTD); |
| 2445 | else |
| 2446 | return true; |
| 2447 | } |
| 2448 | |
| 2449 | // Import TemplateArgumentListInfo. |
| 2450 | TemplateArgumentListInfo ToTAInfo; |
| 2451 | if (ImportTemplateArgumentListInfo( |
| 2452 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 2453 | llvm::makeArrayRef(FromInfo->getTemplateArgs(), |
| 2454 | FromInfo->getNumTemplateArgs()), |
| 2455 | ToTAInfo)) |
| 2456 | return true; |
| 2457 | |
| 2458 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 2459 | TemplDecls, ToTAInfo); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2460 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2461 | } |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2462 | } |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2463 | llvm_unreachable("All cases should be covered!"); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2464 | } |
| 2465 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2466 | FunctionDecl * |
| 2467 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
| 2468 | FunctionTemplateDecl* Template; |
| 2469 | OptionalTemplateArgsTy ToTemplArgs; |
| 2470 | std::tie(Template, ToTemplArgs) = |
| 2471 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| 2472 | if (!Template || !ToTemplArgs) |
| 2473 | return nullptr; |
| 2474 | |
| 2475 | void *InsertPos = nullptr; |
| 2476 | auto *FoundSpec = Template->findSpecialization(*ToTemplArgs, InsertPos); |
| 2477 | return FoundSpec; |
| 2478 | } |
| 2479 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2480 | Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2481 | |
| 2482 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 2483 | auto RedeclIt = Redecls.begin(); |
| 2484 | // Import the first part of the decl chain. I.e. import all previous |
| 2485 | // declarations starting from the canonical decl. |
| 2486 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) |
| 2487 | if (!Importer.Import(*RedeclIt)) |
| 2488 | return nullptr; |
| 2489 | assert(*RedeclIt == D); |
| 2490 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2491 | // Import the major distinguishing characteristics of this function. |
| 2492 | DeclContext *DC, *LexicalDC; |
| 2493 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2494 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2495 | NamedDecl *ToD; |
| 2496 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2497 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2498 | if (ToD) |
| 2499 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2500 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2501 | const FunctionDecl *FoundByLookup = nullptr; |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2502 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2503 | // If this is a function template specialization, then try to find the same |
| 2504 | // existing specialization in the "to" context. The localUncachedLookup |
| 2505 | // below will not find any specialization, but would find the primary |
| 2506 | // template; thus, we have to skip normal lookup in case of specializations. |
| 2507 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 2508 | if (D->getTemplatedKind() == |
| 2509 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
| 2510 | if (FunctionDecl *FoundFunction = FindFunctionTemplateSpecialization(D)) { |
| 2511 | if (D->doesThisDeclarationHaveABody() && |
| 2512 | FoundFunction->hasBody()) |
| 2513 | return Importer.Imported(D, FoundFunction); |
| 2514 | FoundByLookup = FoundFunction; |
| 2515 | } |
| 2516 | } |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2517 | // Try to find a function in our own ("to") context with the same name, same |
| 2518 | // type, and in the same context as the function we're importing. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2519 | else if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2520 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2521 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2522 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2523 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2524 | for (auto *FoundDecl : FoundDecls) { |
| 2525 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2526 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2527 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2528 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 2529 | if (FoundFunction->hasExternalFormalLinkage() && |
| 2530 | D->hasExternalFormalLinkage()) { |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2531 | if (IsStructuralMatch(D, FoundFunction)) { |
| 2532 | const FunctionDecl *Definition = nullptr; |
| 2533 | if (D->doesThisDeclarationHaveABody() && |
| 2534 | FoundFunction->hasBody(Definition)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2535 | return Importer.MapImported( |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2536 | D, const_cast<FunctionDecl *>(Definition)); |
| 2537 | } |
| 2538 | FoundByLookup = FoundFunction; |
| 2539 | break; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2540 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2541 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2542 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 2543 | // Sema::IsOverload out to the AST library. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2544 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2545 | // Function overloading is okay in C++. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2546 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2547 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2548 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2549 | // Complain about inconsistent function types. |
| 2550 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2551 | << Name << D->getType() << FoundFunction->getType(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2552 | Importer.ToDiag(FoundFunction->getLocation(), |
| 2553 | diag::note_odr_value_here) |
| 2554 | << FoundFunction->getType(); |
| 2555 | } |
| 2556 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2557 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2558 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2559 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2560 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2561 | if (!ConflictingDecls.empty()) { |
| 2562 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2563 | ConflictingDecls.data(), |
| 2564 | ConflictingDecls.size()); |
| 2565 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2566 | return nullptr; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2567 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2568 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2569 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2570 | DeclarationNameInfo NameInfo(Name, Loc); |
| 2571 | // Import additional name location/type info. |
| 2572 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 2573 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2574 | QualType FromTy = D->getType(); |
| 2575 | bool usedDifferentExceptionSpec = false; |
| 2576 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2577 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2578 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 2579 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 2580 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 2581 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 2582 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 2583 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 2584 | FromEPI.ExceptionSpec.SourceTemplate || |
| 2585 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2586 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 2587 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2588 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2589 | usedDifferentExceptionSpec = true; |
| 2590 | } |
| 2591 | } |
| 2592 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2593 | // Import the type. |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2594 | QualType T = Importer.Import(FromTy); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2595 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2596 | return nullptr; |
| 2597 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2598 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2599 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2600 | for (auto P : D->parameters()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2601 | auto *ToP = cast_or_null<ParmVarDecl>(Importer.Import(P)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2602 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2603 | return nullptr; |
| 2604 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2605 | Parameters.push_back(ToP); |
| 2606 | } |
| 2607 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2608 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2609 | if (D->getTypeSourceInfo() && !TInfo) |
| 2610 | return nullptr; |
| 2611 | |
| 2612 | // Create the imported function. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2613 | FunctionDecl *ToFunction = nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2614 | SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2615 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2616 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
| 2617 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 2618 | InnerLocStart, NameInfo, T, TInfo, FromConstructor->isExplicit(), |
| 2619 | D->isInlineSpecified(), D->isImplicit(), D->isConstexpr())) |
| 2620 | return ToFunction; |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2621 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 2622 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2623 | for (auto *I : FromConstructor->inits()) { |
| 2624 | auto *ToI = cast_or_null<CXXCtorInitializer>(Importer.Import(I)); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2625 | if (!ToI && I) |
| 2626 | return nullptr; |
| 2627 | CtorInitializers.push_back(ToI); |
| 2628 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2629 | auto **Memory = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2630 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 2631 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2632 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2633 | ToCtor->setCtorInitializers(Memory); |
| 2634 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 2635 | } |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2636 | } else if (isa<CXXDestructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2637 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
| 2638 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 2639 | InnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 2640 | D->isImplicit())) |
| 2641 | return ToFunction; |
| 2642 | } else if (CXXConversionDecl *FromConversion = |
| 2643 | dyn_cast<CXXConversionDecl>(D)) { |
| 2644 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 2645 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 2646 | InnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 2647 | FromConversion->isExplicit(), D->isConstexpr(), SourceLocation())) |
| 2648 | return ToFunction; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2649 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2650 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 2651 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 2652 | InnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
| 2653 | Method->isInlineSpecified(), D->isConstexpr(), SourceLocation())) |
| 2654 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2655 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2656 | if (GetImportedOrCreateDecl(ToFunction, D, Importer.getToContext(), DC, |
| 2657 | InnerLocStart, NameInfo, T, TInfo, |
| 2658 | D->getStorageClass(), D->isInlineSpecified(), |
| 2659 | D->hasWrittenPrototype(), D->isConstexpr())) |
| 2660 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2661 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 2662 | |
| 2663 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2664 | ToFunction->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2665 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2666 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 2667 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 2668 | ToFunction->setTrivial(D->isTrivial()); |
| 2669 | ToFunction->setPure(D->isPure()); |
Rafael Stahl | a001047 | 2018-07-09 08:40:17 +0000 | [diff] [blame] | 2670 | ToFunction->setRangeEnd(Importer.Import(D->getLocEnd())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2671 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2672 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2673 | for (auto *Param : Parameters) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2674 | Param->setOwningFunction(ToFunction); |
| 2675 | ToFunction->addDeclInternal(Param); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2676 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 2677 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2678 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2679 | if (FoundByLookup) { |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2680 | auto *Recent = const_cast<FunctionDecl *>( |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2681 | FoundByLookup->getMostRecentDecl()); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2682 | ToFunction->setPreviousDecl(Recent); |
| 2683 | } |
| 2684 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2685 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 2686 | // params it refers to. |
| 2687 | if (TInfo) { |
| 2688 | if (auto ProtoLoc = |
| 2689 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 2690 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 2691 | ProtoLoc.setParam(I, Parameters[I]); |
| 2692 | } |
| 2693 | } |
| 2694 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2695 | if (usedDifferentExceptionSpec) { |
| 2696 | // Update FunctionProtoType::ExtProtoInfo. |
| 2697 | QualType T = Importer.Import(D->getType()); |
| 2698 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2699 | return nullptr; |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2700 | ToFunction->setType(T); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 2701 | } |
| 2702 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2703 | if (D->doesThisDeclarationHaveABody()) { |
| 2704 | if (Stmt *FromBody = D->getBody()) { |
| 2705 | if (Stmt *ToBody = Importer.Import(FromBody)) { |
| 2706 | ToFunction->setBody(ToBody); |
| 2707 | } |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2708 | } |
| 2709 | } |
| 2710 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2711 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2712 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2713 | // If it is a template, import all related things. |
| 2714 | if (ImportTemplateInformation(D, ToFunction)) |
| 2715 | return nullptr; |
| 2716 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2717 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); |
| 2718 | |
| 2719 | // TODO Can we generalize this approach to other AST nodes as well? |
| 2720 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 2721 | DC->addDeclInternal(ToFunction); |
| 2722 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2723 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2724 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2725 | // Friend declaration's lexical context is the befriending class, but the |
| 2726 | // semantic context is the enclosing scope of the befriending class. |
| 2727 | // We want the friend functions to be found in the semantic context by lookup. |
| 2728 | // FIXME should we handle this generically in VisitFriendDecl? |
| 2729 | // In Other cases when LexicalDC != DC we don't want it to be added, |
| 2730 | // e.g out-of-class definitions like void B::f() {} . |
| 2731 | if (LexicalDC != DC && IsFriend) { |
| 2732 | DC->makeDeclVisibleInContext(ToFunction); |
| 2733 | } |
| 2734 | |
| 2735 | // Import the rest of the chain. I.e. import all subsequent declarations. |
| 2736 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) |
| 2737 | if (!Importer.Import(*RedeclIt)) |
| 2738 | return nullptr; |
| 2739 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 2740 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 2741 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 2742 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2743 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2744 | } |
| 2745 | |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2746 | Decl *ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| 2747 | return VisitFunctionDecl(D); |
| 2748 | } |
| 2749 | |
| 2750 | Decl *ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| 2751 | return VisitCXXMethodDecl(D); |
| 2752 | } |
| 2753 | |
| 2754 | Decl *ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| 2755 | return VisitCXXMethodDecl(D); |
| 2756 | } |
| 2757 | |
| 2758 | Decl *ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| 2759 | return VisitCXXMethodDecl(D); |
| 2760 | } |
| 2761 | |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2762 | static unsigned getFieldIndex(Decl *F) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2763 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2764 | if (!Owner) |
| 2765 | return 0; |
| 2766 | |
| 2767 | unsigned Index = 1; |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2768 | for (const auto *D : Owner->noload_decls()) { |
| 2769 | if (D == F) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2770 | return Index; |
| 2771 | |
| 2772 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 2773 | ++Index; |
| 2774 | } |
| 2775 | |
| 2776 | return Index; |
| 2777 | } |
| 2778 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2779 | Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
| 2780 | // Import the major distinguishing characteristics of a variable. |
| 2781 | DeclContext *DC, *LexicalDC; |
| 2782 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2783 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2784 | NamedDecl *ToD; |
| 2785 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2786 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2787 | if (ToD) |
| 2788 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2789 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2790 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2791 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2792 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2793 | for (auto *FoundDecl : FoundDecls) { |
| 2794 | if (auto *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2795 | // For anonymous fields, match up by index. |
| 2796 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2797 | continue; |
| 2798 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2799 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2800 | FoundField->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2801 | Importer.MapImported(D, FoundField); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2802 | return FoundField; |
| 2803 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2804 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2805 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2806 | << Name << D->getType() << FoundField->getType(); |
| 2807 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2808 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2809 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2810 | } |
| 2811 | } |
| 2812 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2813 | // Import the type. |
| 2814 | QualType T = Importer.Import(D->getType()); |
| 2815 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2816 | return nullptr; |
| 2817 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2818 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2819 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 2820 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2821 | return nullptr; |
| 2822 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2823 | FieldDecl *ToField; |
| 2824 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
| 2825 | Importer.Import(D->getInnerLocStart()), Loc, |
| 2826 | Name.getAsIdentifierInfo(), T, TInfo, BitWidth, |
| 2827 | D->isMutable(), D->getInClassInitStyle())) |
| 2828 | return ToField; |
| 2829 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2830 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2831 | ToField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 3a83ea7 | 2016-03-03 02:22:05 +0000 | [diff] [blame] | 2832 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
Sean Callanan | bb33f58 | 2016-03-03 01:21:28 +0000 | [diff] [blame] | 2833 | Expr *ToInitializer = Importer.Import(FromInitializer); |
| 2834 | if (ToInitializer) |
| 2835 | ToField->setInClassInitializer(ToInitializer); |
| 2836 | else |
| 2837 | return nullptr; |
| 2838 | } |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2839 | ToField->setImplicit(D->isImplicit()); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2840 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2841 | return ToField; |
| 2842 | } |
| 2843 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2844 | Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| 2845 | // Import the major distinguishing characteristics of a variable. |
| 2846 | DeclContext *DC, *LexicalDC; |
| 2847 | DeclarationName Name; |
| 2848 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2849 | NamedDecl *ToD; |
| 2850 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2851 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2852 | if (ToD) |
| 2853 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2854 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2855 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2856 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2857 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2858 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2859 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2860 | // For anonymous indirect fields, match up by index. |
| 2861 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2862 | continue; |
| 2863 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2864 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2865 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 2866 | !Name.isEmpty())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2867 | Importer.MapImported(D, FoundField); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2868 | return FoundField; |
| 2869 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2870 | |
| 2871 | // If there are more anonymous fields to check, continue. |
| 2872 | if (!Name && I < N-1) |
| 2873 | continue; |
| 2874 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2875 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2876 | << Name << D->getType() << FoundField->getType(); |
| 2877 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2878 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2879 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2880 | } |
| 2881 | } |
| 2882 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2883 | // Import the type. |
| 2884 | QualType T = Importer.Import(D->getType()); |
| 2885 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2886 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2887 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2888 | auto **NamedChain = |
| 2889 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2890 | |
| 2891 | unsigned i = 0; |
Aaron Ballman | 29c9460 | 2014-03-07 18:36:15 +0000 | [diff] [blame] | 2892 | for (auto *PI : D->chain()) { |
Aaron Ballman | 1391608 | 2014-03-07 18:11:58 +0000 | [diff] [blame] | 2893 | Decl *D = Importer.Import(PI); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2894 | if (!D) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2895 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2896 | NamedChain[i++] = cast<NamedDecl>(D); |
| 2897 | } |
| 2898 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2899 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 2900 | IndirectFieldDecl *ToIndirectField; |
| 2901 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
| 2902 | Loc, Name.getAsIdentifierInfo(), T, CH)) |
| 2903 | // FIXME here we leak `NamedChain` which is allocated before |
| 2904 | return ToIndirectField; |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2905 | |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 2906 | for (const auto *A : D->attrs()) |
| 2907 | ToIndirectField->addAttr(Importer.Import(A)); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2908 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2909 | ToIndirectField->setAccess(D->getAccess()); |
| 2910 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2911 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2912 | return ToIndirectField; |
| 2913 | } |
| 2914 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2915 | Decl *ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
| 2916 | // Import the major distinguishing characteristics of a declaration. |
| 2917 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 2918 | DeclContext *LexicalDC = D->getDeclContext() == D->getLexicalDeclContext() |
| 2919 | ? DC : Importer.ImportContext(D->getLexicalDeclContext()); |
| 2920 | if (!DC || !LexicalDC) |
| 2921 | return nullptr; |
| 2922 | |
| 2923 | // Determine whether we've already imported this decl. |
| 2924 | // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup. |
| 2925 | auto *RD = cast<CXXRecordDecl>(DC); |
| 2926 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
| 2927 | StructuralEquivalenceContext Context( |
| 2928 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2929 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 2930 | false, false); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2931 | |
| 2932 | while (ImportedFriend) { |
| 2933 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
| 2934 | if (Context.IsStructurallyEquivalent(D->getFriendDecl(), |
| 2935 | ImportedFriend->getFriendDecl())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2936 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2937 | |
| 2938 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 2939 | if (Importer.IsStructurallyEquivalent( |
| 2940 | D->getFriendType()->getType(), |
| 2941 | ImportedFriend->getFriendType()->getType(), true)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2942 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2943 | } |
| 2944 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 2945 | } |
| 2946 | |
| 2947 | // Not found. Create it. |
| 2948 | FriendDecl::FriendUnion ToFU; |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 2949 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
| 2950 | auto *ToFriendD = cast_or_null<NamedDecl>(Importer.Import(FriendD)); |
| 2951 | if (ToFriendD && FriendD->getFriendObjectKind() != Decl::FOK_None && |
| 2952 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 2953 | ToFriendD->setObjectOfFriendDecl(false); |
| 2954 | |
| 2955 | ToFU = ToFriendD; |
| 2956 | } else // The friend is a type, not a decl. |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2957 | ToFU = Importer.Import(D->getFriendType()); |
| 2958 | if (!ToFU) |
| 2959 | return nullptr; |
| 2960 | |
| 2961 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2962 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2963 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
| 2964 | TemplateParameterList *List = ImportTemplateParameterList(FromTPLists[I]); |
| 2965 | if (!List) |
| 2966 | return nullptr; |
| 2967 | ToTPLists[I] = List; |
| 2968 | } |
| 2969 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 2970 | FriendDecl *FrD; |
| 2971 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
| 2972 | Importer.Import(D->getLocation()), ToFU, |
| 2973 | Importer.Import(D->getFriendLoc()), ToTPLists)) |
| 2974 | return FrD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2975 | |
| 2976 | FrD->setAccess(D->getAccess()); |
| 2977 | FrD->setLexicalDeclContext(LexicalDC); |
| 2978 | LexicalDC->addDeclInternal(FrD); |
| 2979 | return FrD; |
| 2980 | } |
| 2981 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2982 | Decl *ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| 2983 | // Import the major distinguishing characteristics of an ivar. |
| 2984 | DeclContext *DC, *LexicalDC; |
| 2985 | DeclarationName Name; |
| 2986 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2987 | NamedDecl *ToD; |
| 2988 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2989 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2990 | if (ToD) |
| 2991 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2992 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2993 | // Determine whether we've already imported this ivar |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2994 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2995 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2996 | for (auto *FoundDecl : FoundDecls) { |
| 2997 | if (auto *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2998 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2999 | FoundIvar->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3000 | Importer.MapImported(D, FoundIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3001 | return FoundIvar; |
| 3002 | } |
| 3003 | |
| 3004 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) |
| 3005 | << Name << D->getType() << FoundIvar->getType(); |
| 3006 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3007 | << FoundIvar->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3008 | return nullptr; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3009 | } |
| 3010 | } |
| 3011 | |
| 3012 | // Import the type. |
| 3013 | QualType T = Importer.Import(D->getType()); |
| 3014 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3015 | return nullptr; |
| 3016 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3017 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3018 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 3019 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3020 | return nullptr; |
| 3021 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3022 | ObjCIvarDecl *ToIvar; |
| 3023 | if (GetImportedOrCreateDecl( |
| 3024 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
| 3025 | Importer.Import(D->getInnerLocStart()), Loc, |
| 3026 | Name.getAsIdentifierInfo(), T, TInfo, D->getAccessControl(), BitWidth, |
| 3027 | D->getSynthesize())) |
| 3028 | return ToIvar; |
| 3029 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3030 | ToIvar->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3031 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3032 | return ToIvar; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3033 | } |
| 3034 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3035 | Decl *ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
| 3036 | // Import the major distinguishing characteristics of a variable. |
| 3037 | DeclContext *DC, *LexicalDC; |
| 3038 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3039 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3040 | NamedDecl *ToD; |
| 3041 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3042 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3043 | if (ToD) |
| 3044 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3045 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3046 | // Try to find a variable in our own ("to") context with the same name and |
| 3047 | // in the same context as the variable we're importing. |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3048 | if (D->isFileVarDecl()) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3049 | VarDecl *MergeWithVar = nullptr; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3050 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3051 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3052 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3053 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3054 | for (auto *FoundDecl : FoundDecls) { |
| 3055 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3056 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3057 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3058 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3059 | // We have found a variable that we may need to merge with. Check it. |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 3060 | if (FoundVar->hasExternalFormalLinkage() && |
| 3061 | D->hasExternalFormalLinkage()) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3062 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3063 | FoundVar->getType())) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3064 | MergeWithVar = FoundVar; |
| 3065 | break; |
| 3066 | } |
| 3067 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3068 | const ArrayType *FoundArray |
| 3069 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3070 | const ArrayType *TArray |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3071 | = Importer.getToContext().getAsArrayType(D->getType()); |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3072 | if (FoundArray && TArray) { |
| 3073 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3074 | isa<ConstantArrayType>(TArray)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3075 | // Import the type. |
| 3076 | QualType T = Importer.Import(D->getType()); |
| 3077 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3078 | return nullptr; |
| 3079 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3080 | FoundVar->setType(T); |
| 3081 | MergeWithVar = FoundVar; |
| 3082 | break; |
| 3083 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3084 | isa<ConstantArrayType>(FoundArray)) { |
| 3085 | MergeWithVar = FoundVar; |
| 3086 | break; |
Douglas Gregor | 2fbe558 | 2010-02-10 17:16:49 +0000 | [diff] [blame] | 3087 | } |
| 3088 | } |
| 3089 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3090 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3091 | << Name << D->getType() << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3092 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3093 | << FoundVar->getType(); |
| 3094 | } |
| 3095 | } |
| 3096 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3097 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3098 | } |
| 3099 | |
| 3100 | if (MergeWithVar) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3101 | // An equivalent variable with external linkage has been found. Link |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3102 | // the two declarations, then merge them. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3103 | Importer.MapImported(D, MergeWithVar); |
| 3104 | updateFlags(D, MergeWithVar); |
| 3105 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3106 | if (VarDecl *DDef = D->getDefinition()) { |
| 3107 | if (VarDecl *ExistingDef = MergeWithVar->getDefinition()) { |
| 3108 | Importer.ToDiag(ExistingDef->getLocation(), |
| 3109 | diag::err_odr_variable_multiple_def) |
| 3110 | << Name; |
| 3111 | Importer.FromDiag(DDef->getLocation(), diag::note_odr_defined_here); |
| 3112 | } else { |
| 3113 | Expr *Init = Importer.Import(DDef->getInit()); |
Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 3114 | MergeWithVar->setInit(Init); |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 3115 | if (DDef->isInitKnownICE()) { |
| 3116 | EvaluatedStmt *Eval = MergeWithVar->ensureEvaluatedStmt(); |
| 3117 | Eval->CheckedICE = true; |
| 3118 | Eval->IsICE = DDef->isInitICE(); |
| 3119 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3120 | } |
| 3121 | } |
| 3122 | |
| 3123 | return MergeWithVar; |
| 3124 | } |
| 3125 | |
| 3126 | if (!ConflictingDecls.empty()) { |
| 3127 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 3128 | ConflictingDecls.data(), |
| 3129 | ConflictingDecls.size()); |
| 3130 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3131 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3132 | } |
| 3133 | } |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 3134 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3135 | // Import the type. |
| 3136 | QualType T = Importer.Import(D->getType()); |
| 3137 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3138 | return nullptr; |
| 3139 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3140 | // Create the imported variable. |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 3141 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3142 | VarDecl *ToVar; |
| 3143 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
| 3144 | Importer.Import(D->getInnerLocStart()), Loc, |
| 3145 | Name.getAsIdentifierInfo(), T, TInfo, |
| 3146 | D->getStorageClass())) |
| 3147 | return ToVar; |
| 3148 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3149 | ToVar->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3150 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3151 | ToVar->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3152 | |
| 3153 | // Templated declarations should never appear in the enclosing DeclContext. |
| 3154 | if (!D->getDescribedVarTemplate()) |
| 3155 | LexicalDC->addDeclInternal(ToVar); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3156 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3157 | // Merge the initializer. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3158 | if (ImportDefinition(D, ToVar)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3159 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3160 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3161 | if (D->isConstexpr()) |
| 3162 | ToVar->setConstexpr(true); |
| 3163 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3164 | return ToVar; |
| 3165 | } |
| 3166 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3167 | Decl *ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| 3168 | // Parameters are created in the translation unit's context, then moved |
| 3169 | // into the function declaration's context afterward. |
| 3170 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 3171 | |
| 3172 | // Import the name of this declaration. |
| 3173 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3174 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3175 | return nullptr; |
| 3176 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3177 | // Import the location of this declaration. |
| 3178 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 3179 | |
| 3180 | // Import the parameter's type. |
| 3181 | QualType T = Importer.Import(D->getType()); |
| 3182 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3183 | return nullptr; |
| 3184 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3185 | // Create the imported parameter. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3186 | ImplicitParamDecl *ToParm = nullptr; |
| 3187 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, Loc, |
| 3188 | Name.getAsIdentifierInfo(), T, |
| 3189 | D->getParameterKind())) |
| 3190 | return ToParm; |
| 3191 | return ToParm; |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3192 | } |
| 3193 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3194 | Decl *ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
| 3195 | // Parameters are created in the translation unit's context, then moved |
| 3196 | // into the function declaration's context afterward. |
| 3197 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 3198 | |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 3199 | // Import the name of this declaration. |
| 3200 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3201 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3202 | return nullptr; |
| 3203 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3204 | // Import the location of this declaration. |
| 3205 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 3206 | |
| 3207 | // Import the parameter's type. |
| 3208 | QualType T = Importer.Import(D->getType()); |
| 3209 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3210 | return nullptr; |
| 3211 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3212 | // Create the imported parameter. |
| 3213 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3214 | ParmVarDecl *ToParm; |
| 3215 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3216 | Importer.Import(D->getInnerLocStart()), Loc, |
| 3217 | Name.getAsIdentifierInfo(), T, TInfo, |
| 3218 | D->getStorageClass(), |
| 3219 | /*DefaultArg*/ nullptr)) |
| 3220 | return ToParm; |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3221 | |
| 3222 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 3223 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3224 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 3225 | |
| 3226 | Expr *ToDefArg = nullptr; |
| 3227 | Expr *FromDefArg = nullptr; |
| 3228 | if (D->hasUninstantiatedDefaultArg()) { |
| 3229 | FromDefArg = D->getUninstantiatedDefaultArg(); |
| 3230 | ToDefArg = Importer.Import(FromDefArg); |
| 3231 | ToParm->setUninstantiatedDefaultArg(ToDefArg); |
| 3232 | } else if (D->hasUnparsedDefaultArg()) { |
| 3233 | ToParm->setUnparsedDefaultArg(); |
| 3234 | } else if (D->hasDefaultArg()) { |
| 3235 | FromDefArg = D->getDefaultArg(); |
| 3236 | ToDefArg = Importer.Import(FromDefArg); |
| 3237 | ToParm->setDefaultArg(ToDefArg); |
| 3238 | } |
| 3239 | if (FromDefArg && !ToDefArg) |
| 3240 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3241 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3242 | if (D->isObjCMethodParameter()) { |
| 3243 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3244 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3245 | } else { |
| 3246 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3247 | D->getFunctionScopeIndex()); |
| 3248 | } |
| 3249 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3250 | return ToParm; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3251 | } |
| 3252 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3253 | Decl *ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| 3254 | // Import the major distinguishing characteristics of a method. |
| 3255 | DeclContext *DC, *LexicalDC; |
| 3256 | DeclarationName Name; |
| 3257 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3258 | NamedDecl *ToD; |
| 3259 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3260 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3261 | if (ToD) |
| 3262 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3263 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3264 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3265 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3266 | for (auto *FoundDecl : FoundDecls) { |
| 3267 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3268 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3269 | continue; |
| 3270 | |
| 3271 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3272 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3273 | FoundMethod->getReturnType())) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3274 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3275 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3276 | << FoundMethod->getReturnType(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3277 | Importer.ToDiag(FoundMethod->getLocation(), |
| 3278 | diag::note_odr_objc_method_here) |
| 3279 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3280 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3281 | } |
| 3282 | |
| 3283 | // Check the number of parameters. |
| 3284 | if (D->param_size() != FoundMethod->param_size()) { |
| 3285 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) |
| 3286 | << D->isInstanceMethod() << Name |
| 3287 | << D->param_size() << FoundMethod->param_size(); |
| 3288 | Importer.ToDiag(FoundMethod->getLocation(), |
| 3289 | diag::note_odr_objc_method_here) |
| 3290 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3291 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3292 | } |
| 3293 | |
| 3294 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3295 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3296 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3297 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3298 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3299 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3300 | Importer.FromDiag((*P)->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3301 | diag::err_odr_objc_method_param_type_inconsistent) |
| 3302 | << D->isInstanceMethod() << Name |
| 3303 | << (*P)->getType() << (*FoundP)->getType(); |
| 3304 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3305 | << (*FoundP)->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3306 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3307 | } |
| 3308 | } |
| 3309 | |
| 3310 | // Check variadic/non-variadic. |
| 3311 | // Check the number of parameters. |
| 3312 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| 3313 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) |
| 3314 | << D->isInstanceMethod() << Name; |
| 3315 | Importer.ToDiag(FoundMethod->getLocation(), |
| 3316 | diag::note_odr_objc_method_here) |
| 3317 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3318 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3319 | } |
| 3320 | |
| 3321 | // FIXME: Any other bits we need to merge? |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3322 | return Importer.MapImported(D, FoundMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3323 | } |
| 3324 | } |
| 3325 | |
| 3326 | // Import the result type. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3327 | QualType ResultTy = Importer.Import(D->getReturnType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3328 | if (ResultTy.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3329 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3330 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3331 | TypeSourceInfo *ReturnTInfo = Importer.Import(D->getReturnTypeSourceInfo()); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3332 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3333 | ObjCMethodDecl *ToMethod; |
| 3334 | if (GetImportedOrCreateDecl( |
| 3335 | ToMethod, D, Importer.getToContext(), Loc, |
| 3336 | Importer.Import(D->getLocEnd()), Name.getObjCSelector(), ResultTy, |
| 3337 | ReturnTInfo, DC, D->isInstanceMethod(), D->isVariadic(), |
| 3338 | D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3339 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 3340 | return ToMethod; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3341 | |
| 3342 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3343 | // deal with implicit parameters. |
| 3344 | |
| 3345 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3346 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3347 | for (auto *FromP : D->parameters()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3348 | auto *ToP = cast_or_null<ParmVarDecl>(Importer.Import(FromP)); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3349 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3350 | return nullptr; |
| 3351 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3352 | ToParams.push_back(ToP); |
| 3353 | } |
| 3354 | |
| 3355 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3356 | for (auto *ToParam : ToParams) { |
| 3357 | ToParam->setOwningFunction(ToMethod); |
| 3358 | ToMethod->addDeclInternal(ToParam); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3359 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3360 | |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 3361 | SmallVector<SourceLocation, 12> SelLocs; |
| 3362 | D->getSelectorLocs(SelLocs); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3363 | for (auto &Loc : SelLocs) |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3364 | Loc = Importer.Import(Loc); |
| 3365 | |
| 3366 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, SelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3367 | |
| 3368 | ToMethod->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3369 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3370 | return ToMethod; |
| 3371 | } |
| 3372 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3373 | Decl *ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| 3374 | // Import the major distinguishing characteristics of a category. |
| 3375 | DeclContext *DC, *LexicalDC; |
| 3376 | DeclarationName Name; |
| 3377 | SourceLocation Loc; |
| 3378 | NamedDecl *ToD; |
| 3379 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3380 | return nullptr; |
| 3381 | if (ToD) |
| 3382 | return ToD; |
| 3383 | |
| 3384 | TypeSourceInfo *BoundInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3385 | if (!BoundInfo) |
| 3386 | return nullptr; |
| 3387 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3388 | ObjCTypeParamDecl *Result; |
| 3389 | if (GetImportedOrCreateDecl( |
| 3390 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
| 3391 | Importer.Import(D->getVarianceLoc()), D->getIndex(), |
| 3392 | Importer.Import(D->getLocation()), Name.getAsIdentifierInfo(), |
| 3393 | Importer.Import(D->getColonLoc()), BoundInfo)) |
| 3394 | return Result; |
| 3395 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3396 | Result->setLexicalDeclContext(LexicalDC); |
| 3397 | return Result; |
| 3398 | } |
| 3399 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3400 | Decl *ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| 3401 | // Import the major distinguishing characteristics of a category. |
| 3402 | DeclContext *DC, *LexicalDC; |
| 3403 | DeclarationName Name; |
| 3404 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3405 | NamedDecl *ToD; |
| 3406 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3407 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3408 | if (ToD) |
| 3409 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3410 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3411 | auto *ToInterface = |
| 3412 | cast_or_null<ObjCInterfaceDecl>(Importer.Import(D->getClassInterface())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3413 | if (!ToInterface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3414 | return nullptr; |
| 3415 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3416 | // Determine if we've already encountered this category. |
| 3417 | ObjCCategoryDecl *MergeWithCategory |
| 3418 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3419 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3420 | if (!ToCategory) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3421 | |
| 3422 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
| 3423 | Importer.Import(D->getAtStartLoc()), Loc, |
| 3424 | Importer.Import(D->getCategoryNameLoc()), |
| 3425 | Name.getAsIdentifierInfo(), ToInterface, |
| 3426 | /*TypeParamList=*/nullptr, |
| 3427 | Importer.Import(D->getIvarLBraceLoc()), |
| 3428 | Importer.Import(D->getIvarRBraceLoc()))) |
| 3429 | return ToCategory; |
| 3430 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3431 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3432 | LexicalDC->addDeclInternal(ToCategory); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3433 | // Import the type parameter list after calling Imported, to avoid |
| 3434 | // loops when bringing in their DeclContext. |
| 3435 | ToCategory->setTypeParamList(ImportObjCTypeParamList( |
| 3436 | D->getTypeParamList())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3437 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3438 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3439 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3440 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3441 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 3442 | = D->protocol_loc_begin(); |
| 3443 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 3444 | FromProtoEnd = D->protocol_end(); |
| 3445 | FromProto != FromProtoEnd; |
| 3446 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3447 | auto *ToProto = |
| 3448 | cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3449 | if (!ToProto) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3450 | return nullptr; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3451 | Protocols.push_back(ToProto); |
| 3452 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3453 | } |
| 3454 | |
| 3455 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3456 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 3457 | ProtocolLocs.data(), Importer.getToContext()); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3458 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3459 | Importer.MapImported(D, ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | // Import all of the members of this category. |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 3463 | ImportDeclContext(D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3464 | |
| 3465 | // If we have an implementation, import it as well. |
| 3466 | if (D->getImplementation()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3467 | auto *Impl = |
| 3468 | cast_or_null<ObjCCategoryImplDecl>( |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3469 | Importer.Import(D->getImplementation())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3470 | if (!Impl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3471 | return nullptr; |
| 3472 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3473 | ToCategory->setImplementation(Impl); |
| 3474 | } |
| 3475 | |
| 3476 | return ToCategory; |
| 3477 | } |
| 3478 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3479 | bool ASTNodeImporter::ImportDefinition(ObjCProtocolDecl *From, |
| 3480 | ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3481 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3482 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3483 | if (shouldForceImportDeclContext(Kind)) |
| 3484 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3485 | return false; |
| 3486 | } |
| 3487 | |
| 3488 | // Start the protocol definition |
| 3489 | To->startDefinition(); |
| 3490 | |
| 3491 | // Import protocols |
| 3492 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3493 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 3494 | ObjCProtocolDecl::protocol_loc_iterator |
| 3495 | FromProtoLoc = From->protocol_loc_begin(); |
| 3496 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3497 | FromProtoEnd = From->protocol_end(); |
| 3498 | FromProto != FromProtoEnd; |
| 3499 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3500 | auto *ToProto = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3501 | if (!ToProto) |
| 3502 | return true; |
| 3503 | Protocols.push_back(ToProto); |
| 3504 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3505 | } |
| 3506 | |
| 3507 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3508 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3509 | ProtocolLocs.data(), Importer.getToContext()); |
| 3510 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3511 | if (shouldForceImportDeclContext(Kind)) { |
| 3512 | // Import all of the members of this protocol. |
| 3513 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3514 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3515 | return false; |
| 3516 | } |
| 3517 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3518 | Decl *ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3519 | // If this protocol has a definition in the translation unit we're coming |
| 3520 | // from, but this particular declaration is not that definition, import the |
| 3521 | // definition and map to that. |
| 3522 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 3523 | if (Definition && Definition != D) { |
| 3524 | Decl *ImportedDef = Importer.Import(Definition); |
| 3525 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3526 | return nullptr; |
| 3527 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3528 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3529 | } |
| 3530 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3531 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3532 | DeclContext *DC, *LexicalDC; |
| 3533 | DeclarationName Name; |
| 3534 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3535 | NamedDecl *ToD; |
| 3536 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3537 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3538 | if (ToD) |
| 3539 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3540 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3541 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3542 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3543 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3544 | for (auto *FoundDecl : FoundDecls) { |
| 3545 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3546 | continue; |
| 3547 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3548 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3549 | break; |
| 3550 | } |
| 3551 | |
| 3552 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3553 | if (!ToProto) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3554 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 3555 | Name.getAsIdentifierInfo(), Loc, |
| 3556 | Importer.Import(D->getAtStartLoc()), |
| 3557 | /*PrevDecl=*/nullptr)) |
| 3558 | return ToProto; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3559 | ToProto->setLexicalDeclContext(LexicalDC); |
| 3560 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3561 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3562 | |
| 3563 | Importer.MapImported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3564 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3565 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToProto)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3566 | return nullptr; |
| 3567 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3568 | return ToProto; |
| 3569 | } |
| 3570 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3571 | Decl *ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 3572 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3573 | DeclContext *LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3574 | |
| 3575 | SourceLocation ExternLoc = Importer.Import(D->getExternLoc()); |
| 3576 | SourceLocation LangLoc = Importer.Import(D->getLocation()); |
| 3577 | |
| 3578 | bool HasBraces = D->hasBraces(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3579 | |
| 3580 | LinkageSpecDecl *ToLinkageSpec; |
| 3581 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
| 3582 | ExternLoc, LangLoc, D->getLanguage(), HasBraces)) |
| 3583 | return ToLinkageSpec; |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3584 | |
| 3585 | if (HasBraces) { |
| 3586 | SourceLocation RBraceLoc = Importer.Import(D->getRBraceLoc()); |
| 3587 | ToLinkageSpec->setRBraceLoc(RBraceLoc); |
| 3588 | } |
| 3589 | |
| 3590 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 3591 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 3592 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3593 | return ToLinkageSpec; |
| 3594 | } |
| 3595 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3596 | Decl *ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
| 3597 | DeclContext *DC, *LexicalDC; |
| 3598 | DeclarationName Name; |
| 3599 | SourceLocation Loc; |
| 3600 | NamedDecl *ToD = nullptr; |
| 3601 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3602 | return nullptr; |
| 3603 | if (ToD) |
| 3604 | return ToD; |
| 3605 | |
| 3606 | DeclarationNameInfo NameInfo(Name, |
| 3607 | Importer.Import(D->getNameInfo().getLoc())); |
| 3608 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3609 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3610 | UsingDecl *ToUsing; |
| 3611 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| 3612 | Importer.Import(D->getUsingLoc()), |
| 3613 | Importer.Import(D->getQualifierLoc()), NameInfo, |
| 3614 | D->hasTypename())) |
| 3615 | return ToUsing; |
| 3616 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3617 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3618 | LexicalDC->addDeclInternal(ToUsing); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3619 | |
| 3620 | if (NamedDecl *FromPattern = |
| 3621 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3622 | if (auto *ToPattern = |
| 3623 | dyn_cast_or_null<NamedDecl>(Importer.Import(FromPattern))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3624 | Importer.getToContext().setInstantiatedFromUsingDecl(ToUsing, ToPattern); |
| 3625 | else |
| 3626 | return nullptr; |
| 3627 | } |
| 3628 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3629 | for (auto *FromShadow : D->shadows()) { |
| 3630 | if (auto *ToShadow = |
| 3631 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromShadow))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3632 | ToUsing->addShadowDecl(ToShadow); |
| 3633 | else |
| 3634 | // FIXME: We return a nullptr here but the definition is already created |
| 3635 | // and available with lookups. How to fix this?.. |
| 3636 | return nullptr; |
| 3637 | } |
| 3638 | return ToUsing; |
| 3639 | } |
| 3640 | |
| 3641 | Decl *ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| 3642 | DeclContext *DC, *LexicalDC; |
| 3643 | DeclarationName Name; |
| 3644 | SourceLocation Loc; |
| 3645 | NamedDecl *ToD = nullptr; |
| 3646 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3647 | return nullptr; |
| 3648 | if (ToD) |
| 3649 | return ToD; |
| 3650 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3651 | auto *ToUsing = dyn_cast_or_null<UsingDecl>( |
| 3652 | Importer.Import(D->getUsingDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3653 | if (!ToUsing) |
| 3654 | return nullptr; |
| 3655 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3656 | auto *ToTarget = dyn_cast_or_null<NamedDecl>( |
| 3657 | Importer.Import(D->getTargetDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3658 | if (!ToTarget) |
| 3659 | return nullptr; |
| 3660 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3661 | UsingShadowDecl *ToShadow; |
| 3662 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
| 3663 | ToUsing, ToTarget)) |
| 3664 | return ToShadow; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3665 | |
| 3666 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 3667 | ToShadow->setAccess(D->getAccess()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3668 | |
| 3669 | if (UsingShadowDecl *FromPattern = |
| 3670 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3671 | if (auto *ToPattern = |
| 3672 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromPattern))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3673 | Importer.getToContext().setInstantiatedFromUsingShadowDecl(ToShadow, |
| 3674 | ToPattern); |
| 3675 | else |
| 3676 | // FIXME: We return a nullptr here but the definition is already created |
| 3677 | // and available with lookups. How to fix this?.. |
| 3678 | return nullptr; |
| 3679 | } |
| 3680 | |
| 3681 | LexicalDC->addDeclInternal(ToShadow); |
| 3682 | |
| 3683 | return ToShadow; |
| 3684 | } |
| 3685 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3686 | Decl *ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 3687 | DeclContext *DC, *LexicalDC; |
| 3688 | DeclarationName Name; |
| 3689 | SourceLocation Loc; |
| 3690 | NamedDecl *ToD = nullptr; |
| 3691 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3692 | return nullptr; |
| 3693 | if (ToD) |
| 3694 | return ToD; |
| 3695 | |
| 3696 | DeclContext *ToComAncestor = Importer.ImportContext(D->getCommonAncestor()); |
| 3697 | if (!ToComAncestor) |
| 3698 | return nullptr; |
| 3699 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3700 | auto *ToNominated = cast_or_null<NamespaceDecl>( |
| 3701 | Importer.Import(D->getNominatedNamespace())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3702 | if (!ToNominated) |
| 3703 | return nullptr; |
| 3704 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3705 | UsingDirectiveDecl *ToUsingDir; |
| 3706 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
| 3707 | Importer.Import(D->getUsingLoc()), |
| 3708 | Importer.Import(D->getNamespaceKeyLocation()), |
| 3709 | Importer.Import(D->getQualifierLoc()), |
| 3710 | Importer.Import(D->getIdentLocation()), |
| 3711 | ToNominated, ToComAncestor)) |
| 3712 | return ToUsingDir; |
| 3713 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3714 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 3715 | LexicalDC->addDeclInternal(ToUsingDir); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3716 | |
| 3717 | return ToUsingDir; |
| 3718 | } |
| 3719 | |
| 3720 | Decl *ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
| 3721 | UnresolvedUsingValueDecl *D) { |
| 3722 | DeclContext *DC, *LexicalDC; |
| 3723 | DeclarationName Name; |
| 3724 | SourceLocation Loc; |
| 3725 | NamedDecl *ToD = nullptr; |
| 3726 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3727 | return nullptr; |
| 3728 | if (ToD) |
| 3729 | return ToD; |
| 3730 | |
| 3731 | DeclarationNameInfo NameInfo(Name, Importer.Import(D->getNameInfo().getLoc())); |
| 3732 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3733 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3734 | UnresolvedUsingValueDecl *ToUsingValue; |
| 3735 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
| 3736 | Importer.Import(D->getUsingLoc()), |
| 3737 | Importer.Import(D->getQualifierLoc()), NameInfo, |
| 3738 | Importer.Import(D->getEllipsisLoc()))) |
| 3739 | return ToUsingValue; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3740 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3741 | ToUsingValue->setAccess(D->getAccess()); |
| 3742 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 3743 | LexicalDC->addDeclInternal(ToUsingValue); |
| 3744 | |
| 3745 | return ToUsingValue; |
| 3746 | } |
| 3747 | |
| 3748 | Decl *ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
| 3749 | UnresolvedUsingTypenameDecl *D) { |
| 3750 | DeclContext *DC, *LexicalDC; |
| 3751 | DeclarationName Name; |
| 3752 | SourceLocation Loc; |
| 3753 | NamedDecl *ToD = nullptr; |
| 3754 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3755 | return nullptr; |
| 3756 | if (ToD) |
| 3757 | return ToD; |
| 3758 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3759 | UnresolvedUsingTypenameDecl *ToUsing; |
| 3760 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| 3761 | Importer.Import(D->getUsingLoc()), |
| 3762 | Importer.Import(D->getTypenameLoc()), |
| 3763 | Importer.Import(D->getQualifierLoc()), Loc, Name, |
| 3764 | Importer.Import(D->getEllipsisLoc()))) |
| 3765 | return ToUsing; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3766 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3767 | ToUsing->setAccess(D->getAccess()); |
| 3768 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3769 | LexicalDC->addDeclInternal(ToUsing); |
| 3770 | |
| 3771 | return ToUsing; |
| 3772 | } |
| 3773 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3774 | bool ASTNodeImporter::ImportDefinition(ObjCInterfaceDecl *From, |
| 3775 | ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3776 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3777 | if (To->getDefinition()) { |
| 3778 | // Check consistency of superclass. |
| 3779 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 3780 | if (FromSuper) { |
| 3781 | FromSuper = cast_or_null<ObjCInterfaceDecl>(Importer.Import(FromSuper)); |
| 3782 | if (!FromSuper) |
| 3783 | return true; |
| 3784 | } |
| 3785 | |
| 3786 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
| 3787 | if ((bool)FromSuper != (bool)ToSuper || |
| 3788 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
| 3789 | Importer.ToDiag(To->getLocation(), |
| 3790 | diag::err_odr_objc_superclass_inconsistent) |
| 3791 | << To->getDeclName(); |
| 3792 | if (ToSuper) |
| 3793 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 3794 | << To->getSuperClass()->getDeclName(); |
| 3795 | else |
| 3796 | Importer.ToDiag(To->getLocation(), |
| 3797 | diag::note_odr_objc_missing_superclass); |
| 3798 | if (From->getSuperClass()) |
| 3799 | Importer.FromDiag(From->getSuperClassLoc(), |
| 3800 | diag::note_odr_objc_superclass) |
| 3801 | << From->getSuperClass()->getDeclName(); |
| 3802 | else |
| 3803 | Importer.FromDiag(From->getLocation(), |
| 3804 | diag::note_odr_objc_missing_superclass); |
| 3805 | } |
| 3806 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3807 | if (shouldForceImportDeclContext(Kind)) |
| 3808 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3809 | return false; |
| 3810 | } |
| 3811 | |
| 3812 | // Start the definition. |
| 3813 | To->startDefinition(); |
| 3814 | |
| 3815 | // If this class has a superclass, import it. |
| 3816 | if (From->getSuperClass()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3817 | TypeSourceInfo *SuperTInfo = Importer.Import(From->getSuperClassTInfo()); |
| 3818 | if (!SuperTInfo) |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3819 | return true; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3820 | |
| 3821 | To->setSuperClass(SuperTInfo); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3822 | } |
| 3823 | |
| 3824 | // Import protocols |
| 3825 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3826 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 3827 | ObjCInterfaceDecl::protocol_loc_iterator |
| 3828 | FromProtoLoc = From->protocol_loc_begin(); |
| 3829 | |
| 3830 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3831 | FromProtoEnd = From->protocol_end(); |
| 3832 | FromProto != FromProtoEnd; |
| 3833 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3834 | auto *ToProto = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3835 | if (!ToProto) |
| 3836 | return true; |
| 3837 | Protocols.push_back(ToProto); |
| 3838 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3839 | } |
| 3840 | |
| 3841 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3842 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3843 | ProtocolLocs.data(), Importer.getToContext()); |
| 3844 | |
| 3845 | // Import categories. When the categories themselves are imported, they'll |
| 3846 | // hook themselves into this interface. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 3847 | for (auto *Cat : From->known_categories()) |
| 3848 | Importer.Import(Cat); |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 3849 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3850 | // If we have an @implementation, import it as well. |
| 3851 | if (From->getImplementation()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3852 | auto *Impl = cast_or_null<ObjCImplementationDecl>( |
| 3853 | Importer.Import(From->getImplementation())); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3854 | if (!Impl) |
| 3855 | return true; |
| 3856 | |
| 3857 | To->setImplementation(Impl); |
| 3858 | } |
| 3859 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3860 | if (shouldForceImportDeclContext(Kind)) { |
| 3861 | // Import all of the members of this class. |
| 3862 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3863 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3864 | return false; |
| 3865 | } |
| 3866 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3867 | ObjCTypeParamList * |
| 3868 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 3869 | if (!list) |
| 3870 | return nullptr; |
| 3871 | |
| 3872 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
| 3873 | for (auto fromTypeParam : *list) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3874 | auto *toTypeParam = cast_or_null<ObjCTypeParamDecl>( |
| 3875 | Importer.Import(fromTypeParam)); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3876 | if (!toTypeParam) |
| 3877 | return nullptr; |
| 3878 | |
| 3879 | toTypeParams.push_back(toTypeParam); |
| 3880 | } |
| 3881 | |
| 3882 | return ObjCTypeParamList::create(Importer.getToContext(), |
| 3883 | Importer.Import(list->getLAngleLoc()), |
| 3884 | toTypeParams, |
| 3885 | Importer.Import(list->getRAngleLoc())); |
| 3886 | } |
| 3887 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3888 | Decl *ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3889 | // If this class has a definition in the translation unit we're coming from, |
| 3890 | // but this particular declaration is not that definition, import the |
| 3891 | // definition and map to that. |
| 3892 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 3893 | if (Definition && Definition != D) { |
| 3894 | Decl *ImportedDef = Importer.Import(Definition); |
| 3895 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3896 | return nullptr; |
| 3897 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3898 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3899 | } |
| 3900 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3901 | // Import the major distinguishing characteristics of an @interface. |
| 3902 | DeclContext *DC, *LexicalDC; |
| 3903 | DeclarationName Name; |
| 3904 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3905 | NamedDecl *ToD; |
| 3906 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3907 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3908 | if (ToD) |
| 3909 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3910 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3911 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3912 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3913 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3914 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3915 | for (auto *FoundDecl : FoundDecls) { |
| 3916 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3917 | continue; |
| 3918 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3919 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3920 | break; |
| 3921 | } |
| 3922 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3923 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3924 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3925 | if (!ToIface) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3926 | if (GetImportedOrCreateDecl( |
| 3927 | ToIface, D, Importer.getToContext(), DC, |
| 3928 | Importer.Import(D->getAtStartLoc()), Name.getAsIdentifierInfo(), |
| 3929 | /*TypeParamList=*/nullptr, |
| 3930 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 3931 | return ToIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3932 | ToIface->setLexicalDeclContext(LexicalDC); |
| 3933 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3934 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3935 | Importer.MapImported(D, ToIface); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3936 | // Import the type parameter list after calling Imported, to avoid |
| 3937 | // loops when bringing in their DeclContext. |
| 3938 | ToIface->setTypeParamList(ImportObjCTypeParamList( |
| 3939 | D->getTypeParamListAsWritten())); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3940 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3941 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToIface)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3942 | return nullptr; |
| 3943 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3944 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3945 | } |
| 3946 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3947 | Decl *ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3948 | auto *Category = cast_or_null<ObjCCategoryDecl>( |
| 3949 | Importer.Import(D->getCategoryDecl())); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3950 | if (!Category) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3951 | return nullptr; |
| 3952 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3953 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 3954 | if (!ToImpl) { |
| 3955 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3956 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3957 | return nullptr; |
| 3958 | |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 3959 | SourceLocation CategoryNameLoc = Importer.Import(D->getCategoryNameLoc()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3960 | if (GetImportedOrCreateDecl( |
| 3961 | ToImpl, D, Importer.getToContext(), DC, |
| 3962 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
| 3963 | Importer.Import(D->getLocation()), |
| 3964 | Importer.Import(D->getAtStartLoc()), CategoryNameLoc)) |
| 3965 | return ToImpl; |
| 3966 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3967 | DeclContext *LexicalDC = DC; |
| 3968 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3969 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3970 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3971 | return nullptr; |
| 3972 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3973 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 3974 | } |
| 3975 | |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3976 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3977 | Category->setImplementation(ToImpl); |
| 3978 | } |
| 3979 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 3980 | Importer.MapImported(D, ToImpl); |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3981 | ImportDeclContext(D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3982 | return ToImpl; |
| 3983 | } |
| 3984 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3985 | Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 3986 | // Find the corresponding interface. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3987 | auto *Iface = cast_or_null<ObjCInterfaceDecl>( |
| 3988 | Importer.Import(D->getClassInterface())); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3989 | if (!Iface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3990 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3991 | |
| 3992 | // Import the superclass, if any. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3993 | ObjCInterfaceDecl *Super = nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3994 | if (D->getSuperClass()) { |
| 3995 | Super = cast_or_null<ObjCInterfaceDecl>( |
| 3996 | Importer.Import(D->getSuperClass())); |
| 3997 | if (!Super) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3998 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3999 | } |
| 4000 | |
| 4001 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4002 | if (!Impl) { |
| 4003 | // We haven't imported an implementation yet. Create a new @implementation |
| 4004 | // now. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4005 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
| 4006 | Importer.ImportContext(D->getDeclContext()), |
| 4007 | Iface, Super, Importer.Import(D->getLocation()), |
| 4008 | Importer.Import(D->getAtStartLoc()), |
| 4009 | Importer.Import(D->getSuperClassLoc()), |
| 4010 | Importer.Import(D->getIvarLBraceLoc()), |
| 4011 | Importer.Import(D->getIvarRBraceLoc()))) |
| 4012 | return Impl; |
| 4013 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4014 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4015 | DeclContext *LexicalDC |
| 4016 | = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4017 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4018 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4019 | Impl->setLexicalDeclContext(LexicalDC); |
| 4020 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4021 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4022 | // Associate the implementation with the class it implements. |
| 4023 | Iface->setImplementation(Impl); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4024 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4025 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4026 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4027 | |
| 4028 | // Verify that the existing @implementation has the same superclass. |
| 4029 | if ((Super && !Impl->getSuperClass()) || |
| 4030 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4031 | (Super && Impl->getSuperClass() && |
| 4032 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4033 | Impl->getSuperClass()))) { |
| 4034 | Importer.ToDiag(Impl->getLocation(), |
| 4035 | diag::err_odr_objc_superclass_inconsistent) |
| 4036 | << Iface->getDeclName(); |
| 4037 | // FIXME: It would be nice to have the location of the superclass |
| 4038 | // below. |
| 4039 | if (Impl->getSuperClass()) |
| 4040 | Importer.ToDiag(Impl->getLocation(), |
| 4041 | diag::note_odr_objc_superclass) |
| 4042 | << Impl->getSuperClass()->getDeclName(); |
| 4043 | else |
| 4044 | Importer.ToDiag(Impl->getLocation(), |
| 4045 | diag::note_odr_objc_missing_superclass); |
| 4046 | if (D->getSuperClass()) |
| 4047 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4048 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4049 | << D->getSuperClass()->getDeclName(); |
| 4050 | else |
| 4051 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4052 | diag::note_odr_objc_missing_superclass); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4053 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4054 | } |
| 4055 | } |
| 4056 | |
| 4057 | // Import all of the members of this @implementation. |
| 4058 | ImportDeclContext(D); |
| 4059 | |
| 4060 | return Impl; |
| 4061 | } |
| 4062 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4063 | Decl *ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 4064 | // Import the major distinguishing characteristics of an @property. |
| 4065 | DeclContext *DC, *LexicalDC; |
| 4066 | DeclarationName Name; |
| 4067 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4068 | NamedDecl *ToD; |
| 4069 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4070 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4071 | if (ToD) |
| 4072 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4073 | |
| 4074 | // Check whether we have already imported this property. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4075 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4076 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4077 | for (auto *FoundDecl : FoundDecls) { |
| 4078 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4079 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4080 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4081 | FoundProp->getType())) { |
| 4082 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) |
| 4083 | << Name << D->getType() << FoundProp->getType(); |
| 4084 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4085 | << FoundProp->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4086 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4087 | } |
| 4088 | |
| 4089 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4090 | |
| 4091 | // Consider these properties to be equivalent. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4092 | Importer.MapImported(D, FoundProp); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4093 | return FoundProp; |
| 4094 | } |
| 4095 | } |
| 4096 | |
| 4097 | // Import the type. |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 4098 | TypeSourceInfo *TSI = Importer.Import(D->getTypeSourceInfo()); |
| 4099 | if (!TSI) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4100 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4101 | |
| 4102 | // Create the new property. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4103 | ObjCPropertyDecl *ToProperty; |
| 4104 | if (GetImportedOrCreateDecl( |
| 4105 | ToProperty, D, Importer.getToContext(), DC, Loc, |
| 4106 | Name.getAsIdentifierInfo(), Importer.Import(D->getAtLoc()), |
| 4107 | Importer.Import(D->getLParenLoc()), Importer.Import(D->getType()), |
| 4108 | TSI, D->getPropertyImplementation())) |
| 4109 | return ToProperty; |
| 4110 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4111 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4112 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4113 | |
| 4114 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4115 | ToProperty->setPropertyAttributesAsWritten( |
| 4116 | D->getPropertyAttributesAsWritten()); |
Argyrios Kyrtzidis | 194b28e | 2017-03-16 18:25:40 +0000 | [diff] [blame] | 4117 | ToProperty->setGetterName(Importer.Import(D->getGetterName()), |
| 4118 | Importer.Import(D->getGetterNameLoc())); |
| 4119 | ToProperty->setSetterName(Importer.Import(D->getSetterName()), |
| 4120 | Importer.Import(D->getSetterNameLoc())); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4121 | ToProperty->setGetterMethodDecl( |
| 4122 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getGetterMethodDecl()))); |
| 4123 | ToProperty->setSetterMethodDecl( |
| 4124 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getSetterMethodDecl()))); |
| 4125 | ToProperty->setPropertyIvarDecl( |
| 4126 | cast_or_null<ObjCIvarDecl>(Importer.Import(D->getPropertyIvarDecl()))); |
| 4127 | return ToProperty; |
| 4128 | } |
| 4129 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4130 | Decl *ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4131 | auto *Property = cast_or_null<ObjCPropertyDecl>( |
| 4132 | Importer.Import(D->getPropertyDecl())); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4133 | if (!Property) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4134 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4135 | |
| 4136 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 4137 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4138 | return nullptr; |
| 4139 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4140 | // Import the lexical declaration context. |
| 4141 | DeclContext *LexicalDC = DC; |
| 4142 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4143 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4144 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4145 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4146 | } |
| 4147 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4148 | auto *InImpl = dyn_cast<ObjCImplDecl>(LexicalDC); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4149 | if (!InImpl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4150 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4151 | |
| 4152 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4153 | ObjCIvarDecl *Ivar = nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4154 | if (D->getPropertyIvarDecl()) { |
| 4155 | Ivar = cast_or_null<ObjCIvarDecl>( |
| 4156 | Importer.Import(D->getPropertyIvarDecl())); |
| 4157 | if (!Ivar) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4158 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4159 | } |
| 4160 | |
| 4161 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 4162 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 4163 | Property->getQueryKind()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4164 | if (!ToImpl) { |
| 4165 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
| 4166 | Importer.Import(D->getLocStart()), |
| 4167 | Importer.Import(D->getLocation()), Property, |
| 4168 | D->getPropertyImplementation(), Ivar, |
| 4169 | Importer.Import(D->getPropertyIvarDeclLoc()))) |
| 4170 | return ToImpl; |
| 4171 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4172 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4173 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4174 | } else { |
| 4175 | // Check that we have the same kind of property implementation (@synthesize |
| 4176 | // vs. @dynamic). |
| 4177 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
| 4178 | Importer.ToDiag(ToImpl->getLocation(), |
| 4179 | diag::err_odr_objc_property_impl_kind_inconsistent) |
| 4180 | << Property->getDeclName() |
| 4181 | << (ToImpl->getPropertyImplementation() |
| 4182 | == ObjCPropertyImplDecl::Dynamic); |
| 4183 | Importer.FromDiag(D->getLocation(), |
| 4184 | diag::note_odr_objc_property_impl_kind) |
| 4185 | << D->getPropertyDecl()->getDeclName() |
| 4186 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4187 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4188 | } |
| 4189 | |
| 4190 | // For @synthesize, check that we have the same |
| 4191 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 4192 | Ivar != ToImpl->getPropertyIvarDecl()) { |
| 4193 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
| 4194 | diag::err_odr_objc_synthesize_ivar_inconsistent) |
| 4195 | << Property->getDeclName() |
| 4196 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 4197 | << Ivar->getDeclName(); |
| 4198 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
| 4199 | diag::note_odr_objc_synthesize_ivar_here) |
| 4200 | << D->getPropertyIvarDecl()->getDeclName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4201 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4202 | } |
| 4203 | |
| 4204 | // Merge the existing implementation with the new implementation. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4205 | Importer.MapImported(D, ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4206 | } |
| 4207 | |
| 4208 | return ToImpl; |
| 4209 | } |
| 4210 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4211 | Decl *ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 4212 | // For template arguments, we adopt the translation unit as our declaration |
| 4213 | // context. This context will be fixed when the actual template declaration |
| 4214 | // is created. |
| 4215 | |
| 4216 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4217 | TemplateTypeParmDecl *ToD = nullptr; |
| 4218 | (void)GetImportedOrCreateDecl( |
| 4219 | ToD, D, Importer.getToContext(), |
| 4220 | Importer.getToContext().getTranslationUnitDecl(), |
| 4221 | Importer.Import(D->getLocStart()), Importer.Import(D->getLocation()), |
| 4222 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| 4223 | D->wasDeclaredWithTypename(), D->isParameterPack()); |
| 4224 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4225 | } |
| 4226 | |
| 4227 | Decl * |
| 4228 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 4229 | // Import the name of this declaration. |
| 4230 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 4231 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4232 | return nullptr; |
| 4233 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4234 | // Import the location of this declaration. |
| 4235 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 4236 | |
| 4237 | // Import the type of this declaration. |
| 4238 | QualType T = Importer.Import(D->getType()); |
| 4239 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4240 | return nullptr; |
| 4241 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4242 | // Import type-source information. |
| 4243 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 4244 | if (D->getTypeSourceInfo() && !TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4245 | return nullptr; |
| 4246 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4247 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4248 | |
| 4249 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 4250 | (void)GetImportedOrCreateDecl( |
| 4251 | ToD, D, Importer.getToContext(), |
| 4252 | Importer.getToContext().getTranslationUnitDecl(), |
| 4253 | Importer.Import(D->getInnerLocStart()), Loc, D->getDepth(), |
| 4254 | D->getPosition(), Name.getAsIdentifierInfo(), T, D->isParameterPack(), |
| 4255 | TInfo); |
| 4256 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4257 | } |
| 4258 | |
| 4259 | Decl * |
| 4260 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 4261 | // Import the name of this declaration. |
| 4262 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 4263 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4264 | return nullptr; |
| 4265 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4266 | // Import the location of this declaration. |
| 4267 | SourceLocation Loc = Importer.Import(D->getLocation()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4268 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4269 | // Import template parameters. |
| 4270 | TemplateParameterList *TemplateParams |
| 4271 | = ImportTemplateParameterList(D->getTemplateParameters()); |
| 4272 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4273 | return nullptr; |
| 4274 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4275 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4276 | |
| 4277 | TemplateTemplateParmDecl *ToD = nullptr; |
| 4278 | (void)GetImportedOrCreateDecl( |
| 4279 | ToD, D, Importer.getToContext(), |
| 4280 | Importer.getToContext().getTranslationUnitDecl(), Loc, D->getDepth(), |
| 4281 | D->getPosition(), D->isParameterPack(), Name.getAsIdentifierInfo(), |
| 4282 | TemplateParams); |
| 4283 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4284 | } |
| 4285 | |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4286 | // Returns the definition for a (forward) declaration of a ClassTemplateDecl, if |
| 4287 | // it has any definition in the redecl chain. |
| 4288 | static ClassTemplateDecl *getDefinition(ClassTemplateDecl *D) { |
| 4289 | CXXRecordDecl *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| 4290 | if (!ToTemplatedDef) |
| 4291 | return nullptr; |
| 4292 | ClassTemplateDecl *TemplateWithDef = |
| 4293 | ToTemplatedDef->getDescribedClassTemplate(); |
| 4294 | return TemplateWithDef; |
| 4295 | } |
| 4296 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4297 | Decl *ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 4298 | // If this record has a definition in the translation unit we're coming from, |
| 4299 | // but this particular declaration is not that definition, import the |
| 4300 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4301 | auto *Definition = |
| 4302 | cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4303 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 4304 | Decl *ImportedDef |
| 4305 | = Importer.Import(Definition->getDescribedClassTemplate()); |
| 4306 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4307 | return nullptr; |
| 4308 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4309 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4310 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4311 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4312 | // Import the major distinguishing characteristics of this class template. |
| 4313 | DeclContext *DC, *LexicalDC; |
| 4314 | DeclarationName Name; |
| 4315 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4316 | NamedDecl *ToD; |
| 4317 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4318 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4319 | if (ToD) |
| 4320 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4321 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4322 | // We may already have a template of the same name; try to find and match it. |
| 4323 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4324 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4325 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4326 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4327 | for (auto *FoundDecl : FoundDecls) { |
| 4328 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4329 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4330 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4331 | Decl *Found = FoundDecl; |
| 4332 | if (auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found)) { |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4333 | |
| 4334 | // The class to be imported is a definition. |
| 4335 | if (D->isThisDeclarationADefinition()) { |
| 4336 | // Lookup will find the fwd decl only if that is more recent than the |
| 4337 | // definition. So, try to get the definition if that is available in |
| 4338 | // the redecl chain. |
| 4339 | ClassTemplateDecl *TemplateWithDef = getDefinition(FoundTemplate); |
| 4340 | if (!TemplateWithDef) |
| 4341 | continue; |
| 4342 | FoundTemplate = TemplateWithDef; // Continue with the definition. |
| 4343 | } |
| 4344 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4345 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 4346 | // The class templates structurally match; call it the same template. |
Aleksei Sidorin | 761c224 | 2018-05-15 11:09:07 +0000 | [diff] [blame] | 4347 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4348 | Importer.MapImported(D->getTemplatedDecl(), |
| 4349 | FoundTemplate->getTemplatedDecl()); |
| 4350 | return Importer.MapImported(D, FoundTemplate); |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4351 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4352 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4353 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4354 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4355 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4356 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4357 | if (!ConflictingDecls.empty()) { |
| 4358 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4359 | ConflictingDecls.data(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4360 | ConflictingDecls.size()); |
| 4361 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4362 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4363 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4364 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4365 | } |
| 4366 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4367 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 4368 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4369 | // Create the declaration that is being templated. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4370 | auto *ToTemplated = cast_or_null<CXXRecordDecl>( |
| 4371 | Importer.Import(FromTemplated)); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4372 | if (!ToTemplated) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4373 | return nullptr; |
| 4374 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4375 | // Create the class template declaration itself. |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4376 | TemplateParameterList *TemplateParams = |
| 4377 | ImportTemplateParameterList(D->getTemplateParameters()); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4378 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4379 | return nullptr; |
| 4380 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4381 | ClassTemplateDecl *D2; |
| 4382 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
| 4383 | TemplateParams, ToTemplated)) |
| 4384 | return D2; |
| 4385 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4386 | ToTemplated->setDescribedClassTemplate(D2); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4387 | |
| 4388 | D2->setAccess(D->getAccess()); |
| 4389 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4390 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4391 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4392 | if (FromTemplated->isCompleteDefinition() && |
| 4393 | !ToTemplated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4394 | // FIXME: Import definition! |
| 4395 | } |
| 4396 | |
| 4397 | return D2; |
| 4398 | } |
| 4399 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4400 | Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
| 4401 | ClassTemplateSpecializationDecl *D) { |
| 4402 | // If this record has a definition in the translation unit we're coming from, |
| 4403 | // but this particular declaration is not that definition, import the |
| 4404 | // definition and map to that. |
| 4405 | TagDecl *Definition = D->getDefinition(); |
| 4406 | if (Definition && Definition != D) { |
| 4407 | Decl *ImportedDef = Importer.Import(Definition); |
| 4408 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4409 | return nullptr; |
| 4410 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4411 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4412 | } |
| 4413 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4414 | auto *ClassTemplate = |
| 4415 | cast_or_null<ClassTemplateDecl>(Importer.Import( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4416 | D->getSpecializedTemplate())); |
| 4417 | if (!ClassTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4418 | return nullptr; |
| 4419 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4420 | // Import the context of this declaration. |
| 4421 | DeclContext *DC = ClassTemplate->getDeclContext(); |
| 4422 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4423 | return nullptr; |
| 4424 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4425 | DeclContext *LexicalDC = DC; |
| 4426 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4427 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4428 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4429 | return nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4430 | } |
| 4431 | |
| 4432 | // Import the location of this declaration. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 4433 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 4434 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4435 | |
| 4436 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4437 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4438 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 4439 | D->getTemplateArgs().size(), |
| 4440 | TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4441 | return nullptr; |
| 4442 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4443 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4444 | void *InsertPos = nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4445 | ClassTemplateSpecializationDecl *D2 |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 4446 | = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4447 | if (D2) { |
| 4448 | // We already have a class template specialization with these template |
| 4449 | // arguments. |
| 4450 | |
| 4451 | // FIXME: Check for specialization vs. instantiation errors. |
| 4452 | |
| 4453 | if (RecordDecl *FoundDef = D2->getDefinition()) { |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4454 | if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4455 | // The record types structurally match, or the "from" translation |
| 4456 | // unit only had a forward declaration anyway; call it the same |
| 4457 | // function. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4458 | return Importer.MapImported(D, FoundDef); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4459 | } |
| 4460 | } |
| 4461 | } else { |
| 4462 | // Create a new specialization. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4463 | if (auto *PartialSpec = |
| 4464 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4465 | // Import TemplateArgumentListInfo |
| 4466 | TemplateArgumentListInfo ToTAInfo; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4467 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 4468 | if (ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4469 | return nullptr; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4470 | |
| 4471 | QualType CanonInjType = Importer.Import( |
| 4472 | PartialSpec->getInjectedSpecializationType()); |
| 4473 | if (CanonInjType.isNull()) |
| 4474 | return nullptr; |
| 4475 | CanonInjType = CanonInjType.getCanonicalType(); |
| 4476 | |
| 4477 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 4478 | PartialSpec->getTemplateParameters()); |
| 4479 | if (!ToTPList && PartialSpec->getTemplateParameters()) |
| 4480 | return nullptr; |
| 4481 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4482 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
| 4483 | D2, D, Importer.getToContext(), D->getTagKind(), DC, StartLoc, |
| 4484 | IdLoc, ToTPList, ClassTemplate, |
| 4485 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 4486 | ToTAInfo, CanonInjType, nullptr)) |
| 4487 | return D2; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4488 | |
| 4489 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4490 | if (GetImportedOrCreateDecl( |
| 4491 | D2, D, Importer.getToContext(), D->getTagKind(), DC, StartLoc, |
| 4492 | IdLoc, ClassTemplate, TemplateArgs, /*PrevDecl=*/nullptr)) |
| 4493 | return D2; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4494 | } |
| 4495 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4496 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 4497 | |
| 4498 | // Add this specialization to the class template. |
| 4499 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 4500 | |
| 4501 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4502 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4503 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4504 | if (auto *TSI = D->getTypeAsWritten()) { |
| 4505 | TypeSourceInfo *TInfo = Importer.Import(TSI); |
| 4506 | if (!TInfo) |
| 4507 | return nullptr; |
| 4508 | D2->setTypeAsWritten(TInfo); |
| 4509 | D2->setTemplateKeywordLoc(Importer.Import(D->getTemplateKeywordLoc())); |
| 4510 | D2->setExternLoc(Importer.Import(D->getExternLoc())); |
| 4511 | } |
| 4512 | |
| 4513 | SourceLocation POI = Importer.Import(D->getPointOfInstantiation()); |
| 4514 | if (POI.isValid()) |
| 4515 | D2->setPointOfInstantiation(POI); |
| 4516 | else if (D->getPointOfInstantiation().isValid()) |
| 4517 | return nullptr; |
| 4518 | |
| 4519 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 4520 | |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 4521 | // Set the context of this specialization/instantiation. |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4522 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 4523 | |
| 4524 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 4525 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 4526 | LexicalDC->addDeclInternal(D2); |
| 4527 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4528 | } |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4529 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4530 | return nullptr; |
| 4531 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4532 | return D2; |
| 4533 | } |
| 4534 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4535 | Decl *ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| 4536 | // If this variable has a definition in the translation unit we're coming |
| 4537 | // from, |
| 4538 | // but this particular declaration is not that definition, import the |
| 4539 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4540 | auto *Definition = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4541 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 4542 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 4543 | Decl *ImportedDef = Importer.Import(Definition->getDescribedVarTemplate()); |
| 4544 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4545 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4546 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4547 | return Importer.MapImported(D, ImportedDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4548 | } |
| 4549 | |
| 4550 | // Import the major distinguishing characteristics of this variable template. |
| 4551 | DeclContext *DC, *LexicalDC; |
| 4552 | DeclarationName Name; |
| 4553 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4554 | NamedDecl *ToD; |
| 4555 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4556 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4557 | if (ToD) |
| 4558 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4559 | |
| 4560 | // We may already have a template of the same name; try to find and match it. |
| 4561 | assert(!DC->isFunctionOrMethod() && |
| 4562 | "Variable templates cannot be declared at function scope"); |
| 4563 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 4564 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4565 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4566 | for (auto *FoundDecl : FoundDecls) { |
| 4567 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4568 | continue; |
| 4569 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4570 | Decl *Found = FoundDecl; |
| 4571 | if (auto *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4572 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 4573 | // The variable templates structurally match; call it the same template. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4574 | Importer.MapImported(D->getTemplatedDecl(), |
| 4575 | FoundTemplate->getTemplatedDecl()); |
| 4576 | return Importer.MapImported(D, FoundTemplate); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4577 | } |
| 4578 | } |
| 4579 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4580 | ConflictingDecls.push_back(FoundDecl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4581 | } |
| 4582 | |
| 4583 | if (!ConflictingDecls.empty()) { |
| 4584 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 4585 | ConflictingDecls.data(), |
| 4586 | ConflictingDecls.size()); |
| 4587 | } |
| 4588 | |
| 4589 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4590 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4591 | |
| 4592 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 4593 | |
| 4594 | // Import the type. |
| 4595 | QualType T = Importer.Import(DTemplated->getType()); |
| 4596 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4597 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4598 | |
| 4599 | // Create the declaration that is being templated. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4600 | auto *ToTemplated = dyn_cast_or_null<VarDecl>(Importer.Import(DTemplated)); |
| 4601 | if (!ToTemplated) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4602 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4603 | |
| 4604 | // Create the variable template declaration itself. |
| 4605 | TemplateParameterList *TemplateParams = |
| 4606 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4607 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4608 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4609 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4610 | VarTemplateDecl *ToVarTD; |
| 4611 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
| 4612 | Name, TemplateParams, ToTemplated)) |
| 4613 | return ToVarTD; |
| 4614 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4615 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4616 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4617 | ToVarTD->setAccess(D->getAccess()); |
| 4618 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 4619 | LexicalDC->addDeclInternal(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4620 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4621 | if (DTemplated->isThisDeclarationADefinition() && |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4622 | !ToTemplated->isThisDeclarationADefinition()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4623 | // FIXME: Import definition! |
| 4624 | } |
| 4625 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4626 | return ToVarTD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4627 | } |
| 4628 | |
| 4629 | Decl *ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
| 4630 | VarTemplateSpecializationDecl *D) { |
| 4631 | // If this record has a definition in the translation unit we're coming from, |
| 4632 | // but this particular declaration is not that definition, import the |
| 4633 | // definition and map to that. |
| 4634 | VarDecl *Definition = D->getDefinition(); |
| 4635 | if (Definition && Definition != D) { |
| 4636 | Decl *ImportedDef = Importer.Import(Definition); |
| 4637 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4638 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4639 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4640 | return Importer.MapImported(D, ImportedDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4641 | } |
| 4642 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4643 | auto *VarTemplate = cast_or_null<VarTemplateDecl>( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4644 | Importer.Import(D->getSpecializedTemplate())); |
| 4645 | if (!VarTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4646 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4647 | |
| 4648 | // Import the context of this declaration. |
| 4649 | DeclContext *DC = VarTemplate->getDeclContext(); |
| 4650 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4651 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4652 | |
| 4653 | DeclContext *LexicalDC = DC; |
| 4654 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4655 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4656 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4657 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4658 | } |
| 4659 | |
| 4660 | // Import the location of this declaration. |
| 4661 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 4662 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
| 4663 | |
| 4664 | // Import template arguments. |
| 4665 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| 4666 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 4667 | D->getTemplateArgs().size(), TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4668 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4669 | |
| 4670 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4671 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4672 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 4673 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4674 | if (D2) { |
| 4675 | // We already have a variable template specialization with these template |
| 4676 | // arguments. |
| 4677 | |
| 4678 | // FIXME: Check for specialization vs. instantiation errors. |
| 4679 | |
| 4680 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 4681 | if (!D->isThisDeclarationADefinition() || |
| 4682 | IsStructuralMatch(D, FoundDef)) { |
| 4683 | // The record types structurally match, or the "from" translation |
| 4684 | // unit only had a forward declaration anyway; call it the same |
| 4685 | // variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4686 | return Importer.MapImported(D, FoundDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4687 | } |
| 4688 | } |
| 4689 | } else { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4690 | // Import the type. |
| 4691 | QualType T = Importer.Import(D->getType()); |
| 4692 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4693 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4694 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4695 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 4696 | if (D->getTypeSourceInfo() && !TInfo) |
| 4697 | return nullptr; |
| 4698 | |
| 4699 | TemplateArgumentListInfo ToTAInfo; |
| 4700 | if (ImportTemplateArgumentListInfo(D->getTemplateArgsInfo(), ToTAInfo)) |
| 4701 | return nullptr; |
| 4702 | |
| 4703 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4704 | // Create a new specialization. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4705 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 4706 | // Import TemplateArgumentListInfo |
| 4707 | TemplateArgumentListInfo ArgInfos; |
| 4708 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 4709 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
| 4710 | if (ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ArgInfos)) |
| 4711 | return nullptr; |
| 4712 | |
| 4713 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 4714 | FromPartial->getTemplateParameters()); |
| 4715 | if (!ToTPList) |
| 4716 | return nullptr; |
| 4717 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4718 | PartVarSpecDecl *ToPartial; |
| 4719 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
| 4720 | StartLoc, IdLoc, ToTPList, VarTemplate, T, |
| 4721 | TInfo, D->getStorageClass(), TemplateArgs, |
| 4722 | ArgInfos)) |
| 4723 | return ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4724 | |
| 4725 | auto *FromInst = FromPartial->getInstantiatedFromMember(); |
| 4726 | auto *ToInst = cast_or_null<PartVarSpecDecl>(Importer.Import(FromInst)); |
| 4727 | if (FromInst && !ToInst) |
| 4728 | return nullptr; |
| 4729 | |
| 4730 | ToPartial->setInstantiatedFromMember(ToInst); |
| 4731 | if (FromPartial->isMemberSpecialization()) |
| 4732 | ToPartial->setMemberSpecialization(); |
| 4733 | |
| 4734 | D2 = ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4735 | } else { // Full specialization |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4736 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, StartLoc, |
| 4737 | IdLoc, VarTemplate, T, TInfo, |
| 4738 | D->getStorageClass(), TemplateArgs)) |
| 4739 | return D2; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | SourceLocation POI = D->getPointOfInstantiation(); |
| 4743 | if (POI.isValid()) |
| 4744 | D2->setPointOfInstantiation(Importer.Import(POI)); |
| 4745 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4746 | D2->setSpecializationKind(D->getSpecializationKind()); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4747 | D2->setTemplateArgsInfo(ToTAInfo); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4748 | |
| 4749 | // Add this specialization to the class template. |
| 4750 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 4751 | |
| 4752 | // Import the qualifier, if any. |
| 4753 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
| 4754 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4755 | if (D->isConstexpr()) |
| 4756 | D2->setConstexpr(true); |
| 4757 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4758 | // Add the specialization to this context. |
| 4759 | D2->setLexicalDeclContext(LexicalDC); |
| 4760 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4761 | |
| 4762 | D2->setAccess(D->getAccess()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4763 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4764 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4765 | // NOTE: isThisDeclarationADefinition() can return DeclarationOnly even if |
| 4766 | // declaration has initializer. Should this be fixed in the AST?.. Anyway, |
| 4767 | // we have to check the declaration for initializer - otherwise, it won't be |
| 4768 | // imported. |
| 4769 | if ((D->isThisDeclarationADefinition() || D->hasInit()) && |
| 4770 | ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4771 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4772 | |
| 4773 | return D2; |
| 4774 | } |
| 4775 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4776 | Decl *ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 4777 | DeclContext *DC, *LexicalDC; |
| 4778 | DeclarationName Name; |
| 4779 | SourceLocation Loc; |
| 4780 | NamedDecl *ToD; |
| 4781 | |
| 4782 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4783 | return nullptr; |
| 4784 | |
| 4785 | if (ToD) |
| 4786 | return ToD; |
| 4787 | |
| 4788 | // Try to find a function in our own ("to") context with the same name, same |
| 4789 | // type, and in the same context as the function we're importing. |
| 4790 | if (!LexicalDC->isFunctionOrMethod()) { |
| 4791 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 4792 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 4793 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4794 | for (auto *FoundDecl : FoundDecls) { |
| 4795 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4796 | continue; |
| 4797 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4798 | if (auto *FoundFunction = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4799 | if (FoundFunction->hasExternalFormalLinkage() && |
| 4800 | D->hasExternalFormalLinkage()) { |
| 4801 | if (IsStructuralMatch(D, FoundFunction)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4802 | Importer.MapImported(D, FoundFunction); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4803 | // FIXME: Actually try to merge the body and other attributes. |
| 4804 | return FoundFunction; |
| 4805 | } |
| 4806 | } |
| 4807 | } |
| 4808 | } |
| 4809 | } |
| 4810 | |
| 4811 | TemplateParameterList *Params = |
| 4812 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4813 | if (!Params) |
| 4814 | return nullptr; |
| 4815 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4816 | auto *TemplatedFD = |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4817 | cast_or_null<FunctionDecl>(Importer.Import(D->getTemplatedDecl())); |
| 4818 | if (!TemplatedFD) |
| 4819 | return nullptr; |
| 4820 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 4821 | FunctionTemplateDecl *ToFunc; |
| 4822 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
| 4823 | Params, TemplatedFD)) |
| 4824 | return ToFunc; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4825 | |
| 4826 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| 4827 | ToFunc->setAccess(D->getAccess()); |
| 4828 | ToFunc->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4829 | |
| 4830 | LexicalDC->addDeclInternal(ToFunc); |
| 4831 | return ToFunc; |
| 4832 | } |
| 4833 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4834 | //---------------------------------------------------------------------------- |
| 4835 | // Import Statements |
| 4836 | //---------------------------------------------------------------------------- |
| 4837 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4838 | DeclGroupRef ASTNodeImporter::ImportDeclGroup(DeclGroupRef DG) { |
| 4839 | if (DG.isNull()) |
| 4840 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 4841 | size_t NumDecls = DG.end() - DG.begin(); |
| 4842 | SmallVector<Decl *, 1> ToDecls(NumDecls); |
| 4843 | auto &_Importer = this->Importer; |
| 4844 | std::transform(DG.begin(), DG.end(), ToDecls.begin(), |
| 4845 | [&_Importer](Decl *D) -> Decl * { |
| 4846 | return _Importer.Import(D); |
| 4847 | }); |
| 4848 | return DeclGroupRef::Create(Importer.getToContext(), |
| 4849 | ToDecls.begin(), |
| 4850 | NumDecls); |
| 4851 | } |
| 4852 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4853 | Stmt *ASTNodeImporter::VisitStmt(Stmt *S) { |
| 4854 | Importer.FromDiag(S->getLocStart(), diag::err_unsupported_ast_node) |
| 4855 | << S->getStmtClassName(); |
| 4856 | return nullptr; |
| 4857 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4858 | |
| 4859 | Stmt *ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
| 4860 | SmallVector<IdentifierInfo *, 4> Names; |
| 4861 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 4862 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 4863 | // ToII is nullptr when no symbolic name is given for output operand |
| 4864 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 4865 | if (!ToII && S->getOutputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4866 | return nullptr; |
| 4867 | Names.push_back(ToII); |
| 4868 | } |
| 4869 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 4870 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 4871 | // ToII is nullptr when no symbolic name is given for input operand |
| 4872 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 4873 | if (!ToII && S->getInputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4874 | return nullptr; |
| 4875 | Names.push_back(ToII); |
| 4876 | } |
| 4877 | |
| 4878 | SmallVector<StringLiteral *, 4> Clobbers; |
| 4879 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4880 | auto *Clobber = cast_or_null<StringLiteral>( |
| 4881 | Importer.Import(S->getClobberStringLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4882 | if (!Clobber) |
| 4883 | return nullptr; |
| 4884 | Clobbers.push_back(Clobber); |
| 4885 | } |
| 4886 | |
| 4887 | SmallVector<StringLiteral *, 4> Constraints; |
| 4888 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4889 | auto *Output = cast_or_null<StringLiteral>( |
| 4890 | Importer.Import(S->getOutputConstraintLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4891 | if (!Output) |
| 4892 | return nullptr; |
| 4893 | Constraints.push_back(Output); |
| 4894 | } |
| 4895 | |
| 4896 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4897 | auto *Input = cast_or_null<StringLiteral>( |
| 4898 | Importer.Import(S->getInputConstraintLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4899 | if (!Input) |
| 4900 | return nullptr; |
| 4901 | Constraints.push_back(Input); |
| 4902 | } |
| 4903 | |
| 4904 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4905 | if (ImportContainerChecked(S->outputs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4906 | return nullptr; |
| 4907 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4908 | if (ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4909 | return nullptr; |
| 4910 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4911 | auto *AsmStr = cast_or_null<StringLiteral>( |
| 4912 | Importer.Import(S->getAsmString())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4913 | if (!AsmStr) |
| 4914 | return nullptr; |
| 4915 | |
| 4916 | return new (Importer.getToContext()) GCCAsmStmt( |
| 4917 | Importer.getToContext(), |
| 4918 | Importer.Import(S->getAsmLoc()), |
| 4919 | S->isSimple(), |
| 4920 | S->isVolatile(), |
| 4921 | S->getNumOutputs(), |
| 4922 | S->getNumInputs(), |
| 4923 | Names.data(), |
| 4924 | Constraints.data(), |
| 4925 | Exprs.data(), |
| 4926 | AsmStr, |
| 4927 | S->getNumClobbers(), |
| 4928 | Clobbers.data(), |
| 4929 | Importer.Import(S->getRParenLoc())); |
| 4930 | } |
| 4931 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4932 | Stmt *ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 4933 | DeclGroupRef ToDG = ImportDeclGroup(S->getDeclGroup()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4934 | for (auto *ToD : ToDG) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4935 | if (!ToD) |
| 4936 | return nullptr; |
| 4937 | } |
| 4938 | SourceLocation ToStartLoc = Importer.Import(S->getStartLoc()); |
| 4939 | SourceLocation ToEndLoc = Importer.Import(S->getEndLoc()); |
| 4940 | return new (Importer.getToContext()) DeclStmt(ToDG, ToStartLoc, ToEndLoc); |
| 4941 | } |
| 4942 | |
| 4943 | Stmt *ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 4944 | SourceLocation ToSemiLoc = Importer.Import(S->getSemiLoc()); |
| 4945 | return new (Importer.getToContext()) NullStmt(ToSemiLoc, |
| 4946 | S->hasLeadingEmptyMacro()); |
| 4947 | } |
| 4948 | |
| 4949 | Stmt *ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4950 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4951 | |
| 4952 | if (ImportContainerChecked(S->body(), ToStmts)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 4953 | return nullptr; |
| 4954 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4955 | SourceLocation ToLBraceLoc = Importer.Import(S->getLBracLoc()); |
| 4956 | SourceLocation ToRBraceLoc = Importer.Import(S->getRBracLoc()); |
Benjamin Kramer | 0742090 | 2017-12-24 16:24:20 +0000 | [diff] [blame] | 4957 | return CompoundStmt::Create(Importer.getToContext(), ToStmts, ToLBraceLoc, |
| 4958 | ToRBraceLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4959 | } |
| 4960 | |
| 4961 | Stmt *ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 4962 | Expr *ToLHS = Importer.Import(S->getLHS()); |
| 4963 | if (!ToLHS) |
| 4964 | return nullptr; |
| 4965 | Expr *ToRHS = Importer.Import(S->getRHS()); |
| 4966 | if (!ToRHS && S->getRHS()) |
| 4967 | return nullptr; |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 4968 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4969 | if (!ToSubStmt && S->getSubStmt()) |
| 4970 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4971 | SourceLocation ToCaseLoc = Importer.Import(S->getCaseLoc()); |
| 4972 | SourceLocation ToEllipsisLoc = Importer.Import(S->getEllipsisLoc()); |
| 4973 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4974 | auto *ToStmt = new (Importer.getToContext()) |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 4975 | CaseStmt(ToLHS, ToRHS, ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
| 4976 | ToStmt->setSubStmt(ToSubStmt); |
| 4977 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | Stmt *ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 4981 | SourceLocation ToDefaultLoc = Importer.Import(S->getDefaultLoc()); |
| 4982 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 4983 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4984 | if (!ToSubStmt && S->getSubStmt()) |
| 4985 | return nullptr; |
| 4986 | return new (Importer.getToContext()) DefaultStmt(ToDefaultLoc, ToColonLoc, |
| 4987 | ToSubStmt); |
| 4988 | } |
| 4989 | |
| 4990 | Stmt *ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 4991 | SourceLocation ToIdentLoc = Importer.Import(S->getIdentLoc()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4992 | auto *ToLabelDecl = cast_or_null<LabelDecl>(Importer.Import(S->getDecl())); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4993 | if (!ToLabelDecl && S->getDecl()) |
| 4994 | return nullptr; |
| 4995 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4996 | if (!ToSubStmt && S->getSubStmt()) |
| 4997 | return nullptr; |
| 4998 | return new (Importer.getToContext()) LabelStmt(ToIdentLoc, ToLabelDecl, |
| 4999 | ToSubStmt); |
| 5000 | } |
| 5001 | |
| 5002 | Stmt *ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 5003 | SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc()); |
| 5004 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 5005 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 5006 | if (ImportContainerChecked(FromAttrs, ToAttrs)) |
| 5007 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5008 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5009 | if (!ToSubStmt && S->getSubStmt()) |
| 5010 | return nullptr; |
| 5011 | return AttributedStmt::Create(Importer.getToContext(), ToAttrLoc, |
| 5012 | ToAttrs, ToSubStmt); |
| 5013 | } |
| 5014 | |
| 5015 | Stmt *ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 5016 | SourceLocation ToIfLoc = Importer.Import(S->getIfLoc()); |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 5017 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 5018 | if (!ToInit && S->getInit()) |
| 5019 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5020 | VarDecl *ToConditionVariable = nullptr; |
| 5021 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5022 | ToConditionVariable = |
| 5023 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5024 | if (!ToConditionVariable) |
| 5025 | return nullptr; |
| 5026 | } |
| 5027 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5028 | if (!ToCondition && S->getCond()) |
| 5029 | return nullptr; |
| 5030 | Stmt *ToThenStmt = Importer.Import(S->getThen()); |
| 5031 | if (!ToThenStmt && S->getThen()) |
| 5032 | return nullptr; |
| 5033 | SourceLocation ToElseLoc = Importer.Import(S->getElseLoc()); |
| 5034 | Stmt *ToElseStmt = Importer.Import(S->getElse()); |
| 5035 | if (!ToElseStmt && S->getElse()) |
| 5036 | return nullptr; |
| 5037 | return new (Importer.getToContext()) IfStmt(Importer.getToContext(), |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 5038 | ToIfLoc, S->isConstexpr(), |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 5039 | ToInit, |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 5040 | ToConditionVariable, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5041 | ToCondition, ToThenStmt, |
| 5042 | ToElseLoc, ToElseStmt); |
| 5043 | } |
| 5044 | |
| 5045 | Stmt *ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 5046 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 5047 | if (!ToInit && S->getInit()) |
| 5048 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5049 | VarDecl *ToConditionVariable = nullptr; |
| 5050 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5051 | ToConditionVariable = |
| 5052 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5053 | if (!ToConditionVariable) |
| 5054 | return nullptr; |
| 5055 | } |
| 5056 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5057 | if (!ToCondition && S->getCond()) |
| 5058 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5059 | auto *ToStmt = new (Importer.getToContext()) SwitchStmt( |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 5060 | Importer.getToContext(), ToInit, |
| 5061 | ToConditionVariable, ToCondition); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5062 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5063 | if (!ToBody && S->getBody()) |
| 5064 | return nullptr; |
| 5065 | ToStmt->setBody(ToBody); |
| 5066 | ToStmt->setSwitchLoc(Importer.Import(S->getSwitchLoc())); |
| 5067 | // Now we have to re-chain the cases. |
| 5068 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 5069 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 5070 | SC = SC->getNextSwitchCase()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5071 | auto *ToSC = dyn_cast_or_null<SwitchCase>(Importer.Import(SC)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5072 | if (!ToSC) |
| 5073 | return nullptr; |
| 5074 | if (LastChainedSwitchCase) |
| 5075 | LastChainedSwitchCase->setNextSwitchCase(ToSC); |
| 5076 | else |
| 5077 | ToStmt->setSwitchCaseList(ToSC); |
| 5078 | LastChainedSwitchCase = ToSC; |
| 5079 | } |
| 5080 | return ToStmt; |
| 5081 | } |
| 5082 | |
| 5083 | Stmt *ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 5084 | VarDecl *ToConditionVariable = nullptr; |
| 5085 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5086 | ToConditionVariable = |
| 5087 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5088 | if (!ToConditionVariable) |
| 5089 | return nullptr; |
| 5090 | } |
| 5091 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5092 | if (!ToCondition && S->getCond()) |
| 5093 | return nullptr; |
| 5094 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5095 | if (!ToBody && S->getBody()) |
| 5096 | return nullptr; |
| 5097 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 5098 | return new (Importer.getToContext()) WhileStmt(Importer.getToContext(), |
| 5099 | ToConditionVariable, |
| 5100 | ToCondition, ToBody, |
| 5101 | ToWhileLoc); |
| 5102 | } |
| 5103 | |
| 5104 | Stmt *ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 5105 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5106 | if (!ToBody && S->getBody()) |
| 5107 | return nullptr; |
| 5108 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5109 | if (!ToCondition && S->getCond()) |
| 5110 | return nullptr; |
| 5111 | SourceLocation ToDoLoc = Importer.Import(S->getDoLoc()); |
| 5112 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 5113 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5114 | return new (Importer.getToContext()) DoStmt(ToBody, ToCondition, |
| 5115 | ToDoLoc, ToWhileLoc, |
| 5116 | ToRParenLoc); |
| 5117 | } |
| 5118 | |
| 5119 | Stmt *ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 5120 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 5121 | if (!ToInit && S->getInit()) |
| 5122 | return nullptr; |
| 5123 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5124 | if (!ToCondition && S->getCond()) |
| 5125 | return nullptr; |
| 5126 | VarDecl *ToConditionVariable = nullptr; |
| 5127 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5128 | ToConditionVariable = |
| 5129 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5130 | if (!ToConditionVariable) |
| 5131 | return nullptr; |
| 5132 | } |
| 5133 | Expr *ToInc = Importer.Import(S->getInc()); |
| 5134 | if (!ToInc && S->getInc()) |
| 5135 | return nullptr; |
| 5136 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5137 | if (!ToBody && S->getBody()) |
| 5138 | return nullptr; |
| 5139 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 5140 | SourceLocation ToLParenLoc = Importer.Import(S->getLParenLoc()); |
| 5141 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5142 | return new (Importer.getToContext()) ForStmt(Importer.getToContext(), |
| 5143 | ToInit, ToCondition, |
| 5144 | ToConditionVariable, |
| 5145 | ToInc, ToBody, |
| 5146 | ToForLoc, ToLParenLoc, |
| 5147 | ToRParenLoc); |
| 5148 | } |
| 5149 | |
| 5150 | Stmt *ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 5151 | LabelDecl *ToLabel = nullptr; |
| 5152 | if (LabelDecl *FromLabel = S->getLabel()) { |
| 5153 | ToLabel = dyn_cast_or_null<LabelDecl>(Importer.Import(FromLabel)); |
| 5154 | if (!ToLabel) |
| 5155 | return nullptr; |
| 5156 | } |
| 5157 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 5158 | SourceLocation ToLabelLoc = Importer.Import(S->getLabelLoc()); |
| 5159 | return new (Importer.getToContext()) GotoStmt(ToLabel, |
| 5160 | ToGotoLoc, ToLabelLoc); |
| 5161 | } |
| 5162 | |
| 5163 | Stmt *ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 5164 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 5165 | SourceLocation ToStarLoc = Importer.Import(S->getStarLoc()); |
| 5166 | Expr *ToTarget = Importer.Import(S->getTarget()); |
| 5167 | if (!ToTarget && S->getTarget()) |
| 5168 | return nullptr; |
| 5169 | return new (Importer.getToContext()) IndirectGotoStmt(ToGotoLoc, ToStarLoc, |
| 5170 | ToTarget); |
| 5171 | } |
| 5172 | |
| 5173 | Stmt *ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 5174 | SourceLocation ToContinueLoc = Importer.Import(S->getContinueLoc()); |
| 5175 | return new (Importer.getToContext()) ContinueStmt(ToContinueLoc); |
| 5176 | } |
| 5177 | |
| 5178 | Stmt *ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 5179 | SourceLocation ToBreakLoc = Importer.Import(S->getBreakLoc()); |
| 5180 | return new (Importer.getToContext()) BreakStmt(ToBreakLoc); |
| 5181 | } |
| 5182 | |
| 5183 | Stmt *ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 5184 | SourceLocation ToRetLoc = Importer.Import(S->getReturnLoc()); |
| 5185 | Expr *ToRetExpr = Importer.Import(S->getRetValue()); |
| 5186 | if (!ToRetExpr && S->getRetValue()) |
| 5187 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5188 | auto *NRVOCandidate = const_cast<VarDecl *>(S->getNRVOCandidate()); |
| 5189 | auto *ToNRVOCandidate = cast_or_null<VarDecl>(Importer.Import(NRVOCandidate)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5190 | if (!ToNRVOCandidate && NRVOCandidate) |
| 5191 | return nullptr; |
| 5192 | return new (Importer.getToContext()) ReturnStmt(ToRetLoc, ToRetExpr, |
| 5193 | ToNRVOCandidate); |
| 5194 | } |
| 5195 | |
| 5196 | Stmt *ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 5197 | SourceLocation ToCatchLoc = Importer.Import(S->getCatchLoc()); |
| 5198 | VarDecl *ToExceptionDecl = nullptr; |
| 5199 | if (VarDecl *FromExceptionDecl = S->getExceptionDecl()) { |
| 5200 | ToExceptionDecl = |
| 5201 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 5202 | if (!ToExceptionDecl) |
| 5203 | return nullptr; |
| 5204 | } |
| 5205 | Stmt *ToHandlerBlock = Importer.Import(S->getHandlerBlock()); |
| 5206 | if (!ToHandlerBlock && S->getHandlerBlock()) |
| 5207 | return nullptr; |
| 5208 | return new (Importer.getToContext()) CXXCatchStmt(ToCatchLoc, |
| 5209 | ToExceptionDecl, |
| 5210 | ToHandlerBlock); |
| 5211 | } |
| 5212 | |
| 5213 | Stmt *ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 5214 | SourceLocation ToTryLoc = Importer.Import(S->getTryLoc()); |
| 5215 | Stmt *ToTryBlock = Importer.Import(S->getTryBlock()); |
| 5216 | if (!ToTryBlock && S->getTryBlock()) |
| 5217 | return nullptr; |
| 5218 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 5219 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 5220 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
| 5221 | if (Stmt *ToHandler = Importer.Import(FromHandler)) |
| 5222 | ToHandlers[HI] = ToHandler; |
| 5223 | else |
| 5224 | return nullptr; |
| 5225 | } |
| 5226 | return CXXTryStmt::Create(Importer.getToContext(), ToTryLoc, ToTryBlock, |
| 5227 | ToHandlers); |
| 5228 | } |
| 5229 | |
| 5230 | Stmt *ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5231 | auto *ToRange = |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5232 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getRangeStmt())); |
| 5233 | if (!ToRange && S->getRangeStmt()) |
| 5234 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5235 | auto *ToBegin = |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5236 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getBeginStmt())); |
| 5237 | if (!ToBegin && S->getBeginStmt()) |
| 5238 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5239 | auto *ToEnd = |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5240 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getEndStmt())); |
| 5241 | if (!ToEnd && S->getEndStmt()) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5242 | return nullptr; |
| 5243 | Expr *ToCond = Importer.Import(S->getCond()); |
| 5244 | if (!ToCond && S->getCond()) |
| 5245 | return nullptr; |
| 5246 | Expr *ToInc = Importer.Import(S->getInc()); |
| 5247 | if (!ToInc && S->getInc()) |
| 5248 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5249 | auto *ToLoopVar = |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5250 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getLoopVarStmt())); |
| 5251 | if (!ToLoopVar && S->getLoopVarStmt()) |
| 5252 | return nullptr; |
| 5253 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5254 | if (!ToBody && S->getBody()) |
| 5255 | return nullptr; |
| 5256 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 5257 | SourceLocation ToCoawaitLoc = Importer.Import(S->getCoawaitLoc()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5258 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 5259 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5260 | return new (Importer.getToContext()) CXXForRangeStmt(ToRange, ToBegin, ToEnd, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5261 | ToCond, ToInc, |
| 5262 | ToLoopVar, ToBody, |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 5263 | ToForLoc, ToCoawaitLoc, |
| 5264 | ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5265 | } |
| 5266 | |
| 5267 | Stmt *ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 5268 | Stmt *ToElem = Importer.Import(S->getElement()); |
| 5269 | if (!ToElem && S->getElement()) |
| 5270 | return nullptr; |
| 5271 | Expr *ToCollect = Importer.Import(S->getCollection()); |
| 5272 | if (!ToCollect && S->getCollection()) |
| 5273 | return nullptr; |
| 5274 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5275 | if (!ToBody && S->getBody()) |
| 5276 | return nullptr; |
| 5277 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 5278 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5279 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElem, |
| 5280 | ToCollect, |
| 5281 | ToBody, ToForLoc, |
| 5282 | ToRParenLoc); |
| 5283 | } |
| 5284 | |
| 5285 | Stmt *ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 5286 | SourceLocation ToAtCatchLoc = Importer.Import(S->getAtCatchLoc()); |
| 5287 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5288 | VarDecl *ToExceptionDecl = nullptr; |
| 5289 | if (VarDecl *FromExceptionDecl = S->getCatchParamDecl()) { |
| 5290 | ToExceptionDecl = |
| 5291 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 5292 | if (!ToExceptionDecl) |
| 5293 | return nullptr; |
| 5294 | } |
| 5295 | Stmt *ToBody = Importer.Import(S->getCatchBody()); |
| 5296 | if (!ToBody && S->getCatchBody()) |
| 5297 | return nullptr; |
| 5298 | return new (Importer.getToContext()) ObjCAtCatchStmt(ToAtCatchLoc, |
| 5299 | ToRParenLoc, |
| 5300 | ToExceptionDecl, |
| 5301 | ToBody); |
| 5302 | } |
| 5303 | |
| 5304 | Stmt *ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 5305 | SourceLocation ToAtFinallyLoc = Importer.Import(S->getAtFinallyLoc()); |
| 5306 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyBody()); |
| 5307 | if (!ToAtFinallyStmt && S->getFinallyBody()) |
| 5308 | return nullptr; |
| 5309 | return new (Importer.getToContext()) ObjCAtFinallyStmt(ToAtFinallyLoc, |
| 5310 | ToAtFinallyStmt); |
| 5311 | } |
| 5312 | |
| 5313 | Stmt *ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 5314 | SourceLocation ToAtTryLoc = Importer.Import(S->getAtTryLoc()); |
| 5315 | Stmt *ToAtTryStmt = Importer.Import(S->getTryBody()); |
| 5316 | if (!ToAtTryStmt && S->getTryBody()) |
| 5317 | return nullptr; |
| 5318 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 5319 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 5320 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
| 5321 | if (Stmt *ToCatchStmt = Importer.Import(FromCatchStmt)) |
| 5322 | ToCatchStmts[CI] = ToCatchStmt; |
| 5323 | else |
| 5324 | return nullptr; |
| 5325 | } |
| 5326 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyStmt()); |
| 5327 | if (!ToAtFinallyStmt && S->getFinallyStmt()) |
| 5328 | return nullptr; |
| 5329 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
| 5330 | ToAtTryLoc, ToAtTryStmt, |
| 5331 | ToCatchStmts.begin(), ToCatchStmts.size(), |
| 5332 | ToAtFinallyStmt); |
| 5333 | } |
| 5334 | |
| 5335 | Stmt *ASTNodeImporter::VisitObjCAtSynchronizedStmt |
| 5336 | (ObjCAtSynchronizedStmt *S) { |
| 5337 | SourceLocation ToAtSynchronizedLoc = |
| 5338 | Importer.Import(S->getAtSynchronizedLoc()); |
| 5339 | Expr *ToSynchExpr = Importer.Import(S->getSynchExpr()); |
| 5340 | if (!ToSynchExpr && S->getSynchExpr()) |
| 5341 | return nullptr; |
| 5342 | Stmt *ToSynchBody = Importer.Import(S->getSynchBody()); |
| 5343 | if (!ToSynchBody && S->getSynchBody()) |
| 5344 | return nullptr; |
| 5345 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 5346 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 5347 | } |
| 5348 | |
| 5349 | Stmt *ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 5350 | SourceLocation ToAtThrowLoc = Importer.Import(S->getThrowLoc()); |
| 5351 | Expr *ToThrow = Importer.Import(S->getThrowExpr()); |
| 5352 | if (!ToThrow && S->getThrowExpr()) |
| 5353 | return nullptr; |
| 5354 | return new (Importer.getToContext()) ObjCAtThrowStmt(ToAtThrowLoc, ToThrow); |
| 5355 | } |
| 5356 | |
| 5357 | Stmt *ASTNodeImporter::VisitObjCAutoreleasePoolStmt |
| 5358 | (ObjCAutoreleasePoolStmt *S) { |
| 5359 | SourceLocation ToAtLoc = Importer.Import(S->getAtLoc()); |
| 5360 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5361 | if (!ToSubStmt && S->getSubStmt()) |
| 5362 | return nullptr; |
| 5363 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(ToAtLoc, |
| 5364 | ToSubStmt); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5365 | } |
| 5366 | |
| 5367 | //---------------------------------------------------------------------------- |
| 5368 | // Import Expressions |
| 5369 | //---------------------------------------------------------------------------- |
| 5370 | Expr *ASTNodeImporter::VisitExpr(Expr *E) { |
| 5371 | Importer.FromDiag(E->getLocStart(), diag::err_unsupported_ast_node) |
| 5372 | << E->getStmtClassName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5373 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5374 | } |
| 5375 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5376 | Expr *ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 5377 | QualType T = Importer.Import(E->getType()); |
| 5378 | if (T.isNull()) |
| 5379 | return nullptr; |
| 5380 | |
| 5381 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5382 | if (!SubExpr && E->getSubExpr()) |
| 5383 | return nullptr; |
| 5384 | |
| 5385 | TypeSourceInfo *TInfo = Importer.Import(E->getWrittenTypeInfo()); |
| 5386 | if (!TInfo) |
| 5387 | return nullptr; |
| 5388 | |
| 5389 | return new (Importer.getToContext()) VAArgExpr( |
| 5390 | Importer.Import(E->getBuiltinLoc()), SubExpr, TInfo, |
| 5391 | Importer.Import(E->getRParenLoc()), T, E->isMicrosoftABI()); |
| 5392 | } |
| 5393 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5394 | Expr *ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 5395 | QualType T = Importer.Import(E->getType()); |
| 5396 | if (T.isNull()) |
| 5397 | return nullptr; |
| 5398 | |
| 5399 | return new (Importer.getToContext()) GNUNullExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5400 | T, Importer.Import(E->getLocStart())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5401 | } |
| 5402 | |
| 5403 | Expr *ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 5404 | QualType T = Importer.Import(E->getType()); |
| 5405 | if (T.isNull()) |
| 5406 | return nullptr; |
| 5407 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5408 | auto *SL = cast_or_null<StringLiteral>(Importer.Import(E->getFunctionName())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5409 | if (!SL && E->getFunctionName()) |
| 5410 | return nullptr; |
| 5411 | |
| 5412 | return new (Importer.getToContext()) PredefinedExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5413 | Importer.Import(E->getLocStart()), T, E->getIdentType(), SL); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5414 | } |
| 5415 | |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5416 | Expr *ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5417 | auto *ToD = cast_or_null<ValueDecl>(Importer.Import(E->getDecl())); |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5418 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5419 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5420 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5421 | NamedDecl *FoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5422 | if (E->getDecl() != E->getFoundDecl()) { |
| 5423 | FoundD = cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl())); |
| 5424 | if (!FoundD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5425 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5426 | } |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5427 | |
| 5428 | QualType T = Importer.Import(E->getType()); |
| 5429 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5430 | return nullptr; |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5431 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5432 | TemplateArgumentListInfo ToTAInfo; |
| 5433 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 5434 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5435 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 5436 | return nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5437 | ResInfo = &ToTAInfo; |
| 5438 | } |
| 5439 | |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5440 | DeclRefExpr *DRE = DeclRefExpr::Create(Importer.getToContext(), |
| 5441 | Importer.Import(E->getQualifierLoc()), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 5442 | Importer.Import(E->getTemplateKeywordLoc()), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5443 | ToD, |
Alexey Bataev | 19acc3d | 2015-01-12 10:17:46 +0000 | [diff] [blame] | 5444 | E->refersToEnclosingVariableOrCapture(), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5445 | Importer.Import(E->getLocation()), |
| 5446 | T, E->getValueKind(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5447 | FoundD, ResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5448 | if (E->hadMultipleCandidates()) |
| 5449 | DRE->setHadMultipleCandidates(true); |
| 5450 | return DRE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5451 | } |
| 5452 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5453 | Expr *ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 5454 | QualType T = Importer.Import(E->getType()); |
| 5455 | if (T.isNull()) |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5456 | return nullptr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5457 | |
| 5458 | return new (Importer.getToContext()) ImplicitValueInitExpr(T); |
| 5459 | } |
| 5460 | |
| 5461 | ASTNodeImporter::Designator |
| 5462 | ASTNodeImporter::ImportDesignator(const Designator &D) { |
| 5463 | if (D.isFieldDesignator()) { |
| 5464 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 5465 | // Caller checks for import error |
| 5466 | return Designator(ToFieldName, Importer.Import(D.getDotLoc()), |
| 5467 | Importer.Import(D.getFieldLoc())); |
| 5468 | } |
| 5469 | if (D.isArrayDesignator()) |
| 5470 | return Designator(D.getFirstExprIndex(), |
| 5471 | Importer.Import(D.getLBracketLoc()), |
| 5472 | Importer.Import(D.getRBracketLoc())); |
| 5473 | |
| 5474 | assert(D.isArrayRangeDesignator()); |
| 5475 | return Designator(D.getFirstExprIndex(), |
| 5476 | Importer.Import(D.getLBracketLoc()), |
| 5477 | Importer.Import(D.getEllipsisLoc()), |
| 5478 | Importer.Import(D.getRBracketLoc())); |
| 5479 | } |
| 5480 | |
| 5481 | |
| 5482 | Expr *ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *DIE) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5483 | auto *Init = cast_or_null<Expr>(Importer.Import(DIE->getInit())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5484 | if (!Init) |
| 5485 | return nullptr; |
| 5486 | |
| 5487 | SmallVector<Expr *, 4> IndexExprs(DIE->getNumSubExprs() - 1); |
| 5488 | // List elements from the second, the first is Init itself |
| 5489 | for (unsigned I = 1, E = DIE->getNumSubExprs(); I < E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5490 | if (auto *Arg = cast_or_null<Expr>(Importer.Import(DIE->getSubExpr(I)))) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5491 | IndexExprs[I - 1] = Arg; |
| 5492 | else |
| 5493 | return nullptr; |
| 5494 | } |
| 5495 | |
| 5496 | SmallVector<Designator, 4> Designators(DIE->size()); |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5497 | llvm::transform(DIE->designators(), Designators.begin(), |
| 5498 | [this](const Designator &D) -> Designator { |
| 5499 | return ImportDesignator(D); |
| 5500 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5501 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5502 | for (const auto &D : DIE->designators()) |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5503 | if (D.isFieldDesignator() && !D.getFieldName()) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5504 | return nullptr; |
| 5505 | |
| 5506 | return DesignatedInitExpr::Create( |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5507 | Importer.getToContext(), Designators, |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5508 | IndexExprs, Importer.Import(DIE->getEqualOrColonLoc()), |
| 5509 | DIE->usesGNUSyntax(), Init); |
| 5510 | } |
| 5511 | |
| 5512 | Expr *ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 5513 | QualType T = Importer.Import(E->getType()); |
| 5514 | if (T.isNull()) |
| 5515 | return nullptr; |
| 5516 | |
| 5517 | return new (Importer.getToContext()) |
| 5518 | CXXNullPtrLiteralExpr(T, Importer.Import(E->getLocation())); |
| 5519 | } |
| 5520 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5521 | Expr *ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 5522 | QualType T = Importer.Import(E->getType()); |
| 5523 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5524 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5525 | |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 5526 | return IntegerLiteral::Create(Importer.getToContext(), |
| 5527 | E->getValue(), T, |
| 5528 | Importer.Import(E->getLocation())); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5529 | } |
| 5530 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5531 | Expr *ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 5532 | QualType T = Importer.Import(E->getType()); |
| 5533 | if (T.isNull()) |
| 5534 | return nullptr; |
| 5535 | |
| 5536 | return FloatingLiteral::Create(Importer.getToContext(), |
| 5537 | E->getValue(), E->isExact(), T, |
| 5538 | Importer.Import(E->getLocation())); |
| 5539 | } |
| 5540 | |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5541 | Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 5542 | QualType T = Importer.Import(E->getType()); |
| 5543 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5544 | return nullptr; |
| 5545 | |
Douglas Gregor | fb65e59 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 5546 | return new (Importer.getToContext()) CharacterLiteral(E->getValue(), |
| 5547 | E->getKind(), T, |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5548 | Importer.Import(E->getLocation())); |
| 5549 | } |
| 5550 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5551 | Expr *ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 5552 | QualType T = Importer.Import(E->getType()); |
| 5553 | if (T.isNull()) |
| 5554 | return nullptr; |
| 5555 | |
| 5556 | SmallVector<SourceLocation, 4> Locations(E->getNumConcatenated()); |
| 5557 | ImportArray(E->tokloc_begin(), E->tokloc_end(), Locations.begin()); |
| 5558 | |
| 5559 | return StringLiteral::Create(Importer.getToContext(), E->getBytes(), |
| 5560 | E->getKind(), E->isPascal(), T, |
| 5561 | Locations.data(), Locations.size()); |
| 5562 | } |
| 5563 | |
| 5564 | Expr *ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 5565 | QualType T = Importer.Import(E->getType()); |
| 5566 | if (T.isNull()) |
| 5567 | return nullptr; |
| 5568 | |
| 5569 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeSourceInfo()); |
| 5570 | if (!TInfo) |
| 5571 | return nullptr; |
| 5572 | |
| 5573 | Expr *Init = Importer.Import(E->getInitializer()); |
| 5574 | if (!Init) |
| 5575 | return nullptr; |
| 5576 | |
| 5577 | return new (Importer.getToContext()) CompoundLiteralExpr( |
| 5578 | Importer.Import(E->getLParenLoc()), TInfo, T, E->getValueKind(), |
| 5579 | Init, E->isFileScope()); |
| 5580 | } |
| 5581 | |
| 5582 | Expr *ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 5583 | QualType T = Importer.Import(E->getType()); |
| 5584 | if (T.isNull()) |
| 5585 | return nullptr; |
| 5586 | |
| 5587 | SmallVector<Expr *, 6> Exprs(E->getNumSubExprs()); |
| 5588 | if (ImportArrayChecked( |
| 5589 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 5590 | Exprs.begin())) |
| 5591 | return nullptr; |
| 5592 | |
| 5593 | return new (Importer.getToContext()) AtomicExpr( |
| 5594 | Importer.Import(E->getBuiltinLoc()), Exprs, T, E->getOp(), |
| 5595 | Importer.Import(E->getRParenLoc())); |
| 5596 | } |
| 5597 | |
| 5598 | Expr *ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 5599 | QualType T = Importer.Import(E->getType()); |
| 5600 | if (T.isNull()) |
| 5601 | return nullptr; |
| 5602 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5603 | auto *ToLabel = cast_or_null<LabelDecl>(Importer.Import(E->getLabel())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5604 | if (!ToLabel) |
| 5605 | return nullptr; |
| 5606 | |
| 5607 | return new (Importer.getToContext()) AddrLabelExpr( |
| 5608 | Importer.Import(E->getAmpAmpLoc()), Importer.Import(E->getLabelLoc()), |
| 5609 | ToLabel, T); |
| 5610 | } |
| 5611 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5612 | Expr *ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 5613 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5614 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5615 | return nullptr; |
| 5616 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5617 | return new (Importer.getToContext()) |
| 5618 | ParenExpr(Importer.Import(E->getLParen()), |
| 5619 | Importer.Import(E->getRParen()), |
| 5620 | SubExpr); |
| 5621 | } |
| 5622 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5623 | Expr *ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 5624 | SmallVector<Expr *, 4> Exprs(E->getNumExprs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5625 | if (ImportContainerChecked(E->exprs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5626 | return nullptr; |
| 5627 | |
| 5628 | return new (Importer.getToContext()) ParenListExpr( |
| 5629 | Importer.getToContext(), Importer.Import(E->getLParenLoc()), |
| 5630 | Exprs, Importer.Import(E->getLParenLoc())); |
| 5631 | } |
| 5632 | |
| 5633 | Expr *ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 5634 | QualType T = Importer.Import(E->getType()); |
| 5635 | if (T.isNull()) |
| 5636 | return nullptr; |
| 5637 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5638 | auto *ToSubStmt = cast_or_null<CompoundStmt>( |
| 5639 | Importer.Import(E->getSubStmt())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5640 | if (!ToSubStmt && E->getSubStmt()) |
| 5641 | return nullptr; |
| 5642 | |
| 5643 | return new (Importer.getToContext()) StmtExpr(ToSubStmt, T, |
| 5644 | Importer.Import(E->getLParenLoc()), Importer.Import(E->getRParenLoc())); |
| 5645 | } |
| 5646 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5647 | Expr *ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 5648 | QualType T = Importer.Import(E->getType()); |
| 5649 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5650 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5651 | |
| 5652 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5653 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5654 | return nullptr; |
| 5655 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5656 | return new (Importer.getToContext()) UnaryOperator( |
| 5657 | SubExpr, E->getOpcode(), T, E->getValueKind(), E->getObjectKind(), |
| 5658 | Importer.Import(E->getOperatorLoc()), E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5659 | } |
| 5660 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5661 | Expr * |
| 5662 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5663 | QualType ResultType = Importer.Import(E->getType()); |
| 5664 | |
| 5665 | if (E->isArgumentType()) { |
| 5666 | TypeSourceInfo *TInfo = Importer.Import(E->getArgumentTypeInfo()); |
| 5667 | if (!TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5668 | return nullptr; |
| 5669 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5670 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5671 | TInfo, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5672 | Importer.Import(E->getOperatorLoc()), |
| 5673 | Importer.Import(E->getRParenLoc())); |
| 5674 | } |
| 5675 | |
| 5676 | Expr *SubExpr = Importer.Import(E->getArgumentExpr()); |
| 5677 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5678 | return nullptr; |
| 5679 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5680 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5681 | SubExpr, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5682 | Importer.Import(E->getOperatorLoc()), |
| 5683 | Importer.Import(E->getRParenLoc())); |
| 5684 | } |
| 5685 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5686 | Expr *ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 5687 | QualType T = Importer.Import(E->getType()); |
| 5688 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5689 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5690 | |
| 5691 | Expr *LHS = Importer.Import(E->getLHS()); |
| 5692 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5693 | return nullptr; |
| 5694 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5695 | Expr *RHS = Importer.Import(E->getRHS()); |
| 5696 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5697 | return nullptr; |
| 5698 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5699 | return new (Importer.getToContext()) BinaryOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 5700 | T, E->getValueKind(), |
| 5701 | E->getObjectKind(), |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 5702 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 5703 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5704 | } |
| 5705 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5706 | Expr *ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 5707 | QualType T = Importer.Import(E->getType()); |
| 5708 | if (T.isNull()) |
| 5709 | return nullptr; |
| 5710 | |
| 5711 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5712 | if (!ToLHS) |
| 5713 | return nullptr; |
| 5714 | |
| 5715 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5716 | if (!ToRHS) |
| 5717 | return nullptr; |
| 5718 | |
| 5719 | Expr *ToCond = Importer.Import(E->getCond()); |
| 5720 | if (!ToCond) |
| 5721 | return nullptr; |
| 5722 | |
| 5723 | return new (Importer.getToContext()) ConditionalOperator( |
| 5724 | ToCond, Importer.Import(E->getQuestionLoc()), |
| 5725 | ToLHS, Importer.Import(E->getColonLoc()), |
| 5726 | ToRHS, T, E->getValueKind(), E->getObjectKind()); |
| 5727 | } |
| 5728 | |
| 5729 | Expr *ASTNodeImporter::VisitBinaryConditionalOperator( |
| 5730 | BinaryConditionalOperator *E) { |
| 5731 | QualType T = Importer.Import(E->getType()); |
| 5732 | if (T.isNull()) |
| 5733 | return nullptr; |
| 5734 | |
| 5735 | Expr *Common = Importer.Import(E->getCommon()); |
| 5736 | if (!Common) |
| 5737 | return nullptr; |
| 5738 | |
| 5739 | Expr *Cond = Importer.Import(E->getCond()); |
| 5740 | if (!Cond) |
| 5741 | return nullptr; |
| 5742 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5743 | auto *OpaqueValue = cast_or_null<OpaqueValueExpr>( |
| 5744 | Importer.Import(E->getOpaqueValue())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5745 | if (!OpaqueValue) |
| 5746 | return nullptr; |
| 5747 | |
| 5748 | Expr *TrueExpr = Importer.Import(E->getTrueExpr()); |
| 5749 | if (!TrueExpr) |
| 5750 | return nullptr; |
| 5751 | |
| 5752 | Expr *FalseExpr = Importer.Import(E->getFalseExpr()); |
| 5753 | if (!FalseExpr) |
| 5754 | return nullptr; |
| 5755 | |
| 5756 | return new (Importer.getToContext()) BinaryConditionalOperator( |
| 5757 | Common, OpaqueValue, Cond, TrueExpr, FalseExpr, |
| 5758 | Importer.Import(E->getQuestionLoc()), Importer.Import(E->getColonLoc()), |
| 5759 | T, E->getValueKind(), E->getObjectKind()); |
| 5760 | } |
| 5761 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5762 | Expr *ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 5763 | QualType T = Importer.Import(E->getType()); |
| 5764 | if (T.isNull()) |
| 5765 | return nullptr; |
| 5766 | |
| 5767 | TypeSourceInfo *ToQueried = Importer.Import(E->getQueriedTypeSourceInfo()); |
| 5768 | if (!ToQueried) |
| 5769 | return nullptr; |
| 5770 | |
| 5771 | Expr *Dim = Importer.Import(E->getDimensionExpression()); |
| 5772 | if (!Dim && E->getDimensionExpression()) |
| 5773 | return nullptr; |
| 5774 | |
| 5775 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
| 5776 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 5777 | E->getValue(), Dim, Importer.Import(E->getLocEnd()), T); |
| 5778 | } |
| 5779 | |
| 5780 | Expr *ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 5781 | QualType T = Importer.Import(E->getType()); |
| 5782 | if (T.isNull()) |
| 5783 | return nullptr; |
| 5784 | |
| 5785 | Expr *ToQueried = Importer.Import(E->getQueriedExpression()); |
| 5786 | if (!ToQueried) |
| 5787 | return nullptr; |
| 5788 | |
| 5789 | return new (Importer.getToContext()) ExpressionTraitExpr( |
| 5790 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 5791 | E->getValue(), Importer.Import(E->getLocEnd()), T); |
| 5792 | } |
| 5793 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5794 | Expr *ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 5795 | QualType T = Importer.Import(E->getType()); |
| 5796 | if (T.isNull()) |
| 5797 | return nullptr; |
| 5798 | |
| 5799 | Expr *SourceExpr = Importer.Import(E->getSourceExpr()); |
| 5800 | if (!SourceExpr && E->getSourceExpr()) |
| 5801 | return nullptr; |
| 5802 | |
| 5803 | return new (Importer.getToContext()) OpaqueValueExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5804 | Importer.Import(E->getLocation()), T, E->getValueKind(), |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5805 | E->getObjectKind(), SourceExpr); |
| 5806 | } |
| 5807 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5808 | Expr *ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 5809 | QualType T = Importer.Import(E->getType()); |
| 5810 | if (T.isNull()) |
| 5811 | return nullptr; |
| 5812 | |
| 5813 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5814 | if (!ToLHS) |
| 5815 | return nullptr; |
| 5816 | |
| 5817 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5818 | if (!ToRHS) |
| 5819 | return nullptr; |
| 5820 | |
| 5821 | return new (Importer.getToContext()) ArraySubscriptExpr( |
| 5822 | ToLHS, ToRHS, T, E->getValueKind(), E->getObjectKind(), |
| 5823 | Importer.Import(E->getRBracketLoc())); |
| 5824 | } |
| 5825 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5826 | Expr *ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 5827 | QualType T = Importer.Import(E->getType()); |
| 5828 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5829 | return nullptr; |
| 5830 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5831 | QualType CompLHSType = Importer.Import(E->getComputationLHSType()); |
| 5832 | if (CompLHSType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5833 | return nullptr; |
| 5834 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5835 | QualType CompResultType = Importer.Import(E->getComputationResultType()); |
| 5836 | if (CompResultType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5837 | return nullptr; |
| 5838 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5839 | Expr *LHS = Importer.Import(E->getLHS()); |
| 5840 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5841 | return nullptr; |
| 5842 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5843 | Expr *RHS = Importer.Import(E->getRHS()); |
| 5844 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5845 | return nullptr; |
| 5846 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5847 | return new (Importer.getToContext()) |
| 5848 | CompoundAssignOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 5849 | T, E->getValueKind(), |
| 5850 | E->getObjectKind(), |
| 5851 | CompLHSType, CompResultType, |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 5852 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 5853 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5854 | } |
| 5855 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5856 | bool ASTNodeImporter::ImportCastPath(CastExpr *CE, CXXCastPath &Path) { |
| 5857 | for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) { |
| 5858 | if (CXXBaseSpecifier *Spec = Importer.Import(*I)) |
| 5859 | Path.push_back(Spec); |
| 5860 | else |
| 5861 | return true; |
| 5862 | } |
| 5863 | return false; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5864 | } |
| 5865 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5866 | Expr *ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 5867 | QualType T = Importer.Import(E->getType()); |
| 5868 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5869 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5870 | |
| 5871 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5872 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5873 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5874 | |
| 5875 | CXXCastPath BasePath; |
| 5876 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5877 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5878 | |
| 5879 | return ImplicitCastExpr::Create(Importer.getToContext(), T, E->getCastKind(), |
John McCall | 2536c6d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 5880 | SubExpr, &BasePath, E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5881 | } |
| 5882 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5883 | Expr *ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5884 | QualType T = Importer.Import(E->getType()); |
| 5885 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5886 | return nullptr; |
| 5887 | |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5888 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5889 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5890 | return nullptr; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5891 | |
| 5892 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeInfoAsWritten()); |
| 5893 | if (!TInfo && E->getTypeInfoAsWritten()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5894 | return nullptr; |
| 5895 | |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5896 | CXXCastPath BasePath; |
| 5897 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5898 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5899 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5900 | switch (E->getStmtClass()) { |
| 5901 | case Stmt::CStyleCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5902 | auto *CCE = cast<CStyleCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5903 | return CStyleCastExpr::Create(Importer.getToContext(), T, |
| 5904 | E->getValueKind(), E->getCastKind(), |
| 5905 | SubExpr, &BasePath, TInfo, |
| 5906 | Importer.Import(CCE->getLParenLoc()), |
| 5907 | Importer.Import(CCE->getRParenLoc())); |
| 5908 | } |
| 5909 | |
| 5910 | case Stmt::CXXFunctionalCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5911 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5912 | return CXXFunctionalCastExpr::Create(Importer.getToContext(), T, |
| 5913 | E->getValueKind(), TInfo, |
| 5914 | E->getCastKind(), SubExpr, &BasePath, |
| 5915 | Importer.Import(FCE->getLParenLoc()), |
| 5916 | Importer.Import(FCE->getRParenLoc())); |
| 5917 | } |
| 5918 | |
| 5919 | case Stmt::ObjCBridgedCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5920 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5921 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 5922 | Importer.Import(OCE->getLParenLoc()), OCE->getBridgeKind(), |
| 5923 | E->getCastKind(), Importer.Import(OCE->getBridgeKeywordLoc()), |
| 5924 | TInfo, SubExpr); |
| 5925 | } |
| 5926 | default: |
| 5927 | break; // just fall through |
| 5928 | } |
| 5929 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5930 | auto *Named = cast<CXXNamedCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5931 | SourceLocation ExprLoc = Importer.Import(Named->getOperatorLoc()), |
| 5932 | RParenLoc = Importer.Import(Named->getRParenLoc()); |
| 5933 | SourceRange Brackets = Importer.Import(Named->getAngleBrackets()); |
| 5934 | |
| 5935 | switch (E->getStmtClass()) { |
| 5936 | case Stmt::CXXStaticCastExprClass: |
| 5937 | return CXXStaticCastExpr::Create(Importer.getToContext(), T, |
| 5938 | E->getValueKind(), E->getCastKind(), |
| 5939 | SubExpr, &BasePath, TInfo, |
| 5940 | ExprLoc, RParenLoc, Brackets); |
| 5941 | |
| 5942 | case Stmt::CXXDynamicCastExprClass: |
| 5943 | return CXXDynamicCastExpr::Create(Importer.getToContext(), T, |
| 5944 | E->getValueKind(), E->getCastKind(), |
| 5945 | SubExpr, &BasePath, TInfo, |
| 5946 | ExprLoc, RParenLoc, Brackets); |
| 5947 | |
| 5948 | case Stmt::CXXReinterpretCastExprClass: |
| 5949 | return CXXReinterpretCastExpr::Create(Importer.getToContext(), T, |
| 5950 | E->getValueKind(), E->getCastKind(), |
| 5951 | SubExpr, &BasePath, TInfo, |
| 5952 | ExprLoc, RParenLoc, Brackets); |
| 5953 | |
| 5954 | case Stmt::CXXConstCastExprClass: |
| 5955 | return CXXConstCastExpr::Create(Importer.getToContext(), T, |
| 5956 | E->getValueKind(), SubExpr, TInfo, ExprLoc, |
| 5957 | RParenLoc, Brackets); |
| 5958 | default: |
| 5959 | llvm_unreachable("Cast expression of unsupported type!"); |
| 5960 | return nullptr; |
| 5961 | } |
| 5962 | } |
| 5963 | |
| 5964 | Expr *ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *OE) { |
| 5965 | QualType T = Importer.Import(OE->getType()); |
| 5966 | if (T.isNull()) |
| 5967 | return nullptr; |
| 5968 | |
| 5969 | SmallVector<OffsetOfNode, 4> Nodes; |
| 5970 | for (int I = 0, E = OE->getNumComponents(); I < E; ++I) { |
| 5971 | const OffsetOfNode &Node = OE->getComponent(I); |
| 5972 | |
| 5973 | switch (Node.getKind()) { |
| 5974 | case OffsetOfNode::Array: |
| 5975 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), |
| 5976 | Node.getArrayExprIndex(), |
| 5977 | Importer.Import(Node.getLocEnd()))); |
| 5978 | break; |
| 5979 | |
| 5980 | case OffsetOfNode::Base: { |
| 5981 | CXXBaseSpecifier *BS = Importer.Import(Node.getBase()); |
| 5982 | if (!BS && Node.getBase()) |
| 5983 | return nullptr; |
| 5984 | Nodes.push_back(OffsetOfNode(BS)); |
| 5985 | break; |
| 5986 | } |
| 5987 | case OffsetOfNode::Field: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5988 | auto *FD = cast_or_null<FieldDecl>(Importer.Import(Node.getField())); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5989 | if (!FD) |
| 5990 | return nullptr; |
| 5991 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), FD, |
| 5992 | Importer.Import(Node.getLocEnd()))); |
| 5993 | break; |
| 5994 | } |
| 5995 | case OffsetOfNode::Identifier: { |
| 5996 | IdentifierInfo *ToII = Importer.Import(Node.getFieldName()); |
| 5997 | if (!ToII) |
| 5998 | return nullptr; |
| 5999 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), ToII, |
| 6000 | Importer.Import(Node.getLocEnd()))); |
| 6001 | break; |
| 6002 | } |
| 6003 | } |
| 6004 | } |
| 6005 | |
| 6006 | SmallVector<Expr *, 4> Exprs(OE->getNumExpressions()); |
| 6007 | for (int I = 0, E = OE->getNumExpressions(); I < E; ++I) { |
| 6008 | Expr *ToIndexExpr = Importer.Import(OE->getIndexExpr(I)); |
| 6009 | if (!ToIndexExpr) |
| 6010 | return nullptr; |
| 6011 | Exprs[I] = ToIndexExpr; |
| 6012 | } |
| 6013 | |
| 6014 | TypeSourceInfo *TInfo = Importer.Import(OE->getTypeSourceInfo()); |
| 6015 | if (!TInfo && OE->getTypeSourceInfo()) |
| 6016 | return nullptr; |
| 6017 | |
| 6018 | return OffsetOfExpr::Create(Importer.getToContext(), T, |
| 6019 | Importer.Import(OE->getOperatorLoc()), |
| 6020 | TInfo, Nodes, Exprs, |
| 6021 | Importer.Import(OE->getRParenLoc())); |
| 6022 | } |
| 6023 | |
| 6024 | Expr *ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 6025 | QualType T = Importer.Import(E->getType()); |
| 6026 | if (T.isNull()) |
| 6027 | return nullptr; |
| 6028 | |
| 6029 | Expr *Operand = Importer.Import(E->getOperand()); |
| 6030 | if (!Operand) |
| 6031 | return nullptr; |
| 6032 | |
| 6033 | CanThrowResult CanThrow; |
| 6034 | if (E->isValueDependent()) |
| 6035 | CanThrow = CT_Dependent; |
| 6036 | else |
| 6037 | CanThrow = E->getValue() ? CT_Can : CT_Cannot; |
| 6038 | |
| 6039 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 6040 | T, Operand, CanThrow, |
| 6041 | Importer.Import(E->getLocStart()), Importer.Import(E->getLocEnd())); |
| 6042 | } |
| 6043 | |
| 6044 | Expr *ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 6045 | QualType T = Importer.Import(E->getType()); |
| 6046 | if (T.isNull()) |
| 6047 | return nullptr; |
| 6048 | |
| 6049 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 6050 | if (!SubExpr && E->getSubExpr()) |
| 6051 | return nullptr; |
| 6052 | |
| 6053 | return new (Importer.getToContext()) CXXThrowExpr( |
| 6054 | SubExpr, T, Importer.Import(E->getThrowLoc()), |
| 6055 | E->isThrownVariableInScope()); |
| 6056 | } |
| 6057 | |
| 6058 | Expr *ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6059 | auto *Param = cast_or_null<ParmVarDecl>(Importer.Import(E->getParam())); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6060 | if (!Param) |
| 6061 | return nullptr; |
| 6062 | |
| 6063 | return CXXDefaultArgExpr::Create( |
| 6064 | Importer.getToContext(), Importer.Import(E->getUsedLocation()), Param); |
| 6065 | } |
| 6066 | |
| 6067 | Expr *ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 6068 | QualType T = Importer.Import(E->getType()); |
| 6069 | if (T.isNull()) |
| 6070 | return nullptr; |
| 6071 | |
| 6072 | TypeSourceInfo *TypeInfo = Importer.Import(E->getTypeSourceInfo()); |
| 6073 | if (!TypeInfo) |
| 6074 | return nullptr; |
| 6075 | |
| 6076 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
| 6077 | T, TypeInfo, Importer.Import(E->getRParenLoc())); |
| 6078 | } |
| 6079 | |
| 6080 | Expr *ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 6081 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 6082 | if (!SubExpr) |
| 6083 | return nullptr; |
| 6084 | |
| 6085 | auto *Dtor = cast_or_null<CXXDestructorDecl>( |
| 6086 | Importer.Import(const_cast<CXXDestructorDecl *>( |
| 6087 | E->getTemporary()->getDestructor()))); |
| 6088 | if (!Dtor) |
| 6089 | return nullptr; |
| 6090 | |
| 6091 | ASTContext &ToCtx = Importer.getToContext(); |
| 6092 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, Dtor); |
| 6093 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, SubExpr); |
| 6094 | } |
| 6095 | |
| 6096 | Expr *ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE) { |
| 6097 | QualType T = Importer.Import(CE->getType()); |
| 6098 | if (T.isNull()) |
| 6099 | return nullptr; |
| 6100 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6101 | TypeSourceInfo *TInfo = Importer.Import(CE->getTypeSourceInfo()); |
| 6102 | if (!TInfo) |
| 6103 | return nullptr; |
| 6104 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6105 | SmallVector<Expr *, 8> Args(CE->getNumArgs()); |
| 6106 | if (ImportContainerChecked(CE->arguments(), Args)) |
| 6107 | return nullptr; |
| 6108 | |
| 6109 | auto *Ctor = cast_or_null<CXXConstructorDecl>( |
| 6110 | Importer.Import(CE->getConstructor())); |
| 6111 | if (!Ctor) |
| 6112 | return nullptr; |
| 6113 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6114 | return new (Importer.getToContext()) CXXTemporaryObjectExpr( |
| 6115 | Importer.getToContext(), Ctor, T, TInfo, Args, |
| 6116 | Importer.Import(CE->getParenOrBraceRange()), CE->hadMultipleCandidates(), |
| 6117 | CE->isListInitialization(), CE->isStdInitListInitialization(), |
| 6118 | CE->requiresZeroInitialization()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6119 | } |
| 6120 | |
| 6121 | Expr * |
| 6122 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
| 6123 | QualType T = Importer.Import(E->getType()); |
| 6124 | if (T.isNull()) |
| 6125 | return nullptr; |
| 6126 | |
| 6127 | Expr *TempE = Importer.Import(E->GetTemporaryExpr()); |
| 6128 | if (!TempE) |
| 6129 | return nullptr; |
| 6130 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6131 | auto *ExtendedBy = cast_or_null<ValueDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6132 | Importer.Import(const_cast<ValueDecl *>(E->getExtendingDecl()))); |
| 6133 | if (!ExtendedBy && E->getExtendingDecl()) |
| 6134 | return nullptr; |
| 6135 | |
| 6136 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
| 6137 | T, TempE, E->isBoundToLvalueReference()); |
| 6138 | |
| 6139 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
| 6140 | ToMTE->setExtendingDecl(ExtendedBy, E->getManglingNumber()); |
| 6141 | return ToMTE; |
| 6142 | } |
| 6143 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6144 | Expr *ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 6145 | QualType T = Importer.Import(E->getType()); |
| 6146 | if (T.isNull()) |
| 6147 | return nullptr; |
| 6148 | |
| 6149 | Expr *Pattern = Importer.Import(E->getPattern()); |
| 6150 | if (!Pattern) |
| 6151 | return nullptr; |
| 6152 | |
| 6153 | return new (Importer.getToContext()) PackExpansionExpr( |
| 6154 | T, Pattern, Importer.Import(E->getEllipsisLoc()), |
| 6155 | E->getNumExpansions()); |
| 6156 | } |
| 6157 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6158 | Expr *ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 6159 | auto *Pack = cast_or_null<NamedDecl>(Importer.Import(E->getPack())); |
| 6160 | if (!Pack) |
| 6161 | return nullptr; |
| 6162 | |
| 6163 | Optional<unsigned> Length; |
| 6164 | |
| 6165 | if (!E->isValueDependent()) |
| 6166 | Length = E->getPackLength(); |
| 6167 | |
| 6168 | SmallVector<TemplateArgument, 8> PartialArguments; |
| 6169 | if (E->isPartiallySubstituted()) { |
| 6170 | if (ImportTemplateArguments(E->getPartialArguments().data(), |
| 6171 | E->getPartialArguments().size(), |
| 6172 | PartialArguments)) |
| 6173 | return nullptr; |
| 6174 | } |
| 6175 | |
| 6176 | return SizeOfPackExpr::Create( |
| 6177 | Importer.getToContext(), Importer.Import(E->getOperatorLoc()), Pack, |
| 6178 | Importer.Import(E->getPackLoc()), Importer.Import(E->getRParenLoc()), |
| 6179 | Length, PartialArguments); |
| 6180 | } |
| 6181 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6182 | Expr *ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *CE) { |
| 6183 | QualType T = Importer.Import(CE->getType()); |
| 6184 | if (T.isNull()) |
| 6185 | return nullptr; |
| 6186 | |
| 6187 | SmallVector<Expr *, 4> PlacementArgs(CE->getNumPlacementArgs()); |
| 6188 | if (ImportContainerChecked(CE->placement_arguments(), PlacementArgs)) |
| 6189 | return nullptr; |
| 6190 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6191 | auto *OperatorNewDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6192 | Importer.Import(CE->getOperatorNew())); |
| 6193 | if (!OperatorNewDecl && CE->getOperatorNew()) |
| 6194 | return nullptr; |
| 6195 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6196 | auto *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6197 | Importer.Import(CE->getOperatorDelete())); |
| 6198 | if (!OperatorDeleteDecl && CE->getOperatorDelete()) |
| 6199 | return nullptr; |
| 6200 | |
| 6201 | Expr *ToInit = Importer.Import(CE->getInitializer()); |
| 6202 | if (!ToInit && CE->getInitializer()) |
| 6203 | return nullptr; |
| 6204 | |
| 6205 | TypeSourceInfo *TInfo = Importer.Import(CE->getAllocatedTypeSourceInfo()); |
| 6206 | if (!TInfo) |
| 6207 | return nullptr; |
| 6208 | |
| 6209 | Expr *ToArrSize = Importer.Import(CE->getArraySize()); |
| 6210 | if (!ToArrSize && CE->getArraySize()) |
| 6211 | return nullptr; |
| 6212 | |
| 6213 | return new (Importer.getToContext()) CXXNewExpr( |
| 6214 | Importer.getToContext(), |
| 6215 | CE->isGlobalNew(), |
| 6216 | OperatorNewDecl, OperatorDeleteDecl, |
Richard Smith | b2f0f05 | 2016-10-10 18:54:32 +0000 | [diff] [blame] | 6217 | CE->passAlignment(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6218 | CE->doesUsualArrayDeleteWantSize(), |
| 6219 | PlacementArgs, |
| 6220 | Importer.Import(CE->getTypeIdParens()), |
| 6221 | ToArrSize, CE->getInitializationStyle(), ToInit, T, TInfo, |
| 6222 | Importer.Import(CE->getSourceRange()), |
| 6223 | Importer.Import(CE->getDirectInitRange())); |
| 6224 | } |
| 6225 | |
| 6226 | Expr *ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 6227 | QualType T = Importer.Import(E->getType()); |
| 6228 | if (T.isNull()) |
| 6229 | return nullptr; |
| 6230 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6231 | auto *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6232 | Importer.Import(E->getOperatorDelete())); |
| 6233 | if (!OperatorDeleteDecl && E->getOperatorDelete()) |
| 6234 | return nullptr; |
| 6235 | |
| 6236 | Expr *ToArg = Importer.Import(E->getArgument()); |
| 6237 | if (!ToArg && E->getArgument()) |
| 6238 | return nullptr; |
| 6239 | |
| 6240 | return new (Importer.getToContext()) CXXDeleteExpr( |
| 6241 | T, E->isGlobalDelete(), |
| 6242 | E->isArrayForm(), |
| 6243 | E->isArrayFormAsWritten(), |
| 6244 | E->doesUsualArrayDeleteWantSize(), |
| 6245 | OperatorDeleteDecl, |
| 6246 | ToArg, |
| 6247 | Importer.Import(E->getLocStart())); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6248 | } |
| 6249 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6250 | Expr *ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 6251 | QualType T = Importer.Import(E->getType()); |
| 6252 | if (T.isNull()) |
| 6253 | return nullptr; |
| 6254 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6255 | auto *ToCCD = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6256 | dyn_cast_or_null<CXXConstructorDecl>(Importer.Import(E->getConstructor())); |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 6257 | if (!ToCCD) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6258 | return nullptr; |
| 6259 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6260 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6261 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6262 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6263 | |
| 6264 | return CXXConstructExpr::Create(Importer.getToContext(), T, |
| 6265 | Importer.Import(E->getLocation()), |
Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 6266 | ToCCD, E->isElidable(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6267 | ToArgs, E->hadMultipleCandidates(), |
| 6268 | E->isListInitialization(), |
| 6269 | E->isStdInitListInitialization(), |
| 6270 | E->requiresZeroInitialization(), |
| 6271 | E->getConstructionKind(), |
| 6272 | Importer.Import(E->getParenOrBraceRange())); |
| 6273 | } |
| 6274 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6275 | Expr *ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *EWC) { |
| 6276 | Expr *SubExpr = Importer.Import(EWC->getSubExpr()); |
| 6277 | if (!SubExpr && EWC->getSubExpr()) |
| 6278 | return nullptr; |
| 6279 | |
| 6280 | SmallVector<ExprWithCleanups::CleanupObject, 8> Objs(EWC->getNumObjects()); |
| 6281 | for (unsigned I = 0, E = EWC->getNumObjects(); I < E; I++) |
| 6282 | if (ExprWithCleanups::CleanupObject Obj = |
| 6283 | cast_or_null<BlockDecl>(Importer.Import(EWC->getObject(I)))) |
| 6284 | Objs[I] = Obj; |
| 6285 | else |
| 6286 | return nullptr; |
| 6287 | |
| 6288 | return ExprWithCleanups::Create(Importer.getToContext(), |
| 6289 | SubExpr, EWC->cleanupsHaveSideEffects(), |
| 6290 | Objs); |
| 6291 | } |
| 6292 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6293 | Expr *ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6294 | QualType T = Importer.Import(E->getType()); |
| 6295 | if (T.isNull()) |
| 6296 | return nullptr; |
| 6297 | |
| 6298 | Expr *ToFn = Importer.Import(E->getCallee()); |
| 6299 | if (!ToFn) |
| 6300 | return nullptr; |
| 6301 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6302 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6303 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6304 | return nullptr; |
| 6305 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6306 | return new (Importer.getToContext()) CXXMemberCallExpr( |
| 6307 | Importer.getToContext(), ToFn, ToArgs, T, E->getValueKind(), |
| 6308 | Importer.Import(E->getRParenLoc())); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6309 | } |
| 6310 | |
| 6311 | Expr *ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 6312 | QualType T = Importer.Import(E->getType()); |
| 6313 | if (T.isNull()) |
| 6314 | return nullptr; |
| 6315 | |
| 6316 | return new (Importer.getToContext()) |
| 6317 | CXXThisExpr(Importer.Import(E->getLocation()), T, E->isImplicit()); |
| 6318 | } |
| 6319 | |
| 6320 | Expr *ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 6321 | QualType T = Importer.Import(E->getType()); |
| 6322 | if (T.isNull()) |
| 6323 | return nullptr; |
| 6324 | |
| 6325 | return new (Importer.getToContext()) |
| 6326 | CXXBoolLiteralExpr(E->getValue(), T, Importer.Import(E->getLocation())); |
| 6327 | } |
| 6328 | |
| 6329 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6330 | Expr *ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 6331 | QualType T = Importer.Import(E->getType()); |
| 6332 | if (T.isNull()) |
| 6333 | return nullptr; |
| 6334 | |
| 6335 | Expr *ToBase = Importer.Import(E->getBase()); |
| 6336 | if (!ToBase && E->getBase()) |
| 6337 | return nullptr; |
| 6338 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6339 | auto *ToMember = dyn_cast<ValueDecl>(Importer.Import(E->getMemberDecl())); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6340 | if (!ToMember && E->getMemberDecl()) |
| 6341 | return nullptr; |
| 6342 | |
Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 6343 | auto *ToDecl = |
| 6344 | dyn_cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl().getDecl())); |
| 6345 | if (!ToDecl && E->getFoundDecl().getDecl()) |
| 6346 | return nullptr; |
| 6347 | |
| 6348 | DeclAccessPair ToFoundDecl = |
| 6349 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6350 | |
| 6351 | DeclarationNameInfo ToMemberNameInfo( |
| 6352 | Importer.Import(E->getMemberNameInfo().getName()), |
| 6353 | Importer.Import(E->getMemberNameInfo().getLoc())); |
| 6354 | |
| 6355 | if (E->hasExplicitTemplateArgs()) { |
| 6356 | return nullptr; // FIXME: handle template arguments |
| 6357 | } |
| 6358 | |
| 6359 | return MemberExpr::Create(Importer.getToContext(), ToBase, |
| 6360 | E->isArrow(), |
| 6361 | Importer.Import(E->getOperatorLoc()), |
| 6362 | Importer.Import(E->getQualifierLoc()), |
| 6363 | Importer.Import(E->getTemplateKeywordLoc()), |
| 6364 | ToMember, ToFoundDecl, ToMemberNameInfo, |
| 6365 | nullptr, T, E->getValueKind(), |
| 6366 | E->getObjectKind()); |
| 6367 | } |
| 6368 | |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 6369 | Expr *ASTNodeImporter::VisitCXXPseudoDestructorExpr( |
| 6370 | CXXPseudoDestructorExpr *E) { |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 6371 | Expr *BaseE = Importer.Import(E->getBase()); |
| 6372 | if (!BaseE) |
| 6373 | return nullptr; |
| 6374 | |
| 6375 | TypeSourceInfo *ScopeInfo = Importer.Import(E->getScopeTypeInfo()); |
| 6376 | if (!ScopeInfo && E->getScopeTypeInfo()) |
| 6377 | return nullptr; |
| 6378 | |
| 6379 | PseudoDestructorTypeStorage Storage; |
| 6380 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 6381 | IdentifierInfo *ToII = Importer.Import(FromII); |
| 6382 | if (!ToII) |
| 6383 | return nullptr; |
| 6384 | Storage = PseudoDestructorTypeStorage( |
| 6385 | ToII, Importer.Import(E->getDestroyedTypeLoc())); |
| 6386 | } else { |
| 6387 | TypeSourceInfo *TI = Importer.Import(E->getDestroyedTypeInfo()); |
| 6388 | if (!TI) |
| 6389 | return nullptr; |
| 6390 | Storage = PseudoDestructorTypeStorage(TI); |
| 6391 | } |
| 6392 | |
| 6393 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
| 6394 | Importer.getToContext(), BaseE, E->isArrow(), |
| 6395 | Importer.Import(E->getOperatorLoc()), |
| 6396 | Importer.Import(E->getQualifierLoc()), |
| 6397 | ScopeInfo, Importer.Import(E->getColonColonLoc()), |
| 6398 | Importer.Import(E->getTildeLoc()), Storage); |
| 6399 | } |
| 6400 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6401 | Expr *ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
| 6402 | CXXDependentScopeMemberExpr *E) { |
| 6403 | Expr *Base = nullptr; |
| 6404 | if (!E->isImplicitAccess()) { |
| 6405 | Base = Importer.Import(E->getBase()); |
| 6406 | if (!Base) |
| 6407 | return nullptr; |
| 6408 | } |
| 6409 | |
| 6410 | QualType BaseType = Importer.Import(E->getBaseType()); |
| 6411 | if (BaseType.isNull()) |
| 6412 | return nullptr; |
| 6413 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6414 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6415 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6416 | if (ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6417 | E->template_arguments(), ToTAInfo)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6418 | return nullptr; |
| 6419 | ResInfo = &ToTAInfo; |
| 6420 | } |
| 6421 | |
| 6422 | DeclarationName Name = Importer.Import(E->getMember()); |
| 6423 | if (!E->getMember().isEmpty() && Name.isEmpty()) |
| 6424 | return nullptr; |
| 6425 | |
| 6426 | DeclarationNameInfo MemberNameInfo(Name, Importer.Import(E->getMemberLoc())); |
| 6427 | // Import additional name location/type info. |
| 6428 | ImportDeclarationNameLoc(E->getMemberNameInfo(), MemberNameInfo); |
| 6429 | auto ToFQ = Importer.Import(E->getFirstQualifierFoundInScope()); |
| 6430 | if (!ToFQ && E->getFirstQualifierFoundInScope()) |
| 6431 | return nullptr; |
| 6432 | |
| 6433 | return CXXDependentScopeMemberExpr::Create( |
| 6434 | Importer.getToContext(), Base, BaseType, E->isArrow(), |
| 6435 | Importer.Import(E->getOperatorLoc()), |
| 6436 | Importer.Import(E->getQualifierLoc()), |
| 6437 | Importer.Import(E->getTemplateKeywordLoc()), |
| 6438 | cast_or_null<NamedDecl>(ToFQ), MemberNameInfo, ResInfo); |
| 6439 | } |
| 6440 | |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 6441 | Expr * |
| 6442 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
| 6443 | DeclarationName Name = Importer.Import(E->getDeclName()); |
| 6444 | if (!E->getDeclName().isEmpty() && Name.isEmpty()) |
| 6445 | return nullptr; |
| 6446 | |
| 6447 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getExprLoc())); |
| 6448 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6449 | |
| 6450 | TemplateArgumentListInfo ToTAInfo(Importer.Import(E->getLAngleLoc()), |
| 6451 | Importer.Import(E->getRAngleLoc())); |
| 6452 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 6453 | if (E->hasExplicitTemplateArgs()) { |
| 6454 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6455 | return nullptr; |
| 6456 | ResInfo = &ToTAInfo; |
| 6457 | } |
| 6458 | |
| 6459 | return DependentScopeDeclRefExpr::Create( |
| 6460 | Importer.getToContext(), Importer.Import(E->getQualifierLoc()), |
| 6461 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, ResInfo); |
| 6462 | } |
| 6463 | |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6464 | Expr *ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 6465 | CXXUnresolvedConstructExpr *CE) { |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6466 | unsigned NumArgs = CE->arg_size(); |
| 6467 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6468 | SmallVector<Expr *, 8> ToArgs(NumArgs); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6469 | if (ImportArrayChecked(CE->arg_begin(), CE->arg_end(), ToArgs.begin())) |
| 6470 | return nullptr; |
| 6471 | |
| 6472 | return CXXUnresolvedConstructExpr::Create( |
| 6473 | Importer.getToContext(), Importer.Import(CE->getTypeSourceInfo()), |
| 6474 | Importer.Import(CE->getLParenLoc()), llvm::makeArrayRef(ToArgs), |
| 6475 | Importer.Import(CE->getRParenLoc())); |
| 6476 | } |
| 6477 | |
| 6478 | Expr *ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6479 | auto *NamingClass = |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6480 | cast_or_null<CXXRecordDecl>(Importer.Import(E->getNamingClass())); |
| 6481 | if (E->getNamingClass() && !NamingClass) |
| 6482 | return nullptr; |
| 6483 | |
| 6484 | DeclarationName Name = Importer.Import(E->getName()); |
| 6485 | if (E->getName() && !Name) |
| 6486 | return nullptr; |
| 6487 | |
| 6488 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getNameLoc())); |
| 6489 | // Import additional name location/type info. |
| 6490 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6491 | |
| 6492 | UnresolvedSet<8> ToDecls; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6493 | for (auto *D : E->decls()) { |
| 6494 | if (auto *To = cast_or_null<NamedDecl>(Importer.Import(D))) |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6495 | ToDecls.addDecl(To); |
| 6496 | else |
| 6497 | return nullptr; |
| 6498 | } |
| 6499 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6500 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6501 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6502 | if (ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6503 | E->template_arguments(), ToTAInfo)) |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6504 | return nullptr; |
| 6505 | ResInfo = &ToTAInfo; |
| 6506 | } |
| 6507 | |
| 6508 | if (ResInfo || E->getTemplateKeywordLoc().isValid()) |
| 6509 | return UnresolvedLookupExpr::Create( |
| 6510 | Importer.getToContext(), NamingClass, |
| 6511 | Importer.Import(E->getQualifierLoc()), |
| 6512 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, E->requiresADL(), |
| 6513 | ResInfo, ToDecls.begin(), ToDecls.end()); |
| 6514 | |
| 6515 | return UnresolvedLookupExpr::Create( |
| 6516 | Importer.getToContext(), NamingClass, |
| 6517 | Importer.Import(E->getQualifierLoc()), NameInfo, E->requiresADL(), |
| 6518 | E->isOverloaded(), ToDecls.begin(), ToDecls.end()); |
| 6519 | } |
| 6520 | |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 6521 | Expr *ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 6522 | DeclarationName Name = Importer.Import(E->getName()); |
| 6523 | if (!E->getName().isEmpty() && Name.isEmpty()) |
| 6524 | return nullptr; |
| 6525 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getNameLoc())); |
| 6526 | // Import additional name location/type info. |
| 6527 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6528 | |
| 6529 | QualType BaseType = Importer.Import(E->getType()); |
| 6530 | if (!E->getType().isNull() && BaseType.isNull()) |
| 6531 | return nullptr; |
| 6532 | |
| 6533 | UnresolvedSet<8> ToDecls; |
| 6534 | for (Decl *D : E->decls()) { |
| 6535 | if (NamedDecl *To = cast_or_null<NamedDecl>(Importer.Import(D))) |
| 6536 | ToDecls.addDecl(To); |
| 6537 | else |
| 6538 | return nullptr; |
| 6539 | } |
| 6540 | |
| 6541 | TemplateArgumentListInfo ToTAInfo; |
| 6542 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 6543 | if (E->hasExplicitTemplateArgs()) { |
| 6544 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6545 | return nullptr; |
| 6546 | ResInfo = &ToTAInfo; |
| 6547 | } |
| 6548 | |
| 6549 | Expr *BaseE = E->isImplicitAccess() ? nullptr : Importer.Import(E->getBase()); |
| 6550 | if (!BaseE && !E->isImplicitAccess() && E->getBase()) { |
| 6551 | return nullptr; |
| 6552 | } |
| 6553 | |
| 6554 | return UnresolvedMemberExpr::Create( |
| 6555 | Importer.getToContext(), E->hasUnresolvedUsing(), BaseE, BaseType, |
| 6556 | E->isArrow(), Importer.Import(E->getOperatorLoc()), |
| 6557 | Importer.Import(E->getQualifierLoc()), |
| 6558 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, ResInfo, |
| 6559 | ToDecls.begin(), ToDecls.end()); |
| 6560 | } |
| 6561 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6562 | Expr *ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 6563 | QualType T = Importer.Import(E->getType()); |
| 6564 | if (T.isNull()) |
| 6565 | return nullptr; |
| 6566 | |
| 6567 | Expr *ToCallee = Importer.Import(E->getCallee()); |
| 6568 | if (!ToCallee && E->getCallee()) |
| 6569 | return nullptr; |
| 6570 | |
| 6571 | unsigned NumArgs = E->getNumArgs(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6572 | SmallVector<Expr *, 2> ToArgs(NumArgs); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6573 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
| 6574 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6575 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6576 | auto **ToArgs_Copied = new (Importer.getToContext()) Expr*[NumArgs]; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6577 | |
| 6578 | for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) |
| 6579 | ToArgs_Copied[ai] = ToArgs[ai]; |
| 6580 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6581 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| 6582 | return new (Importer.getToContext()) CXXOperatorCallExpr( |
| 6583 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, T, |
| 6584 | OCE->getValueKind(), Importer.Import(OCE->getRParenLoc()), |
| 6585 | OCE->getFPFeatures()); |
| 6586 | } |
| 6587 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6588 | return new (Importer.getToContext()) |
| 6589 | CallExpr(Importer.getToContext(), ToCallee, |
Craig Topper | c005cc0 | 2015-09-27 03:44:08 +0000 | [diff] [blame] | 6590 | llvm::makeArrayRef(ToArgs_Copied, NumArgs), T, E->getValueKind(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6591 | Importer.Import(E->getRParenLoc())); |
| 6592 | } |
| 6593 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6594 | Optional<LambdaCapture> |
| 6595 | ASTNodeImporter::ImportLambdaCapture(const LambdaCapture &From) { |
| 6596 | VarDecl *Var = nullptr; |
| 6597 | if (From.capturesVariable()) { |
| 6598 | Var = cast_or_null<VarDecl>(Importer.Import(From.getCapturedVar())); |
| 6599 | if (!Var) |
| 6600 | return None; |
| 6601 | } |
| 6602 | |
| 6603 | return LambdaCapture(Importer.Import(From.getLocation()), From.isImplicit(), |
| 6604 | From.getCaptureKind(), Var, |
| 6605 | From.isPackExpansion() |
| 6606 | ? Importer.Import(From.getEllipsisLoc()) |
| 6607 | : SourceLocation()); |
| 6608 | } |
| 6609 | |
| 6610 | Expr *ASTNodeImporter::VisitLambdaExpr(LambdaExpr *LE) { |
| 6611 | CXXRecordDecl *FromClass = LE->getLambdaClass(); |
| 6612 | auto *ToClass = dyn_cast_or_null<CXXRecordDecl>(Importer.Import(FromClass)); |
| 6613 | if (!ToClass) |
| 6614 | return nullptr; |
| 6615 | |
| 6616 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 6617 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 6618 | // manually. |
| 6619 | if (ToClass->isBeingDefined()) { |
| 6620 | for (auto FromField : FromClass->fields()) { |
| 6621 | auto *ToField = cast_or_null<FieldDecl>(Importer.Import(FromField)); |
| 6622 | if (!ToField) |
| 6623 | return nullptr; |
| 6624 | } |
| 6625 | } |
| 6626 | |
| 6627 | auto *ToCallOp = dyn_cast_or_null<CXXMethodDecl>( |
| 6628 | Importer.Import(LE->getCallOperator())); |
| 6629 | if (!ToCallOp) |
| 6630 | return nullptr; |
| 6631 | |
| 6632 | ToClass->completeDefinition(); |
| 6633 | |
| 6634 | unsigned NumCaptures = LE->capture_size(); |
| 6635 | SmallVector<LambdaCapture, 8> Captures; |
| 6636 | Captures.reserve(NumCaptures); |
| 6637 | for (const auto &FromCapture : LE->captures()) { |
| 6638 | if (auto ToCapture = ImportLambdaCapture(FromCapture)) |
| 6639 | Captures.push_back(*ToCapture); |
| 6640 | else |
| 6641 | return nullptr; |
| 6642 | } |
| 6643 | |
| 6644 | SmallVector<Expr *, 8> InitCaptures(NumCaptures); |
| 6645 | if (ImportContainerChecked(LE->capture_inits(), InitCaptures)) |
| 6646 | return nullptr; |
| 6647 | |
| 6648 | return LambdaExpr::Create(Importer.getToContext(), ToClass, |
| 6649 | Importer.Import(LE->getIntroducerRange()), |
| 6650 | LE->getCaptureDefault(), |
| 6651 | Importer.Import(LE->getCaptureDefaultLoc()), |
| 6652 | Captures, |
| 6653 | LE->hasExplicitParameters(), |
| 6654 | LE->hasExplicitResultType(), |
| 6655 | InitCaptures, |
| 6656 | Importer.Import(LE->getLocEnd()), |
| 6657 | LE->containsUnexpandedParameterPack()); |
| 6658 | } |
| 6659 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6660 | Expr *ASTNodeImporter::VisitInitListExpr(InitListExpr *ILE) { |
| 6661 | QualType T = Importer.Import(ILE->getType()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6662 | if (T.isNull()) |
| 6663 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6664 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6665 | SmallVector<Expr *, 4> Exprs(ILE->getNumInits()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6666 | if (ImportContainerChecked(ILE->inits(), Exprs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6667 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6668 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6669 | ASTContext &ToCtx = Importer.getToContext(); |
| 6670 | InitListExpr *To = new (ToCtx) InitListExpr( |
| 6671 | ToCtx, Importer.Import(ILE->getLBraceLoc()), |
| 6672 | Exprs, Importer.Import(ILE->getLBraceLoc())); |
| 6673 | To->setType(T); |
| 6674 | |
| 6675 | if (ILE->hasArrayFiller()) { |
| 6676 | Expr *Filler = Importer.Import(ILE->getArrayFiller()); |
| 6677 | if (!Filler) |
| 6678 | return nullptr; |
| 6679 | To->setArrayFiller(Filler); |
| 6680 | } |
| 6681 | |
| 6682 | if (FieldDecl *FromFD = ILE->getInitializedFieldInUnion()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6683 | auto *ToFD = cast_or_null<FieldDecl>(Importer.Import(FromFD)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6684 | if (!ToFD) |
| 6685 | return nullptr; |
| 6686 | To->setInitializedFieldInUnion(ToFD); |
| 6687 | } |
| 6688 | |
| 6689 | if (InitListExpr *SyntForm = ILE->getSyntacticForm()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6690 | auto *ToSyntForm = cast_or_null<InitListExpr>(Importer.Import(SyntForm)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6691 | if (!ToSyntForm) |
| 6692 | return nullptr; |
| 6693 | To->setSyntacticForm(ToSyntForm); |
| 6694 | } |
| 6695 | |
| 6696 | To->sawArrayRangeDesignator(ILE->hadArrayRangeDesignator()); |
| 6697 | To->setValueDependent(ILE->isValueDependent()); |
| 6698 | To->setInstantiationDependent(ILE->isInstantiationDependent()); |
| 6699 | |
| 6700 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6701 | } |
| 6702 | |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 6703 | Expr *ASTNodeImporter::VisitCXXStdInitializerListExpr( |
| 6704 | CXXStdInitializerListExpr *E) { |
| 6705 | QualType T = Importer.Import(E->getType()); |
| 6706 | if (T.isNull()) |
| 6707 | return nullptr; |
| 6708 | |
| 6709 | Expr *SE = Importer.Import(E->getSubExpr()); |
| 6710 | if (!SE) |
| 6711 | return nullptr; |
| 6712 | |
| 6713 | return new (Importer.getToContext()) CXXStdInitializerListExpr(T, SE); |
| 6714 | } |
| 6715 | |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 6716 | Expr *ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 6717 | QualType ToType = Importer.Import(E->getType()); |
| 6718 | if (ToType.isNull()) |
| 6719 | return nullptr; |
| 6720 | |
| 6721 | Expr *ToCommon = Importer.Import(E->getCommonExpr()); |
| 6722 | if (!ToCommon && E->getCommonExpr()) |
| 6723 | return nullptr; |
| 6724 | |
| 6725 | Expr *ToSubExpr = Importer.Import(E->getSubExpr()); |
| 6726 | if (!ToSubExpr && E->getSubExpr()) |
| 6727 | return nullptr; |
| 6728 | |
| 6729 | return new (Importer.getToContext()) |
| 6730 | ArrayInitLoopExpr(ToType, ToCommon, ToSubExpr); |
| 6731 | } |
| 6732 | |
| 6733 | Expr *ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 6734 | QualType ToType = Importer.Import(E->getType()); |
| 6735 | if (ToType.isNull()) |
| 6736 | return nullptr; |
| 6737 | return new (Importer.getToContext()) ArrayInitIndexExpr(ToType); |
| 6738 | } |
| 6739 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6740 | Expr *ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6741 | auto *ToField = dyn_cast_or_null<FieldDecl>(Importer.Import(DIE->getField())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6742 | if (!ToField && DIE->getField()) |
| 6743 | return nullptr; |
| 6744 | |
| 6745 | return CXXDefaultInitExpr::Create( |
| 6746 | Importer.getToContext(), Importer.Import(DIE->getLocStart()), ToField); |
| 6747 | } |
| 6748 | |
| 6749 | Expr *ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 6750 | QualType ToType = Importer.Import(E->getType()); |
| 6751 | if (ToType.isNull() && !E->getType().isNull()) |
| 6752 | return nullptr; |
| 6753 | ExprValueKind VK = E->getValueKind(); |
| 6754 | CastKind CK = E->getCastKind(); |
| 6755 | Expr *ToOp = Importer.Import(E->getSubExpr()); |
| 6756 | if (!ToOp && E->getSubExpr()) |
| 6757 | return nullptr; |
| 6758 | CXXCastPath BasePath; |
| 6759 | if (ImportCastPath(E, BasePath)) |
| 6760 | return nullptr; |
| 6761 | TypeSourceInfo *ToWritten = Importer.Import(E->getTypeInfoAsWritten()); |
| 6762 | SourceLocation ToOperatorLoc = Importer.Import(E->getOperatorLoc()); |
| 6763 | SourceLocation ToRParenLoc = Importer.Import(E->getRParenLoc()); |
| 6764 | SourceRange ToAngleBrackets = Importer.Import(E->getAngleBrackets()); |
| 6765 | |
| 6766 | if (isa<CXXStaticCastExpr>(E)) { |
| 6767 | return CXXStaticCastExpr::Create( |
| 6768 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6769 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6770 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 6771 | return CXXDynamicCastExpr::Create( |
| 6772 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6773 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6774 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 6775 | return CXXReinterpretCastExpr::Create( |
| 6776 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6777 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6778 | } else { |
| 6779 | return nullptr; |
| 6780 | } |
| 6781 | } |
| 6782 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6783 | Expr *ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
| 6784 | SubstNonTypeTemplateParmExpr *E) { |
| 6785 | QualType T = Importer.Import(E->getType()); |
| 6786 | if (T.isNull()) |
| 6787 | return nullptr; |
| 6788 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6789 | auto *Param = cast_or_null<NonTypeTemplateParmDecl>( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6790 | Importer.Import(E->getParameter())); |
| 6791 | if (!Param) |
| 6792 | return nullptr; |
| 6793 | |
| 6794 | Expr *Replacement = Importer.Import(E->getReplacement()); |
| 6795 | if (!Replacement) |
| 6796 | return nullptr; |
| 6797 | |
| 6798 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
| 6799 | T, E->getValueKind(), Importer.Import(E->getExprLoc()), Param, |
| 6800 | Replacement); |
| 6801 | } |
| 6802 | |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 6803 | Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 6804 | QualType ToType = Importer.Import(E->getType()); |
| 6805 | if (ToType.isNull()) |
| 6806 | return nullptr; |
| 6807 | |
| 6808 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
| 6809 | if (ImportContainerChecked(E->getArgs(), ToArgs)) |
| 6810 | return nullptr; |
| 6811 | |
| 6812 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 6813 | // Value is always false. |
| 6814 | bool ToValue = false; |
| 6815 | if (!E->isValueDependent()) |
| 6816 | ToValue = E->getValue(); |
| 6817 | |
| 6818 | return TypeTraitExpr::Create( |
| 6819 | Importer.getToContext(), ToType, Importer.Import(E->getLocStart()), |
| 6820 | E->getTrait(), ToArgs, Importer.Import(E->getLocEnd()), ToValue); |
| 6821 | } |
| 6822 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6823 | Expr *ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 6824 | QualType ToType = Importer.Import(E->getType()); |
| 6825 | if (ToType.isNull()) |
| 6826 | return nullptr; |
| 6827 | |
| 6828 | if (E->isTypeOperand()) { |
| 6829 | TypeSourceInfo *TSI = Importer.Import(E->getTypeOperandSourceInfo()); |
| 6830 | if (!TSI) |
| 6831 | return nullptr; |
| 6832 | |
| 6833 | return new (Importer.getToContext()) |
| 6834 | CXXTypeidExpr(ToType, TSI, Importer.Import(E->getSourceRange())); |
| 6835 | } |
| 6836 | |
| 6837 | Expr *Op = Importer.Import(E->getExprOperand()); |
| 6838 | if (!Op) |
| 6839 | return nullptr; |
| 6840 | |
| 6841 | return new (Importer.getToContext()) |
| 6842 | CXXTypeidExpr(ToType, Op, Importer.Import(E->getSourceRange())); |
| 6843 | } |
| 6844 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 6845 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 6846 | CXXMethodDecl *FromMethod) { |
| 6847 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) |
| 6848 | ToMethod->addOverriddenMethod( |
| 6849 | cast<CXXMethodDecl>(Importer.Import(const_cast<CXXMethodDecl*>( |
| 6850 | FromOverriddenMethod)))); |
| 6851 | } |
| 6852 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6853 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6854 | ASTContext &FromContext, FileManager &FromFileManager, |
| 6855 | bool MinimalImport) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6856 | : ToContext(ToContext), FromContext(FromContext), |
| 6857 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| 6858 | Minimal(MinimalImport) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6859 | ImportedDecls[FromContext.getTranslationUnitDecl()] |
| 6860 | = ToContext.getTranslationUnitDecl(); |
| 6861 | } |
| 6862 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6863 | ASTImporter::~ASTImporter() = default; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6864 | |
| 6865 | QualType ASTImporter::Import(QualType FromT) { |
| 6866 | if (FromT.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6867 | return {}; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6868 | |
| 6869 | const Type *fromTy = FromT.getTypePtr(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6870 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6871 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6872 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
| 6873 | = ImportedTypes.find(fromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6874 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6875 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6876 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6877 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6878 | ASTNodeImporter Importer(*this); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6879 | QualType ToT = Importer.Visit(fromTy); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6880 | if (ToT.isNull()) |
| 6881 | return ToT; |
| 6882 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6883 | // Record the imported type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6884 | ImportedTypes[fromTy] = ToT.getTypePtr(); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6885 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6886 | return ToContext.getQualifiedType(ToT, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6887 | } |
| 6888 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6889 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 6890 | if (!FromTSI) |
| 6891 | return FromTSI; |
| 6892 | |
| 6893 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 6894 | // on the type and a single location. Implement a real version of this. |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 6895 | QualType T = Import(FromTSI->getType()); |
| 6896 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6897 | return nullptr; |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 6898 | |
| 6899 | return ToContext.getTrivialTypeSourceInfo(T, |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6900 | Import(FromTSI->getTypeLoc().getLocStart())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6901 | } |
| 6902 | |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 6903 | Attr *ASTImporter::Import(const Attr *FromAttr) { |
| 6904 | Attr *ToAttr = FromAttr->clone(ToContext); |
| 6905 | ToAttr->setRange(Import(FromAttr->getRange())); |
| 6906 | return ToAttr; |
| 6907 | } |
| 6908 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6909 | Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) { |
| 6910 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
| 6911 | if (Pos != ImportedDecls.end()) { |
| 6912 | Decl *ToD = Pos->second; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 6913 | // FIXME: move this call to ImportDeclParts(). |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6914 | ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD); |
| 6915 | return ToD; |
| 6916 | } else { |
| 6917 | return nullptr; |
| 6918 | } |
| 6919 | } |
| 6920 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6921 | Decl *ASTImporter::Import(Decl *FromD) { |
| 6922 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6923 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6924 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6925 | ASTNodeImporter Importer(*this); |
| 6926 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 6927 | // Check whether we've already imported this declaration. |
| 6928 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 6929 | if (ToD) { |
| 6930 | // If FromD has some updated flags after last import, apply it |
| 6931 | updateFlags(FromD, ToD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6932 | return ToD; |
| 6933 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 6934 | |
| 6935 | // Import the type. |
| 6936 | ToD = Importer.Visit(FromD); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6937 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6938 | return nullptr; |
| 6939 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 6940 | // Notify subclasses. |
| 6941 | Imported(FromD, ToD); |
| 6942 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6943 | return ToD; |
| 6944 | } |
| 6945 | |
| 6946 | DeclContext *ASTImporter::ImportContext(DeclContext *FromDC) { |
| 6947 | if (!FromDC) |
| 6948 | return FromDC; |
| 6949 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6950 | auto *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6951 | if (!ToDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6952 | return nullptr; |
| 6953 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6954 | // When we're using a record/enum/Objective-C class/protocol as a context, we |
| 6955 | // need it to have a definition. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6956 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 6957 | auto *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6958 | if (ToRecord->isCompleteDefinition()) { |
| 6959 | // Do nothing. |
| 6960 | } else if (FromRecord->isCompleteDefinition()) { |
| 6961 | ASTNodeImporter(*this).ImportDefinition(FromRecord, ToRecord, |
| 6962 | ASTNodeImporter::IDK_Basic); |
| 6963 | } else { |
| 6964 | CompleteDecl(ToRecord); |
| 6965 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6966 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 6967 | auto *FromEnum = cast<EnumDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6968 | if (ToEnum->isCompleteDefinition()) { |
| 6969 | // Do nothing. |
| 6970 | } else if (FromEnum->isCompleteDefinition()) { |
| 6971 | ASTNodeImporter(*this).ImportDefinition(FromEnum, ToEnum, |
| 6972 | ASTNodeImporter::IDK_Basic); |
| 6973 | } else { |
| 6974 | CompleteDecl(ToEnum); |
| 6975 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6976 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 6977 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6978 | if (ToClass->getDefinition()) { |
| 6979 | // Do nothing. |
| 6980 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
| 6981 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToClass, |
| 6982 | ASTNodeImporter::IDK_Basic); |
| 6983 | } else { |
| 6984 | CompleteDecl(ToClass); |
| 6985 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6986 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 6987 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6988 | if (ToProto->getDefinition()) { |
| 6989 | // Do nothing. |
| 6990 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
| 6991 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToProto, |
| 6992 | ASTNodeImporter::IDK_Basic); |
| 6993 | } else { |
| 6994 | CompleteDecl(ToProto); |
| 6995 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 6996 | } |
| 6997 | |
| 6998 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6999 | } |
| 7000 | |
| 7001 | Expr *ASTImporter::Import(Expr *FromE) { |
| 7002 | if (!FromE) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7003 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7004 | |
| 7005 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); |
| 7006 | } |
| 7007 | |
| 7008 | Stmt *ASTImporter::Import(Stmt *FromS) { |
| 7009 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7010 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7011 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7012 | // Check whether we've already imported this declaration. |
| 7013 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 7014 | if (Pos != ImportedStmts.end()) |
| 7015 | return Pos->second; |
| 7016 | |
| 7017 | // Import the type |
| 7018 | ASTNodeImporter Importer(*this); |
| 7019 | Stmt *ToS = Importer.Visit(FromS); |
| 7020 | if (!ToS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7021 | return nullptr; |
| 7022 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7023 | // Record the imported declaration. |
| 7024 | ImportedStmts[FromS] = ToS; |
| 7025 | return ToS; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7026 | } |
| 7027 | |
| 7028 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| 7029 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7030 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7031 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7032 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); |
| 7033 | |
| 7034 | switch (FromNNS->getKind()) { |
| 7035 | case NestedNameSpecifier::Identifier: |
| 7036 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { |
| 7037 | return NestedNameSpecifier::Create(ToContext, prefix, II); |
| 7038 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7039 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7040 | |
| 7041 | case NestedNameSpecifier::Namespace: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7042 | if (auto *NS = |
| 7043 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7044 | return NestedNameSpecifier::Create(ToContext, prefix, NS); |
| 7045 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7046 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7047 | |
| 7048 | case NestedNameSpecifier::NamespaceAlias: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7049 | if (auto *NSAD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7050 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7051 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); |
| 7052 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7053 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7054 | |
| 7055 | case NestedNameSpecifier::Global: |
| 7056 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 7057 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7058 | case NestedNameSpecifier::Super: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7059 | if (auto *RD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7060 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7061 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); |
| 7062 | } |
| 7063 | return nullptr; |
| 7064 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7065 | case NestedNameSpecifier::TypeSpec: |
| 7066 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7067 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); |
| 7068 | if (!T.isNull()) { |
| 7069 | bool bTemplate = FromNNS->getKind() == |
| 7070 | NestedNameSpecifier::TypeSpecWithTemplate; |
| 7071 | return NestedNameSpecifier::Create(ToContext, prefix, |
| 7072 | bTemplate, T.getTypePtr()); |
| 7073 | } |
| 7074 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7075 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7076 | } |
| 7077 | |
| 7078 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7079 | } |
| 7080 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 7081 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7082 | // Copied from NestedNameSpecifier mostly. |
| 7083 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 7084 | NestedNameSpecifierLoc NNS = FromNNS; |
| 7085 | |
| 7086 | // Push each of the nested-name-specifiers's onto a stack for |
| 7087 | // serialization in reverse order. |
| 7088 | while (NNS) { |
| 7089 | NestedNames.push_back(NNS); |
| 7090 | NNS = NNS.getPrefix(); |
| 7091 | } |
| 7092 | |
| 7093 | NestedNameSpecifierLocBuilder Builder; |
| 7094 | |
| 7095 | while (!NestedNames.empty()) { |
| 7096 | NNS = NestedNames.pop_back_val(); |
| 7097 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); |
| 7098 | if (!Spec) |
| 7099 | return NestedNameSpecifierLoc(); |
| 7100 | |
| 7101 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| 7102 | switch (Kind) { |
| 7103 | case NestedNameSpecifier::Identifier: |
| 7104 | Builder.Extend(getToContext(), |
| 7105 | Spec->getAsIdentifier(), |
| 7106 | Import(NNS.getLocalBeginLoc()), |
| 7107 | Import(NNS.getLocalEndLoc())); |
| 7108 | break; |
| 7109 | |
| 7110 | case NestedNameSpecifier::Namespace: |
| 7111 | Builder.Extend(getToContext(), |
| 7112 | Spec->getAsNamespace(), |
| 7113 | Import(NNS.getLocalBeginLoc()), |
| 7114 | Import(NNS.getLocalEndLoc())); |
| 7115 | break; |
| 7116 | |
| 7117 | case NestedNameSpecifier::NamespaceAlias: |
| 7118 | Builder.Extend(getToContext(), |
| 7119 | Spec->getAsNamespaceAlias(), |
| 7120 | Import(NNS.getLocalBeginLoc()), |
| 7121 | Import(NNS.getLocalEndLoc())); |
| 7122 | break; |
| 7123 | |
| 7124 | case NestedNameSpecifier::TypeSpec: |
| 7125 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7126 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| 7127 | QualType(Spec->getAsType(), 0)); |
| 7128 | Builder.Extend(getToContext(), |
| 7129 | Import(NNS.getLocalBeginLoc()), |
| 7130 | TSI->getTypeLoc(), |
| 7131 | Import(NNS.getLocalEndLoc())); |
| 7132 | break; |
| 7133 | } |
| 7134 | |
| 7135 | case NestedNameSpecifier::Global: |
| 7136 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); |
| 7137 | break; |
| 7138 | |
| 7139 | case NestedNameSpecifier::Super: { |
| 7140 | SourceRange ToRange = Import(NNS.getSourceRange()); |
| 7141 | Builder.MakeSuper(getToContext(), |
| 7142 | Spec->getAsRecordDecl(), |
| 7143 | ToRange.getBegin(), |
| 7144 | ToRange.getEnd()); |
| 7145 | } |
| 7146 | } |
| 7147 | } |
| 7148 | |
| 7149 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 7150 | } |
| 7151 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7152 | TemplateName ASTImporter::Import(TemplateName From) { |
| 7153 | switch (From.getKind()) { |
| 7154 | case TemplateName::Template: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7155 | if (auto *ToTemplate = |
| 7156 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7157 | return TemplateName(ToTemplate); |
| 7158 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7159 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7160 | |
| 7161 | case TemplateName::OverloadedTemplate: { |
| 7162 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 7163 | UnresolvedSet<2> ToTemplates; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7164 | for (auto *I : *FromStorage) { |
| 7165 | if (auto *To = cast_or_null<NamedDecl>(Import(I))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7166 | ToTemplates.addDecl(To); |
| 7167 | else |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7168 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7169 | } |
| 7170 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
| 7171 | ToTemplates.end()); |
| 7172 | } |
| 7173 | |
| 7174 | case TemplateName::QualifiedTemplate: { |
| 7175 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| 7176 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); |
| 7177 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7178 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7179 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7180 | if (auto *ToTemplate = |
| 7181 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7182 | return ToContext.getQualifiedTemplateName(Qualifier, |
| 7183 | QTN->hasTemplateKeyword(), |
| 7184 | ToTemplate); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7185 | |
| 7186 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7187 | } |
| 7188 | |
| 7189 | case TemplateName::DependentTemplate: { |
| 7190 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| 7191 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); |
| 7192 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7193 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7194 | |
| 7195 | if (DTN->isIdentifier()) { |
| 7196 | return ToContext.getDependentTemplateName(Qualifier, |
| 7197 | Import(DTN->getIdentifier())); |
| 7198 | } |
| 7199 | |
| 7200 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); |
| 7201 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7202 | |
| 7203 | case TemplateName::SubstTemplateTemplateParm: { |
| 7204 | SubstTemplateTemplateParmStorage *subst |
| 7205 | = From.getAsSubstTemplateTemplateParm(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7206 | auto *param = |
| 7207 | cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7208 | if (!param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7209 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7210 | |
| 7211 | TemplateName replacement = Import(subst->getReplacement()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7212 | if (replacement.isNull()) |
| 7213 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7214 | |
| 7215 | return ToContext.getSubstTemplateTemplateParm(param, replacement); |
| 7216 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7217 | |
| 7218 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 7219 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 7220 | = From.getAsSubstTemplateTemplateParmPack(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7221 | auto *Param = |
| 7222 | cast_or_null<TemplateTemplateParmDecl>( |
| 7223 | Import(SubstPack->getParameterPack())); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7224 | if (!Param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7225 | return {}; |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7226 | |
| 7227 | ASTNodeImporter Importer(*this); |
| 7228 | TemplateArgument ArgPack |
| 7229 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 7230 | if (ArgPack.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7231 | return {}; |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7232 | |
| 7233 | return ToContext.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 7234 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7235 | } |
| 7236 | |
| 7237 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7238 | } |
| 7239 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7240 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { |
| 7241 | if (FromLoc.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7242 | return {}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7243 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7244 | SourceManager &FromSM = FromContext.getSourceManager(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7245 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7246 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 7247 | FileID ToFileID = Import(Decomposed.first); |
| 7248 | if (ToFileID.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7249 | return {}; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7250 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 7251 | return ToSM.getComposedLoc(ToFileID, Decomposed.second); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7252 | } |
| 7253 | |
| 7254 | SourceRange ASTImporter::Import(SourceRange FromRange) { |
| 7255 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); |
| 7256 | } |
| 7257 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7258 | FileID ASTImporter::Import(FileID FromID) { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7259 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7260 | if (Pos != ImportedFileIDs.end()) |
| 7261 | return Pos->second; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7262 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7263 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 7264 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 7265 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7266 | |
| 7267 | // Map the FromID to the "to" source manager. |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7268 | FileID ToID; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7269 | if (FromSLoc.isExpansion()) { |
| 7270 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
| 7271 | SourceLocation ToSpLoc = Import(FromEx.getSpellingLoc()); |
| 7272 | SourceLocation ToExLocS = Import(FromEx.getExpansionLocStart()); |
| 7273 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 7274 | SourceLocation MLoc; |
| 7275 | if (FromEx.isMacroArgExpansion()) { |
| 7276 | MLoc = ToSM.createMacroArgExpansionLoc(ToSpLoc, ToExLocS, TokenLen); |
| 7277 | } else { |
| 7278 | SourceLocation ToExLocE = Import(FromEx.getExpansionLocEnd()); |
| 7279 | MLoc = ToSM.createExpansionLoc(ToSpLoc, ToExLocS, ToExLocE, TokenLen, |
| 7280 | FromEx.isExpansionTokenRange()); |
| 7281 | } |
| 7282 | ToID = ToSM.getFileID(MLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7283 | } else { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7284 | // Include location of this file. |
| 7285 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| 7286 | |
| 7287 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
| 7288 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 7289 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 7290 | // disk again |
| 7291 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 7292 | // than mmap the files several times. |
| 7293 | const FileEntry *Entry = |
| 7294 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 7295 | if (!Entry) |
| 7296 | return {}; |
| 7297 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, |
| 7298 | FromSLoc.getFile().getFileCharacteristic()); |
| 7299 | } else { |
| 7300 | // FIXME: We want to re-use the existing MemoryBuffer! |
| 7301 | const llvm::MemoryBuffer *FromBuf = |
| 7302 | Cache->getBuffer(FromContext.getDiagnostics(), FromSM); |
| 7303 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 7304 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 7305 | FromBuf->getBufferIdentifier()); |
| 7306 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 7307 | FromSLoc.getFile().getFileCharacteristic()); |
| 7308 | } |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7309 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7310 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 7311 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7312 | return ToID; |
| 7313 | } |
| 7314 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7315 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
| 7316 | Expr *ToExpr = Import(From->getInit()); |
| 7317 | if (!ToExpr && From->getInit()) |
| 7318 | return nullptr; |
| 7319 | |
| 7320 | if (From->isBaseInitializer()) { |
| 7321 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 7322 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 7323 | return nullptr; |
| 7324 | |
| 7325 | return new (ToContext) CXXCtorInitializer( |
| 7326 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), |
| 7327 | ToExpr, Import(From->getRParenLoc()), |
| 7328 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) |
| 7329 | : SourceLocation()); |
| 7330 | } else if (From->isMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7331 | auto *ToField = cast_or_null<FieldDecl>(Import(From->getMember())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7332 | if (!ToField && From->getMember()) |
| 7333 | return nullptr; |
| 7334 | |
| 7335 | return new (ToContext) CXXCtorInitializer( |
| 7336 | ToContext, ToField, Import(From->getMemberLocation()), |
| 7337 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 7338 | } else if (From->isIndirectMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7339 | auto *ToIField = cast_or_null<IndirectFieldDecl>( |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7340 | Import(From->getIndirectMember())); |
| 7341 | if (!ToIField && From->getIndirectMember()) |
| 7342 | return nullptr; |
| 7343 | |
| 7344 | return new (ToContext) CXXCtorInitializer( |
| 7345 | ToContext, ToIField, Import(From->getMemberLocation()), |
| 7346 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 7347 | } else if (From->isDelegatingInitializer()) { |
| 7348 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 7349 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 7350 | return nullptr; |
| 7351 | |
| 7352 | return new (ToContext) |
| 7353 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), |
| 7354 | ToExpr, Import(From->getRParenLoc())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7355 | } else { |
| 7356 | return nullptr; |
| 7357 | } |
| 7358 | } |
| 7359 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7360 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| 7361 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 7362 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 7363 | return Pos->second; |
| 7364 | |
| 7365 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| 7366 | Import(BaseSpec->getSourceRange()), |
| 7367 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 7368 | BaseSpec->getAccessSpecifierAsWritten(), |
| 7369 | Import(BaseSpec->getTypeSourceInfo()), |
| 7370 | Import(BaseSpec->getEllipsisLoc())); |
| 7371 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 7372 | return Imported; |
| 7373 | } |
| 7374 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7375 | void ASTImporter::ImportDefinition(Decl *From) { |
| 7376 | Decl *To = Import(From); |
| 7377 | if (!To) |
| 7378 | return; |
| 7379 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7380 | if (auto *FromDC = cast<DeclContext>(From)) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7381 | ASTNodeImporter Importer(*this); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7382 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7383 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7384 | if (!ToRecord->getDefinition()) { |
| 7385 | Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7386 | ASTNodeImporter::IDK_Everything); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7387 | return; |
| 7388 | } |
| 7389 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7390 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7391 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7392 | if (!ToEnum->getDefinition()) { |
| 7393 | Importer.ImportDefinition(cast<EnumDecl>(FromDC), ToEnum, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7394 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7395 | return; |
| 7396 | } |
| 7397 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7398 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7399 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7400 | if (!ToIFace->getDefinition()) { |
| 7401 | Importer.ImportDefinition(cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7402 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7403 | return; |
| 7404 | } |
| 7405 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7406 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7407 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7408 | if (!ToProto->getDefinition()) { |
| 7409 | Importer.ImportDefinition(cast<ObjCProtocolDecl>(FromDC), ToProto, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7410 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7411 | return; |
| 7412 | } |
| 7413 | } |
| 7414 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7415 | Importer.ImportDeclContext(FromDC, true); |
| 7416 | } |
| 7417 | } |
| 7418 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7419 | DeclarationName ASTImporter::Import(DeclarationName FromName) { |
| 7420 | if (!FromName) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7421 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7422 | |
| 7423 | switch (FromName.getNameKind()) { |
| 7424 | case DeclarationName::Identifier: |
| 7425 | return Import(FromName.getAsIdentifierInfo()); |
| 7426 | |
| 7427 | case DeclarationName::ObjCZeroArgSelector: |
| 7428 | case DeclarationName::ObjCOneArgSelector: |
| 7429 | case DeclarationName::ObjCMultiArgSelector: |
| 7430 | return Import(FromName.getObjCSelector()); |
| 7431 | |
| 7432 | case DeclarationName::CXXConstructorName: { |
| 7433 | QualType T = Import(FromName.getCXXNameType()); |
| 7434 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7435 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7436 | |
| 7437 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 7438 | ToContext.getCanonicalType(T)); |
| 7439 | } |
| 7440 | |
| 7441 | case DeclarationName::CXXDestructorName: { |
| 7442 | QualType T = Import(FromName.getCXXNameType()); |
| 7443 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7444 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7445 | |
| 7446 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 7447 | ToContext.getCanonicalType(T)); |
| 7448 | } |
| 7449 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7450 | case DeclarationName::CXXDeductionGuideName: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7451 | auto *Template = cast_or_null<TemplateDecl>( |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7452 | Import(FromName.getCXXDeductionGuideTemplate())); |
| 7453 | if (!Template) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7454 | return {}; |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7455 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); |
| 7456 | } |
| 7457 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7458 | case DeclarationName::CXXConversionFunctionName: { |
| 7459 | QualType T = Import(FromName.getCXXNameType()); |
| 7460 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7461 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7462 | |
| 7463 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 7464 | ToContext.getCanonicalType(T)); |
| 7465 | } |
| 7466 | |
| 7467 | case DeclarationName::CXXOperatorName: |
| 7468 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 7469 | FromName.getCXXOverloadedOperator()); |
| 7470 | |
| 7471 | case DeclarationName::CXXLiteralOperatorName: |
| 7472 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| 7473 | Import(FromName.getCXXLiteralIdentifier())); |
| 7474 | |
| 7475 | case DeclarationName::CXXUsingDirective: |
| 7476 | // FIXME: STATICS! |
| 7477 | return DeclarationName::getUsingDirectiveName(); |
| 7478 | } |
| 7479 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 7480 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7481 | } |
| 7482 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7483 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7484 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7485 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7486 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 7487 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 7488 | |
| 7489 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 7490 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 7491 | |
| 7492 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7493 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7494 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7495 | Selector ASTImporter::Import(Selector FromSel) { |
| 7496 | if (FromSel.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7497 | return {}; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7498 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 7499 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7500 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 7501 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 7502 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 7503 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 7504 | } |
| 7505 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7506 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 7507 | DeclContext *DC, |
| 7508 | unsigned IDNS, |
| 7509 | NamedDecl **Decls, |
| 7510 | unsigned NumDecls) { |
| 7511 | return Name; |
| 7512 | } |
| 7513 | |
| 7514 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 7515 | if (LastDiagFromFrom) |
| 7516 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 7517 | FromContext.getDiagnostics()); |
| 7518 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7519 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7520 | } |
| 7521 | |
| 7522 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 7523 | if (!LastDiagFromFrom) |
| 7524 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 7525 | ToContext.getDiagnostics()); |
| 7526 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7527 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7528 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7529 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7530 | void ASTImporter::CompleteDecl (Decl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7531 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7532 | if (!ID->getDefinition()) |
| 7533 | ID->startDefinition(); |
| 7534 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7535 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7536 | if (!PD->getDefinition()) |
| 7537 | PD->startDefinition(); |
| 7538 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7539 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7540 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 7541 | TD->startDefinition(); |
| 7542 | TD->setCompleteDefinition(true); |
| 7543 | } |
| 7544 | } |
| 7545 | else { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7546 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7547 | } |
| 7548 | } |
| 7549 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 7550 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 7551 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 7552 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 7553 | "Try to import an already imported Decl"); |
| 7554 | if (Pos != ImportedDecls.end()) |
| 7555 | return Pos->second; |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7556 | ImportedDecls[From] = To; |
| 7557 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 7558 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7559 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 7560 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 7561 | bool Complain) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7562 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7563 | = ImportedTypes.find(From.getTypePtr()); |
| 7564 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) |
| 7565 | return true; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 7566 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 7567 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame^] | 7568 | getStructuralEquivalenceKind(*this), false, |
| 7569 | Complain); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 7570 | return Ctx.IsStructurallyEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7571 | } |