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 |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +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); |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 231 | void ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 232 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 233 | bool ImportCastPath(CastExpr *E, CXXCastPath &Path); |
| 234 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 235 | using Designator = DesignatedInitExpr::Designator; |
| 236 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 237 | Designator ImportDesignator(const Designator &D); |
| 238 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 239 | Optional<LambdaCapture> ImportLambdaCapture(const LambdaCapture &From); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 240 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 241 | /// What we should import from the definition. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 242 | enum ImportDefinitionKind { |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 243 | /// Import the default subset of the definition, which might be |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 244 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 245 | /// import is not set). |
| 246 | IDK_Default, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 247 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 248 | /// Import everything. |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 249 | IDK_Everything, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 250 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 251 | /// Import only the bare bones needed to establish a valid |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 252 | /// DeclContext. |
| 253 | IDK_Basic |
| 254 | }; |
| 255 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 256 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 257 | return IDK == IDK_Everything || |
| 258 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 259 | } |
| 260 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 261 | bool ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 262 | ImportDefinitionKind Kind = IDK_Default); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 263 | bool ImportDefinition(VarDecl *From, VarDecl *To, |
| 264 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 265 | bool ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 266 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 267 | bool ImportDefinition(ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 268 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 269 | bool ImportDefinition(ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 270 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 271 | TemplateParameterList *ImportTemplateParameterList( |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 272 | TemplateParameterList *Params); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 273 | TemplateArgument ImportTemplateArgument(const TemplateArgument &From); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 274 | Optional<TemplateArgumentLoc> ImportTemplateArgumentLoc( |
| 275 | const TemplateArgumentLoc &TALoc); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 276 | bool ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 277 | unsigned NumFromArgs, |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 278 | SmallVectorImpl<TemplateArgument> &ToArgs); |
| 279 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 280 | template <typename InContainerTy> |
| 281 | bool ImportTemplateArgumentListInfo(const InContainerTy &Container, |
| 282 | TemplateArgumentListInfo &ToTAInfo); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 283 | |
| 284 | template<typename InContainerTy> |
| 285 | bool ImportTemplateArgumentListInfo(SourceLocation FromLAngleLoc, |
| 286 | SourceLocation FromRAngleLoc, |
| 287 | const InContainerTy &Container, |
| 288 | TemplateArgumentListInfo &Result); |
| 289 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 290 | using TemplateArgsTy = SmallVector<TemplateArgument, 8>; |
| 291 | using OptionalTemplateArgsTy = Optional<TemplateArgsTy>; |
| 292 | std::tuple<FunctionTemplateDecl *, OptionalTemplateArgsTy> |
| 293 | ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 294 | FunctionDecl *FromFD); |
| 295 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 296 | bool ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); |
| 297 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 298 | bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 299 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 300 | bool Complain = true); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 301 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 302 | bool Complain = true); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 303 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 304 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 305 | bool IsStructuralMatch(FunctionTemplateDecl *From, |
| 306 | FunctionTemplateDecl *To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 307 | bool IsStructuralMatch(FunctionDecl *From, FunctionDecl *To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 308 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 309 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 310 | Decl *VisitDecl(Decl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 311 | Decl *VisitEmptyDecl(EmptyDecl *D); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 312 | Decl *VisitAccessSpecDecl(AccessSpecDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 313 | Decl *VisitStaticAssertDecl(StaticAssertDecl *D); |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 314 | Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 315 | Decl *VisitNamespaceDecl(NamespaceDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 316 | Decl *VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 317 | Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 318 | Decl *VisitTypedefDecl(TypedefDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 319 | Decl *VisitTypeAliasDecl(TypeAliasDecl *D); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 320 | Decl *VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 321 | Decl *VisitLabelDecl(LabelDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 322 | Decl *VisitEnumDecl(EnumDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 323 | Decl *VisitRecordDecl(RecordDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 324 | Decl *VisitEnumConstantDecl(EnumConstantDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 325 | Decl *VisitFunctionDecl(FunctionDecl *D); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 326 | Decl *VisitCXXMethodDecl(CXXMethodDecl *D); |
| 327 | Decl *VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 328 | Decl *VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 329 | Decl *VisitCXXConversionDecl(CXXConversionDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 330 | Decl *VisitFieldDecl(FieldDecl *D); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 331 | Decl *VisitIndirectFieldDecl(IndirectFieldDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 332 | Decl *VisitFriendDecl(FriendDecl *D); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 333 | Decl *VisitObjCIvarDecl(ObjCIvarDecl *D); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 334 | Decl *VisitVarDecl(VarDecl *D); |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 335 | Decl *VisitImplicitParamDecl(ImplicitParamDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 336 | Decl *VisitParmVarDecl(ParmVarDecl *D); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 337 | Decl *VisitObjCMethodDecl(ObjCMethodDecl *D); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 338 | Decl *VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 339 | Decl *VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 340 | Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 341 | Decl *VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 342 | Decl *VisitUsingDecl(UsingDecl *D); |
| 343 | Decl *VisitUsingShadowDecl(UsingShadowDecl *D); |
| 344 | Decl *VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 345 | Decl *VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 346 | Decl *VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
| 347 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 348 | ObjCTypeParamList *ImportObjCTypeParamList(ObjCTypeParamList *list); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 349 | Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 350 | Decl *VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 351 | Decl *VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 352 | Decl *VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 353 | Decl *VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 354 | Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 355 | Decl *VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 356 | Decl *VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 357 | Decl *VisitClassTemplateDecl(ClassTemplateDecl *D); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 358 | Decl *VisitClassTemplateSpecializationDecl( |
| 359 | ClassTemplateSpecializationDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 360 | Decl *VisitVarTemplateDecl(VarTemplateDecl *D); |
| 361 | Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 362 | Decl *VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 363 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 364 | // Importing statements |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 365 | DeclGroupRef ImportDeclGroup(DeclGroupRef DG); |
| 366 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 367 | Stmt *VisitStmt(Stmt *S); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 368 | Stmt *VisitGCCAsmStmt(GCCAsmStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 369 | Stmt *VisitDeclStmt(DeclStmt *S); |
| 370 | Stmt *VisitNullStmt(NullStmt *S); |
| 371 | Stmt *VisitCompoundStmt(CompoundStmt *S); |
| 372 | Stmt *VisitCaseStmt(CaseStmt *S); |
| 373 | Stmt *VisitDefaultStmt(DefaultStmt *S); |
| 374 | Stmt *VisitLabelStmt(LabelStmt *S); |
| 375 | Stmt *VisitAttributedStmt(AttributedStmt *S); |
| 376 | Stmt *VisitIfStmt(IfStmt *S); |
| 377 | Stmt *VisitSwitchStmt(SwitchStmt *S); |
| 378 | Stmt *VisitWhileStmt(WhileStmt *S); |
| 379 | Stmt *VisitDoStmt(DoStmt *S); |
| 380 | Stmt *VisitForStmt(ForStmt *S); |
| 381 | Stmt *VisitGotoStmt(GotoStmt *S); |
| 382 | Stmt *VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 383 | Stmt *VisitContinueStmt(ContinueStmt *S); |
| 384 | Stmt *VisitBreakStmt(BreakStmt *S); |
| 385 | Stmt *VisitReturnStmt(ReturnStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 386 | // FIXME: MSAsmStmt |
| 387 | // FIXME: SEHExceptStmt |
| 388 | // FIXME: SEHFinallyStmt |
| 389 | // FIXME: SEHTryStmt |
| 390 | // FIXME: SEHLeaveStmt |
| 391 | // FIXME: CapturedStmt |
| 392 | Stmt *VisitCXXCatchStmt(CXXCatchStmt *S); |
| 393 | Stmt *VisitCXXTryStmt(CXXTryStmt *S); |
| 394 | Stmt *VisitCXXForRangeStmt(CXXForRangeStmt *S); |
| 395 | // FIXME: MSDependentExistsStmt |
| 396 | Stmt *VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 397 | Stmt *VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 398 | Stmt *VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 399 | Stmt *VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 400 | Stmt *VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 401 | Stmt *VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 402 | Stmt *VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 403 | |
| 404 | // Importing expressions |
| 405 | Expr *VisitExpr(Expr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 406 | Expr *VisitVAArgExpr(VAArgExpr *E); |
| 407 | Expr *VisitGNUNullExpr(GNUNullExpr *E); |
| 408 | Expr *VisitPredefinedExpr(PredefinedExpr *E); |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 409 | Expr *VisitDeclRefExpr(DeclRefExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 410 | Expr *VisitImplicitValueInitExpr(ImplicitValueInitExpr *ILE); |
| 411 | Expr *VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 412 | Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 413 | Expr *VisitIntegerLiteral(IntegerLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 414 | Expr *VisitFloatingLiteral(FloatingLiteral *E); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 415 | Expr *VisitCharacterLiteral(CharacterLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 416 | Expr *VisitStringLiteral(StringLiteral *E); |
| 417 | Expr *VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 418 | Expr *VisitAtomicExpr(AtomicExpr *E); |
| 419 | Expr *VisitAddrLabelExpr(AddrLabelExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 420 | Expr *VisitParenExpr(ParenExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 421 | Expr *VisitParenListExpr(ParenListExpr *E); |
| 422 | Expr *VisitStmtExpr(StmtExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 423 | Expr *VisitUnaryOperator(UnaryOperator *E); |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 424 | Expr *VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 425 | Expr *VisitBinaryOperator(BinaryOperator *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 426 | Expr *VisitConditionalOperator(ConditionalOperator *E); |
| 427 | Expr *VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 428 | Expr *VisitOpaqueValueExpr(OpaqueValueExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 429 | Expr *VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 430 | Expr *VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 431 | Expr *VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 432 | Expr *VisitCompoundAssignOperator(CompoundAssignOperator *E); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 433 | Expr *VisitImplicitCastExpr(ImplicitCastExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 434 | Expr *VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 435 | Expr *VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 436 | Expr *VisitCXXThrowExpr(CXXThrowExpr *E); |
| 437 | Expr *VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 438 | Expr *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 439 | Expr *VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 440 | Expr *VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 441 | Expr *VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE); |
| 442 | Expr *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 443 | Expr *VisitPackExpansionExpr(PackExpansionExpr *E); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 444 | Expr *VisitSizeOfPackExpr(SizeOfPackExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 445 | Expr *VisitCXXNewExpr(CXXNewExpr *CE); |
| 446 | Expr *VisitCXXDeleteExpr(CXXDeleteExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 447 | Expr *VisitCXXConstructExpr(CXXConstructExpr *E); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 448 | Expr *VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 449 | Expr *VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 450 | Expr *VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 451 | Expr *VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *CE); |
| 452 | Expr *VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 453 | Expr *VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 454 | Expr *VisitExprWithCleanups(ExprWithCleanups *EWC); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 455 | Expr *VisitCXXThisExpr(CXXThisExpr *E); |
| 456 | Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 457 | Expr *VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 458 | Expr *VisitMemberExpr(MemberExpr *E); |
| 459 | Expr *VisitCallExpr(CallExpr *E); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 460 | Expr *VisitLambdaExpr(LambdaExpr *LE); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 461 | Expr *VisitInitListExpr(InitListExpr *E); |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 462 | Expr *VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E); |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 463 | Expr *VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 464 | Expr *VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 465 | Expr *VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 466 | Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 467 | Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 468 | Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 469 | Expr *VisitTypeTraitExpr(TypeTraitExpr *E); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 470 | Expr *VisitCXXTypeidExpr(CXXTypeidExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 471 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 472 | template<typename IIter, typename OIter> |
| 473 | void ImportArray(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 474 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; |
| 475 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 476 | ASTImporter &ImporterRef = Importer; |
| 477 | std::transform(Ibegin, Iend, Obegin, |
| 478 | [&ImporterRef](ItemT From) -> ItemT { |
| 479 | return ImporterRef.Import(From); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 480 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | template<typename IIter, typename OIter> |
| 484 | bool ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 485 | using ItemT = typename std::remove_reference<decltype(**Obegin)>::type; |
| 486 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 487 | ASTImporter &ImporterRef = Importer; |
| 488 | bool Failed = false; |
| 489 | std::transform(Ibegin, Iend, Obegin, |
| 490 | [&ImporterRef, &Failed](ItemT *From) -> ItemT * { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 491 | auto *To = cast_or_null<ItemT>(ImporterRef.Import(From)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 492 | if (!To && From) |
| 493 | Failed = true; |
| 494 | return To; |
| 495 | }); |
| 496 | return Failed; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 497 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 498 | |
| 499 | template<typename InContainerTy, typename OutContainerTy> |
| 500 | bool ImportContainerChecked(const InContainerTy &InContainer, |
| 501 | OutContainerTy &OutContainer) { |
| 502 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), |
| 503 | OutContainer.begin()); |
| 504 | } |
| 505 | |
| 506 | template<typename InContainerTy, typename OIter> |
| 507 | bool ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
| 508 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 509 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 510 | |
| 511 | // Importing overrides. |
| 512 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 513 | |
| 514 | FunctionDecl *FindFunctionTemplateSpecialization(FunctionDecl *FromFD); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 515 | }; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 516 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 517 | template <typename InContainerTy> |
| 518 | bool ASTNodeImporter::ImportTemplateArgumentListInfo( |
| 519 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 520 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
| 521 | TemplateArgumentListInfo ToTAInfo(Importer.Import(FromLAngleLoc), |
| 522 | Importer.Import(FromRAngleLoc)); |
| 523 | if (ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 524 | return true; |
| 525 | Result = ToTAInfo; |
| 526 | return false; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 527 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 528 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 529 | template <> |
| 530 | bool ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
| 531 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 532 | return ImportTemplateArgumentListInfo( |
| 533 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 534 | } |
| 535 | |
| 536 | template <> |
| 537 | bool ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 538 | ASTTemplateArgumentListInfo>(const ASTTemplateArgumentListInfo &From, |
| 539 | TemplateArgumentListInfo &Result) { |
| 540 | return ImportTemplateArgumentListInfo(From.LAngleLoc, From.RAngleLoc, |
| 541 | From.arguments(), Result); |
| 542 | } |
| 543 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 544 | std::tuple<FunctionTemplateDecl *, ASTNodeImporter::OptionalTemplateArgsTy> |
| 545 | ASTNodeImporter::ImportFunctionTemplateWithTemplateArgsFromSpecialization( |
| 546 | FunctionDecl *FromFD) { |
| 547 | assert(FromFD->getTemplatedKind() == |
| 548 | FunctionDecl::TK_FunctionTemplateSpecialization); |
| 549 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
| 550 | auto *Template = cast_or_null<FunctionTemplateDecl>( |
| 551 | Importer.Import(FTSInfo->getTemplate())); |
| 552 | |
| 553 | // Import template arguments. |
| 554 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
| 555 | TemplateArgsTy ToTemplArgs; |
| 556 | if (ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 557 | ToTemplArgs)) // Error during import. |
| 558 | return std::make_tuple(Template, OptionalTemplateArgsTy()); |
| 559 | |
| 560 | return std::make_tuple(Template, ToTemplArgs); |
| 561 | } |
| 562 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 563 | } // namespace clang |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 564 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 565 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 566 | // Import Types |
| 567 | //---------------------------------------------------------------------------- |
| 568 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 569 | using namespace clang; |
| 570 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 571 | QualType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 572 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 573 | << T->getTypeClassName(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 574 | return {}; |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 577 | QualType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 578 | QualType UnderlyingType = Importer.Import(T->getValueType()); |
| 579 | if(UnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 580 | return {}; |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 581 | |
| 582 | return Importer.getToContext().getAtomicType(UnderlyingType); |
| 583 | } |
| 584 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 585 | QualType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 586 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 587 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 588 | case BuiltinType::Id: \ |
| 589 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 590 | #include "clang/Basic/OpenCLImageTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 591 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 592 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 593 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 594 | #include "clang/AST/BuiltinTypes.def" |
| 595 | |
| 596 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 597 | // context supports C++. |
| 598 | |
| 599 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 600 | // context supports ObjC. |
| 601 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 602 | case BuiltinType::Char_U: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 603 | // The context we're importing from has an unsigned 'char'. If we're |
| 604 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 605 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 606 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 607 | return Importer.getToContext().UnsignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 608 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 609 | return Importer.getToContext().CharTy; |
| 610 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 611 | case BuiltinType::Char_S: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 612 | // The context we're importing from has an unsigned 'char'. If we're |
| 613 | // importing into a context with a signed 'char', translate to |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 614 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 615 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 616 | return Importer.getToContext().SignedCharTy; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 617 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 618 | return Importer.getToContext().CharTy; |
| 619 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 620 | case BuiltinType::WChar_S: |
| 621 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 622 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 623 | // wchar_t? |
| 624 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 625 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 626 | |
| 627 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 628 | } |
| 629 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 630 | QualType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 631 | QualType OrigT = Importer.Import(T->getOriginalType()); |
| 632 | if (OrigT.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 633 | return {}; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 634 | |
| 635 | return Importer.getToContext().getDecayedType(OrigT); |
| 636 | } |
| 637 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 638 | QualType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 639 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 640 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 641 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 642 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 643 | return Importer.getToContext().getComplexType(ToElementType); |
| 644 | } |
| 645 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 646 | QualType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 647 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 648 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 649 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 650 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 651 | return Importer.getToContext().getPointerType(ToPointeeType); |
| 652 | } |
| 653 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 654 | QualType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 655 | // FIXME: Check for blocks support in "to" context. |
| 656 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 657 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 658 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 659 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 660 | return Importer.getToContext().getBlockPointerType(ToPointeeType); |
| 661 | } |
| 662 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 663 | QualType |
| 664 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 665 | // FIXME: Check for C++ support in "to" context. |
| 666 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 667 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 668 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 669 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 670 | return Importer.getToContext().getLValueReferenceType(ToPointeeType); |
| 671 | } |
| 672 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 673 | QualType |
| 674 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 675 | // FIXME: Check for C++0x support in "to" context. |
| 676 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 677 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 678 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 679 | |
| 680 | return Importer.getToContext().getRValueReferenceType(ToPointeeType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 681 | } |
| 682 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 683 | QualType ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 684 | // FIXME: Check for C++ support in "to" context. |
| 685 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 686 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 687 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 688 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 689 | QualType ClassType = Importer.Import(QualType(T->getClass(), 0)); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 690 | return Importer.getToContext().getMemberPointerType(ToPointeeType, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 691 | ClassType.getTypePtr()); |
| 692 | } |
| 693 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 694 | QualType ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 695 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 696 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 697 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 698 | |
| 699 | return Importer.getToContext().getConstantArrayType(ToElementType, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 700 | T->getSize(), |
| 701 | T->getSizeModifier(), |
| 702 | T->getIndexTypeCVRQualifiers()); |
| 703 | } |
| 704 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 705 | QualType |
| 706 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 707 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 708 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 709 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 710 | |
| 711 | return Importer.getToContext().getIncompleteArrayType(ToElementType, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 712 | T->getSizeModifier(), |
| 713 | T->getIndexTypeCVRQualifiers()); |
| 714 | } |
| 715 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 716 | QualType ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 717 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 718 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 719 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 720 | |
| 721 | Expr *Size = Importer.Import(T->getSizeExpr()); |
| 722 | if (!Size) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 723 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 724 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 725 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); |
| 726 | return Importer.getToContext().getVariableArrayType(ToElementType, Size, |
| 727 | T->getSizeModifier(), |
| 728 | T->getIndexTypeCVRQualifiers(), |
| 729 | Brackets); |
| 730 | } |
| 731 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 732 | QualType ASTNodeImporter::VisitDependentSizedArrayType( |
| 733 | const DependentSizedArrayType *T) { |
| 734 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 735 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 736 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 737 | |
| 738 | // SizeExpr may be null if size is not specified directly. |
| 739 | // For example, 'int a[]'. |
| 740 | Expr *Size = Importer.Import(T->getSizeExpr()); |
| 741 | if (!Size && T->getSizeExpr()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 742 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 743 | |
| 744 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); |
| 745 | return Importer.getToContext().getDependentSizedArrayType( |
| 746 | ToElementType, Size, T->getSizeModifier(), T->getIndexTypeCVRQualifiers(), |
| 747 | Brackets); |
| 748 | } |
| 749 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 750 | QualType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 751 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 752 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 753 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 754 | |
| 755 | return Importer.getToContext().getVectorType(ToElementType, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 756 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 757 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 758 | } |
| 759 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 760 | QualType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 761 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 762 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 763 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 764 | |
| 765 | return Importer.getToContext().getExtVectorType(ToElementType, |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 766 | T->getNumElements()); |
| 767 | } |
| 768 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 769 | QualType |
| 770 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 771 | // FIXME: What happens if we're importing a function without a prototype |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 772 | // into C++? Should we make it variadic? |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 773 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 774 | if (ToResultType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 775 | return {}; |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 776 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 777 | return Importer.getToContext().getFunctionNoProtoType(ToResultType, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 778 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 779 | } |
| 780 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 781 | QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 782 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 783 | if (ToResultType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 784 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 785 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 786 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 787 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 788 | for (const auto &A : T->param_types()) { |
| 789 | QualType ArgType = Importer.Import(A); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 790 | if (ArgType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 791 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 792 | ArgTypes.push_back(ArgType); |
| 793 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 794 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 795 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 796 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 797 | for (const auto &E : T->exceptions()) { |
| 798 | QualType ExceptionType = Importer.Import(E); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 799 | if (ExceptionType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 800 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 801 | ExceptionTypes.push_back(ExceptionType); |
| 802 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 803 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 804 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 805 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 806 | |
| 807 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 808 | ToEPI.Variadic = FromEPI.Variadic; |
| 809 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 810 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 811 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 812 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 813 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
| 814 | ToEPI.ExceptionSpec.NoexceptExpr = |
| 815 | Importer.Import(FromEPI.ExceptionSpec.NoexceptExpr); |
| 816 | ToEPI.ExceptionSpec.SourceDecl = cast_or_null<FunctionDecl>( |
| 817 | Importer.Import(FromEPI.ExceptionSpec.SourceDecl)); |
| 818 | ToEPI.ExceptionSpec.SourceTemplate = cast_or_null<FunctionDecl>( |
| 819 | Importer.Import(FromEPI.ExceptionSpec.SourceTemplate)); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 820 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 821 | return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 822 | } |
| 823 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 824 | QualType ASTNodeImporter::VisitUnresolvedUsingType( |
| 825 | const UnresolvedUsingType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 826 | const auto *ToD = |
| 827 | cast_or_null<UnresolvedUsingTypenameDecl>(Importer.Import(T->getDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 828 | if (!ToD) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 829 | return {}; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 830 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 831 | auto *ToPrevD = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 832 | cast_or_null<UnresolvedUsingTypenameDecl>( |
| 833 | Importer.Import(T->getDecl()->getPreviousDecl())); |
| 834 | if (!ToPrevD && T->getDecl()->getPreviousDecl()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 835 | return {}; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 836 | |
| 837 | return Importer.getToContext().getTypeDeclType(ToD, ToPrevD); |
| 838 | } |
| 839 | |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 840 | QualType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 841 | QualType ToInnerType = Importer.Import(T->getInnerType()); |
| 842 | if (ToInnerType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 843 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 844 | |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 845 | return Importer.getToContext().getParenType(ToInnerType); |
| 846 | } |
| 847 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 848 | QualType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 849 | auto *ToDecl = |
| 850 | dyn_cast_or_null<TypedefNameDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 851 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 852 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 853 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 854 | return Importer.getToContext().getTypeDeclType(ToDecl); |
| 855 | } |
| 856 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 857 | QualType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 858 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 859 | if (!ToExpr) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 860 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 861 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 862 | return Importer.getToContext().getTypeOfExprType(ToExpr); |
| 863 | } |
| 864 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 865 | QualType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 866 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 867 | if (ToUnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 868 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 869 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 870 | return Importer.getToContext().getTypeOfType(ToUnderlyingType); |
| 871 | } |
| 872 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 873 | QualType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 874 | // FIXME: Make sure that the "to" context supports C++0x! |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 875 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 876 | if (!ToExpr) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 877 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 878 | |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 879 | QualType UnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 880 | if (UnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 881 | return {}; |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 882 | |
| 883 | return Importer.getToContext().getDecltypeType(ToExpr, UnderlyingType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 884 | } |
| 885 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 886 | QualType ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 887 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 888 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 889 | if (ToBaseType.isNull() || ToUnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 890 | return {}; |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 891 | |
| 892 | return Importer.getToContext().getUnaryTransformType(ToBaseType, |
| 893 | ToUnderlyingType, |
| 894 | T->getUTTKind()); |
| 895 | } |
| 896 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 897 | QualType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 898 | // FIXME: Make sure that the "to" context supports C++11! |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 899 | QualType FromDeduced = T->getDeducedType(); |
| 900 | QualType ToDeduced; |
| 901 | if (!FromDeduced.isNull()) { |
| 902 | ToDeduced = Importer.Import(FromDeduced); |
| 903 | if (ToDeduced.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 904 | return {}; |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 905 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 906 | |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 907 | return Importer.getToContext().getAutoType(ToDeduced, T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 908 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 909 | } |
| 910 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 911 | QualType ASTNodeImporter::VisitInjectedClassNameType( |
| 912 | const InjectedClassNameType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 913 | auto *D = cast_or_null<CXXRecordDecl>(Importer.Import(T->getDecl())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 914 | if (!D) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 915 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 916 | |
| 917 | QualType InjType = Importer.Import(T->getInjectedSpecializationType()); |
| 918 | if (InjType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 919 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 920 | |
| 921 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 922 | // See comments in InjectedClassNameType definition for details |
| 923 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 924 | enum { |
| 925 | TypeAlignmentInBits = 4, |
| 926 | TypeAlignment = 1 << TypeAlignmentInBits |
| 927 | }; |
| 928 | |
| 929 | return QualType(new (Importer.getToContext(), TypeAlignment) |
| 930 | InjectedClassNameType(D, InjType), 0); |
| 931 | } |
| 932 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 933 | QualType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 934 | auto *ToDecl = dyn_cast_or_null<RecordDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 935 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 936 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 937 | |
| 938 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 939 | } |
| 940 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 941 | QualType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 942 | auto *ToDecl = dyn_cast_or_null<EnumDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 943 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 944 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 945 | |
| 946 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 947 | } |
| 948 | |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 949 | QualType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 950 | QualType FromModifiedType = T->getModifiedType(); |
| 951 | QualType FromEquivalentType = T->getEquivalentType(); |
| 952 | QualType ToModifiedType; |
| 953 | QualType ToEquivalentType; |
| 954 | |
| 955 | if (!FromModifiedType.isNull()) { |
| 956 | ToModifiedType = Importer.Import(FromModifiedType); |
| 957 | if (ToModifiedType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 958 | return {}; |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 959 | } |
| 960 | if (!FromEquivalentType.isNull()) { |
| 961 | ToEquivalentType = Importer.Import(FromEquivalentType); |
| 962 | if (ToEquivalentType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 963 | return {}; |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
| 967 | ToModifiedType, ToEquivalentType); |
| 968 | } |
| 969 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 970 | QualType ASTNodeImporter::VisitTemplateTypeParmType( |
| 971 | const TemplateTypeParmType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 972 | auto *ParmDecl = |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 973 | cast_or_null<TemplateTypeParmDecl>(Importer.Import(T->getDecl())); |
| 974 | if (!ParmDecl && T->getDecl()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 975 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 976 | |
| 977 | return Importer.getToContext().getTemplateTypeParmType( |
| 978 | T->getDepth(), T->getIndex(), T->isParameterPack(), ParmDecl); |
| 979 | } |
| 980 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 981 | QualType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
| 982 | const SubstTemplateTypeParmType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 983 | const auto *Replaced = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 984 | cast_or_null<TemplateTypeParmType>(Importer.Import( |
| 985 | QualType(T->getReplacedParameter(), 0)).getTypePtr()); |
| 986 | if (!Replaced) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 987 | return {}; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 988 | |
| 989 | QualType Replacement = Importer.Import(T->getReplacementType()); |
| 990 | if (Replacement.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 991 | return {}; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 992 | Replacement = Replacement.getCanonicalType(); |
| 993 | |
| 994 | return Importer.getToContext().getSubstTemplateTypeParmType( |
| 995 | Replaced, Replacement); |
| 996 | } |
| 997 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 998 | QualType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 999 | const TemplateSpecializationType *T) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1000 | TemplateName ToTemplate = Importer.Import(T->getTemplateName()); |
| 1001 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1002 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1003 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1004 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1005 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1006 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1007 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1008 | QualType ToCanonType; |
| 1009 | if (!QualType(T, 0).isCanonical()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1010 | QualType FromCanonType |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1011 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
| 1012 | ToCanonType =Importer.Import(FromCanonType); |
| 1013 | if (ToCanonType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1014 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1015 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1016 | return Importer.getToContext().getTemplateSpecializationType(ToTemplate, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 1017 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1018 | ToCanonType); |
| 1019 | } |
| 1020 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1021 | QualType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1022 | NestedNameSpecifier *ToQualifier = nullptr; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1023 | // Note: the qualifier in an ElaboratedType is optional. |
| 1024 | if (T->getQualifier()) { |
| 1025 | ToQualifier = Importer.Import(T->getQualifier()); |
| 1026 | if (!ToQualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1027 | return {}; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1028 | } |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1029 | |
| 1030 | QualType ToNamedType = Importer.Import(T->getNamedType()); |
| 1031 | if (ToNamedType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1032 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1033 | |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1034 | TagDecl *OwnedTagDecl = |
| 1035 | cast_or_null<TagDecl>(Importer.Import(T->getOwnedTagDecl())); |
| 1036 | if (!OwnedTagDecl && T->getOwnedTagDecl()) |
| 1037 | return {}; |
| 1038 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1039 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 1040 | ToQualifier, ToNamedType, |
| 1041 | OwnedTagDecl); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1044 | QualType ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 1045 | QualType Pattern = Importer.Import(T->getPattern()); |
| 1046 | if (Pattern.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1047 | return {}; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1048 | |
| 1049 | return Importer.getToContext().getPackExpansionType(Pattern, |
| 1050 | T->getNumExpansions()); |
| 1051 | } |
| 1052 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1053 | QualType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
| 1054 | const DependentTemplateSpecializationType *T) { |
| 1055 | NestedNameSpecifier *Qualifier = Importer.Import(T->getQualifier()); |
| 1056 | if (!Qualifier && T->getQualifier()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1057 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1058 | |
| 1059 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
| 1060 | if (!Name && T->getIdentifier()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1061 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1062 | |
| 1063 | SmallVector<TemplateArgument, 2> ToPack; |
| 1064 | ToPack.reserve(T->getNumArgs()); |
| 1065 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToPack)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1066 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 1067 | |
| 1068 | return Importer.getToContext().getDependentTemplateSpecializationType( |
| 1069 | T->getKeyword(), Qualifier, Name, ToPack); |
| 1070 | } |
| 1071 | |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 1072 | QualType ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { |
| 1073 | NestedNameSpecifier *NNS = Importer.Import(T->getQualifier()); |
| 1074 | if (!NNS && T->getQualifier()) |
| 1075 | return QualType(); |
| 1076 | |
| 1077 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
| 1078 | if (!Name && T->getIdentifier()) |
| 1079 | return QualType(); |
| 1080 | |
| 1081 | QualType Canon = (T == T->getCanonicalTypeInternal().getTypePtr()) |
| 1082 | ? QualType() |
| 1083 | : Importer.Import(T->getCanonicalTypeInternal()); |
| 1084 | if (!Canon.isNull()) |
| 1085 | Canon = Canon.getCanonicalType(); |
| 1086 | |
| 1087 | return Importer.getToContext().getDependentNameType(T->getKeyword(), NNS, |
| 1088 | Name, Canon); |
| 1089 | } |
| 1090 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1091 | QualType ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1092 | auto *Class = |
| 1093 | dyn_cast_or_null<ObjCInterfaceDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1094 | if (!Class) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1095 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1096 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1097 | return Importer.getToContext().getObjCInterfaceType(Class); |
| 1098 | } |
| 1099 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1100 | QualType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1101 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 1102 | if (ToBaseType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1103 | return {}; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1104 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1105 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 1106 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1107 | QualType ImportedTypeArg = Importer.Import(TypeArg); |
| 1108 | if (ImportedTypeArg.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1109 | return {}; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1110 | |
| 1111 | TypeArgs.push_back(ImportedTypeArg); |
| 1112 | } |
| 1113 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1114 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 1115 | for (auto *P : T->quals()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1116 | auto *Protocol = dyn_cast_or_null<ObjCProtocolDecl>(Importer.Import(P)); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1117 | if (!Protocol) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1118 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1119 | Protocols.push_back(Protocol); |
| 1120 | } |
| 1121 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 1122 | return Importer.getToContext().getObjCObjectType(ToBaseType, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1123 | Protocols, |
| 1124 | T->isKindOfTypeAsWritten()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1127 | QualType |
| 1128 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1129 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 1130 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1131 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1132 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1133 | return Importer.getToContext().getObjCObjectPointerType(ToPointeeType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1136 | //---------------------------------------------------------------------------- |
| 1137 | // Import Declarations |
| 1138 | //---------------------------------------------------------------------------- |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1139 | bool ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 1140 | DeclContext *&LexicalDC, |
| 1141 | DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1142 | NamedDecl *&ToD, |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1143 | SourceLocation &Loc) { |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1144 | // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop. |
| 1145 | // example: int struct_in_proto(struct data_t{int a;int b;} *d); |
| 1146 | DeclContext *OrigDC = D->getDeclContext(); |
| 1147 | FunctionDecl *FunDecl; |
| 1148 | if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) && |
| 1149 | FunDecl->hasBody()) { |
Gabor Marton | fe68e29 | 2018-08-06 14:38:37 +0000 | [diff] [blame^] | 1150 | auto getLeafPointeeType = [](const Type *T) { |
| 1151 | while (T->isPointerType() || T->isArrayType()) { |
| 1152 | T = T->getPointeeOrArrayElementType(); |
| 1153 | } |
| 1154 | return T; |
| 1155 | }; |
| 1156 | for (const ParmVarDecl *P : FunDecl->parameters()) { |
| 1157 | const Type *LeafT = |
| 1158 | getLeafPointeeType(P->getType().getCanonicalType().getTypePtr()); |
| 1159 | auto *RT = dyn_cast<RecordType>(LeafT); |
| 1160 | if (RT && RT->getDecl() == D) { |
| 1161 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 1162 | << D->getDeclKindName(); |
| 1163 | return true; |
| 1164 | } |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1165 | } |
| 1166 | } |
| 1167 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1168 | // Import the context of this declaration. |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1169 | DC = Importer.ImportContext(OrigDC); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1170 | if (!DC) |
| 1171 | return true; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1172 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1173 | LexicalDC = DC; |
| 1174 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 1175 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 1176 | if (!LexicalDC) |
| 1177 | return true; |
| 1178 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1179 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1180 | // Import the name of this declaration. |
| 1181 | Name = Importer.Import(D->getDeclName()); |
| 1182 | if (D->getDeclName() && !Name) |
| 1183 | return true; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1184 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1185 | // Import the location of this declaration. |
| 1186 | Loc = Importer.Import(D->getLocation()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1187 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1188 | return false; |
| 1189 | } |
| 1190 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1191 | void ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
| 1192 | if (!FromD) |
| 1193 | return; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1194 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1195 | if (!ToD) { |
| 1196 | ToD = Importer.Import(FromD); |
| 1197 | if (!ToD) |
| 1198 | return; |
| 1199 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1200 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1201 | if (auto *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1202 | if (auto *ToRecord = cast_or_null<RecordDecl>(ToD)) { |
Sean Callanan | 19dfc93 | 2013-01-11 23:17:47 +0000 | [diff] [blame] | 1203 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && !ToRecord->getDefinition()) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1204 | ImportDefinition(FromRecord, ToRecord); |
| 1205 | } |
| 1206 | } |
| 1207 | return; |
| 1208 | } |
| 1209 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1210 | if (auto *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1211 | if (auto *ToEnum = cast_or_null<EnumDecl>(ToD)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1212 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
| 1213 | ImportDefinition(FromEnum, ToEnum); |
| 1214 | } |
| 1215 | } |
| 1216 | return; |
| 1217 | } |
| 1218 | } |
| 1219 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1220 | void |
| 1221 | ASTNodeImporter::ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 1222 | DeclarationNameInfo& To) { |
| 1223 | // NOTE: To.Name and To.Loc are already imported. |
| 1224 | // We only have to import To.LocInfo. |
| 1225 | switch (To.getName().getNameKind()) { |
| 1226 | case DeclarationName::Identifier: |
| 1227 | case DeclarationName::ObjCZeroArgSelector: |
| 1228 | case DeclarationName::ObjCOneArgSelector: |
| 1229 | case DeclarationName::ObjCMultiArgSelector: |
| 1230 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1231 | case DeclarationName::CXXDeductionGuideName: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1232 | return; |
| 1233 | |
| 1234 | case DeclarationName::CXXOperatorName: { |
| 1235 | SourceRange Range = From.getCXXOperatorNameRange(); |
| 1236 | To.setCXXOperatorNameRange(Importer.Import(Range)); |
| 1237 | return; |
| 1238 | } |
| 1239 | case DeclarationName::CXXLiteralOperatorName: { |
| 1240 | SourceLocation Loc = From.getCXXLiteralOperatorNameLoc(); |
| 1241 | To.setCXXLiteralOperatorNameLoc(Importer.Import(Loc)); |
| 1242 | return; |
| 1243 | } |
| 1244 | case DeclarationName::CXXConstructorName: |
| 1245 | case DeclarationName::CXXDestructorName: |
| 1246 | case DeclarationName::CXXConversionFunctionName: { |
| 1247 | TypeSourceInfo *FromTInfo = From.getNamedTypeInfo(); |
| 1248 | To.setNamedTypeInfo(Importer.Import(FromTInfo)); |
| 1249 | return; |
| 1250 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1251 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1252 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1253 | } |
| 1254 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1255 | void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1256 | if (Importer.isMinimalImport() && !ForceImport) { |
Sean Callanan | 81d577c | 2011-07-22 23:46:03 +0000 | [diff] [blame] | 1257 | Importer.ImportContext(FromDC); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1258 | return; |
| 1259 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1260 | |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 1261 | for (auto *From : FromDC->decls()) |
| 1262 | Importer.Import(From); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1263 | } |
| 1264 | |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1265 | void ASTNodeImporter::ImportImplicitMethods( |
| 1266 | const CXXRecordDecl *From, CXXRecordDecl *To) { |
| 1267 | assert(From->isCompleteDefinition() && To->getDefinition() == To && |
| 1268 | "Import implicit methods to or from non-definition"); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1269 | |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1270 | for (CXXMethodDecl *FromM : From->methods()) |
| 1271 | if (FromM->isImplicit()) |
| 1272 | Importer.Import(FromM); |
| 1273 | } |
| 1274 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1275 | static void setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1276 | ASTImporter &Importer) { |
| 1277 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
| 1278 | auto *ToTypedef = |
| 1279 | cast_or_null<TypedefNameDecl>(Importer.Import(FromTypedef)); |
| 1280 | assert (ToTypedef && "Failed to import typedef of an anonymous structure"); |
| 1281 | |
| 1282 | To->setTypedefNameForAnonDecl(ToTypedef); |
| 1283 | } |
| 1284 | } |
| 1285 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1286 | bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1287 | ImportDefinitionKind Kind) { |
| 1288 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1289 | if (Kind == IDK_Everything) |
| 1290 | ImportDeclContext(From, /*ForceImport=*/true); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1291 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1292 | return false; |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1293 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1294 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1295 | To->startDefinition(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1296 | |
| 1297 | setTypedefNameForAnonDecl(From, To, Importer); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1298 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1299 | // Add base classes. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1300 | if (auto *ToCXX = dyn_cast<CXXRecordDecl>(To)) { |
| 1301 | auto *FromCXX = cast<CXXRecordDecl>(From); |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1302 | |
| 1303 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1304 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 1305 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1306 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1307 | ToData.Aggregate = FromData.Aggregate; |
| 1308 | ToData.PlainOldData = FromData.PlainOldData; |
| 1309 | ToData.Empty = FromData.Empty; |
| 1310 | ToData.Polymorphic = FromData.Polymorphic; |
| 1311 | ToData.Abstract = FromData.Abstract; |
| 1312 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1313 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; |
| 1314 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; |
| 1315 | ToData.HasBasesWithNonStaticDataMembers = |
| 1316 | FromData.HasBasesWithNonStaticDataMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1317 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 1318 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 1319 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 1320 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1321 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1322 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1323 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1324 | ToData.HasUninitializedReferenceMember |
| 1325 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1326 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1327 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1328 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1329 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1330 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1331 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1332 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1333 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1334 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1335 | ToData.NeedOverloadResolutionForDestructor |
| 1336 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1337 | ToData.DefaultedCopyConstructorIsDeleted |
| 1338 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1339 | ToData.DefaultedMoveConstructorIsDeleted |
| 1340 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1341 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1342 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1343 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1344 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1345 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1346 | ToData.HasConstexprNonCopyMoveConstructor |
| 1347 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1348 | ToData.HasDefaultedDefaultConstructor |
| 1349 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1350 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1351 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1352 | ToData.HasConstexprDefaultConstructor |
| 1353 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1354 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1355 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1356 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1357 | ToData.UserProvidedDefaultConstructor |
| 1358 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1359 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1360 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1361 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1362 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1363 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1364 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1365 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1366 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1367 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1368 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1369 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1370 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1371 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1372 | for (const auto &Base1 : FromCXX->bases()) { |
| 1373 | QualType T = Importer.Import(Base1.getType()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1374 | if (T.isNull()) |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1375 | return true; |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1376 | |
| 1377 | SourceLocation EllipsisLoc; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1378 | if (Base1.isPackExpansion()) |
| 1379 | EllipsisLoc = Importer.Import(Base1.getEllipsisLoc()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1380 | |
| 1381 | // Ensure that we have a definition for the base. |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1382 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1383 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1384 | Bases.push_back( |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1385 | new (Importer.getToContext()) |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1386 | CXXBaseSpecifier(Importer.Import(Base1.getSourceRange()), |
| 1387 | Base1.isVirtual(), |
| 1388 | Base1.isBaseOfClass(), |
| 1389 | Base1.getAccessSpecifierAsWritten(), |
| 1390 | Importer.Import(Base1.getTypeSourceInfo()), |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1391 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1392 | } |
| 1393 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1394 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1395 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1396 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1397 | if (shouldForceImportDeclContext(Kind)) |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1398 | ImportDeclContext(From, /*ForceImport=*/true); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1399 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1400 | To->completeDefinition(); |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1401 | return false; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1402 | } |
| 1403 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1404 | bool ASTNodeImporter::ImportDefinition(VarDecl *From, VarDecl *To, |
| 1405 | ImportDefinitionKind Kind) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1406 | if (To->getAnyInitializer()) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1407 | return false; |
| 1408 | |
| 1409 | // FIXME: Can we really import any initializer? Alternatively, we could force |
| 1410 | // ourselves to import every declaration of a variable and then only use |
| 1411 | // getInit() here. |
| 1412 | To->setInit(Importer.Import(const_cast<Expr *>(From->getAnyInitializer()))); |
| 1413 | |
| 1414 | // FIXME: Other bits to merge? |
| 1415 | |
| 1416 | return false; |
| 1417 | } |
| 1418 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1419 | bool ASTNodeImporter::ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1420 | ImportDefinitionKind Kind) { |
| 1421 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1422 | if (Kind == IDK_Everything) |
| 1423 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1424 | return false; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1425 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1426 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1427 | To->startDefinition(); |
| 1428 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1429 | setTypedefNameForAnonDecl(From, To, Importer); |
| 1430 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1431 | QualType T = Importer.Import(Importer.getFromContext().getTypeDeclType(From)); |
| 1432 | if (T.isNull()) |
| 1433 | return true; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1434 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1435 | QualType ToPromotionType = Importer.Import(From->getPromotionType()); |
| 1436 | if (ToPromotionType.isNull()) |
| 1437 | return true; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1438 | |
| 1439 | if (shouldForceImportDeclContext(Kind)) |
| 1440 | ImportDeclContext(From, /*ForceImport=*/true); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1441 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1442 | // FIXME: we might need to merge the number of positive or negative bits |
| 1443 | // if the enumerator lists don't match. |
| 1444 | To->completeDefinition(T, ToPromotionType, |
| 1445 | From->getNumPositiveBits(), |
| 1446 | From->getNumNegativeBits()); |
| 1447 | return false; |
| 1448 | } |
| 1449 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1450 | TemplateParameterList *ASTNodeImporter::ImportTemplateParameterList( |
| 1451 | TemplateParameterList *Params) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1452 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); |
| 1453 | if (ImportContainerChecked(*Params, ToParams)) |
| 1454 | return nullptr; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1455 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1456 | Expr *ToRequiresClause; |
| 1457 | if (Expr *const R = Params->getRequiresClause()) { |
| 1458 | ToRequiresClause = Importer.Import(R); |
| 1459 | if (!ToRequiresClause) |
| 1460 | return nullptr; |
| 1461 | } else { |
| 1462 | ToRequiresClause = nullptr; |
| 1463 | } |
| 1464 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1465 | return TemplateParameterList::Create(Importer.getToContext(), |
| 1466 | Importer.Import(Params->getTemplateLoc()), |
| 1467 | Importer.Import(Params->getLAngleLoc()), |
David Majnemer | 902f8c6 | 2015-12-27 07:16:27 +0000 | [diff] [blame] | 1468 | ToParams, |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1469 | Importer.Import(Params->getRAngleLoc()), |
| 1470 | ToRequiresClause); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1473 | TemplateArgument |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1474 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1475 | switch (From.getKind()) { |
| 1476 | case TemplateArgument::Null: |
| 1477 | return TemplateArgument(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1478 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1479 | case TemplateArgument::Type: { |
| 1480 | QualType ToType = Importer.Import(From.getAsType()); |
| 1481 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1482 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1483 | return TemplateArgument(ToType); |
| 1484 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1485 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1486 | case TemplateArgument::Integral: { |
| 1487 | QualType ToType = Importer.Import(From.getIntegralType()); |
| 1488 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1489 | return {}; |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 1490 | return TemplateArgument(From, ToType); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1493 | case TemplateArgument::Declaration: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1494 | auto *To = cast_or_null<ValueDecl>(Importer.Import(From.getAsDecl())); |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1495 | QualType ToType = Importer.Import(From.getParamTypeForDecl()); |
| 1496 | if (!To || ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1497 | return {}; |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1498 | return TemplateArgument(To, ToType); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | case TemplateArgument::NullPtr: { |
| 1502 | QualType ToType = Importer.Import(From.getNullPtrType()); |
| 1503 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1504 | return {}; |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1505 | return TemplateArgument(ToType, /*isNullPtr*/true); |
| 1506 | } |
| 1507 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1508 | case TemplateArgument::Template: { |
| 1509 | TemplateName ToTemplate = Importer.Import(From.getAsTemplate()); |
| 1510 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1511 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1512 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1513 | return TemplateArgument(ToTemplate); |
| 1514 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1515 | |
| 1516 | case TemplateArgument::TemplateExpansion: { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1517 | TemplateName ToTemplate |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1518 | = Importer.Import(From.getAsTemplateOrTemplatePattern()); |
| 1519 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1520 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1521 | |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 1522 | return TemplateArgument(ToTemplate, From.getNumTemplateExpansions()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1523 | } |
| 1524 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1525 | case TemplateArgument::Expression: |
| 1526 | if (Expr *ToExpr = Importer.Import(From.getAsExpr())) |
| 1527 | return TemplateArgument(ToExpr); |
| 1528 | return TemplateArgument(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1529 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1530 | case TemplateArgument::Pack: { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1531 | SmallVector<TemplateArgument, 2> ToPack; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1532 | ToPack.reserve(From.pack_size()); |
| 1533 | if (ImportTemplateArguments(From.pack_begin(), From.pack_size(), ToPack)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1534 | return {}; |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 1535 | |
| 1536 | return TemplateArgument( |
| 1537 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1538 | } |
| 1539 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1540 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1541 | llvm_unreachable("Invalid template argument kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1542 | } |
| 1543 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1544 | Optional<TemplateArgumentLoc> |
| 1545 | ASTNodeImporter::ImportTemplateArgumentLoc(const TemplateArgumentLoc &TALoc) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1546 | TemplateArgument Arg = ImportTemplateArgument(TALoc.getArgument()); |
| 1547 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 1548 | TemplateArgumentLocInfo ToInfo; |
| 1549 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 1550 | Expr *E = Importer.Import(FromInfo.getAsExpr()); |
| 1551 | ToInfo = TemplateArgumentLocInfo(E); |
| 1552 | if (!E) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1553 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1554 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 1555 | if (TypeSourceInfo *TSI = Importer.Import(FromInfo.getAsTypeSourceInfo())) |
| 1556 | ToInfo = TemplateArgumentLocInfo(TSI); |
| 1557 | else |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1558 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1559 | } else { |
| 1560 | ToInfo = TemplateArgumentLocInfo( |
| 1561 | Importer.Import(FromInfo.getTemplateQualifierLoc()), |
| 1562 | Importer.Import(FromInfo.getTemplateNameLoc()), |
| 1563 | Importer.Import(FromInfo.getTemplateEllipsisLoc())); |
| 1564 | } |
| 1565 | return TemplateArgumentLoc(Arg, ToInfo); |
| 1566 | } |
| 1567 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1568 | bool ASTNodeImporter::ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 1569 | unsigned NumFromArgs, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1570 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1571 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
| 1572 | TemplateArgument To = ImportTemplateArgument(FromArgs[I]); |
| 1573 | if (To.isNull() && !FromArgs[I].isNull()) |
| 1574 | return true; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1575 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1576 | ToArgs.push_back(To); |
| 1577 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1578 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1579 | return false; |
| 1580 | } |
| 1581 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 1582 | // We cannot use Optional<> pattern here and below because |
| 1583 | // TemplateArgumentListInfo's operator new is declared as deleted so it cannot |
| 1584 | // be stored in Optional. |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1585 | template <typename InContainerTy> |
| 1586 | bool ASTNodeImporter::ImportTemplateArgumentListInfo( |
| 1587 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1588 | for (const auto &FromLoc : Container) { |
| 1589 | if (auto ToLoc = ImportTemplateArgumentLoc(FromLoc)) |
| 1590 | ToTAInfo.addArgument(*ToLoc); |
| 1591 | else |
| 1592 | return true; |
| 1593 | } |
| 1594 | return false; |
| 1595 | } |
| 1596 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1597 | static StructuralEquivalenceKind |
| 1598 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 1599 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 1600 | : StructuralEquivalenceKind::Default; |
| 1601 | } |
| 1602 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1603 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { |
| 1604 | StructuralEquivalenceContext Ctx( |
| 1605 | Importer.getFromContext(), Importer.getToContext(), |
| 1606 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1607 | false, Complain); |
| 1608 | return Ctx.IsEquivalent(From, To); |
| 1609 | } |
| 1610 | |
| 1611 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1612 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1613 | // Eliminate a potential failure point where we attempt to re-import |
| 1614 | // something we're trying to import while completing ToRecord. |
| 1615 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1616 | if (ToOrigin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1617 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1618 | if (ToOriginRecord) |
| 1619 | ToRecord = ToOriginRecord; |
| 1620 | } |
| 1621 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1622 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1623 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1624 | Importer.getNonEquivalentDecls(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1625 | getStructuralEquivalenceKind(Importer), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1626 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1627 | return Ctx.IsEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1630 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 1631 | bool Complain) { |
| 1632 | StructuralEquivalenceContext Ctx( |
| 1633 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1634 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1635 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1636 | return Ctx.IsEquivalent(FromVar, ToVar); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1637 | } |
| 1638 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1639 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1640 | StructuralEquivalenceContext Ctx( |
| 1641 | Importer.getFromContext(), Importer.getToContext(), |
| 1642 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1643 | return Ctx.IsEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1644 | } |
| 1645 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1646 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 1647 | FunctionTemplateDecl *To) { |
| 1648 | StructuralEquivalenceContext Ctx( |
| 1649 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1650 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1651 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1652 | return Ctx.IsEquivalent(From, To); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1653 | } |
| 1654 | |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 1655 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 1656 | StructuralEquivalenceContext Ctx( |
| 1657 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1658 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1659 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1660 | return Ctx.IsEquivalent(From, To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1663 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1664 | EnumConstantDecl *ToEC) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1665 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 1666 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 1667 | |
| 1668 | return FromVal.isSigned() == ToVal.isSigned() && |
| 1669 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 1670 | FromVal == ToVal; |
| 1671 | } |
| 1672 | |
| 1673 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1674 | ClassTemplateDecl *To) { |
| 1675 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1676 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1677 | Importer.getNonEquivalentDecls(), |
| 1678 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1679 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1682 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 1683 | VarTemplateDecl *To) { |
| 1684 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1685 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1686 | Importer.getNonEquivalentDecls(), |
| 1687 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1688 | return Ctx.IsEquivalent(From, To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1691 | Decl *ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 1692 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1693 | << D->getDeclKindName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1694 | return nullptr; |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1695 | } |
| 1696 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1697 | Decl *ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 1698 | // Import the context of this declaration. |
| 1699 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1700 | if (!DC) |
| 1701 | return nullptr; |
| 1702 | |
| 1703 | DeclContext *LexicalDC = DC; |
| 1704 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 1705 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 1706 | if (!LexicalDC) |
| 1707 | return nullptr; |
| 1708 | } |
| 1709 | |
| 1710 | // Import the location of this declaration. |
| 1711 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1712 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1713 | EmptyDecl *ToD; |
| 1714 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc)) |
| 1715 | return ToD; |
| 1716 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1717 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1718 | LexicalDC->addDeclInternal(ToD); |
| 1719 | return ToD; |
| 1720 | } |
| 1721 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 1722 | Decl *ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1723 | TranslationUnitDecl *ToD = |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 1724 | Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1725 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1726 | Importer.MapImported(D, ToD); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1727 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 1728 | return ToD; |
| 1729 | } |
| 1730 | |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1731 | Decl *ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1732 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1733 | SourceLocation ColonLoc = Importer.Import(D->getColonLoc()); |
| 1734 | |
| 1735 | // Import the context of this declaration. |
| 1736 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1737 | if (!DC) |
| 1738 | return nullptr; |
| 1739 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1740 | AccessSpecDecl *ToD; |
| 1741 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
| 1742 | DC, Loc, ColonLoc)) |
| 1743 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1744 | |
| 1745 | // Lexical DeclContext and Semantic DeclContext |
| 1746 | // is always the same for the accessSpec. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1747 | ToD->setLexicalDeclContext(DC); |
| 1748 | DC->addDeclInternal(ToD); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1749 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1750 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1751 | } |
| 1752 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1753 | Decl *ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 1754 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1755 | if (!DC) |
| 1756 | return nullptr; |
| 1757 | |
| 1758 | DeclContext *LexicalDC = DC; |
| 1759 | |
| 1760 | // Import the location of this declaration. |
| 1761 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1762 | |
| 1763 | Expr *AssertExpr = Importer.Import(D->getAssertExpr()); |
| 1764 | if (!AssertExpr) |
| 1765 | return nullptr; |
| 1766 | |
| 1767 | StringLiteral *FromMsg = D->getMessage(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1768 | auto *ToMsg = cast_or_null<StringLiteral>(Importer.Import(FromMsg)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1769 | if (!ToMsg && FromMsg) |
| 1770 | return nullptr; |
| 1771 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1772 | StaticAssertDecl *ToD; |
| 1773 | if (GetImportedOrCreateDecl( |
| 1774 | ToD, D, Importer.getToContext(), DC, Loc, AssertExpr, ToMsg, |
| 1775 | Importer.Import(D->getRParenLoc()), D->isFailed())) |
| 1776 | return ToD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1777 | |
| 1778 | ToD->setLexicalDeclContext(LexicalDC); |
| 1779 | LexicalDC->addDeclInternal(ToD); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1780 | return ToD; |
| 1781 | } |
| 1782 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1783 | Decl *ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
| 1784 | // Import the major distinguishing characteristics of this namespace. |
| 1785 | DeclContext *DC, *LexicalDC; |
| 1786 | DeclarationName Name; |
| 1787 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1788 | NamedDecl *ToD; |
| 1789 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1790 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1791 | if (ToD) |
| 1792 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1793 | |
| 1794 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1795 | if (!Name) { |
| 1796 | // This is an anonymous namespace. Adopt an existing anonymous |
| 1797 | // namespace if we can. |
| 1798 | // FIXME: Not testable. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1799 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1800 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 1801 | else |
| 1802 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 1803 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1804 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1805 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1806 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1807 | for (auto *FoundDecl : FoundDecls) { |
| 1808 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1809 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1810 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1811 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1812 | MergeWithNamespace = FoundNS; |
| 1813 | ConflictingDecls.clear(); |
| 1814 | break; |
| 1815 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1816 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1817 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1818 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1819 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1820 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 1821 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1822 | ConflictingDecls.data(), |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1823 | ConflictingDecls.size()); |
| 1824 | } |
| 1825 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1826 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1827 | // Create the "to" namespace, if needed. |
| 1828 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 1829 | if (!ToNamespace) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1830 | if (GetImportedOrCreateDecl( |
| 1831 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
| 1832 | Importer.Import(D->getLocStart()), Loc, Name.getAsIdentifierInfo(), |
| 1833 | /*PrevDecl=*/nullptr)) |
| 1834 | return ToNamespace; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1835 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1836 | LexicalDC->addDeclInternal(ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1837 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1838 | // If this is an anonymous namespace, register it as the anonymous |
| 1839 | // namespace within its context. |
| 1840 | if (!Name) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1841 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1842 | TU->setAnonymousNamespace(ToNamespace); |
| 1843 | else |
| 1844 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 1845 | } |
| 1846 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1847 | Importer.MapImported(D, ToNamespace); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1848 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1849 | ImportDeclContext(D); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1850 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1851 | return ToNamespace; |
| 1852 | } |
| 1853 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1854 | Decl *ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 1855 | // Import the major distinguishing characteristics of this namespace. |
| 1856 | DeclContext *DC, *LexicalDC; |
| 1857 | DeclarationName Name; |
| 1858 | SourceLocation Loc; |
| 1859 | NamedDecl *LookupD; |
| 1860 | if (ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 1861 | return nullptr; |
| 1862 | if (LookupD) |
| 1863 | return LookupD; |
| 1864 | |
| 1865 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 1866 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1867 | auto *TargetDecl = cast_or_null<NamespaceDecl>( |
| 1868 | Importer.Import(D->getNamespace())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1869 | if (!TargetDecl) |
| 1870 | return nullptr; |
| 1871 | |
| 1872 | IdentifierInfo *ToII = Importer.Import(D->getIdentifier()); |
| 1873 | if (!ToII) |
| 1874 | return nullptr; |
| 1875 | |
| 1876 | NestedNameSpecifierLoc ToQLoc = Importer.Import(D->getQualifierLoc()); |
| 1877 | if (D->getQualifierLoc() && !ToQLoc) |
| 1878 | return nullptr; |
| 1879 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1880 | NamespaceAliasDecl *ToD; |
| 1881 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, |
| 1882 | Importer.Import(D->getNamespaceLoc()), |
| 1883 | Importer.Import(D->getAliasLoc()), ToII, ToQLoc, |
| 1884 | Importer.Import(D->getTargetNameLoc()), |
| 1885 | TargetDecl)) |
| 1886 | return ToD; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1887 | |
| 1888 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1889 | LexicalDC->addDeclInternal(ToD); |
| 1890 | |
| 1891 | return ToD; |
| 1892 | } |
| 1893 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1894 | Decl *ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1895 | // Import the major distinguishing characteristics of this typedef. |
| 1896 | DeclContext *DC, *LexicalDC; |
| 1897 | DeclarationName Name; |
| 1898 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1899 | NamedDecl *ToD; |
| 1900 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1901 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1902 | if (ToD) |
| 1903 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1904 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1905 | // If this typedef is not in block scope, determine whether we've |
| 1906 | // seen a typedef with the same name (that we can merge with) or any |
| 1907 | // other entity by that name (which name lookup could conflict with). |
| 1908 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1909 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1910 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1911 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1912 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1913 | for (auto *FoundDecl : FoundDecls) { |
| 1914 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1915 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1916 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1917 | if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(), |
| 1918 | FoundTypedef->getUnderlyingType())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1919 | return Importer.MapImported(D, FoundTypedef); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1920 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1921 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1922 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1923 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1924 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1925 | if (!ConflictingDecls.empty()) { |
| 1926 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1927 | ConflictingDecls.data(), |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1928 | ConflictingDecls.size()); |
| 1929 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1930 | return nullptr; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1931 | } |
| 1932 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1933 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1934 | // Import the underlying type of this typedef; |
| 1935 | QualType T = Importer.Import(D->getUnderlyingType()); |
| 1936 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1937 | return nullptr; |
| 1938 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1939 | // Create the new typedef node. |
| 1940 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 1941 | SourceLocation StartL = Importer.Import(D->getLocStart()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1942 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1943 | TypedefNameDecl *ToTypedef; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1944 | if (IsAlias) { |
| 1945 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
| 1946 | ToTypedef, D, Importer.getToContext(), DC, StartL, Loc, |
| 1947 | Name.getAsIdentifierInfo(), TInfo)) |
| 1948 | return ToTypedef; |
| 1949 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
| 1950 | ToTypedef, D, Importer.getToContext(), DC, StartL, Loc, |
| 1951 | Name.getAsIdentifierInfo(), TInfo)) |
| 1952 | return ToTypedef; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1953 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1954 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1955 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1956 | |
| 1957 | // Templated declarations should not appear in DeclContext. |
| 1958 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 1959 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 1960 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1961 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1962 | return ToTypedef; |
| 1963 | } |
| 1964 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1965 | Decl *ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
| 1966 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 1967 | } |
| 1968 | |
| 1969 | Decl *ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| 1970 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 1971 | } |
| 1972 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1973 | Decl *ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| 1974 | // Import the major distinguishing characteristics of this typedef. |
| 1975 | DeclContext *DC, *LexicalDC; |
| 1976 | DeclarationName Name; |
| 1977 | SourceLocation Loc; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1978 | NamedDecl *FoundD; |
| 1979 | if (ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1980 | return nullptr; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1981 | if (FoundD) |
| 1982 | return FoundD; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1983 | |
| 1984 | // If this typedef is not in block scope, determine whether we've |
| 1985 | // seen a typedef with the same name (that we can merge with) or any |
| 1986 | // other entity by that name (which name lookup could conflict with). |
| 1987 | if (!DC->isFunctionOrMethod()) { |
| 1988 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 1989 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 1990 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 1991 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1992 | for (auto *FoundDecl : FoundDecls) { |
| 1993 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1994 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1995 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1996 | return Importer.MapImported(D, FoundAlias); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1997 | ConflictingDecls.push_back(FoundDecl); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | if (!ConflictingDecls.empty()) { |
| 2001 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2002 | ConflictingDecls.data(), |
| 2003 | ConflictingDecls.size()); |
| 2004 | if (!Name) |
| 2005 | return nullptr; |
| 2006 | } |
| 2007 | } |
| 2008 | |
| 2009 | TemplateParameterList *Params = ImportTemplateParameterList( |
| 2010 | D->getTemplateParameters()); |
| 2011 | if (!Params) |
| 2012 | return nullptr; |
| 2013 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2014 | auto *TemplDecl = cast_or_null<TypeAliasDecl>( |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2015 | Importer.Import(D->getTemplatedDecl())); |
| 2016 | if (!TemplDecl) |
| 2017 | return nullptr; |
| 2018 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2019 | TypeAliasTemplateDecl *ToAlias; |
| 2020 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
| 2021 | Name, Params, TemplDecl)) |
| 2022 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2023 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2024 | TemplDecl->setDescribedAliasTemplate(ToAlias); |
| 2025 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2026 | ToAlias->setAccess(D->getAccess()); |
| 2027 | ToAlias->setLexicalDeclContext(LexicalDC); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2028 | LexicalDC->addDeclInternal(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2029 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2030 | } |
| 2031 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2032 | Decl *ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
| 2033 | // Import the major distinguishing characteristics of this label. |
| 2034 | DeclContext *DC, *LexicalDC; |
| 2035 | DeclarationName Name; |
| 2036 | SourceLocation Loc; |
| 2037 | NamedDecl *ToD; |
| 2038 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2039 | return nullptr; |
| 2040 | if (ToD) |
| 2041 | return ToD; |
| 2042 | |
| 2043 | assert(LexicalDC->isFunctionOrMethod()); |
| 2044 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2045 | LabelDecl *ToLabel; |
| 2046 | if (D->isGnuLocal() |
| 2047 | ? GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, |
| 2048 | Importer.Import(D->getLocation()), |
| 2049 | Name.getAsIdentifierInfo(), |
| 2050 | Importer.Import(D->getLocStart())) |
| 2051 | : GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, |
| 2052 | Importer.Import(D->getLocation()), |
| 2053 | Name.getAsIdentifierInfo())) |
| 2054 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2055 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2056 | auto *Label = cast_or_null<LabelStmt>(Importer.Import(D->getStmt())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2057 | if (!Label) |
| 2058 | return nullptr; |
| 2059 | |
| 2060 | ToLabel->setStmt(Label); |
| 2061 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2062 | LexicalDC->addDeclInternal(ToLabel); |
| 2063 | return ToLabel; |
| 2064 | } |
| 2065 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2066 | Decl *ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
| 2067 | // Import the major distinguishing characteristics of this enum. |
| 2068 | DeclContext *DC, *LexicalDC; |
| 2069 | DeclarationName Name; |
| 2070 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2071 | NamedDecl *ToD; |
| 2072 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2073 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2074 | if (ToD) |
| 2075 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2076 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2077 | // Figure out what enum name we're looking for. |
| 2078 | unsigned IDNS = Decl::IDNS_Tag; |
| 2079 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2080 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 2081 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2082 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2083 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2084 | IDNS |= Decl::IDNS_Ordinary; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2085 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2086 | // We may already have an enum of the same name; try to find and match it. |
| 2087 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2088 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2089 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 2090 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2091 | for (auto *FoundDecl : FoundDecls) { |
| 2092 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2093 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2094 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2095 | Decl *Found = FoundDecl; |
| 2096 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2097 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2098 | Found = Tag->getDecl(); |
| 2099 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2100 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2101 | if (auto *FoundEnum = dyn_cast<EnumDecl>(Found)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2102 | if (IsStructuralMatch(D, FoundEnum)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2103 | return Importer.MapImported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2104 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2105 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2106 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2107 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2108 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2109 | if (!ConflictingDecls.empty()) { |
| 2110 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2111 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2112 | ConflictingDecls.size()); |
| 2113 | } |
| 2114 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2115 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2116 | // Create the enum declaration. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2117 | EnumDecl *D2; |
| 2118 | if (GetImportedOrCreateDecl( |
| 2119 | D2, D, Importer.getToContext(), DC, Importer.Import(D->getLocStart()), |
| 2120 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), |
| 2121 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2122 | return D2; |
| 2123 | |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 2124 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2125 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2126 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2127 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2128 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2129 | |
| 2130 | // Import the integer type. |
| 2131 | QualType ToIntegerType = Importer.Import(D->getIntegerType()); |
| 2132 | if (ToIntegerType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2133 | return nullptr; |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2134 | D2->setIntegerType(ToIntegerType); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2135 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2136 | // Import the definition |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 2137 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2138 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2139 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2140 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2141 | } |
| 2142 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2143 | Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
| 2144 | // If this record has a definition in the translation unit we're coming from, |
| 2145 | // but this particular declaration is not that definition, import the |
| 2146 | // definition and map to that. |
Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 2147 | TagDecl *Definition = D->getDefinition(); |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2148 | if (Definition && Definition != D && |
| 2149 | // In contrast to a normal CXXRecordDecl, the implicit |
| 2150 | // CXXRecordDecl of ClassTemplateSpecializationDecl is its redeclaration. |
| 2151 | // The definition of the implicit CXXRecordDecl in this case is the |
| 2152 | // ClassTemplateSpecializationDecl itself. Thus, we start with an extra |
| 2153 | // condition in order to be able to import the implict Decl. |
| 2154 | !D->isImplicit()) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2155 | Decl *ImportedDef = Importer.Import(Definition); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2156 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2157 | return nullptr; |
| 2158 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2159 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2160 | } |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2161 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2162 | // Import the major distinguishing characteristics of this record. |
| 2163 | DeclContext *DC, *LexicalDC; |
| 2164 | DeclarationName Name; |
| 2165 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2166 | NamedDecl *ToD; |
| 2167 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2168 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2169 | if (ToD) |
| 2170 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2171 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2172 | // Figure out what structure name we're looking for. |
| 2173 | unsigned IDNS = Decl::IDNS_Tag; |
| 2174 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2175 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 2176 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2177 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2178 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2179 | IDNS |= Decl::IDNS_Ordinary; |
| 2180 | |
| 2181 | // 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] | 2182 | RecordDecl *AdoptDecl = nullptr; |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2183 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2184 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2185 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2186 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 2187 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2188 | |
| 2189 | if (!FoundDecls.empty()) { |
| 2190 | // We're going to have to compare D against potentially conflicting Decls, so complete it. |
| 2191 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2192 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2193 | } |
| 2194 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2195 | for (auto *FoundDecl : FoundDecls) { |
| 2196 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2197 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2198 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2199 | Decl *Found = FoundDecl; |
| 2200 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2201 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2202 | Found = Tag->getDecl(); |
| 2203 | } |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2204 | |
| 2205 | if (D->getDescribedTemplate()) { |
| 2206 | if (auto *Template = dyn_cast<ClassTemplateDecl>(Found)) |
| 2207 | Found = Template->getTemplatedDecl(); |
| 2208 | else |
| 2209 | continue; |
| 2210 | } |
| 2211 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2212 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Aleksei Sidorin | 499de6c | 2018-04-05 15:31:49 +0000 | [diff] [blame] | 2213 | if (!SearchName) { |
Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2214 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2215 | continue; |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2216 | } |
| 2217 | |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2218 | PrevDecl = FoundRecord; |
| 2219 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2220 | if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2221 | if ((SearchName && !D->isCompleteDefinition()) |
| 2222 | || (D->isCompleteDefinition() && |
| 2223 | D->isAnonymousStructOrUnion() |
| 2224 | == FoundDef->isAnonymousStructOrUnion() && |
| 2225 | IsStructuralMatch(D, FoundDef))) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2226 | // The record types structurally match, or the "from" translation |
| 2227 | // unit only had a forward declaration anyway; call it the same |
| 2228 | // function. |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2229 | // FIXME: Structural equivalence check should check for same |
| 2230 | // user-defined methods. |
| 2231 | Importer.MapImported(D, FoundDef); |
| 2232 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2233 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); |
| 2234 | assert(FoundCXX && "Record type mismatch"); |
| 2235 | |
| 2236 | if (D->isCompleteDefinition() && !Importer.isMinimalImport()) |
| 2237 | // FoundDef may not have every implicit method that D has |
| 2238 | // because implicit methods are created only if they are used. |
| 2239 | ImportImplicitMethods(DCXX, FoundCXX); |
| 2240 | } |
| 2241 | return FoundDef; |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2242 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2243 | } else if (!D->isCompleteDefinition()) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2244 | // We have a forward declaration of this type, so adopt that forward |
| 2245 | // declaration rather than building a new one. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2246 | |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2247 | // If one or both can be completed from external storage then try one |
| 2248 | // last time to complete and compare them before doing this. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2249 | |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2250 | if (FoundRecord->hasExternalLexicalStorage() && |
| 2251 | !FoundRecord->isCompleteDefinition()) |
| 2252 | FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord); |
| 2253 | if (D->hasExternalLexicalStorage()) |
| 2254 | D->getASTContext().getExternalSource()->CompleteType(D); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2255 | |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2256 | if (FoundRecord->isCompleteDefinition() && |
| 2257 | D->isCompleteDefinition() && |
| 2258 | !IsStructuralMatch(D, FoundRecord)) |
| 2259 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2260 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2261 | AdoptDecl = FoundRecord; |
| 2262 | continue; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2263 | } else if (!SearchName) { |
| 2264 | continue; |
| 2265 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2266 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2267 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2268 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2269 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2270 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2271 | if (!ConflictingDecls.empty() && SearchName) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2272 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2273 | ConflictingDecls.data(), |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2274 | ConflictingDecls.size()); |
| 2275 | } |
| 2276 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2277 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2278 | // Create the record declaration. |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2279 | RecordDecl *D2 = AdoptDecl; |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 2280 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2281 | if (!D2) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2282 | CXXRecordDecl *D2CXX = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2283 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2284 | if (DCXX->isLambda()) { |
| 2285 | TypeSourceInfo *TInfo = Importer.Import(DCXX->getLambdaTypeInfo()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2286 | if (GetImportedOrCreateSpecialDecl( |
| 2287 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
| 2288 | DC, TInfo, Loc, DCXX->isDependentLambda(), |
| 2289 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2290 | return D2CXX; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2291 | Decl *CDecl = Importer.Import(DCXX->getLambdaContextDecl()); |
| 2292 | if (DCXX->getLambdaContextDecl() && !CDecl) |
| 2293 | return nullptr; |
Sean Callanan | 041cceb | 2016-05-14 05:43:57 +0000 | [diff] [blame] | 2294 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), CDecl); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2295 | } else if (DCXX->isInjectedClassName()) { |
| 2296 | // We have to be careful to do a similar dance to the one in |
| 2297 | // Sema::ActOnStartCXXMemberDeclarations |
| 2298 | CXXRecordDecl *const PrevDecl = nullptr; |
| 2299 | const bool DelayTypeCreation = true; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2300 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2301 | D->getTagKind(), DC, StartLoc, Loc, |
| 2302 | Name.getAsIdentifierInfo(), PrevDecl, |
| 2303 | DelayTypeCreation)) |
| 2304 | return D2CXX; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2305 | Importer.getToContext().getTypeDeclType( |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2306 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2307 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2308 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2309 | D->getTagKind(), DC, StartLoc, Loc, |
| 2310 | Name.getAsIdentifierInfo(), |
| 2311 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2312 | return D2CXX; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2313 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2314 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2315 | D2 = D2CXX; |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2316 | D2->setAccess(D->getAccess()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2317 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | de8bf26 | 2018-05-17 09:46:07 +0000 | [diff] [blame] | 2318 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2319 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2320 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2321 | if (ClassTemplateDecl *FromDescribed = |
| 2322 | DCXX->getDescribedClassTemplate()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2323 | auto *ToDescribed = cast_or_null<ClassTemplateDecl>( |
| 2324 | Importer.Import(FromDescribed)); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2325 | if (!ToDescribed) |
| 2326 | return nullptr; |
| 2327 | D2CXX->setDescribedClassTemplate(ToDescribed); |
Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2328 | if (!DCXX->isInjectedClassName()) { |
| 2329 | // In a record describing a template the type should be an |
| 2330 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2331 | // previously set type to the correct value here (ToDescribed is not |
| 2332 | // available at record create). |
| 2333 | // FIXME: The previous type is cleared but not removed from |
| 2334 | // ASTContext's internal storage. |
| 2335 | CXXRecordDecl *Injected = nullptr; |
| 2336 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2337 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2338 | if (Record && Record->isInjectedClassName()) { |
| 2339 | Injected = Record; |
| 2340 | break; |
| 2341 | } |
| 2342 | } |
| 2343 | D2CXX->setTypeForDecl(nullptr); |
| 2344 | Importer.getToContext().getInjectedClassNameType(D2CXX, |
| 2345 | ToDescribed->getInjectedClassNameSpecialization()); |
| 2346 | if (Injected) { |
| 2347 | Injected->setTypeForDecl(nullptr); |
| 2348 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2349 | } |
| 2350 | } |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2351 | } else if (MemberSpecializationInfo *MemberInfo = |
| 2352 | DCXX->getMemberSpecializationInfo()) { |
| 2353 | TemplateSpecializationKind SK = |
| 2354 | MemberInfo->getTemplateSpecializationKind(); |
| 2355 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2356 | auto *ToInst = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2357 | cast_or_null<CXXRecordDecl>(Importer.Import(FromInst)); |
| 2358 | if (FromInst && !ToInst) |
| 2359 | return nullptr; |
| 2360 | D2CXX->setInstantiationOfMemberClass(ToInst, SK); |
| 2361 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2362 | Importer.Import(MemberInfo->getPointOfInstantiation())); |
| 2363 | } |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2364 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2365 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
| 2366 | D->getTagKind(), DC, StartLoc, Loc, |
| 2367 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2368 | return D2; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2369 | D2->setLexicalDeclContext(LexicalDC); |
| 2370 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2371 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2372 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2373 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2374 | if (D->isAnonymousStructOrUnion()) |
| 2375 | D2->setAnonymousStructOrUnion(true); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2376 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2377 | |
| 2378 | Importer.MapImported(D, D2); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2379 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 2380 | if (D->isCompleteDefinition() && ImportDefinition(D, D2, IDK_Default)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2381 | return nullptr; |
| 2382 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2383 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2384 | } |
| 2385 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2386 | Decl *ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| 2387 | // Import the major distinguishing characteristics of this enumerator. |
| 2388 | DeclContext *DC, *LexicalDC; |
| 2389 | DeclarationName Name; |
| 2390 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2391 | NamedDecl *ToD; |
| 2392 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2393 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2394 | if (ToD) |
| 2395 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2396 | |
| 2397 | QualType T = Importer.Import(D->getType()); |
| 2398 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2399 | return nullptr; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2400 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2401 | // Determine whether there are any other declarations with the same name and |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2402 | // in the same context. |
| 2403 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2404 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2405 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2406 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2407 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2408 | for (auto *FoundDecl : FoundDecls) { |
| 2409 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2410 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2411 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2412 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2413 | if (IsStructuralMatch(D, FoundEnumConstant)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2414 | return Importer.MapImported(D, FoundEnumConstant); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2415 | } |
| 2416 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2417 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2418 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2419 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2420 | if (!ConflictingDecls.empty()) { |
| 2421 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2422 | ConflictingDecls.data(), |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2423 | ConflictingDecls.size()); |
| 2424 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2425 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2426 | } |
| 2427 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2428 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2429 | Expr *Init = Importer.Import(D->getInitExpr()); |
| 2430 | if (D->getInitExpr() && !Init) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2431 | return nullptr; |
| 2432 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2433 | EnumConstantDecl *ToEnumerator; |
| 2434 | if (GetImportedOrCreateDecl( |
| 2435 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
| 2436 | Name.getAsIdentifierInfo(), T, Init, D->getInitVal())) |
| 2437 | return ToEnumerator; |
| 2438 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2439 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2440 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2441 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2442 | return ToEnumerator; |
| 2443 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2444 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2445 | bool ASTNodeImporter::ImportTemplateInformation(FunctionDecl *FromFD, |
| 2446 | FunctionDecl *ToFD) { |
| 2447 | switch (FromFD->getTemplatedKind()) { |
| 2448 | case FunctionDecl::TK_NonTemplate: |
| 2449 | case FunctionDecl::TK_FunctionTemplate: |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2450 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2451 | |
| 2452 | case FunctionDecl::TK_MemberSpecialization: { |
| 2453 | auto *InstFD = cast_or_null<FunctionDecl>( |
| 2454 | Importer.Import(FromFD->getInstantiatedFromMemberFunction())); |
| 2455 | if (!InstFD) |
| 2456 | return true; |
| 2457 | |
| 2458 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
| 2459 | SourceLocation POI = Importer.Import( |
| 2460 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation()); |
| 2461 | ToFD->setInstantiationOfMemberFunction(InstFD, TSK); |
| 2462 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2463 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2464 | } |
| 2465 | |
| 2466 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2467 | FunctionTemplateDecl* Template; |
| 2468 | OptionalTemplateArgsTy ToTemplArgs; |
| 2469 | std::tie(Template, ToTemplArgs) = |
| 2470 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| 2471 | if (!Template || !ToTemplArgs) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2472 | return true; |
| 2473 | |
| 2474 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2475 | Importer.getToContext(), *ToTemplArgs); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2476 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2477 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2478 | TemplateArgumentListInfo ToTAInfo; |
| 2479 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2480 | if (FromTAArgsAsWritten) |
| 2481 | if (ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2482 | return true; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2483 | |
| 2484 | SourceLocation POI = Importer.Import(FTSInfo->getPointOfInstantiation()); |
| 2485 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2486 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2487 | ToFD->setFunctionTemplateSpecialization( |
| 2488 | Template, ToTAList, /* InsertPos= */ nullptr, |
| 2489 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, POI); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2490 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2491 | } |
| 2492 | |
| 2493 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 2494 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 2495 | UnresolvedSet<8> TemplDecls; |
| 2496 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 2497 | for (unsigned I = 0; I < NumTemplates; I++) { |
| 2498 | if (auto *ToFTD = cast_or_null<FunctionTemplateDecl>( |
| 2499 | Importer.Import(FromInfo->getTemplate(I)))) |
| 2500 | TemplDecls.addDecl(ToFTD); |
| 2501 | else |
| 2502 | return true; |
| 2503 | } |
| 2504 | |
| 2505 | // Import TemplateArgumentListInfo. |
| 2506 | TemplateArgumentListInfo ToTAInfo; |
| 2507 | if (ImportTemplateArgumentListInfo( |
| 2508 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 2509 | llvm::makeArrayRef(FromInfo->getTemplateArgs(), |
| 2510 | FromInfo->getNumTemplateArgs()), |
| 2511 | ToTAInfo)) |
| 2512 | return true; |
| 2513 | |
| 2514 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 2515 | TemplDecls, ToTAInfo); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2516 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2517 | } |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2518 | } |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2519 | llvm_unreachable("All cases should be covered!"); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2520 | } |
| 2521 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2522 | FunctionDecl * |
| 2523 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
| 2524 | FunctionTemplateDecl* Template; |
| 2525 | OptionalTemplateArgsTy ToTemplArgs; |
| 2526 | std::tie(Template, ToTemplArgs) = |
| 2527 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| 2528 | if (!Template || !ToTemplArgs) |
| 2529 | return nullptr; |
| 2530 | |
| 2531 | void *InsertPos = nullptr; |
| 2532 | auto *FoundSpec = Template->findSpecialization(*ToTemplArgs, InsertPos); |
| 2533 | return FoundSpec; |
| 2534 | } |
| 2535 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2536 | Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2537 | |
| 2538 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 2539 | auto RedeclIt = Redecls.begin(); |
| 2540 | // Import the first part of the decl chain. I.e. import all previous |
| 2541 | // declarations starting from the canonical decl. |
| 2542 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) |
| 2543 | if (!Importer.Import(*RedeclIt)) |
| 2544 | return nullptr; |
| 2545 | assert(*RedeclIt == D); |
| 2546 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2547 | // Import the major distinguishing characteristics of this function. |
| 2548 | DeclContext *DC, *LexicalDC; |
| 2549 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2550 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2551 | NamedDecl *ToD; |
| 2552 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2553 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2554 | if (ToD) |
| 2555 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2556 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2557 | const FunctionDecl *FoundByLookup = nullptr; |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 2558 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2559 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2560 | // If this is a function template specialization, then try to find the same |
| 2561 | // existing specialization in the "to" context. The localUncachedLookup |
| 2562 | // below will not find any specialization, but would find the primary |
| 2563 | // template; thus, we have to skip normal lookup in case of specializations. |
| 2564 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 2565 | if (D->getTemplatedKind() == |
| 2566 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
| 2567 | if (FunctionDecl *FoundFunction = FindFunctionTemplateSpecialization(D)) { |
| 2568 | if (D->doesThisDeclarationHaveABody() && |
| 2569 | FoundFunction->hasBody()) |
| 2570 | return Importer.Imported(D, FoundFunction); |
| 2571 | FoundByLookup = FoundFunction; |
| 2572 | } |
| 2573 | } |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2574 | // Try to find a function in our own ("to") context with the same name, same |
| 2575 | // type, and in the same context as the function we're importing. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2576 | else if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2577 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2578 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2579 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2580 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2581 | for (auto *FoundDecl : FoundDecls) { |
| 2582 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2583 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2584 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 2585 | // If template was found, look at the templated function. |
| 2586 | if (FromFT) { |
| 2587 | if (auto *Template = dyn_cast<FunctionTemplateDecl>(FoundDecl)) |
| 2588 | FoundDecl = Template->getTemplatedDecl(); |
| 2589 | else |
| 2590 | continue; |
| 2591 | } |
| 2592 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2593 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 2594 | if (FoundFunction->hasExternalFormalLinkage() && |
| 2595 | D->hasExternalFormalLinkage()) { |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2596 | if (IsStructuralMatch(D, FoundFunction)) { |
| 2597 | const FunctionDecl *Definition = nullptr; |
| 2598 | if (D->doesThisDeclarationHaveABody() && |
| 2599 | FoundFunction->hasBody(Definition)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2600 | return Importer.MapImported( |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2601 | D, const_cast<FunctionDecl *>(Definition)); |
| 2602 | } |
| 2603 | FoundByLookup = FoundFunction; |
| 2604 | break; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2605 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2606 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2607 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 2608 | // Sema::IsOverload out to the AST library. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2609 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2610 | // Function overloading is okay in C++. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2611 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2612 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2613 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2614 | // Complain about inconsistent function types. |
| 2615 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2616 | << Name << D->getType() << FoundFunction->getType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2617 | Importer.ToDiag(FoundFunction->getLocation(), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2618 | diag::note_odr_value_here) |
| 2619 | << FoundFunction->getType(); |
| 2620 | } |
| 2621 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2622 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2623 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2624 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2625 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2626 | if (!ConflictingDecls.empty()) { |
| 2627 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2628 | ConflictingDecls.data(), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2629 | ConflictingDecls.size()); |
| 2630 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2631 | return nullptr; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2632 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2633 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2634 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2635 | DeclarationNameInfo NameInfo(Name, Loc); |
| 2636 | // Import additional name location/type info. |
| 2637 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 2638 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2639 | QualType FromTy = D->getType(); |
| 2640 | bool usedDifferentExceptionSpec = false; |
| 2641 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2642 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2643 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 2644 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 2645 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 2646 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 2647 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 2648 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 2649 | FromEPI.ExceptionSpec.SourceTemplate || |
| 2650 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2651 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 2652 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2653 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2654 | usedDifferentExceptionSpec = true; |
| 2655 | } |
| 2656 | } |
| 2657 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2658 | // Import the type. |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2659 | QualType T = Importer.Import(FromTy); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2660 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2661 | return nullptr; |
| 2662 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2663 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2664 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2665 | for (auto P : D->parameters()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2666 | auto *ToP = cast_or_null<ParmVarDecl>(Importer.Import(P)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2667 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2668 | return nullptr; |
| 2669 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2670 | Parameters.push_back(ToP); |
| 2671 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2672 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2673 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2674 | if (D->getTypeSourceInfo() && !TInfo) |
| 2675 | return nullptr; |
| 2676 | |
| 2677 | // Create the imported function. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2678 | FunctionDecl *ToFunction = nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2679 | SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2680 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2681 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
| 2682 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 2683 | InnerLocStart, NameInfo, T, TInfo, FromConstructor->isExplicit(), |
| 2684 | D->isInlineSpecified(), D->isImplicit(), D->isConstexpr())) |
| 2685 | return ToFunction; |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2686 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 2687 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2688 | for (auto *I : FromConstructor->inits()) { |
| 2689 | auto *ToI = cast_or_null<CXXCtorInitializer>(Importer.Import(I)); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2690 | if (!ToI && I) |
| 2691 | return nullptr; |
| 2692 | CtorInitializers.push_back(ToI); |
| 2693 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2694 | auto **Memory = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2695 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 2696 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2697 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2698 | ToCtor->setCtorInitializers(Memory); |
| 2699 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 2700 | } |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2701 | } else if (isa<CXXDestructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2702 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
| 2703 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 2704 | InnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 2705 | D->isImplicit())) |
| 2706 | return ToFunction; |
| 2707 | } else if (CXXConversionDecl *FromConversion = |
| 2708 | dyn_cast<CXXConversionDecl>(D)) { |
| 2709 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 2710 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 2711 | InnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 2712 | FromConversion->isExplicit(), D->isConstexpr(), SourceLocation())) |
| 2713 | return ToFunction; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2714 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2715 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 2716 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 2717 | InnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
| 2718 | Method->isInlineSpecified(), D->isConstexpr(), SourceLocation())) |
| 2719 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2720 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2721 | if (GetImportedOrCreateDecl(ToFunction, D, Importer.getToContext(), DC, |
| 2722 | InnerLocStart, NameInfo, T, TInfo, |
| 2723 | D->getStorageClass(), D->isInlineSpecified(), |
| 2724 | D->hasWrittenPrototype(), D->isConstexpr())) |
| 2725 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2726 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 2727 | |
| 2728 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2729 | ToFunction->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2730 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2731 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 2732 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 2733 | ToFunction->setTrivial(D->isTrivial()); |
| 2734 | ToFunction->setPure(D->isPure()); |
Rafael Stahl | a001047 | 2018-07-09 08:40:17 +0000 | [diff] [blame] | 2735 | ToFunction->setRangeEnd(Importer.Import(D->getLocEnd())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2736 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2737 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2738 | for (auto *Param : Parameters) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2739 | Param->setOwningFunction(ToFunction); |
| 2740 | ToFunction->addDeclInternal(Param); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2741 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 2742 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2743 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2744 | if (FoundByLookup) { |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2745 | auto *Recent = const_cast<FunctionDecl *>( |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2746 | FoundByLookup->getMostRecentDecl()); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2747 | ToFunction->setPreviousDecl(Recent); |
| 2748 | } |
| 2749 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2750 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 2751 | // params it refers to. |
| 2752 | if (TInfo) { |
| 2753 | if (auto ProtoLoc = |
| 2754 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 2755 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 2756 | ProtoLoc.setParam(I, Parameters[I]); |
| 2757 | } |
| 2758 | } |
| 2759 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2760 | if (usedDifferentExceptionSpec) { |
| 2761 | // Update FunctionProtoType::ExtProtoInfo. |
| 2762 | QualType T = Importer.Import(D->getType()); |
| 2763 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2764 | return nullptr; |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2765 | ToFunction->setType(T); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 2766 | } |
| 2767 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 2768 | // Import the describing template function, if any. |
| 2769 | if (FromFT) |
| 2770 | if (!Importer.Import(FromFT)) |
| 2771 | return nullptr; |
| 2772 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2773 | if (D->doesThisDeclarationHaveABody()) { |
| 2774 | if (Stmt *FromBody = D->getBody()) { |
| 2775 | if (Stmt *ToBody = Importer.Import(FromBody)) { |
| 2776 | ToFunction->setBody(ToBody); |
| 2777 | } |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2778 | } |
| 2779 | } |
| 2780 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2781 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2782 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2783 | // If it is a template, import all related things. |
| 2784 | if (ImportTemplateInformation(D, ToFunction)) |
| 2785 | return nullptr; |
| 2786 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2787 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); |
| 2788 | |
| 2789 | // TODO Can we generalize this approach to other AST nodes as well? |
| 2790 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 2791 | DC->addDeclInternal(ToFunction); |
| 2792 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2793 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2794 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2795 | // Friend declaration's lexical context is the befriending class, but the |
| 2796 | // semantic context is the enclosing scope of the befriending class. |
| 2797 | // We want the friend functions to be found in the semantic context by lookup. |
| 2798 | // FIXME should we handle this generically in VisitFriendDecl? |
| 2799 | // In Other cases when LexicalDC != DC we don't want it to be added, |
| 2800 | // e.g out-of-class definitions like void B::f() {} . |
| 2801 | if (LexicalDC != DC && IsFriend) { |
| 2802 | DC->makeDeclVisibleInContext(ToFunction); |
| 2803 | } |
| 2804 | |
| 2805 | // Import the rest of the chain. I.e. import all subsequent declarations. |
| 2806 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) |
| 2807 | if (!Importer.Import(*RedeclIt)) |
| 2808 | return nullptr; |
| 2809 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 2810 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 2811 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 2812 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2813 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2814 | } |
| 2815 | |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2816 | Decl *ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| 2817 | return VisitFunctionDecl(D); |
| 2818 | } |
| 2819 | |
| 2820 | Decl *ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| 2821 | return VisitCXXMethodDecl(D); |
| 2822 | } |
| 2823 | |
| 2824 | Decl *ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| 2825 | return VisitCXXMethodDecl(D); |
| 2826 | } |
| 2827 | |
| 2828 | Decl *ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| 2829 | return VisitCXXMethodDecl(D); |
| 2830 | } |
| 2831 | |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2832 | static unsigned getFieldIndex(Decl *F) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2833 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2834 | if (!Owner) |
| 2835 | return 0; |
| 2836 | |
| 2837 | unsigned Index = 1; |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2838 | for (const auto *D : Owner->noload_decls()) { |
| 2839 | if (D == F) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2840 | return Index; |
| 2841 | |
| 2842 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 2843 | ++Index; |
| 2844 | } |
| 2845 | |
| 2846 | return Index; |
| 2847 | } |
| 2848 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2849 | Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
| 2850 | // Import the major distinguishing characteristics of a variable. |
| 2851 | DeclContext *DC, *LexicalDC; |
| 2852 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2853 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2854 | NamedDecl *ToD; |
| 2855 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2856 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2857 | if (ToD) |
| 2858 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2859 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2860 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2861 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2862 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2863 | for (auto *FoundDecl : FoundDecls) { |
| 2864 | if (auto *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2865 | // For anonymous fields, match up by index. |
| 2866 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2867 | continue; |
| 2868 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2869 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2870 | FoundField->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2871 | Importer.MapImported(D, FoundField); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2872 | return FoundField; |
| 2873 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 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 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +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; |
| 2887 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2888 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2889 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 2890 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2891 | return nullptr; |
| 2892 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2893 | FieldDecl *ToField; |
| 2894 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
| 2895 | Importer.Import(D->getInnerLocStart()), Loc, |
| 2896 | Name.getAsIdentifierInfo(), T, TInfo, BitWidth, |
| 2897 | D->isMutable(), D->getInClassInitStyle())) |
| 2898 | return ToField; |
| 2899 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2900 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2901 | ToField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 3a83ea7 | 2016-03-03 02:22:05 +0000 | [diff] [blame] | 2902 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
Sean Callanan | bb33f58 | 2016-03-03 01:21:28 +0000 | [diff] [blame] | 2903 | Expr *ToInitializer = Importer.Import(FromInitializer); |
| 2904 | if (ToInitializer) |
| 2905 | ToField->setInClassInitializer(ToInitializer); |
| 2906 | else |
| 2907 | return nullptr; |
| 2908 | } |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2909 | ToField->setImplicit(D->isImplicit()); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2910 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2911 | return ToField; |
| 2912 | } |
| 2913 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2914 | Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| 2915 | // Import the major distinguishing characteristics of a variable. |
| 2916 | DeclContext *DC, *LexicalDC; |
| 2917 | DeclarationName Name; |
| 2918 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2919 | NamedDecl *ToD; |
| 2920 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2921 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2922 | if (ToD) |
| 2923 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2924 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2925 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2926 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2927 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2928 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2929 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2930 | // For anonymous indirect fields, match up by index. |
| 2931 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2932 | continue; |
| 2933 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2934 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2935 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 2936 | !Name.isEmpty())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2937 | Importer.MapImported(D, FoundField); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2938 | return FoundField; |
| 2939 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2940 | |
| 2941 | // If there are more anonymous fields to check, continue. |
| 2942 | if (!Name && I < N-1) |
| 2943 | continue; |
| 2944 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2945 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2946 | << Name << D->getType() << FoundField->getType(); |
| 2947 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2948 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2949 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2950 | } |
| 2951 | } |
| 2952 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2953 | // Import the type. |
| 2954 | QualType T = Importer.Import(D->getType()); |
| 2955 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2956 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2957 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2958 | auto **NamedChain = |
| 2959 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2960 | |
| 2961 | unsigned i = 0; |
Aaron Ballman | 29c9460 | 2014-03-07 18:36:15 +0000 | [diff] [blame] | 2962 | for (auto *PI : D->chain()) { |
Aaron Ballman | 1391608 | 2014-03-07 18:11:58 +0000 | [diff] [blame] | 2963 | Decl *D = Importer.Import(PI); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2964 | if (!D) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2965 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2966 | NamedChain[i++] = cast<NamedDecl>(D); |
| 2967 | } |
| 2968 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2969 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 2970 | IndirectFieldDecl *ToIndirectField; |
| 2971 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
| 2972 | Loc, Name.getAsIdentifierInfo(), T, CH)) |
| 2973 | // FIXME here we leak `NamedChain` which is allocated before |
| 2974 | return ToIndirectField; |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2975 | |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 2976 | for (const auto *A : D->attrs()) |
| 2977 | ToIndirectField->addAttr(Importer.Import(A)); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2978 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2979 | ToIndirectField->setAccess(D->getAccess()); |
| 2980 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2981 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2982 | return ToIndirectField; |
| 2983 | } |
| 2984 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2985 | Decl *ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
| 2986 | // Import the major distinguishing characteristics of a declaration. |
| 2987 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 2988 | DeclContext *LexicalDC = D->getDeclContext() == D->getLexicalDeclContext() |
| 2989 | ? DC : Importer.ImportContext(D->getLexicalDeclContext()); |
| 2990 | if (!DC || !LexicalDC) |
| 2991 | return nullptr; |
| 2992 | |
| 2993 | // Determine whether we've already imported this decl. |
| 2994 | // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup. |
| 2995 | auto *RD = cast<CXXRecordDecl>(DC); |
| 2996 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2997 | |
| 2998 | while (ImportedFriend) { |
| 2999 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 3000 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 3001 | /*Complain=*/false)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3002 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3003 | |
| 3004 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 3005 | if (Importer.IsStructurallyEquivalent( |
| 3006 | D->getFriendType()->getType(), |
| 3007 | ImportedFriend->getFriendType()->getType(), true)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3008 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3009 | } |
| 3010 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3011 | } |
| 3012 | |
| 3013 | // Not found. Create it. |
| 3014 | FriendDecl::FriendUnion ToFU; |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3015 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
| 3016 | auto *ToFriendD = cast_or_null<NamedDecl>(Importer.Import(FriendD)); |
| 3017 | if (ToFriendD && FriendD->getFriendObjectKind() != Decl::FOK_None && |
| 3018 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3019 | ToFriendD->setObjectOfFriendDecl(false); |
| 3020 | |
| 3021 | ToFU = ToFriendD; |
| 3022 | } else // The friend is a type, not a decl. |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3023 | ToFU = Importer.Import(D->getFriendType()); |
| 3024 | if (!ToFU) |
| 3025 | return nullptr; |
| 3026 | |
| 3027 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3028 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3029 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
| 3030 | TemplateParameterList *List = ImportTemplateParameterList(FromTPLists[I]); |
| 3031 | if (!List) |
| 3032 | return nullptr; |
| 3033 | ToTPLists[I] = List; |
| 3034 | } |
| 3035 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3036 | FriendDecl *FrD; |
| 3037 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
| 3038 | Importer.Import(D->getLocation()), ToFU, |
| 3039 | Importer.Import(D->getFriendLoc()), ToTPLists)) |
| 3040 | return FrD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3041 | |
| 3042 | FrD->setAccess(D->getAccess()); |
| 3043 | FrD->setLexicalDeclContext(LexicalDC); |
| 3044 | LexicalDC->addDeclInternal(FrD); |
| 3045 | return FrD; |
| 3046 | } |
| 3047 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3048 | Decl *ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| 3049 | // Import the major distinguishing characteristics of an ivar. |
| 3050 | DeclContext *DC, *LexicalDC; |
| 3051 | DeclarationName Name; |
| 3052 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3053 | NamedDecl *ToD; |
| 3054 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3055 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3056 | if (ToD) |
| 3057 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3058 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3059 | // Determine whether we've already imported this ivar |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3060 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3061 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3062 | for (auto *FoundDecl : FoundDecls) { |
| 3063 | if (auto *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3064 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3065 | FoundIvar->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3066 | Importer.MapImported(D, FoundIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3067 | return FoundIvar; |
| 3068 | } |
| 3069 | |
| 3070 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) |
| 3071 | << Name << D->getType() << FoundIvar->getType(); |
| 3072 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3073 | << FoundIvar->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3074 | return nullptr; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3075 | } |
| 3076 | } |
| 3077 | |
| 3078 | // Import the type. |
| 3079 | QualType T = Importer.Import(D->getType()); |
| 3080 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3081 | return nullptr; |
| 3082 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3083 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3084 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 3085 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3086 | return nullptr; |
| 3087 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3088 | ObjCIvarDecl *ToIvar; |
| 3089 | if (GetImportedOrCreateDecl( |
| 3090 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
| 3091 | Importer.Import(D->getInnerLocStart()), Loc, |
| 3092 | Name.getAsIdentifierInfo(), T, TInfo, D->getAccessControl(), BitWidth, |
| 3093 | D->getSynthesize())) |
| 3094 | return ToIvar; |
| 3095 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3096 | ToIvar->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3097 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3098 | return ToIvar; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3099 | } |
| 3100 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3101 | Decl *ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
| 3102 | // Import the major distinguishing characteristics of a variable. |
| 3103 | DeclContext *DC, *LexicalDC; |
| 3104 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3105 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3106 | NamedDecl *ToD; |
| 3107 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3108 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3109 | if (ToD) |
| 3110 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3111 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3112 | // Try to find a variable in our own ("to") context with the same name and |
| 3113 | // in the same context as the variable we're importing. |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3114 | if (D->isFileVarDecl()) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3115 | VarDecl *MergeWithVar = nullptr; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3116 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3117 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3118 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3119 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3120 | for (auto *FoundDecl : FoundDecls) { |
| 3121 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3122 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3123 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3124 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3125 | // 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] | 3126 | if (FoundVar->hasExternalFormalLinkage() && |
| 3127 | D->hasExternalFormalLinkage()) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3128 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3129 | FoundVar->getType())) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3130 | MergeWithVar = FoundVar; |
| 3131 | break; |
| 3132 | } |
| 3133 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3134 | const ArrayType *FoundArray |
| 3135 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3136 | const ArrayType *TArray |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3137 | = Importer.getToContext().getAsArrayType(D->getType()); |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3138 | if (FoundArray && TArray) { |
| 3139 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3140 | isa<ConstantArrayType>(TArray)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3141 | // Import the type. |
| 3142 | QualType T = Importer.Import(D->getType()); |
| 3143 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3144 | return nullptr; |
| 3145 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3146 | FoundVar->setType(T); |
| 3147 | MergeWithVar = FoundVar; |
| 3148 | break; |
| 3149 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3150 | isa<ConstantArrayType>(FoundArray)) { |
| 3151 | MergeWithVar = FoundVar; |
| 3152 | break; |
Douglas Gregor | 2fbe558 | 2010-02-10 17:16:49 +0000 | [diff] [blame] | 3153 | } |
| 3154 | } |
| 3155 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3156 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3157 | << Name << D->getType() << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3158 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3159 | << FoundVar->getType(); |
| 3160 | } |
| 3161 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3162 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3163 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3164 | } |
| 3165 | |
| 3166 | if (MergeWithVar) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3167 | // An equivalent variable with external linkage has been found. Link |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3168 | // the two declarations, then merge them. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3169 | Importer.MapImported(D, MergeWithVar); |
| 3170 | updateFlags(D, MergeWithVar); |
| 3171 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3172 | if (VarDecl *DDef = D->getDefinition()) { |
| 3173 | if (VarDecl *ExistingDef = MergeWithVar->getDefinition()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3174 | Importer.ToDiag(ExistingDef->getLocation(), |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3175 | diag::err_odr_variable_multiple_def) |
| 3176 | << Name; |
| 3177 | Importer.FromDiag(DDef->getLocation(), diag::note_odr_defined_here); |
| 3178 | } else { |
| 3179 | Expr *Init = Importer.Import(DDef->getInit()); |
Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 3180 | MergeWithVar->setInit(Init); |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 3181 | if (DDef->isInitKnownICE()) { |
| 3182 | EvaluatedStmt *Eval = MergeWithVar->ensureEvaluatedStmt(); |
| 3183 | Eval->CheckedICE = true; |
| 3184 | Eval->IsICE = DDef->isInitICE(); |
| 3185 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3186 | } |
| 3187 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3188 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3189 | return MergeWithVar; |
| 3190 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3191 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3192 | if (!ConflictingDecls.empty()) { |
| 3193 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3194 | ConflictingDecls.data(), |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3195 | ConflictingDecls.size()); |
| 3196 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3197 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3198 | } |
| 3199 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3200 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3201 | // Import the type. |
| 3202 | QualType T = Importer.Import(D->getType()); |
| 3203 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3204 | return nullptr; |
| 3205 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3206 | // Create the imported variable. |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 3207 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3208 | VarDecl *ToVar; |
| 3209 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
| 3210 | Importer.Import(D->getInnerLocStart()), Loc, |
| 3211 | Name.getAsIdentifierInfo(), T, TInfo, |
| 3212 | D->getStorageClass())) |
| 3213 | return ToVar; |
| 3214 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3215 | ToVar->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3216 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3217 | ToVar->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3218 | |
| 3219 | // Templated declarations should never appear in the enclosing DeclContext. |
| 3220 | if (!D->getDescribedVarTemplate()) |
| 3221 | LexicalDC->addDeclInternal(ToVar); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3222 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3223 | // Merge the initializer. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3224 | if (ImportDefinition(D, ToVar)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3225 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3226 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3227 | if (D->isConstexpr()) |
| 3228 | ToVar->setConstexpr(true); |
| 3229 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3230 | return ToVar; |
| 3231 | } |
| 3232 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3233 | Decl *ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| 3234 | // Parameters are created in the translation unit's context, then moved |
| 3235 | // into the function declaration's context afterward. |
| 3236 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3237 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3238 | // Import the name of this declaration. |
| 3239 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3240 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3241 | return nullptr; |
| 3242 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3243 | // Import the location of this declaration. |
| 3244 | SourceLocation Loc = Importer.Import(D->getLocation()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3245 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3246 | // Import the parameter's type. |
| 3247 | QualType T = Importer.Import(D->getType()); |
| 3248 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3249 | return nullptr; |
| 3250 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3251 | // Create the imported parameter. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3252 | ImplicitParamDecl *ToParm = nullptr; |
| 3253 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, Loc, |
| 3254 | Name.getAsIdentifierInfo(), T, |
| 3255 | D->getParameterKind())) |
| 3256 | return ToParm; |
| 3257 | return ToParm; |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3258 | } |
| 3259 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3260 | Decl *ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
| 3261 | // Parameters are created in the translation unit's context, then moved |
| 3262 | // into the function declaration's context afterward. |
| 3263 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3264 | |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 3265 | // Import the name of this declaration. |
| 3266 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3267 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3268 | return nullptr; |
| 3269 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3270 | // Import the location of this declaration. |
| 3271 | SourceLocation Loc = Importer.Import(D->getLocation()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3272 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3273 | // Import the parameter's type. |
| 3274 | QualType T = Importer.Import(D->getType()); |
| 3275 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3276 | return nullptr; |
| 3277 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3278 | // Create the imported parameter. |
| 3279 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3280 | ParmVarDecl *ToParm; |
| 3281 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3282 | Importer.Import(D->getInnerLocStart()), Loc, |
| 3283 | Name.getAsIdentifierInfo(), T, TInfo, |
| 3284 | D->getStorageClass(), |
| 3285 | /*DefaultArg*/ nullptr)) |
| 3286 | return ToParm; |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3287 | |
| 3288 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 3289 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3290 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 3291 | |
| 3292 | Expr *ToDefArg = nullptr; |
| 3293 | Expr *FromDefArg = nullptr; |
| 3294 | if (D->hasUninstantiatedDefaultArg()) { |
| 3295 | FromDefArg = D->getUninstantiatedDefaultArg(); |
| 3296 | ToDefArg = Importer.Import(FromDefArg); |
| 3297 | ToParm->setUninstantiatedDefaultArg(ToDefArg); |
| 3298 | } else if (D->hasUnparsedDefaultArg()) { |
| 3299 | ToParm->setUnparsedDefaultArg(); |
| 3300 | } else if (D->hasDefaultArg()) { |
| 3301 | FromDefArg = D->getDefaultArg(); |
| 3302 | ToDefArg = Importer.Import(FromDefArg); |
| 3303 | ToParm->setDefaultArg(ToDefArg); |
| 3304 | } |
| 3305 | if (FromDefArg && !ToDefArg) |
| 3306 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3307 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3308 | if (D->isObjCMethodParameter()) { |
| 3309 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3310 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3311 | } else { |
| 3312 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3313 | D->getFunctionScopeIndex()); |
| 3314 | } |
| 3315 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3316 | return ToParm; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3317 | } |
| 3318 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3319 | Decl *ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| 3320 | // Import the major distinguishing characteristics of a method. |
| 3321 | DeclContext *DC, *LexicalDC; |
| 3322 | DeclarationName Name; |
| 3323 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3324 | NamedDecl *ToD; |
| 3325 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3326 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3327 | if (ToD) |
| 3328 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3329 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3330 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3331 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3332 | for (auto *FoundDecl : FoundDecls) { |
| 3333 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3334 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3335 | continue; |
| 3336 | |
| 3337 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3338 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3339 | FoundMethod->getReturnType())) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3340 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3341 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3342 | << FoundMethod->getReturnType(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3343 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3344 | diag::note_odr_objc_method_here) |
| 3345 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3346 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3347 | } |
| 3348 | |
| 3349 | // Check the number of parameters. |
| 3350 | if (D->param_size() != FoundMethod->param_size()) { |
| 3351 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) |
| 3352 | << D->isInstanceMethod() << Name |
| 3353 | << D->param_size() << FoundMethod->param_size(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3354 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3355 | diag::note_odr_objc_method_here) |
| 3356 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3357 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3361 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3362 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3363 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3364 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3365 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3366 | Importer.FromDiag((*P)->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3367 | diag::err_odr_objc_method_param_type_inconsistent) |
| 3368 | << D->isInstanceMethod() << Name |
| 3369 | << (*P)->getType() << (*FoundP)->getType(); |
| 3370 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3371 | << (*FoundP)->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3372 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3373 | } |
| 3374 | } |
| 3375 | |
| 3376 | // Check variadic/non-variadic. |
| 3377 | // Check the number of parameters. |
| 3378 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| 3379 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) |
| 3380 | << D->isInstanceMethod() << Name; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3381 | Importer.ToDiag(FoundMethod->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3382 | diag::note_odr_objc_method_here) |
| 3383 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3384 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3385 | } |
| 3386 | |
| 3387 | // FIXME: Any other bits we need to merge? |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3388 | return Importer.MapImported(D, FoundMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3389 | } |
| 3390 | } |
| 3391 | |
| 3392 | // Import the result type. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3393 | QualType ResultTy = Importer.Import(D->getReturnType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3394 | if (ResultTy.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3395 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3396 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3397 | TypeSourceInfo *ReturnTInfo = Importer.Import(D->getReturnTypeSourceInfo()); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3398 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3399 | ObjCMethodDecl *ToMethod; |
| 3400 | if (GetImportedOrCreateDecl( |
| 3401 | ToMethod, D, Importer.getToContext(), Loc, |
| 3402 | Importer.Import(D->getLocEnd()), Name.getObjCSelector(), ResultTy, |
| 3403 | ReturnTInfo, DC, D->isInstanceMethod(), D->isVariadic(), |
| 3404 | D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3405 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 3406 | return ToMethod; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3407 | |
| 3408 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3409 | // deal with implicit parameters. |
| 3410 | |
| 3411 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3412 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3413 | for (auto *FromP : D->parameters()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3414 | auto *ToP = cast_or_null<ParmVarDecl>(Importer.Import(FromP)); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3415 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3416 | return nullptr; |
| 3417 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3418 | ToParams.push_back(ToP); |
| 3419 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3420 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3421 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3422 | for (auto *ToParam : ToParams) { |
| 3423 | ToParam->setOwningFunction(ToMethod); |
| 3424 | ToMethod->addDeclInternal(ToParam); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3425 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3426 | |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 3427 | SmallVector<SourceLocation, 12> SelLocs; |
| 3428 | D->getSelectorLocs(SelLocs); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3429 | for (auto &Loc : SelLocs) |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3430 | Loc = Importer.Import(Loc); |
| 3431 | |
| 3432 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, SelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3433 | |
| 3434 | ToMethod->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3435 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3436 | return ToMethod; |
| 3437 | } |
| 3438 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3439 | Decl *ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| 3440 | // Import the major distinguishing characteristics of a category. |
| 3441 | DeclContext *DC, *LexicalDC; |
| 3442 | DeclarationName Name; |
| 3443 | SourceLocation Loc; |
| 3444 | NamedDecl *ToD; |
| 3445 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3446 | return nullptr; |
| 3447 | if (ToD) |
| 3448 | return ToD; |
| 3449 | |
| 3450 | TypeSourceInfo *BoundInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3451 | if (!BoundInfo) |
| 3452 | return nullptr; |
| 3453 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3454 | ObjCTypeParamDecl *Result; |
| 3455 | if (GetImportedOrCreateDecl( |
| 3456 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
| 3457 | Importer.Import(D->getVarianceLoc()), D->getIndex(), |
| 3458 | Importer.Import(D->getLocation()), Name.getAsIdentifierInfo(), |
| 3459 | Importer.Import(D->getColonLoc()), BoundInfo)) |
| 3460 | return Result; |
| 3461 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3462 | Result->setLexicalDeclContext(LexicalDC); |
| 3463 | return Result; |
| 3464 | } |
| 3465 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3466 | Decl *ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| 3467 | // Import the major distinguishing characteristics of a category. |
| 3468 | DeclContext *DC, *LexicalDC; |
| 3469 | DeclarationName Name; |
| 3470 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3471 | NamedDecl *ToD; |
| 3472 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3473 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3474 | if (ToD) |
| 3475 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3476 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3477 | auto *ToInterface = |
| 3478 | cast_or_null<ObjCInterfaceDecl>(Importer.Import(D->getClassInterface())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3479 | if (!ToInterface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3480 | return nullptr; |
| 3481 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3482 | // Determine if we've already encountered this category. |
| 3483 | ObjCCategoryDecl *MergeWithCategory |
| 3484 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3485 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3486 | if (!ToCategory) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3487 | |
| 3488 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
| 3489 | Importer.Import(D->getAtStartLoc()), Loc, |
| 3490 | Importer.Import(D->getCategoryNameLoc()), |
| 3491 | Name.getAsIdentifierInfo(), ToInterface, |
| 3492 | /*TypeParamList=*/nullptr, |
| 3493 | Importer.Import(D->getIvarLBraceLoc()), |
| 3494 | Importer.Import(D->getIvarRBraceLoc()))) |
| 3495 | return ToCategory; |
| 3496 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3497 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3498 | LexicalDC->addDeclInternal(ToCategory); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3499 | // Import the type parameter list after calling Imported, to avoid |
| 3500 | // loops when bringing in their DeclContext. |
| 3501 | ToCategory->setTypeParamList(ImportObjCTypeParamList( |
| 3502 | D->getTypeParamList())); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3503 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3504 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3505 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3506 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3507 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 3508 | = D->protocol_loc_begin(); |
| 3509 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 3510 | FromProtoEnd = D->protocol_end(); |
| 3511 | FromProto != FromProtoEnd; |
| 3512 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3513 | auto *ToProto = |
| 3514 | cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3515 | if (!ToProto) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3516 | return nullptr; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3517 | Protocols.push_back(ToProto); |
| 3518 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3519 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3520 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3521 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3522 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 3523 | ProtocolLocs.data(), Importer.getToContext()); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3524 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3525 | Importer.MapImported(D, ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3526 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3527 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3528 | // Import all of the members of this category. |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 3529 | ImportDeclContext(D); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3530 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3531 | // If we have an implementation, import it as well. |
| 3532 | if (D->getImplementation()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3533 | auto *Impl = |
| 3534 | cast_or_null<ObjCCategoryImplDecl>( |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3535 | Importer.Import(D->getImplementation())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3536 | if (!Impl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3537 | return nullptr; |
| 3538 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3539 | ToCategory->setImplementation(Impl); |
| 3540 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3541 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3542 | return ToCategory; |
| 3543 | } |
| 3544 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3545 | bool ASTNodeImporter::ImportDefinition(ObjCProtocolDecl *From, |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3546 | ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3547 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3548 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3549 | if (shouldForceImportDeclContext(Kind)) |
| 3550 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3551 | return false; |
| 3552 | } |
| 3553 | |
| 3554 | // Start the protocol definition |
| 3555 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3556 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3557 | // Import protocols |
| 3558 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3559 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3560 | ObjCProtocolDecl::protocol_loc_iterator |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3561 | FromProtoLoc = From->protocol_loc_begin(); |
| 3562 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3563 | FromProtoEnd = From->protocol_end(); |
| 3564 | FromProto != FromProtoEnd; |
| 3565 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3566 | auto *ToProto = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3567 | if (!ToProto) |
| 3568 | return true; |
| 3569 | Protocols.push_back(ToProto); |
| 3570 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3571 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3572 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3573 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3574 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3575 | ProtocolLocs.data(), Importer.getToContext()); |
| 3576 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3577 | if (shouldForceImportDeclContext(Kind)) { |
| 3578 | // Import all of the members of this protocol. |
| 3579 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3580 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3581 | return false; |
| 3582 | } |
| 3583 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3584 | Decl *ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3585 | // If this protocol has a definition in the translation unit we're coming |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3586 | // from, but this particular declaration is not that definition, import the |
| 3587 | // definition and map to that. |
| 3588 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 3589 | if (Definition && Definition != D) { |
| 3590 | Decl *ImportedDef = Importer.Import(Definition); |
| 3591 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3592 | return nullptr; |
| 3593 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3594 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3595 | } |
| 3596 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3597 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3598 | DeclContext *DC, *LexicalDC; |
| 3599 | DeclarationName Name; |
| 3600 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3601 | NamedDecl *ToD; |
| 3602 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3603 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3604 | if (ToD) |
| 3605 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3606 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3607 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3608 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3609 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3610 | for (auto *FoundDecl : FoundDecls) { |
| 3611 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3612 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3613 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3614 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3615 | break; |
| 3616 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3617 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3618 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3619 | if (!ToProto) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3620 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 3621 | Name.getAsIdentifierInfo(), Loc, |
| 3622 | Importer.Import(D->getAtStartLoc()), |
| 3623 | /*PrevDecl=*/nullptr)) |
| 3624 | return ToProto; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3625 | ToProto->setLexicalDeclContext(LexicalDC); |
| 3626 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3627 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3628 | |
| 3629 | Importer.MapImported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3630 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3631 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToProto)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3632 | return nullptr; |
| 3633 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3634 | return ToProto; |
| 3635 | } |
| 3636 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3637 | Decl *ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 3638 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3639 | DeclContext *LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3640 | |
| 3641 | SourceLocation ExternLoc = Importer.Import(D->getExternLoc()); |
| 3642 | SourceLocation LangLoc = Importer.Import(D->getLocation()); |
| 3643 | |
| 3644 | bool HasBraces = D->hasBraces(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3645 | |
| 3646 | LinkageSpecDecl *ToLinkageSpec; |
| 3647 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
| 3648 | ExternLoc, LangLoc, D->getLanguage(), HasBraces)) |
| 3649 | return ToLinkageSpec; |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3650 | |
| 3651 | if (HasBraces) { |
| 3652 | SourceLocation RBraceLoc = Importer.Import(D->getRBraceLoc()); |
| 3653 | ToLinkageSpec->setRBraceLoc(RBraceLoc); |
| 3654 | } |
| 3655 | |
| 3656 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 3657 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 3658 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3659 | return ToLinkageSpec; |
| 3660 | } |
| 3661 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3662 | Decl *ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
| 3663 | DeclContext *DC, *LexicalDC; |
| 3664 | DeclarationName Name; |
| 3665 | SourceLocation Loc; |
| 3666 | NamedDecl *ToD = nullptr; |
| 3667 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3668 | return nullptr; |
| 3669 | if (ToD) |
| 3670 | return ToD; |
| 3671 | |
| 3672 | DeclarationNameInfo NameInfo(Name, |
| 3673 | Importer.Import(D->getNameInfo().getLoc())); |
| 3674 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3675 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3676 | UsingDecl *ToUsing; |
| 3677 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| 3678 | Importer.Import(D->getUsingLoc()), |
| 3679 | Importer.Import(D->getQualifierLoc()), NameInfo, |
| 3680 | D->hasTypename())) |
| 3681 | return ToUsing; |
| 3682 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3683 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3684 | LexicalDC->addDeclInternal(ToUsing); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3685 | |
| 3686 | if (NamedDecl *FromPattern = |
| 3687 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3688 | if (auto *ToPattern = |
| 3689 | dyn_cast_or_null<NamedDecl>(Importer.Import(FromPattern))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3690 | Importer.getToContext().setInstantiatedFromUsingDecl(ToUsing, ToPattern); |
| 3691 | else |
| 3692 | return nullptr; |
| 3693 | } |
| 3694 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3695 | for (auto *FromShadow : D->shadows()) { |
| 3696 | if (auto *ToShadow = |
| 3697 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromShadow))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3698 | ToUsing->addShadowDecl(ToShadow); |
| 3699 | else |
| 3700 | // FIXME: We return a nullptr here but the definition is already created |
| 3701 | // and available with lookups. How to fix this?.. |
| 3702 | return nullptr; |
| 3703 | } |
| 3704 | return ToUsing; |
| 3705 | } |
| 3706 | |
| 3707 | Decl *ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| 3708 | DeclContext *DC, *LexicalDC; |
| 3709 | DeclarationName Name; |
| 3710 | SourceLocation Loc; |
| 3711 | NamedDecl *ToD = nullptr; |
| 3712 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3713 | return nullptr; |
| 3714 | if (ToD) |
| 3715 | return ToD; |
| 3716 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3717 | auto *ToUsing = dyn_cast_or_null<UsingDecl>( |
| 3718 | Importer.Import(D->getUsingDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3719 | if (!ToUsing) |
| 3720 | return nullptr; |
| 3721 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3722 | auto *ToTarget = dyn_cast_or_null<NamedDecl>( |
| 3723 | Importer.Import(D->getTargetDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3724 | if (!ToTarget) |
| 3725 | return nullptr; |
| 3726 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3727 | UsingShadowDecl *ToShadow; |
| 3728 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
| 3729 | ToUsing, ToTarget)) |
| 3730 | return ToShadow; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3731 | |
| 3732 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 3733 | ToShadow->setAccess(D->getAccess()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3734 | |
| 3735 | if (UsingShadowDecl *FromPattern = |
| 3736 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3737 | if (auto *ToPattern = |
| 3738 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromPattern))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3739 | Importer.getToContext().setInstantiatedFromUsingShadowDecl(ToShadow, |
| 3740 | ToPattern); |
| 3741 | else |
| 3742 | // FIXME: We return a nullptr here but the definition is already created |
| 3743 | // and available with lookups. How to fix this?.. |
| 3744 | return nullptr; |
| 3745 | } |
| 3746 | |
| 3747 | LexicalDC->addDeclInternal(ToShadow); |
| 3748 | |
| 3749 | return ToShadow; |
| 3750 | } |
| 3751 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3752 | Decl *ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 3753 | DeclContext *DC, *LexicalDC; |
| 3754 | DeclarationName Name; |
| 3755 | SourceLocation Loc; |
| 3756 | NamedDecl *ToD = nullptr; |
| 3757 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3758 | return nullptr; |
| 3759 | if (ToD) |
| 3760 | return ToD; |
| 3761 | |
| 3762 | DeclContext *ToComAncestor = Importer.ImportContext(D->getCommonAncestor()); |
| 3763 | if (!ToComAncestor) |
| 3764 | return nullptr; |
| 3765 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3766 | auto *ToNominated = cast_or_null<NamespaceDecl>( |
| 3767 | Importer.Import(D->getNominatedNamespace())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3768 | if (!ToNominated) |
| 3769 | return nullptr; |
| 3770 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3771 | UsingDirectiveDecl *ToUsingDir; |
| 3772 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
| 3773 | Importer.Import(D->getUsingLoc()), |
| 3774 | Importer.Import(D->getNamespaceKeyLocation()), |
| 3775 | Importer.Import(D->getQualifierLoc()), |
| 3776 | Importer.Import(D->getIdentLocation()), |
| 3777 | ToNominated, ToComAncestor)) |
| 3778 | return ToUsingDir; |
| 3779 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3780 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 3781 | LexicalDC->addDeclInternal(ToUsingDir); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3782 | |
| 3783 | return ToUsingDir; |
| 3784 | } |
| 3785 | |
| 3786 | Decl *ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
| 3787 | UnresolvedUsingValueDecl *D) { |
| 3788 | DeclContext *DC, *LexicalDC; |
| 3789 | DeclarationName Name; |
| 3790 | SourceLocation Loc; |
| 3791 | NamedDecl *ToD = nullptr; |
| 3792 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3793 | return nullptr; |
| 3794 | if (ToD) |
| 3795 | return ToD; |
| 3796 | |
| 3797 | DeclarationNameInfo NameInfo(Name, Importer.Import(D->getNameInfo().getLoc())); |
| 3798 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3799 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3800 | UnresolvedUsingValueDecl *ToUsingValue; |
| 3801 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
| 3802 | Importer.Import(D->getUsingLoc()), |
| 3803 | Importer.Import(D->getQualifierLoc()), NameInfo, |
| 3804 | Importer.Import(D->getEllipsisLoc()))) |
| 3805 | return ToUsingValue; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3806 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3807 | ToUsingValue->setAccess(D->getAccess()); |
| 3808 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 3809 | LexicalDC->addDeclInternal(ToUsingValue); |
| 3810 | |
| 3811 | return ToUsingValue; |
| 3812 | } |
| 3813 | |
| 3814 | Decl *ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
| 3815 | UnresolvedUsingTypenameDecl *D) { |
| 3816 | DeclContext *DC, *LexicalDC; |
| 3817 | DeclarationName Name; |
| 3818 | SourceLocation Loc; |
| 3819 | NamedDecl *ToD = nullptr; |
| 3820 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3821 | return nullptr; |
| 3822 | if (ToD) |
| 3823 | return ToD; |
| 3824 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3825 | UnresolvedUsingTypenameDecl *ToUsing; |
| 3826 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| 3827 | Importer.Import(D->getUsingLoc()), |
| 3828 | Importer.Import(D->getTypenameLoc()), |
| 3829 | Importer.Import(D->getQualifierLoc()), Loc, Name, |
| 3830 | Importer.Import(D->getEllipsisLoc()))) |
| 3831 | return ToUsing; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3832 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3833 | ToUsing->setAccess(D->getAccess()); |
| 3834 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3835 | LexicalDC->addDeclInternal(ToUsing); |
| 3836 | |
| 3837 | return ToUsing; |
| 3838 | } |
| 3839 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3840 | bool ASTNodeImporter::ImportDefinition(ObjCInterfaceDecl *From, |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3841 | ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3842 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3843 | if (To->getDefinition()) { |
| 3844 | // Check consistency of superclass. |
| 3845 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 3846 | if (FromSuper) { |
| 3847 | FromSuper = cast_or_null<ObjCInterfaceDecl>(Importer.Import(FromSuper)); |
| 3848 | if (!FromSuper) |
| 3849 | return true; |
| 3850 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3851 | |
| 3852 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3853 | if ((bool)FromSuper != (bool)ToSuper || |
| 3854 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3855 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3856 | diag::err_odr_objc_superclass_inconsistent) |
| 3857 | << To->getDeclName(); |
| 3858 | if (ToSuper) |
| 3859 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 3860 | << To->getSuperClass()->getDeclName(); |
| 3861 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3862 | Importer.ToDiag(To->getLocation(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3863 | diag::note_odr_objc_missing_superclass); |
| 3864 | if (From->getSuperClass()) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3865 | Importer.FromDiag(From->getSuperClassLoc(), |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3866 | diag::note_odr_objc_superclass) |
| 3867 | << From->getSuperClass()->getDeclName(); |
| 3868 | else |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3869 | Importer.FromDiag(From->getLocation(), |
| 3870 | diag::note_odr_objc_missing_superclass); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3871 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3872 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3873 | if (shouldForceImportDeclContext(Kind)) |
| 3874 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3875 | return false; |
| 3876 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3877 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3878 | // Start the definition. |
| 3879 | To->startDefinition(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3880 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3881 | // If this class has a superclass, import it. |
| 3882 | if (From->getSuperClass()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3883 | TypeSourceInfo *SuperTInfo = Importer.Import(From->getSuperClassTInfo()); |
| 3884 | if (!SuperTInfo) |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3885 | return true; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3886 | |
| 3887 | To->setSuperClass(SuperTInfo); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3888 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3889 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3890 | // Import protocols |
| 3891 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3892 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3893 | ObjCInterfaceDecl::protocol_loc_iterator |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3894 | FromProtoLoc = From->protocol_loc_begin(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3895 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3896 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3897 | FromProtoEnd = From->protocol_end(); |
| 3898 | FromProto != FromProtoEnd; |
| 3899 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3900 | auto *ToProto = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3901 | if (!ToProto) |
| 3902 | return true; |
| 3903 | Protocols.push_back(ToProto); |
| 3904 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3905 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3906 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3907 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3908 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3909 | ProtocolLocs.data(), Importer.getToContext()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3910 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3911 | // Import categories. When the categories themselves are imported, they'll |
| 3912 | // hook themselves into this interface. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 3913 | for (auto *Cat : From->known_categories()) |
| 3914 | Importer.Import(Cat); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3915 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3916 | // If we have an @implementation, import it as well. |
| 3917 | if (From->getImplementation()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3918 | auto *Impl = cast_or_null<ObjCImplementationDecl>( |
| 3919 | Importer.Import(From->getImplementation())); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3920 | if (!Impl) |
| 3921 | return true; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3922 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3923 | To->setImplementation(Impl); |
| 3924 | } |
| 3925 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3926 | if (shouldForceImportDeclContext(Kind)) { |
| 3927 | // Import all of the members of this class. |
| 3928 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3929 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3930 | return false; |
| 3931 | } |
| 3932 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3933 | ObjCTypeParamList * |
| 3934 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 3935 | if (!list) |
| 3936 | return nullptr; |
| 3937 | |
| 3938 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
| 3939 | for (auto fromTypeParam : *list) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3940 | auto *toTypeParam = cast_or_null<ObjCTypeParamDecl>( |
| 3941 | Importer.Import(fromTypeParam)); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3942 | if (!toTypeParam) |
| 3943 | return nullptr; |
| 3944 | |
| 3945 | toTypeParams.push_back(toTypeParam); |
| 3946 | } |
| 3947 | |
| 3948 | return ObjCTypeParamList::create(Importer.getToContext(), |
| 3949 | Importer.Import(list->getLAngleLoc()), |
| 3950 | toTypeParams, |
| 3951 | Importer.Import(list->getRAngleLoc())); |
| 3952 | } |
| 3953 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3954 | Decl *ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3955 | // If this class has a definition in the translation unit we're coming from, |
| 3956 | // but this particular declaration is not that definition, import the |
| 3957 | // definition and map to that. |
| 3958 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 3959 | if (Definition && Definition != D) { |
| 3960 | Decl *ImportedDef = Importer.Import(Definition); |
| 3961 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3962 | return nullptr; |
| 3963 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3964 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3965 | } |
| 3966 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3967 | // Import the major distinguishing characteristics of an @interface. |
| 3968 | DeclContext *DC, *LexicalDC; |
| 3969 | DeclarationName Name; |
| 3970 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3971 | NamedDecl *ToD; |
| 3972 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3973 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3974 | if (ToD) |
| 3975 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3976 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3977 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3978 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3979 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3980 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3981 | for (auto *FoundDecl : FoundDecls) { |
| 3982 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3983 | continue; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3984 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3985 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3986 | break; |
| 3987 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3988 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3989 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3990 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3991 | if (!ToIface) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3992 | if (GetImportedOrCreateDecl( |
| 3993 | ToIface, D, Importer.getToContext(), DC, |
| 3994 | Importer.Import(D->getAtStartLoc()), Name.getAsIdentifierInfo(), |
| 3995 | /*TypeParamList=*/nullptr, |
| 3996 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 3997 | return ToIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3998 | ToIface->setLexicalDeclContext(LexicalDC); |
| 3999 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4000 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4001 | Importer.MapImported(D, ToIface); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 4002 | // Import the type parameter list after calling Imported, to avoid |
| 4003 | // loops when bringing in their DeclContext. |
| 4004 | ToIface->setTypeParamList(ImportObjCTypeParamList( |
| 4005 | D->getTypeParamListAsWritten())); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4006 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4007 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToIface)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4008 | return nullptr; |
| 4009 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4010 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4011 | } |
| 4012 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4013 | Decl *ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4014 | auto *Category = cast_or_null<ObjCCategoryDecl>( |
| 4015 | Importer.Import(D->getCategoryDecl())); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4016 | if (!Category) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4017 | return nullptr; |
| 4018 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4019 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4020 | if (!ToImpl) { |
| 4021 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 4022 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4023 | return nullptr; |
| 4024 | |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 4025 | SourceLocation CategoryNameLoc = Importer.Import(D->getCategoryNameLoc()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4026 | if (GetImportedOrCreateDecl( |
| 4027 | ToImpl, D, Importer.getToContext(), DC, |
| 4028 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
| 4029 | Importer.Import(D->getLocation()), |
| 4030 | Importer.Import(D->getAtStartLoc()), CategoryNameLoc)) |
| 4031 | return ToImpl; |
| 4032 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4033 | DeclContext *LexicalDC = DC; |
| 4034 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4035 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4036 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4037 | return nullptr; |
| 4038 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4039 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 4040 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4041 | |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4042 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4043 | Category->setImplementation(ToImpl); |
| 4044 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4045 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4046 | Importer.MapImported(D, ToImpl); |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 4047 | ImportDeclContext(D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4048 | return ToImpl; |
| 4049 | } |
| 4050 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4051 | Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 4052 | // Find the corresponding interface. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4053 | auto *Iface = cast_or_null<ObjCInterfaceDecl>( |
| 4054 | Importer.Import(D->getClassInterface())); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4055 | if (!Iface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4056 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4057 | |
| 4058 | // Import the superclass, if any. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4059 | ObjCInterfaceDecl *Super = nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4060 | if (D->getSuperClass()) { |
| 4061 | Super = cast_or_null<ObjCInterfaceDecl>( |
| 4062 | Importer.Import(D->getSuperClass())); |
| 4063 | if (!Super) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4064 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4068 | if (!Impl) { |
| 4069 | // We haven't imported an implementation yet. Create a new @implementation |
| 4070 | // now. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4071 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
| 4072 | Importer.ImportContext(D->getDeclContext()), |
| 4073 | Iface, Super, Importer.Import(D->getLocation()), |
| 4074 | Importer.Import(D->getAtStartLoc()), |
| 4075 | Importer.Import(D->getSuperClassLoc()), |
| 4076 | Importer.Import(D->getIvarLBraceLoc()), |
| 4077 | Importer.Import(D->getIvarRBraceLoc()))) |
| 4078 | return Impl; |
| 4079 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4080 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4081 | DeclContext *LexicalDC |
| 4082 | = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4083 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4084 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4085 | Impl->setLexicalDeclContext(LexicalDC); |
| 4086 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4087 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4088 | // Associate the implementation with the class it implements. |
| 4089 | Iface->setImplementation(Impl); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4090 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4091 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4092 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4093 | |
| 4094 | // Verify that the existing @implementation has the same superclass. |
| 4095 | if ((Super && !Impl->getSuperClass()) || |
| 4096 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4097 | (Super && Impl->getSuperClass() && |
| 4098 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4099 | Impl->getSuperClass()))) { |
| 4100 | Importer.ToDiag(Impl->getLocation(), |
| 4101 | diag::err_odr_objc_superclass_inconsistent) |
| 4102 | << Iface->getDeclName(); |
| 4103 | // FIXME: It would be nice to have the location of the superclass |
| 4104 | // below. |
| 4105 | if (Impl->getSuperClass()) |
| 4106 | Importer.ToDiag(Impl->getLocation(), |
| 4107 | diag::note_odr_objc_superclass) |
| 4108 | << Impl->getSuperClass()->getDeclName(); |
| 4109 | else |
| 4110 | Importer.ToDiag(Impl->getLocation(), |
| 4111 | diag::note_odr_objc_missing_superclass); |
| 4112 | if (D->getSuperClass()) |
| 4113 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4114 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4115 | << D->getSuperClass()->getDeclName(); |
| 4116 | else |
| 4117 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4118 | diag::note_odr_objc_missing_superclass); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4119 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4120 | } |
| 4121 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4122 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4123 | // Import all of the members of this @implementation. |
| 4124 | ImportDeclContext(D); |
| 4125 | |
| 4126 | return Impl; |
| 4127 | } |
| 4128 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4129 | Decl *ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 4130 | // Import the major distinguishing characteristics of an @property. |
| 4131 | DeclContext *DC, *LexicalDC; |
| 4132 | DeclarationName Name; |
| 4133 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4134 | NamedDecl *ToD; |
| 4135 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4136 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4137 | if (ToD) |
| 4138 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4139 | |
| 4140 | // Check whether we have already imported this property. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4141 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4142 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4143 | for (auto *FoundDecl : FoundDecls) { |
| 4144 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4145 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4146 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4147 | FoundProp->getType())) { |
| 4148 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) |
| 4149 | << Name << D->getType() << FoundProp->getType(); |
| 4150 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4151 | << FoundProp->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4152 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4153 | } |
| 4154 | |
| 4155 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4156 | |
| 4157 | // Consider these properties to be equivalent. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4158 | Importer.MapImported(D, FoundProp); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4159 | return FoundProp; |
| 4160 | } |
| 4161 | } |
| 4162 | |
| 4163 | // Import the type. |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 4164 | TypeSourceInfo *TSI = Importer.Import(D->getTypeSourceInfo()); |
| 4165 | if (!TSI) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4166 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4167 | |
| 4168 | // Create the new property. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4169 | ObjCPropertyDecl *ToProperty; |
| 4170 | if (GetImportedOrCreateDecl( |
| 4171 | ToProperty, D, Importer.getToContext(), DC, Loc, |
| 4172 | Name.getAsIdentifierInfo(), Importer.Import(D->getAtLoc()), |
| 4173 | Importer.Import(D->getLParenLoc()), Importer.Import(D->getType()), |
| 4174 | TSI, D->getPropertyImplementation())) |
| 4175 | return ToProperty; |
| 4176 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4177 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4178 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4179 | |
| 4180 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4181 | ToProperty->setPropertyAttributesAsWritten( |
| 4182 | D->getPropertyAttributesAsWritten()); |
Argyrios Kyrtzidis | 194b28e | 2017-03-16 18:25:40 +0000 | [diff] [blame] | 4183 | ToProperty->setGetterName(Importer.Import(D->getGetterName()), |
| 4184 | Importer.Import(D->getGetterNameLoc())); |
| 4185 | ToProperty->setSetterName(Importer.Import(D->getSetterName()), |
| 4186 | Importer.Import(D->getSetterNameLoc())); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4187 | ToProperty->setGetterMethodDecl( |
| 4188 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getGetterMethodDecl()))); |
| 4189 | ToProperty->setSetterMethodDecl( |
| 4190 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getSetterMethodDecl()))); |
| 4191 | ToProperty->setPropertyIvarDecl( |
| 4192 | cast_or_null<ObjCIvarDecl>(Importer.Import(D->getPropertyIvarDecl()))); |
| 4193 | return ToProperty; |
| 4194 | } |
| 4195 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4196 | Decl *ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4197 | auto *Property = cast_or_null<ObjCPropertyDecl>( |
| 4198 | Importer.Import(D->getPropertyDecl())); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4199 | if (!Property) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4200 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4201 | |
| 4202 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 4203 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4204 | return nullptr; |
| 4205 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4206 | // Import the lexical declaration context. |
| 4207 | DeclContext *LexicalDC = DC; |
| 4208 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4209 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4210 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4211 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4212 | } |
| 4213 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4214 | auto *InImpl = dyn_cast<ObjCImplDecl>(LexicalDC); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4215 | if (!InImpl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4216 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4217 | |
| 4218 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4219 | ObjCIvarDecl *Ivar = nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4220 | if (D->getPropertyIvarDecl()) { |
| 4221 | Ivar = cast_or_null<ObjCIvarDecl>( |
| 4222 | Importer.Import(D->getPropertyIvarDecl())); |
| 4223 | if (!Ivar) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4224 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4225 | } |
| 4226 | |
| 4227 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 4228 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 4229 | Property->getQueryKind()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4230 | if (!ToImpl) { |
| 4231 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
| 4232 | Importer.Import(D->getLocStart()), |
| 4233 | Importer.Import(D->getLocation()), Property, |
| 4234 | D->getPropertyImplementation(), Ivar, |
| 4235 | Importer.Import(D->getPropertyIvarDeclLoc()))) |
| 4236 | return ToImpl; |
| 4237 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4238 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4239 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4240 | } else { |
| 4241 | // Check that we have the same kind of property implementation (@synthesize |
| 4242 | // vs. @dynamic). |
| 4243 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4244 | Importer.ToDiag(ToImpl->getLocation(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4245 | diag::err_odr_objc_property_impl_kind_inconsistent) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4246 | << Property->getDeclName() |
| 4247 | << (ToImpl->getPropertyImplementation() |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4248 | == ObjCPropertyImplDecl::Dynamic); |
| 4249 | Importer.FromDiag(D->getLocation(), |
| 4250 | diag::note_odr_objc_property_impl_kind) |
| 4251 | << D->getPropertyDecl()->getDeclName() |
| 4252 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4253 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4254 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4255 | |
| 4256 | // For @synthesize, check that we have the same |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4257 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 4258 | Ivar != ToImpl->getPropertyIvarDecl()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4259 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4260 | diag::err_odr_objc_synthesize_ivar_inconsistent) |
| 4261 | << Property->getDeclName() |
| 4262 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 4263 | << Ivar->getDeclName(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4264 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4265 | diag::note_odr_objc_synthesize_ivar_here) |
| 4266 | << D->getPropertyIvarDecl()->getDeclName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4267 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4268 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4269 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4270 | // Merge the existing implementation with the new implementation. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4271 | Importer.MapImported(D, ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4272 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4273 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4274 | return ToImpl; |
| 4275 | } |
| 4276 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4277 | Decl *ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 4278 | // For template arguments, we adopt the translation unit as our declaration |
| 4279 | // context. This context will be fixed when the actual template declaration |
| 4280 | // is created. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4281 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4282 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4283 | TemplateTypeParmDecl *ToD = nullptr; |
| 4284 | (void)GetImportedOrCreateDecl( |
| 4285 | ToD, D, Importer.getToContext(), |
| 4286 | Importer.getToContext().getTranslationUnitDecl(), |
| 4287 | Importer.Import(D->getLocStart()), Importer.Import(D->getLocation()), |
| 4288 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| 4289 | D->wasDeclaredWithTypename(), D->isParameterPack()); |
| 4290 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4291 | } |
| 4292 | |
| 4293 | Decl * |
| 4294 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 4295 | // Import the name of this declaration. |
| 4296 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 4297 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4298 | return nullptr; |
| 4299 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4300 | // Import the location of this declaration. |
| 4301 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 4302 | |
| 4303 | // Import the type of this declaration. |
| 4304 | QualType T = Importer.Import(D->getType()); |
| 4305 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4306 | return nullptr; |
| 4307 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4308 | // Import type-source information. |
| 4309 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 4310 | if (D->getTypeSourceInfo() && !TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4311 | return nullptr; |
| 4312 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4313 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4314 | |
| 4315 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 4316 | (void)GetImportedOrCreateDecl( |
| 4317 | ToD, D, Importer.getToContext(), |
| 4318 | Importer.getToContext().getTranslationUnitDecl(), |
| 4319 | Importer.Import(D->getInnerLocStart()), Loc, D->getDepth(), |
| 4320 | D->getPosition(), Name.getAsIdentifierInfo(), T, D->isParameterPack(), |
| 4321 | TInfo); |
| 4322 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4323 | } |
| 4324 | |
| 4325 | Decl * |
| 4326 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 4327 | // Import the name of this declaration. |
| 4328 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 4329 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4330 | return nullptr; |
| 4331 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4332 | // Import the location of this declaration. |
| 4333 | SourceLocation Loc = Importer.Import(D->getLocation()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4334 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4335 | // Import template parameters. |
| 4336 | TemplateParameterList *TemplateParams |
| 4337 | = ImportTemplateParameterList(D->getTemplateParameters()); |
| 4338 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4339 | return nullptr; |
| 4340 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4341 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4342 | |
| 4343 | TemplateTemplateParmDecl *ToD = nullptr; |
| 4344 | (void)GetImportedOrCreateDecl( |
| 4345 | ToD, D, Importer.getToContext(), |
| 4346 | Importer.getToContext().getTranslationUnitDecl(), Loc, D->getDepth(), |
| 4347 | D->getPosition(), D->isParameterPack(), Name.getAsIdentifierInfo(), |
| 4348 | TemplateParams); |
| 4349 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4350 | } |
| 4351 | |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4352 | // Returns the definition for a (forward) declaration of a ClassTemplateDecl, if |
| 4353 | // it has any definition in the redecl chain. |
| 4354 | static ClassTemplateDecl *getDefinition(ClassTemplateDecl *D) { |
| 4355 | CXXRecordDecl *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| 4356 | if (!ToTemplatedDef) |
| 4357 | return nullptr; |
| 4358 | ClassTemplateDecl *TemplateWithDef = |
| 4359 | ToTemplatedDef->getDescribedClassTemplate(); |
| 4360 | return TemplateWithDef; |
| 4361 | } |
| 4362 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4363 | Decl *ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 4364 | // If this record has a definition in the translation unit we're coming from, |
| 4365 | // but this particular declaration is not that definition, import the |
| 4366 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4367 | auto *Definition = |
| 4368 | cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4369 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 4370 | Decl *ImportedDef |
| 4371 | = Importer.Import(Definition->getDescribedClassTemplate()); |
| 4372 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4373 | return nullptr; |
| 4374 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4375 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4376 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4377 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4378 | // Import the major distinguishing characteristics of this class template. |
| 4379 | DeclContext *DC, *LexicalDC; |
| 4380 | DeclarationName Name; |
| 4381 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4382 | NamedDecl *ToD; |
| 4383 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4384 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4385 | if (ToD) |
| 4386 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4387 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4388 | // We may already have a template of the same name; try to find and match it. |
| 4389 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4390 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4391 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4392 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4393 | for (auto *FoundDecl : FoundDecls) { |
| 4394 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4395 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4396 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4397 | Decl *Found = FoundDecl; |
| 4398 | if (auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found)) { |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4399 | |
| 4400 | // The class to be imported is a definition. |
| 4401 | if (D->isThisDeclarationADefinition()) { |
| 4402 | // Lookup will find the fwd decl only if that is more recent than the |
| 4403 | // definition. So, try to get the definition if that is available in |
| 4404 | // the redecl chain. |
| 4405 | ClassTemplateDecl *TemplateWithDef = getDefinition(FoundTemplate); |
| 4406 | if (!TemplateWithDef) |
| 4407 | continue; |
| 4408 | FoundTemplate = TemplateWithDef; // Continue with the definition. |
| 4409 | } |
| 4410 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4411 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 4412 | // The class templates structurally match; call it the same template. |
Aleksei Sidorin | 761c224 | 2018-05-15 11:09:07 +0000 | [diff] [blame] | 4413 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4414 | Importer.MapImported(D->getTemplatedDecl(), |
| 4415 | FoundTemplate->getTemplatedDecl()); |
| 4416 | return Importer.MapImported(D, FoundTemplate); |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4417 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4418 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4419 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4420 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4421 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4422 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4423 | if (!ConflictingDecls.empty()) { |
| 4424 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4425 | ConflictingDecls.data(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4426 | ConflictingDecls.size()); |
| 4427 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4428 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4429 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4430 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4431 | } |
| 4432 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4433 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 4434 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4435 | // Create the declaration that is being templated. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4436 | auto *ToTemplated = cast_or_null<CXXRecordDecl>( |
| 4437 | Importer.Import(FromTemplated)); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4438 | if (!ToTemplated) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4439 | return nullptr; |
| 4440 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4441 | // Create the class template declaration itself. |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4442 | TemplateParameterList *TemplateParams = |
| 4443 | ImportTemplateParameterList(D->getTemplateParameters()); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4444 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4445 | return nullptr; |
| 4446 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4447 | ClassTemplateDecl *D2; |
| 4448 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
| 4449 | TemplateParams, ToTemplated)) |
| 4450 | return D2; |
| 4451 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4452 | ToTemplated->setDescribedClassTemplate(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4453 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4454 | D2->setAccess(D->getAccess()); |
| 4455 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4456 | LexicalDC->addDeclInternal(D2); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4457 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4458 | if (FromTemplated->isCompleteDefinition() && |
| 4459 | !ToTemplated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4460 | // FIXME: Import definition! |
| 4461 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4462 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4463 | return D2; |
| 4464 | } |
| 4465 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4466 | Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
| 4467 | ClassTemplateSpecializationDecl *D) { |
| 4468 | // If this record has a definition in the translation unit we're coming from, |
| 4469 | // but this particular declaration is not that definition, import the |
| 4470 | // definition and map to that. |
| 4471 | TagDecl *Definition = D->getDefinition(); |
| 4472 | if (Definition && Definition != D) { |
| 4473 | Decl *ImportedDef = Importer.Import(Definition); |
| 4474 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4475 | return nullptr; |
| 4476 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4477 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4478 | } |
| 4479 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4480 | auto *ClassTemplate = |
| 4481 | cast_or_null<ClassTemplateDecl>(Importer.Import( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4482 | D->getSpecializedTemplate())); |
| 4483 | if (!ClassTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4484 | return nullptr; |
| 4485 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4486 | // Import the context of this declaration. |
| 4487 | DeclContext *DC = ClassTemplate->getDeclContext(); |
| 4488 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4489 | return nullptr; |
| 4490 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4491 | DeclContext *LexicalDC = DC; |
| 4492 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4493 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4494 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4495 | return nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4496 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4497 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4498 | // Import the location of this declaration. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 4499 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 4500 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4501 | |
| 4502 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4503 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4504 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4505 | D->getTemplateArgs().size(), |
| 4506 | TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4507 | return nullptr; |
| 4508 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4509 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4510 | void *InsertPos = nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4511 | ClassTemplateSpecializationDecl *D2 |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 4512 | = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4513 | if (D2) { |
| 4514 | // We already have a class template specialization with these template |
| 4515 | // arguments. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4516 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4517 | // FIXME: Check for specialization vs. instantiation errors. |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4518 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4519 | if (RecordDecl *FoundDef = D2->getDefinition()) { |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4520 | if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4521 | // The record types structurally match, or the "from" translation |
| 4522 | // unit only had a forward declaration anyway; call it the same |
| 4523 | // function. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4524 | return Importer.MapImported(D, FoundDef); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4525 | } |
| 4526 | } |
| 4527 | } else { |
| 4528 | // Create a new specialization. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4529 | if (auto *PartialSpec = |
| 4530 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4531 | // Import TemplateArgumentListInfo |
| 4532 | TemplateArgumentListInfo ToTAInfo; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4533 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 4534 | if (ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4535 | return nullptr; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4536 | |
| 4537 | QualType CanonInjType = Importer.Import( |
| 4538 | PartialSpec->getInjectedSpecializationType()); |
| 4539 | if (CanonInjType.isNull()) |
| 4540 | return nullptr; |
| 4541 | CanonInjType = CanonInjType.getCanonicalType(); |
| 4542 | |
| 4543 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 4544 | PartialSpec->getTemplateParameters()); |
| 4545 | if (!ToTPList && PartialSpec->getTemplateParameters()) |
| 4546 | return nullptr; |
| 4547 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4548 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
| 4549 | D2, D, Importer.getToContext(), D->getTagKind(), DC, StartLoc, |
| 4550 | IdLoc, ToTPList, ClassTemplate, |
| 4551 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 4552 | ToTAInfo, CanonInjType, nullptr)) |
| 4553 | return D2; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4554 | |
| 4555 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4556 | if (GetImportedOrCreateDecl( |
| 4557 | D2, D, Importer.getToContext(), D->getTagKind(), DC, StartLoc, |
| 4558 | IdLoc, ClassTemplate, TemplateArgs, /*PrevDecl=*/nullptr)) |
| 4559 | return D2; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4560 | } |
| 4561 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4562 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 4563 | |
| 4564 | // Add this specialization to the class template. |
| 4565 | ClassTemplate->AddSpecialization(D2, InsertPos); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4566 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4567 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4568 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4569 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4570 | if (auto *TSI = D->getTypeAsWritten()) { |
| 4571 | TypeSourceInfo *TInfo = Importer.Import(TSI); |
| 4572 | if (!TInfo) |
| 4573 | return nullptr; |
| 4574 | D2->setTypeAsWritten(TInfo); |
| 4575 | D2->setTemplateKeywordLoc(Importer.Import(D->getTemplateKeywordLoc())); |
| 4576 | D2->setExternLoc(Importer.Import(D->getExternLoc())); |
| 4577 | } |
| 4578 | |
| 4579 | SourceLocation POI = Importer.Import(D->getPointOfInstantiation()); |
| 4580 | if (POI.isValid()) |
| 4581 | D2->setPointOfInstantiation(POI); |
| 4582 | else if (D->getPointOfInstantiation().isValid()) |
| 4583 | return nullptr; |
| 4584 | |
| 4585 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 4586 | |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 4587 | // Set the context of this specialization/instantiation. |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4588 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 4589 | |
| 4590 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 4591 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 4592 | LexicalDC->addDeclInternal(D2); |
| 4593 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4594 | } |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4595 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4596 | return nullptr; |
| 4597 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4598 | return D2; |
| 4599 | } |
| 4600 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4601 | Decl *ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| 4602 | // If this variable has a definition in the translation unit we're coming |
| 4603 | // from, |
| 4604 | // but this particular declaration is not that definition, import the |
| 4605 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4606 | auto *Definition = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4607 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 4608 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 4609 | Decl *ImportedDef = Importer.Import(Definition->getDescribedVarTemplate()); |
| 4610 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4611 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4612 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4613 | return Importer.MapImported(D, ImportedDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4614 | } |
| 4615 | |
| 4616 | // Import the major distinguishing characteristics of this variable template. |
| 4617 | DeclContext *DC, *LexicalDC; |
| 4618 | DeclarationName Name; |
| 4619 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4620 | NamedDecl *ToD; |
| 4621 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4622 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4623 | if (ToD) |
| 4624 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4625 | |
| 4626 | // We may already have a template of the same name; try to find and match it. |
| 4627 | assert(!DC->isFunctionOrMethod() && |
| 4628 | "Variable templates cannot be declared at function scope"); |
| 4629 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 4630 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4631 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4632 | for (auto *FoundDecl : FoundDecls) { |
| 4633 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4634 | continue; |
| 4635 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4636 | Decl *Found = FoundDecl; |
| 4637 | if (auto *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4638 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 4639 | // The variable templates structurally match; call it the same template. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4640 | Importer.MapImported(D->getTemplatedDecl(), |
| 4641 | FoundTemplate->getTemplatedDecl()); |
| 4642 | return Importer.MapImported(D, FoundTemplate); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4643 | } |
| 4644 | } |
| 4645 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4646 | ConflictingDecls.push_back(FoundDecl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | if (!ConflictingDecls.empty()) { |
| 4650 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 4651 | ConflictingDecls.data(), |
| 4652 | ConflictingDecls.size()); |
| 4653 | } |
| 4654 | |
| 4655 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4656 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4657 | |
| 4658 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 4659 | |
| 4660 | // Import the type. |
| 4661 | QualType T = Importer.Import(DTemplated->getType()); |
| 4662 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4663 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4664 | |
| 4665 | // Create the declaration that is being templated. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4666 | auto *ToTemplated = dyn_cast_or_null<VarDecl>(Importer.Import(DTemplated)); |
| 4667 | if (!ToTemplated) |
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 | // Create the variable template declaration itself. |
| 4671 | TemplateParameterList *TemplateParams = |
| 4672 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4673 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4674 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4675 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4676 | VarTemplateDecl *ToVarTD; |
| 4677 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
| 4678 | Name, TemplateParams, ToTemplated)) |
| 4679 | return ToVarTD; |
| 4680 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4681 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4682 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4683 | ToVarTD->setAccess(D->getAccess()); |
| 4684 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 4685 | LexicalDC->addDeclInternal(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4686 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4687 | if (DTemplated->isThisDeclarationADefinition() && |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4688 | !ToTemplated->isThisDeclarationADefinition()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4689 | // FIXME: Import definition! |
| 4690 | } |
| 4691 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4692 | return ToVarTD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4693 | } |
| 4694 | |
| 4695 | Decl *ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
| 4696 | VarTemplateSpecializationDecl *D) { |
| 4697 | // If this record has a definition in the translation unit we're coming from, |
| 4698 | // but this particular declaration is not that definition, import the |
| 4699 | // definition and map to that. |
| 4700 | VarDecl *Definition = D->getDefinition(); |
| 4701 | if (Definition && Definition != D) { |
| 4702 | Decl *ImportedDef = Importer.Import(Definition); |
| 4703 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4704 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4705 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4706 | return Importer.MapImported(D, ImportedDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4707 | } |
| 4708 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4709 | auto *VarTemplate = cast_or_null<VarTemplateDecl>( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4710 | Importer.Import(D->getSpecializedTemplate())); |
| 4711 | if (!VarTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4712 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4713 | |
| 4714 | // Import the context of this declaration. |
| 4715 | DeclContext *DC = VarTemplate->getDeclContext(); |
| 4716 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4717 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4718 | |
| 4719 | DeclContext *LexicalDC = DC; |
| 4720 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4721 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4722 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4723 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4724 | } |
| 4725 | |
| 4726 | // Import the location of this declaration. |
| 4727 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 4728 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
| 4729 | |
| 4730 | // Import template arguments. |
| 4731 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| 4732 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 4733 | D->getTemplateArgs().size(), TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4734 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4735 | |
| 4736 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4737 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4738 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 4739 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4740 | if (D2) { |
| 4741 | // We already have a variable template specialization with these template |
| 4742 | // arguments. |
| 4743 | |
| 4744 | // FIXME: Check for specialization vs. instantiation errors. |
| 4745 | |
| 4746 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 4747 | if (!D->isThisDeclarationADefinition() || |
| 4748 | IsStructuralMatch(D, FoundDef)) { |
| 4749 | // The record types structurally match, or the "from" translation |
| 4750 | // unit only had a forward declaration anyway; call it the same |
| 4751 | // variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4752 | return Importer.MapImported(D, FoundDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4753 | } |
| 4754 | } |
| 4755 | } else { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4756 | // Import the type. |
| 4757 | QualType T = Importer.Import(D->getType()); |
| 4758 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4759 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4760 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4761 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 4762 | if (D->getTypeSourceInfo() && !TInfo) |
| 4763 | return nullptr; |
| 4764 | |
| 4765 | TemplateArgumentListInfo ToTAInfo; |
| 4766 | if (ImportTemplateArgumentListInfo(D->getTemplateArgsInfo(), ToTAInfo)) |
| 4767 | return nullptr; |
| 4768 | |
| 4769 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4770 | // Create a new specialization. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4771 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 4772 | // Import TemplateArgumentListInfo |
| 4773 | TemplateArgumentListInfo ArgInfos; |
| 4774 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 4775 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
| 4776 | if (ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ArgInfos)) |
| 4777 | return nullptr; |
| 4778 | |
| 4779 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 4780 | FromPartial->getTemplateParameters()); |
| 4781 | if (!ToTPList) |
| 4782 | return nullptr; |
| 4783 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4784 | PartVarSpecDecl *ToPartial; |
| 4785 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
| 4786 | StartLoc, IdLoc, ToTPList, VarTemplate, T, |
| 4787 | TInfo, D->getStorageClass(), TemplateArgs, |
| 4788 | ArgInfos)) |
| 4789 | return ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4790 | |
| 4791 | auto *FromInst = FromPartial->getInstantiatedFromMember(); |
| 4792 | auto *ToInst = cast_or_null<PartVarSpecDecl>(Importer.Import(FromInst)); |
| 4793 | if (FromInst && !ToInst) |
| 4794 | return nullptr; |
| 4795 | |
| 4796 | ToPartial->setInstantiatedFromMember(ToInst); |
| 4797 | if (FromPartial->isMemberSpecialization()) |
| 4798 | ToPartial->setMemberSpecialization(); |
| 4799 | |
| 4800 | D2 = ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4801 | } else { // Full specialization |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4802 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, StartLoc, |
| 4803 | IdLoc, VarTemplate, T, TInfo, |
| 4804 | D->getStorageClass(), TemplateArgs)) |
| 4805 | return D2; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4806 | } |
| 4807 | |
| 4808 | SourceLocation POI = D->getPointOfInstantiation(); |
| 4809 | if (POI.isValid()) |
| 4810 | D2->setPointOfInstantiation(Importer.Import(POI)); |
| 4811 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4812 | D2->setSpecializationKind(D->getSpecializationKind()); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4813 | D2->setTemplateArgsInfo(ToTAInfo); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4814 | |
| 4815 | // Add this specialization to the class template. |
| 4816 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 4817 | |
| 4818 | // Import the qualifier, if any. |
| 4819 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
| 4820 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4821 | if (D->isConstexpr()) |
| 4822 | D2->setConstexpr(true); |
| 4823 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4824 | // Add the specialization to this context. |
| 4825 | D2->setLexicalDeclContext(LexicalDC); |
| 4826 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4827 | |
| 4828 | D2->setAccess(D->getAccess()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4829 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4830 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4831 | // NOTE: isThisDeclarationADefinition() can return DeclarationOnly even if |
| 4832 | // declaration has initializer. Should this be fixed in the AST?.. Anyway, |
| 4833 | // we have to check the declaration for initializer - otherwise, it won't be |
| 4834 | // imported. |
| 4835 | if ((D->isThisDeclarationADefinition() || D->hasInit()) && |
| 4836 | ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4837 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4838 | |
| 4839 | return D2; |
| 4840 | } |
| 4841 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4842 | Decl *ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 4843 | DeclContext *DC, *LexicalDC; |
| 4844 | DeclarationName Name; |
| 4845 | SourceLocation Loc; |
| 4846 | NamedDecl *ToD; |
| 4847 | |
| 4848 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4849 | return nullptr; |
| 4850 | |
| 4851 | if (ToD) |
| 4852 | return ToD; |
| 4853 | |
| 4854 | // Try to find a function in our own ("to") context with the same name, same |
| 4855 | // type, and in the same context as the function we're importing. |
| 4856 | if (!LexicalDC->isFunctionOrMethod()) { |
| 4857 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 4858 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 4859 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4860 | for (auto *FoundDecl : FoundDecls) { |
| 4861 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4862 | continue; |
| 4863 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4864 | if (auto *FoundFunction = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4865 | if (FoundFunction->hasExternalFormalLinkage() && |
| 4866 | D->hasExternalFormalLinkage()) { |
| 4867 | if (IsStructuralMatch(D, FoundFunction)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4868 | Importer.MapImported(D, FoundFunction); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4869 | // FIXME: Actually try to merge the body and other attributes. |
| 4870 | return FoundFunction; |
| 4871 | } |
| 4872 | } |
| 4873 | } |
| 4874 | } |
| 4875 | } |
| 4876 | |
| 4877 | TemplateParameterList *Params = |
| 4878 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4879 | if (!Params) |
| 4880 | return nullptr; |
| 4881 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4882 | auto *TemplatedFD = |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4883 | cast_or_null<FunctionDecl>(Importer.Import(D->getTemplatedDecl())); |
| 4884 | if (!TemplatedFD) |
| 4885 | return nullptr; |
| 4886 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4887 | FunctionTemplateDecl *ToFunc; |
| 4888 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
| 4889 | Params, TemplatedFD)) |
| 4890 | return ToFunc; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4891 | |
| 4892 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| 4893 | ToFunc->setAccess(D->getAccess()); |
| 4894 | ToFunc->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4895 | |
| 4896 | LexicalDC->addDeclInternal(ToFunc); |
| 4897 | return ToFunc; |
| 4898 | } |
| 4899 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4900 | //---------------------------------------------------------------------------- |
| 4901 | // Import Statements |
| 4902 | //---------------------------------------------------------------------------- |
| 4903 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4904 | DeclGroupRef ASTNodeImporter::ImportDeclGroup(DeclGroupRef DG) { |
| 4905 | if (DG.isNull()) |
| 4906 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 4907 | size_t NumDecls = DG.end() - DG.begin(); |
| 4908 | SmallVector<Decl *, 1> ToDecls(NumDecls); |
| 4909 | auto &_Importer = this->Importer; |
| 4910 | std::transform(DG.begin(), DG.end(), ToDecls.begin(), |
| 4911 | [&_Importer](Decl *D) -> Decl * { |
| 4912 | return _Importer.Import(D); |
| 4913 | }); |
| 4914 | return DeclGroupRef::Create(Importer.getToContext(), |
| 4915 | ToDecls.begin(), |
| 4916 | NumDecls); |
| 4917 | } |
| 4918 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4919 | Stmt *ASTNodeImporter::VisitStmt(Stmt *S) { |
| 4920 | Importer.FromDiag(S->getLocStart(), diag::err_unsupported_ast_node) |
| 4921 | << S->getStmtClassName(); |
| 4922 | return nullptr; |
| 4923 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4924 | |
| 4925 | Stmt *ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
| 4926 | SmallVector<IdentifierInfo *, 4> Names; |
| 4927 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 4928 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 4929 | // ToII is nullptr when no symbolic name is given for output operand |
| 4930 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 4931 | if (!ToII && S->getOutputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4932 | return nullptr; |
| 4933 | Names.push_back(ToII); |
| 4934 | } |
| 4935 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 4936 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 4937 | // ToII is nullptr when no symbolic name is given for input operand |
| 4938 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 4939 | if (!ToII && S->getInputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4940 | return nullptr; |
| 4941 | Names.push_back(ToII); |
| 4942 | } |
| 4943 | |
| 4944 | SmallVector<StringLiteral *, 4> Clobbers; |
| 4945 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4946 | auto *Clobber = cast_or_null<StringLiteral>( |
| 4947 | Importer.Import(S->getClobberStringLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4948 | if (!Clobber) |
| 4949 | return nullptr; |
| 4950 | Clobbers.push_back(Clobber); |
| 4951 | } |
| 4952 | |
| 4953 | SmallVector<StringLiteral *, 4> Constraints; |
| 4954 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4955 | auto *Output = cast_or_null<StringLiteral>( |
| 4956 | Importer.Import(S->getOutputConstraintLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4957 | if (!Output) |
| 4958 | return nullptr; |
| 4959 | Constraints.push_back(Output); |
| 4960 | } |
| 4961 | |
| 4962 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4963 | auto *Input = cast_or_null<StringLiteral>( |
| 4964 | Importer.Import(S->getInputConstraintLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4965 | if (!Input) |
| 4966 | return nullptr; |
| 4967 | Constraints.push_back(Input); |
| 4968 | } |
| 4969 | |
| 4970 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4971 | if (ImportContainerChecked(S->outputs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4972 | return nullptr; |
| 4973 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4974 | if (ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4975 | return nullptr; |
| 4976 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4977 | auto *AsmStr = cast_or_null<StringLiteral>( |
| 4978 | Importer.Import(S->getAsmString())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4979 | if (!AsmStr) |
| 4980 | return nullptr; |
| 4981 | |
| 4982 | return new (Importer.getToContext()) GCCAsmStmt( |
| 4983 | Importer.getToContext(), |
| 4984 | Importer.Import(S->getAsmLoc()), |
| 4985 | S->isSimple(), |
| 4986 | S->isVolatile(), |
| 4987 | S->getNumOutputs(), |
| 4988 | S->getNumInputs(), |
| 4989 | Names.data(), |
| 4990 | Constraints.data(), |
| 4991 | Exprs.data(), |
| 4992 | AsmStr, |
| 4993 | S->getNumClobbers(), |
| 4994 | Clobbers.data(), |
| 4995 | Importer.Import(S->getRParenLoc())); |
| 4996 | } |
| 4997 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4998 | Stmt *ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 4999 | DeclGroupRef ToDG = ImportDeclGroup(S->getDeclGroup()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5000 | for (auto *ToD : ToDG) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5001 | if (!ToD) |
| 5002 | return nullptr; |
| 5003 | } |
| 5004 | SourceLocation ToStartLoc = Importer.Import(S->getStartLoc()); |
| 5005 | SourceLocation ToEndLoc = Importer.Import(S->getEndLoc()); |
| 5006 | return new (Importer.getToContext()) DeclStmt(ToDG, ToStartLoc, ToEndLoc); |
| 5007 | } |
| 5008 | |
| 5009 | Stmt *ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5010 | SourceLocation ToSemiLoc = Importer.Import(S->getSemiLoc()); |
| 5011 | return new (Importer.getToContext()) NullStmt(ToSemiLoc, |
| 5012 | S->hasLeadingEmptyMacro()); |
| 5013 | } |
| 5014 | |
| 5015 | Stmt *ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5016 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5017 | |
| 5018 | if (ImportContainerChecked(S->body(), ToStmts)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5019 | return nullptr; |
| 5020 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5021 | SourceLocation ToLBraceLoc = Importer.Import(S->getLBracLoc()); |
| 5022 | SourceLocation ToRBraceLoc = Importer.Import(S->getRBracLoc()); |
Benjamin Kramer | 0742090 | 2017-12-24 16:24:20 +0000 | [diff] [blame] | 5023 | return CompoundStmt::Create(Importer.getToContext(), ToStmts, ToLBraceLoc, |
| 5024 | ToRBraceLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5025 | } |
| 5026 | |
| 5027 | Stmt *ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 5028 | Expr *ToLHS = Importer.Import(S->getLHS()); |
| 5029 | if (!ToLHS) |
| 5030 | return nullptr; |
| 5031 | Expr *ToRHS = Importer.Import(S->getRHS()); |
| 5032 | if (!ToRHS && S->getRHS()) |
| 5033 | return nullptr; |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5034 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5035 | if (!ToSubStmt && S->getSubStmt()) |
| 5036 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5037 | SourceLocation ToCaseLoc = Importer.Import(S->getCaseLoc()); |
| 5038 | SourceLocation ToEllipsisLoc = Importer.Import(S->getEllipsisLoc()); |
| 5039 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5040 | auto *ToStmt = new (Importer.getToContext()) |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5041 | CaseStmt(ToLHS, ToRHS, ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
| 5042 | ToStmt->setSubStmt(ToSubStmt); |
| 5043 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5044 | } |
| 5045 | |
| 5046 | Stmt *ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 5047 | SourceLocation ToDefaultLoc = Importer.Import(S->getDefaultLoc()); |
| 5048 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 5049 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5050 | if (!ToSubStmt && S->getSubStmt()) |
| 5051 | return nullptr; |
| 5052 | return new (Importer.getToContext()) DefaultStmt(ToDefaultLoc, ToColonLoc, |
| 5053 | ToSubStmt); |
| 5054 | } |
| 5055 | |
| 5056 | Stmt *ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 5057 | SourceLocation ToIdentLoc = Importer.Import(S->getIdentLoc()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5058 | auto *ToLabelDecl = cast_or_null<LabelDecl>(Importer.Import(S->getDecl())); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5059 | if (!ToLabelDecl && S->getDecl()) |
| 5060 | return nullptr; |
| 5061 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5062 | if (!ToSubStmt && S->getSubStmt()) |
| 5063 | return nullptr; |
| 5064 | return new (Importer.getToContext()) LabelStmt(ToIdentLoc, ToLabelDecl, |
| 5065 | ToSubStmt); |
| 5066 | } |
| 5067 | |
| 5068 | Stmt *ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 5069 | SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc()); |
| 5070 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 5071 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 5072 | if (ImportContainerChecked(FromAttrs, ToAttrs)) |
| 5073 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5074 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5075 | if (!ToSubStmt && S->getSubStmt()) |
| 5076 | return nullptr; |
| 5077 | return AttributedStmt::Create(Importer.getToContext(), ToAttrLoc, |
| 5078 | ToAttrs, ToSubStmt); |
| 5079 | } |
| 5080 | |
| 5081 | Stmt *ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 5082 | SourceLocation ToIfLoc = Importer.Import(S->getIfLoc()); |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 5083 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 5084 | if (!ToInit && S->getInit()) |
| 5085 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5086 | VarDecl *ToConditionVariable = nullptr; |
| 5087 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5088 | ToConditionVariable = |
| 5089 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5090 | if (!ToConditionVariable) |
| 5091 | return nullptr; |
| 5092 | } |
| 5093 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5094 | if (!ToCondition && S->getCond()) |
| 5095 | return nullptr; |
| 5096 | Stmt *ToThenStmt = Importer.Import(S->getThen()); |
| 5097 | if (!ToThenStmt && S->getThen()) |
| 5098 | return nullptr; |
| 5099 | SourceLocation ToElseLoc = Importer.Import(S->getElseLoc()); |
| 5100 | Stmt *ToElseStmt = Importer.Import(S->getElse()); |
| 5101 | if (!ToElseStmt && S->getElse()) |
| 5102 | return nullptr; |
| 5103 | return new (Importer.getToContext()) IfStmt(Importer.getToContext(), |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 5104 | ToIfLoc, S->isConstexpr(), |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 5105 | ToInit, |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 5106 | ToConditionVariable, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5107 | ToCondition, ToThenStmt, |
| 5108 | ToElseLoc, ToElseStmt); |
| 5109 | } |
| 5110 | |
| 5111 | Stmt *ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 5112 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 5113 | if (!ToInit && S->getInit()) |
| 5114 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5115 | VarDecl *ToConditionVariable = nullptr; |
| 5116 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5117 | ToConditionVariable = |
| 5118 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5119 | if (!ToConditionVariable) |
| 5120 | return nullptr; |
| 5121 | } |
| 5122 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5123 | if (!ToCondition && S->getCond()) |
| 5124 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5125 | auto *ToStmt = new (Importer.getToContext()) SwitchStmt( |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 5126 | Importer.getToContext(), ToInit, |
| 5127 | ToConditionVariable, ToCondition); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5128 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5129 | if (!ToBody && S->getBody()) |
| 5130 | return nullptr; |
| 5131 | ToStmt->setBody(ToBody); |
| 5132 | ToStmt->setSwitchLoc(Importer.Import(S->getSwitchLoc())); |
| 5133 | // Now we have to re-chain the cases. |
| 5134 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 5135 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 5136 | SC = SC->getNextSwitchCase()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5137 | auto *ToSC = dyn_cast_or_null<SwitchCase>(Importer.Import(SC)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5138 | if (!ToSC) |
| 5139 | return nullptr; |
| 5140 | if (LastChainedSwitchCase) |
| 5141 | LastChainedSwitchCase->setNextSwitchCase(ToSC); |
| 5142 | else |
| 5143 | ToStmt->setSwitchCaseList(ToSC); |
| 5144 | LastChainedSwitchCase = ToSC; |
| 5145 | } |
| 5146 | return ToStmt; |
| 5147 | } |
| 5148 | |
| 5149 | Stmt *ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 5150 | VarDecl *ToConditionVariable = nullptr; |
| 5151 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5152 | ToConditionVariable = |
| 5153 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5154 | if (!ToConditionVariable) |
| 5155 | return nullptr; |
| 5156 | } |
| 5157 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5158 | if (!ToCondition && S->getCond()) |
| 5159 | return nullptr; |
| 5160 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5161 | if (!ToBody && S->getBody()) |
| 5162 | return nullptr; |
| 5163 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 5164 | return new (Importer.getToContext()) WhileStmt(Importer.getToContext(), |
| 5165 | ToConditionVariable, |
| 5166 | ToCondition, ToBody, |
| 5167 | ToWhileLoc); |
| 5168 | } |
| 5169 | |
| 5170 | Stmt *ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 5171 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5172 | if (!ToBody && S->getBody()) |
| 5173 | return nullptr; |
| 5174 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5175 | if (!ToCondition && S->getCond()) |
| 5176 | return nullptr; |
| 5177 | SourceLocation ToDoLoc = Importer.Import(S->getDoLoc()); |
| 5178 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 5179 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5180 | return new (Importer.getToContext()) DoStmt(ToBody, ToCondition, |
| 5181 | ToDoLoc, ToWhileLoc, |
| 5182 | ToRParenLoc); |
| 5183 | } |
| 5184 | |
| 5185 | Stmt *ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 5186 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 5187 | if (!ToInit && S->getInit()) |
| 5188 | return nullptr; |
| 5189 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5190 | if (!ToCondition && S->getCond()) |
| 5191 | return nullptr; |
| 5192 | VarDecl *ToConditionVariable = nullptr; |
| 5193 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5194 | ToConditionVariable = |
| 5195 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5196 | if (!ToConditionVariable) |
| 5197 | return nullptr; |
| 5198 | } |
| 5199 | Expr *ToInc = Importer.Import(S->getInc()); |
| 5200 | if (!ToInc && S->getInc()) |
| 5201 | return nullptr; |
| 5202 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5203 | if (!ToBody && S->getBody()) |
| 5204 | return nullptr; |
| 5205 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 5206 | SourceLocation ToLParenLoc = Importer.Import(S->getLParenLoc()); |
| 5207 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5208 | return new (Importer.getToContext()) ForStmt(Importer.getToContext(), |
| 5209 | ToInit, ToCondition, |
| 5210 | ToConditionVariable, |
| 5211 | ToInc, ToBody, |
| 5212 | ToForLoc, ToLParenLoc, |
| 5213 | ToRParenLoc); |
| 5214 | } |
| 5215 | |
| 5216 | Stmt *ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 5217 | LabelDecl *ToLabel = nullptr; |
| 5218 | if (LabelDecl *FromLabel = S->getLabel()) { |
| 5219 | ToLabel = dyn_cast_or_null<LabelDecl>(Importer.Import(FromLabel)); |
| 5220 | if (!ToLabel) |
| 5221 | return nullptr; |
| 5222 | } |
| 5223 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 5224 | SourceLocation ToLabelLoc = Importer.Import(S->getLabelLoc()); |
| 5225 | return new (Importer.getToContext()) GotoStmt(ToLabel, |
| 5226 | ToGotoLoc, ToLabelLoc); |
| 5227 | } |
| 5228 | |
| 5229 | Stmt *ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 5230 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 5231 | SourceLocation ToStarLoc = Importer.Import(S->getStarLoc()); |
| 5232 | Expr *ToTarget = Importer.Import(S->getTarget()); |
| 5233 | if (!ToTarget && S->getTarget()) |
| 5234 | return nullptr; |
| 5235 | return new (Importer.getToContext()) IndirectGotoStmt(ToGotoLoc, ToStarLoc, |
| 5236 | ToTarget); |
| 5237 | } |
| 5238 | |
| 5239 | Stmt *ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 5240 | SourceLocation ToContinueLoc = Importer.Import(S->getContinueLoc()); |
| 5241 | return new (Importer.getToContext()) ContinueStmt(ToContinueLoc); |
| 5242 | } |
| 5243 | |
| 5244 | Stmt *ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 5245 | SourceLocation ToBreakLoc = Importer.Import(S->getBreakLoc()); |
| 5246 | return new (Importer.getToContext()) BreakStmt(ToBreakLoc); |
| 5247 | } |
| 5248 | |
| 5249 | Stmt *ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 5250 | SourceLocation ToRetLoc = Importer.Import(S->getReturnLoc()); |
| 5251 | Expr *ToRetExpr = Importer.Import(S->getRetValue()); |
| 5252 | if (!ToRetExpr && S->getRetValue()) |
| 5253 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5254 | auto *NRVOCandidate = const_cast<VarDecl *>(S->getNRVOCandidate()); |
| 5255 | auto *ToNRVOCandidate = cast_or_null<VarDecl>(Importer.Import(NRVOCandidate)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5256 | if (!ToNRVOCandidate && NRVOCandidate) |
| 5257 | return nullptr; |
| 5258 | return new (Importer.getToContext()) ReturnStmt(ToRetLoc, ToRetExpr, |
| 5259 | ToNRVOCandidate); |
| 5260 | } |
| 5261 | |
| 5262 | Stmt *ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 5263 | SourceLocation ToCatchLoc = Importer.Import(S->getCatchLoc()); |
| 5264 | VarDecl *ToExceptionDecl = nullptr; |
| 5265 | if (VarDecl *FromExceptionDecl = S->getExceptionDecl()) { |
| 5266 | ToExceptionDecl = |
| 5267 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 5268 | if (!ToExceptionDecl) |
| 5269 | return nullptr; |
| 5270 | } |
| 5271 | Stmt *ToHandlerBlock = Importer.Import(S->getHandlerBlock()); |
| 5272 | if (!ToHandlerBlock && S->getHandlerBlock()) |
| 5273 | return nullptr; |
| 5274 | return new (Importer.getToContext()) CXXCatchStmt(ToCatchLoc, |
| 5275 | ToExceptionDecl, |
| 5276 | ToHandlerBlock); |
| 5277 | } |
| 5278 | |
| 5279 | Stmt *ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 5280 | SourceLocation ToTryLoc = Importer.Import(S->getTryLoc()); |
| 5281 | Stmt *ToTryBlock = Importer.Import(S->getTryBlock()); |
| 5282 | if (!ToTryBlock && S->getTryBlock()) |
| 5283 | return nullptr; |
| 5284 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 5285 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 5286 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
| 5287 | if (Stmt *ToHandler = Importer.Import(FromHandler)) |
| 5288 | ToHandlers[HI] = ToHandler; |
| 5289 | else |
| 5290 | return nullptr; |
| 5291 | } |
| 5292 | return CXXTryStmt::Create(Importer.getToContext(), ToTryLoc, ToTryBlock, |
| 5293 | ToHandlers); |
| 5294 | } |
| 5295 | |
| 5296 | Stmt *ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5297 | auto *ToRange = |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5298 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getRangeStmt())); |
| 5299 | if (!ToRange && S->getRangeStmt()) |
| 5300 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5301 | auto *ToBegin = |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5302 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getBeginStmt())); |
| 5303 | if (!ToBegin && S->getBeginStmt()) |
| 5304 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5305 | auto *ToEnd = |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5306 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getEndStmt())); |
| 5307 | if (!ToEnd && S->getEndStmt()) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5308 | return nullptr; |
| 5309 | Expr *ToCond = Importer.Import(S->getCond()); |
| 5310 | if (!ToCond && S->getCond()) |
| 5311 | return nullptr; |
| 5312 | Expr *ToInc = Importer.Import(S->getInc()); |
| 5313 | if (!ToInc && S->getInc()) |
| 5314 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5315 | auto *ToLoopVar = |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5316 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getLoopVarStmt())); |
| 5317 | if (!ToLoopVar && S->getLoopVarStmt()) |
| 5318 | return nullptr; |
| 5319 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5320 | if (!ToBody && S->getBody()) |
| 5321 | return nullptr; |
| 5322 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 5323 | SourceLocation ToCoawaitLoc = Importer.Import(S->getCoawaitLoc()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5324 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 5325 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5326 | return new (Importer.getToContext()) CXXForRangeStmt(ToRange, ToBegin, ToEnd, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5327 | ToCond, ToInc, |
| 5328 | ToLoopVar, ToBody, |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 5329 | ToForLoc, ToCoawaitLoc, |
| 5330 | ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5331 | } |
| 5332 | |
| 5333 | Stmt *ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 5334 | Stmt *ToElem = Importer.Import(S->getElement()); |
| 5335 | if (!ToElem && S->getElement()) |
| 5336 | return nullptr; |
| 5337 | Expr *ToCollect = Importer.Import(S->getCollection()); |
| 5338 | if (!ToCollect && S->getCollection()) |
| 5339 | return nullptr; |
| 5340 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5341 | if (!ToBody && S->getBody()) |
| 5342 | return nullptr; |
| 5343 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 5344 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5345 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElem, |
| 5346 | ToCollect, |
| 5347 | ToBody, ToForLoc, |
| 5348 | ToRParenLoc); |
| 5349 | } |
| 5350 | |
| 5351 | Stmt *ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 5352 | SourceLocation ToAtCatchLoc = Importer.Import(S->getAtCatchLoc()); |
| 5353 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5354 | VarDecl *ToExceptionDecl = nullptr; |
| 5355 | if (VarDecl *FromExceptionDecl = S->getCatchParamDecl()) { |
| 5356 | ToExceptionDecl = |
| 5357 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 5358 | if (!ToExceptionDecl) |
| 5359 | return nullptr; |
| 5360 | } |
| 5361 | Stmt *ToBody = Importer.Import(S->getCatchBody()); |
| 5362 | if (!ToBody && S->getCatchBody()) |
| 5363 | return nullptr; |
| 5364 | return new (Importer.getToContext()) ObjCAtCatchStmt(ToAtCatchLoc, |
| 5365 | ToRParenLoc, |
| 5366 | ToExceptionDecl, |
| 5367 | ToBody); |
| 5368 | } |
| 5369 | |
| 5370 | Stmt *ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 5371 | SourceLocation ToAtFinallyLoc = Importer.Import(S->getAtFinallyLoc()); |
| 5372 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyBody()); |
| 5373 | if (!ToAtFinallyStmt && S->getFinallyBody()) |
| 5374 | return nullptr; |
| 5375 | return new (Importer.getToContext()) ObjCAtFinallyStmt(ToAtFinallyLoc, |
| 5376 | ToAtFinallyStmt); |
| 5377 | } |
| 5378 | |
| 5379 | Stmt *ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 5380 | SourceLocation ToAtTryLoc = Importer.Import(S->getAtTryLoc()); |
| 5381 | Stmt *ToAtTryStmt = Importer.Import(S->getTryBody()); |
| 5382 | if (!ToAtTryStmt && S->getTryBody()) |
| 5383 | return nullptr; |
| 5384 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 5385 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 5386 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
| 5387 | if (Stmt *ToCatchStmt = Importer.Import(FromCatchStmt)) |
| 5388 | ToCatchStmts[CI] = ToCatchStmt; |
| 5389 | else |
| 5390 | return nullptr; |
| 5391 | } |
| 5392 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyStmt()); |
| 5393 | if (!ToAtFinallyStmt && S->getFinallyStmt()) |
| 5394 | return nullptr; |
| 5395 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
| 5396 | ToAtTryLoc, ToAtTryStmt, |
| 5397 | ToCatchStmts.begin(), ToCatchStmts.size(), |
| 5398 | ToAtFinallyStmt); |
| 5399 | } |
| 5400 | |
| 5401 | Stmt *ASTNodeImporter::VisitObjCAtSynchronizedStmt |
| 5402 | (ObjCAtSynchronizedStmt *S) { |
| 5403 | SourceLocation ToAtSynchronizedLoc = |
| 5404 | Importer.Import(S->getAtSynchronizedLoc()); |
| 5405 | Expr *ToSynchExpr = Importer.Import(S->getSynchExpr()); |
| 5406 | if (!ToSynchExpr && S->getSynchExpr()) |
| 5407 | return nullptr; |
| 5408 | Stmt *ToSynchBody = Importer.Import(S->getSynchBody()); |
| 5409 | if (!ToSynchBody && S->getSynchBody()) |
| 5410 | return nullptr; |
| 5411 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 5412 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 5413 | } |
| 5414 | |
| 5415 | Stmt *ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 5416 | SourceLocation ToAtThrowLoc = Importer.Import(S->getThrowLoc()); |
| 5417 | Expr *ToThrow = Importer.Import(S->getThrowExpr()); |
| 5418 | if (!ToThrow && S->getThrowExpr()) |
| 5419 | return nullptr; |
| 5420 | return new (Importer.getToContext()) ObjCAtThrowStmt(ToAtThrowLoc, ToThrow); |
| 5421 | } |
| 5422 | |
| 5423 | Stmt *ASTNodeImporter::VisitObjCAutoreleasePoolStmt |
| 5424 | (ObjCAutoreleasePoolStmt *S) { |
| 5425 | SourceLocation ToAtLoc = Importer.Import(S->getAtLoc()); |
| 5426 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5427 | if (!ToSubStmt && S->getSubStmt()) |
| 5428 | return nullptr; |
| 5429 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(ToAtLoc, |
| 5430 | ToSubStmt); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5431 | } |
| 5432 | |
| 5433 | //---------------------------------------------------------------------------- |
| 5434 | // Import Expressions |
| 5435 | //---------------------------------------------------------------------------- |
| 5436 | Expr *ASTNodeImporter::VisitExpr(Expr *E) { |
| 5437 | Importer.FromDiag(E->getLocStart(), diag::err_unsupported_ast_node) |
| 5438 | << E->getStmtClassName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5439 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5440 | } |
| 5441 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5442 | Expr *ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 5443 | QualType T = Importer.Import(E->getType()); |
| 5444 | if (T.isNull()) |
| 5445 | return nullptr; |
| 5446 | |
| 5447 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5448 | if (!SubExpr && E->getSubExpr()) |
| 5449 | return nullptr; |
| 5450 | |
| 5451 | TypeSourceInfo *TInfo = Importer.Import(E->getWrittenTypeInfo()); |
| 5452 | if (!TInfo) |
| 5453 | return nullptr; |
| 5454 | |
| 5455 | return new (Importer.getToContext()) VAArgExpr( |
| 5456 | Importer.Import(E->getBuiltinLoc()), SubExpr, TInfo, |
| 5457 | Importer.Import(E->getRParenLoc()), T, E->isMicrosoftABI()); |
| 5458 | } |
| 5459 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5460 | Expr *ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 5461 | QualType T = Importer.Import(E->getType()); |
| 5462 | if (T.isNull()) |
| 5463 | return nullptr; |
| 5464 | |
| 5465 | return new (Importer.getToContext()) GNUNullExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5466 | T, Importer.Import(E->getLocStart())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5467 | } |
| 5468 | |
| 5469 | Expr *ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 5470 | QualType T = Importer.Import(E->getType()); |
| 5471 | if (T.isNull()) |
| 5472 | return nullptr; |
| 5473 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5474 | auto *SL = cast_or_null<StringLiteral>(Importer.Import(E->getFunctionName())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5475 | if (!SL && E->getFunctionName()) |
| 5476 | return nullptr; |
| 5477 | |
| 5478 | return new (Importer.getToContext()) PredefinedExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5479 | Importer.Import(E->getLocStart()), T, E->getIdentType(), SL); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5480 | } |
| 5481 | |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5482 | Expr *ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5483 | auto *ToD = cast_or_null<ValueDecl>(Importer.Import(E->getDecl())); |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5484 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5485 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5486 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5487 | NamedDecl *FoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5488 | if (E->getDecl() != E->getFoundDecl()) { |
| 5489 | FoundD = cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl())); |
| 5490 | if (!FoundD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5491 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5492 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5493 | |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5494 | QualType T = Importer.Import(E->getType()); |
| 5495 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5496 | return nullptr; |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5497 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5498 | TemplateArgumentListInfo ToTAInfo; |
| 5499 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 5500 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5501 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 5502 | return nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5503 | ResInfo = &ToTAInfo; |
| 5504 | } |
| 5505 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5506 | DeclRefExpr *DRE = DeclRefExpr::Create(Importer.getToContext(), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5507 | Importer.Import(E->getQualifierLoc()), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 5508 | Importer.Import(E->getTemplateKeywordLoc()), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5509 | ToD, |
Alexey Bataev | 19acc3d | 2015-01-12 10:17:46 +0000 | [diff] [blame] | 5510 | E->refersToEnclosingVariableOrCapture(), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5511 | Importer.Import(E->getLocation()), |
| 5512 | T, E->getValueKind(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5513 | FoundD, ResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5514 | if (E->hadMultipleCandidates()) |
| 5515 | DRE->setHadMultipleCandidates(true); |
| 5516 | return DRE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5517 | } |
| 5518 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5519 | Expr *ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 5520 | QualType T = Importer.Import(E->getType()); |
| 5521 | if (T.isNull()) |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5522 | return nullptr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5523 | |
| 5524 | return new (Importer.getToContext()) ImplicitValueInitExpr(T); |
| 5525 | } |
| 5526 | |
| 5527 | ASTNodeImporter::Designator |
| 5528 | ASTNodeImporter::ImportDesignator(const Designator &D) { |
| 5529 | if (D.isFieldDesignator()) { |
| 5530 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 5531 | // Caller checks for import error |
| 5532 | return Designator(ToFieldName, Importer.Import(D.getDotLoc()), |
| 5533 | Importer.Import(D.getFieldLoc())); |
| 5534 | } |
| 5535 | if (D.isArrayDesignator()) |
| 5536 | return Designator(D.getFirstExprIndex(), |
| 5537 | Importer.Import(D.getLBracketLoc()), |
| 5538 | Importer.Import(D.getRBracketLoc())); |
| 5539 | |
| 5540 | assert(D.isArrayRangeDesignator()); |
| 5541 | return Designator(D.getFirstExprIndex(), |
| 5542 | Importer.Import(D.getLBracketLoc()), |
| 5543 | Importer.Import(D.getEllipsisLoc()), |
| 5544 | Importer.Import(D.getRBracketLoc())); |
| 5545 | } |
| 5546 | |
| 5547 | |
| 5548 | Expr *ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *DIE) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5549 | auto *Init = cast_or_null<Expr>(Importer.Import(DIE->getInit())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5550 | if (!Init) |
| 5551 | return nullptr; |
| 5552 | |
| 5553 | SmallVector<Expr *, 4> IndexExprs(DIE->getNumSubExprs() - 1); |
| 5554 | // List elements from the second, the first is Init itself |
| 5555 | for (unsigned I = 1, E = DIE->getNumSubExprs(); I < E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5556 | if (auto *Arg = cast_or_null<Expr>(Importer.Import(DIE->getSubExpr(I)))) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5557 | IndexExprs[I - 1] = Arg; |
| 5558 | else |
| 5559 | return nullptr; |
| 5560 | } |
| 5561 | |
| 5562 | SmallVector<Designator, 4> Designators(DIE->size()); |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5563 | llvm::transform(DIE->designators(), Designators.begin(), |
| 5564 | [this](const Designator &D) -> Designator { |
| 5565 | return ImportDesignator(D); |
| 5566 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5567 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5568 | for (const auto &D : DIE->designators()) |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5569 | if (D.isFieldDesignator() && !D.getFieldName()) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5570 | return nullptr; |
| 5571 | |
| 5572 | return DesignatedInitExpr::Create( |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5573 | Importer.getToContext(), Designators, |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5574 | IndexExprs, Importer.Import(DIE->getEqualOrColonLoc()), |
| 5575 | DIE->usesGNUSyntax(), Init); |
| 5576 | } |
| 5577 | |
| 5578 | Expr *ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 5579 | QualType T = Importer.Import(E->getType()); |
| 5580 | if (T.isNull()) |
| 5581 | return nullptr; |
| 5582 | |
| 5583 | return new (Importer.getToContext()) |
| 5584 | CXXNullPtrLiteralExpr(T, Importer.Import(E->getLocation())); |
| 5585 | } |
| 5586 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5587 | Expr *ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 5588 | QualType T = Importer.Import(E->getType()); |
| 5589 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5590 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5591 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5592 | return IntegerLiteral::Create(Importer.getToContext(), |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 5593 | E->getValue(), T, |
| 5594 | Importer.Import(E->getLocation())); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5595 | } |
| 5596 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5597 | Expr *ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 5598 | QualType T = Importer.Import(E->getType()); |
| 5599 | if (T.isNull()) |
| 5600 | return nullptr; |
| 5601 | |
| 5602 | return FloatingLiteral::Create(Importer.getToContext(), |
| 5603 | E->getValue(), E->isExact(), T, |
| 5604 | Importer.Import(E->getLocation())); |
| 5605 | } |
| 5606 | |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5607 | Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 5608 | QualType T = Importer.Import(E->getType()); |
| 5609 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5610 | return nullptr; |
| 5611 | |
Douglas Gregor | fb65e59 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 5612 | return new (Importer.getToContext()) CharacterLiteral(E->getValue(), |
| 5613 | E->getKind(), T, |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5614 | Importer.Import(E->getLocation())); |
| 5615 | } |
| 5616 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5617 | Expr *ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 5618 | QualType T = Importer.Import(E->getType()); |
| 5619 | if (T.isNull()) |
| 5620 | return nullptr; |
| 5621 | |
| 5622 | SmallVector<SourceLocation, 4> Locations(E->getNumConcatenated()); |
| 5623 | ImportArray(E->tokloc_begin(), E->tokloc_end(), Locations.begin()); |
| 5624 | |
| 5625 | return StringLiteral::Create(Importer.getToContext(), E->getBytes(), |
| 5626 | E->getKind(), E->isPascal(), T, |
| 5627 | Locations.data(), Locations.size()); |
| 5628 | } |
| 5629 | |
| 5630 | Expr *ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 5631 | QualType T = Importer.Import(E->getType()); |
| 5632 | if (T.isNull()) |
| 5633 | return nullptr; |
| 5634 | |
| 5635 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeSourceInfo()); |
| 5636 | if (!TInfo) |
| 5637 | return nullptr; |
| 5638 | |
| 5639 | Expr *Init = Importer.Import(E->getInitializer()); |
| 5640 | if (!Init) |
| 5641 | return nullptr; |
| 5642 | |
| 5643 | return new (Importer.getToContext()) CompoundLiteralExpr( |
| 5644 | Importer.Import(E->getLParenLoc()), TInfo, T, E->getValueKind(), |
| 5645 | Init, E->isFileScope()); |
| 5646 | } |
| 5647 | |
| 5648 | Expr *ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 5649 | QualType T = Importer.Import(E->getType()); |
| 5650 | if (T.isNull()) |
| 5651 | return nullptr; |
| 5652 | |
| 5653 | SmallVector<Expr *, 6> Exprs(E->getNumSubExprs()); |
| 5654 | if (ImportArrayChecked( |
| 5655 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 5656 | Exprs.begin())) |
| 5657 | return nullptr; |
| 5658 | |
| 5659 | return new (Importer.getToContext()) AtomicExpr( |
| 5660 | Importer.Import(E->getBuiltinLoc()), Exprs, T, E->getOp(), |
| 5661 | Importer.Import(E->getRParenLoc())); |
| 5662 | } |
| 5663 | |
| 5664 | Expr *ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 5665 | QualType T = Importer.Import(E->getType()); |
| 5666 | if (T.isNull()) |
| 5667 | return nullptr; |
| 5668 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5669 | auto *ToLabel = cast_or_null<LabelDecl>(Importer.Import(E->getLabel())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5670 | if (!ToLabel) |
| 5671 | return nullptr; |
| 5672 | |
| 5673 | return new (Importer.getToContext()) AddrLabelExpr( |
| 5674 | Importer.Import(E->getAmpAmpLoc()), Importer.Import(E->getLabelLoc()), |
| 5675 | ToLabel, T); |
| 5676 | } |
| 5677 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5678 | Expr *ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 5679 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5680 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5681 | return nullptr; |
| 5682 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5683 | return new (Importer.getToContext()) |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5684 | ParenExpr(Importer.Import(E->getLParen()), |
| 5685 | Importer.Import(E->getRParen()), |
| 5686 | SubExpr); |
| 5687 | } |
| 5688 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5689 | Expr *ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 5690 | SmallVector<Expr *, 4> Exprs(E->getNumExprs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5691 | if (ImportContainerChecked(E->exprs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5692 | return nullptr; |
| 5693 | |
| 5694 | return new (Importer.getToContext()) ParenListExpr( |
| 5695 | Importer.getToContext(), Importer.Import(E->getLParenLoc()), |
| 5696 | Exprs, Importer.Import(E->getLParenLoc())); |
| 5697 | } |
| 5698 | |
| 5699 | Expr *ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 5700 | QualType T = Importer.Import(E->getType()); |
| 5701 | if (T.isNull()) |
| 5702 | return nullptr; |
| 5703 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5704 | auto *ToSubStmt = cast_or_null<CompoundStmt>( |
| 5705 | Importer.Import(E->getSubStmt())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5706 | if (!ToSubStmt && E->getSubStmt()) |
| 5707 | return nullptr; |
| 5708 | |
| 5709 | return new (Importer.getToContext()) StmtExpr(ToSubStmt, T, |
| 5710 | Importer.Import(E->getLParenLoc()), Importer.Import(E->getRParenLoc())); |
| 5711 | } |
| 5712 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5713 | Expr *ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 5714 | QualType T = Importer.Import(E->getType()); |
| 5715 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5716 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5717 | |
| 5718 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5719 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5720 | return nullptr; |
| 5721 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5722 | return new (Importer.getToContext()) UnaryOperator( |
| 5723 | SubExpr, E->getOpcode(), T, E->getValueKind(), E->getObjectKind(), |
| 5724 | Importer.Import(E->getOperatorLoc()), E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5725 | } |
| 5726 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5727 | Expr * |
| 5728 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5729 | QualType ResultType = Importer.Import(E->getType()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5730 | |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5731 | if (E->isArgumentType()) { |
| 5732 | TypeSourceInfo *TInfo = Importer.Import(E->getArgumentTypeInfo()); |
| 5733 | if (!TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5734 | return nullptr; |
| 5735 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5736 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5737 | TInfo, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5738 | Importer.Import(E->getOperatorLoc()), |
| 5739 | Importer.Import(E->getRParenLoc())); |
| 5740 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5741 | |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5742 | Expr *SubExpr = Importer.Import(E->getArgumentExpr()); |
| 5743 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5744 | return nullptr; |
| 5745 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5746 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5747 | SubExpr, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5748 | Importer.Import(E->getOperatorLoc()), |
| 5749 | Importer.Import(E->getRParenLoc())); |
| 5750 | } |
| 5751 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5752 | Expr *ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 5753 | QualType T = Importer.Import(E->getType()); |
| 5754 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5755 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5756 | |
| 5757 | Expr *LHS = Importer.Import(E->getLHS()); |
| 5758 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5759 | return nullptr; |
| 5760 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5761 | Expr *RHS = Importer.Import(E->getRHS()); |
| 5762 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5763 | return nullptr; |
| 5764 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5765 | return new (Importer.getToContext()) BinaryOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 5766 | T, E->getValueKind(), |
| 5767 | E->getObjectKind(), |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 5768 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 5769 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5770 | } |
| 5771 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5772 | Expr *ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 5773 | QualType T = Importer.Import(E->getType()); |
| 5774 | if (T.isNull()) |
| 5775 | return nullptr; |
| 5776 | |
| 5777 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5778 | if (!ToLHS) |
| 5779 | return nullptr; |
| 5780 | |
| 5781 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5782 | if (!ToRHS) |
| 5783 | return nullptr; |
| 5784 | |
| 5785 | Expr *ToCond = Importer.Import(E->getCond()); |
| 5786 | if (!ToCond) |
| 5787 | return nullptr; |
| 5788 | |
| 5789 | return new (Importer.getToContext()) ConditionalOperator( |
| 5790 | ToCond, Importer.Import(E->getQuestionLoc()), |
| 5791 | ToLHS, Importer.Import(E->getColonLoc()), |
| 5792 | ToRHS, T, E->getValueKind(), E->getObjectKind()); |
| 5793 | } |
| 5794 | |
| 5795 | Expr *ASTNodeImporter::VisitBinaryConditionalOperator( |
| 5796 | BinaryConditionalOperator *E) { |
| 5797 | QualType T = Importer.Import(E->getType()); |
| 5798 | if (T.isNull()) |
| 5799 | return nullptr; |
| 5800 | |
| 5801 | Expr *Common = Importer.Import(E->getCommon()); |
| 5802 | if (!Common) |
| 5803 | return nullptr; |
| 5804 | |
| 5805 | Expr *Cond = Importer.Import(E->getCond()); |
| 5806 | if (!Cond) |
| 5807 | return nullptr; |
| 5808 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5809 | auto *OpaqueValue = cast_or_null<OpaqueValueExpr>( |
| 5810 | Importer.Import(E->getOpaqueValue())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5811 | if (!OpaqueValue) |
| 5812 | return nullptr; |
| 5813 | |
| 5814 | Expr *TrueExpr = Importer.Import(E->getTrueExpr()); |
| 5815 | if (!TrueExpr) |
| 5816 | return nullptr; |
| 5817 | |
| 5818 | Expr *FalseExpr = Importer.Import(E->getFalseExpr()); |
| 5819 | if (!FalseExpr) |
| 5820 | return nullptr; |
| 5821 | |
| 5822 | return new (Importer.getToContext()) BinaryConditionalOperator( |
| 5823 | Common, OpaqueValue, Cond, TrueExpr, FalseExpr, |
| 5824 | Importer.Import(E->getQuestionLoc()), Importer.Import(E->getColonLoc()), |
| 5825 | T, E->getValueKind(), E->getObjectKind()); |
| 5826 | } |
| 5827 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5828 | Expr *ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 5829 | QualType T = Importer.Import(E->getType()); |
| 5830 | if (T.isNull()) |
| 5831 | return nullptr; |
| 5832 | |
| 5833 | TypeSourceInfo *ToQueried = Importer.Import(E->getQueriedTypeSourceInfo()); |
| 5834 | if (!ToQueried) |
| 5835 | return nullptr; |
| 5836 | |
| 5837 | Expr *Dim = Importer.Import(E->getDimensionExpression()); |
| 5838 | if (!Dim && E->getDimensionExpression()) |
| 5839 | return nullptr; |
| 5840 | |
| 5841 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
| 5842 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 5843 | E->getValue(), Dim, Importer.Import(E->getLocEnd()), T); |
| 5844 | } |
| 5845 | |
| 5846 | Expr *ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 5847 | QualType T = Importer.Import(E->getType()); |
| 5848 | if (T.isNull()) |
| 5849 | return nullptr; |
| 5850 | |
| 5851 | Expr *ToQueried = Importer.Import(E->getQueriedExpression()); |
| 5852 | if (!ToQueried) |
| 5853 | return nullptr; |
| 5854 | |
| 5855 | return new (Importer.getToContext()) ExpressionTraitExpr( |
| 5856 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 5857 | E->getValue(), Importer.Import(E->getLocEnd()), T); |
| 5858 | } |
| 5859 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5860 | Expr *ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 5861 | QualType T = Importer.Import(E->getType()); |
| 5862 | if (T.isNull()) |
| 5863 | return nullptr; |
| 5864 | |
| 5865 | Expr *SourceExpr = Importer.Import(E->getSourceExpr()); |
| 5866 | if (!SourceExpr && E->getSourceExpr()) |
| 5867 | return nullptr; |
| 5868 | |
| 5869 | return new (Importer.getToContext()) OpaqueValueExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5870 | Importer.Import(E->getLocation()), T, E->getValueKind(), |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5871 | E->getObjectKind(), SourceExpr); |
| 5872 | } |
| 5873 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5874 | Expr *ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 5875 | QualType T = Importer.Import(E->getType()); |
| 5876 | if (T.isNull()) |
| 5877 | return nullptr; |
| 5878 | |
| 5879 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5880 | if (!ToLHS) |
| 5881 | return nullptr; |
| 5882 | |
| 5883 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5884 | if (!ToRHS) |
| 5885 | return nullptr; |
| 5886 | |
| 5887 | return new (Importer.getToContext()) ArraySubscriptExpr( |
| 5888 | ToLHS, ToRHS, T, E->getValueKind(), E->getObjectKind(), |
| 5889 | Importer.Import(E->getRBracketLoc())); |
| 5890 | } |
| 5891 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5892 | Expr *ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 5893 | QualType T = Importer.Import(E->getType()); |
| 5894 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5895 | return nullptr; |
| 5896 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5897 | QualType CompLHSType = Importer.Import(E->getComputationLHSType()); |
| 5898 | if (CompLHSType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5899 | return nullptr; |
| 5900 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5901 | QualType CompResultType = Importer.Import(E->getComputationResultType()); |
| 5902 | if (CompResultType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5903 | return nullptr; |
| 5904 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5905 | Expr *LHS = Importer.Import(E->getLHS()); |
| 5906 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5907 | return nullptr; |
| 5908 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5909 | Expr *RHS = Importer.Import(E->getRHS()); |
| 5910 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5911 | return nullptr; |
| 5912 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 5913 | return new (Importer.getToContext()) |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5914 | CompoundAssignOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 5915 | T, E->getValueKind(), |
| 5916 | E->getObjectKind(), |
| 5917 | CompLHSType, CompResultType, |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 5918 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 5919 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5920 | } |
| 5921 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5922 | bool ASTNodeImporter::ImportCastPath(CastExpr *CE, CXXCastPath &Path) { |
| 5923 | for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) { |
| 5924 | if (CXXBaseSpecifier *Spec = Importer.Import(*I)) |
| 5925 | Path.push_back(Spec); |
| 5926 | else |
| 5927 | return true; |
| 5928 | } |
| 5929 | return false; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5930 | } |
| 5931 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5932 | Expr *ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 5933 | QualType T = Importer.Import(E->getType()); |
| 5934 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5935 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5936 | |
| 5937 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5938 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5939 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5940 | |
| 5941 | CXXCastPath BasePath; |
| 5942 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5943 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5944 | |
| 5945 | return ImplicitCastExpr::Create(Importer.getToContext(), T, E->getCastKind(), |
John McCall | 2536c6d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 5946 | SubExpr, &BasePath, E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5947 | } |
| 5948 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5949 | Expr *ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5950 | QualType T = Importer.Import(E->getType()); |
| 5951 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5952 | return nullptr; |
| 5953 | |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5954 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5955 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5956 | return nullptr; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5957 | |
| 5958 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeInfoAsWritten()); |
| 5959 | if (!TInfo && E->getTypeInfoAsWritten()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5960 | return nullptr; |
| 5961 | |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5962 | CXXCastPath BasePath; |
| 5963 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5964 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5965 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5966 | switch (E->getStmtClass()) { |
| 5967 | case Stmt::CStyleCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5968 | auto *CCE = cast<CStyleCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5969 | return CStyleCastExpr::Create(Importer.getToContext(), T, |
| 5970 | E->getValueKind(), E->getCastKind(), |
| 5971 | SubExpr, &BasePath, TInfo, |
| 5972 | Importer.Import(CCE->getLParenLoc()), |
| 5973 | Importer.Import(CCE->getRParenLoc())); |
| 5974 | } |
| 5975 | |
| 5976 | case Stmt::CXXFunctionalCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5977 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5978 | return CXXFunctionalCastExpr::Create(Importer.getToContext(), T, |
| 5979 | E->getValueKind(), TInfo, |
| 5980 | E->getCastKind(), SubExpr, &BasePath, |
| 5981 | Importer.Import(FCE->getLParenLoc()), |
| 5982 | Importer.Import(FCE->getRParenLoc())); |
| 5983 | } |
| 5984 | |
| 5985 | case Stmt::ObjCBridgedCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5986 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5987 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 5988 | Importer.Import(OCE->getLParenLoc()), OCE->getBridgeKind(), |
| 5989 | E->getCastKind(), Importer.Import(OCE->getBridgeKeywordLoc()), |
| 5990 | TInfo, SubExpr); |
| 5991 | } |
| 5992 | default: |
| 5993 | break; // just fall through |
| 5994 | } |
| 5995 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5996 | auto *Named = cast<CXXNamedCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5997 | SourceLocation ExprLoc = Importer.Import(Named->getOperatorLoc()), |
| 5998 | RParenLoc = Importer.Import(Named->getRParenLoc()); |
| 5999 | SourceRange Brackets = Importer.Import(Named->getAngleBrackets()); |
| 6000 | |
| 6001 | switch (E->getStmtClass()) { |
| 6002 | case Stmt::CXXStaticCastExprClass: |
| 6003 | return CXXStaticCastExpr::Create(Importer.getToContext(), T, |
| 6004 | E->getValueKind(), E->getCastKind(), |
| 6005 | SubExpr, &BasePath, TInfo, |
| 6006 | ExprLoc, RParenLoc, Brackets); |
| 6007 | |
| 6008 | case Stmt::CXXDynamicCastExprClass: |
| 6009 | return CXXDynamicCastExpr::Create(Importer.getToContext(), T, |
| 6010 | E->getValueKind(), E->getCastKind(), |
| 6011 | SubExpr, &BasePath, TInfo, |
| 6012 | ExprLoc, RParenLoc, Brackets); |
| 6013 | |
| 6014 | case Stmt::CXXReinterpretCastExprClass: |
| 6015 | return CXXReinterpretCastExpr::Create(Importer.getToContext(), T, |
| 6016 | E->getValueKind(), E->getCastKind(), |
| 6017 | SubExpr, &BasePath, TInfo, |
| 6018 | ExprLoc, RParenLoc, Brackets); |
| 6019 | |
| 6020 | case Stmt::CXXConstCastExprClass: |
| 6021 | return CXXConstCastExpr::Create(Importer.getToContext(), T, |
| 6022 | E->getValueKind(), SubExpr, TInfo, ExprLoc, |
| 6023 | RParenLoc, Brackets); |
| 6024 | default: |
| 6025 | llvm_unreachable("Cast expression of unsupported type!"); |
| 6026 | return nullptr; |
| 6027 | } |
| 6028 | } |
| 6029 | |
| 6030 | Expr *ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *OE) { |
| 6031 | QualType T = Importer.Import(OE->getType()); |
| 6032 | if (T.isNull()) |
| 6033 | return nullptr; |
| 6034 | |
| 6035 | SmallVector<OffsetOfNode, 4> Nodes; |
| 6036 | for (int I = 0, E = OE->getNumComponents(); I < E; ++I) { |
| 6037 | const OffsetOfNode &Node = OE->getComponent(I); |
| 6038 | |
| 6039 | switch (Node.getKind()) { |
| 6040 | case OffsetOfNode::Array: |
| 6041 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), |
| 6042 | Node.getArrayExprIndex(), |
| 6043 | Importer.Import(Node.getLocEnd()))); |
| 6044 | break; |
| 6045 | |
| 6046 | case OffsetOfNode::Base: { |
| 6047 | CXXBaseSpecifier *BS = Importer.Import(Node.getBase()); |
| 6048 | if (!BS && Node.getBase()) |
| 6049 | return nullptr; |
| 6050 | Nodes.push_back(OffsetOfNode(BS)); |
| 6051 | break; |
| 6052 | } |
| 6053 | case OffsetOfNode::Field: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6054 | auto *FD = cast_or_null<FieldDecl>(Importer.Import(Node.getField())); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6055 | if (!FD) |
| 6056 | return nullptr; |
| 6057 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), FD, |
| 6058 | Importer.Import(Node.getLocEnd()))); |
| 6059 | break; |
| 6060 | } |
| 6061 | case OffsetOfNode::Identifier: { |
| 6062 | IdentifierInfo *ToII = Importer.Import(Node.getFieldName()); |
| 6063 | if (!ToII) |
| 6064 | return nullptr; |
| 6065 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), ToII, |
| 6066 | Importer.Import(Node.getLocEnd()))); |
| 6067 | break; |
| 6068 | } |
| 6069 | } |
| 6070 | } |
| 6071 | |
| 6072 | SmallVector<Expr *, 4> Exprs(OE->getNumExpressions()); |
| 6073 | for (int I = 0, E = OE->getNumExpressions(); I < E; ++I) { |
| 6074 | Expr *ToIndexExpr = Importer.Import(OE->getIndexExpr(I)); |
| 6075 | if (!ToIndexExpr) |
| 6076 | return nullptr; |
| 6077 | Exprs[I] = ToIndexExpr; |
| 6078 | } |
| 6079 | |
| 6080 | TypeSourceInfo *TInfo = Importer.Import(OE->getTypeSourceInfo()); |
| 6081 | if (!TInfo && OE->getTypeSourceInfo()) |
| 6082 | return nullptr; |
| 6083 | |
| 6084 | return OffsetOfExpr::Create(Importer.getToContext(), T, |
| 6085 | Importer.Import(OE->getOperatorLoc()), |
| 6086 | TInfo, Nodes, Exprs, |
| 6087 | Importer.Import(OE->getRParenLoc())); |
| 6088 | } |
| 6089 | |
| 6090 | Expr *ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 6091 | QualType T = Importer.Import(E->getType()); |
| 6092 | if (T.isNull()) |
| 6093 | return nullptr; |
| 6094 | |
| 6095 | Expr *Operand = Importer.Import(E->getOperand()); |
| 6096 | if (!Operand) |
| 6097 | return nullptr; |
| 6098 | |
| 6099 | CanThrowResult CanThrow; |
| 6100 | if (E->isValueDependent()) |
| 6101 | CanThrow = CT_Dependent; |
| 6102 | else |
| 6103 | CanThrow = E->getValue() ? CT_Can : CT_Cannot; |
| 6104 | |
| 6105 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 6106 | T, Operand, CanThrow, |
| 6107 | Importer.Import(E->getLocStart()), Importer.Import(E->getLocEnd())); |
| 6108 | } |
| 6109 | |
| 6110 | Expr *ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 6111 | QualType T = Importer.Import(E->getType()); |
| 6112 | if (T.isNull()) |
| 6113 | return nullptr; |
| 6114 | |
| 6115 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 6116 | if (!SubExpr && E->getSubExpr()) |
| 6117 | return nullptr; |
| 6118 | |
| 6119 | return new (Importer.getToContext()) CXXThrowExpr( |
| 6120 | SubExpr, T, Importer.Import(E->getThrowLoc()), |
| 6121 | E->isThrownVariableInScope()); |
| 6122 | } |
| 6123 | |
| 6124 | Expr *ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6125 | auto *Param = cast_or_null<ParmVarDecl>(Importer.Import(E->getParam())); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6126 | if (!Param) |
| 6127 | return nullptr; |
| 6128 | |
| 6129 | return CXXDefaultArgExpr::Create( |
| 6130 | Importer.getToContext(), Importer.Import(E->getUsedLocation()), Param); |
| 6131 | } |
| 6132 | |
| 6133 | Expr *ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 6134 | QualType T = Importer.Import(E->getType()); |
| 6135 | if (T.isNull()) |
| 6136 | return nullptr; |
| 6137 | |
| 6138 | TypeSourceInfo *TypeInfo = Importer.Import(E->getTypeSourceInfo()); |
| 6139 | if (!TypeInfo) |
| 6140 | return nullptr; |
| 6141 | |
| 6142 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
| 6143 | T, TypeInfo, Importer.Import(E->getRParenLoc())); |
| 6144 | } |
| 6145 | |
| 6146 | Expr *ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 6147 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 6148 | if (!SubExpr) |
| 6149 | return nullptr; |
| 6150 | |
| 6151 | auto *Dtor = cast_or_null<CXXDestructorDecl>( |
| 6152 | Importer.Import(const_cast<CXXDestructorDecl *>( |
| 6153 | E->getTemporary()->getDestructor()))); |
| 6154 | if (!Dtor) |
| 6155 | return nullptr; |
| 6156 | |
| 6157 | ASTContext &ToCtx = Importer.getToContext(); |
| 6158 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, Dtor); |
| 6159 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, SubExpr); |
| 6160 | } |
| 6161 | |
| 6162 | Expr *ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE) { |
| 6163 | QualType T = Importer.Import(CE->getType()); |
| 6164 | if (T.isNull()) |
| 6165 | return nullptr; |
| 6166 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6167 | TypeSourceInfo *TInfo = Importer.Import(CE->getTypeSourceInfo()); |
| 6168 | if (!TInfo) |
| 6169 | return nullptr; |
| 6170 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6171 | SmallVector<Expr *, 8> Args(CE->getNumArgs()); |
| 6172 | if (ImportContainerChecked(CE->arguments(), Args)) |
| 6173 | return nullptr; |
| 6174 | |
| 6175 | auto *Ctor = cast_or_null<CXXConstructorDecl>( |
| 6176 | Importer.Import(CE->getConstructor())); |
| 6177 | if (!Ctor) |
| 6178 | return nullptr; |
| 6179 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6180 | return new (Importer.getToContext()) CXXTemporaryObjectExpr( |
| 6181 | Importer.getToContext(), Ctor, T, TInfo, Args, |
| 6182 | Importer.Import(CE->getParenOrBraceRange()), CE->hadMultipleCandidates(), |
| 6183 | CE->isListInitialization(), CE->isStdInitListInitialization(), |
| 6184 | CE->requiresZeroInitialization()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6185 | } |
| 6186 | |
| 6187 | Expr * |
| 6188 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
| 6189 | QualType T = Importer.Import(E->getType()); |
| 6190 | if (T.isNull()) |
| 6191 | return nullptr; |
| 6192 | |
| 6193 | Expr *TempE = Importer.Import(E->GetTemporaryExpr()); |
| 6194 | if (!TempE) |
| 6195 | return nullptr; |
| 6196 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6197 | auto *ExtendedBy = cast_or_null<ValueDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6198 | Importer.Import(const_cast<ValueDecl *>(E->getExtendingDecl()))); |
| 6199 | if (!ExtendedBy && E->getExtendingDecl()) |
| 6200 | return nullptr; |
| 6201 | |
| 6202 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
| 6203 | T, TempE, E->isBoundToLvalueReference()); |
| 6204 | |
| 6205 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
| 6206 | ToMTE->setExtendingDecl(ExtendedBy, E->getManglingNumber()); |
| 6207 | return ToMTE; |
| 6208 | } |
| 6209 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6210 | Expr *ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 6211 | QualType T = Importer.Import(E->getType()); |
| 6212 | if (T.isNull()) |
| 6213 | return nullptr; |
| 6214 | |
| 6215 | Expr *Pattern = Importer.Import(E->getPattern()); |
| 6216 | if (!Pattern) |
| 6217 | return nullptr; |
| 6218 | |
| 6219 | return new (Importer.getToContext()) PackExpansionExpr( |
| 6220 | T, Pattern, Importer.Import(E->getEllipsisLoc()), |
| 6221 | E->getNumExpansions()); |
| 6222 | } |
| 6223 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6224 | Expr *ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 6225 | auto *Pack = cast_or_null<NamedDecl>(Importer.Import(E->getPack())); |
| 6226 | if (!Pack) |
| 6227 | return nullptr; |
| 6228 | |
| 6229 | Optional<unsigned> Length; |
| 6230 | |
| 6231 | if (!E->isValueDependent()) |
| 6232 | Length = E->getPackLength(); |
| 6233 | |
| 6234 | SmallVector<TemplateArgument, 8> PartialArguments; |
| 6235 | if (E->isPartiallySubstituted()) { |
| 6236 | if (ImportTemplateArguments(E->getPartialArguments().data(), |
| 6237 | E->getPartialArguments().size(), |
| 6238 | PartialArguments)) |
| 6239 | return nullptr; |
| 6240 | } |
| 6241 | |
| 6242 | return SizeOfPackExpr::Create( |
| 6243 | Importer.getToContext(), Importer.Import(E->getOperatorLoc()), Pack, |
| 6244 | Importer.Import(E->getPackLoc()), Importer.Import(E->getRParenLoc()), |
| 6245 | Length, PartialArguments); |
| 6246 | } |
| 6247 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6248 | Expr *ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *CE) { |
| 6249 | QualType T = Importer.Import(CE->getType()); |
| 6250 | if (T.isNull()) |
| 6251 | return nullptr; |
| 6252 | |
| 6253 | SmallVector<Expr *, 4> PlacementArgs(CE->getNumPlacementArgs()); |
| 6254 | if (ImportContainerChecked(CE->placement_arguments(), PlacementArgs)) |
| 6255 | return nullptr; |
| 6256 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6257 | auto *OperatorNewDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6258 | Importer.Import(CE->getOperatorNew())); |
| 6259 | if (!OperatorNewDecl && CE->getOperatorNew()) |
| 6260 | return nullptr; |
| 6261 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6262 | auto *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6263 | Importer.Import(CE->getOperatorDelete())); |
| 6264 | if (!OperatorDeleteDecl && CE->getOperatorDelete()) |
| 6265 | return nullptr; |
| 6266 | |
| 6267 | Expr *ToInit = Importer.Import(CE->getInitializer()); |
| 6268 | if (!ToInit && CE->getInitializer()) |
| 6269 | return nullptr; |
| 6270 | |
| 6271 | TypeSourceInfo *TInfo = Importer.Import(CE->getAllocatedTypeSourceInfo()); |
| 6272 | if (!TInfo) |
| 6273 | return nullptr; |
| 6274 | |
| 6275 | Expr *ToArrSize = Importer.Import(CE->getArraySize()); |
| 6276 | if (!ToArrSize && CE->getArraySize()) |
| 6277 | return nullptr; |
| 6278 | |
| 6279 | return new (Importer.getToContext()) CXXNewExpr( |
| 6280 | Importer.getToContext(), |
| 6281 | CE->isGlobalNew(), |
| 6282 | OperatorNewDecl, OperatorDeleteDecl, |
Richard Smith | b2f0f05 | 2016-10-10 18:54:32 +0000 | [diff] [blame] | 6283 | CE->passAlignment(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6284 | CE->doesUsualArrayDeleteWantSize(), |
| 6285 | PlacementArgs, |
| 6286 | Importer.Import(CE->getTypeIdParens()), |
| 6287 | ToArrSize, CE->getInitializationStyle(), ToInit, T, TInfo, |
| 6288 | Importer.Import(CE->getSourceRange()), |
| 6289 | Importer.Import(CE->getDirectInitRange())); |
| 6290 | } |
| 6291 | |
| 6292 | Expr *ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 6293 | QualType T = Importer.Import(E->getType()); |
| 6294 | if (T.isNull()) |
| 6295 | return nullptr; |
| 6296 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6297 | auto *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6298 | Importer.Import(E->getOperatorDelete())); |
| 6299 | if (!OperatorDeleteDecl && E->getOperatorDelete()) |
| 6300 | return nullptr; |
| 6301 | |
| 6302 | Expr *ToArg = Importer.Import(E->getArgument()); |
| 6303 | if (!ToArg && E->getArgument()) |
| 6304 | return nullptr; |
| 6305 | |
| 6306 | return new (Importer.getToContext()) CXXDeleteExpr( |
| 6307 | T, E->isGlobalDelete(), |
| 6308 | E->isArrayForm(), |
| 6309 | E->isArrayFormAsWritten(), |
| 6310 | E->doesUsualArrayDeleteWantSize(), |
| 6311 | OperatorDeleteDecl, |
| 6312 | ToArg, |
| 6313 | Importer.Import(E->getLocStart())); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6314 | } |
| 6315 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6316 | Expr *ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 6317 | QualType T = Importer.Import(E->getType()); |
| 6318 | if (T.isNull()) |
| 6319 | return nullptr; |
| 6320 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6321 | auto *ToCCD = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6322 | dyn_cast_or_null<CXXConstructorDecl>(Importer.Import(E->getConstructor())); |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 6323 | if (!ToCCD) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6324 | return nullptr; |
| 6325 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6326 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6327 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6328 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6329 | |
| 6330 | return CXXConstructExpr::Create(Importer.getToContext(), T, |
| 6331 | Importer.Import(E->getLocation()), |
Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 6332 | ToCCD, E->isElidable(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6333 | ToArgs, E->hadMultipleCandidates(), |
| 6334 | E->isListInitialization(), |
| 6335 | E->isStdInitListInitialization(), |
| 6336 | E->requiresZeroInitialization(), |
| 6337 | E->getConstructionKind(), |
| 6338 | Importer.Import(E->getParenOrBraceRange())); |
| 6339 | } |
| 6340 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6341 | Expr *ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *EWC) { |
| 6342 | Expr *SubExpr = Importer.Import(EWC->getSubExpr()); |
| 6343 | if (!SubExpr && EWC->getSubExpr()) |
| 6344 | return nullptr; |
| 6345 | |
| 6346 | SmallVector<ExprWithCleanups::CleanupObject, 8> Objs(EWC->getNumObjects()); |
| 6347 | for (unsigned I = 0, E = EWC->getNumObjects(); I < E; I++) |
| 6348 | if (ExprWithCleanups::CleanupObject Obj = |
| 6349 | cast_or_null<BlockDecl>(Importer.Import(EWC->getObject(I)))) |
| 6350 | Objs[I] = Obj; |
| 6351 | else |
| 6352 | return nullptr; |
| 6353 | |
| 6354 | return ExprWithCleanups::Create(Importer.getToContext(), |
| 6355 | SubExpr, EWC->cleanupsHaveSideEffects(), |
| 6356 | Objs); |
| 6357 | } |
| 6358 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6359 | Expr *ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6360 | QualType T = Importer.Import(E->getType()); |
| 6361 | if (T.isNull()) |
| 6362 | return nullptr; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6363 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6364 | Expr *ToFn = Importer.Import(E->getCallee()); |
| 6365 | if (!ToFn) |
| 6366 | return nullptr; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6367 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6368 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6369 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6370 | return nullptr; |
| 6371 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6372 | return new (Importer.getToContext()) CXXMemberCallExpr( |
| 6373 | Importer.getToContext(), ToFn, ToArgs, T, E->getValueKind(), |
| 6374 | Importer.Import(E->getRParenLoc())); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6375 | } |
| 6376 | |
| 6377 | Expr *ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 6378 | QualType T = Importer.Import(E->getType()); |
| 6379 | if (T.isNull()) |
| 6380 | return nullptr; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6381 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6382 | return new (Importer.getToContext()) |
| 6383 | CXXThisExpr(Importer.Import(E->getLocation()), T, E->isImplicit()); |
| 6384 | } |
| 6385 | |
| 6386 | Expr *ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 6387 | QualType T = Importer.Import(E->getType()); |
| 6388 | if (T.isNull()) |
| 6389 | return nullptr; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6390 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6391 | return new (Importer.getToContext()) |
| 6392 | CXXBoolLiteralExpr(E->getValue(), T, Importer.Import(E->getLocation())); |
| 6393 | } |
| 6394 | |
| 6395 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6396 | Expr *ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 6397 | QualType T = Importer.Import(E->getType()); |
| 6398 | if (T.isNull()) |
| 6399 | return nullptr; |
| 6400 | |
| 6401 | Expr *ToBase = Importer.Import(E->getBase()); |
| 6402 | if (!ToBase && E->getBase()) |
| 6403 | return nullptr; |
| 6404 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6405 | auto *ToMember = dyn_cast<ValueDecl>(Importer.Import(E->getMemberDecl())); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6406 | if (!ToMember && E->getMemberDecl()) |
| 6407 | return nullptr; |
| 6408 | |
Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 6409 | auto *ToDecl = |
| 6410 | dyn_cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl().getDecl())); |
| 6411 | if (!ToDecl && E->getFoundDecl().getDecl()) |
| 6412 | return nullptr; |
| 6413 | |
| 6414 | DeclAccessPair ToFoundDecl = |
| 6415 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6416 | |
| 6417 | DeclarationNameInfo ToMemberNameInfo( |
| 6418 | Importer.Import(E->getMemberNameInfo().getName()), |
| 6419 | Importer.Import(E->getMemberNameInfo().getLoc())); |
| 6420 | |
| 6421 | if (E->hasExplicitTemplateArgs()) { |
| 6422 | return nullptr; // FIXME: handle template arguments |
| 6423 | } |
| 6424 | |
| 6425 | return MemberExpr::Create(Importer.getToContext(), ToBase, |
| 6426 | E->isArrow(), |
| 6427 | Importer.Import(E->getOperatorLoc()), |
| 6428 | Importer.Import(E->getQualifierLoc()), |
| 6429 | Importer.Import(E->getTemplateKeywordLoc()), |
| 6430 | ToMember, ToFoundDecl, ToMemberNameInfo, |
| 6431 | nullptr, T, E->getValueKind(), |
| 6432 | E->getObjectKind()); |
| 6433 | } |
| 6434 | |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 6435 | Expr *ASTNodeImporter::VisitCXXPseudoDestructorExpr( |
| 6436 | CXXPseudoDestructorExpr *E) { |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 6437 | Expr *BaseE = Importer.Import(E->getBase()); |
| 6438 | if (!BaseE) |
| 6439 | return nullptr; |
| 6440 | |
| 6441 | TypeSourceInfo *ScopeInfo = Importer.Import(E->getScopeTypeInfo()); |
| 6442 | if (!ScopeInfo && E->getScopeTypeInfo()) |
| 6443 | return nullptr; |
| 6444 | |
| 6445 | PseudoDestructorTypeStorage Storage; |
| 6446 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 6447 | IdentifierInfo *ToII = Importer.Import(FromII); |
| 6448 | if (!ToII) |
| 6449 | return nullptr; |
| 6450 | Storage = PseudoDestructorTypeStorage( |
| 6451 | ToII, Importer.Import(E->getDestroyedTypeLoc())); |
| 6452 | } else { |
| 6453 | TypeSourceInfo *TI = Importer.Import(E->getDestroyedTypeInfo()); |
| 6454 | if (!TI) |
| 6455 | return nullptr; |
| 6456 | Storage = PseudoDestructorTypeStorage(TI); |
| 6457 | } |
| 6458 | |
| 6459 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
| 6460 | Importer.getToContext(), BaseE, E->isArrow(), |
| 6461 | Importer.Import(E->getOperatorLoc()), |
| 6462 | Importer.Import(E->getQualifierLoc()), |
| 6463 | ScopeInfo, Importer.Import(E->getColonColonLoc()), |
| 6464 | Importer.Import(E->getTildeLoc()), Storage); |
| 6465 | } |
| 6466 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6467 | Expr *ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
| 6468 | CXXDependentScopeMemberExpr *E) { |
| 6469 | Expr *Base = nullptr; |
| 6470 | if (!E->isImplicitAccess()) { |
| 6471 | Base = Importer.Import(E->getBase()); |
| 6472 | if (!Base) |
| 6473 | return nullptr; |
| 6474 | } |
| 6475 | |
| 6476 | QualType BaseType = Importer.Import(E->getBaseType()); |
| 6477 | if (BaseType.isNull()) |
| 6478 | return nullptr; |
| 6479 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6480 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6481 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6482 | if (ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6483 | E->template_arguments(), ToTAInfo)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6484 | return nullptr; |
| 6485 | ResInfo = &ToTAInfo; |
| 6486 | } |
| 6487 | |
| 6488 | DeclarationName Name = Importer.Import(E->getMember()); |
| 6489 | if (!E->getMember().isEmpty() && Name.isEmpty()) |
| 6490 | return nullptr; |
| 6491 | |
| 6492 | DeclarationNameInfo MemberNameInfo(Name, Importer.Import(E->getMemberLoc())); |
| 6493 | // Import additional name location/type info. |
| 6494 | ImportDeclarationNameLoc(E->getMemberNameInfo(), MemberNameInfo); |
| 6495 | auto ToFQ = Importer.Import(E->getFirstQualifierFoundInScope()); |
| 6496 | if (!ToFQ && E->getFirstQualifierFoundInScope()) |
| 6497 | return nullptr; |
| 6498 | |
| 6499 | return CXXDependentScopeMemberExpr::Create( |
| 6500 | Importer.getToContext(), Base, BaseType, E->isArrow(), |
| 6501 | Importer.Import(E->getOperatorLoc()), |
| 6502 | Importer.Import(E->getQualifierLoc()), |
| 6503 | Importer.Import(E->getTemplateKeywordLoc()), |
| 6504 | cast_or_null<NamedDecl>(ToFQ), MemberNameInfo, ResInfo); |
| 6505 | } |
| 6506 | |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 6507 | Expr * |
| 6508 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
| 6509 | DeclarationName Name = Importer.Import(E->getDeclName()); |
| 6510 | if (!E->getDeclName().isEmpty() && Name.isEmpty()) |
| 6511 | return nullptr; |
| 6512 | |
| 6513 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getExprLoc())); |
| 6514 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6515 | |
| 6516 | TemplateArgumentListInfo ToTAInfo(Importer.Import(E->getLAngleLoc()), |
| 6517 | Importer.Import(E->getRAngleLoc())); |
| 6518 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 6519 | if (E->hasExplicitTemplateArgs()) { |
| 6520 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6521 | return nullptr; |
| 6522 | ResInfo = &ToTAInfo; |
| 6523 | } |
| 6524 | |
| 6525 | return DependentScopeDeclRefExpr::Create( |
| 6526 | Importer.getToContext(), Importer.Import(E->getQualifierLoc()), |
| 6527 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, ResInfo); |
| 6528 | } |
| 6529 | |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6530 | Expr *ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 6531 | CXXUnresolvedConstructExpr *CE) { |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6532 | unsigned NumArgs = CE->arg_size(); |
| 6533 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6534 | SmallVector<Expr *, 8> ToArgs(NumArgs); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6535 | if (ImportArrayChecked(CE->arg_begin(), CE->arg_end(), ToArgs.begin())) |
| 6536 | return nullptr; |
| 6537 | |
| 6538 | return CXXUnresolvedConstructExpr::Create( |
| 6539 | Importer.getToContext(), Importer.Import(CE->getTypeSourceInfo()), |
| 6540 | Importer.Import(CE->getLParenLoc()), llvm::makeArrayRef(ToArgs), |
| 6541 | Importer.Import(CE->getRParenLoc())); |
| 6542 | } |
| 6543 | |
| 6544 | Expr *ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6545 | auto *NamingClass = |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6546 | cast_or_null<CXXRecordDecl>(Importer.Import(E->getNamingClass())); |
| 6547 | if (E->getNamingClass() && !NamingClass) |
| 6548 | return nullptr; |
| 6549 | |
| 6550 | DeclarationName Name = Importer.Import(E->getName()); |
| 6551 | if (E->getName() && !Name) |
| 6552 | return nullptr; |
| 6553 | |
| 6554 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getNameLoc())); |
| 6555 | // Import additional name location/type info. |
| 6556 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6557 | |
| 6558 | UnresolvedSet<8> ToDecls; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6559 | for (auto *D : E->decls()) { |
| 6560 | if (auto *To = cast_or_null<NamedDecl>(Importer.Import(D))) |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6561 | ToDecls.addDecl(To); |
| 6562 | else |
| 6563 | return nullptr; |
| 6564 | } |
| 6565 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6566 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6567 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6568 | if (ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6569 | E->template_arguments(), ToTAInfo)) |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6570 | return nullptr; |
| 6571 | ResInfo = &ToTAInfo; |
| 6572 | } |
| 6573 | |
| 6574 | if (ResInfo || E->getTemplateKeywordLoc().isValid()) |
| 6575 | return UnresolvedLookupExpr::Create( |
| 6576 | Importer.getToContext(), NamingClass, |
| 6577 | Importer.Import(E->getQualifierLoc()), |
| 6578 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, E->requiresADL(), |
| 6579 | ResInfo, ToDecls.begin(), ToDecls.end()); |
| 6580 | |
| 6581 | return UnresolvedLookupExpr::Create( |
| 6582 | Importer.getToContext(), NamingClass, |
| 6583 | Importer.Import(E->getQualifierLoc()), NameInfo, E->requiresADL(), |
| 6584 | E->isOverloaded(), ToDecls.begin(), ToDecls.end()); |
| 6585 | } |
| 6586 | |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 6587 | Expr *ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 6588 | DeclarationName Name = Importer.Import(E->getName()); |
| 6589 | if (!E->getName().isEmpty() && Name.isEmpty()) |
| 6590 | return nullptr; |
| 6591 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getNameLoc())); |
| 6592 | // Import additional name location/type info. |
| 6593 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6594 | |
| 6595 | QualType BaseType = Importer.Import(E->getType()); |
| 6596 | if (!E->getType().isNull() && BaseType.isNull()) |
| 6597 | return nullptr; |
| 6598 | |
| 6599 | UnresolvedSet<8> ToDecls; |
| 6600 | for (Decl *D : E->decls()) { |
| 6601 | if (NamedDecl *To = cast_or_null<NamedDecl>(Importer.Import(D))) |
| 6602 | ToDecls.addDecl(To); |
| 6603 | else |
| 6604 | return nullptr; |
| 6605 | } |
| 6606 | |
| 6607 | TemplateArgumentListInfo ToTAInfo; |
| 6608 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 6609 | if (E->hasExplicitTemplateArgs()) { |
| 6610 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6611 | return nullptr; |
| 6612 | ResInfo = &ToTAInfo; |
| 6613 | } |
| 6614 | |
| 6615 | Expr *BaseE = E->isImplicitAccess() ? nullptr : Importer.Import(E->getBase()); |
| 6616 | if (!BaseE && !E->isImplicitAccess() && E->getBase()) { |
| 6617 | return nullptr; |
| 6618 | } |
| 6619 | |
| 6620 | return UnresolvedMemberExpr::Create( |
| 6621 | Importer.getToContext(), E->hasUnresolvedUsing(), BaseE, BaseType, |
| 6622 | E->isArrow(), Importer.Import(E->getOperatorLoc()), |
| 6623 | Importer.Import(E->getQualifierLoc()), |
| 6624 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, ResInfo, |
| 6625 | ToDecls.begin(), ToDecls.end()); |
| 6626 | } |
| 6627 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6628 | Expr *ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 6629 | QualType T = Importer.Import(E->getType()); |
| 6630 | if (T.isNull()) |
| 6631 | return nullptr; |
| 6632 | |
| 6633 | Expr *ToCallee = Importer.Import(E->getCallee()); |
| 6634 | if (!ToCallee && E->getCallee()) |
| 6635 | return nullptr; |
| 6636 | |
| 6637 | unsigned NumArgs = E->getNumArgs(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6638 | SmallVector<Expr *, 2> ToArgs(NumArgs); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6639 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
| 6640 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6641 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6642 | auto **ToArgs_Copied = new (Importer.getToContext()) Expr*[NumArgs]; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6643 | |
| 6644 | for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) |
| 6645 | ToArgs_Copied[ai] = ToArgs[ai]; |
| 6646 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6647 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| 6648 | return new (Importer.getToContext()) CXXOperatorCallExpr( |
| 6649 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, T, |
| 6650 | OCE->getValueKind(), Importer.Import(OCE->getRParenLoc()), |
| 6651 | OCE->getFPFeatures()); |
| 6652 | } |
| 6653 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6654 | return new (Importer.getToContext()) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6655 | CallExpr(Importer.getToContext(), ToCallee, |
Craig Topper | c005cc0 | 2015-09-27 03:44:08 +0000 | [diff] [blame] | 6656 | llvm::makeArrayRef(ToArgs_Copied, NumArgs), T, E->getValueKind(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6657 | Importer.Import(E->getRParenLoc())); |
| 6658 | } |
| 6659 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6660 | Optional<LambdaCapture> |
| 6661 | ASTNodeImporter::ImportLambdaCapture(const LambdaCapture &From) { |
| 6662 | VarDecl *Var = nullptr; |
| 6663 | if (From.capturesVariable()) { |
| 6664 | Var = cast_or_null<VarDecl>(Importer.Import(From.getCapturedVar())); |
| 6665 | if (!Var) |
| 6666 | return None; |
| 6667 | } |
| 6668 | |
| 6669 | return LambdaCapture(Importer.Import(From.getLocation()), From.isImplicit(), |
| 6670 | From.getCaptureKind(), Var, |
| 6671 | From.isPackExpansion() |
| 6672 | ? Importer.Import(From.getEllipsisLoc()) |
| 6673 | : SourceLocation()); |
| 6674 | } |
| 6675 | |
| 6676 | Expr *ASTNodeImporter::VisitLambdaExpr(LambdaExpr *LE) { |
| 6677 | CXXRecordDecl *FromClass = LE->getLambdaClass(); |
| 6678 | auto *ToClass = dyn_cast_or_null<CXXRecordDecl>(Importer.Import(FromClass)); |
| 6679 | if (!ToClass) |
| 6680 | return nullptr; |
| 6681 | |
| 6682 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 6683 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 6684 | // manually. |
| 6685 | if (ToClass->isBeingDefined()) { |
| 6686 | for (auto FromField : FromClass->fields()) { |
| 6687 | auto *ToField = cast_or_null<FieldDecl>(Importer.Import(FromField)); |
| 6688 | if (!ToField) |
| 6689 | return nullptr; |
| 6690 | } |
| 6691 | } |
| 6692 | |
| 6693 | auto *ToCallOp = dyn_cast_or_null<CXXMethodDecl>( |
| 6694 | Importer.Import(LE->getCallOperator())); |
| 6695 | if (!ToCallOp) |
| 6696 | return nullptr; |
| 6697 | |
| 6698 | ToClass->completeDefinition(); |
| 6699 | |
| 6700 | unsigned NumCaptures = LE->capture_size(); |
| 6701 | SmallVector<LambdaCapture, 8> Captures; |
| 6702 | Captures.reserve(NumCaptures); |
| 6703 | for (const auto &FromCapture : LE->captures()) { |
| 6704 | if (auto ToCapture = ImportLambdaCapture(FromCapture)) |
| 6705 | Captures.push_back(*ToCapture); |
| 6706 | else |
| 6707 | return nullptr; |
| 6708 | } |
| 6709 | |
| 6710 | SmallVector<Expr *, 8> InitCaptures(NumCaptures); |
| 6711 | if (ImportContainerChecked(LE->capture_inits(), InitCaptures)) |
| 6712 | return nullptr; |
| 6713 | |
| 6714 | return LambdaExpr::Create(Importer.getToContext(), ToClass, |
| 6715 | Importer.Import(LE->getIntroducerRange()), |
| 6716 | LE->getCaptureDefault(), |
| 6717 | Importer.Import(LE->getCaptureDefaultLoc()), |
| 6718 | Captures, |
| 6719 | LE->hasExplicitParameters(), |
| 6720 | LE->hasExplicitResultType(), |
| 6721 | InitCaptures, |
| 6722 | Importer.Import(LE->getLocEnd()), |
| 6723 | LE->containsUnexpandedParameterPack()); |
| 6724 | } |
| 6725 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6726 | Expr *ASTNodeImporter::VisitInitListExpr(InitListExpr *ILE) { |
| 6727 | QualType T = Importer.Import(ILE->getType()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6728 | if (T.isNull()) |
| 6729 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6730 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6731 | SmallVector<Expr *, 4> Exprs(ILE->getNumInits()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6732 | if (ImportContainerChecked(ILE->inits(), Exprs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6733 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6734 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6735 | ASTContext &ToCtx = Importer.getToContext(); |
| 6736 | InitListExpr *To = new (ToCtx) InitListExpr( |
| 6737 | ToCtx, Importer.Import(ILE->getLBraceLoc()), |
| 6738 | Exprs, Importer.Import(ILE->getLBraceLoc())); |
| 6739 | To->setType(T); |
| 6740 | |
| 6741 | if (ILE->hasArrayFiller()) { |
| 6742 | Expr *Filler = Importer.Import(ILE->getArrayFiller()); |
| 6743 | if (!Filler) |
| 6744 | return nullptr; |
| 6745 | To->setArrayFiller(Filler); |
| 6746 | } |
| 6747 | |
| 6748 | if (FieldDecl *FromFD = ILE->getInitializedFieldInUnion()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6749 | auto *ToFD = cast_or_null<FieldDecl>(Importer.Import(FromFD)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6750 | if (!ToFD) |
| 6751 | return nullptr; |
| 6752 | To->setInitializedFieldInUnion(ToFD); |
| 6753 | } |
| 6754 | |
| 6755 | if (InitListExpr *SyntForm = ILE->getSyntacticForm()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6756 | auto *ToSyntForm = cast_or_null<InitListExpr>(Importer.Import(SyntForm)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6757 | if (!ToSyntForm) |
| 6758 | return nullptr; |
| 6759 | To->setSyntacticForm(ToSyntForm); |
| 6760 | } |
| 6761 | |
| 6762 | To->sawArrayRangeDesignator(ILE->hadArrayRangeDesignator()); |
| 6763 | To->setValueDependent(ILE->isValueDependent()); |
| 6764 | To->setInstantiationDependent(ILE->isInstantiationDependent()); |
| 6765 | |
| 6766 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6767 | } |
| 6768 | |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 6769 | Expr *ASTNodeImporter::VisitCXXStdInitializerListExpr( |
| 6770 | CXXStdInitializerListExpr *E) { |
| 6771 | QualType T = Importer.Import(E->getType()); |
| 6772 | if (T.isNull()) |
| 6773 | return nullptr; |
| 6774 | |
| 6775 | Expr *SE = Importer.Import(E->getSubExpr()); |
| 6776 | if (!SE) |
| 6777 | return nullptr; |
| 6778 | |
| 6779 | return new (Importer.getToContext()) CXXStdInitializerListExpr(T, SE); |
| 6780 | } |
| 6781 | |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame] | 6782 | Expr *ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
| 6783 | CXXInheritedCtorInitExpr *E) { |
| 6784 | QualType T = Importer.Import(E->getType()); |
| 6785 | if (T.isNull()) |
| 6786 | return nullptr; |
| 6787 | |
| 6788 | auto *Ctor = cast_or_null<CXXConstructorDecl>(Importer.Import( |
| 6789 | E->getConstructor())); |
| 6790 | if (!Ctor) |
| 6791 | return nullptr; |
| 6792 | |
| 6793 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
| 6794 | Importer.Import(E->getLocation()), T, Ctor, |
| 6795 | E->constructsVBase(), E->inheritedFromVBase()); |
| 6796 | } |
| 6797 | |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 6798 | Expr *ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 6799 | QualType ToType = Importer.Import(E->getType()); |
| 6800 | if (ToType.isNull()) |
| 6801 | return nullptr; |
| 6802 | |
| 6803 | Expr *ToCommon = Importer.Import(E->getCommonExpr()); |
| 6804 | if (!ToCommon && E->getCommonExpr()) |
| 6805 | return nullptr; |
| 6806 | |
| 6807 | Expr *ToSubExpr = Importer.Import(E->getSubExpr()); |
| 6808 | if (!ToSubExpr && E->getSubExpr()) |
| 6809 | return nullptr; |
| 6810 | |
| 6811 | return new (Importer.getToContext()) |
| 6812 | ArrayInitLoopExpr(ToType, ToCommon, ToSubExpr); |
| 6813 | } |
| 6814 | |
| 6815 | Expr *ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 6816 | QualType ToType = Importer.Import(E->getType()); |
| 6817 | if (ToType.isNull()) |
| 6818 | return nullptr; |
| 6819 | return new (Importer.getToContext()) ArrayInitIndexExpr(ToType); |
| 6820 | } |
| 6821 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6822 | Expr *ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6823 | auto *ToField = dyn_cast_or_null<FieldDecl>(Importer.Import(DIE->getField())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6824 | if (!ToField && DIE->getField()) |
| 6825 | return nullptr; |
| 6826 | |
| 6827 | return CXXDefaultInitExpr::Create( |
| 6828 | Importer.getToContext(), Importer.Import(DIE->getLocStart()), ToField); |
| 6829 | } |
| 6830 | |
| 6831 | Expr *ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 6832 | QualType ToType = Importer.Import(E->getType()); |
| 6833 | if (ToType.isNull() && !E->getType().isNull()) |
| 6834 | return nullptr; |
| 6835 | ExprValueKind VK = E->getValueKind(); |
| 6836 | CastKind CK = E->getCastKind(); |
| 6837 | Expr *ToOp = Importer.Import(E->getSubExpr()); |
| 6838 | if (!ToOp && E->getSubExpr()) |
| 6839 | return nullptr; |
| 6840 | CXXCastPath BasePath; |
| 6841 | if (ImportCastPath(E, BasePath)) |
| 6842 | return nullptr; |
| 6843 | TypeSourceInfo *ToWritten = Importer.Import(E->getTypeInfoAsWritten()); |
| 6844 | SourceLocation ToOperatorLoc = Importer.Import(E->getOperatorLoc()); |
| 6845 | SourceLocation ToRParenLoc = Importer.Import(E->getRParenLoc()); |
| 6846 | SourceRange ToAngleBrackets = Importer.Import(E->getAngleBrackets()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6847 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6848 | if (isa<CXXStaticCastExpr>(E)) { |
| 6849 | return CXXStaticCastExpr::Create( |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6850 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6851 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6852 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 6853 | return CXXDynamicCastExpr::Create( |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6854 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6855 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6856 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 6857 | return CXXReinterpretCastExpr::Create( |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6858 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6859 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6860 | } else { |
| 6861 | return nullptr; |
| 6862 | } |
| 6863 | } |
| 6864 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6865 | Expr *ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
| 6866 | SubstNonTypeTemplateParmExpr *E) { |
| 6867 | QualType T = Importer.Import(E->getType()); |
| 6868 | if (T.isNull()) |
| 6869 | return nullptr; |
| 6870 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6871 | auto *Param = cast_or_null<NonTypeTemplateParmDecl>( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6872 | Importer.Import(E->getParameter())); |
| 6873 | if (!Param) |
| 6874 | return nullptr; |
| 6875 | |
| 6876 | Expr *Replacement = Importer.Import(E->getReplacement()); |
| 6877 | if (!Replacement) |
| 6878 | return nullptr; |
| 6879 | |
| 6880 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
| 6881 | T, E->getValueKind(), Importer.Import(E->getExprLoc()), Param, |
| 6882 | Replacement); |
| 6883 | } |
| 6884 | |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 6885 | Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 6886 | QualType ToType = Importer.Import(E->getType()); |
| 6887 | if (ToType.isNull()) |
| 6888 | return nullptr; |
| 6889 | |
| 6890 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
| 6891 | if (ImportContainerChecked(E->getArgs(), ToArgs)) |
| 6892 | return nullptr; |
| 6893 | |
| 6894 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 6895 | // Value is always false. |
| 6896 | bool ToValue = false; |
| 6897 | if (!E->isValueDependent()) |
| 6898 | ToValue = E->getValue(); |
| 6899 | |
| 6900 | return TypeTraitExpr::Create( |
| 6901 | Importer.getToContext(), ToType, Importer.Import(E->getLocStart()), |
| 6902 | E->getTrait(), ToArgs, Importer.Import(E->getLocEnd()), ToValue); |
| 6903 | } |
| 6904 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6905 | Expr *ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 6906 | QualType ToType = Importer.Import(E->getType()); |
| 6907 | if (ToType.isNull()) |
| 6908 | return nullptr; |
| 6909 | |
| 6910 | if (E->isTypeOperand()) { |
| 6911 | TypeSourceInfo *TSI = Importer.Import(E->getTypeOperandSourceInfo()); |
| 6912 | if (!TSI) |
| 6913 | return nullptr; |
| 6914 | |
| 6915 | return new (Importer.getToContext()) |
| 6916 | CXXTypeidExpr(ToType, TSI, Importer.Import(E->getSourceRange())); |
| 6917 | } |
| 6918 | |
| 6919 | Expr *Op = Importer.Import(E->getExprOperand()); |
| 6920 | if (!Op) |
| 6921 | return nullptr; |
| 6922 | |
| 6923 | return new (Importer.getToContext()) |
| 6924 | CXXTypeidExpr(ToType, Op, Importer.Import(E->getSourceRange())); |
| 6925 | } |
| 6926 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 6927 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 6928 | CXXMethodDecl *FromMethod) { |
| 6929 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) |
| 6930 | ToMethod->addOverriddenMethod( |
| 6931 | cast<CXXMethodDecl>(Importer.Import(const_cast<CXXMethodDecl*>( |
| 6932 | FromOverriddenMethod)))); |
| 6933 | } |
| 6934 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6935 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6936 | ASTContext &FromContext, FileManager &FromFileManager, |
| 6937 | bool MinimalImport) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6938 | : ToContext(ToContext), FromContext(FromContext), |
| 6939 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| 6940 | Minimal(MinimalImport) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6941 | ImportedDecls[FromContext.getTranslationUnitDecl()] |
| 6942 | = ToContext.getTranslationUnitDecl(); |
| 6943 | } |
| 6944 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6945 | ASTImporter::~ASTImporter() = default; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6946 | |
| 6947 | QualType ASTImporter::Import(QualType FromT) { |
| 6948 | if (FromT.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6949 | return {}; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6950 | |
| 6951 | const Type *fromTy = FromT.getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6952 | |
| 6953 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6954 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
| 6955 | = ImportedTypes.find(fromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6956 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6957 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6958 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6959 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6960 | ASTNodeImporter Importer(*this); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6961 | QualType ToT = Importer.Visit(fromTy); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6962 | if (ToT.isNull()) |
| 6963 | return ToT; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6964 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6965 | // Record the imported type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6966 | ImportedTypes[fromTy] = ToT.getTypePtr(); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6967 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6968 | return ToContext.getQualifiedType(ToT, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6969 | } |
| 6970 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6971 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 6972 | if (!FromTSI) |
| 6973 | return FromTSI; |
| 6974 | |
| 6975 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 6976 | // 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] | 6977 | QualType T = Import(FromTSI->getType()); |
| 6978 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6979 | return nullptr; |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 6980 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6981 | return ToContext.getTrivialTypeSourceInfo(T, |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6982 | Import(FromTSI->getTypeLoc().getLocStart())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6983 | } |
| 6984 | |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 6985 | Attr *ASTImporter::Import(const Attr *FromAttr) { |
| 6986 | Attr *ToAttr = FromAttr->clone(ToContext); |
| 6987 | ToAttr->setRange(Import(FromAttr->getRange())); |
| 6988 | return ToAttr; |
| 6989 | } |
| 6990 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6991 | Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) { |
| 6992 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
| 6993 | if (Pos != ImportedDecls.end()) { |
| 6994 | Decl *ToD = Pos->second; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 6995 | // FIXME: move this call to ImportDeclParts(). |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6996 | ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD); |
| 6997 | return ToD; |
| 6998 | } else { |
| 6999 | return nullptr; |
| 7000 | } |
| 7001 | } |
| 7002 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7003 | Decl *ASTImporter::Import(Decl *FromD) { |
| 7004 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7005 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7006 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7007 | ASTNodeImporter Importer(*this); |
| 7008 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7009 | // Check whether we've already imported this declaration. |
| 7010 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 7011 | if (ToD) { |
| 7012 | // If FromD has some updated flags after last import, apply it |
| 7013 | updateFlags(FromD, ToD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7014 | return ToD; |
| 7015 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7016 | |
| 7017 | // Import the type. |
| 7018 | ToD = Importer.Visit(FromD); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7019 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7020 | return nullptr; |
| 7021 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7022 | // Notify subclasses. |
| 7023 | Imported(FromD, ToD); |
| 7024 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7025 | return ToD; |
| 7026 | } |
| 7027 | |
| 7028 | DeclContext *ASTImporter::ImportContext(DeclContext *FromDC) { |
| 7029 | if (!FromDC) |
| 7030 | return FromDC; |
| 7031 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7032 | auto *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7033 | if (!ToDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7034 | return nullptr; |
| 7035 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7036 | // When we're using a record/enum/Objective-C class/protocol as a context, we |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7037 | // need it to have a definition. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7038 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 7039 | auto *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7040 | if (ToRecord->isCompleteDefinition()) { |
| 7041 | // Do nothing. |
| 7042 | } else if (FromRecord->isCompleteDefinition()) { |
| 7043 | ASTNodeImporter(*this).ImportDefinition(FromRecord, ToRecord, |
| 7044 | ASTNodeImporter::IDK_Basic); |
| 7045 | } else { |
| 7046 | CompleteDecl(ToRecord); |
| 7047 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7048 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 7049 | auto *FromEnum = cast<EnumDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7050 | if (ToEnum->isCompleteDefinition()) { |
| 7051 | // Do nothing. |
| 7052 | } else if (FromEnum->isCompleteDefinition()) { |
| 7053 | ASTNodeImporter(*this).ImportDefinition(FromEnum, ToEnum, |
| 7054 | ASTNodeImporter::IDK_Basic); |
| 7055 | } else { |
| 7056 | CompleteDecl(ToEnum); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7057 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7058 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 7059 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7060 | if (ToClass->getDefinition()) { |
| 7061 | // Do nothing. |
| 7062 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
| 7063 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToClass, |
| 7064 | ASTNodeImporter::IDK_Basic); |
| 7065 | } else { |
| 7066 | CompleteDecl(ToClass); |
| 7067 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7068 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 7069 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7070 | if (ToProto->getDefinition()) { |
| 7071 | // Do nothing. |
| 7072 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
| 7073 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToProto, |
| 7074 | ASTNodeImporter::IDK_Basic); |
| 7075 | } else { |
| 7076 | CompleteDecl(ToProto); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7077 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7078 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7079 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7080 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7081 | } |
| 7082 | |
| 7083 | Expr *ASTImporter::Import(Expr *FromE) { |
| 7084 | if (!FromE) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7085 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7086 | |
| 7087 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); |
| 7088 | } |
| 7089 | |
| 7090 | Stmt *ASTImporter::Import(Stmt *FromS) { |
| 7091 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7092 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7093 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7094 | // Check whether we've already imported this declaration. |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7095 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 7096 | if (Pos != ImportedStmts.end()) |
| 7097 | return Pos->second; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7098 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7099 | // Import the type |
| 7100 | ASTNodeImporter Importer(*this); |
| 7101 | Stmt *ToS = Importer.Visit(FromS); |
| 7102 | if (!ToS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7103 | return nullptr; |
| 7104 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7105 | // Record the imported declaration. |
| 7106 | ImportedStmts[FromS] = ToS; |
| 7107 | return ToS; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7108 | } |
| 7109 | |
| 7110 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| 7111 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7112 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7113 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7114 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); |
| 7115 | |
| 7116 | switch (FromNNS->getKind()) { |
| 7117 | case NestedNameSpecifier::Identifier: |
| 7118 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { |
| 7119 | return NestedNameSpecifier::Create(ToContext, prefix, II); |
| 7120 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7121 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7122 | |
| 7123 | case NestedNameSpecifier::Namespace: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7124 | if (auto *NS = |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7125 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7126 | return NestedNameSpecifier::Create(ToContext, prefix, NS); |
| 7127 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7128 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7129 | |
| 7130 | case NestedNameSpecifier::NamespaceAlias: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7131 | if (auto *NSAD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7132 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7133 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); |
| 7134 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7135 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7136 | |
| 7137 | case NestedNameSpecifier::Global: |
| 7138 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 7139 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7140 | case NestedNameSpecifier::Super: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7141 | if (auto *RD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7142 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7143 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); |
| 7144 | } |
| 7145 | return nullptr; |
| 7146 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7147 | case NestedNameSpecifier::TypeSpec: |
| 7148 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7149 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); |
| 7150 | if (!T.isNull()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7151 | bool bTemplate = FromNNS->getKind() == |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7152 | NestedNameSpecifier::TypeSpecWithTemplate; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7153 | return NestedNameSpecifier::Create(ToContext, prefix, |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7154 | bTemplate, T.getTypePtr()); |
| 7155 | } |
| 7156 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7157 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7158 | } |
| 7159 | |
| 7160 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7161 | } |
| 7162 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 7163 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7164 | // Copied from NestedNameSpecifier mostly. |
| 7165 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 7166 | NestedNameSpecifierLoc NNS = FromNNS; |
| 7167 | |
| 7168 | // Push each of the nested-name-specifiers's onto a stack for |
| 7169 | // serialization in reverse order. |
| 7170 | while (NNS) { |
| 7171 | NestedNames.push_back(NNS); |
| 7172 | NNS = NNS.getPrefix(); |
| 7173 | } |
| 7174 | |
| 7175 | NestedNameSpecifierLocBuilder Builder; |
| 7176 | |
| 7177 | while (!NestedNames.empty()) { |
| 7178 | NNS = NestedNames.pop_back_val(); |
| 7179 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); |
| 7180 | if (!Spec) |
| 7181 | return NestedNameSpecifierLoc(); |
| 7182 | |
| 7183 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| 7184 | switch (Kind) { |
| 7185 | case NestedNameSpecifier::Identifier: |
| 7186 | Builder.Extend(getToContext(), |
| 7187 | Spec->getAsIdentifier(), |
| 7188 | Import(NNS.getLocalBeginLoc()), |
| 7189 | Import(NNS.getLocalEndLoc())); |
| 7190 | break; |
| 7191 | |
| 7192 | case NestedNameSpecifier::Namespace: |
| 7193 | Builder.Extend(getToContext(), |
| 7194 | Spec->getAsNamespace(), |
| 7195 | Import(NNS.getLocalBeginLoc()), |
| 7196 | Import(NNS.getLocalEndLoc())); |
| 7197 | break; |
| 7198 | |
| 7199 | case NestedNameSpecifier::NamespaceAlias: |
| 7200 | Builder.Extend(getToContext(), |
| 7201 | Spec->getAsNamespaceAlias(), |
| 7202 | Import(NNS.getLocalBeginLoc()), |
| 7203 | Import(NNS.getLocalEndLoc())); |
| 7204 | break; |
| 7205 | |
| 7206 | case NestedNameSpecifier::TypeSpec: |
| 7207 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7208 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| 7209 | QualType(Spec->getAsType(), 0)); |
| 7210 | Builder.Extend(getToContext(), |
| 7211 | Import(NNS.getLocalBeginLoc()), |
| 7212 | TSI->getTypeLoc(), |
| 7213 | Import(NNS.getLocalEndLoc())); |
| 7214 | break; |
| 7215 | } |
| 7216 | |
| 7217 | case NestedNameSpecifier::Global: |
| 7218 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); |
| 7219 | break; |
| 7220 | |
| 7221 | case NestedNameSpecifier::Super: { |
| 7222 | SourceRange ToRange = Import(NNS.getSourceRange()); |
| 7223 | Builder.MakeSuper(getToContext(), |
| 7224 | Spec->getAsRecordDecl(), |
| 7225 | ToRange.getBegin(), |
| 7226 | ToRange.getEnd()); |
| 7227 | } |
| 7228 | } |
| 7229 | } |
| 7230 | |
| 7231 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 7232 | } |
| 7233 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7234 | TemplateName ASTImporter::Import(TemplateName From) { |
| 7235 | switch (From.getKind()) { |
| 7236 | case TemplateName::Template: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7237 | if (auto *ToTemplate = |
| 7238 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7239 | return TemplateName(ToTemplate); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7240 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7241 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7242 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7243 | case TemplateName::OverloadedTemplate: { |
| 7244 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 7245 | UnresolvedSet<2> ToTemplates; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7246 | for (auto *I : *FromStorage) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7247 | if (auto *To = cast_or_null<NamedDecl>(Import(I))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7248 | ToTemplates.addDecl(To); |
| 7249 | else |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7250 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7251 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7252 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7253 | ToTemplates.end()); |
| 7254 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7255 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7256 | case TemplateName::QualifiedTemplate: { |
| 7257 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| 7258 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); |
| 7259 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7260 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7261 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7262 | if (auto *ToTemplate = |
| 7263 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7264 | return ToContext.getQualifiedTemplateName(Qualifier, |
| 7265 | QTN->hasTemplateKeyword(), |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7266 | ToTemplate); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7267 | |
| 7268 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7269 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7270 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7271 | case TemplateName::DependentTemplate: { |
| 7272 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| 7273 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); |
| 7274 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7275 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7276 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7277 | if (DTN->isIdentifier()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7278 | return ToContext.getDependentTemplateName(Qualifier, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7279 | Import(DTN->getIdentifier())); |
| 7280 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7281 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7282 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); |
| 7283 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7284 | |
| 7285 | case TemplateName::SubstTemplateTemplateParm: { |
| 7286 | SubstTemplateTemplateParmStorage *subst |
| 7287 | = From.getAsSubstTemplateTemplateParm(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7288 | auto *param = |
| 7289 | cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7290 | if (!param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7291 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7292 | |
| 7293 | TemplateName replacement = Import(subst->getReplacement()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7294 | if (replacement.isNull()) |
| 7295 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7296 | |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7297 | return ToContext.getSubstTemplateTemplateParm(param, replacement); |
| 7298 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7299 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7300 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 7301 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 7302 | = From.getAsSubstTemplateTemplateParmPack(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7303 | auto *Param = |
| 7304 | cast_or_null<TemplateTemplateParmDecl>( |
| 7305 | Import(SubstPack->getParameterPack())); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7306 | if (!Param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7307 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7308 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7309 | ASTNodeImporter Importer(*this); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7310 | TemplateArgument ArgPack |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7311 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 7312 | if (ArgPack.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7313 | return {}; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7314 | |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7315 | return ToContext.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 7316 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7317 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7318 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7319 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7320 | } |
| 7321 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7322 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { |
| 7323 | if (FromLoc.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7324 | return {}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7325 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7326 | SourceManager &FromSM = FromContext.getSourceManager(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7327 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7328 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 7329 | FileID ToFileID = Import(Decomposed.first); |
| 7330 | if (ToFileID.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7331 | return {}; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7332 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 7333 | return ToSM.getComposedLoc(ToFileID, Decomposed.second); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7334 | } |
| 7335 | |
| 7336 | SourceRange ASTImporter::Import(SourceRange FromRange) { |
| 7337 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); |
| 7338 | } |
| 7339 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7340 | FileID ASTImporter::Import(FileID FromID) { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7341 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7342 | if (Pos != ImportedFileIDs.end()) |
| 7343 | return Pos->second; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7344 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7345 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 7346 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 7347 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7348 | |
| 7349 | // Map the FromID to the "to" source manager. |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7350 | FileID ToID; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7351 | if (FromSLoc.isExpansion()) { |
| 7352 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
| 7353 | SourceLocation ToSpLoc = Import(FromEx.getSpellingLoc()); |
| 7354 | SourceLocation ToExLocS = Import(FromEx.getExpansionLocStart()); |
| 7355 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 7356 | SourceLocation MLoc; |
| 7357 | if (FromEx.isMacroArgExpansion()) { |
| 7358 | MLoc = ToSM.createMacroArgExpansionLoc(ToSpLoc, ToExLocS, TokenLen); |
| 7359 | } else { |
| 7360 | SourceLocation ToExLocE = Import(FromEx.getExpansionLocEnd()); |
| 7361 | MLoc = ToSM.createExpansionLoc(ToSpLoc, ToExLocS, ToExLocE, TokenLen, |
| 7362 | FromEx.isExpansionTokenRange()); |
| 7363 | } |
| 7364 | ToID = ToSM.getFileID(MLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7365 | } else { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7366 | // Include location of this file. |
| 7367 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| 7368 | |
| 7369 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
| 7370 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 7371 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 7372 | // disk again |
| 7373 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 7374 | // than mmap the files several times. |
| 7375 | const FileEntry *Entry = |
| 7376 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 7377 | if (!Entry) |
| 7378 | return {}; |
| 7379 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, |
| 7380 | FromSLoc.getFile().getFileCharacteristic()); |
| 7381 | } else { |
| 7382 | // FIXME: We want to re-use the existing MemoryBuffer! |
| 7383 | const llvm::MemoryBuffer *FromBuf = |
| 7384 | Cache->getBuffer(FromContext.getDiagnostics(), FromSM); |
| 7385 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 7386 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 7387 | FromBuf->getBufferIdentifier()); |
| 7388 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 7389 | FromSLoc.getFile().getFileCharacteristic()); |
| 7390 | } |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7391 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7392 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 7393 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7394 | return ToID; |
| 7395 | } |
| 7396 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7397 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
| 7398 | Expr *ToExpr = Import(From->getInit()); |
| 7399 | if (!ToExpr && From->getInit()) |
| 7400 | return nullptr; |
| 7401 | |
| 7402 | if (From->isBaseInitializer()) { |
| 7403 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 7404 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 7405 | return nullptr; |
| 7406 | |
| 7407 | return new (ToContext) CXXCtorInitializer( |
| 7408 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), |
| 7409 | ToExpr, Import(From->getRParenLoc()), |
| 7410 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) |
| 7411 | : SourceLocation()); |
| 7412 | } else if (From->isMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7413 | auto *ToField = cast_or_null<FieldDecl>(Import(From->getMember())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7414 | if (!ToField && From->getMember()) |
| 7415 | return nullptr; |
| 7416 | |
| 7417 | return new (ToContext) CXXCtorInitializer( |
| 7418 | ToContext, ToField, Import(From->getMemberLocation()), |
| 7419 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 7420 | } else if (From->isIndirectMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7421 | auto *ToIField = cast_or_null<IndirectFieldDecl>( |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7422 | Import(From->getIndirectMember())); |
| 7423 | if (!ToIField && From->getIndirectMember()) |
| 7424 | return nullptr; |
| 7425 | |
| 7426 | return new (ToContext) CXXCtorInitializer( |
| 7427 | ToContext, ToIField, Import(From->getMemberLocation()), |
| 7428 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 7429 | } else if (From->isDelegatingInitializer()) { |
| 7430 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 7431 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 7432 | return nullptr; |
| 7433 | |
| 7434 | return new (ToContext) |
| 7435 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), |
| 7436 | ToExpr, Import(From->getRParenLoc())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7437 | } else { |
| 7438 | return nullptr; |
| 7439 | } |
| 7440 | } |
| 7441 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7442 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| 7443 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 7444 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 7445 | return Pos->second; |
| 7446 | |
| 7447 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| 7448 | Import(BaseSpec->getSourceRange()), |
| 7449 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 7450 | BaseSpec->getAccessSpecifierAsWritten(), |
| 7451 | Import(BaseSpec->getTypeSourceInfo()), |
| 7452 | Import(BaseSpec->getEllipsisLoc())); |
| 7453 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 7454 | return Imported; |
| 7455 | } |
| 7456 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7457 | void ASTImporter::ImportDefinition(Decl *From) { |
| 7458 | Decl *To = Import(From); |
| 7459 | if (!To) |
| 7460 | return; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7461 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7462 | if (auto *FromDC = cast<DeclContext>(From)) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7463 | ASTNodeImporter Importer(*this); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7464 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7465 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7466 | if (!ToRecord->getDefinition()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7467 | Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7468 | ASTNodeImporter::IDK_Everything); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7469 | return; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7470 | } |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7471 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7472 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7473 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7474 | if (!ToEnum->getDefinition()) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7475 | Importer.ImportDefinition(cast<EnumDecl>(FromDC), ToEnum, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7476 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7477 | return; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7478 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7479 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7480 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7481 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7482 | if (!ToIFace->getDefinition()) { |
| 7483 | Importer.ImportDefinition(cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7484 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7485 | return; |
| 7486 | } |
| 7487 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7488 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7489 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7490 | if (!ToProto->getDefinition()) { |
| 7491 | Importer.ImportDefinition(cast<ObjCProtocolDecl>(FromDC), ToProto, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7492 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7493 | return; |
| 7494 | } |
| 7495 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 7496 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7497 | Importer.ImportDeclContext(FromDC, true); |
| 7498 | } |
| 7499 | } |
| 7500 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7501 | DeclarationName ASTImporter::Import(DeclarationName FromName) { |
| 7502 | if (!FromName) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7503 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7504 | |
| 7505 | switch (FromName.getNameKind()) { |
| 7506 | case DeclarationName::Identifier: |
| 7507 | return Import(FromName.getAsIdentifierInfo()); |
| 7508 | |
| 7509 | case DeclarationName::ObjCZeroArgSelector: |
| 7510 | case DeclarationName::ObjCOneArgSelector: |
| 7511 | case DeclarationName::ObjCMultiArgSelector: |
| 7512 | return Import(FromName.getObjCSelector()); |
| 7513 | |
| 7514 | case DeclarationName::CXXConstructorName: { |
| 7515 | QualType T = Import(FromName.getCXXNameType()); |
| 7516 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7517 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7518 | |
| 7519 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 7520 | ToContext.getCanonicalType(T)); |
| 7521 | } |
| 7522 | |
| 7523 | case DeclarationName::CXXDestructorName: { |
| 7524 | QualType T = Import(FromName.getCXXNameType()); |
| 7525 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7526 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7527 | |
| 7528 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 7529 | ToContext.getCanonicalType(T)); |
| 7530 | } |
| 7531 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7532 | case DeclarationName::CXXDeductionGuideName: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7533 | auto *Template = cast_or_null<TemplateDecl>( |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7534 | Import(FromName.getCXXDeductionGuideTemplate())); |
| 7535 | if (!Template) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7536 | return {}; |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7537 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); |
| 7538 | } |
| 7539 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7540 | case DeclarationName::CXXConversionFunctionName: { |
| 7541 | QualType T = Import(FromName.getCXXNameType()); |
| 7542 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7543 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7544 | |
| 7545 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 7546 | ToContext.getCanonicalType(T)); |
| 7547 | } |
| 7548 | |
| 7549 | case DeclarationName::CXXOperatorName: |
| 7550 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 7551 | FromName.getCXXOverloadedOperator()); |
| 7552 | |
| 7553 | case DeclarationName::CXXLiteralOperatorName: |
| 7554 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| 7555 | Import(FromName.getCXXLiteralIdentifier())); |
| 7556 | |
| 7557 | case DeclarationName::CXXUsingDirective: |
| 7558 | // FIXME: STATICS! |
| 7559 | return DeclarationName::getUsingDirectiveName(); |
| 7560 | } |
| 7561 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 7562 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7563 | } |
| 7564 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7565 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7566 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7567 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7568 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 7569 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 7570 | |
| 7571 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 7572 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 7573 | |
| 7574 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7575 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7576 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7577 | Selector ASTImporter::Import(Selector FromSel) { |
| 7578 | if (FromSel.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7579 | return {}; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7580 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 7581 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7582 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 7583 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 7584 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 7585 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 7586 | } |
| 7587 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7588 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 7589 | DeclContext *DC, |
| 7590 | unsigned IDNS, |
| 7591 | NamedDecl **Decls, |
| 7592 | unsigned NumDecls) { |
| 7593 | return Name; |
| 7594 | } |
| 7595 | |
| 7596 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 7597 | if (LastDiagFromFrom) |
| 7598 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 7599 | FromContext.getDiagnostics()); |
| 7600 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7601 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7602 | } |
| 7603 | |
| 7604 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 7605 | if (!LastDiagFromFrom) |
| 7606 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 7607 | ToContext.getDiagnostics()); |
| 7608 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7609 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7610 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7611 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7612 | void ASTImporter::CompleteDecl (Decl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7613 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7614 | if (!ID->getDefinition()) |
| 7615 | ID->startDefinition(); |
| 7616 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7617 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7618 | if (!PD->getDefinition()) |
| 7619 | PD->startDefinition(); |
| 7620 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7621 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7622 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 7623 | TD->startDefinition(); |
| 7624 | TD->setCompleteDefinition(true); |
| 7625 | } |
| 7626 | } |
| 7627 | else { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7628 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7629 | } |
| 7630 | } |
| 7631 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7632 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 7633 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 7634 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 7635 | "Try to import an already imported Decl"); |
| 7636 | if (Pos != ImportedDecls.end()) |
| 7637 | return Pos->second; |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7638 | ImportedDecls[From] = To; |
| 7639 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 7640 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7641 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 7642 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 7643 | bool Complain) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7644 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7645 | = ImportedTypes.find(From.getTypePtr()); |
| 7646 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) |
| 7647 | return true; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 7648 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 7649 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7650 | getStructuralEquivalenceKind(*this), false, |
| 7651 | Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 7652 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7653 | } |