Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1 | //===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===// |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the ASTImporter class which imports AST nodes from one |
| 11 | // context into another context. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 14 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTImporter.h" |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTDiagnostic.h" |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTStructuralEquivalence.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 19 | #include "clang/AST/Attr.h" |
| 20 | #include "clang/AST/Decl.h" |
| 21 | #include "clang/AST/DeclAccessPair.h" |
| 22 | #include "clang/AST/DeclBase.h" |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclCXX.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclFriend.h" |
| 25 | #include "clang/AST/DeclGroup.h" |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 26 | #include "clang/AST/DeclObjC.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 27 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 28 | #include "clang/AST/DeclVisitor.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 29 | #include "clang/AST/DeclarationName.h" |
| 30 | #include "clang/AST/Expr.h" |
| 31 | #include "clang/AST/ExprCXX.h" |
| 32 | #include "clang/AST/ExprObjC.h" |
| 33 | #include "clang/AST/ExternalASTSource.h" |
| 34 | #include "clang/AST/LambdaCapture.h" |
| 35 | #include "clang/AST/NestedNameSpecifier.h" |
| 36 | #include "clang/AST/OperationKinds.h" |
| 37 | #include "clang/AST/Stmt.h" |
| 38 | #include "clang/AST/StmtCXX.h" |
| 39 | #include "clang/AST/StmtObjC.h" |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 40 | #include "clang/AST/StmtVisitor.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 41 | #include "clang/AST/TemplateBase.h" |
| 42 | #include "clang/AST/TemplateName.h" |
| 43 | #include "clang/AST/Type.h" |
| 44 | #include "clang/AST/TypeLoc.h" |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 45 | #include "clang/AST/TypeVisitor.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 46 | #include "clang/AST/UnresolvedSet.h" |
| 47 | #include "clang/Basic/ExceptionSpecificationType.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 48 | #include "clang/Basic/FileManager.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 49 | #include "clang/Basic/IdentifierTable.h" |
| 50 | #include "clang/Basic/LLVM.h" |
| 51 | #include "clang/Basic/LangOptions.h" |
| 52 | #include "clang/Basic/SourceLocation.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 53 | #include "clang/Basic/SourceManager.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 54 | #include "clang/Basic/Specifiers.h" |
| 55 | #include "llvm/ADT/APSInt.h" |
| 56 | #include "llvm/ADT/ArrayRef.h" |
| 57 | #include "llvm/ADT/DenseMap.h" |
| 58 | #include "llvm/ADT/None.h" |
| 59 | #include "llvm/ADT/Optional.h" |
| 60 | #include "llvm/ADT/STLExtras.h" |
| 61 | #include "llvm/ADT/SmallVector.h" |
| 62 | #include "llvm/Support/Casting.h" |
| 63 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 64 | #include "llvm/Support/MemoryBuffer.h" |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 65 | #include <algorithm> |
| 66 | #include <cassert> |
| 67 | #include <cstddef> |
| 68 | #include <memory> |
| 69 | #include <type_traits> |
| 70 | #include <utility> |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 71 | |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 72 | namespace clang { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 73 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 74 | template <class T> |
| 75 | SmallVector<Decl*, 2> |
| 76 | getCanonicalForwardRedeclChain(Redeclarable<T>* D) { |
| 77 | SmallVector<Decl*, 2> Redecls; |
| 78 | for (auto *R : D->getFirstDecl()->redecls()) { |
| 79 | if (R != D->getFirstDecl()) |
| 80 | Redecls.push_back(R); |
| 81 | } |
| 82 | Redecls.push_back(D->getFirstDecl()); |
| 83 | std::reverse(Redecls.begin(), Redecls.end()); |
| 84 | return Redecls; |
| 85 | } |
| 86 | |
| 87 | SmallVector<Decl*, 2> getCanonicalForwardRedeclChain(Decl* D) { |
| 88 | // Currently only FunctionDecl is supported |
| 89 | auto FD = cast<FunctionDecl>(D); |
| 90 | return getCanonicalForwardRedeclChain<FunctionDecl>(FD); |
| 91 | } |
| 92 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 93 | void updateFlags(const Decl *From, Decl *To) { |
| 94 | // Check if some flags or attrs are new in 'From' and copy into 'To'. |
| 95 | // FIXME: Other flags or attrs? |
| 96 | if (From->isUsed(false) && !To->isUsed(false)) |
| 97 | To->setIsUsed(); |
| 98 | } |
| 99 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 100 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, QualType>, |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 101 | public DeclVisitor<ASTNodeImporter, Decl *>, |
| 102 | public StmtVisitor<ASTNodeImporter, Stmt *> { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 103 | ASTImporter &Importer; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 104 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 105 | // Wrapper for an overload set. |
| 106 | template <typename ToDeclT> struct CallOverloadedCreateFun { |
| 107 | template <typename... Args> |
| 108 | auto operator()(Args &&... args) |
| 109 | -> decltype(ToDeclT::Create(std::forward<Args>(args)...)) { |
| 110 | return ToDeclT::Create(std::forward<Args>(args)...); |
| 111 | } |
| 112 | }; |
| 113 | |
| 114 | // Always use these functions to create a Decl during import. There are |
| 115 | // certain tasks which must be done after the Decl was created, e.g. we |
| 116 | // must immediately register that as an imported Decl. The parameter `ToD` |
| 117 | // will be set to the newly created Decl or if had been imported before |
| 118 | // then to the already imported Decl. Returns a bool value set to true if |
| 119 | // the `FromD` had been imported before. |
| 120 | template <typename ToDeclT, typename FromDeclT, typename... Args> |
| 121 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 122 | Args &&... args) { |
| 123 | // There may be several overloads of ToDeclT::Create. We must make sure |
| 124 | // to call the one which would be chosen by the arguments, thus we use a |
| 125 | // wrapper for the overload set. |
| 126 | CallOverloadedCreateFun<ToDeclT> OC; |
| 127 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 128 | std::forward<Args>(args)...); |
| 129 | } |
| 130 | // Use this overload if a special Type is needed to be created. E.g if we |
| 131 | // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl` |
| 132 | // then: |
| 133 | // TypedefNameDecl *ToTypedef; |
| 134 | // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...); |
| 135 | template <typename NewDeclT, typename ToDeclT, typename FromDeclT, |
| 136 | typename... Args> |
| 137 | LLVM_NODISCARD bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD, |
| 138 | Args &&... args) { |
| 139 | CallOverloadedCreateFun<NewDeclT> OC; |
| 140 | return GetImportedOrCreateSpecialDecl(ToD, OC, FromD, |
| 141 | std::forward<Args>(args)...); |
| 142 | } |
| 143 | // Use this version if a special create function must be |
| 144 | // used, e.g. CXXRecordDecl::CreateLambda . |
| 145 | template <typename ToDeclT, typename CreateFunT, typename FromDeclT, |
| 146 | typename... Args> |
| 147 | LLVM_NODISCARD bool |
| 148 | GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun, |
| 149 | FromDeclT *FromD, Args &&... args) { |
| 150 | ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD)); |
| 151 | if (ToD) |
| 152 | return true; // Already imported. |
| 153 | ToD = CreateFun(std::forward<Args>(args)...); |
| 154 | InitializeImportedDecl(FromD, ToD); |
| 155 | return false; // A new Decl is created. |
| 156 | } |
| 157 | |
| 158 | void InitializeImportedDecl(Decl *FromD, Decl *ToD) { |
| 159 | Importer.MapImported(FromD, ToD); |
| 160 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; |
| 161 | if (FromD->hasAttrs()) |
| 162 | for (const Attr *FromAttr : FromD->getAttrs()) |
| 163 | ToD->addAttr(Importer.Import(FromAttr)); |
| 164 | if (FromD->isUsed()) |
| 165 | ToD->setIsUsed(); |
| 166 | if (FromD->isImplicit()) |
| 167 | ToD->setImplicit(); |
| 168 | } |
| 169 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 170 | public: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 171 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} |
Gabor Marton | 344b099 | 2018-05-16 11:48:11 +0000 | [diff] [blame] | 172 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 173 | using TypeVisitor<ASTNodeImporter, QualType>::Visit; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 174 | using DeclVisitor<ASTNodeImporter, Decl *>::Visit; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 175 | using StmtVisitor<ASTNodeImporter, Stmt *>::Visit; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 176 | |
| 177 | // Importing types |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 178 | QualType VisitType(const Type *T); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 179 | QualType VisitAtomicType(const AtomicType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 180 | QualType VisitBuiltinType(const BuiltinType *T); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 181 | QualType VisitDecayedType(const DecayedType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 182 | QualType VisitComplexType(const ComplexType *T); |
| 183 | QualType VisitPointerType(const PointerType *T); |
| 184 | QualType VisitBlockPointerType(const BlockPointerType *T); |
| 185 | QualType VisitLValueReferenceType(const LValueReferenceType *T); |
| 186 | QualType VisitRValueReferenceType(const RValueReferenceType *T); |
| 187 | QualType VisitMemberPointerType(const MemberPointerType *T); |
| 188 | QualType VisitConstantArrayType(const ConstantArrayType *T); |
| 189 | QualType VisitIncompleteArrayType(const IncompleteArrayType *T); |
| 190 | QualType VisitVariableArrayType(const VariableArrayType *T); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 191 | QualType VisitDependentSizedArrayType(const DependentSizedArrayType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 192 | // FIXME: DependentSizedExtVectorType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 193 | QualType VisitVectorType(const VectorType *T); |
| 194 | QualType VisitExtVectorType(const ExtVectorType *T); |
| 195 | QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T); |
| 196 | QualType VisitFunctionProtoType(const FunctionProtoType *T); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 197 | QualType VisitUnresolvedUsingType(const UnresolvedUsingType *T); |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 198 | QualType VisitParenType(const ParenType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 199 | QualType VisitTypedefType(const TypedefType *T); |
| 200 | QualType VisitTypeOfExprType(const TypeOfExprType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 201 | // FIXME: DependentTypeOfExprType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 202 | QualType VisitTypeOfType(const TypeOfType *T); |
| 203 | QualType VisitDecltypeType(const DecltypeType *T); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 204 | QualType VisitUnaryTransformType(const UnaryTransformType *T); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 205 | QualType VisitAutoType(const AutoType *T); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 206 | QualType VisitInjectedClassNameType(const InjectedClassNameType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 207 | // FIXME: DependentDecltypeType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 208 | QualType VisitRecordType(const RecordType *T); |
| 209 | QualType VisitEnumType(const EnumType *T); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 210 | QualType VisitAttributedType(const AttributedType *T); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 211 | QualType VisitTemplateTypeParmType(const TemplateTypeParmType *T); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 212 | QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 213 | QualType VisitTemplateSpecializationType(const TemplateSpecializationType *T); |
| 214 | QualType VisitElaboratedType(const ElaboratedType *T); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 215 | QualType VisitDependentNameType(const DependentNameType *T); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 216 | QualType VisitPackExpansionType(const PackExpansionType *T); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 217 | QualType VisitDependentTemplateSpecializationType( |
| 218 | const DependentTemplateSpecializationType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 219 | QualType VisitObjCInterfaceType(const ObjCInterfaceType *T); |
| 220 | QualType VisitObjCObjectType(const ObjCObjectType *T); |
| 221 | QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); |
Rafael Stahl | df55620 | 2018-05-29 08:12:15 +0000 | [diff] [blame] | 222 | |
| 223 | // Importing declarations |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 224 | bool ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 225 | DeclContext *&LexicalDC, DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 226 | NamedDecl *&ToD, SourceLocation &Loc); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 227 | void ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 228 | void ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 229 | DeclarationNameInfo& To); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 230 | void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); |
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); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 240 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 241 | /// What we should import from the definition. |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +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 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +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: |
| 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 |
| 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; |
| 608 | |
| 609 | return Importer.getToContext().CharTy; |
| 610 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 611 | case BuiltinType::Char_S: |
| 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 |
| 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; |
| 617 | |
| 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 {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 642 | |
| 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 {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 650 | |
| 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 {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 659 | |
| 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 {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 669 | |
| 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 {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 679 | |
| 680 | return Importer.getToContext().getRValueReferenceType(ToPointeeType); |
| 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 {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 688 | |
| 689 | QualType ClassType = Importer.Import(QualType(T->getClass(), 0)); |
| 690 | return Importer.getToContext().getMemberPointerType(ToPointeeType, |
| 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 {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 698 | |
| 699 | return Importer.getToContext().getConstantArrayType(ToElementType, |
| 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 {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 710 | |
| 711 | return Importer.getToContext().getIncompleteArrayType(ToElementType, |
| 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 {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 724 | |
| 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 {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 754 | |
| 755 | return Importer.getToContext().getVectorType(ToElementType, |
| 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 {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 764 | |
| 765 | return Importer.getToContext().getExtVectorType(ToElementType, |
| 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) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 771 | // FIXME: What happens if we're importing a function without a prototype |
| 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 {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 785 | |
| 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 | } |
| 794 | |
| 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 {}; |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 844 | |
| 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 {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 853 | |
| 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 {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 861 | |
| 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 {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 869 | |
| 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 {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +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 | } |
| 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 {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +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 {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1007 | |
| 1008 | QualType ToCanonType; |
| 1009 | if (!QualType(T, 0).isCanonical()) { |
| 1010 | QualType FromCanonType |
| 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 | } |
| 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 | //---------------------------------------------------------------------------- |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +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()) { |
| 1150 | SourceRange RecR = D->getSourceRange(); |
| 1151 | SourceRange BodyR = FunDecl->getBody()->getSourceRange(); |
| 1152 | // If RecordDecl is not in Body (it is a param), we bail out. |
| 1153 | if (RecR.isValid() && BodyR.isValid() && |
| 1154 | (RecR.getBegin() < BodyR.getBegin() || |
| 1155 | BodyR.getEnd() < RecR.getEnd())) { |
| 1156 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
| 1157 | << D->getDeclKindName(); |
| 1158 | return true; |
| 1159 | } |
| 1160 | } |
| 1161 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1162 | // Import the context of this declaration. |
Gabor Marton | 6e1510c | 2018-07-12 11:50:21 +0000 | [diff] [blame] | 1163 | DC = Importer.ImportContext(OrigDC); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1164 | if (!DC) |
| 1165 | return true; |
| 1166 | |
| 1167 | LexicalDC = DC; |
| 1168 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 1169 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 1170 | if (!LexicalDC) |
| 1171 | return true; |
| 1172 | } |
| 1173 | |
| 1174 | // Import the name of this declaration. |
| 1175 | Name = Importer.Import(D->getDeclName()); |
| 1176 | if (D->getDeclName() && !Name) |
| 1177 | return true; |
| 1178 | |
| 1179 | // Import the location of this declaration. |
| 1180 | Loc = Importer.Import(D->getLocation()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1181 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1182 | return false; |
| 1183 | } |
| 1184 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1185 | void ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
| 1186 | if (!FromD) |
| 1187 | return; |
| 1188 | |
| 1189 | if (!ToD) { |
| 1190 | ToD = Importer.Import(FromD); |
| 1191 | if (!ToD) |
| 1192 | return; |
| 1193 | } |
| 1194 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1195 | if (auto *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1196 | if (auto *ToRecord = cast_or_null<RecordDecl>(ToD)) { |
Sean Callanan | 19dfc93 | 2013-01-11 23:17:47 +0000 | [diff] [blame] | 1197 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && !ToRecord->getDefinition()) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1198 | ImportDefinition(FromRecord, ToRecord); |
| 1199 | } |
| 1200 | } |
| 1201 | return; |
| 1202 | } |
| 1203 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1204 | if (auto *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1205 | if (auto *ToEnum = cast_or_null<EnumDecl>(ToD)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1206 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
| 1207 | ImportDefinition(FromEnum, ToEnum); |
| 1208 | } |
| 1209 | } |
| 1210 | return; |
| 1211 | } |
| 1212 | } |
| 1213 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1214 | void |
| 1215 | ASTNodeImporter::ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 1216 | DeclarationNameInfo& To) { |
| 1217 | // NOTE: To.Name and To.Loc are already imported. |
| 1218 | // We only have to import To.LocInfo. |
| 1219 | switch (To.getName().getNameKind()) { |
| 1220 | case DeclarationName::Identifier: |
| 1221 | case DeclarationName::ObjCZeroArgSelector: |
| 1222 | case DeclarationName::ObjCOneArgSelector: |
| 1223 | case DeclarationName::ObjCMultiArgSelector: |
| 1224 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1225 | case DeclarationName::CXXDeductionGuideName: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1226 | return; |
| 1227 | |
| 1228 | case DeclarationName::CXXOperatorName: { |
| 1229 | SourceRange Range = From.getCXXOperatorNameRange(); |
| 1230 | To.setCXXOperatorNameRange(Importer.Import(Range)); |
| 1231 | return; |
| 1232 | } |
| 1233 | case DeclarationName::CXXLiteralOperatorName: { |
| 1234 | SourceLocation Loc = From.getCXXLiteralOperatorNameLoc(); |
| 1235 | To.setCXXLiteralOperatorNameLoc(Importer.Import(Loc)); |
| 1236 | return; |
| 1237 | } |
| 1238 | case DeclarationName::CXXConstructorName: |
| 1239 | case DeclarationName::CXXDestructorName: |
| 1240 | case DeclarationName::CXXConversionFunctionName: { |
| 1241 | TypeSourceInfo *FromTInfo = From.getNamedTypeInfo(); |
| 1242 | To.setNamedTypeInfo(Importer.Import(FromTInfo)); |
| 1243 | return; |
| 1244 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1245 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1246 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1249 | void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1250 | if (Importer.isMinimalImport() && !ForceImport) { |
Sean Callanan | 81d577c | 2011-07-22 23:46:03 +0000 | [diff] [blame] | 1251 | Importer.ImportContext(FromDC); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1252 | return; |
| 1253 | } |
| 1254 | |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 1255 | for (auto *From : FromDC->decls()) |
| 1256 | Importer.Import(From); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 1259 | void ASTNodeImporter::ImportImplicitMethods( |
| 1260 | const CXXRecordDecl *From, CXXRecordDecl *To) { |
| 1261 | assert(From->isCompleteDefinition() && To->getDefinition() == To && |
| 1262 | "Import implicit methods to or from non-definition"); |
| 1263 | |
| 1264 | for (CXXMethodDecl *FromM : From->methods()) |
| 1265 | if (FromM->isImplicit()) |
| 1266 | Importer.Import(FromM); |
| 1267 | } |
| 1268 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1269 | static void setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1270 | ASTImporter &Importer) { |
| 1271 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
| 1272 | auto *ToTypedef = |
| 1273 | cast_or_null<TypedefNameDecl>(Importer.Import(FromTypedef)); |
| 1274 | assert (ToTypedef && "Failed to import typedef of an anonymous structure"); |
| 1275 | |
| 1276 | To->setTypedefNameForAnonDecl(ToTypedef); |
| 1277 | } |
| 1278 | } |
| 1279 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1280 | bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1281 | ImportDefinitionKind Kind) { |
| 1282 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1283 | if (Kind == IDK_Everything) |
| 1284 | ImportDeclContext(From, /*ForceImport=*/true); |
| 1285 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1286 | return false; |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1287 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1288 | |
| 1289 | To->startDefinition(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1290 | |
| 1291 | setTypedefNameForAnonDecl(From, To, Importer); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1292 | |
| 1293 | // Add base classes. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1294 | if (auto *ToCXX = dyn_cast<CXXRecordDecl>(To)) { |
| 1295 | auto *FromCXX = cast<CXXRecordDecl>(From); |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1296 | |
| 1297 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1298 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 1299 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1300 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1301 | ToData.Aggregate = FromData.Aggregate; |
| 1302 | ToData.PlainOldData = FromData.PlainOldData; |
| 1303 | ToData.Empty = FromData.Empty; |
| 1304 | ToData.Polymorphic = FromData.Polymorphic; |
| 1305 | ToData.Abstract = FromData.Abstract; |
| 1306 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1307 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; |
| 1308 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; |
| 1309 | ToData.HasBasesWithNonStaticDataMembers = |
| 1310 | FromData.HasBasesWithNonStaticDataMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1311 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 1312 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 1313 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 1314 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1315 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1316 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1317 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1318 | ToData.HasUninitializedReferenceMember |
| 1319 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1320 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1321 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1322 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1323 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1324 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1325 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1326 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1327 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1328 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1329 | ToData.NeedOverloadResolutionForDestructor |
| 1330 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1331 | ToData.DefaultedCopyConstructorIsDeleted |
| 1332 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1333 | ToData.DefaultedMoveConstructorIsDeleted |
| 1334 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1335 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1336 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1337 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1338 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1339 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1340 | ToData.HasConstexprNonCopyMoveConstructor |
| 1341 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1342 | ToData.HasDefaultedDefaultConstructor |
| 1343 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1344 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1345 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1346 | ToData.HasConstexprDefaultConstructor |
| 1347 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1348 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1349 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1350 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1351 | ToData.UserProvidedDefaultConstructor |
| 1352 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1353 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1354 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1355 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1356 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1357 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1358 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1359 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1360 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1361 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1362 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1363 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1364 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1365 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1366 | for (const auto &Base1 : FromCXX->bases()) { |
| 1367 | QualType T = Importer.Import(Base1.getType()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1368 | if (T.isNull()) |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1369 | return true; |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1370 | |
| 1371 | SourceLocation EllipsisLoc; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1372 | if (Base1.isPackExpansion()) |
| 1373 | EllipsisLoc = Importer.Import(Base1.getEllipsisLoc()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1374 | |
| 1375 | // Ensure that we have a definition for the base. |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1376 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1377 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1378 | Bases.push_back( |
| 1379 | new (Importer.getToContext()) |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1380 | CXXBaseSpecifier(Importer.Import(Base1.getSourceRange()), |
| 1381 | Base1.isVirtual(), |
| 1382 | Base1.isBaseOfClass(), |
| 1383 | Base1.getAccessSpecifierAsWritten(), |
| 1384 | Importer.Import(Base1.getTypeSourceInfo()), |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1385 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1386 | } |
| 1387 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1388 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1391 | if (shouldForceImportDeclContext(Kind)) |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1392 | ImportDeclContext(From, /*ForceImport=*/true); |
| 1393 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1394 | To->completeDefinition(); |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1395 | return false; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1396 | } |
| 1397 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1398 | bool ASTNodeImporter::ImportDefinition(VarDecl *From, VarDecl *To, |
| 1399 | ImportDefinitionKind Kind) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1400 | if (To->getAnyInitializer()) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1401 | return false; |
| 1402 | |
| 1403 | // FIXME: Can we really import any initializer? Alternatively, we could force |
| 1404 | // ourselves to import every declaration of a variable and then only use |
| 1405 | // getInit() here. |
| 1406 | To->setInit(Importer.Import(const_cast<Expr *>(From->getAnyInitializer()))); |
| 1407 | |
| 1408 | // FIXME: Other bits to merge? |
| 1409 | |
| 1410 | return false; |
| 1411 | } |
| 1412 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1413 | bool ASTNodeImporter::ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1414 | ImportDefinitionKind Kind) { |
| 1415 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1416 | if (Kind == IDK_Everything) |
| 1417 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1418 | return false; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1419 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1420 | |
| 1421 | To->startDefinition(); |
| 1422 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1423 | setTypedefNameForAnonDecl(From, To, Importer); |
| 1424 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1425 | QualType T = Importer.Import(Importer.getFromContext().getTypeDeclType(From)); |
| 1426 | if (T.isNull()) |
| 1427 | return true; |
| 1428 | |
| 1429 | QualType ToPromotionType = Importer.Import(From->getPromotionType()); |
| 1430 | if (ToPromotionType.isNull()) |
| 1431 | return true; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1432 | |
| 1433 | if (shouldForceImportDeclContext(Kind)) |
| 1434 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1435 | |
| 1436 | // FIXME: we might need to merge the number of positive or negative bits |
| 1437 | // if the enumerator lists don't match. |
| 1438 | To->completeDefinition(T, ToPromotionType, |
| 1439 | From->getNumPositiveBits(), |
| 1440 | From->getNumNegativeBits()); |
| 1441 | return false; |
| 1442 | } |
| 1443 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1444 | TemplateParameterList *ASTNodeImporter::ImportTemplateParameterList( |
| 1445 | TemplateParameterList *Params) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1446 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); |
| 1447 | if (ImportContainerChecked(*Params, ToParams)) |
| 1448 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1449 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1450 | Expr *ToRequiresClause; |
| 1451 | if (Expr *const R = Params->getRequiresClause()) { |
| 1452 | ToRequiresClause = Importer.Import(R); |
| 1453 | if (!ToRequiresClause) |
| 1454 | return nullptr; |
| 1455 | } else { |
| 1456 | ToRequiresClause = nullptr; |
| 1457 | } |
| 1458 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1459 | return TemplateParameterList::Create(Importer.getToContext(), |
| 1460 | Importer.Import(Params->getTemplateLoc()), |
| 1461 | Importer.Import(Params->getLAngleLoc()), |
David Majnemer | 902f8c6 | 2015-12-27 07:16:27 +0000 | [diff] [blame] | 1462 | ToParams, |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1463 | Importer.Import(Params->getRAngleLoc()), |
| 1464 | ToRequiresClause); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1467 | TemplateArgument |
| 1468 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1469 | switch (From.getKind()) { |
| 1470 | case TemplateArgument::Null: |
| 1471 | return TemplateArgument(); |
| 1472 | |
| 1473 | case TemplateArgument::Type: { |
| 1474 | QualType ToType = Importer.Import(From.getAsType()); |
| 1475 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1476 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1477 | return TemplateArgument(ToType); |
| 1478 | } |
| 1479 | |
| 1480 | case TemplateArgument::Integral: { |
| 1481 | QualType ToType = Importer.Import(From.getIntegralType()); |
| 1482 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1483 | return {}; |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 1484 | return TemplateArgument(From, ToType); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1487 | case TemplateArgument::Declaration: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1488 | auto *To = cast_or_null<ValueDecl>(Importer.Import(From.getAsDecl())); |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1489 | QualType ToType = Importer.Import(From.getParamTypeForDecl()); |
| 1490 | if (!To || ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1491 | return {}; |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1492 | return TemplateArgument(To, ToType); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | case TemplateArgument::NullPtr: { |
| 1496 | QualType ToType = Importer.Import(From.getNullPtrType()); |
| 1497 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1498 | return {}; |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1499 | return TemplateArgument(ToType, /*isNullPtr*/true); |
| 1500 | } |
| 1501 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1502 | case TemplateArgument::Template: { |
| 1503 | TemplateName ToTemplate = Importer.Import(From.getAsTemplate()); |
| 1504 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1505 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1506 | |
| 1507 | return TemplateArgument(ToTemplate); |
| 1508 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1509 | |
| 1510 | case TemplateArgument::TemplateExpansion: { |
| 1511 | TemplateName ToTemplate |
| 1512 | = Importer.Import(From.getAsTemplateOrTemplatePattern()); |
| 1513 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1514 | return {}; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1515 | |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 1516 | return TemplateArgument(ToTemplate, From.getNumTemplateExpansions()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1519 | case TemplateArgument::Expression: |
| 1520 | if (Expr *ToExpr = Importer.Import(From.getAsExpr())) |
| 1521 | return TemplateArgument(ToExpr); |
| 1522 | return TemplateArgument(); |
| 1523 | |
| 1524 | case TemplateArgument::Pack: { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1525 | SmallVector<TemplateArgument, 2> ToPack; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1526 | ToPack.reserve(From.pack_size()); |
| 1527 | if (ImportTemplateArguments(From.pack_begin(), From.pack_size(), ToPack)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1528 | return {}; |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 1529 | |
| 1530 | return TemplateArgument( |
| 1531 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | llvm_unreachable("Invalid template argument kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1536 | } |
| 1537 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1538 | Optional<TemplateArgumentLoc> |
| 1539 | ASTNodeImporter::ImportTemplateArgumentLoc(const TemplateArgumentLoc &TALoc) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1540 | TemplateArgument Arg = ImportTemplateArgument(TALoc.getArgument()); |
| 1541 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 1542 | TemplateArgumentLocInfo ToInfo; |
| 1543 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 1544 | Expr *E = Importer.Import(FromInfo.getAsExpr()); |
| 1545 | ToInfo = TemplateArgumentLocInfo(E); |
| 1546 | if (!E) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1547 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1548 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 1549 | if (TypeSourceInfo *TSI = Importer.Import(FromInfo.getAsTypeSourceInfo())) |
| 1550 | ToInfo = TemplateArgumentLocInfo(TSI); |
| 1551 | else |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1552 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1553 | } else { |
| 1554 | ToInfo = TemplateArgumentLocInfo( |
| 1555 | Importer.Import(FromInfo.getTemplateQualifierLoc()), |
| 1556 | Importer.Import(FromInfo.getTemplateNameLoc()), |
| 1557 | Importer.Import(FromInfo.getTemplateEllipsisLoc())); |
| 1558 | } |
| 1559 | return TemplateArgumentLoc(Arg, ToInfo); |
| 1560 | } |
| 1561 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1562 | bool ASTNodeImporter::ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 1563 | unsigned NumFromArgs, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1564 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1565 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
| 1566 | TemplateArgument To = ImportTemplateArgument(FromArgs[I]); |
| 1567 | if (To.isNull() && !FromArgs[I].isNull()) |
| 1568 | return true; |
| 1569 | |
| 1570 | ToArgs.push_back(To); |
| 1571 | } |
| 1572 | |
| 1573 | return false; |
| 1574 | } |
| 1575 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 1576 | // We cannot use Optional<> pattern here and below because |
| 1577 | // TemplateArgumentListInfo's operator new is declared as deleted so it cannot |
| 1578 | // be stored in Optional. |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1579 | template <typename InContainerTy> |
| 1580 | bool ASTNodeImporter::ImportTemplateArgumentListInfo( |
| 1581 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1582 | for (const auto &FromLoc : Container) { |
| 1583 | if (auto ToLoc = ImportTemplateArgumentLoc(FromLoc)) |
| 1584 | ToTAInfo.addArgument(*ToLoc); |
| 1585 | else |
| 1586 | return true; |
| 1587 | } |
| 1588 | return false; |
| 1589 | } |
| 1590 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1591 | static StructuralEquivalenceKind |
| 1592 | getStructuralEquivalenceKind(const ASTImporter &Importer) { |
| 1593 | return Importer.isMinimalImport() ? StructuralEquivalenceKind::Minimal |
| 1594 | : StructuralEquivalenceKind::Default; |
| 1595 | } |
| 1596 | |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1597 | bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) { |
| 1598 | StructuralEquivalenceContext Ctx( |
| 1599 | Importer.getFromContext(), Importer.getToContext(), |
| 1600 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1601 | false, Complain); |
| 1602 | return Ctx.IsEquivalent(From, To); |
| 1603 | } |
| 1604 | |
| 1605 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1606 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1607 | // Eliminate a potential failure point where we attempt to re-import |
| 1608 | // something we're trying to import while completing ToRecord. |
| 1609 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1610 | if (ToOrigin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1611 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1612 | if (ToOriginRecord) |
| 1613 | ToRecord = ToOriginRecord; |
| 1614 | } |
| 1615 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1616 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1617 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1618 | Importer.getNonEquivalentDecls(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1619 | getStructuralEquivalenceKind(Importer), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1620 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1621 | return Ctx.IsEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1622 | } |
| 1623 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1624 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 1625 | bool Complain) { |
| 1626 | StructuralEquivalenceContext Ctx( |
| 1627 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1628 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1629 | false, Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1630 | return Ctx.IsEquivalent(FromVar, ToVar); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1631 | } |
| 1632 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1633 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1634 | StructuralEquivalenceContext Ctx( |
| 1635 | Importer.getFromContext(), Importer.getToContext(), |
| 1636 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1637 | return Ctx.IsEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1640 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 1641 | FunctionTemplateDecl *To) { |
| 1642 | StructuralEquivalenceContext Ctx( |
| 1643 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1644 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1645 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1646 | return Ctx.IsEquivalent(From, To); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1647 | } |
| 1648 | |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 1649 | bool ASTNodeImporter::IsStructuralMatch(FunctionDecl *From, FunctionDecl *To) { |
| 1650 | StructuralEquivalenceContext Ctx( |
| 1651 | Importer.getFromContext(), Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1652 | Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer), |
| 1653 | false, false); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1654 | return Ctx.IsEquivalent(From, To); |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1657 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1658 | EnumConstantDecl *ToEC) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1659 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 1660 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 1661 | |
| 1662 | return FromVal.isSigned() == ToVal.isSigned() && |
| 1663 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 1664 | FromVal == ToVal; |
| 1665 | } |
| 1666 | |
| 1667 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1668 | ClassTemplateDecl *To) { |
| 1669 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1670 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1671 | Importer.getNonEquivalentDecls(), |
| 1672 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1673 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1674 | } |
| 1675 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1676 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 1677 | VarTemplateDecl *To) { |
| 1678 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1679 | Importer.getToContext(), |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1680 | Importer.getNonEquivalentDecls(), |
| 1681 | getStructuralEquivalenceKind(Importer)); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 1682 | return Ctx.IsEquivalent(From, To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1685 | Decl *ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 1686 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1687 | << D->getDeclKindName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1688 | return nullptr; |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1691 | Decl *ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 1692 | // Import the context of this declaration. |
| 1693 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1694 | if (!DC) |
| 1695 | return nullptr; |
| 1696 | |
| 1697 | DeclContext *LexicalDC = DC; |
| 1698 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 1699 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 1700 | if (!LexicalDC) |
| 1701 | return nullptr; |
| 1702 | } |
| 1703 | |
| 1704 | // Import the location of this declaration. |
| 1705 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1706 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1707 | EmptyDecl *ToD; |
| 1708 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc)) |
| 1709 | return ToD; |
| 1710 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1711 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1712 | LexicalDC->addDeclInternal(ToD); |
| 1713 | return ToD; |
| 1714 | } |
| 1715 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 1716 | Decl *ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 1717 | TranslationUnitDecl *ToD = |
| 1718 | Importer.getToContext().getTranslationUnitDecl(); |
| 1719 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1720 | Importer.MapImported(D, ToD); |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 1721 | |
| 1722 | return ToD; |
| 1723 | } |
| 1724 | |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1725 | Decl *ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1726 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1727 | SourceLocation ColonLoc = Importer.Import(D->getColonLoc()); |
| 1728 | |
| 1729 | // Import the context of this declaration. |
| 1730 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1731 | if (!DC) |
| 1732 | return nullptr; |
| 1733 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1734 | AccessSpecDecl *ToD; |
| 1735 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(), |
| 1736 | DC, Loc, ColonLoc)) |
| 1737 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1738 | |
| 1739 | // Lexical DeclContext and Semantic DeclContext |
| 1740 | // is always the same for the accessSpec. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1741 | ToD->setLexicalDeclContext(DC); |
| 1742 | DC->addDeclInternal(ToD); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1743 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1744 | return ToD; |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1745 | } |
| 1746 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1747 | Decl *ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 1748 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1749 | if (!DC) |
| 1750 | return nullptr; |
| 1751 | |
| 1752 | DeclContext *LexicalDC = DC; |
| 1753 | |
| 1754 | // Import the location of this declaration. |
| 1755 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1756 | |
| 1757 | Expr *AssertExpr = Importer.Import(D->getAssertExpr()); |
| 1758 | if (!AssertExpr) |
| 1759 | return nullptr; |
| 1760 | |
| 1761 | StringLiteral *FromMsg = D->getMessage(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1762 | auto *ToMsg = cast_or_null<StringLiteral>(Importer.Import(FromMsg)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1763 | if (!ToMsg && FromMsg) |
| 1764 | return nullptr; |
| 1765 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1766 | StaticAssertDecl *ToD; |
| 1767 | if (GetImportedOrCreateDecl( |
| 1768 | ToD, D, Importer.getToContext(), DC, Loc, AssertExpr, ToMsg, |
| 1769 | Importer.Import(D->getRParenLoc()), D->isFailed())) |
| 1770 | return ToD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1771 | |
| 1772 | ToD->setLexicalDeclContext(LexicalDC); |
| 1773 | LexicalDC->addDeclInternal(ToD); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1774 | return ToD; |
| 1775 | } |
| 1776 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1777 | Decl *ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
| 1778 | // Import the major distinguishing characteristics of this namespace. |
| 1779 | DeclContext *DC, *LexicalDC; |
| 1780 | DeclarationName Name; |
| 1781 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1782 | NamedDecl *ToD; |
| 1783 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1784 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1785 | if (ToD) |
| 1786 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1787 | |
| 1788 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1789 | if (!Name) { |
| 1790 | // This is an anonymous namespace. Adopt an existing anonymous |
| 1791 | // namespace if we can. |
| 1792 | // FIXME: Not testable. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1793 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1794 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 1795 | else |
| 1796 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 1797 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1798 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1799 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1800 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1801 | for (auto *FoundDecl : FoundDecls) { |
| 1802 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1803 | continue; |
| 1804 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1805 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1806 | MergeWithNamespace = FoundNS; |
| 1807 | ConflictingDecls.clear(); |
| 1808 | break; |
| 1809 | } |
| 1810 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1811 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 1815 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1816 | ConflictingDecls.data(), |
| 1817 | ConflictingDecls.size()); |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | // Create the "to" namespace, if needed. |
| 1822 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 1823 | if (!ToNamespace) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1824 | if (GetImportedOrCreateDecl( |
| 1825 | ToNamespace, D, Importer.getToContext(), DC, D->isInline(), |
| 1826 | Importer.Import(D->getLocStart()), Loc, Name.getAsIdentifierInfo(), |
| 1827 | /*PrevDecl=*/nullptr)) |
| 1828 | return ToNamespace; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1829 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1830 | LexicalDC->addDeclInternal(ToNamespace); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1831 | |
| 1832 | // If this is an anonymous namespace, register it as the anonymous |
| 1833 | // namespace within its context. |
| 1834 | if (!Name) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1835 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1836 | TU->setAnonymousNamespace(ToNamespace); |
| 1837 | else |
| 1838 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 1839 | } |
| 1840 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1841 | Importer.MapImported(D, ToNamespace); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1842 | |
| 1843 | ImportDeclContext(D); |
| 1844 | |
| 1845 | return ToNamespace; |
| 1846 | } |
| 1847 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1848 | Decl *ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 1849 | // Import the major distinguishing characteristics of this namespace. |
| 1850 | DeclContext *DC, *LexicalDC; |
| 1851 | DeclarationName Name; |
| 1852 | SourceLocation Loc; |
| 1853 | NamedDecl *LookupD; |
| 1854 | if (ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 1855 | return nullptr; |
| 1856 | if (LookupD) |
| 1857 | return LookupD; |
| 1858 | |
| 1859 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 1860 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1861 | auto *TargetDecl = cast_or_null<NamespaceDecl>( |
| 1862 | Importer.Import(D->getNamespace())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1863 | if (!TargetDecl) |
| 1864 | return nullptr; |
| 1865 | |
| 1866 | IdentifierInfo *ToII = Importer.Import(D->getIdentifier()); |
| 1867 | if (!ToII) |
| 1868 | return nullptr; |
| 1869 | |
| 1870 | NestedNameSpecifierLoc ToQLoc = Importer.Import(D->getQualifierLoc()); |
| 1871 | if (D->getQualifierLoc() && !ToQLoc) |
| 1872 | return nullptr; |
| 1873 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1874 | NamespaceAliasDecl *ToD; |
| 1875 | if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, |
| 1876 | Importer.Import(D->getNamespaceLoc()), |
| 1877 | Importer.Import(D->getAliasLoc()), ToII, ToQLoc, |
| 1878 | Importer.Import(D->getTargetNameLoc()), |
| 1879 | TargetDecl)) |
| 1880 | return ToD; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1881 | |
| 1882 | ToD->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1883 | LexicalDC->addDeclInternal(ToD); |
| 1884 | |
| 1885 | return ToD; |
| 1886 | } |
| 1887 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1888 | Decl *ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1889 | // Import the major distinguishing characteristics of this typedef. |
| 1890 | DeclContext *DC, *LexicalDC; |
| 1891 | DeclarationName Name; |
| 1892 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1893 | NamedDecl *ToD; |
| 1894 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1895 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1896 | if (ToD) |
| 1897 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1898 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1899 | // If this typedef is not in block scope, determine whether we've |
| 1900 | // seen a typedef with the same name (that we can merge with) or any |
| 1901 | // other entity by that name (which name lookup could conflict with). |
| 1902 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1903 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1904 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1905 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1906 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1907 | for (auto *FoundDecl : FoundDecls) { |
| 1908 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1909 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1910 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1911 | if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(), |
| 1912 | FoundTypedef->getUnderlyingType())) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1913 | return Importer.MapImported(D, FoundTypedef); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1914 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1915 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1916 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1917 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1918 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1919 | if (!ConflictingDecls.empty()) { |
| 1920 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1921 | ConflictingDecls.data(), |
| 1922 | ConflictingDecls.size()); |
| 1923 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1924 | return nullptr; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1925 | } |
| 1926 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1927 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1928 | // Import the underlying type of this typedef; |
| 1929 | QualType T = Importer.Import(D->getUnderlyingType()); |
| 1930 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1931 | return nullptr; |
| 1932 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1933 | // Create the new typedef node. |
| 1934 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 1935 | SourceLocation StartL = Importer.Import(D->getLocStart()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1936 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1937 | TypedefNameDecl *ToTypedef; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1938 | if (IsAlias) { |
| 1939 | if (GetImportedOrCreateDecl<TypeAliasDecl>( |
| 1940 | ToTypedef, D, Importer.getToContext(), DC, StartL, Loc, |
| 1941 | Name.getAsIdentifierInfo(), TInfo)) |
| 1942 | return ToTypedef; |
| 1943 | } else if (GetImportedOrCreateDecl<TypedefDecl>( |
| 1944 | ToTypedef, D, Importer.getToContext(), DC, StartL, Loc, |
| 1945 | Name.getAsIdentifierInfo(), TInfo)) |
| 1946 | return ToTypedef; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1947 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1948 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1949 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1950 | |
| 1951 | // Templated declarations should not appear in DeclContext. |
| 1952 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 1953 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 1954 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1955 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1956 | return ToTypedef; |
| 1957 | } |
| 1958 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1959 | Decl *ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
| 1960 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 1961 | } |
| 1962 | |
| 1963 | Decl *ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| 1964 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 1965 | } |
| 1966 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1967 | Decl *ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| 1968 | // Import the major distinguishing characteristics of this typedef. |
| 1969 | DeclContext *DC, *LexicalDC; |
| 1970 | DeclarationName Name; |
| 1971 | SourceLocation Loc; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1972 | NamedDecl *FoundD; |
| 1973 | if (ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1974 | return nullptr; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1975 | if (FoundD) |
| 1976 | return FoundD; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1977 | |
| 1978 | // If this typedef is not in block scope, determine whether we've |
| 1979 | // seen a typedef with the same name (that we can merge with) or any |
| 1980 | // other entity by that name (which name lookup could conflict with). |
| 1981 | if (!DC->isFunctionOrMethod()) { |
| 1982 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 1983 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 1984 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 1985 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1986 | for (auto *FoundDecl : FoundDecls) { |
| 1987 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1988 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1989 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 1990 | return Importer.MapImported(D, FoundAlias); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1991 | ConflictingDecls.push_back(FoundDecl); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | if (!ConflictingDecls.empty()) { |
| 1995 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1996 | ConflictingDecls.data(), |
| 1997 | ConflictingDecls.size()); |
| 1998 | if (!Name) |
| 1999 | return nullptr; |
| 2000 | } |
| 2001 | } |
| 2002 | |
| 2003 | TemplateParameterList *Params = ImportTemplateParameterList( |
| 2004 | D->getTemplateParameters()); |
| 2005 | if (!Params) |
| 2006 | return nullptr; |
| 2007 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2008 | auto *TemplDecl = cast_or_null<TypeAliasDecl>( |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2009 | Importer.Import(D->getTemplatedDecl())); |
| 2010 | if (!TemplDecl) |
| 2011 | return nullptr; |
| 2012 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2013 | TypeAliasTemplateDecl *ToAlias; |
| 2014 | if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc, |
| 2015 | Name, Params, TemplDecl)) |
| 2016 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2017 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2018 | TemplDecl->setDescribedAliasTemplate(ToAlias); |
| 2019 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2020 | ToAlias->setAccess(D->getAccess()); |
| 2021 | ToAlias->setLexicalDeclContext(LexicalDC); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2022 | LexicalDC->addDeclInternal(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2023 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 2024 | } |
| 2025 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2026 | Decl *ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
| 2027 | // Import the major distinguishing characteristics of this label. |
| 2028 | DeclContext *DC, *LexicalDC; |
| 2029 | DeclarationName Name; |
| 2030 | SourceLocation Loc; |
| 2031 | NamedDecl *ToD; |
| 2032 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 2033 | return nullptr; |
| 2034 | if (ToD) |
| 2035 | return ToD; |
| 2036 | |
| 2037 | assert(LexicalDC->isFunctionOrMethod()); |
| 2038 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2039 | LabelDecl *ToLabel; |
| 2040 | if (D->isGnuLocal() |
| 2041 | ? GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, |
| 2042 | Importer.Import(D->getLocation()), |
| 2043 | Name.getAsIdentifierInfo(), |
| 2044 | Importer.Import(D->getLocStart())) |
| 2045 | : GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, |
| 2046 | Importer.Import(D->getLocation()), |
| 2047 | Name.getAsIdentifierInfo())) |
| 2048 | return ToLabel; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2049 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2050 | auto *Label = cast_or_null<LabelStmt>(Importer.Import(D->getStmt())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 2051 | if (!Label) |
| 2052 | return nullptr; |
| 2053 | |
| 2054 | ToLabel->setStmt(Label); |
| 2055 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 2056 | LexicalDC->addDeclInternal(ToLabel); |
| 2057 | return ToLabel; |
| 2058 | } |
| 2059 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2060 | Decl *ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
| 2061 | // Import the major distinguishing characteristics of this enum. |
| 2062 | DeclContext *DC, *LexicalDC; |
| 2063 | DeclarationName Name; |
| 2064 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2065 | NamedDecl *ToD; |
| 2066 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2067 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2068 | if (ToD) |
| 2069 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2070 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2071 | // Figure out what enum name we're looking for. |
| 2072 | unsigned IDNS = Decl::IDNS_Tag; |
| 2073 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2074 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 2075 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2076 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2077 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2078 | IDNS |= Decl::IDNS_Ordinary; |
| 2079 | |
| 2080 | // We may already have an enum of the same name; try to find and match it. |
| 2081 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2082 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2083 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 2084 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2085 | for (auto *FoundDecl : FoundDecls) { |
| 2086 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2087 | continue; |
| 2088 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2089 | Decl *Found = FoundDecl; |
| 2090 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2091 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2092 | Found = Tag->getDecl(); |
| 2093 | } |
| 2094 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2095 | if (auto *FoundEnum = dyn_cast<EnumDecl>(Found)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2096 | if (IsStructuralMatch(D, FoundEnum)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2097 | return Importer.MapImported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2098 | } |
| 2099 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2100 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | if (!ConflictingDecls.empty()) { |
| 2104 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2105 | ConflictingDecls.data(), |
| 2106 | ConflictingDecls.size()); |
| 2107 | } |
| 2108 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2109 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2110 | // Create the enum declaration. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2111 | EnumDecl *D2; |
| 2112 | if (GetImportedOrCreateDecl( |
| 2113 | D2, D, Importer.getToContext(), DC, Importer.Import(D->getLocStart()), |
| 2114 | Loc, Name.getAsIdentifierInfo(), nullptr, D->isScoped(), |
| 2115 | D->isScopedUsingClassTag(), D->isFixed())) |
| 2116 | return D2; |
| 2117 | |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 2118 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2119 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2120 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2121 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2122 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2123 | |
| 2124 | // Import the integer type. |
| 2125 | QualType ToIntegerType = Importer.Import(D->getIntegerType()); |
| 2126 | if (ToIntegerType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2127 | return nullptr; |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2128 | D2->setIntegerType(ToIntegerType); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2129 | |
| 2130 | // Import the definition |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 2131 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2132 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2133 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2134 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2137 | Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
| 2138 | // If this record has a definition in the translation unit we're coming from, |
| 2139 | // but this particular declaration is not that definition, import the |
| 2140 | // definition and map to that. |
Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 2141 | TagDecl *Definition = D->getDefinition(); |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2142 | if (Definition && Definition != D && |
| 2143 | // In contrast to a normal CXXRecordDecl, the implicit |
| 2144 | // CXXRecordDecl of ClassTemplateSpecializationDecl is its redeclaration. |
| 2145 | // The definition of the implicit CXXRecordDecl in this case is the |
| 2146 | // ClassTemplateSpecializationDecl itself. Thus, we start with an extra |
| 2147 | // condition in order to be able to import the implict Decl. |
| 2148 | !D->isImplicit()) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2149 | Decl *ImportedDef = Importer.Import(Definition); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2150 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2151 | return nullptr; |
| 2152 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2153 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2154 | } |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame] | 2155 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2156 | // Import the major distinguishing characteristics of this record. |
| 2157 | DeclContext *DC, *LexicalDC; |
| 2158 | DeclarationName Name; |
| 2159 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2160 | NamedDecl *ToD; |
| 2161 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2162 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2163 | if (ToD) |
| 2164 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2165 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2166 | // Figure out what structure name we're looking for. |
| 2167 | unsigned IDNS = Decl::IDNS_Tag; |
| 2168 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 2169 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 2170 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2171 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2172 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2173 | IDNS |= Decl::IDNS_Ordinary; |
| 2174 | |
| 2175 | // 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] | 2176 | RecordDecl *AdoptDecl = nullptr; |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2177 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2178 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2179 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2180 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 2181 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2182 | |
| 2183 | if (!FoundDecls.empty()) { |
| 2184 | // We're going to have to compare D against potentially conflicting Decls, so complete it. |
| 2185 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2186 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2187 | } |
| 2188 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2189 | for (auto *FoundDecl : FoundDecls) { |
| 2190 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2191 | continue; |
| 2192 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2193 | Decl *Found = FoundDecl; |
| 2194 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2195 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2196 | Found = Tag->getDecl(); |
| 2197 | } |
Gabor Marton | a0df7a9 | 2018-05-30 09:19:26 +0000 | [diff] [blame] | 2198 | |
| 2199 | if (D->getDescribedTemplate()) { |
| 2200 | if (auto *Template = dyn_cast<ClassTemplateDecl>(Found)) |
| 2201 | Found = Template->getTemplatedDecl(); |
| 2202 | else |
| 2203 | continue; |
| 2204 | } |
| 2205 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2206 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Aleksei Sidorin | 499de6c | 2018-04-05 15:31:49 +0000 | [diff] [blame] | 2207 | if (!SearchName) { |
Gabor Marton | 0bebf95 | 2018-07-05 09:51:13 +0000 | [diff] [blame] | 2208 | if (!IsStructuralMatch(D, FoundRecord, false)) |
| 2209 | continue; |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2210 | } |
| 2211 | |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2212 | PrevDecl = FoundRecord; |
| 2213 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2214 | if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2215 | if ((SearchName && !D->isCompleteDefinition()) |
| 2216 | || (D->isCompleteDefinition() && |
| 2217 | D->isAnonymousStructOrUnion() |
| 2218 | == FoundDef->isAnonymousStructOrUnion() && |
| 2219 | IsStructuralMatch(D, FoundDef))) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2220 | // The record types structurally match, or the "from" translation |
| 2221 | // unit only had a forward declaration anyway; call it the same |
| 2222 | // function. |
Balazs Keri | 1d20cc2 | 2018-07-16 12:16:39 +0000 | [diff] [blame] | 2223 | // FIXME: Structural equivalence check should check for same |
| 2224 | // user-defined methods. |
| 2225 | Importer.MapImported(D, FoundDef); |
| 2226 | if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
| 2227 | auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef); |
| 2228 | assert(FoundCXX && "Record type mismatch"); |
| 2229 | |
| 2230 | if (D->isCompleteDefinition() && !Importer.isMinimalImport()) |
| 2231 | // FoundDef may not have every implicit method that D has |
| 2232 | // because implicit methods are created only if they are used. |
| 2233 | ImportImplicitMethods(DCXX, FoundCXX); |
| 2234 | } |
| 2235 | return FoundDef; |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2236 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2237 | } else if (!D->isCompleteDefinition()) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2238 | // We have a forward declaration of this type, so adopt that forward |
| 2239 | // declaration rather than building a new one. |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2240 | |
| 2241 | // If one or both can be completed from external storage then try one |
| 2242 | // last time to complete and compare them before doing this. |
| 2243 | |
| 2244 | if (FoundRecord->hasExternalLexicalStorage() && |
| 2245 | !FoundRecord->isCompleteDefinition()) |
| 2246 | FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord); |
| 2247 | if (D->hasExternalLexicalStorage()) |
| 2248 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2249 | |
| 2250 | if (FoundRecord->isCompleteDefinition() && |
| 2251 | D->isCompleteDefinition() && |
| 2252 | !IsStructuralMatch(D, FoundRecord)) |
| 2253 | continue; |
| 2254 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2255 | AdoptDecl = FoundRecord; |
| 2256 | continue; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2257 | } else if (!SearchName) { |
| 2258 | continue; |
| 2259 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2260 | } |
| 2261 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2262 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2263 | } |
| 2264 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2265 | if (!ConflictingDecls.empty() && SearchName) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2266 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2267 | ConflictingDecls.data(), |
| 2268 | ConflictingDecls.size()); |
| 2269 | } |
| 2270 | } |
| 2271 | |
| 2272 | // Create the record declaration. |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2273 | RecordDecl *D2 = AdoptDecl; |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 2274 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2275 | if (!D2) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2276 | CXXRecordDecl *D2CXX = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2277 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2278 | if (DCXX->isLambda()) { |
| 2279 | TypeSourceInfo *TInfo = Importer.Import(DCXX->getLambdaTypeInfo()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2280 | if (GetImportedOrCreateSpecialDecl( |
| 2281 | D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(), |
| 2282 | DC, TInfo, Loc, DCXX->isDependentLambda(), |
| 2283 | DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault())) |
| 2284 | return D2CXX; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2285 | Decl *CDecl = Importer.Import(DCXX->getLambdaContextDecl()); |
| 2286 | if (DCXX->getLambdaContextDecl() && !CDecl) |
| 2287 | return nullptr; |
Sean Callanan | 041cceb | 2016-05-14 05:43:57 +0000 | [diff] [blame] | 2288 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), CDecl); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2289 | } else if (DCXX->isInjectedClassName()) { |
| 2290 | // We have to be careful to do a similar dance to the one in |
| 2291 | // Sema::ActOnStartCXXMemberDeclarations |
| 2292 | CXXRecordDecl *const PrevDecl = nullptr; |
| 2293 | const bool DelayTypeCreation = true; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2294 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2295 | D->getTagKind(), DC, StartLoc, Loc, |
| 2296 | Name.getAsIdentifierInfo(), PrevDecl, |
| 2297 | DelayTypeCreation)) |
| 2298 | return D2CXX; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2299 | Importer.getToContext().getTypeDeclType( |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2300 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2301 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2302 | if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(), |
| 2303 | D->getTagKind(), DC, StartLoc, Loc, |
| 2304 | Name.getAsIdentifierInfo(), |
| 2305 | cast_or_null<CXXRecordDecl>(PrevDecl))) |
| 2306 | return D2CXX; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2307 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2308 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2309 | D2 = D2CXX; |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2310 | D2->setAccess(D->getAccess()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2311 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | de8bf26 | 2018-05-17 09:46:07 +0000 | [diff] [blame] | 2312 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2313 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2314 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2315 | if (ClassTemplateDecl *FromDescribed = |
| 2316 | DCXX->getDescribedClassTemplate()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2317 | auto *ToDescribed = cast_or_null<ClassTemplateDecl>( |
| 2318 | Importer.Import(FromDescribed)); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2319 | if (!ToDescribed) |
| 2320 | return nullptr; |
| 2321 | D2CXX->setDescribedClassTemplate(ToDescribed); |
Gabor Marton | 5915777e | 2018-06-26 13:44:24 +0000 | [diff] [blame] | 2322 | if (!DCXX->isInjectedClassName()) { |
| 2323 | // In a record describing a template the type should be an |
| 2324 | // InjectedClassNameType (see Sema::CheckClassTemplate). Update the |
| 2325 | // previously set type to the correct value here (ToDescribed is not |
| 2326 | // available at record create). |
| 2327 | // FIXME: The previous type is cleared but not removed from |
| 2328 | // ASTContext's internal storage. |
| 2329 | CXXRecordDecl *Injected = nullptr; |
| 2330 | for (NamedDecl *Found : D2CXX->noload_lookup(Name)) { |
| 2331 | auto *Record = dyn_cast<CXXRecordDecl>(Found); |
| 2332 | if (Record && Record->isInjectedClassName()) { |
| 2333 | Injected = Record; |
| 2334 | break; |
| 2335 | } |
| 2336 | } |
| 2337 | D2CXX->setTypeForDecl(nullptr); |
| 2338 | Importer.getToContext().getInjectedClassNameType(D2CXX, |
| 2339 | ToDescribed->getInjectedClassNameSpecialization()); |
| 2340 | if (Injected) { |
| 2341 | Injected->setTypeForDecl(nullptr); |
| 2342 | Importer.getToContext().getTypeDeclType(Injected, D2CXX); |
| 2343 | } |
| 2344 | } |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2345 | } else if (MemberSpecializationInfo *MemberInfo = |
| 2346 | DCXX->getMemberSpecializationInfo()) { |
| 2347 | TemplateSpecializationKind SK = |
| 2348 | MemberInfo->getTemplateSpecializationKind(); |
| 2349 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2350 | auto *ToInst = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2351 | cast_or_null<CXXRecordDecl>(Importer.Import(FromInst)); |
| 2352 | if (FromInst && !ToInst) |
| 2353 | return nullptr; |
| 2354 | D2CXX->setInstantiationOfMemberClass(ToInst, SK); |
| 2355 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2356 | Importer.Import(MemberInfo->getPointOfInstantiation())); |
| 2357 | } |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2358 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2359 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), |
| 2360 | D->getTagKind(), DC, StartLoc, Loc, |
| 2361 | Name.getAsIdentifierInfo(), PrevDecl)) |
| 2362 | return D2; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2363 | D2->setLexicalDeclContext(LexicalDC); |
| 2364 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2365 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2366 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2367 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2368 | if (D->isAnonymousStructOrUnion()) |
| 2369 | D2->setAnonymousStructOrUnion(true); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2370 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2371 | |
| 2372 | Importer.MapImported(D, D2); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2373 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 2374 | if (D->isCompleteDefinition() && ImportDefinition(D, D2, IDK_Default)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2375 | return nullptr; |
| 2376 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2377 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2380 | Decl *ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| 2381 | // Import the major distinguishing characteristics of this enumerator. |
| 2382 | DeclContext *DC, *LexicalDC; |
| 2383 | DeclarationName Name; |
| 2384 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2385 | NamedDecl *ToD; |
| 2386 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2387 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2388 | if (ToD) |
| 2389 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2390 | |
| 2391 | QualType T = Importer.Import(D->getType()); |
| 2392 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2393 | return nullptr; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2394 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2395 | // Determine whether there are any other declarations with the same name and |
| 2396 | // in the same context. |
| 2397 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2398 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2399 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2400 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2401 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2402 | for (auto *FoundDecl : FoundDecls) { |
| 2403 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2404 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2405 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2406 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2407 | if (IsStructuralMatch(D, FoundEnumConstant)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2408 | return Importer.MapImported(D, FoundEnumConstant); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2409 | } |
| 2410 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2411 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | if (!ConflictingDecls.empty()) { |
| 2415 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2416 | ConflictingDecls.data(), |
| 2417 | ConflictingDecls.size()); |
| 2418 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2419 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2420 | } |
| 2421 | } |
| 2422 | |
| 2423 | Expr *Init = Importer.Import(D->getInitExpr()); |
| 2424 | if (D->getInitExpr() && !Init) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2425 | return nullptr; |
| 2426 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2427 | EnumConstantDecl *ToEnumerator; |
| 2428 | if (GetImportedOrCreateDecl( |
| 2429 | ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
| 2430 | Name.getAsIdentifierInfo(), T, Init, D->getInitVal())) |
| 2431 | return ToEnumerator; |
| 2432 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2433 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2434 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2435 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2436 | return ToEnumerator; |
| 2437 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2438 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2439 | bool ASTNodeImporter::ImportTemplateInformation(FunctionDecl *FromFD, |
| 2440 | FunctionDecl *ToFD) { |
| 2441 | switch (FromFD->getTemplatedKind()) { |
| 2442 | case FunctionDecl::TK_NonTemplate: |
| 2443 | case FunctionDecl::TK_FunctionTemplate: |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2444 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2445 | |
| 2446 | case FunctionDecl::TK_MemberSpecialization: { |
| 2447 | auto *InstFD = cast_or_null<FunctionDecl>( |
| 2448 | Importer.Import(FromFD->getInstantiatedFromMemberFunction())); |
| 2449 | if (!InstFD) |
| 2450 | return true; |
| 2451 | |
| 2452 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
| 2453 | SourceLocation POI = Importer.Import( |
| 2454 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation()); |
| 2455 | ToFD->setInstantiationOfMemberFunction(InstFD, TSK); |
| 2456 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2457 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2458 | } |
| 2459 | |
| 2460 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2461 | FunctionTemplateDecl* Template; |
| 2462 | OptionalTemplateArgsTy ToTemplArgs; |
| 2463 | std::tie(Template, ToTemplArgs) = |
| 2464 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| 2465 | if (!Template || !ToTemplArgs) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2466 | return true; |
| 2467 | |
| 2468 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2469 | Importer.getToContext(), *ToTemplArgs); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2470 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2471 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2472 | TemplateArgumentListInfo ToTAInfo; |
| 2473 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2474 | if (FromTAArgsAsWritten) |
| 2475 | if (ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2476 | return true; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2477 | |
| 2478 | SourceLocation POI = Importer.Import(FTSInfo->getPointOfInstantiation()); |
| 2479 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2480 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2481 | ToFD->setFunctionTemplateSpecialization( |
| 2482 | Template, ToTAList, /* InsertPos= */ nullptr, |
| 2483 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, POI); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2484 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 2488 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 2489 | UnresolvedSet<8> TemplDecls; |
| 2490 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 2491 | for (unsigned I = 0; I < NumTemplates; I++) { |
| 2492 | if (auto *ToFTD = cast_or_null<FunctionTemplateDecl>( |
| 2493 | Importer.Import(FromInfo->getTemplate(I)))) |
| 2494 | TemplDecls.addDecl(ToFTD); |
| 2495 | else |
| 2496 | return true; |
| 2497 | } |
| 2498 | |
| 2499 | // Import TemplateArgumentListInfo. |
| 2500 | TemplateArgumentListInfo ToTAInfo; |
| 2501 | if (ImportTemplateArgumentListInfo( |
| 2502 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 2503 | llvm::makeArrayRef(FromInfo->getTemplateArgs(), |
| 2504 | FromInfo->getNumTemplateArgs()), |
| 2505 | ToTAInfo)) |
| 2506 | return true; |
| 2507 | |
| 2508 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 2509 | TemplDecls, ToTAInfo); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2510 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2511 | } |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2512 | } |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2513 | llvm_unreachable("All cases should be covered!"); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2514 | } |
| 2515 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2516 | FunctionDecl * |
| 2517 | ASTNodeImporter::FindFunctionTemplateSpecialization(FunctionDecl *FromFD) { |
| 2518 | FunctionTemplateDecl* Template; |
| 2519 | OptionalTemplateArgsTy ToTemplArgs; |
| 2520 | std::tie(Template, ToTemplArgs) = |
| 2521 | ImportFunctionTemplateWithTemplateArgsFromSpecialization(FromFD); |
| 2522 | if (!Template || !ToTemplArgs) |
| 2523 | return nullptr; |
| 2524 | |
| 2525 | void *InsertPos = nullptr; |
| 2526 | auto *FoundSpec = Template->findSpecialization(*ToTemplArgs, InsertPos); |
| 2527 | return FoundSpec; |
| 2528 | } |
| 2529 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2530 | Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2531 | |
| 2532 | SmallVector<Decl*, 2> Redecls = getCanonicalForwardRedeclChain(D); |
| 2533 | auto RedeclIt = Redecls.begin(); |
| 2534 | // Import the first part of the decl chain. I.e. import all previous |
| 2535 | // declarations starting from the canonical decl. |
| 2536 | for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) |
| 2537 | if (!Importer.Import(*RedeclIt)) |
| 2538 | return nullptr; |
| 2539 | assert(*RedeclIt == D); |
| 2540 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2541 | // Import the major distinguishing characteristics of this function. |
| 2542 | DeclContext *DC, *LexicalDC; |
| 2543 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2544 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2545 | NamedDecl *ToD; |
| 2546 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2547 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2548 | if (ToD) |
| 2549 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2550 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2551 | const FunctionDecl *FoundByLookup = nullptr; |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 2552 | FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate(); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2553 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2554 | // If this is a function template specialization, then try to find the same |
| 2555 | // existing specialization in the "to" context. The localUncachedLookup |
| 2556 | // below will not find any specialization, but would find the primary |
| 2557 | // template; thus, we have to skip normal lookup in case of specializations. |
| 2558 | // FIXME handle member function templates (TK_MemberSpecialization) similarly? |
| 2559 | if (D->getTemplatedKind() == |
| 2560 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
| 2561 | if (FunctionDecl *FoundFunction = FindFunctionTemplateSpecialization(D)) { |
| 2562 | if (D->doesThisDeclarationHaveABody() && |
| 2563 | FoundFunction->hasBody()) |
| 2564 | return Importer.Imported(D, FoundFunction); |
| 2565 | FoundByLookup = FoundFunction; |
| 2566 | } |
| 2567 | } |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2568 | // Try to find a function in our own ("to") context with the same name, same |
| 2569 | // type, and in the same context as the function we're importing. |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2570 | else if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2571 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2572 | unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_OrdinaryFriend; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2573 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2574 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2575 | for (auto *FoundDecl : FoundDecls) { |
| 2576 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2577 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2578 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 2579 | // If template was found, look at the templated function. |
| 2580 | if (FromFT) { |
| 2581 | if (auto *Template = dyn_cast<FunctionTemplateDecl>(FoundDecl)) |
| 2582 | FoundDecl = Template->getTemplatedDecl(); |
| 2583 | else |
| 2584 | continue; |
| 2585 | } |
| 2586 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2587 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 2588 | if (FoundFunction->hasExternalFormalLinkage() && |
| 2589 | D->hasExternalFormalLinkage()) { |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2590 | if (IsStructuralMatch(D, FoundFunction)) { |
| 2591 | const FunctionDecl *Definition = nullptr; |
| 2592 | if (D->doesThisDeclarationHaveABody() && |
| 2593 | FoundFunction->hasBody(Definition)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2594 | return Importer.MapImported( |
Balazs Keri | c7797c4 | 2018-07-11 09:37:24 +0000 | [diff] [blame] | 2595 | D, const_cast<FunctionDecl *>(Definition)); |
| 2596 | } |
| 2597 | FoundByLookup = FoundFunction; |
| 2598 | break; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2599 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2600 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2601 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 2602 | // Sema::IsOverload out to the AST library. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2603 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2604 | // Function overloading is okay in C++. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2605 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2606 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2607 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2608 | // Complain about inconsistent function types. |
| 2609 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2610 | << Name << D->getType() << FoundFunction->getType(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2611 | Importer.ToDiag(FoundFunction->getLocation(), |
| 2612 | diag::note_odr_value_here) |
| 2613 | << FoundFunction->getType(); |
| 2614 | } |
| 2615 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2616 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2617 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2618 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2619 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2620 | if (!ConflictingDecls.empty()) { |
| 2621 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2622 | ConflictingDecls.data(), |
| 2623 | ConflictingDecls.size()); |
| 2624 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2625 | return nullptr; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2626 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2627 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2628 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2629 | DeclarationNameInfo NameInfo(Name, Loc); |
| 2630 | // Import additional name location/type info. |
| 2631 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 2632 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2633 | QualType FromTy = D->getType(); |
| 2634 | bool usedDifferentExceptionSpec = false; |
| 2635 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2636 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2637 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 2638 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 2639 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 2640 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 2641 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 2642 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 2643 | FromEPI.ExceptionSpec.SourceTemplate || |
| 2644 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2645 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 2646 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2647 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2648 | usedDifferentExceptionSpec = true; |
| 2649 | } |
| 2650 | } |
| 2651 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2652 | // Import the type. |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2653 | QualType T = Importer.Import(FromTy); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2654 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2655 | return nullptr; |
| 2656 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2657 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2658 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2659 | for (auto P : D->parameters()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2660 | auto *ToP = cast_or_null<ParmVarDecl>(Importer.Import(P)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2661 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2662 | return nullptr; |
| 2663 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2664 | Parameters.push_back(ToP); |
| 2665 | } |
| 2666 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2667 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2668 | if (D->getTypeSourceInfo() && !TInfo) |
| 2669 | return nullptr; |
| 2670 | |
| 2671 | // Create the imported function. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2672 | FunctionDecl *ToFunction = nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2673 | SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2674 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2675 | if (GetImportedOrCreateDecl<CXXConstructorDecl>( |
| 2676 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 2677 | InnerLocStart, NameInfo, T, TInfo, FromConstructor->isExplicit(), |
| 2678 | D->isInlineSpecified(), D->isImplicit(), D->isConstexpr())) |
| 2679 | return ToFunction; |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2680 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 2681 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2682 | for (auto *I : FromConstructor->inits()) { |
| 2683 | auto *ToI = cast_or_null<CXXCtorInitializer>(Importer.Import(I)); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2684 | if (!ToI && I) |
| 2685 | return nullptr; |
| 2686 | CtorInitializers.push_back(ToI); |
| 2687 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2688 | auto **Memory = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2689 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 2690 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2691 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2692 | ToCtor->setCtorInitializers(Memory); |
| 2693 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 2694 | } |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2695 | } else if (isa<CXXDestructorDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2696 | if (GetImportedOrCreateDecl<CXXDestructorDecl>( |
| 2697 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 2698 | InnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 2699 | D->isImplicit())) |
| 2700 | return ToFunction; |
| 2701 | } else if (CXXConversionDecl *FromConversion = |
| 2702 | dyn_cast<CXXConversionDecl>(D)) { |
| 2703 | if (GetImportedOrCreateDecl<CXXConversionDecl>( |
| 2704 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 2705 | InnerLocStart, NameInfo, T, TInfo, D->isInlineSpecified(), |
| 2706 | FromConversion->isExplicit(), D->isConstexpr(), SourceLocation())) |
| 2707 | return ToFunction; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2708 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2709 | if (GetImportedOrCreateDecl<CXXMethodDecl>( |
| 2710 | ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC), |
| 2711 | InnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(), |
| 2712 | Method->isInlineSpecified(), D->isConstexpr(), SourceLocation())) |
| 2713 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2714 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2715 | if (GetImportedOrCreateDecl(ToFunction, D, Importer.getToContext(), DC, |
| 2716 | InnerLocStart, NameInfo, T, TInfo, |
| 2717 | D->getStorageClass(), D->isInlineSpecified(), |
| 2718 | D->hasWrittenPrototype(), D->isConstexpr())) |
| 2719 | return ToFunction; |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2720 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 2721 | |
| 2722 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2723 | ToFunction->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2724 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2725 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 2726 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 2727 | ToFunction->setTrivial(D->isTrivial()); |
| 2728 | ToFunction->setPure(D->isPure()); |
Rafael Stahl | a001047 | 2018-07-09 08:40:17 +0000 | [diff] [blame] | 2729 | ToFunction->setRangeEnd(Importer.Import(D->getLocEnd())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2730 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2731 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2732 | for (auto *Param : Parameters) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2733 | Param->setOwningFunction(ToFunction); |
| 2734 | ToFunction->addDeclInternal(Param); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2735 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 2736 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2737 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2738 | if (FoundByLookup) { |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2739 | auto *Recent = const_cast<FunctionDecl *>( |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2740 | FoundByLookup->getMostRecentDecl()); |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2741 | ToFunction->setPreviousDecl(Recent); |
| 2742 | } |
| 2743 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2744 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 2745 | // params it refers to. |
| 2746 | if (TInfo) { |
| 2747 | if (auto ProtoLoc = |
| 2748 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 2749 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 2750 | ProtoLoc.setParam(I, Parameters[I]); |
| 2751 | } |
| 2752 | } |
| 2753 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2754 | if (usedDifferentExceptionSpec) { |
| 2755 | // Update FunctionProtoType::ExtProtoInfo. |
| 2756 | QualType T = Importer.Import(D->getType()); |
| 2757 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2758 | return nullptr; |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2759 | ToFunction->setType(T); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 2760 | } |
| 2761 | |
Balazs Keri | a35798d | 2018-07-17 09:52:41 +0000 | [diff] [blame] | 2762 | // Import the describing template function, if any. |
| 2763 | if (FromFT) |
| 2764 | if (!Importer.Import(FromFT)) |
| 2765 | return nullptr; |
| 2766 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2767 | if (D->doesThisDeclarationHaveABody()) { |
| 2768 | if (Stmt *FromBody = D->getBody()) { |
| 2769 | if (Stmt *ToBody = Importer.Import(FromBody)) { |
| 2770 | ToFunction->setBody(ToBody); |
| 2771 | } |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2772 | } |
| 2773 | } |
| 2774 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2775 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2776 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2777 | // If it is a template, import all related things. |
| 2778 | if (ImportTemplateInformation(D, ToFunction)) |
| 2779 | return nullptr; |
| 2780 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2781 | bool IsFriend = D->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend); |
| 2782 | |
| 2783 | // TODO Can we generalize this approach to other AST nodes as well? |
| 2784 | if (D->getDeclContext()->containsDeclAndLoad(D)) |
| 2785 | DC->addDeclInternal(ToFunction); |
| 2786 | if (DC != LexicalDC && D->getLexicalDeclContext()->containsDeclAndLoad(D)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2787 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2788 | |
Gabor Marton | 5254e64 | 2018-06-27 13:32:50 +0000 | [diff] [blame] | 2789 | // Friend declaration's lexical context is the befriending class, but the |
| 2790 | // semantic context is the enclosing scope of the befriending class. |
| 2791 | // We want the friend functions to be found in the semantic context by lookup. |
| 2792 | // FIXME should we handle this generically in VisitFriendDecl? |
| 2793 | // In Other cases when LexicalDC != DC we don't want it to be added, |
| 2794 | // e.g out-of-class definitions like void B::f() {} . |
| 2795 | if (LexicalDC != DC && IsFriend) { |
| 2796 | DC->makeDeclVisibleInContext(ToFunction); |
| 2797 | } |
| 2798 | |
| 2799 | // Import the rest of the chain. I.e. import all subsequent declarations. |
| 2800 | for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) |
| 2801 | if (!Importer.Import(*RedeclIt)) |
| 2802 | return nullptr; |
| 2803 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 2804 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 2805 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 2806 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2807 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2808 | } |
| 2809 | |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2810 | Decl *ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| 2811 | return VisitFunctionDecl(D); |
| 2812 | } |
| 2813 | |
| 2814 | Decl *ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| 2815 | return VisitCXXMethodDecl(D); |
| 2816 | } |
| 2817 | |
| 2818 | Decl *ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| 2819 | return VisitCXXMethodDecl(D); |
| 2820 | } |
| 2821 | |
| 2822 | Decl *ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| 2823 | return VisitCXXMethodDecl(D); |
| 2824 | } |
| 2825 | |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2826 | static unsigned getFieldIndex(Decl *F) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2827 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2828 | if (!Owner) |
| 2829 | return 0; |
| 2830 | |
| 2831 | unsigned Index = 1; |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2832 | for (const auto *D : Owner->noload_decls()) { |
| 2833 | if (D == F) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2834 | return Index; |
| 2835 | |
| 2836 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 2837 | ++Index; |
| 2838 | } |
| 2839 | |
| 2840 | return Index; |
| 2841 | } |
| 2842 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2843 | Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
| 2844 | // Import the major distinguishing characteristics of a variable. |
| 2845 | DeclContext *DC, *LexicalDC; |
| 2846 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2847 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2848 | NamedDecl *ToD; |
| 2849 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2850 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2851 | if (ToD) |
| 2852 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2853 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2854 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2855 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2856 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2857 | for (auto *FoundDecl : FoundDecls) { |
| 2858 | if (auto *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2859 | // For anonymous fields, match up by index. |
| 2860 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2861 | continue; |
| 2862 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2863 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2864 | FoundField->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2865 | Importer.MapImported(D, FoundField); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2866 | return FoundField; |
| 2867 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2868 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2869 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2870 | << Name << D->getType() << FoundField->getType(); |
| 2871 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2872 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2873 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2874 | } |
| 2875 | } |
| 2876 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2877 | // Import the type. |
| 2878 | QualType T = Importer.Import(D->getType()); |
| 2879 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2880 | return nullptr; |
| 2881 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2882 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2883 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 2884 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2885 | return nullptr; |
| 2886 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2887 | FieldDecl *ToField; |
| 2888 | if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, |
| 2889 | Importer.Import(D->getInnerLocStart()), Loc, |
| 2890 | Name.getAsIdentifierInfo(), T, TInfo, BitWidth, |
| 2891 | D->isMutable(), D->getInClassInitStyle())) |
| 2892 | return ToField; |
| 2893 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2894 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2895 | ToField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 3a83ea7 | 2016-03-03 02:22:05 +0000 | [diff] [blame] | 2896 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
Sean Callanan | bb33f58 | 2016-03-03 01:21:28 +0000 | [diff] [blame] | 2897 | Expr *ToInitializer = Importer.Import(FromInitializer); |
| 2898 | if (ToInitializer) |
| 2899 | ToField->setInClassInitializer(ToInitializer); |
| 2900 | else |
| 2901 | return nullptr; |
| 2902 | } |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2903 | ToField->setImplicit(D->isImplicit()); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2904 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2905 | return ToField; |
| 2906 | } |
| 2907 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2908 | Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| 2909 | // Import the major distinguishing characteristics of a variable. |
| 2910 | DeclContext *DC, *LexicalDC; |
| 2911 | DeclarationName Name; |
| 2912 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2913 | NamedDecl *ToD; |
| 2914 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2915 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2916 | if (ToD) |
| 2917 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2918 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2919 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2920 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2921 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2922 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2923 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2924 | // For anonymous indirect fields, match up by index. |
| 2925 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2926 | continue; |
| 2927 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2928 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2929 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 2930 | !Name.isEmpty())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2931 | Importer.MapImported(D, FoundField); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2932 | return FoundField; |
| 2933 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2934 | |
| 2935 | // If there are more anonymous fields to check, continue. |
| 2936 | if (!Name && I < N-1) |
| 2937 | continue; |
| 2938 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2939 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2940 | << Name << D->getType() << FoundField->getType(); |
| 2941 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2942 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2943 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2944 | } |
| 2945 | } |
| 2946 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2947 | // Import the type. |
| 2948 | QualType T = Importer.Import(D->getType()); |
| 2949 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2950 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2951 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2952 | auto **NamedChain = |
| 2953 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2954 | |
| 2955 | unsigned i = 0; |
Aaron Ballman | 29c9460 | 2014-03-07 18:36:15 +0000 | [diff] [blame] | 2956 | for (auto *PI : D->chain()) { |
Aaron Ballman | 1391608 | 2014-03-07 18:11:58 +0000 | [diff] [blame] | 2957 | Decl *D = Importer.Import(PI); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2958 | if (!D) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2959 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2960 | NamedChain[i++] = cast<NamedDecl>(D); |
| 2961 | } |
| 2962 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2963 | llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()}; |
| 2964 | IndirectFieldDecl *ToIndirectField; |
| 2965 | if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC, |
| 2966 | Loc, Name.getAsIdentifierInfo(), T, CH)) |
| 2967 | // FIXME here we leak `NamedChain` which is allocated before |
| 2968 | return ToIndirectField; |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2969 | |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 2970 | for (const auto *A : D->attrs()) |
| 2971 | ToIndirectField->addAttr(Importer.Import(A)); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2972 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2973 | ToIndirectField->setAccess(D->getAccess()); |
| 2974 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2975 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2976 | return ToIndirectField; |
| 2977 | } |
| 2978 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2979 | Decl *ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
| 2980 | // Import the major distinguishing characteristics of a declaration. |
| 2981 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 2982 | DeclContext *LexicalDC = D->getDeclContext() == D->getLexicalDeclContext() |
| 2983 | ? DC : Importer.ImportContext(D->getLexicalDeclContext()); |
| 2984 | if (!DC || !LexicalDC) |
| 2985 | return nullptr; |
| 2986 | |
| 2987 | // Determine whether we've already imported this decl. |
| 2988 | // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup. |
| 2989 | auto *RD = cast<CXXRecordDecl>(DC); |
| 2990 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2991 | |
| 2992 | while (ImportedFriend) { |
| 2993 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 2994 | if (IsStructuralMatch(D->getFriendDecl(), ImportedFriend->getFriendDecl(), |
| 2995 | /*Complain=*/false)) |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 2996 | return Importer.MapImported(D, ImportedFriend); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2997 | |
| 2998 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 2999 | if (Importer.IsStructurallyEquivalent( |
| 3000 | D->getFriendType()->getType(), |
| 3001 | ImportedFriend->getFriendType()->getType(), true)) |
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 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 3005 | } |
| 3006 | |
| 3007 | // Not found. Create it. |
| 3008 | FriendDecl::FriendUnion ToFU; |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 3009 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
| 3010 | auto *ToFriendD = cast_or_null<NamedDecl>(Importer.Import(FriendD)); |
| 3011 | if (ToFriendD && FriendD->getFriendObjectKind() != Decl::FOK_None && |
| 3012 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 3013 | ToFriendD->setObjectOfFriendDecl(false); |
| 3014 | |
| 3015 | ToFU = ToFriendD; |
| 3016 | } else // The friend is a type, not a decl. |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3017 | ToFU = Importer.Import(D->getFriendType()); |
| 3018 | if (!ToFU) |
| 3019 | return nullptr; |
| 3020 | |
| 3021 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3022 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3023 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
| 3024 | TemplateParameterList *List = ImportTemplateParameterList(FromTPLists[I]); |
| 3025 | if (!List) |
| 3026 | return nullptr; |
| 3027 | ToTPLists[I] = List; |
| 3028 | } |
| 3029 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3030 | FriendDecl *FrD; |
| 3031 | if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC, |
| 3032 | Importer.Import(D->getLocation()), ToFU, |
| 3033 | Importer.Import(D->getFriendLoc()), ToTPLists)) |
| 3034 | return FrD; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 3035 | |
| 3036 | FrD->setAccess(D->getAccess()); |
| 3037 | FrD->setLexicalDeclContext(LexicalDC); |
| 3038 | LexicalDC->addDeclInternal(FrD); |
| 3039 | return FrD; |
| 3040 | } |
| 3041 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3042 | Decl *ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| 3043 | // Import the major distinguishing characteristics of an ivar. |
| 3044 | DeclContext *DC, *LexicalDC; |
| 3045 | DeclarationName Name; |
| 3046 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3047 | NamedDecl *ToD; |
| 3048 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3049 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3050 | if (ToD) |
| 3051 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3052 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3053 | // Determine whether we've already imported this ivar |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3054 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3055 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3056 | for (auto *FoundDecl : FoundDecls) { |
| 3057 | if (auto *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3058 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3059 | FoundIvar->getType())) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3060 | Importer.MapImported(D, FoundIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3061 | return FoundIvar; |
| 3062 | } |
| 3063 | |
| 3064 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) |
| 3065 | << Name << D->getType() << FoundIvar->getType(); |
| 3066 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 3067 | << FoundIvar->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3068 | return nullptr; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3069 | } |
| 3070 | } |
| 3071 | |
| 3072 | // Import the type. |
| 3073 | QualType T = Importer.Import(D->getType()); |
| 3074 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3075 | return nullptr; |
| 3076 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3077 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3078 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 3079 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3080 | return nullptr; |
| 3081 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3082 | ObjCIvarDecl *ToIvar; |
| 3083 | if (GetImportedOrCreateDecl( |
| 3084 | ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC), |
| 3085 | Importer.Import(D->getInnerLocStart()), Loc, |
| 3086 | Name.getAsIdentifierInfo(), T, TInfo, D->getAccessControl(), BitWidth, |
| 3087 | D->getSynthesize())) |
| 3088 | return ToIvar; |
| 3089 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3090 | ToIvar->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3091 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3092 | return ToIvar; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 3093 | } |
| 3094 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3095 | Decl *ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
| 3096 | // Import the major distinguishing characteristics of a variable. |
| 3097 | DeclContext *DC, *LexicalDC; |
| 3098 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3099 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3100 | NamedDecl *ToD; |
| 3101 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3102 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3103 | if (ToD) |
| 3104 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3105 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3106 | // Try to find a variable in our own ("to") context with the same name and |
| 3107 | // in the same context as the variable we're importing. |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3108 | if (D->isFileVarDecl()) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3109 | VarDecl *MergeWithVar = nullptr; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3110 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3111 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3112 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3113 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3114 | for (auto *FoundDecl : FoundDecls) { |
| 3115 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3116 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3117 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3118 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3119 | // 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] | 3120 | if (FoundVar->hasExternalFormalLinkage() && |
| 3121 | D->hasExternalFormalLinkage()) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3122 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3123 | FoundVar->getType())) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3124 | MergeWithVar = FoundVar; |
| 3125 | break; |
| 3126 | } |
| 3127 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3128 | const ArrayType *FoundArray |
| 3129 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 3130 | const ArrayType *TArray |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3131 | = Importer.getToContext().getAsArrayType(D->getType()); |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3132 | if (FoundArray && TArray) { |
| 3133 | if (isa<IncompleteArrayType>(FoundArray) && |
| 3134 | isa<ConstantArrayType>(TArray)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3135 | // Import the type. |
| 3136 | QualType T = Importer.Import(D->getType()); |
| 3137 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3138 | return nullptr; |
| 3139 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 3140 | FoundVar->setType(T); |
| 3141 | MergeWithVar = FoundVar; |
| 3142 | break; |
| 3143 | } else if (isa<IncompleteArrayType>(TArray) && |
| 3144 | isa<ConstantArrayType>(FoundArray)) { |
| 3145 | MergeWithVar = FoundVar; |
| 3146 | break; |
Douglas Gregor | 2fbe558 | 2010-02-10 17:16:49 +0000 | [diff] [blame] | 3147 | } |
| 3148 | } |
| 3149 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3150 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3151 | << Name << D->getType() << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3152 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 3153 | << FoundVar->getType(); |
| 3154 | } |
| 3155 | } |
| 3156 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3157 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | if (MergeWithVar) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3161 | // An equivalent variable with external linkage has been found. Link |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3162 | // the two declarations, then merge them. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3163 | Importer.MapImported(D, MergeWithVar); |
| 3164 | updateFlags(D, MergeWithVar); |
| 3165 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3166 | if (VarDecl *DDef = D->getDefinition()) { |
| 3167 | if (VarDecl *ExistingDef = MergeWithVar->getDefinition()) { |
| 3168 | Importer.ToDiag(ExistingDef->getLocation(), |
| 3169 | diag::err_odr_variable_multiple_def) |
| 3170 | << Name; |
| 3171 | Importer.FromDiag(DDef->getLocation(), diag::note_odr_defined_here); |
| 3172 | } else { |
| 3173 | Expr *Init = Importer.Import(DDef->getInit()); |
Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 3174 | MergeWithVar->setInit(Init); |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 3175 | if (DDef->isInitKnownICE()) { |
| 3176 | EvaluatedStmt *Eval = MergeWithVar->ensureEvaluatedStmt(); |
| 3177 | Eval->CheckedICE = true; |
| 3178 | Eval->IsICE = DDef->isInitICE(); |
| 3179 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3180 | } |
| 3181 | } |
| 3182 | |
| 3183 | return MergeWithVar; |
| 3184 | } |
| 3185 | |
| 3186 | if (!ConflictingDecls.empty()) { |
| 3187 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 3188 | ConflictingDecls.data(), |
| 3189 | ConflictingDecls.size()); |
| 3190 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3191 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3192 | } |
| 3193 | } |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 3194 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 3195 | // Import the type. |
| 3196 | QualType T = Importer.Import(D->getType()); |
| 3197 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3198 | return nullptr; |
| 3199 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3200 | // Create the imported variable. |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 3201 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3202 | VarDecl *ToVar; |
| 3203 | if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC, |
| 3204 | Importer.Import(D->getInnerLocStart()), Loc, |
| 3205 | Name.getAsIdentifierInfo(), T, TInfo, |
| 3206 | D->getStorageClass())) |
| 3207 | return ToVar; |
| 3208 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 3209 | ToVar->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 3210 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3211 | ToVar->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 3212 | |
| 3213 | // Templated declarations should never appear in the enclosing DeclContext. |
| 3214 | if (!D->getDescribedVarTemplate()) |
| 3215 | LexicalDC->addDeclInternal(ToVar); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 3216 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3217 | // Merge the initializer. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3218 | if (ImportDefinition(D, ToVar)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3219 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3220 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 3221 | if (D->isConstexpr()) |
| 3222 | ToVar->setConstexpr(true); |
| 3223 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 3224 | return ToVar; |
| 3225 | } |
| 3226 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3227 | Decl *ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| 3228 | // Parameters are created in the translation unit's context, then moved |
| 3229 | // into the function declaration's context afterward. |
| 3230 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 3231 | |
| 3232 | // Import the name of this declaration. |
| 3233 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3234 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3235 | return nullptr; |
| 3236 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3237 | // Import the location of this declaration. |
| 3238 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 3239 | |
| 3240 | // Import the parameter's type. |
| 3241 | QualType T = Importer.Import(D->getType()); |
| 3242 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3243 | return nullptr; |
| 3244 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3245 | // Create the imported parameter. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3246 | ImplicitParamDecl *ToParm = nullptr; |
| 3247 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, Loc, |
| 3248 | Name.getAsIdentifierInfo(), T, |
| 3249 | D->getParameterKind())) |
| 3250 | return ToParm; |
| 3251 | return ToParm; |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 3252 | } |
| 3253 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3254 | Decl *ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
| 3255 | // Parameters are created in the translation unit's context, then moved |
| 3256 | // into the function declaration's context afterward. |
| 3257 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 3258 | |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 3259 | // Import the name of this declaration. |
| 3260 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3261 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3262 | return nullptr; |
| 3263 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3264 | // Import the location of this declaration. |
| 3265 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 3266 | |
| 3267 | // Import the parameter's type. |
| 3268 | QualType T = Importer.Import(D->getType()); |
| 3269 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3270 | return nullptr; |
| 3271 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3272 | // Create the imported parameter. |
| 3273 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3274 | ParmVarDecl *ToParm; |
| 3275 | if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC, |
| 3276 | Importer.Import(D->getInnerLocStart()), Loc, |
| 3277 | Name.getAsIdentifierInfo(), T, TInfo, |
| 3278 | D->getStorageClass(), |
| 3279 | /*DefaultArg*/ nullptr)) |
| 3280 | return ToParm; |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3281 | |
| 3282 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 3283 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3284 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 3285 | |
| 3286 | Expr *ToDefArg = nullptr; |
| 3287 | Expr *FromDefArg = nullptr; |
| 3288 | if (D->hasUninstantiatedDefaultArg()) { |
| 3289 | FromDefArg = D->getUninstantiatedDefaultArg(); |
| 3290 | ToDefArg = Importer.Import(FromDefArg); |
| 3291 | ToParm->setUninstantiatedDefaultArg(ToDefArg); |
| 3292 | } else if (D->hasUnparsedDefaultArg()) { |
| 3293 | ToParm->setUnparsedDefaultArg(); |
| 3294 | } else if (D->hasDefaultArg()) { |
| 3295 | FromDefArg = D->getDefaultArg(); |
| 3296 | ToDefArg = Importer.Import(FromDefArg); |
| 3297 | ToParm->setDefaultArg(ToDefArg); |
| 3298 | } |
| 3299 | if (FromDefArg && !ToDefArg) |
| 3300 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3301 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3302 | if (D->isObjCMethodParameter()) { |
| 3303 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3304 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3305 | } else { |
| 3306 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3307 | D->getFunctionScopeIndex()); |
| 3308 | } |
| 3309 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3310 | return ToParm; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3311 | } |
| 3312 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3313 | Decl *ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| 3314 | // Import the major distinguishing characteristics of a method. |
| 3315 | DeclContext *DC, *LexicalDC; |
| 3316 | DeclarationName Name; |
| 3317 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3318 | NamedDecl *ToD; |
| 3319 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3320 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3321 | if (ToD) |
| 3322 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3323 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3324 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3325 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3326 | for (auto *FoundDecl : FoundDecls) { |
| 3327 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3328 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3329 | continue; |
| 3330 | |
| 3331 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3332 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3333 | FoundMethod->getReturnType())) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3334 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3335 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3336 | << FoundMethod->getReturnType(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3337 | Importer.ToDiag(FoundMethod->getLocation(), |
| 3338 | diag::note_odr_objc_method_here) |
| 3339 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3340 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3341 | } |
| 3342 | |
| 3343 | // Check the number of parameters. |
| 3344 | if (D->param_size() != FoundMethod->param_size()) { |
| 3345 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) |
| 3346 | << D->isInstanceMethod() << Name |
| 3347 | << D->param_size() << FoundMethod->param_size(); |
| 3348 | Importer.ToDiag(FoundMethod->getLocation(), |
| 3349 | diag::note_odr_objc_method_here) |
| 3350 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3351 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3352 | } |
| 3353 | |
| 3354 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3355 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3356 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3357 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3358 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3359 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3360 | Importer.FromDiag((*P)->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3361 | diag::err_odr_objc_method_param_type_inconsistent) |
| 3362 | << D->isInstanceMethod() << Name |
| 3363 | << (*P)->getType() << (*FoundP)->getType(); |
| 3364 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3365 | << (*FoundP)->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3366 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3367 | } |
| 3368 | } |
| 3369 | |
| 3370 | // Check variadic/non-variadic. |
| 3371 | // Check the number of parameters. |
| 3372 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| 3373 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) |
| 3374 | << D->isInstanceMethod() << Name; |
| 3375 | Importer.ToDiag(FoundMethod->getLocation(), |
| 3376 | diag::note_odr_objc_method_here) |
| 3377 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3378 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | // FIXME: Any other bits we need to merge? |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3382 | return Importer.MapImported(D, FoundMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3383 | } |
| 3384 | } |
| 3385 | |
| 3386 | // Import the result type. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3387 | QualType ResultTy = Importer.Import(D->getReturnType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3388 | if (ResultTy.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3389 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3390 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3391 | TypeSourceInfo *ReturnTInfo = Importer.Import(D->getReturnTypeSourceInfo()); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3392 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3393 | ObjCMethodDecl *ToMethod; |
| 3394 | if (GetImportedOrCreateDecl( |
| 3395 | ToMethod, D, Importer.getToContext(), Loc, |
| 3396 | Importer.Import(D->getLocEnd()), Name.getObjCSelector(), ResultTy, |
| 3397 | ReturnTInfo, DC, D->isInstanceMethod(), D->isVariadic(), |
| 3398 | D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3399 | D->getImplementationControl(), D->hasRelatedResultType())) |
| 3400 | return ToMethod; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3401 | |
| 3402 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3403 | // deal with implicit parameters. |
| 3404 | |
| 3405 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3406 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3407 | for (auto *FromP : D->parameters()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3408 | auto *ToP = cast_or_null<ParmVarDecl>(Importer.Import(FromP)); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3409 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3410 | return nullptr; |
| 3411 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3412 | ToParams.push_back(ToP); |
| 3413 | } |
| 3414 | |
| 3415 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3416 | for (auto *ToParam : ToParams) { |
| 3417 | ToParam->setOwningFunction(ToMethod); |
| 3418 | ToMethod->addDeclInternal(ToParam); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3419 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3420 | |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 3421 | SmallVector<SourceLocation, 12> SelLocs; |
| 3422 | D->getSelectorLocs(SelLocs); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3423 | for (auto &Loc : SelLocs) |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3424 | Loc = Importer.Import(Loc); |
| 3425 | |
| 3426 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, SelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3427 | |
| 3428 | ToMethod->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3429 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3430 | return ToMethod; |
| 3431 | } |
| 3432 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3433 | Decl *ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| 3434 | // Import the major distinguishing characteristics of a category. |
| 3435 | DeclContext *DC, *LexicalDC; |
| 3436 | DeclarationName Name; |
| 3437 | SourceLocation Loc; |
| 3438 | NamedDecl *ToD; |
| 3439 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3440 | return nullptr; |
| 3441 | if (ToD) |
| 3442 | return ToD; |
| 3443 | |
| 3444 | TypeSourceInfo *BoundInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3445 | if (!BoundInfo) |
| 3446 | return nullptr; |
| 3447 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3448 | ObjCTypeParamDecl *Result; |
| 3449 | if (GetImportedOrCreateDecl( |
| 3450 | Result, D, Importer.getToContext(), DC, D->getVariance(), |
| 3451 | Importer.Import(D->getVarianceLoc()), D->getIndex(), |
| 3452 | Importer.Import(D->getLocation()), Name.getAsIdentifierInfo(), |
| 3453 | Importer.Import(D->getColonLoc()), BoundInfo)) |
| 3454 | return Result; |
| 3455 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3456 | Result->setLexicalDeclContext(LexicalDC); |
| 3457 | return Result; |
| 3458 | } |
| 3459 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3460 | Decl *ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| 3461 | // Import the major distinguishing characteristics of a category. |
| 3462 | DeclContext *DC, *LexicalDC; |
| 3463 | DeclarationName Name; |
| 3464 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3465 | NamedDecl *ToD; |
| 3466 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3467 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3468 | if (ToD) |
| 3469 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3470 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3471 | auto *ToInterface = |
| 3472 | cast_or_null<ObjCInterfaceDecl>(Importer.Import(D->getClassInterface())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3473 | if (!ToInterface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3474 | return nullptr; |
| 3475 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3476 | // Determine if we've already encountered this category. |
| 3477 | ObjCCategoryDecl *MergeWithCategory |
| 3478 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3479 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3480 | if (!ToCategory) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3481 | |
| 3482 | if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC, |
| 3483 | Importer.Import(D->getAtStartLoc()), Loc, |
| 3484 | Importer.Import(D->getCategoryNameLoc()), |
| 3485 | Name.getAsIdentifierInfo(), ToInterface, |
| 3486 | /*TypeParamList=*/nullptr, |
| 3487 | Importer.Import(D->getIvarLBraceLoc()), |
| 3488 | Importer.Import(D->getIvarRBraceLoc()))) |
| 3489 | return ToCategory; |
| 3490 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3491 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3492 | LexicalDC->addDeclInternal(ToCategory); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3493 | // Import the type parameter list after calling Imported, to avoid |
| 3494 | // loops when bringing in their DeclContext. |
| 3495 | ToCategory->setTypeParamList(ImportObjCTypeParamList( |
| 3496 | D->getTypeParamList())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3497 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3498 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3499 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3500 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3501 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 3502 | = D->protocol_loc_begin(); |
| 3503 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 3504 | FromProtoEnd = D->protocol_end(); |
| 3505 | FromProto != FromProtoEnd; |
| 3506 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3507 | auto *ToProto = |
| 3508 | cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3509 | if (!ToProto) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3510 | return nullptr; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3511 | Protocols.push_back(ToProto); |
| 3512 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3513 | } |
| 3514 | |
| 3515 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3516 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 3517 | ProtocolLocs.data(), Importer.getToContext()); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3518 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3519 | Importer.MapImported(D, ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | // Import all of the members of this category. |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 3523 | ImportDeclContext(D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3524 | |
| 3525 | // If we have an implementation, import it as well. |
| 3526 | if (D->getImplementation()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3527 | auto *Impl = |
| 3528 | cast_or_null<ObjCCategoryImplDecl>( |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3529 | Importer.Import(D->getImplementation())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3530 | if (!Impl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3531 | return nullptr; |
| 3532 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3533 | ToCategory->setImplementation(Impl); |
| 3534 | } |
| 3535 | |
| 3536 | return ToCategory; |
| 3537 | } |
| 3538 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3539 | bool ASTNodeImporter::ImportDefinition(ObjCProtocolDecl *From, |
| 3540 | ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3541 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3542 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3543 | if (shouldForceImportDeclContext(Kind)) |
| 3544 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3545 | return false; |
| 3546 | } |
| 3547 | |
| 3548 | // Start the protocol definition |
| 3549 | To->startDefinition(); |
| 3550 | |
| 3551 | // Import protocols |
| 3552 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3553 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 3554 | ObjCProtocolDecl::protocol_loc_iterator |
| 3555 | FromProtoLoc = From->protocol_loc_begin(); |
| 3556 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3557 | FromProtoEnd = From->protocol_end(); |
| 3558 | FromProto != FromProtoEnd; |
| 3559 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3560 | auto *ToProto = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3561 | if (!ToProto) |
| 3562 | return true; |
| 3563 | Protocols.push_back(ToProto); |
| 3564 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3565 | } |
| 3566 | |
| 3567 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3568 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3569 | ProtocolLocs.data(), Importer.getToContext()); |
| 3570 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3571 | if (shouldForceImportDeclContext(Kind)) { |
| 3572 | // Import all of the members of this protocol. |
| 3573 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3574 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3575 | return false; |
| 3576 | } |
| 3577 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3578 | Decl *ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3579 | // If this protocol has a definition in the translation unit we're coming |
| 3580 | // from, but this particular declaration is not that definition, import the |
| 3581 | // definition and map to that. |
| 3582 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 3583 | if (Definition && Definition != D) { |
| 3584 | Decl *ImportedDef = Importer.Import(Definition); |
| 3585 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3586 | return nullptr; |
| 3587 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3588 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3589 | } |
| 3590 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3591 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3592 | DeclContext *DC, *LexicalDC; |
| 3593 | DeclarationName Name; |
| 3594 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3595 | NamedDecl *ToD; |
| 3596 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3597 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3598 | if (ToD) |
| 3599 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3600 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3601 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3602 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3603 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3604 | for (auto *FoundDecl : FoundDecls) { |
| 3605 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3606 | continue; |
| 3607 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3608 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3609 | break; |
| 3610 | } |
| 3611 | |
| 3612 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3613 | if (!ToProto) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3614 | if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC, |
| 3615 | Name.getAsIdentifierInfo(), Loc, |
| 3616 | Importer.Import(D->getAtStartLoc()), |
| 3617 | /*PrevDecl=*/nullptr)) |
| 3618 | return ToProto; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3619 | ToProto->setLexicalDeclContext(LexicalDC); |
| 3620 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3621 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3622 | |
| 3623 | Importer.MapImported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3624 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3625 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToProto)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3626 | return nullptr; |
| 3627 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3628 | return ToProto; |
| 3629 | } |
| 3630 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3631 | Decl *ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 3632 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3633 | DeclContext *LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3634 | |
| 3635 | SourceLocation ExternLoc = Importer.Import(D->getExternLoc()); |
| 3636 | SourceLocation LangLoc = Importer.Import(D->getLocation()); |
| 3637 | |
| 3638 | bool HasBraces = D->hasBraces(); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3639 | |
| 3640 | LinkageSpecDecl *ToLinkageSpec; |
| 3641 | if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC, |
| 3642 | ExternLoc, LangLoc, D->getLanguage(), HasBraces)) |
| 3643 | return ToLinkageSpec; |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3644 | |
| 3645 | if (HasBraces) { |
| 3646 | SourceLocation RBraceLoc = Importer.Import(D->getRBraceLoc()); |
| 3647 | ToLinkageSpec->setRBraceLoc(RBraceLoc); |
| 3648 | } |
| 3649 | |
| 3650 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 3651 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 3652 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3653 | return ToLinkageSpec; |
| 3654 | } |
| 3655 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3656 | Decl *ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
| 3657 | DeclContext *DC, *LexicalDC; |
| 3658 | DeclarationName Name; |
| 3659 | SourceLocation Loc; |
| 3660 | NamedDecl *ToD = nullptr; |
| 3661 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3662 | return nullptr; |
| 3663 | if (ToD) |
| 3664 | return ToD; |
| 3665 | |
| 3666 | DeclarationNameInfo NameInfo(Name, |
| 3667 | Importer.Import(D->getNameInfo().getLoc())); |
| 3668 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3669 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3670 | UsingDecl *ToUsing; |
| 3671 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| 3672 | Importer.Import(D->getUsingLoc()), |
| 3673 | Importer.Import(D->getQualifierLoc()), NameInfo, |
| 3674 | D->hasTypename())) |
| 3675 | return ToUsing; |
| 3676 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3677 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3678 | LexicalDC->addDeclInternal(ToUsing); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3679 | |
| 3680 | if (NamedDecl *FromPattern = |
| 3681 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3682 | if (auto *ToPattern = |
| 3683 | dyn_cast_or_null<NamedDecl>(Importer.Import(FromPattern))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3684 | Importer.getToContext().setInstantiatedFromUsingDecl(ToUsing, ToPattern); |
| 3685 | else |
| 3686 | return nullptr; |
| 3687 | } |
| 3688 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3689 | for (auto *FromShadow : D->shadows()) { |
| 3690 | if (auto *ToShadow = |
| 3691 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromShadow))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3692 | ToUsing->addShadowDecl(ToShadow); |
| 3693 | else |
| 3694 | // FIXME: We return a nullptr here but the definition is already created |
| 3695 | // and available with lookups. How to fix this?.. |
| 3696 | return nullptr; |
| 3697 | } |
| 3698 | return ToUsing; |
| 3699 | } |
| 3700 | |
| 3701 | Decl *ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| 3702 | DeclContext *DC, *LexicalDC; |
| 3703 | DeclarationName Name; |
| 3704 | SourceLocation Loc; |
| 3705 | NamedDecl *ToD = nullptr; |
| 3706 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3707 | return nullptr; |
| 3708 | if (ToD) |
| 3709 | return ToD; |
| 3710 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3711 | auto *ToUsing = dyn_cast_or_null<UsingDecl>( |
| 3712 | Importer.Import(D->getUsingDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3713 | if (!ToUsing) |
| 3714 | return nullptr; |
| 3715 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3716 | auto *ToTarget = dyn_cast_or_null<NamedDecl>( |
| 3717 | Importer.Import(D->getTargetDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3718 | if (!ToTarget) |
| 3719 | return nullptr; |
| 3720 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3721 | UsingShadowDecl *ToShadow; |
| 3722 | if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc, |
| 3723 | ToUsing, ToTarget)) |
| 3724 | return ToShadow; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3725 | |
| 3726 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 3727 | ToShadow->setAccess(D->getAccess()); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3728 | |
| 3729 | if (UsingShadowDecl *FromPattern = |
| 3730 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3731 | if (auto *ToPattern = |
| 3732 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromPattern))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3733 | Importer.getToContext().setInstantiatedFromUsingShadowDecl(ToShadow, |
| 3734 | ToPattern); |
| 3735 | else |
| 3736 | // FIXME: We return a nullptr here but the definition is already created |
| 3737 | // and available with lookups. How to fix this?.. |
| 3738 | return nullptr; |
| 3739 | } |
| 3740 | |
| 3741 | LexicalDC->addDeclInternal(ToShadow); |
| 3742 | |
| 3743 | return ToShadow; |
| 3744 | } |
| 3745 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3746 | Decl *ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 3747 | DeclContext *DC, *LexicalDC; |
| 3748 | DeclarationName Name; |
| 3749 | SourceLocation Loc; |
| 3750 | NamedDecl *ToD = nullptr; |
| 3751 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3752 | return nullptr; |
| 3753 | if (ToD) |
| 3754 | return ToD; |
| 3755 | |
| 3756 | DeclContext *ToComAncestor = Importer.ImportContext(D->getCommonAncestor()); |
| 3757 | if (!ToComAncestor) |
| 3758 | return nullptr; |
| 3759 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3760 | auto *ToNominated = cast_or_null<NamespaceDecl>( |
| 3761 | Importer.Import(D->getNominatedNamespace())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3762 | if (!ToNominated) |
| 3763 | return nullptr; |
| 3764 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3765 | UsingDirectiveDecl *ToUsingDir; |
| 3766 | if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC, |
| 3767 | Importer.Import(D->getUsingLoc()), |
| 3768 | Importer.Import(D->getNamespaceKeyLocation()), |
| 3769 | Importer.Import(D->getQualifierLoc()), |
| 3770 | Importer.Import(D->getIdentLocation()), |
| 3771 | ToNominated, ToComAncestor)) |
| 3772 | return ToUsingDir; |
| 3773 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3774 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 3775 | LexicalDC->addDeclInternal(ToUsingDir); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3776 | |
| 3777 | return ToUsingDir; |
| 3778 | } |
| 3779 | |
| 3780 | Decl *ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
| 3781 | UnresolvedUsingValueDecl *D) { |
| 3782 | DeclContext *DC, *LexicalDC; |
| 3783 | DeclarationName Name; |
| 3784 | SourceLocation Loc; |
| 3785 | NamedDecl *ToD = nullptr; |
| 3786 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3787 | return nullptr; |
| 3788 | if (ToD) |
| 3789 | return ToD; |
| 3790 | |
| 3791 | DeclarationNameInfo NameInfo(Name, Importer.Import(D->getNameInfo().getLoc())); |
| 3792 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3793 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3794 | UnresolvedUsingValueDecl *ToUsingValue; |
| 3795 | if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC, |
| 3796 | Importer.Import(D->getUsingLoc()), |
| 3797 | Importer.Import(D->getQualifierLoc()), NameInfo, |
| 3798 | Importer.Import(D->getEllipsisLoc()))) |
| 3799 | return ToUsingValue; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3800 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3801 | ToUsingValue->setAccess(D->getAccess()); |
| 3802 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 3803 | LexicalDC->addDeclInternal(ToUsingValue); |
| 3804 | |
| 3805 | return ToUsingValue; |
| 3806 | } |
| 3807 | |
| 3808 | Decl *ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
| 3809 | UnresolvedUsingTypenameDecl *D) { |
| 3810 | DeclContext *DC, *LexicalDC; |
| 3811 | DeclarationName Name; |
| 3812 | SourceLocation Loc; |
| 3813 | NamedDecl *ToD = nullptr; |
| 3814 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3815 | return nullptr; |
| 3816 | if (ToD) |
| 3817 | return ToD; |
| 3818 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3819 | UnresolvedUsingTypenameDecl *ToUsing; |
| 3820 | if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC, |
| 3821 | Importer.Import(D->getUsingLoc()), |
| 3822 | Importer.Import(D->getTypenameLoc()), |
| 3823 | Importer.Import(D->getQualifierLoc()), Loc, Name, |
| 3824 | Importer.Import(D->getEllipsisLoc()))) |
| 3825 | return ToUsing; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3826 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3827 | ToUsing->setAccess(D->getAccess()); |
| 3828 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3829 | LexicalDC->addDeclInternal(ToUsing); |
| 3830 | |
| 3831 | return ToUsing; |
| 3832 | } |
| 3833 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3834 | bool ASTNodeImporter::ImportDefinition(ObjCInterfaceDecl *From, |
| 3835 | ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3836 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3837 | if (To->getDefinition()) { |
| 3838 | // Check consistency of superclass. |
| 3839 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 3840 | if (FromSuper) { |
| 3841 | FromSuper = cast_or_null<ObjCInterfaceDecl>(Importer.Import(FromSuper)); |
| 3842 | if (!FromSuper) |
| 3843 | return true; |
| 3844 | } |
| 3845 | |
| 3846 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
| 3847 | if ((bool)FromSuper != (bool)ToSuper || |
| 3848 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
| 3849 | Importer.ToDiag(To->getLocation(), |
| 3850 | diag::err_odr_objc_superclass_inconsistent) |
| 3851 | << To->getDeclName(); |
| 3852 | if (ToSuper) |
| 3853 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 3854 | << To->getSuperClass()->getDeclName(); |
| 3855 | else |
| 3856 | Importer.ToDiag(To->getLocation(), |
| 3857 | diag::note_odr_objc_missing_superclass); |
| 3858 | if (From->getSuperClass()) |
| 3859 | Importer.FromDiag(From->getSuperClassLoc(), |
| 3860 | diag::note_odr_objc_superclass) |
| 3861 | << From->getSuperClass()->getDeclName(); |
| 3862 | else |
| 3863 | Importer.FromDiag(From->getLocation(), |
| 3864 | diag::note_odr_objc_missing_superclass); |
| 3865 | } |
| 3866 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3867 | if (shouldForceImportDeclContext(Kind)) |
| 3868 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3869 | return false; |
| 3870 | } |
| 3871 | |
| 3872 | // Start the definition. |
| 3873 | To->startDefinition(); |
| 3874 | |
| 3875 | // If this class has a superclass, import it. |
| 3876 | if (From->getSuperClass()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3877 | TypeSourceInfo *SuperTInfo = Importer.Import(From->getSuperClassTInfo()); |
| 3878 | if (!SuperTInfo) |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3879 | return true; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3880 | |
| 3881 | To->setSuperClass(SuperTInfo); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3882 | } |
| 3883 | |
| 3884 | // Import protocols |
| 3885 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3886 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 3887 | ObjCInterfaceDecl::protocol_loc_iterator |
| 3888 | FromProtoLoc = From->protocol_loc_begin(); |
| 3889 | |
| 3890 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3891 | FromProtoEnd = From->protocol_end(); |
| 3892 | FromProto != FromProtoEnd; |
| 3893 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3894 | auto *ToProto = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3895 | if (!ToProto) |
| 3896 | return true; |
| 3897 | Protocols.push_back(ToProto); |
| 3898 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3899 | } |
| 3900 | |
| 3901 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3902 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3903 | ProtocolLocs.data(), Importer.getToContext()); |
| 3904 | |
| 3905 | // Import categories. When the categories themselves are imported, they'll |
| 3906 | // hook themselves into this interface. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 3907 | for (auto *Cat : From->known_categories()) |
| 3908 | Importer.Import(Cat); |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 3909 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3910 | // If we have an @implementation, import it as well. |
| 3911 | if (From->getImplementation()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3912 | auto *Impl = cast_or_null<ObjCImplementationDecl>( |
| 3913 | Importer.Import(From->getImplementation())); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3914 | if (!Impl) |
| 3915 | return true; |
| 3916 | |
| 3917 | To->setImplementation(Impl); |
| 3918 | } |
| 3919 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3920 | if (shouldForceImportDeclContext(Kind)) { |
| 3921 | // Import all of the members of this class. |
| 3922 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3923 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3924 | return false; |
| 3925 | } |
| 3926 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3927 | ObjCTypeParamList * |
| 3928 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 3929 | if (!list) |
| 3930 | return nullptr; |
| 3931 | |
| 3932 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
| 3933 | for (auto fromTypeParam : *list) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3934 | auto *toTypeParam = cast_or_null<ObjCTypeParamDecl>( |
| 3935 | Importer.Import(fromTypeParam)); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3936 | if (!toTypeParam) |
| 3937 | return nullptr; |
| 3938 | |
| 3939 | toTypeParams.push_back(toTypeParam); |
| 3940 | } |
| 3941 | |
| 3942 | return ObjCTypeParamList::create(Importer.getToContext(), |
| 3943 | Importer.Import(list->getLAngleLoc()), |
| 3944 | toTypeParams, |
| 3945 | Importer.Import(list->getRAngleLoc())); |
| 3946 | } |
| 3947 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3948 | Decl *ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3949 | // If this class has a definition in the translation unit we're coming from, |
| 3950 | // but this particular declaration is not that definition, import the |
| 3951 | // definition and map to that. |
| 3952 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 3953 | if (Definition && Definition != D) { |
| 3954 | Decl *ImportedDef = Importer.Import(Definition); |
| 3955 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3956 | return nullptr; |
| 3957 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3958 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3959 | } |
| 3960 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3961 | // Import the major distinguishing characteristics of an @interface. |
| 3962 | DeclContext *DC, *LexicalDC; |
| 3963 | DeclarationName Name; |
| 3964 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3965 | NamedDecl *ToD; |
| 3966 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3967 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3968 | if (ToD) |
| 3969 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3970 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3971 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3972 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3973 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3974 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3975 | for (auto *FoundDecl : FoundDecls) { |
| 3976 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3977 | continue; |
| 3978 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3979 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3980 | break; |
| 3981 | } |
| 3982 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3983 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3984 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3985 | if (!ToIface) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3986 | if (GetImportedOrCreateDecl( |
| 3987 | ToIface, D, Importer.getToContext(), DC, |
| 3988 | Importer.Import(D->getAtStartLoc()), Name.getAsIdentifierInfo(), |
| 3989 | /*TypeParamList=*/nullptr, |
| 3990 | /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl())) |
| 3991 | return ToIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3992 | ToIface->setLexicalDeclContext(LexicalDC); |
| 3993 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3994 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 3995 | Importer.MapImported(D, ToIface); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3996 | // Import the type parameter list after calling Imported, to avoid |
| 3997 | // loops when bringing in their DeclContext. |
| 3998 | ToIface->setTypeParamList(ImportObjCTypeParamList( |
| 3999 | D->getTypeParamListAsWritten())); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4000 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 4001 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToIface)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4002 | return nullptr; |
| 4003 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 4004 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 4005 | } |
| 4006 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4007 | Decl *ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4008 | auto *Category = cast_or_null<ObjCCategoryDecl>( |
| 4009 | Importer.Import(D->getCategoryDecl())); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4010 | if (!Category) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4011 | return nullptr; |
| 4012 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4013 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 4014 | if (!ToImpl) { |
| 4015 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 4016 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4017 | return nullptr; |
| 4018 | |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 4019 | SourceLocation CategoryNameLoc = Importer.Import(D->getCategoryNameLoc()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4020 | if (GetImportedOrCreateDecl( |
| 4021 | ToImpl, D, Importer.getToContext(), DC, |
| 4022 | Importer.Import(D->getIdentifier()), Category->getClassInterface(), |
| 4023 | Importer.Import(D->getLocation()), |
| 4024 | Importer.Import(D->getAtStartLoc()), CategoryNameLoc)) |
| 4025 | return ToImpl; |
| 4026 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4027 | DeclContext *LexicalDC = DC; |
| 4028 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4029 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4030 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4031 | return nullptr; |
| 4032 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4033 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 4034 | } |
| 4035 | |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4036 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4037 | Category->setImplementation(ToImpl); |
| 4038 | } |
| 4039 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4040 | Importer.MapImported(D, ToImpl); |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 4041 | ImportDeclContext(D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 4042 | return ToImpl; |
| 4043 | } |
| 4044 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4045 | Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 4046 | // Find the corresponding interface. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4047 | auto *Iface = cast_or_null<ObjCInterfaceDecl>( |
| 4048 | Importer.Import(D->getClassInterface())); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4049 | if (!Iface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4050 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4051 | |
| 4052 | // Import the superclass, if any. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4053 | ObjCInterfaceDecl *Super = nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4054 | if (D->getSuperClass()) { |
| 4055 | Super = cast_or_null<ObjCInterfaceDecl>( |
| 4056 | Importer.Import(D->getSuperClass())); |
| 4057 | if (!Super) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4058 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 4062 | if (!Impl) { |
| 4063 | // We haven't imported an implementation yet. Create a new @implementation |
| 4064 | // now. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4065 | if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(), |
| 4066 | Importer.ImportContext(D->getDeclContext()), |
| 4067 | Iface, Super, Importer.Import(D->getLocation()), |
| 4068 | Importer.Import(D->getAtStartLoc()), |
| 4069 | Importer.Import(D->getSuperClassLoc()), |
| 4070 | Importer.Import(D->getIvarLBraceLoc()), |
| 4071 | Importer.Import(D->getIvarRBraceLoc()))) |
| 4072 | return Impl; |
| 4073 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4074 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4075 | DeclContext *LexicalDC |
| 4076 | = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4077 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4078 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4079 | Impl->setLexicalDeclContext(LexicalDC); |
| 4080 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4081 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4082 | // Associate the implementation with the class it implements. |
| 4083 | Iface->setImplementation(Impl); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4084 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4085 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4086 | Importer.MapImported(D, Iface->getImplementation()); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4087 | |
| 4088 | // Verify that the existing @implementation has the same superclass. |
| 4089 | if ((Super && !Impl->getSuperClass()) || |
| 4090 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4091 | (Super && Impl->getSuperClass() && |
| 4092 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 4093 | Impl->getSuperClass()))) { |
| 4094 | Importer.ToDiag(Impl->getLocation(), |
| 4095 | diag::err_odr_objc_superclass_inconsistent) |
| 4096 | << Iface->getDeclName(); |
| 4097 | // FIXME: It would be nice to have the location of the superclass |
| 4098 | // below. |
| 4099 | if (Impl->getSuperClass()) |
| 4100 | Importer.ToDiag(Impl->getLocation(), |
| 4101 | diag::note_odr_objc_superclass) |
| 4102 | << Impl->getSuperClass()->getDeclName(); |
| 4103 | else |
| 4104 | Importer.ToDiag(Impl->getLocation(), |
| 4105 | diag::note_odr_objc_missing_superclass); |
| 4106 | if (D->getSuperClass()) |
| 4107 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4108 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 4109 | << D->getSuperClass()->getDeclName(); |
| 4110 | else |
| 4111 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4112 | diag::note_odr_objc_missing_superclass); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4113 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 4114 | } |
| 4115 | } |
| 4116 | |
| 4117 | // Import all of the members of this @implementation. |
| 4118 | ImportDeclContext(D); |
| 4119 | |
| 4120 | return Impl; |
| 4121 | } |
| 4122 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4123 | Decl *ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 4124 | // Import the major distinguishing characteristics of an @property. |
| 4125 | DeclContext *DC, *LexicalDC; |
| 4126 | DeclarationName Name; |
| 4127 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4128 | NamedDecl *ToD; |
| 4129 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4130 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4131 | if (ToD) |
| 4132 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4133 | |
| 4134 | // Check whether we have already imported this property. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4135 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4136 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4137 | for (auto *FoundDecl : FoundDecls) { |
| 4138 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4139 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 4140 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4141 | FoundProp->getType())) { |
| 4142 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) |
| 4143 | << Name << D->getType() << FoundProp->getType(); |
| 4144 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 4145 | << FoundProp->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4146 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4147 | } |
| 4148 | |
| 4149 | // FIXME: Check property attributes, getters, setters, etc.? |
| 4150 | |
| 4151 | // Consider these properties to be equivalent. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4152 | Importer.MapImported(D, FoundProp); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4153 | return FoundProp; |
| 4154 | } |
| 4155 | } |
| 4156 | |
| 4157 | // Import the type. |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 4158 | TypeSourceInfo *TSI = Importer.Import(D->getTypeSourceInfo()); |
| 4159 | if (!TSI) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4160 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4161 | |
| 4162 | // Create the new property. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4163 | ObjCPropertyDecl *ToProperty; |
| 4164 | if (GetImportedOrCreateDecl( |
| 4165 | ToProperty, D, Importer.getToContext(), DC, Loc, |
| 4166 | Name.getAsIdentifierInfo(), Importer.Import(D->getAtLoc()), |
| 4167 | Importer.Import(D->getLParenLoc()), Importer.Import(D->getType()), |
| 4168 | TSI, D->getPropertyImplementation())) |
| 4169 | return ToProperty; |
| 4170 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4171 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4172 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4173 | |
| 4174 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 4175 | ToProperty->setPropertyAttributesAsWritten( |
| 4176 | D->getPropertyAttributesAsWritten()); |
Argyrios Kyrtzidis | 194b28e | 2017-03-16 18:25:40 +0000 | [diff] [blame] | 4177 | ToProperty->setGetterName(Importer.Import(D->getGetterName()), |
| 4178 | Importer.Import(D->getGetterNameLoc())); |
| 4179 | ToProperty->setSetterName(Importer.Import(D->getSetterName()), |
| 4180 | Importer.Import(D->getSetterNameLoc())); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 4181 | ToProperty->setGetterMethodDecl( |
| 4182 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getGetterMethodDecl()))); |
| 4183 | ToProperty->setSetterMethodDecl( |
| 4184 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getSetterMethodDecl()))); |
| 4185 | ToProperty->setPropertyIvarDecl( |
| 4186 | cast_or_null<ObjCIvarDecl>(Importer.Import(D->getPropertyIvarDecl()))); |
| 4187 | return ToProperty; |
| 4188 | } |
| 4189 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4190 | Decl *ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4191 | auto *Property = cast_or_null<ObjCPropertyDecl>( |
| 4192 | Importer.Import(D->getPropertyDecl())); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4193 | if (!Property) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4194 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4195 | |
| 4196 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 4197 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4198 | return nullptr; |
| 4199 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4200 | // Import the lexical declaration context. |
| 4201 | DeclContext *LexicalDC = DC; |
| 4202 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4203 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4204 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4205 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4206 | } |
| 4207 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4208 | auto *InImpl = dyn_cast<ObjCImplDecl>(LexicalDC); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4209 | if (!InImpl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4210 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4211 | |
| 4212 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4213 | ObjCIvarDecl *Ivar = nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4214 | if (D->getPropertyIvarDecl()) { |
| 4215 | Ivar = cast_or_null<ObjCIvarDecl>( |
| 4216 | Importer.Import(D->getPropertyIvarDecl())); |
| 4217 | if (!Ivar) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4218 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 4222 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 4223 | Property->getQueryKind()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4224 | if (!ToImpl) { |
| 4225 | if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC, |
| 4226 | Importer.Import(D->getLocStart()), |
| 4227 | Importer.Import(D->getLocation()), Property, |
| 4228 | D->getPropertyImplementation(), Ivar, |
| 4229 | Importer.Import(D->getPropertyIvarDeclLoc()))) |
| 4230 | return ToImpl; |
| 4231 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4232 | ToImpl->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4233 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4234 | } else { |
| 4235 | // Check that we have the same kind of property implementation (@synthesize |
| 4236 | // vs. @dynamic). |
| 4237 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
| 4238 | Importer.ToDiag(ToImpl->getLocation(), |
| 4239 | diag::err_odr_objc_property_impl_kind_inconsistent) |
| 4240 | << Property->getDeclName() |
| 4241 | << (ToImpl->getPropertyImplementation() |
| 4242 | == ObjCPropertyImplDecl::Dynamic); |
| 4243 | Importer.FromDiag(D->getLocation(), |
| 4244 | diag::note_odr_objc_property_impl_kind) |
| 4245 | << D->getPropertyDecl()->getDeclName() |
| 4246 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4247 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4248 | } |
| 4249 | |
| 4250 | // For @synthesize, check that we have the same |
| 4251 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 4252 | Ivar != ToImpl->getPropertyIvarDecl()) { |
| 4253 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
| 4254 | diag::err_odr_objc_synthesize_ivar_inconsistent) |
| 4255 | << Property->getDeclName() |
| 4256 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 4257 | << Ivar->getDeclName(); |
| 4258 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
| 4259 | diag::note_odr_objc_synthesize_ivar_here) |
| 4260 | << D->getPropertyIvarDecl()->getDeclName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4261 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | // Merge the existing implementation with the new implementation. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4265 | Importer.MapImported(D, ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 4266 | } |
| 4267 | |
| 4268 | return ToImpl; |
| 4269 | } |
| 4270 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4271 | Decl *ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 4272 | // For template arguments, we adopt the translation unit as our declaration |
| 4273 | // context. This context will be fixed when the actual template declaration |
| 4274 | // is created. |
| 4275 | |
| 4276 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4277 | TemplateTypeParmDecl *ToD = nullptr; |
| 4278 | (void)GetImportedOrCreateDecl( |
| 4279 | ToD, D, Importer.getToContext(), |
| 4280 | Importer.getToContext().getTranslationUnitDecl(), |
| 4281 | Importer.Import(D->getLocStart()), Importer.Import(D->getLocation()), |
| 4282 | D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()), |
| 4283 | D->wasDeclaredWithTypename(), D->isParameterPack()); |
| 4284 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4285 | } |
| 4286 | |
| 4287 | Decl * |
| 4288 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 4289 | // Import the name of this declaration. |
| 4290 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 4291 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4292 | return nullptr; |
| 4293 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4294 | // Import the location of this declaration. |
| 4295 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 4296 | |
| 4297 | // Import the type of this declaration. |
| 4298 | QualType T = Importer.Import(D->getType()); |
| 4299 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4300 | return nullptr; |
| 4301 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4302 | // Import type-source information. |
| 4303 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 4304 | if (D->getTypeSourceInfo() && !TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4305 | return nullptr; |
| 4306 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4307 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4308 | |
| 4309 | NonTypeTemplateParmDecl *ToD = nullptr; |
| 4310 | (void)GetImportedOrCreateDecl( |
| 4311 | ToD, D, Importer.getToContext(), |
| 4312 | Importer.getToContext().getTranslationUnitDecl(), |
| 4313 | Importer.Import(D->getInnerLocStart()), Loc, D->getDepth(), |
| 4314 | D->getPosition(), Name.getAsIdentifierInfo(), T, D->isParameterPack(), |
| 4315 | TInfo); |
| 4316 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4317 | } |
| 4318 | |
| 4319 | Decl * |
| 4320 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 4321 | // Import the name of this declaration. |
| 4322 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 4323 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4324 | return nullptr; |
| 4325 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4326 | // Import the location of this declaration. |
| 4327 | SourceLocation Loc = Importer.Import(D->getLocation()); |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4328 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4329 | // Import template parameters. |
| 4330 | TemplateParameterList *TemplateParams |
| 4331 | = ImportTemplateParameterList(D->getTemplateParameters()); |
| 4332 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4333 | return nullptr; |
| 4334 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4335 | // FIXME: Import default argument. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4336 | |
| 4337 | TemplateTemplateParmDecl *ToD = nullptr; |
| 4338 | (void)GetImportedOrCreateDecl( |
| 4339 | ToD, D, Importer.getToContext(), |
| 4340 | Importer.getToContext().getTranslationUnitDecl(), Loc, D->getDepth(), |
| 4341 | D->getPosition(), D->isParameterPack(), Name.getAsIdentifierInfo(), |
| 4342 | TemplateParams); |
| 4343 | return ToD; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4344 | } |
| 4345 | |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4346 | // Returns the definition for a (forward) declaration of a ClassTemplateDecl, if |
| 4347 | // it has any definition in the redecl chain. |
| 4348 | static ClassTemplateDecl *getDefinition(ClassTemplateDecl *D) { |
| 4349 | CXXRecordDecl *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| 4350 | if (!ToTemplatedDef) |
| 4351 | return nullptr; |
| 4352 | ClassTemplateDecl *TemplateWithDef = |
| 4353 | ToTemplatedDef->getDescribedClassTemplate(); |
| 4354 | return TemplateWithDef; |
| 4355 | } |
| 4356 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4357 | Decl *ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 4358 | // If this record has a definition in the translation unit we're coming from, |
| 4359 | // but this particular declaration is not that definition, import the |
| 4360 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4361 | auto *Definition = |
| 4362 | cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4363 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 4364 | Decl *ImportedDef |
| 4365 | = Importer.Import(Definition->getDescribedClassTemplate()); |
| 4366 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4367 | return nullptr; |
| 4368 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4369 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4370 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4371 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4372 | // Import the major distinguishing characteristics of this class template. |
| 4373 | DeclContext *DC, *LexicalDC; |
| 4374 | DeclarationName Name; |
| 4375 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4376 | NamedDecl *ToD; |
| 4377 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4378 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4379 | if (ToD) |
| 4380 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4381 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4382 | // We may already have a template of the same name; try to find and match it. |
| 4383 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4384 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4385 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4386 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4387 | for (auto *FoundDecl : FoundDecls) { |
| 4388 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4389 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4390 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4391 | Decl *Found = FoundDecl; |
| 4392 | if (auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found)) { |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4393 | |
| 4394 | // The class to be imported is a definition. |
| 4395 | if (D->isThisDeclarationADefinition()) { |
| 4396 | // Lookup will find the fwd decl only if that is more recent than the |
| 4397 | // definition. So, try to get the definition if that is available in |
| 4398 | // the redecl chain. |
| 4399 | ClassTemplateDecl *TemplateWithDef = getDefinition(FoundTemplate); |
| 4400 | if (!TemplateWithDef) |
| 4401 | continue; |
| 4402 | FoundTemplate = TemplateWithDef; // Continue with the definition. |
| 4403 | } |
| 4404 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4405 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 4406 | // The class templates structurally match; call it the same template. |
Aleksei Sidorin | 761c224 | 2018-05-15 11:09:07 +0000 | [diff] [blame] | 4407 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4408 | Importer.MapImported(D->getTemplatedDecl(), |
| 4409 | FoundTemplate->getTemplatedDecl()); |
| 4410 | return Importer.MapImported(D, FoundTemplate); |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4411 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4412 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4413 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4414 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4415 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4416 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4417 | if (!ConflictingDecls.empty()) { |
| 4418 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4419 | ConflictingDecls.data(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4420 | ConflictingDecls.size()); |
| 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 (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4424 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4425 | } |
| 4426 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4427 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 4428 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4429 | // Create the declaration that is being templated. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4430 | auto *ToTemplated = cast_or_null<CXXRecordDecl>( |
| 4431 | Importer.Import(FromTemplated)); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4432 | if (!ToTemplated) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4433 | return nullptr; |
| 4434 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4435 | // Create the class template declaration itself. |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4436 | TemplateParameterList *TemplateParams = |
| 4437 | ImportTemplateParameterList(D->getTemplateParameters()); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4438 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4439 | return nullptr; |
| 4440 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4441 | ClassTemplateDecl *D2; |
| 4442 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name, |
| 4443 | TemplateParams, ToTemplated)) |
| 4444 | return D2; |
| 4445 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4446 | ToTemplated->setDescribedClassTemplate(D2); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4447 | |
| 4448 | D2->setAccess(D->getAccess()); |
| 4449 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4450 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4451 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4452 | if (FromTemplated->isCompleteDefinition() && |
| 4453 | !ToTemplated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4454 | // FIXME: Import definition! |
| 4455 | } |
| 4456 | |
| 4457 | return D2; |
| 4458 | } |
| 4459 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4460 | Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
| 4461 | ClassTemplateSpecializationDecl *D) { |
| 4462 | // If this record has a definition in the translation unit we're coming from, |
| 4463 | // but this particular declaration is not that definition, import the |
| 4464 | // definition and map to that. |
| 4465 | TagDecl *Definition = D->getDefinition(); |
| 4466 | if (Definition && Definition != D) { |
| 4467 | Decl *ImportedDef = Importer.Import(Definition); |
| 4468 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4469 | return nullptr; |
| 4470 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4471 | return Importer.MapImported(D, ImportedDef); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4472 | } |
| 4473 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4474 | auto *ClassTemplate = |
| 4475 | cast_or_null<ClassTemplateDecl>(Importer.Import( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4476 | D->getSpecializedTemplate())); |
| 4477 | if (!ClassTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4478 | return nullptr; |
| 4479 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4480 | // Import the context of this declaration. |
| 4481 | DeclContext *DC = ClassTemplate->getDeclContext(); |
| 4482 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4483 | return nullptr; |
| 4484 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4485 | DeclContext *LexicalDC = DC; |
| 4486 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4487 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4488 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4489 | return nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4490 | } |
| 4491 | |
| 4492 | // Import the location of this declaration. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 4493 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 4494 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4495 | |
| 4496 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4497 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4498 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 4499 | D->getTemplateArgs().size(), |
| 4500 | TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4501 | return nullptr; |
| 4502 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4503 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4504 | void *InsertPos = nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4505 | ClassTemplateSpecializationDecl *D2 |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 4506 | = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4507 | if (D2) { |
| 4508 | // We already have a class template specialization with these template |
| 4509 | // arguments. |
| 4510 | |
| 4511 | // FIXME: Check for specialization vs. instantiation errors. |
| 4512 | |
| 4513 | if (RecordDecl *FoundDef = D2->getDefinition()) { |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4514 | if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4515 | // The record types structurally match, or the "from" translation |
| 4516 | // unit only had a forward declaration anyway; call it the same |
| 4517 | // function. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4518 | return Importer.MapImported(D, FoundDef); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4519 | } |
| 4520 | } |
| 4521 | } else { |
| 4522 | // Create a new specialization. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4523 | if (auto *PartialSpec = |
| 4524 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4525 | // Import TemplateArgumentListInfo |
| 4526 | TemplateArgumentListInfo ToTAInfo; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4527 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 4528 | if (ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4529 | return nullptr; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4530 | |
| 4531 | QualType CanonInjType = Importer.Import( |
| 4532 | PartialSpec->getInjectedSpecializationType()); |
| 4533 | if (CanonInjType.isNull()) |
| 4534 | return nullptr; |
| 4535 | CanonInjType = CanonInjType.getCanonicalType(); |
| 4536 | |
| 4537 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 4538 | PartialSpec->getTemplateParameters()); |
| 4539 | if (!ToTPList && PartialSpec->getTemplateParameters()) |
| 4540 | return nullptr; |
| 4541 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4542 | if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>( |
| 4543 | D2, D, Importer.getToContext(), D->getTagKind(), DC, StartLoc, |
| 4544 | IdLoc, ToTPList, ClassTemplate, |
| 4545 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 4546 | ToTAInfo, CanonInjType, nullptr)) |
| 4547 | return D2; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4548 | |
| 4549 | } else { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4550 | if (GetImportedOrCreateDecl( |
| 4551 | D2, D, Importer.getToContext(), D->getTagKind(), DC, StartLoc, |
| 4552 | IdLoc, ClassTemplate, TemplateArgs, /*PrevDecl=*/nullptr)) |
| 4553 | return D2; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4554 | } |
| 4555 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4556 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 4557 | |
| 4558 | // Add this specialization to the class template. |
| 4559 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 4560 | |
| 4561 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4562 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4563 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4564 | if (auto *TSI = D->getTypeAsWritten()) { |
| 4565 | TypeSourceInfo *TInfo = Importer.Import(TSI); |
| 4566 | if (!TInfo) |
| 4567 | return nullptr; |
| 4568 | D2->setTypeAsWritten(TInfo); |
| 4569 | D2->setTemplateKeywordLoc(Importer.Import(D->getTemplateKeywordLoc())); |
| 4570 | D2->setExternLoc(Importer.Import(D->getExternLoc())); |
| 4571 | } |
| 4572 | |
| 4573 | SourceLocation POI = Importer.Import(D->getPointOfInstantiation()); |
| 4574 | if (POI.isValid()) |
| 4575 | D2->setPointOfInstantiation(POI); |
| 4576 | else if (D->getPointOfInstantiation().isValid()) |
| 4577 | return nullptr; |
| 4578 | |
| 4579 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 4580 | |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 4581 | // Set the context of this specialization/instantiation. |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4582 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | b14056b | 2018-05-25 11:21:24 +0000 | [diff] [blame] | 4583 | |
| 4584 | // Add to the DC only if it was an explicit specialization/instantiation. |
| 4585 | if (D2->isExplicitInstantiationOrSpecialization()) { |
| 4586 | LexicalDC->addDeclInternal(D2); |
| 4587 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4588 | } |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4589 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4590 | return nullptr; |
| 4591 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4592 | return D2; |
| 4593 | } |
| 4594 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4595 | Decl *ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| 4596 | // If this variable has a definition in the translation unit we're coming |
| 4597 | // from, |
| 4598 | // but this particular declaration is not that definition, import the |
| 4599 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4600 | auto *Definition = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4601 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 4602 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 4603 | Decl *ImportedDef = Importer.Import(Definition->getDescribedVarTemplate()); |
| 4604 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4605 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4606 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4607 | return Importer.MapImported(D, ImportedDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4608 | } |
| 4609 | |
| 4610 | // Import the major distinguishing characteristics of this variable template. |
| 4611 | DeclContext *DC, *LexicalDC; |
| 4612 | DeclarationName Name; |
| 4613 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4614 | NamedDecl *ToD; |
| 4615 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4616 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4617 | if (ToD) |
| 4618 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4619 | |
| 4620 | // We may already have a template of the same name; try to find and match it. |
| 4621 | assert(!DC->isFunctionOrMethod() && |
| 4622 | "Variable templates cannot be declared at function scope"); |
| 4623 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 4624 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4625 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4626 | for (auto *FoundDecl : FoundDecls) { |
| 4627 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4628 | continue; |
| 4629 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4630 | Decl *Found = FoundDecl; |
| 4631 | if (auto *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4632 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 4633 | // The variable templates structurally match; call it the same template. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4634 | Importer.MapImported(D->getTemplatedDecl(), |
| 4635 | FoundTemplate->getTemplatedDecl()); |
| 4636 | return Importer.MapImported(D, FoundTemplate); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4637 | } |
| 4638 | } |
| 4639 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4640 | ConflictingDecls.push_back(FoundDecl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4641 | } |
| 4642 | |
| 4643 | if (!ConflictingDecls.empty()) { |
| 4644 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 4645 | ConflictingDecls.data(), |
| 4646 | ConflictingDecls.size()); |
| 4647 | } |
| 4648 | |
| 4649 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4650 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4651 | |
| 4652 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 4653 | |
| 4654 | // Import the type. |
| 4655 | QualType T = Importer.Import(DTemplated->getType()); |
| 4656 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4657 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4658 | |
| 4659 | // Create the declaration that is being templated. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4660 | auto *ToTemplated = dyn_cast_or_null<VarDecl>(Importer.Import(DTemplated)); |
| 4661 | if (!ToTemplated) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4662 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4663 | |
| 4664 | // Create the variable template declaration itself. |
| 4665 | TemplateParameterList *TemplateParams = |
| 4666 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4667 | if (!TemplateParams) |
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 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4670 | VarTemplateDecl *ToVarTD; |
| 4671 | if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc, |
| 4672 | Name, TemplateParams, ToTemplated)) |
| 4673 | return ToVarTD; |
| 4674 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4675 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4676 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4677 | ToVarTD->setAccess(D->getAccess()); |
| 4678 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 4679 | LexicalDC->addDeclInternal(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4680 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4681 | if (DTemplated->isThisDeclarationADefinition() && |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4682 | !ToTemplated->isThisDeclarationADefinition()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4683 | // FIXME: Import definition! |
| 4684 | } |
| 4685 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4686 | return ToVarTD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4687 | } |
| 4688 | |
| 4689 | Decl *ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
| 4690 | VarTemplateSpecializationDecl *D) { |
| 4691 | // If this record has a definition in the translation unit we're coming from, |
| 4692 | // but this particular declaration is not that definition, import the |
| 4693 | // definition and map to that. |
| 4694 | VarDecl *Definition = D->getDefinition(); |
| 4695 | if (Definition && Definition != D) { |
| 4696 | Decl *ImportedDef = Importer.Import(Definition); |
| 4697 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4698 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4699 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4700 | return Importer.MapImported(D, ImportedDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4701 | } |
| 4702 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4703 | auto *VarTemplate = cast_or_null<VarTemplateDecl>( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4704 | Importer.Import(D->getSpecializedTemplate())); |
| 4705 | if (!VarTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4706 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4707 | |
| 4708 | // Import the context of this declaration. |
| 4709 | DeclContext *DC = VarTemplate->getDeclContext(); |
| 4710 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4711 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4712 | |
| 4713 | DeclContext *LexicalDC = DC; |
| 4714 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4715 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4716 | if (!LexicalDC) |
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 | |
| 4720 | // Import the location of this declaration. |
| 4721 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 4722 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
| 4723 | |
| 4724 | // Import template arguments. |
| 4725 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| 4726 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 4727 | D->getTemplateArgs().size(), TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4728 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4729 | |
| 4730 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4731 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4732 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 4733 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4734 | if (D2) { |
| 4735 | // We already have a variable template specialization with these template |
| 4736 | // arguments. |
| 4737 | |
| 4738 | // FIXME: Check for specialization vs. instantiation errors. |
| 4739 | |
| 4740 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 4741 | if (!D->isThisDeclarationADefinition() || |
| 4742 | IsStructuralMatch(D, FoundDef)) { |
| 4743 | // The record types structurally match, or the "from" translation |
| 4744 | // unit only had a forward declaration anyway; call it the same |
| 4745 | // variable. |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4746 | return Importer.MapImported(D, FoundDef); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4747 | } |
| 4748 | } |
| 4749 | } else { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4750 | // Import the type. |
| 4751 | QualType T = Importer.Import(D->getType()); |
| 4752 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4753 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4754 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4755 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 4756 | if (D->getTypeSourceInfo() && !TInfo) |
| 4757 | return nullptr; |
| 4758 | |
| 4759 | TemplateArgumentListInfo ToTAInfo; |
| 4760 | if (ImportTemplateArgumentListInfo(D->getTemplateArgsInfo(), ToTAInfo)) |
| 4761 | return nullptr; |
| 4762 | |
| 4763 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4764 | // Create a new specialization. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4765 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 4766 | // Import TemplateArgumentListInfo |
| 4767 | TemplateArgumentListInfo ArgInfos; |
| 4768 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 4769 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
| 4770 | if (ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ArgInfos)) |
| 4771 | return nullptr; |
| 4772 | |
| 4773 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 4774 | FromPartial->getTemplateParameters()); |
| 4775 | if (!ToTPList) |
| 4776 | return nullptr; |
| 4777 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4778 | PartVarSpecDecl *ToPartial; |
| 4779 | if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC, |
| 4780 | StartLoc, IdLoc, ToTPList, VarTemplate, T, |
| 4781 | TInfo, D->getStorageClass(), TemplateArgs, |
| 4782 | ArgInfos)) |
| 4783 | return ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4784 | |
| 4785 | auto *FromInst = FromPartial->getInstantiatedFromMember(); |
| 4786 | auto *ToInst = cast_or_null<PartVarSpecDecl>(Importer.Import(FromInst)); |
| 4787 | if (FromInst && !ToInst) |
| 4788 | return nullptr; |
| 4789 | |
| 4790 | ToPartial->setInstantiatedFromMember(ToInst); |
| 4791 | if (FromPartial->isMemberSpecialization()) |
| 4792 | ToPartial->setMemberSpecialization(); |
| 4793 | |
| 4794 | D2 = ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4795 | } else { // Full specialization |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4796 | if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, StartLoc, |
| 4797 | IdLoc, VarTemplate, T, TInfo, |
| 4798 | D->getStorageClass(), TemplateArgs)) |
| 4799 | return D2; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4800 | } |
| 4801 | |
| 4802 | SourceLocation POI = D->getPointOfInstantiation(); |
| 4803 | if (POI.isValid()) |
| 4804 | D2->setPointOfInstantiation(Importer.Import(POI)); |
| 4805 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4806 | D2->setSpecializationKind(D->getSpecializationKind()); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4807 | D2->setTemplateArgsInfo(ToTAInfo); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4808 | |
| 4809 | // Add this specialization to the class template. |
| 4810 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 4811 | |
| 4812 | // Import the qualifier, if any. |
| 4813 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
| 4814 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4815 | if (D->isConstexpr()) |
| 4816 | D2->setConstexpr(true); |
| 4817 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4818 | // Add the specialization to this context. |
| 4819 | D2->setLexicalDeclContext(LexicalDC); |
| 4820 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4821 | |
| 4822 | D2->setAccess(D->getAccess()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4823 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4824 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4825 | // NOTE: isThisDeclarationADefinition() can return DeclarationOnly even if |
| 4826 | // declaration has initializer. Should this be fixed in the AST?.. Anyway, |
| 4827 | // we have to check the declaration for initializer - otherwise, it won't be |
| 4828 | // imported. |
| 4829 | if ((D->isThisDeclarationADefinition() || D->hasInit()) && |
| 4830 | ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4831 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4832 | |
| 4833 | return D2; |
| 4834 | } |
| 4835 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4836 | Decl *ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 4837 | DeclContext *DC, *LexicalDC; |
| 4838 | DeclarationName Name; |
| 4839 | SourceLocation Loc; |
| 4840 | NamedDecl *ToD; |
| 4841 | |
| 4842 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4843 | return nullptr; |
| 4844 | |
| 4845 | if (ToD) |
| 4846 | return ToD; |
| 4847 | |
| 4848 | // Try to find a function in our own ("to") context with the same name, same |
| 4849 | // type, and in the same context as the function we're importing. |
| 4850 | if (!LexicalDC->isFunctionOrMethod()) { |
| 4851 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 4852 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 4853 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4854 | for (auto *FoundDecl : FoundDecls) { |
| 4855 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4856 | continue; |
| 4857 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4858 | if (auto *FoundFunction = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4859 | if (FoundFunction->hasExternalFormalLinkage() && |
| 4860 | D->hasExternalFormalLinkage()) { |
| 4861 | if (IsStructuralMatch(D, FoundFunction)) { |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4862 | Importer.MapImported(D, FoundFunction); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4863 | // FIXME: Actually try to merge the body and other attributes. |
| 4864 | return FoundFunction; |
| 4865 | } |
| 4866 | } |
| 4867 | } |
| 4868 | } |
| 4869 | } |
| 4870 | |
| 4871 | TemplateParameterList *Params = |
| 4872 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4873 | if (!Params) |
| 4874 | return nullptr; |
| 4875 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4876 | auto *TemplatedFD = |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4877 | cast_or_null<FunctionDecl>(Importer.Import(D->getTemplatedDecl())); |
| 4878 | if (!TemplatedFD) |
| 4879 | return nullptr; |
| 4880 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 4881 | FunctionTemplateDecl *ToFunc; |
| 4882 | if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name, |
| 4883 | Params, TemplatedFD)) |
| 4884 | return ToFunc; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4885 | |
| 4886 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| 4887 | ToFunc->setAccess(D->getAccess()); |
| 4888 | ToFunc->setLexicalDeclContext(LexicalDC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4889 | |
| 4890 | LexicalDC->addDeclInternal(ToFunc); |
| 4891 | return ToFunc; |
| 4892 | } |
| 4893 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4894 | //---------------------------------------------------------------------------- |
| 4895 | // Import Statements |
| 4896 | //---------------------------------------------------------------------------- |
| 4897 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4898 | DeclGroupRef ASTNodeImporter::ImportDeclGroup(DeclGroupRef DG) { |
| 4899 | if (DG.isNull()) |
| 4900 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 4901 | size_t NumDecls = DG.end() - DG.begin(); |
| 4902 | SmallVector<Decl *, 1> ToDecls(NumDecls); |
| 4903 | auto &_Importer = this->Importer; |
| 4904 | std::transform(DG.begin(), DG.end(), ToDecls.begin(), |
| 4905 | [&_Importer](Decl *D) -> Decl * { |
| 4906 | return _Importer.Import(D); |
| 4907 | }); |
| 4908 | return DeclGroupRef::Create(Importer.getToContext(), |
| 4909 | ToDecls.begin(), |
| 4910 | NumDecls); |
| 4911 | } |
| 4912 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4913 | Stmt *ASTNodeImporter::VisitStmt(Stmt *S) { |
| 4914 | Importer.FromDiag(S->getLocStart(), diag::err_unsupported_ast_node) |
| 4915 | << S->getStmtClassName(); |
| 4916 | return nullptr; |
| 4917 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4918 | |
| 4919 | Stmt *ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
| 4920 | SmallVector<IdentifierInfo *, 4> Names; |
| 4921 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 4922 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 4923 | // ToII is nullptr when no symbolic name is given for output operand |
| 4924 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 4925 | if (!ToII && S->getOutputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4926 | return nullptr; |
| 4927 | Names.push_back(ToII); |
| 4928 | } |
| 4929 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 4930 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 4931 | // ToII is nullptr when no symbolic name is given for input operand |
| 4932 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 4933 | if (!ToII && S->getInputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4934 | return nullptr; |
| 4935 | Names.push_back(ToII); |
| 4936 | } |
| 4937 | |
| 4938 | SmallVector<StringLiteral *, 4> Clobbers; |
| 4939 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4940 | auto *Clobber = cast_or_null<StringLiteral>( |
| 4941 | Importer.Import(S->getClobberStringLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4942 | if (!Clobber) |
| 4943 | return nullptr; |
| 4944 | Clobbers.push_back(Clobber); |
| 4945 | } |
| 4946 | |
| 4947 | SmallVector<StringLiteral *, 4> Constraints; |
| 4948 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4949 | auto *Output = cast_or_null<StringLiteral>( |
| 4950 | Importer.Import(S->getOutputConstraintLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4951 | if (!Output) |
| 4952 | return nullptr; |
| 4953 | Constraints.push_back(Output); |
| 4954 | } |
| 4955 | |
| 4956 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4957 | auto *Input = cast_or_null<StringLiteral>( |
| 4958 | Importer.Import(S->getInputConstraintLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4959 | if (!Input) |
| 4960 | return nullptr; |
| 4961 | Constraints.push_back(Input); |
| 4962 | } |
| 4963 | |
| 4964 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4965 | if (ImportContainerChecked(S->outputs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4966 | return nullptr; |
| 4967 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4968 | if (ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4969 | return nullptr; |
| 4970 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4971 | auto *AsmStr = cast_or_null<StringLiteral>( |
| 4972 | Importer.Import(S->getAsmString())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4973 | if (!AsmStr) |
| 4974 | return nullptr; |
| 4975 | |
| 4976 | return new (Importer.getToContext()) GCCAsmStmt( |
| 4977 | Importer.getToContext(), |
| 4978 | Importer.Import(S->getAsmLoc()), |
| 4979 | S->isSimple(), |
| 4980 | S->isVolatile(), |
| 4981 | S->getNumOutputs(), |
| 4982 | S->getNumInputs(), |
| 4983 | Names.data(), |
| 4984 | Constraints.data(), |
| 4985 | Exprs.data(), |
| 4986 | AsmStr, |
| 4987 | S->getNumClobbers(), |
| 4988 | Clobbers.data(), |
| 4989 | Importer.Import(S->getRParenLoc())); |
| 4990 | } |
| 4991 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4992 | Stmt *ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 4993 | DeclGroupRef ToDG = ImportDeclGroup(S->getDeclGroup()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4994 | for (auto *ToD : ToDG) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4995 | if (!ToD) |
| 4996 | return nullptr; |
| 4997 | } |
| 4998 | SourceLocation ToStartLoc = Importer.Import(S->getStartLoc()); |
| 4999 | SourceLocation ToEndLoc = Importer.Import(S->getEndLoc()); |
| 5000 | return new (Importer.getToContext()) DeclStmt(ToDG, ToStartLoc, ToEndLoc); |
| 5001 | } |
| 5002 | |
| 5003 | Stmt *ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 5004 | SourceLocation ToSemiLoc = Importer.Import(S->getSemiLoc()); |
| 5005 | return new (Importer.getToContext()) NullStmt(ToSemiLoc, |
| 5006 | S->hasLeadingEmptyMacro()); |
| 5007 | } |
| 5008 | |
| 5009 | Stmt *ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5010 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5011 | |
| 5012 | if (ImportContainerChecked(S->body(), ToStmts)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 5013 | return nullptr; |
| 5014 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5015 | SourceLocation ToLBraceLoc = Importer.Import(S->getLBracLoc()); |
| 5016 | SourceLocation ToRBraceLoc = Importer.Import(S->getRBracLoc()); |
Benjamin Kramer | 0742090 | 2017-12-24 16:24:20 +0000 | [diff] [blame] | 5017 | return CompoundStmt::Create(Importer.getToContext(), ToStmts, ToLBraceLoc, |
| 5018 | ToRBraceLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5019 | } |
| 5020 | |
| 5021 | Stmt *ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 5022 | Expr *ToLHS = Importer.Import(S->getLHS()); |
| 5023 | if (!ToLHS) |
| 5024 | return nullptr; |
| 5025 | Expr *ToRHS = Importer.Import(S->getRHS()); |
| 5026 | if (!ToRHS && S->getRHS()) |
| 5027 | return nullptr; |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5028 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5029 | if (!ToSubStmt && S->getSubStmt()) |
| 5030 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5031 | SourceLocation ToCaseLoc = Importer.Import(S->getCaseLoc()); |
| 5032 | SourceLocation ToEllipsisLoc = Importer.Import(S->getEllipsisLoc()); |
| 5033 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5034 | auto *ToStmt = new (Importer.getToContext()) |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 5035 | CaseStmt(ToLHS, ToRHS, ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
| 5036 | ToStmt->setSubStmt(ToSubStmt); |
| 5037 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5038 | } |
| 5039 | |
| 5040 | Stmt *ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 5041 | SourceLocation ToDefaultLoc = Importer.Import(S->getDefaultLoc()); |
| 5042 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 5043 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5044 | if (!ToSubStmt && S->getSubStmt()) |
| 5045 | return nullptr; |
| 5046 | return new (Importer.getToContext()) DefaultStmt(ToDefaultLoc, ToColonLoc, |
| 5047 | ToSubStmt); |
| 5048 | } |
| 5049 | |
| 5050 | Stmt *ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 5051 | SourceLocation ToIdentLoc = Importer.Import(S->getIdentLoc()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5052 | auto *ToLabelDecl = cast_or_null<LabelDecl>(Importer.Import(S->getDecl())); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5053 | if (!ToLabelDecl && S->getDecl()) |
| 5054 | return nullptr; |
| 5055 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5056 | if (!ToSubStmt && S->getSubStmt()) |
| 5057 | return nullptr; |
| 5058 | return new (Importer.getToContext()) LabelStmt(ToIdentLoc, ToLabelDecl, |
| 5059 | ToSubStmt); |
| 5060 | } |
| 5061 | |
| 5062 | Stmt *ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 5063 | SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc()); |
| 5064 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 5065 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 5066 | if (ImportContainerChecked(FromAttrs, ToAttrs)) |
| 5067 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5068 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5069 | if (!ToSubStmt && S->getSubStmt()) |
| 5070 | return nullptr; |
| 5071 | return AttributedStmt::Create(Importer.getToContext(), ToAttrLoc, |
| 5072 | ToAttrs, ToSubStmt); |
| 5073 | } |
| 5074 | |
| 5075 | Stmt *ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 5076 | SourceLocation ToIfLoc = Importer.Import(S->getIfLoc()); |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 5077 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 5078 | if (!ToInit && S->getInit()) |
| 5079 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5080 | VarDecl *ToConditionVariable = nullptr; |
| 5081 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5082 | ToConditionVariable = |
| 5083 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5084 | if (!ToConditionVariable) |
| 5085 | return nullptr; |
| 5086 | } |
| 5087 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5088 | if (!ToCondition && S->getCond()) |
| 5089 | return nullptr; |
| 5090 | Stmt *ToThenStmt = Importer.Import(S->getThen()); |
| 5091 | if (!ToThenStmt && S->getThen()) |
| 5092 | return nullptr; |
| 5093 | SourceLocation ToElseLoc = Importer.Import(S->getElseLoc()); |
| 5094 | Stmt *ToElseStmt = Importer.Import(S->getElse()); |
| 5095 | if (!ToElseStmt && S->getElse()) |
| 5096 | return nullptr; |
| 5097 | return new (Importer.getToContext()) IfStmt(Importer.getToContext(), |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 5098 | ToIfLoc, S->isConstexpr(), |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 5099 | ToInit, |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 5100 | ToConditionVariable, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5101 | ToCondition, ToThenStmt, |
| 5102 | ToElseLoc, ToElseStmt); |
| 5103 | } |
| 5104 | |
| 5105 | Stmt *ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 5106 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 5107 | if (!ToInit && S->getInit()) |
| 5108 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5109 | VarDecl *ToConditionVariable = nullptr; |
| 5110 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5111 | ToConditionVariable = |
| 5112 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5113 | if (!ToConditionVariable) |
| 5114 | return nullptr; |
| 5115 | } |
| 5116 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5117 | if (!ToCondition && S->getCond()) |
| 5118 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5119 | auto *ToStmt = new (Importer.getToContext()) SwitchStmt( |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 5120 | Importer.getToContext(), ToInit, |
| 5121 | ToConditionVariable, ToCondition); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5122 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5123 | if (!ToBody && S->getBody()) |
| 5124 | return nullptr; |
| 5125 | ToStmt->setBody(ToBody); |
| 5126 | ToStmt->setSwitchLoc(Importer.Import(S->getSwitchLoc())); |
| 5127 | // Now we have to re-chain the cases. |
| 5128 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 5129 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 5130 | SC = SC->getNextSwitchCase()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5131 | auto *ToSC = dyn_cast_or_null<SwitchCase>(Importer.Import(SC)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5132 | if (!ToSC) |
| 5133 | return nullptr; |
| 5134 | if (LastChainedSwitchCase) |
| 5135 | LastChainedSwitchCase->setNextSwitchCase(ToSC); |
| 5136 | else |
| 5137 | ToStmt->setSwitchCaseList(ToSC); |
| 5138 | LastChainedSwitchCase = ToSC; |
| 5139 | } |
| 5140 | return ToStmt; |
| 5141 | } |
| 5142 | |
| 5143 | Stmt *ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 5144 | VarDecl *ToConditionVariable = nullptr; |
| 5145 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5146 | ToConditionVariable = |
| 5147 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5148 | if (!ToConditionVariable) |
| 5149 | return nullptr; |
| 5150 | } |
| 5151 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5152 | if (!ToCondition && S->getCond()) |
| 5153 | return nullptr; |
| 5154 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5155 | if (!ToBody && S->getBody()) |
| 5156 | return nullptr; |
| 5157 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 5158 | return new (Importer.getToContext()) WhileStmt(Importer.getToContext(), |
| 5159 | ToConditionVariable, |
| 5160 | ToCondition, ToBody, |
| 5161 | ToWhileLoc); |
| 5162 | } |
| 5163 | |
| 5164 | Stmt *ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 5165 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5166 | if (!ToBody && S->getBody()) |
| 5167 | return nullptr; |
| 5168 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5169 | if (!ToCondition && S->getCond()) |
| 5170 | return nullptr; |
| 5171 | SourceLocation ToDoLoc = Importer.Import(S->getDoLoc()); |
| 5172 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 5173 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5174 | return new (Importer.getToContext()) DoStmt(ToBody, ToCondition, |
| 5175 | ToDoLoc, ToWhileLoc, |
| 5176 | ToRParenLoc); |
| 5177 | } |
| 5178 | |
| 5179 | Stmt *ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 5180 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 5181 | if (!ToInit && S->getInit()) |
| 5182 | return nullptr; |
| 5183 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 5184 | if (!ToCondition && S->getCond()) |
| 5185 | return nullptr; |
| 5186 | VarDecl *ToConditionVariable = nullptr; |
| 5187 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 5188 | ToConditionVariable = |
| 5189 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 5190 | if (!ToConditionVariable) |
| 5191 | return nullptr; |
| 5192 | } |
| 5193 | Expr *ToInc = Importer.Import(S->getInc()); |
| 5194 | if (!ToInc && S->getInc()) |
| 5195 | return nullptr; |
| 5196 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5197 | if (!ToBody && S->getBody()) |
| 5198 | return nullptr; |
| 5199 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 5200 | SourceLocation ToLParenLoc = Importer.Import(S->getLParenLoc()); |
| 5201 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5202 | return new (Importer.getToContext()) ForStmt(Importer.getToContext(), |
| 5203 | ToInit, ToCondition, |
| 5204 | ToConditionVariable, |
| 5205 | ToInc, ToBody, |
| 5206 | ToForLoc, ToLParenLoc, |
| 5207 | ToRParenLoc); |
| 5208 | } |
| 5209 | |
| 5210 | Stmt *ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 5211 | LabelDecl *ToLabel = nullptr; |
| 5212 | if (LabelDecl *FromLabel = S->getLabel()) { |
| 5213 | ToLabel = dyn_cast_or_null<LabelDecl>(Importer.Import(FromLabel)); |
| 5214 | if (!ToLabel) |
| 5215 | return nullptr; |
| 5216 | } |
| 5217 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 5218 | SourceLocation ToLabelLoc = Importer.Import(S->getLabelLoc()); |
| 5219 | return new (Importer.getToContext()) GotoStmt(ToLabel, |
| 5220 | ToGotoLoc, ToLabelLoc); |
| 5221 | } |
| 5222 | |
| 5223 | Stmt *ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 5224 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 5225 | SourceLocation ToStarLoc = Importer.Import(S->getStarLoc()); |
| 5226 | Expr *ToTarget = Importer.Import(S->getTarget()); |
| 5227 | if (!ToTarget && S->getTarget()) |
| 5228 | return nullptr; |
| 5229 | return new (Importer.getToContext()) IndirectGotoStmt(ToGotoLoc, ToStarLoc, |
| 5230 | ToTarget); |
| 5231 | } |
| 5232 | |
| 5233 | Stmt *ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 5234 | SourceLocation ToContinueLoc = Importer.Import(S->getContinueLoc()); |
| 5235 | return new (Importer.getToContext()) ContinueStmt(ToContinueLoc); |
| 5236 | } |
| 5237 | |
| 5238 | Stmt *ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 5239 | SourceLocation ToBreakLoc = Importer.Import(S->getBreakLoc()); |
| 5240 | return new (Importer.getToContext()) BreakStmt(ToBreakLoc); |
| 5241 | } |
| 5242 | |
| 5243 | Stmt *ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 5244 | SourceLocation ToRetLoc = Importer.Import(S->getReturnLoc()); |
| 5245 | Expr *ToRetExpr = Importer.Import(S->getRetValue()); |
| 5246 | if (!ToRetExpr && S->getRetValue()) |
| 5247 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5248 | auto *NRVOCandidate = const_cast<VarDecl *>(S->getNRVOCandidate()); |
| 5249 | auto *ToNRVOCandidate = cast_or_null<VarDecl>(Importer.Import(NRVOCandidate)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5250 | if (!ToNRVOCandidate && NRVOCandidate) |
| 5251 | return nullptr; |
| 5252 | return new (Importer.getToContext()) ReturnStmt(ToRetLoc, ToRetExpr, |
| 5253 | ToNRVOCandidate); |
| 5254 | } |
| 5255 | |
| 5256 | Stmt *ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 5257 | SourceLocation ToCatchLoc = Importer.Import(S->getCatchLoc()); |
| 5258 | VarDecl *ToExceptionDecl = nullptr; |
| 5259 | if (VarDecl *FromExceptionDecl = S->getExceptionDecl()) { |
| 5260 | ToExceptionDecl = |
| 5261 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 5262 | if (!ToExceptionDecl) |
| 5263 | return nullptr; |
| 5264 | } |
| 5265 | Stmt *ToHandlerBlock = Importer.Import(S->getHandlerBlock()); |
| 5266 | if (!ToHandlerBlock && S->getHandlerBlock()) |
| 5267 | return nullptr; |
| 5268 | return new (Importer.getToContext()) CXXCatchStmt(ToCatchLoc, |
| 5269 | ToExceptionDecl, |
| 5270 | ToHandlerBlock); |
| 5271 | } |
| 5272 | |
| 5273 | Stmt *ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 5274 | SourceLocation ToTryLoc = Importer.Import(S->getTryLoc()); |
| 5275 | Stmt *ToTryBlock = Importer.Import(S->getTryBlock()); |
| 5276 | if (!ToTryBlock && S->getTryBlock()) |
| 5277 | return nullptr; |
| 5278 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 5279 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 5280 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
| 5281 | if (Stmt *ToHandler = Importer.Import(FromHandler)) |
| 5282 | ToHandlers[HI] = ToHandler; |
| 5283 | else |
| 5284 | return nullptr; |
| 5285 | } |
| 5286 | return CXXTryStmt::Create(Importer.getToContext(), ToTryLoc, ToTryBlock, |
| 5287 | ToHandlers); |
| 5288 | } |
| 5289 | |
| 5290 | Stmt *ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5291 | auto *ToRange = |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5292 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getRangeStmt())); |
| 5293 | if (!ToRange && S->getRangeStmt()) |
| 5294 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5295 | auto *ToBegin = |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5296 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getBeginStmt())); |
| 5297 | if (!ToBegin && S->getBeginStmt()) |
| 5298 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5299 | auto *ToEnd = |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5300 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getEndStmt())); |
| 5301 | if (!ToEnd && S->getEndStmt()) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5302 | return nullptr; |
| 5303 | Expr *ToCond = Importer.Import(S->getCond()); |
| 5304 | if (!ToCond && S->getCond()) |
| 5305 | return nullptr; |
| 5306 | Expr *ToInc = Importer.Import(S->getInc()); |
| 5307 | if (!ToInc && S->getInc()) |
| 5308 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5309 | auto *ToLoopVar = |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5310 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getLoopVarStmt())); |
| 5311 | if (!ToLoopVar && S->getLoopVarStmt()) |
| 5312 | return nullptr; |
| 5313 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5314 | if (!ToBody && S->getBody()) |
| 5315 | return nullptr; |
| 5316 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 5317 | SourceLocation ToCoawaitLoc = Importer.Import(S->getCoawaitLoc()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5318 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 5319 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5320 | return new (Importer.getToContext()) CXXForRangeStmt(ToRange, ToBegin, ToEnd, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5321 | ToCond, ToInc, |
| 5322 | ToLoopVar, ToBody, |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 5323 | ToForLoc, ToCoawaitLoc, |
| 5324 | ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | Stmt *ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 5328 | Stmt *ToElem = Importer.Import(S->getElement()); |
| 5329 | if (!ToElem && S->getElement()) |
| 5330 | return nullptr; |
| 5331 | Expr *ToCollect = Importer.Import(S->getCollection()); |
| 5332 | if (!ToCollect && S->getCollection()) |
| 5333 | return nullptr; |
| 5334 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5335 | if (!ToBody && S->getBody()) |
| 5336 | return nullptr; |
| 5337 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 5338 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5339 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElem, |
| 5340 | ToCollect, |
| 5341 | ToBody, ToForLoc, |
| 5342 | ToRParenLoc); |
| 5343 | } |
| 5344 | |
| 5345 | Stmt *ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 5346 | SourceLocation ToAtCatchLoc = Importer.Import(S->getAtCatchLoc()); |
| 5347 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5348 | VarDecl *ToExceptionDecl = nullptr; |
| 5349 | if (VarDecl *FromExceptionDecl = S->getCatchParamDecl()) { |
| 5350 | ToExceptionDecl = |
| 5351 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 5352 | if (!ToExceptionDecl) |
| 5353 | return nullptr; |
| 5354 | } |
| 5355 | Stmt *ToBody = Importer.Import(S->getCatchBody()); |
| 5356 | if (!ToBody && S->getCatchBody()) |
| 5357 | return nullptr; |
| 5358 | return new (Importer.getToContext()) ObjCAtCatchStmt(ToAtCatchLoc, |
| 5359 | ToRParenLoc, |
| 5360 | ToExceptionDecl, |
| 5361 | ToBody); |
| 5362 | } |
| 5363 | |
| 5364 | Stmt *ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 5365 | SourceLocation ToAtFinallyLoc = Importer.Import(S->getAtFinallyLoc()); |
| 5366 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyBody()); |
| 5367 | if (!ToAtFinallyStmt && S->getFinallyBody()) |
| 5368 | return nullptr; |
| 5369 | return new (Importer.getToContext()) ObjCAtFinallyStmt(ToAtFinallyLoc, |
| 5370 | ToAtFinallyStmt); |
| 5371 | } |
| 5372 | |
| 5373 | Stmt *ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 5374 | SourceLocation ToAtTryLoc = Importer.Import(S->getAtTryLoc()); |
| 5375 | Stmt *ToAtTryStmt = Importer.Import(S->getTryBody()); |
| 5376 | if (!ToAtTryStmt && S->getTryBody()) |
| 5377 | return nullptr; |
| 5378 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 5379 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 5380 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
| 5381 | if (Stmt *ToCatchStmt = Importer.Import(FromCatchStmt)) |
| 5382 | ToCatchStmts[CI] = ToCatchStmt; |
| 5383 | else |
| 5384 | return nullptr; |
| 5385 | } |
| 5386 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyStmt()); |
| 5387 | if (!ToAtFinallyStmt && S->getFinallyStmt()) |
| 5388 | return nullptr; |
| 5389 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
| 5390 | ToAtTryLoc, ToAtTryStmt, |
| 5391 | ToCatchStmts.begin(), ToCatchStmts.size(), |
| 5392 | ToAtFinallyStmt); |
| 5393 | } |
| 5394 | |
| 5395 | Stmt *ASTNodeImporter::VisitObjCAtSynchronizedStmt |
| 5396 | (ObjCAtSynchronizedStmt *S) { |
| 5397 | SourceLocation ToAtSynchronizedLoc = |
| 5398 | Importer.Import(S->getAtSynchronizedLoc()); |
| 5399 | Expr *ToSynchExpr = Importer.Import(S->getSynchExpr()); |
| 5400 | if (!ToSynchExpr && S->getSynchExpr()) |
| 5401 | return nullptr; |
| 5402 | Stmt *ToSynchBody = Importer.Import(S->getSynchBody()); |
| 5403 | if (!ToSynchBody && S->getSynchBody()) |
| 5404 | return nullptr; |
| 5405 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 5406 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 5407 | } |
| 5408 | |
| 5409 | Stmt *ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 5410 | SourceLocation ToAtThrowLoc = Importer.Import(S->getThrowLoc()); |
| 5411 | Expr *ToThrow = Importer.Import(S->getThrowExpr()); |
| 5412 | if (!ToThrow && S->getThrowExpr()) |
| 5413 | return nullptr; |
| 5414 | return new (Importer.getToContext()) ObjCAtThrowStmt(ToAtThrowLoc, ToThrow); |
| 5415 | } |
| 5416 | |
| 5417 | Stmt *ASTNodeImporter::VisitObjCAutoreleasePoolStmt |
| 5418 | (ObjCAutoreleasePoolStmt *S) { |
| 5419 | SourceLocation ToAtLoc = Importer.Import(S->getAtLoc()); |
| 5420 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5421 | if (!ToSubStmt && S->getSubStmt()) |
| 5422 | return nullptr; |
| 5423 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(ToAtLoc, |
| 5424 | ToSubStmt); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5425 | } |
| 5426 | |
| 5427 | //---------------------------------------------------------------------------- |
| 5428 | // Import Expressions |
| 5429 | //---------------------------------------------------------------------------- |
| 5430 | Expr *ASTNodeImporter::VisitExpr(Expr *E) { |
| 5431 | Importer.FromDiag(E->getLocStart(), diag::err_unsupported_ast_node) |
| 5432 | << E->getStmtClassName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5433 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5434 | } |
| 5435 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5436 | Expr *ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 5437 | QualType T = Importer.Import(E->getType()); |
| 5438 | if (T.isNull()) |
| 5439 | return nullptr; |
| 5440 | |
| 5441 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5442 | if (!SubExpr && E->getSubExpr()) |
| 5443 | return nullptr; |
| 5444 | |
| 5445 | TypeSourceInfo *TInfo = Importer.Import(E->getWrittenTypeInfo()); |
| 5446 | if (!TInfo) |
| 5447 | return nullptr; |
| 5448 | |
| 5449 | return new (Importer.getToContext()) VAArgExpr( |
| 5450 | Importer.Import(E->getBuiltinLoc()), SubExpr, TInfo, |
| 5451 | Importer.Import(E->getRParenLoc()), T, E->isMicrosoftABI()); |
| 5452 | } |
| 5453 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5454 | Expr *ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 5455 | QualType T = Importer.Import(E->getType()); |
| 5456 | if (T.isNull()) |
| 5457 | return nullptr; |
| 5458 | |
| 5459 | return new (Importer.getToContext()) GNUNullExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5460 | T, Importer.Import(E->getLocStart())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5461 | } |
| 5462 | |
| 5463 | Expr *ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 5464 | QualType T = Importer.Import(E->getType()); |
| 5465 | if (T.isNull()) |
| 5466 | return nullptr; |
| 5467 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5468 | auto *SL = cast_or_null<StringLiteral>(Importer.Import(E->getFunctionName())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5469 | if (!SL && E->getFunctionName()) |
| 5470 | return nullptr; |
| 5471 | |
| 5472 | return new (Importer.getToContext()) PredefinedExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5473 | Importer.Import(E->getLocStart()), T, E->getIdentType(), SL); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5474 | } |
| 5475 | |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5476 | Expr *ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5477 | auto *ToD = cast_or_null<ValueDecl>(Importer.Import(E->getDecl())); |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5478 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5479 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5480 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5481 | NamedDecl *FoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5482 | if (E->getDecl() != E->getFoundDecl()) { |
| 5483 | FoundD = cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl())); |
| 5484 | if (!FoundD) |
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 | } |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5487 | |
| 5488 | QualType T = Importer.Import(E->getType()); |
| 5489 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5490 | return nullptr; |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5491 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5492 | TemplateArgumentListInfo ToTAInfo; |
| 5493 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 5494 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5495 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 5496 | return nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5497 | ResInfo = &ToTAInfo; |
| 5498 | } |
| 5499 | |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5500 | DeclRefExpr *DRE = DeclRefExpr::Create(Importer.getToContext(), |
| 5501 | Importer.Import(E->getQualifierLoc()), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 5502 | Importer.Import(E->getTemplateKeywordLoc()), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5503 | ToD, |
Alexey Bataev | 19acc3d | 2015-01-12 10:17:46 +0000 | [diff] [blame] | 5504 | E->refersToEnclosingVariableOrCapture(), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5505 | Importer.Import(E->getLocation()), |
| 5506 | T, E->getValueKind(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5507 | FoundD, ResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5508 | if (E->hadMultipleCandidates()) |
| 5509 | DRE->setHadMultipleCandidates(true); |
| 5510 | return DRE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5511 | } |
| 5512 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5513 | Expr *ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 5514 | QualType T = Importer.Import(E->getType()); |
| 5515 | if (T.isNull()) |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5516 | return nullptr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5517 | |
| 5518 | return new (Importer.getToContext()) ImplicitValueInitExpr(T); |
| 5519 | } |
| 5520 | |
| 5521 | ASTNodeImporter::Designator |
| 5522 | ASTNodeImporter::ImportDesignator(const Designator &D) { |
| 5523 | if (D.isFieldDesignator()) { |
| 5524 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 5525 | // Caller checks for import error |
| 5526 | return Designator(ToFieldName, Importer.Import(D.getDotLoc()), |
| 5527 | Importer.Import(D.getFieldLoc())); |
| 5528 | } |
| 5529 | if (D.isArrayDesignator()) |
| 5530 | return Designator(D.getFirstExprIndex(), |
| 5531 | Importer.Import(D.getLBracketLoc()), |
| 5532 | Importer.Import(D.getRBracketLoc())); |
| 5533 | |
| 5534 | assert(D.isArrayRangeDesignator()); |
| 5535 | return Designator(D.getFirstExprIndex(), |
| 5536 | Importer.Import(D.getLBracketLoc()), |
| 5537 | Importer.Import(D.getEllipsisLoc()), |
| 5538 | Importer.Import(D.getRBracketLoc())); |
| 5539 | } |
| 5540 | |
| 5541 | |
| 5542 | Expr *ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *DIE) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5543 | auto *Init = cast_or_null<Expr>(Importer.Import(DIE->getInit())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5544 | if (!Init) |
| 5545 | return nullptr; |
| 5546 | |
| 5547 | SmallVector<Expr *, 4> IndexExprs(DIE->getNumSubExprs() - 1); |
| 5548 | // List elements from the second, the first is Init itself |
| 5549 | for (unsigned I = 1, E = DIE->getNumSubExprs(); I < E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5550 | if (auto *Arg = cast_or_null<Expr>(Importer.Import(DIE->getSubExpr(I)))) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5551 | IndexExprs[I - 1] = Arg; |
| 5552 | else |
| 5553 | return nullptr; |
| 5554 | } |
| 5555 | |
| 5556 | SmallVector<Designator, 4> Designators(DIE->size()); |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5557 | llvm::transform(DIE->designators(), Designators.begin(), |
| 5558 | [this](const Designator &D) -> Designator { |
| 5559 | return ImportDesignator(D); |
| 5560 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5561 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5562 | for (const auto &D : DIE->designators()) |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5563 | if (D.isFieldDesignator() && !D.getFieldName()) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5564 | return nullptr; |
| 5565 | |
| 5566 | return DesignatedInitExpr::Create( |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5567 | Importer.getToContext(), Designators, |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5568 | IndexExprs, Importer.Import(DIE->getEqualOrColonLoc()), |
| 5569 | DIE->usesGNUSyntax(), Init); |
| 5570 | } |
| 5571 | |
| 5572 | Expr *ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 5573 | QualType T = Importer.Import(E->getType()); |
| 5574 | if (T.isNull()) |
| 5575 | return nullptr; |
| 5576 | |
| 5577 | return new (Importer.getToContext()) |
| 5578 | CXXNullPtrLiteralExpr(T, Importer.Import(E->getLocation())); |
| 5579 | } |
| 5580 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5581 | Expr *ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 5582 | QualType T = Importer.Import(E->getType()); |
| 5583 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5584 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5585 | |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 5586 | return IntegerLiteral::Create(Importer.getToContext(), |
| 5587 | E->getValue(), T, |
| 5588 | Importer.Import(E->getLocation())); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5589 | } |
| 5590 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5591 | Expr *ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 5592 | QualType T = Importer.Import(E->getType()); |
| 5593 | if (T.isNull()) |
| 5594 | return nullptr; |
| 5595 | |
| 5596 | return FloatingLiteral::Create(Importer.getToContext(), |
| 5597 | E->getValue(), E->isExact(), T, |
| 5598 | Importer.Import(E->getLocation())); |
| 5599 | } |
| 5600 | |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5601 | Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 5602 | QualType T = Importer.Import(E->getType()); |
| 5603 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5604 | return nullptr; |
| 5605 | |
Douglas Gregor | fb65e59 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 5606 | return new (Importer.getToContext()) CharacterLiteral(E->getValue(), |
| 5607 | E->getKind(), T, |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5608 | Importer.Import(E->getLocation())); |
| 5609 | } |
| 5610 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5611 | Expr *ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 5612 | QualType T = Importer.Import(E->getType()); |
| 5613 | if (T.isNull()) |
| 5614 | return nullptr; |
| 5615 | |
| 5616 | SmallVector<SourceLocation, 4> Locations(E->getNumConcatenated()); |
| 5617 | ImportArray(E->tokloc_begin(), E->tokloc_end(), Locations.begin()); |
| 5618 | |
| 5619 | return StringLiteral::Create(Importer.getToContext(), E->getBytes(), |
| 5620 | E->getKind(), E->isPascal(), T, |
| 5621 | Locations.data(), Locations.size()); |
| 5622 | } |
| 5623 | |
| 5624 | Expr *ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 5625 | QualType T = Importer.Import(E->getType()); |
| 5626 | if (T.isNull()) |
| 5627 | return nullptr; |
| 5628 | |
| 5629 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeSourceInfo()); |
| 5630 | if (!TInfo) |
| 5631 | return nullptr; |
| 5632 | |
| 5633 | Expr *Init = Importer.Import(E->getInitializer()); |
| 5634 | if (!Init) |
| 5635 | return nullptr; |
| 5636 | |
| 5637 | return new (Importer.getToContext()) CompoundLiteralExpr( |
| 5638 | Importer.Import(E->getLParenLoc()), TInfo, T, E->getValueKind(), |
| 5639 | Init, E->isFileScope()); |
| 5640 | } |
| 5641 | |
| 5642 | Expr *ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 5643 | QualType T = Importer.Import(E->getType()); |
| 5644 | if (T.isNull()) |
| 5645 | return nullptr; |
| 5646 | |
| 5647 | SmallVector<Expr *, 6> Exprs(E->getNumSubExprs()); |
| 5648 | if (ImportArrayChecked( |
| 5649 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 5650 | Exprs.begin())) |
| 5651 | return nullptr; |
| 5652 | |
| 5653 | return new (Importer.getToContext()) AtomicExpr( |
| 5654 | Importer.Import(E->getBuiltinLoc()), Exprs, T, E->getOp(), |
| 5655 | Importer.Import(E->getRParenLoc())); |
| 5656 | } |
| 5657 | |
| 5658 | Expr *ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 5659 | QualType T = Importer.Import(E->getType()); |
| 5660 | if (T.isNull()) |
| 5661 | return nullptr; |
| 5662 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5663 | auto *ToLabel = cast_or_null<LabelDecl>(Importer.Import(E->getLabel())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5664 | if (!ToLabel) |
| 5665 | return nullptr; |
| 5666 | |
| 5667 | return new (Importer.getToContext()) AddrLabelExpr( |
| 5668 | Importer.Import(E->getAmpAmpLoc()), Importer.Import(E->getLabelLoc()), |
| 5669 | ToLabel, T); |
| 5670 | } |
| 5671 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5672 | Expr *ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 5673 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5674 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5675 | return nullptr; |
| 5676 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5677 | return new (Importer.getToContext()) |
| 5678 | ParenExpr(Importer.Import(E->getLParen()), |
| 5679 | Importer.Import(E->getRParen()), |
| 5680 | SubExpr); |
| 5681 | } |
| 5682 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5683 | Expr *ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 5684 | SmallVector<Expr *, 4> Exprs(E->getNumExprs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5685 | if (ImportContainerChecked(E->exprs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5686 | return nullptr; |
| 5687 | |
| 5688 | return new (Importer.getToContext()) ParenListExpr( |
| 5689 | Importer.getToContext(), Importer.Import(E->getLParenLoc()), |
| 5690 | Exprs, Importer.Import(E->getLParenLoc())); |
| 5691 | } |
| 5692 | |
| 5693 | Expr *ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 5694 | QualType T = Importer.Import(E->getType()); |
| 5695 | if (T.isNull()) |
| 5696 | return nullptr; |
| 5697 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5698 | auto *ToSubStmt = cast_or_null<CompoundStmt>( |
| 5699 | Importer.Import(E->getSubStmt())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5700 | if (!ToSubStmt && E->getSubStmt()) |
| 5701 | return nullptr; |
| 5702 | |
| 5703 | return new (Importer.getToContext()) StmtExpr(ToSubStmt, T, |
| 5704 | Importer.Import(E->getLParenLoc()), Importer.Import(E->getRParenLoc())); |
| 5705 | } |
| 5706 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5707 | Expr *ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 5708 | QualType T = Importer.Import(E->getType()); |
| 5709 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5710 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5711 | |
| 5712 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5713 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5714 | return nullptr; |
| 5715 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5716 | return new (Importer.getToContext()) UnaryOperator( |
| 5717 | SubExpr, E->getOpcode(), T, E->getValueKind(), E->getObjectKind(), |
| 5718 | Importer.Import(E->getOperatorLoc()), E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5719 | } |
| 5720 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5721 | Expr * |
| 5722 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5723 | QualType ResultType = Importer.Import(E->getType()); |
| 5724 | |
| 5725 | if (E->isArgumentType()) { |
| 5726 | TypeSourceInfo *TInfo = Importer.Import(E->getArgumentTypeInfo()); |
| 5727 | if (!TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5728 | return nullptr; |
| 5729 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5730 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5731 | TInfo, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5732 | Importer.Import(E->getOperatorLoc()), |
| 5733 | Importer.Import(E->getRParenLoc())); |
| 5734 | } |
| 5735 | |
| 5736 | Expr *SubExpr = Importer.Import(E->getArgumentExpr()); |
| 5737 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5738 | return nullptr; |
| 5739 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5740 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5741 | SubExpr, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5742 | Importer.Import(E->getOperatorLoc()), |
| 5743 | Importer.Import(E->getRParenLoc())); |
| 5744 | } |
| 5745 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5746 | Expr *ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 5747 | QualType T = Importer.Import(E->getType()); |
| 5748 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5749 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5750 | |
| 5751 | Expr *LHS = Importer.Import(E->getLHS()); |
| 5752 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5753 | return nullptr; |
| 5754 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5755 | Expr *RHS = Importer.Import(E->getRHS()); |
| 5756 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5757 | return nullptr; |
| 5758 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5759 | return new (Importer.getToContext()) BinaryOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 5760 | T, E->getValueKind(), |
| 5761 | E->getObjectKind(), |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 5762 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 5763 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5764 | } |
| 5765 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5766 | Expr *ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 5767 | QualType T = Importer.Import(E->getType()); |
| 5768 | if (T.isNull()) |
| 5769 | return nullptr; |
| 5770 | |
| 5771 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5772 | if (!ToLHS) |
| 5773 | return nullptr; |
| 5774 | |
| 5775 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5776 | if (!ToRHS) |
| 5777 | return nullptr; |
| 5778 | |
| 5779 | Expr *ToCond = Importer.Import(E->getCond()); |
| 5780 | if (!ToCond) |
| 5781 | return nullptr; |
| 5782 | |
| 5783 | return new (Importer.getToContext()) ConditionalOperator( |
| 5784 | ToCond, Importer.Import(E->getQuestionLoc()), |
| 5785 | ToLHS, Importer.Import(E->getColonLoc()), |
| 5786 | ToRHS, T, E->getValueKind(), E->getObjectKind()); |
| 5787 | } |
| 5788 | |
| 5789 | Expr *ASTNodeImporter::VisitBinaryConditionalOperator( |
| 5790 | BinaryConditionalOperator *E) { |
| 5791 | QualType T = Importer.Import(E->getType()); |
| 5792 | if (T.isNull()) |
| 5793 | return nullptr; |
| 5794 | |
| 5795 | Expr *Common = Importer.Import(E->getCommon()); |
| 5796 | if (!Common) |
| 5797 | return nullptr; |
| 5798 | |
| 5799 | Expr *Cond = Importer.Import(E->getCond()); |
| 5800 | if (!Cond) |
| 5801 | return nullptr; |
| 5802 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5803 | auto *OpaqueValue = cast_or_null<OpaqueValueExpr>( |
| 5804 | Importer.Import(E->getOpaqueValue())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5805 | if (!OpaqueValue) |
| 5806 | return nullptr; |
| 5807 | |
| 5808 | Expr *TrueExpr = Importer.Import(E->getTrueExpr()); |
| 5809 | if (!TrueExpr) |
| 5810 | return nullptr; |
| 5811 | |
| 5812 | Expr *FalseExpr = Importer.Import(E->getFalseExpr()); |
| 5813 | if (!FalseExpr) |
| 5814 | return nullptr; |
| 5815 | |
| 5816 | return new (Importer.getToContext()) BinaryConditionalOperator( |
| 5817 | Common, OpaqueValue, Cond, TrueExpr, FalseExpr, |
| 5818 | Importer.Import(E->getQuestionLoc()), Importer.Import(E->getColonLoc()), |
| 5819 | T, E->getValueKind(), E->getObjectKind()); |
| 5820 | } |
| 5821 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5822 | Expr *ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 5823 | QualType T = Importer.Import(E->getType()); |
| 5824 | if (T.isNull()) |
| 5825 | return nullptr; |
| 5826 | |
| 5827 | TypeSourceInfo *ToQueried = Importer.Import(E->getQueriedTypeSourceInfo()); |
| 5828 | if (!ToQueried) |
| 5829 | return nullptr; |
| 5830 | |
| 5831 | Expr *Dim = Importer.Import(E->getDimensionExpression()); |
| 5832 | if (!Dim && E->getDimensionExpression()) |
| 5833 | return nullptr; |
| 5834 | |
| 5835 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
| 5836 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 5837 | E->getValue(), Dim, Importer.Import(E->getLocEnd()), T); |
| 5838 | } |
| 5839 | |
| 5840 | Expr *ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 5841 | QualType T = Importer.Import(E->getType()); |
| 5842 | if (T.isNull()) |
| 5843 | return nullptr; |
| 5844 | |
| 5845 | Expr *ToQueried = Importer.Import(E->getQueriedExpression()); |
| 5846 | if (!ToQueried) |
| 5847 | return nullptr; |
| 5848 | |
| 5849 | return new (Importer.getToContext()) ExpressionTraitExpr( |
| 5850 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 5851 | E->getValue(), Importer.Import(E->getLocEnd()), T); |
| 5852 | } |
| 5853 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5854 | Expr *ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 5855 | QualType T = Importer.Import(E->getType()); |
| 5856 | if (T.isNull()) |
| 5857 | return nullptr; |
| 5858 | |
| 5859 | Expr *SourceExpr = Importer.Import(E->getSourceExpr()); |
| 5860 | if (!SourceExpr && E->getSourceExpr()) |
| 5861 | return nullptr; |
| 5862 | |
| 5863 | return new (Importer.getToContext()) OpaqueValueExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5864 | Importer.Import(E->getLocation()), T, E->getValueKind(), |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5865 | E->getObjectKind(), SourceExpr); |
| 5866 | } |
| 5867 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5868 | Expr *ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 5869 | QualType T = Importer.Import(E->getType()); |
| 5870 | if (T.isNull()) |
| 5871 | return nullptr; |
| 5872 | |
| 5873 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5874 | if (!ToLHS) |
| 5875 | return nullptr; |
| 5876 | |
| 5877 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5878 | if (!ToRHS) |
| 5879 | return nullptr; |
| 5880 | |
| 5881 | return new (Importer.getToContext()) ArraySubscriptExpr( |
| 5882 | ToLHS, ToRHS, T, E->getValueKind(), E->getObjectKind(), |
| 5883 | Importer.Import(E->getRBracketLoc())); |
| 5884 | } |
| 5885 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5886 | Expr *ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 5887 | QualType T = Importer.Import(E->getType()); |
| 5888 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5889 | return nullptr; |
| 5890 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5891 | QualType CompLHSType = Importer.Import(E->getComputationLHSType()); |
| 5892 | if (CompLHSType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5893 | return nullptr; |
| 5894 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5895 | QualType CompResultType = Importer.Import(E->getComputationResultType()); |
| 5896 | if (CompResultType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5897 | return nullptr; |
| 5898 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5899 | Expr *LHS = Importer.Import(E->getLHS()); |
| 5900 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5901 | return nullptr; |
| 5902 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5903 | Expr *RHS = Importer.Import(E->getRHS()); |
| 5904 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5905 | return nullptr; |
| 5906 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5907 | return new (Importer.getToContext()) |
| 5908 | CompoundAssignOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 5909 | T, E->getValueKind(), |
| 5910 | E->getObjectKind(), |
| 5911 | CompLHSType, CompResultType, |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 5912 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 5913 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5914 | } |
| 5915 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5916 | bool ASTNodeImporter::ImportCastPath(CastExpr *CE, CXXCastPath &Path) { |
| 5917 | for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) { |
| 5918 | if (CXXBaseSpecifier *Spec = Importer.Import(*I)) |
| 5919 | Path.push_back(Spec); |
| 5920 | else |
| 5921 | return true; |
| 5922 | } |
| 5923 | return false; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5924 | } |
| 5925 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5926 | Expr *ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 5927 | QualType T = Importer.Import(E->getType()); |
| 5928 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5929 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5930 | |
| 5931 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5932 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5933 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5934 | |
| 5935 | CXXCastPath BasePath; |
| 5936 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5937 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5938 | |
| 5939 | return ImplicitCastExpr::Create(Importer.getToContext(), T, E->getCastKind(), |
John McCall | 2536c6d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 5940 | SubExpr, &BasePath, E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5941 | } |
| 5942 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5943 | Expr *ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5944 | QualType T = Importer.Import(E->getType()); |
| 5945 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5946 | return nullptr; |
| 5947 | |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5948 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5949 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5950 | return nullptr; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5951 | |
| 5952 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeInfoAsWritten()); |
| 5953 | if (!TInfo && E->getTypeInfoAsWritten()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5954 | return nullptr; |
| 5955 | |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5956 | CXXCastPath BasePath; |
| 5957 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5958 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5959 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5960 | switch (E->getStmtClass()) { |
| 5961 | case Stmt::CStyleCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5962 | auto *CCE = cast<CStyleCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5963 | return CStyleCastExpr::Create(Importer.getToContext(), T, |
| 5964 | E->getValueKind(), E->getCastKind(), |
| 5965 | SubExpr, &BasePath, TInfo, |
| 5966 | Importer.Import(CCE->getLParenLoc()), |
| 5967 | Importer.Import(CCE->getRParenLoc())); |
| 5968 | } |
| 5969 | |
| 5970 | case Stmt::CXXFunctionalCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5971 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5972 | return CXXFunctionalCastExpr::Create(Importer.getToContext(), T, |
| 5973 | E->getValueKind(), TInfo, |
| 5974 | E->getCastKind(), SubExpr, &BasePath, |
| 5975 | Importer.Import(FCE->getLParenLoc()), |
| 5976 | Importer.Import(FCE->getRParenLoc())); |
| 5977 | } |
| 5978 | |
| 5979 | case Stmt::ObjCBridgedCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5980 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5981 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 5982 | Importer.Import(OCE->getLParenLoc()), OCE->getBridgeKind(), |
| 5983 | E->getCastKind(), Importer.Import(OCE->getBridgeKeywordLoc()), |
| 5984 | TInfo, SubExpr); |
| 5985 | } |
| 5986 | default: |
| 5987 | break; // just fall through |
| 5988 | } |
| 5989 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5990 | auto *Named = cast<CXXNamedCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5991 | SourceLocation ExprLoc = Importer.Import(Named->getOperatorLoc()), |
| 5992 | RParenLoc = Importer.Import(Named->getRParenLoc()); |
| 5993 | SourceRange Brackets = Importer.Import(Named->getAngleBrackets()); |
| 5994 | |
| 5995 | switch (E->getStmtClass()) { |
| 5996 | case Stmt::CXXStaticCastExprClass: |
| 5997 | return CXXStaticCastExpr::Create(Importer.getToContext(), T, |
| 5998 | E->getValueKind(), E->getCastKind(), |
| 5999 | SubExpr, &BasePath, TInfo, |
| 6000 | ExprLoc, RParenLoc, Brackets); |
| 6001 | |
| 6002 | case Stmt::CXXDynamicCastExprClass: |
| 6003 | return CXXDynamicCastExpr::Create(Importer.getToContext(), T, |
| 6004 | E->getValueKind(), E->getCastKind(), |
| 6005 | SubExpr, &BasePath, TInfo, |
| 6006 | ExprLoc, RParenLoc, Brackets); |
| 6007 | |
| 6008 | case Stmt::CXXReinterpretCastExprClass: |
| 6009 | return CXXReinterpretCastExpr::Create(Importer.getToContext(), T, |
| 6010 | E->getValueKind(), E->getCastKind(), |
| 6011 | SubExpr, &BasePath, TInfo, |
| 6012 | ExprLoc, RParenLoc, Brackets); |
| 6013 | |
| 6014 | case Stmt::CXXConstCastExprClass: |
| 6015 | return CXXConstCastExpr::Create(Importer.getToContext(), T, |
| 6016 | E->getValueKind(), SubExpr, TInfo, ExprLoc, |
| 6017 | RParenLoc, Brackets); |
| 6018 | default: |
| 6019 | llvm_unreachable("Cast expression of unsupported type!"); |
| 6020 | return nullptr; |
| 6021 | } |
| 6022 | } |
| 6023 | |
| 6024 | Expr *ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *OE) { |
| 6025 | QualType T = Importer.Import(OE->getType()); |
| 6026 | if (T.isNull()) |
| 6027 | return nullptr; |
| 6028 | |
| 6029 | SmallVector<OffsetOfNode, 4> Nodes; |
| 6030 | for (int I = 0, E = OE->getNumComponents(); I < E; ++I) { |
| 6031 | const OffsetOfNode &Node = OE->getComponent(I); |
| 6032 | |
| 6033 | switch (Node.getKind()) { |
| 6034 | case OffsetOfNode::Array: |
| 6035 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), |
| 6036 | Node.getArrayExprIndex(), |
| 6037 | Importer.Import(Node.getLocEnd()))); |
| 6038 | break; |
| 6039 | |
| 6040 | case OffsetOfNode::Base: { |
| 6041 | CXXBaseSpecifier *BS = Importer.Import(Node.getBase()); |
| 6042 | if (!BS && Node.getBase()) |
| 6043 | return nullptr; |
| 6044 | Nodes.push_back(OffsetOfNode(BS)); |
| 6045 | break; |
| 6046 | } |
| 6047 | case OffsetOfNode::Field: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6048 | auto *FD = cast_or_null<FieldDecl>(Importer.Import(Node.getField())); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6049 | if (!FD) |
| 6050 | return nullptr; |
| 6051 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), FD, |
| 6052 | Importer.Import(Node.getLocEnd()))); |
| 6053 | break; |
| 6054 | } |
| 6055 | case OffsetOfNode::Identifier: { |
| 6056 | IdentifierInfo *ToII = Importer.Import(Node.getFieldName()); |
| 6057 | if (!ToII) |
| 6058 | return nullptr; |
| 6059 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), ToII, |
| 6060 | Importer.Import(Node.getLocEnd()))); |
| 6061 | break; |
| 6062 | } |
| 6063 | } |
| 6064 | } |
| 6065 | |
| 6066 | SmallVector<Expr *, 4> Exprs(OE->getNumExpressions()); |
| 6067 | for (int I = 0, E = OE->getNumExpressions(); I < E; ++I) { |
| 6068 | Expr *ToIndexExpr = Importer.Import(OE->getIndexExpr(I)); |
| 6069 | if (!ToIndexExpr) |
| 6070 | return nullptr; |
| 6071 | Exprs[I] = ToIndexExpr; |
| 6072 | } |
| 6073 | |
| 6074 | TypeSourceInfo *TInfo = Importer.Import(OE->getTypeSourceInfo()); |
| 6075 | if (!TInfo && OE->getTypeSourceInfo()) |
| 6076 | return nullptr; |
| 6077 | |
| 6078 | return OffsetOfExpr::Create(Importer.getToContext(), T, |
| 6079 | Importer.Import(OE->getOperatorLoc()), |
| 6080 | TInfo, Nodes, Exprs, |
| 6081 | Importer.Import(OE->getRParenLoc())); |
| 6082 | } |
| 6083 | |
| 6084 | Expr *ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 6085 | QualType T = Importer.Import(E->getType()); |
| 6086 | if (T.isNull()) |
| 6087 | return nullptr; |
| 6088 | |
| 6089 | Expr *Operand = Importer.Import(E->getOperand()); |
| 6090 | if (!Operand) |
| 6091 | return nullptr; |
| 6092 | |
| 6093 | CanThrowResult CanThrow; |
| 6094 | if (E->isValueDependent()) |
| 6095 | CanThrow = CT_Dependent; |
| 6096 | else |
| 6097 | CanThrow = E->getValue() ? CT_Can : CT_Cannot; |
| 6098 | |
| 6099 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 6100 | T, Operand, CanThrow, |
| 6101 | Importer.Import(E->getLocStart()), Importer.Import(E->getLocEnd())); |
| 6102 | } |
| 6103 | |
| 6104 | Expr *ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 6105 | QualType T = Importer.Import(E->getType()); |
| 6106 | if (T.isNull()) |
| 6107 | return nullptr; |
| 6108 | |
| 6109 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 6110 | if (!SubExpr && E->getSubExpr()) |
| 6111 | return nullptr; |
| 6112 | |
| 6113 | return new (Importer.getToContext()) CXXThrowExpr( |
| 6114 | SubExpr, T, Importer.Import(E->getThrowLoc()), |
| 6115 | E->isThrownVariableInScope()); |
| 6116 | } |
| 6117 | |
| 6118 | Expr *ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6119 | auto *Param = cast_or_null<ParmVarDecl>(Importer.Import(E->getParam())); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6120 | if (!Param) |
| 6121 | return nullptr; |
| 6122 | |
| 6123 | return CXXDefaultArgExpr::Create( |
| 6124 | Importer.getToContext(), Importer.Import(E->getUsedLocation()), Param); |
| 6125 | } |
| 6126 | |
| 6127 | Expr *ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 6128 | QualType T = Importer.Import(E->getType()); |
| 6129 | if (T.isNull()) |
| 6130 | return nullptr; |
| 6131 | |
| 6132 | TypeSourceInfo *TypeInfo = Importer.Import(E->getTypeSourceInfo()); |
| 6133 | if (!TypeInfo) |
| 6134 | return nullptr; |
| 6135 | |
| 6136 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
| 6137 | T, TypeInfo, Importer.Import(E->getRParenLoc())); |
| 6138 | } |
| 6139 | |
| 6140 | Expr *ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 6141 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 6142 | if (!SubExpr) |
| 6143 | return nullptr; |
| 6144 | |
| 6145 | auto *Dtor = cast_or_null<CXXDestructorDecl>( |
| 6146 | Importer.Import(const_cast<CXXDestructorDecl *>( |
| 6147 | E->getTemporary()->getDestructor()))); |
| 6148 | if (!Dtor) |
| 6149 | return nullptr; |
| 6150 | |
| 6151 | ASTContext &ToCtx = Importer.getToContext(); |
| 6152 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, Dtor); |
| 6153 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, SubExpr); |
| 6154 | } |
| 6155 | |
| 6156 | Expr *ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE) { |
| 6157 | QualType T = Importer.Import(CE->getType()); |
| 6158 | if (T.isNull()) |
| 6159 | return nullptr; |
| 6160 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6161 | TypeSourceInfo *TInfo = Importer.Import(CE->getTypeSourceInfo()); |
| 6162 | if (!TInfo) |
| 6163 | return nullptr; |
| 6164 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6165 | SmallVector<Expr *, 8> Args(CE->getNumArgs()); |
| 6166 | if (ImportContainerChecked(CE->arguments(), Args)) |
| 6167 | return nullptr; |
| 6168 | |
| 6169 | auto *Ctor = cast_or_null<CXXConstructorDecl>( |
| 6170 | Importer.Import(CE->getConstructor())); |
| 6171 | if (!Ctor) |
| 6172 | return nullptr; |
| 6173 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6174 | return new (Importer.getToContext()) CXXTemporaryObjectExpr( |
| 6175 | Importer.getToContext(), Ctor, T, TInfo, Args, |
| 6176 | Importer.Import(CE->getParenOrBraceRange()), CE->hadMultipleCandidates(), |
| 6177 | CE->isListInitialization(), CE->isStdInitListInitialization(), |
| 6178 | CE->requiresZeroInitialization()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6179 | } |
| 6180 | |
| 6181 | Expr * |
| 6182 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
| 6183 | QualType T = Importer.Import(E->getType()); |
| 6184 | if (T.isNull()) |
| 6185 | return nullptr; |
| 6186 | |
| 6187 | Expr *TempE = Importer.Import(E->GetTemporaryExpr()); |
| 6188 | if (!TempE) |
| 6189 | return nullptr; |
| 6190 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6191 | auto *ExtendedBy = cast_or_null<ValueDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6192 | Importer.Import(const_cast<ValueDecl *>(E->getExtendingDecl()))); |
| 6193 | if (!ExtendedBy && E->getExtendingDecl()) |
| 6194 | return nullptr; |
| 6195 | |
| 6196 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
| 6197 | T, TempE, E->isBoundToLvalueReference()); |
| 6198 | |
| 6199 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
| 6200 | ToMTE->setExtendingDecl(ExtendedBy, E->getManglingNumber()); |
| 6201 | return ToMTE; |
| 6202 | } |
| 6203 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 6204 | Expr *ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 6205 | QualType T = Importer.Import(E->getType()); |
| 6206 | if (T.isNull()) |
| 6207 | return nullptr; |
| 6208 | |
| 6209 | Expr *Pattern = Importer.Import(E->getPattern()); |
| 6210 | if (!Pattern) |
| 6211 | return nullptr; |
| 6212 | |
| 6213 | return new (Importer.getToContext()) PackExpansionExpr( |
| 6214 | T, Pattern, Importer.Import(E->getEllipsisLoc()), |
| 6215 | E->getNumExpansions()); |
| 6216 | } |
| 6217 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6218 | Expr *ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 6219 | auto *Pack = cast_or_null<NamedDecl>(Importer.Import(E->getPack())); |
| 6220 | if (!Pack) |
| 6221 | return nullptr; |
| 6222 | |
| 6223 | Optional<unsigned> Length; |
| 6224 | |
| 6225 | if (!E->isValueDependent()) |
| 6226 | Length = E->getPackLength(); |
| 6227 | |
| 6228 | SmallVector<TemplateArgument, 8> PartialArguments; |
| 6229 | if (E->isPartiallySubstituted()) { |
| 6230 | if (ImportTemplateArguments(E->getPartialArguments().data(), |
| 6231 | E->getPartialArguments().size(), |
| 6232 | PartialArguments)) |
| 6233 | return nullptr; |
| 6234 | } |
| 6235 | |
| 6236 | return SizeOfPackExpr::Create( |
| 6237 | Importer.getToContext(), Importer.Import(E->getOperatorLoc()), Pack, |
| 6238 | Importer.Import(E->getPackLoc()), Importer.Import(E->getRParenLoc()), |
| 6239 | Length, PartialArguments); |
| 6240 | } |
| 6241 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6242 | Expr *ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *CE) { |
| 6243 | QualType T = Importer.Import(CE->getType()); |
| 6244 | if (T.isNull()) |
| 6245 | return nullptr; |
| 6246 | |
| 6247 | SmallVector<Expr *, 4> PlacementArgs(CE->getNumPlacementArgs()); |
| 6248 | if (ImportContainerChecked(CE->placement_arguments(), PlacementArgs)) |
| 6249 | return nullptr; |
| 6250 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6251 | auto *OperatorNewDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6252 | Importer.Import(CE->getOperatorNew())); |
| 6253 | if (!OperatorNewDecl && CE->getOperatorNew()) |
| 6254 | return nullptr; |
| 6255 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6256 | auto *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6257 | Importer.Import(CE->getOperatorDelete())); |
| 6258 | if (!OperatorDeleteDecl && CE->getOperatorDelete()) |
| 6259 | return nullptr; |
| 6260 | |
| 6261 | Expr *ToInit = Importer.Import(CE->getInitializer()); |
| 6262 | if (!ToInit && CE->getInitializer()) |
| 6263 | return nullptr; |
| 6264 | |
| 6265 | TypeSourceInfo *TInfo = Importer.Import(CE->getAllocatedTypeSourceInfo()); |
| 6266 | if (!TInfo) |
| 6267 | return nullptr; |
| 6268 | |
| 6269 | Expr *ToArrSize = Importer.Import(CE->getArraySize()); |
| 6270 | if (!ToArrSize && CE->getArraySize()) |
| 6271 | return nullptr; |
| 6272 | |
| 6273 | return new (Importer.getToContext()) CXXNewExpr( |
| 6274 | Importer.getToContext(), |
| 6275 | CE->isGlobalNew(), |
| 6276 | OperatorNewDecl, OperatorDeleteDecl, |
Richard Smith | b2f0f05 | 2016-10-10 18:54:32 +0000 | [diff] [blame] | 6277 | CE->passAlignment(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6278 | CE->doesUsualArrayDeleteWantSize(), |
| 6279 | PlacementArgs, |
| 6280 | Importer.Import(CE->getTypeIdParens()), |
| 6281 | ToArrSize, CE->getInitializationStyle(), ToInit, T, TInfo, |
| 6282 | Importer.Import(CE->getSourceRange()), |
| 6283 | Importer.Import(CE->getDirectInitRange())); |
| 6284 | } |
| 6285 | |
| 6286 | Expr *ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 6287 | QualType T = Importer.Import(E->getType()); |
| 6288 | if (T.isNull()) |
| 6289 | return nullptr; |
| 6290 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6291 | auto *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6292 | Importer.Import(E->getOperatorDelete())); |
| 6293 | if (!OperatorDeleteDecl && E->getOperatorDelete()) |
| 6294 | return nullptr; |
| 6295 | |
| 6296 | Expr *ToArg = Importer.Import(E->getArgument()); |
| 6297 | if (!ToArg && E->getArgument()) |
| 6298 | return nullptr; |
| 6299 | |
| 6300 | return new (Importer.getToContext()) CXXDeleteExpr( |
| 6301 | T, E->isGlobalDelete(), |
| 6302 | E->isArrayForm(), |
| 6303 | E->isArrayFormAsWritten(), |
| 6304 | E->doesUsualArrayDeleteWantSize(), |
| 6305 | OperatorDeleteDecl, |
| 6306 | ToArg, |
| 6307 | Importer.Import(E->getLocStart())); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6308 | } |
| 6309 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6310 | Expr *ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 6311 | QualType T = Importer.Import(E->getType()); |
| 6312 | if (T.isNull()) |
| 6313 | return nullptr; |
| 6314 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6315 | auto *ToCCD = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6316 | dyn_cast_or_null<CXXConstructorDecl>(Importer.Import(E->getConstructor())); |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 6317 | if (!ToCCD) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6318 | return nullptr; |
| 6319 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6320 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6321 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6322 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6323 | |
| 6324 | return CXXConstructExpr::Create(Importer.getToContext(), T, |
| 6325 | Importer.Import(E->getLocation()), |
Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 6326 | ToCCD, E->isElidable(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6327 | ToArgs, E->hadMultipleCandidates(), |
| 6328 | E->isListInitialization(), |
| 6329 | E->isStdInitListInitialization(), |
| 6330 | E->requiresZeroInitialization(), |
| 6331 | E->getConstructionKind(), |
| 6332 | Importer.Import(E->getParenOrBraceRange())); |
| 6333 | } |
| 6334 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6335 | Expr *ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *EWC) { |
| 6336 | Expr *SubExpr = Importer.Import(EWC->getSubExpr()); |
| 6337 | if (!SubExpr && EWC->getSubExpr()) |
| 6338 | return nullptr; |
| 6339 | |
| 6340 | SmallVector<ExprWithCleanups::CleanupObject, 8> Objs(EWC->getNumObjects()); |
| 6341 | for (unsigned I = 0, E = EWC->getNumObjects(); I < E; I++) |
| 6342 | if (ExprWithCleanups::CleanupObject Obj = |
| 6343 | cast_or_null<BlockDecl>(Importer.Import(EWC->getObject(I)))) |
| 6344 | Objs[I] = Obj; |
| 6345 | else |
| 6346 | return nullptr; |
| 6347 | |
| 6348 | return ExprWithCleanups::Create(Importer.getToContext(), |
| 6349 | SubExpr, EWC->cleanupsHaveSideEffects(), |
| 6350 | Objs); |
| 6351 | } |
| 6352 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6353 | Expr *ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6354 | QualType T = Importer.Import(E->getType()); |
| 6355 | if (T.isNull()) |
| 6356 | return nullptr; |
| 6357 | |
| 6358 | Expr *ToFn = Importer.Import(E->getCallee()); |
| 6359 | if (!ToFn) |
| 6360 | return nullptr; |
| 6361 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6362 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6363 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6364 | return nullptr; |
| 6365 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6366 | return new (Importer.getToContext()) CXXMemberCallExpr( |
| 6367 | Importer.getToContext(), ToFn, ToArgs, T, E->getValueKind(), |
| 6368 | Importer.Import(E->getRParenLoc())); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6369 | } |
| 6370 | |
| 6371 | Expr *ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 6372 | QualType T = Importer.Import(E->getType()); |
| 6373 | if (T.isNull()) |
| 6374 | return nullptr; |
| 6375 | |
| 6376 | return new (Importer.getToContext()) |
| 6377 | CXXThisExpr(Importer.Import(E->getLocation()), T, E->isImplicit()); |
| 6378 | } |
| 6379 | |
| 6380 | Expr *ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 6381 | QualType T = Importer.Import(E->getType()); |
| 6382 | if (T.isNull()) |
| 6383 | return nullptr; |
| 6384 | |
| 6385 | return new (Importer.getToContext()) |
| 6386 | CXXBoolLiteralExpr(E->getValue(), T, Importer.Import(E->getLocation())); |
| 6387 | } |
| 6388 | |
| 6389 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6390 | Expr *ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 6391 | QualType T = Importer.Import(E->getType()); |
| 6392 | if (T.isNull()) |
| 6393 | return nullptr; |
| 6394 | |
| 6395 | Expr *ToBase = Importer.Import(E->getBase()); |
| 6396 | if (!ToBase && E->getBase()) |
| 6397 | return nullptr; |
| 6398 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6399 | auto *ToMember = dyn_cast<ValueDecl>(Importer.Import(E->getMemberDecl())); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6400 | if (!ToMember && E->getMemberDecl()) |
| 6401 | return nullptr; |
| 6402 | |
Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 6403 | auto *ToDecl = |
| 6404 | dyn_cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl().getDecl())); |
| 6405 | if (!ToDecl && E->getFoundDecl().getDecl()) |
| 6406 | return nullptr; |
| 6407 | |
| 6408 | DeclAccessPair ToFoundDecl = |
| 6409 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6410 | |
| 6411 | DeclarationNameInfo ToMemberNameInfo( |
| 6412 | Importer.Import(E->getMemberNameInfo().getName()), |
| 6413 | Importer.Import(E->getMemberNameInfo().getLoc())); |
| 6414 | |
| 6415 | if (E->hasExplicitTemplateArgs()) { |
| 6416 | return nullptr; // FIXME: handle template arguments |
| 6417 | } |
| 6418 | |
| 6419 | return MemberExpr::Create(Importer.getToContext(), ToBase, |
| 6420 | E->isArrow(), |
| 6421 | Importer.Import(E->getOperatorLoc()), |
| 6422 | Importer.Import(E->getQualifierLoc()), |
| 6423 | Importer.Import(E->getTemplateKeywordLoc()), |
| 6424 | ToMember, ToFoundDecl, ToMemberNameInfo, |
| 6425 | nullptr, T, E->getValueKind(), |
| 6426 | E->getObjectKind()); |
| 6427 | } |
| 6428 | |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 6429 | Expr *ASTNodeImporter::VisitCXXPseudoDestructorExpr( |
| 6430 | CXXPseudoDestructorExpr *E) { |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 6431 | Expr *BaseE = Importer.Import(E->getBase()); |
| 6432 | if (!BaseE) |
| 6433 | return nullptr; |
| 6434 | |
| 6435 | TypeSourceInfo *ScopeInfo = Importer.Import(E->getScopeTypeInfo()); |
| 6436 | if (!ScopeInfo && E->getScopeTypeInfo()) |
| 6437 | return nullptr; |
| 6438 | |
| 6439 | PseudoDestructorTypeStorage Storage; |
| 6440 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 6441 | IdentifierInfo *ToII = Importer.Import(FromII); |
| 6442 | if (!ToII) |
| 6443 | return nullptr; |
| 6444 | Storage = PseudoDestructorTypeStorage( |
| 6445 | ToII, Importer.Import(E->getDestroyedTypeLoc())); |
| 6446 | } else { |
| 6447 | TypeSourceInfo *TI = Importer.Import(E->getDestroyedTypeInfo()); |
| 6448 | if (!TI) |
| 6449 | return nullptr; |
| 6450 | Storage = PseudoDestructorTypeStorage(TI); |
| 6451 | } |
| 6452 | |
| 6453 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
| 6454 | Importer.getToContext(), BaseE, E->isArrow(), |
| 6455 | Importer.Import(E->getOperatorLoc()), |
| 6456 | Importer.Import(E->getQualifierLoc()), |
| 6457 | ScopeInfo, Importer.Import(E->getColonColonLoc()), |
| 6458 | Importer.Import(E->getTildeLoc()), Storage); |
| 6459 | } |
| 6460 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6461 | Expr *ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
| 6462 | CXXDependentScopeMemberExpr *E) { |
| 6463 | Expr *Base = nullptr; |
| 6464 | if (!E->isImplicitAccess()) { |
| 6465 | Base = Importer.Import(E->getBase()); |
| 6466 | if (!Base) |
| 6467 | return nullptr; |
| 6468 | } |
| 6469 | |
| 6470 | QualType BaseType = Importer.Import(E->getBaseType()); |
| 6471 | if (BaseType.isNull()) |
| 6472 | return nullptr; |
| 6473 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6474 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6475 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6476 | if (ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6477 | E->template_arguments(), ToTAInfo)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6478 | return nullptr; |
| 6479 | ResInfo = &ToTAInfo; |
| 6480 | } |
| 6481 | |
| 6482 | DeclarationName Name = Importer.Import(E->getMember()); |
| 6483 | if (!E->getMember().isEmpty() && Name.isEmpty()) |
| 6484 | return nullptr; |
| 6485 | |
| 6486 | DeclarationNameInfo MemberNameInfo(Name, Importer.Import(E->getMemberLoc())); |
| 6487 | // Import additional name location/type info. |
| 6488 | ImportDeclarationNameLoc(E->getMemberNameInfo(), MemberNameInfo); |
| 6489 | auto ToFQ = Importer.Import(E->getFirstQualifierFoundInScope()); |
| 6490 | if (!ToFQ && E->getFirstQualifierFoundInScope()) |
| 6491 | return nullptr; |
| 6492 | |
| 6493 | return CXXDependentScopeMemberExpr::Create( |
| 6494 | Importer.getToContext(), Base, BaseType, E->isArrow(), |
| 6495 | Importer.Import(E->getOperatorLoc()), |
| 6496 | Importer.Import(E->getQualifierLoc()), |
| 6497 | Importer.Import(E->getTemplateKeywordLoc()), |
| 6498 | cast_or_null<NamedDecl>(ToFQ), MemberNameInfo, ResInfo); |
| 6499 | } |
| 6500 | |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 6501 | Expr * |
| 6502 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
| 6503 | DeclarationName Name = Importer.Import(E->getDeclName()); |
| 6504 | if (!E->getDeclName().isEmpty() && Name.isEmpty()) |
| 6505 | return nullptr; |
| 6506 | |
| 6507 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getExprLoc())); |
| 6508 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6509 | |
| 6510 | TemplateArgumentListInfo ToTAInfo(Importer.Import(E->getLAngleLoc()), |
| 6511 | Importer.Import(E->getRAngleLoc())); |
| 6512 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 6513 | if (E->hasExplicitTemplateArgs()) { |
| 6514 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6515 | return nullptr; |
| 6516 | ResInfo = &ToTAInfo; |
| 6517 | } |
| 6518 | |
| 6519 | return DependentScopeDeclRefExpr::Create( |
| 6520 | Importer.getToContext(), Importer.Import(E->getQualifierLoc()), |
| 6521 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, ResInfo); |
| 6522 | } |
| 6523 | |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6524 | Expr *ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 6525 | CXXUnresolvedConstructExpr *CE) { |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6526 | unsigned NumArgs = CE->arg_size(); |
| 6527 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6528 | SmallVector<Expr *, 8> ToArgs(NumArgs); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6529 | if (ImportArrayChecked(CE->arg_begin(), CE->arg_end(), ToArgs.begin())) |
| 6530 | return nullptr; |
| 6531 | |
| 6532 | return CXXUnresolvedConstructExpr::Create( |
| 6533 | Importer.getToContext(), Importer.Import(CE->getTypeSourceInfo()), |
| 6534 | Importer.Import(CE->getLParenLoc()), llvm::makeArrayRef(ToArgs), |
| 6535 | Importer.Import(CE->getRParenLoc())); |
| 6536 | } |
| 6537 | |
| 6538 | Expr *ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6539 | auto *NamingClass = |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6540 | cast_or_null<CXXRecordDecl>(Importer.Import(E->getNamingClass())); |
| 6541 | if (E->getNamingClass() && !NamingClass) |
| 6542 | return nullptr; |
| 6543 | |
| 6544 | DeclarationName Name = Importer.Import(E->getName()); |
| 6545 | if (E->getName() && !Name) |
| 6546 | return nullptr; |
| 6547 | |
| 6548 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getNameLoc())); |
| 6549 | // Import additional name location/type info. |
| 6550 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6551 | |
| 6552 | UnresolvedSet<8> ToDecls; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6553 | for (auto *D : E->decls()) { |
| 6554 | if (auto *To = cast_or_null<NamedDecl>(Importer.Import(D))) |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6555 | ToDecls.addDecl(To); |
| 6556 | else |
| 6557 | return nullptr; |
| 6558 | } |
| 6559 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6560 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6561 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6562 | if (ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6563 | E->template_arguments(), ToTAInfo)) |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6564 | return nullptr; |
| 6565 | ResInfo = &ToTAInfo; |
| 6566 | } |
| 6567 | |
| 6568 | if (ResInfo || E->getTemplateKeywordLoc().isValid()) |
| 6569 | return UnresolvedLookupExpr::Create( |
| 6570 | Importer.getToContext(), NamingClass, |
| 6571 | Importer.Import(E->getQualifierLoc()), |
| 6572 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, E->requiresADL(), |
| 6573 | ResInfo, ToDecls.begin(), ToDecls.end()); |
| 6574 | |
| 6575 | return UnresolvedLookupExpr::Create( |
| 6576 | Importer.getToContext(), NamingClass, |
| 6577 | Importer.Import(E->getQualifierLoc()), NameInfo, E->requiresADL(), |
| 6578 | E->isOverloaded(), ToDecls.begin(), ToDecls.end()); |
| 6579 | } |
| 6580 | |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 6581 | Expr *ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 6582 | DeclarationName Name = Importer.Import(E->getName()); |
| 6583 | if (!E->getName().isEmpty() && Name.isEmpty()) |
| 6584 | return nullptr; |
| 6585 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getNameLoc())); |
| 6586 | // Import additional name location/type info. |
| 6587 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6588 | |
| 6589 | QualType BaseType = Importer.Import(E->getType()); |
| 6590 | if (!E->getType().isNull() && BaseType.isNull()) |
| 6591 | return nullptr; |
| 6592 | |
| 6593 | UnresolvedSet<8> ToDecls; |
| 6594 | for (Decl *D : E->decls()) { |
| 6595 | if (NamedDecl *To = cast_or_null<NamedDecl>(Importer.Import(D))) |
| 6596 | ToDecls.addDecl(To); |
| 6597 | else |
| 6598 | return nullptr; |
| 6599 | } |
| 6600 | |
| 6601 | TemplateArgumentListInfo ToTAInfo; |
| 6602 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 6603 | if (E->hasExplicitTemplateArgs()) { |
| 6604 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6605 | return nullptr; |
| 6606 | ResInfo = &ToTAInfo; |
| 6607 | } |
| 6608 | |
| 6609 | Expr *BaseE = E->isImplicitAccess() ? nullptr : Importer.Import(E->getBase()); |
| 6610 | if (!BaseE && !E->isImplicitAccess() && E->getBase()) { |
| 6611 | return nullptr; |
| 6612 | } |
| 6613 | |
| 6614 | return UnresolvedMemberExpr::Create( |
| 6615 | Importer.getToContext(), E->hasUnresolvedUsing(), BaseE, BaseType, |
| 6616 | E->isArrow(), Importer.Import(E->getOperatorLoc()), |
| 6617 | Importer.Import(E->getQualifierLoc()), |
| 6618 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, ResInfo, |
| 6619 | ToDecls.begin(), ToDecls.end()); |
| 6620 | } |
| 6621 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6622 | Expr *ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 6623 | QualType T = Importer.Import(E->getType()); |
| 6624 | if (T.isNull()) |
| 6625 | return nullptr; |
| 6626 | |
| 6627 | Expr *ToCallee = Importer.Import(E->getCallee()); |
| 6628 | if (!ToCallee && E->getCallee()) |
| 6629 | return nullptr; |
| 6630 | |
| 6631 | unsigned NumArgs = E->getNumArgs(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6632 | SmallVector<Expr *, 2> ToArgs(NumArgs); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6633 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
| 6634 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6635 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6636 | auto **ToArgs_Copied = new (Importer.getToContext()) Expr*[NumArgs]; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6637 | |
| 6638 | for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) |
| 6639 | ToArgs_Copied[ai] = ToArgs[ai]; |
| 6640 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6641 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| 6642 | return new (Importer.getToContext()) CXXOperatorCallExpr( |
| 6643 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, T, |
| 6644 | OCE->getValueKind(), Importer.Import(OCE->getRParenLoc()), |
| 6645 | OCE->getFPFeatures()); |
| 6646 | } |
| 6647 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6648 | return new (Importer.getToContext()) |
| 6649 | CallExpr(Importer.getToContext(), ToCallee, |
Craig Topper | c005cc0 | 2015-09-27 03:44:08 +0000 | [diff] [blame] | 6650 | llvm::makeArrayRef(ToArgs_Copied, NumArgs), T, E->getValueKind(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6651 | Importer.Import(E->getRParenLoc())); |
| 6652 | } |
| 6653 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6654 | Optional<LambdaCapture> |
| 6655 | ASTNodeImporter::ImportLambdaCapture(const LambdaCapture &From) { |
| 6656 | VarDecl *Var = nullptr; |
| 6657 | if (From.capturesVariable()) { |
| 6658 | Var = cast_or_null<VarDecl>(Importer.Import(From.getCapturedVar())); |
| 6659 | if (!Var) |
| 6660 | return None; |
| 6661 | } |
| 6662 | |
| 6663 | return LambdaCapture(Importer.Import(From.getLocation()), From.isImplicit(), |
| 6664 | From.getCaptureKind(), Var, |
| 6665 | From.isPackExpansion() |
| 6666 | ? Importer.Import(From.getEllipsisLoc()) |
| 6667 | : SourceLocation()); |
| 6668 | } |
| 6669 | |
| 6670 | Expr *ASTNodeImporter::VisitLambdaExpr(LambdaExpr *LE) { |
| 6671 | CXXRecordDecl *FromClass = LE->getLambdaClass(); |
| 6672 | auto *ToClass = dyn_cast_or_null<CXXRecordDecl>(Importer.Import(FromClass)); |
| 6673 | if (!ToClass) |
| 6674 | return nullptr; |
| 6675 | |
| 6676 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 6677 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 6678 | // manually. |
| 6679 | if (ToClass->isBeingDefined()) { |
| 6680 | for (auto FromField : FromClass->fields()) { |
| 6681 | auto *ToField = cast_or_null<FieldDecl>(Importer.Import(FromField)); |
| 6682 | if (!ToField) |
| 6683 | return nullptr; |
| 6684 | } |
| 6685 | } |
| 6686 | |
| 6687 | auto *ToCallOp = dyn_cast_or_null<CXXMethodDecl>( |
| 6688 | Importer.Import(LE->getCallOperator())); |
| 6689 | if (!ToCallOp) |
| 6690 | return nullptr; |
| 6691 | |
| 6692 | ToClass->completeDefinition(); |
| 6693 | |
| 6694 | unsigned NumCaptures = LE->capture_size(); |
| 6695 | SmallVector<LambdaCapture, 8> Captures; |
| 6696 | Captures.reserve(NumCaptures); |
| 6697 | for (const auto &FromCapture : LE->captures()) { |
| 6698 | if (auto ToCapture = ImportLambdaCapture(FromCapture)) |
| 6699 | Captures.push_back(*ToCapture); |
| 6700 | else |
| 6701 | return nullptr; |
| 6702 | } |
| 6703 | |
| 6704 | SmallVector<Expr *, 8> InitCaptures(NumCaptures); |
| 6705 | if (ImportContainerChecked(LE->capture_inits(), InitCaptures)) |
| 6706 | return nullptr; |
| 6707 | |
| 6708 | return LambdaExpr::Create(Importer.getToContext(), ToClass, |
| 6709 | Importer.Import(LE->getIntroducerRange()), |
| 6710 | LE->getCaptureDefault(), |
| 6711 | Importer.Import(LE->getCaptureDefaultLoc()), |
| 6712 | Captures, |
| 6713 | LE->hasExplicitParameters(), |
| 6714 | LE->hasExplicitResultType(), |
| 6715 | InitCaptures, |
| 6716 | Importer.Import(LE->getLocEnd()), |
| 6717 | LE->containsUnexpandedParameterPack()); |
| 6718 | } |
| 6719 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6720 | Expr *ASTNodeImporter::VisitInitListExpr(InitListExpr *ILE) { |
| 6721 | QualType T = Importer.Import(ILE->getType()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6722 | if (T.isNull()) |
| 6723 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6724 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6725 | SmallVector<Expr *, 4> Exprs(ILE->getNumInits()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6726 | if (ImportContainerChecked(ILE->inits(), Exprs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6727 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6728 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6729 | ASTContext &ToCtx = Importer.getToContext(); |
| 6730 | InitListExpr *To = new (ToCtx) InitListExpr( |
| 6731 | ToCtx, Importer.Import(ILE->getLBraceLoc()), |
| 6732 | Exprs, Importer.Import(ILE->getLBraceLoc())); |
| 6733 | To->setType(T); |
| 6734 | |
| 6735 | if (ILE->hasArrayFiller()) { |
| 6736 | Expr *Filler = Importer.Import(ILE->getArrayFiller()); |
| 6737 | if (!Filler) |
| 6738 | return nullptr; |
| 6739 | To->setArrayFiller(Filler); |
| 6740 | } |
| 6741 | |
| 6742 | if (FieldDecl *FromFD = ILE->getInitializedFieldInUnion()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6743 | auto *ToFD = cast_or_null<FieldDecl>(Importer.Import(FromFD)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6744 | if (!ToFD) |
| 6745 | return nullptr; |
| 6746 | To->setInitializedFieldInUnion(ToFD); |
| 6747 | } |
| 6748 | |
| 6749 | if (InitListExpr *SyntForm = ILE->getSyntacticForm()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6750 | auto *ToSyntForm = cast_or_null<InitListExpr>(Importer.Import(SyntForm)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6751 | if (!ToSyntForm) |
| 6752 | return nullptr; |
| 6753 | To->setSyntacticForm(ToSyntForm); |
| 6754 | } |
| 6755 | |
| 6756 | To->sawArrayRangeDesignator(ILE->hadArrayRangeDesignator()); |
| 6757 | To->setValueDependent(ILE->isValueDependent()); |
| 6758 | To->setInstantiationDependent(ILE->isInstantiationDependent()); |
| 6759 | |
| 6760 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6761 | } |
| 6762 | |
Gabor Marton | 07b01ff | 2018-06-29 12:17:34 +0000 | [diff] [blame] | 6763 | Expr *ASTNodeImporter::VisitCXXStdInitializerListExpr( |
| 6764 | CXXStdInitializerListExpr *E) { |
| 6765 | QualType T = Importer.Import(E->getType()); |
| 6766 | if (T.isNull()) |
| 6767 | return nullptr; |
| 6768 | |
| 6769 | Expr *SE = Importer.Import(E->getSubExpr()); |
| 6770 | if (!SE) |
| 6771 | return nullptr; |
| 6772 | |
| 6773 | return new (Importer.getToContext()) CXXStdInitializerListExpr(T, SE); |
| 6774 | } |
| 6775 | |
Balazs Keri | 95baa84 | 2018-07-25 10:21:06 +0000 | [diff] [blame^] | 6776 | Expr *ASTNodeImporter::VisitCXXInheritedCtorInitExpr( |
| 6777 | CXXInheritedCtorInitExpr *E) { |
| 6778 | QualType T = Importer.Import(E->getType()); |
| 6779 | if (T.isNull()) |
| 6780 | return nullptr; |
| 6781 | |
| 6782 | auto *Ctor = cast_or_null<CXXConstructorDecl>(Importer.Import( |
| 6783 | E->getConstructor())); |
| 6784 | if (!Ctor) |
| 6785 | return nullptr; |
| 6786 | |
| 6787 | return new (Importer.getToContext()) CXXInheritedCtorInitExpr( |
| 6788 | Importer.Import(E->getLocation()), T, Ctor, |
| 6789 | E->constructsVBase(), E->inheritedFromVBase()); |
| 6790 | } |
| 6791 | |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 6792 | Expr *ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 6793 | QualType ToType = Importer.Import(E->getType()); |
| 6794 | if (ToType.isNull()) |
| 6795 | return nullptr; |
| 6796 | |
| 6797 | Expr *ToCommon = Importer.Import(E->getCommonExpr()); |
| 6798 | if (!ToCommon && E->getCommonExpr()) |
| 6799 | return nullptr; |
| 6800 | |
| 6801 | Expr *ToSubExpr = Importer.Import(E->getSubExpr()); |
| 6802 | if (!ToSubExpr && E->getSubExpr()) |
| 6803 | return nullptr; |
| 6804 | |
| 6805 | return new (Importer.getToContext()) |
| 6806 | ArrayInitLoopExpr(ToType, ToCommon, ToSubExpr); |
| 6807 | } |
| 6808 | |
| 6809 | Expr *ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 6810 | QualType ToType = Importer.Import(E->getType()); |
| 6811 | if (ToType.isNull()) |
| 6812 | return nullptr; |
| 6813 | return new (Importer.getToContext()) ArrayInitIndexExpr(ToType); |
| 6814 | } |
| 6815 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6816 | Expr *ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6817 | auto *ToField = dyn_cast_or_null<FieldDecl>(Importer.Import(DIE->getField())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6818 | if (!ToField && DIE->getField()) |
| 6819 | return nullptr; |
| 6820 | |
| 6821 | return CXXDefaultInitExpr::Create( |
| 6822 | Importer.getToContext(), Importer.Import(DIE->getLocStart()), ToField); |
| 6823 | } |
| 6824 | |
| 6825 | Expr *ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 6826 | QualType ToType = Importer.Import(E->getType()); |
| 6827 | if (ToType.isNull() && !E->getType().isNull()) |
| 6828 | return nullptr; |
| 6829 | ExprValueKind VK = E->getValueKind(); |
| 6830 | CastKind CK = E->getCastKind(); |
| 6831 | Expr *ToOp = Importer.Import(E->getSubExpr()); |
| 6832 | if (!ToOp && E->getSubExpr()) |
| 6833 | return nullptr; |
| 6834 | CXXCastPath BasePath; |
| 6835 | if (ImportCastPath(E, BasePath)) |
| 6836 | return nullptr; |
| 6837 | TypeSourceInfo *ToWritten = Importer.Import(E->getTypeInfoAsWritten()); |
| 6838 | SourceLocation ToOperatorLoc = Importer.Import(E->getOperatorLoc()); |
| 6839 | SourceLocation ToRParenLoc = Importer.Import(E->getRParenLoc()); |
| 6840 | SourceRange ToAngleBrackets = Importer.Import(E->getAngleBrackets()); |
| 6841 | |
| 6842 | if (isa<CXXStaticCastExpr>(E)) { |
| 6843 | return CXXStaticCastExpr::Create( |
| 6844 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6845 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6846 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 6847 | return CXXDynamicCastExpr::Create( |
| 6848 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6849 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6850 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 6851 | return CXXReinterpretCastExpr::Create( |
| 6852 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6853 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6854 | } else { |
| 6855 | return nullptr; |
| 6856 | } |
| 6857 | } |
| 6858 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6859 | Expr *ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
| 6860 | SubstNonTypeTemplateParmExpr *E) { |
| 6861 | QualType T = Importer.Import(E->getType()); |
| 6862 | if (T.isNull()) |
| 6863 | return nullptr; |
| 6864 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6865 | auto *Param = cast_or_null<NonTypeTemplateParmDecl>( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6866 | Importer.Import(E->getParameter())); |
| 6867 | if (!Param) |
| 6868 | return nullptr; |
| 6869 | |
| 6870 | Expr *Replacement = Importer.Import(E->getReplacement()); |
| 6871 | if (!Replacement) |
| 6872 | return nullptr; |
| 6873 | |
| 6874 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
| 6875 | T, E->getValueKind(), Importer.Import(E->getExprLoc()), Param, |
| 6876 | Replacement); |
| 6877 | } |
| 6878 | |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 6879 | Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 6880 | QualType ToType = Importer.Import(E->getType()); |
| 6881 | if (ToType.isNull()) |
| 6882 | return nullptr; |
| 6883 | |
| 6884 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
| 6885 | if (ImportContainerChecked(E->getArgs(), ToArgs)) |
| 6886 | return nullptr; |
| 6887 | |
| 6888 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 6889 | // Value is always false. |
| 6890 | bool ToValue = false; |
| 6891 | if (!E->isValueDependent()) |
| 6892 | ToValue = E->getValue(); |
| 6893 | |
| 6894 | return TypeTraitExpr::Create( |
| 6895 | Importer.getToContext(), ToType, Importer.Import(E->getLocStart()), |
| 6896 | E->getTrait(), ToArgs, Importer.Import(E->getLocEnd()), ToValue); |
| 6897 | } |
| 6898 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6899 | Expr *ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 6900 | QualType ToType = Importer.Import(E->getType()); |
| 6901 | if (ToType.isNull()) |
| 6902 | return nullptr; |
| 6903 | |
| 6904 | if (E->isTypeOperand()) { |
| 6905 | TypeSourceInfo *TSI = Importer.Import(E->getTypeOperandSourceInfo()); |
| 6906 | if (!TSI) |
| 6907 | return nullptr; |
| 6908 | |
| 6909 | return new (Importer.getToContext()) |
| 6910 | CXXTypeidExpr(ToType, TSI, Importer.Import(E->getSourceRange())); |
| 6911 | } |
| 6912 | |
| 6913 | Expr *Op = Importer.Import(E->getExprOperand()); |
| 6914 | if (!Op) |
| 6915 | return nullptr; |
| 6916 | |
| 6917 | return new (Importer.getToContext()) |
| 6918 | CXXTypeidExpr(ToType, Op, Importer.Import(E->getSourceRange())); |
| 6919 | } |
| 6920 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 6921 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 6922 | CXXMethodDecl *FromMethod) { |
| 6923 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) |
| 6924 | ToMethod->addOverriddenMethod( |
| 6925 | cast<CXXMethodDecl>(Importer.Import(const_cast<CXXMethodDecl*>( |
| 6926 | FromOverriddenMethod)))); |
| 6927 | } |
| 6928 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6929 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6930 | ASTContext &FromContext, FileManager &FromFileManager, |
| 6931 | bool MinimalImport) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6932 | : ToContext(ToContext), FromContext(FromContext), |
| 6933 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| 6934 | Minimal(MinimalImport) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6935 | ImportedDecls[FromContext.getTranslationUnitDecl()] |
| 6936 | = ToContext.getTranslationUnitDecl(); |
| 6937 | } |
| 6938 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6939 | ASTImporter::~ASTImporter() = default; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6940 | |
| 6941 | QualType ASTImporter::Import(QualType FromT) { |
| 6942 | if (FromT.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6943 | return {}; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6944 | |
| 6945 | const Type *fromTy = FromT.getTypePtr(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6946 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6947 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6948 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
| 6949 | = ImportedTypes.find(fromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6950 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6951 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6952 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6953 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6954 | ASTNodeImporter Importer(*this); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6955 | QualType ToT = Importer.Visit(fromTy); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6956 | if (ToT.isNull()) |
| 6957 | return ToT; |
| 6958 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6959 | // Record the imported type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6960 | ImportedTypes[fromTy] = ToT.getTypePtr(); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6961 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6962 | return ToContext.getQualifiedType(ToT, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6963 | } |
| 6964 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6965 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 6966 | if (!FromTSI) |
| 6967 | return FromTSI; |
| 6968 | |
| 6969 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 6970 | // 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] | 6971 | QualType T = Import(FromTSI->getType()); |
| 6972 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6973 | return nullptr; |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 6974 | |
| 6975 | return ToContext.getTrivialTypeSourceInfo(T, |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6976 | Import(FromTSI->getTypeLoc().getLocStart())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6977 | } |
| 6978 | |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 6979 | Attr *ASTImporter::Import(const Attr *FromAttr) { |
| 6980 | Attr *ToAttr = FromAttr->clone(ToContext); |
| 6981 | ToAttr->setRange(Import(FromAttr->getRange())); |
| 6982 | return ToAttr; |
| 6983 | } |
| 6984 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6985 | Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) { |
| 6986 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
| 6987 | if (Pos != ImportedDecls.end()) { |
| 6988 | Decl *ToD = Pos->second; |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 6989 | // FIXME: move this call to ImportDeclParts(). |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6990 | ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD); |
| 6991 | return ToD; |
| 6992 | } else { |
| 6993 | return nullptr; |
| 6994 | } |
| 6995 | } |
| 6996 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6997 | Decl *ASTImporter::Import(Decl *FromD) { |
| 6998 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6999 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7000 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7001 | ASTNodeImporter Importer(*this); |
| 7002 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7003 | // Check whether we've already imported this declaration. |
| 7004 | Decl *ToD = GetAlreadyImportedOrNull(FromD); |
| 7005 | if (ToD) { |
| 7006 | // If FromD has some updated flags after last import, apply it |
| 7007 | updateFlags(FromD, ToD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7008 | return ToD; |
| 7009 | } |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7010 | |
| 7011 | // Import the type. |
| 7012 | ToD = Importer.Visit(FromD); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7013 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7014 | return nullptr; |
| 7015 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7016 | // Notify subclasses. |
| 7017 | Imported(FromD, ToD); |
| 7018 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7019 | return ToD; |
| 7020 | } |
| 7021 | |
| 7022 | DeclContext *ASTImporter::ImportContext(DeclContext *FromDC) { |
| 7023 | if (!FromDC) |
| 7024 | return FromDC; |
| 7025 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7026 | auto *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7027 | if (!ToDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7028 | return nullptr; |
| 7029 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7030 | // When we're using a record/enum/Objective-C class/protocol as a context, we |
| 7031 | // need it to have a definition. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7032 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 7033 | auto *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7034 | if (ToRecord->isCompleteDefinition()) { |
| 7035 | // Do nothing. |
| 7036 | } else if (FromRecord->isCompleteDefinition()) { |
| 7037 | ASTNodeImporter(*this).ImportDefinition(FromRecord, ToRecord, |
| 7038 | ASTNodeImporter::IDK_Basic); |
| 7039 | } else { |
| 7040 | CompleteDecl(ToRecord); |
| 7041 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7042 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 7043 | auto *FromEnum = cast<EnumDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7044 | if (ToEnum->isCompleteDefinition()) { |
| 7045 | // Do nothing. |
| 7046 | } else if (FromEnum->isCompleteDefinition()) { |
| 7047 | ASTNodeImporter(*this).ImportDefinition(FromEnum, ToEnum, |
| 7048 | ASTNodeImporter::IDK_Basic); |
| 7049 | } else { |
| 7050 | CompleteDecl(ToEnum); |
| 7051 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7052 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 7053 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7054 | if (ToClass->getDefinition()) { |
| 7055 | // Do nothing. |
| 7056 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
| 7057 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToClass, |
| 7058 | ASTNodeImporter::IDK_Basic); |
| 7059 | } else { |
| 7060 | CompleteDecl(ToClass); |
| 7061 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7062 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 7063 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7064 | if (ToProto->getDefinition()) { |
| 7065 | // Do nothing. |
| 7066 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
| 7067 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToProto, |
| 7068 | ASTNodeImporter::IDK_Basic); |
| 7069 | } else { |
| 7070 | CompleteDecl(ToProto); |
| 7071 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7072 | } |
| 7073 | |
| 7074 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7075 | } |
| 7076 | |
| 7077 | Expr *ASTImporter::Import(Expr *FromE) { |
| 7078 | if (!FromE) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7079 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7080 | |
| 7081 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); |
| 7082 | } |
| 7083 | |
| 7084 | Stmt *ASTImporter::Import(Stmt *FromS) { |
| 7085 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7086 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7087 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7088 | // Check whether we've already imported this declaration. |
| 7089 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 7090 | if (Pos != ImportedStmts.end()) |
| 7091 | return Pos->second; |
| 7092 | |
| 7093 | // Import the type |
| 7094 | ASTNodeImporter Importer(*this); |
| 7095 | Stmt *ToS = Importer.Visit(FromS); |
| 7096 | if (!ToS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7097 | return nullptr; |
| 7098 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 7099 | // Record the imported declaration. |
| 7100 | ImportedStmts[FromS] = ToS; |
| 7101 | return ToS; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7102 | } |
| 7103 | |
| 7104 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| 7105 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7106 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7107 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7108 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); |
| 7109 | |
| 7110 | switch (FromNNS->getKind()) { |
| 7111 | case NestedNameSpecifier::Identifier: |
| 7112 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { |
| 7113 | return NestedNameSpecifier::Create(ToContext, prefix, II); |
| 7114 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7115 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7116 | |
| 7117 | case NestedNameSpecifier::Namespace: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7118 | if (auto *NS = |
| 7119 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7120 | return NestedNameSpecifier::Create(ToContext, prefix, NS); |
| 7121 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7122 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7123 | |
| 7124 | case NestedNameSpecifier::NamespaceAlias: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7125 | if (auto *NSAD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7126 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7127 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); |
| 7128 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7129 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7130 | |
| 7131 | case NestedNameSpecifier::Global: |
| 7132 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 7133 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7134 | case NestedNameSpecifier::Super: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7135 | if (auto *RD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7136 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 7137 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); |
| 7138 | } |
| 7139 | return nullptr; |
| 7140 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7141 | case NestedNameSpecifier::TypeSpec: |
| 7142 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7143 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); |
| 7144 | if (!T.isNull()) { |
| 7145 | bool bTemplate = FromNNS->getKind() == |
| 7146 | NestedNameSpecifier::TypeSpecWithTemplate; |
| 7147 | return NestedNameSpecifier::Create(ToContext, prefix, |
| 7148 | bTemplate, T.getTypePtr()); |
| 7149 | } |
| 7150 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7151 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 7152 | } |
| 7153 | |
| 7154 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7155 | } |
| 7156 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 7157 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 7158 | // Copied from NestedNameSpecifier mostly. |
| 7159 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 7160 | NestedNameSpecifierLoc NNS = FromNNS; |
| 7161 | |
| 7162 | // Push each of the nested-name-specifiers's onto a stack for |
| 7163 | // serialization in reverse order. |
| 7164 | while (NNS) { |
| 7165 | NestedNames.push_back(NNS); |
| 7166 | NNS = NNS.getPrefix(); |
| 7167 | } |
| 7168 | |
| 7169 | NestedNameSpecifierLocBuilder Builder; |
| 7170 | |
| 7171 | while (!NestedNames.empty()) { |
| 7172 | NNS = NestedNames.pop_back_val(); |
| 7173 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); |
| 7174 | if (!Spec) |
| 7175 | return NestedNameSpecifierLoc(); |
| 7176 | |
| 7177 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| 7178 | switch (Kind) { |
| 7179 | case NestedNameSpecifier::Identifier: |
| 7180 | Builder.Extend(getToContext(), |
| 7181 | Spec->getAsIdentifier(), |
| 7182 | Import(NNS.getLocalBeginLoc()), |
| 7183 | Import(NNS.getLocalEndLoc())); |
| 7184 | break; |
| 7185 | |
| 7186 | case NestedNameSpecifier::Namespace: |
| 7187 | Builder.Extend(getToContext(), |
| 7188 | Spec->getAsNamespace(), |
| 7189 | Import(NNS.getLocalBeginLoc()), |
| 7190 | Import(NNS.getLocalEndLoc())); |
| 7191 | break; |
| 7192 | |
| 7193 | case NestedNameSpecifier::NamespaceAlias: |
| 7194 | Builder.Extend(getToContext(), |
| 7195 | Spec->getAsNamespaceAlias(), |
| 7196 | Import(NNS.getLocalBeginLoc()), |
| 7197 | Import(NNS.getLocalEndLoc())); |
| 7198 | break; |
| 7199 | |
| 7200 | case NestedNameSpecifier::TypeSpec: |
| 7201 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 7202 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| 7203 | QualType(Spec->getAsType(), 0)); |
| 7204 | Builder.Extend(getToContext(), |
| 7205 | Import(NNS.getLocalBeginLoc()), |
| 7206 | TSI->getTypeLoc(), |
| 7207 | Import(NNS.getLocalEndLoc())); |
| 7208 | break; |
| 7209 | } |
| 7210 | |
| 7211 | case NestedNameSpecifier::Global: |
| 7212 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); |
| 7213 | break; |
| 7214 | |
| 7215 | case NestedNameSpecifier::Super: { |
| 7216 | SourceRange ToRange = Import(NNS.getSourceRange()); |
| 7217 | Builder.MakeSuper(getToContext(), |
| 7218 | Spec->getAsRecordDecl(), |
| 7219 | ToRange.getBegin(), |
| 7220 | ToRange.getEnd()); |
| 7221 | } |
| 7222 | } |
| 7223 | } |
| 7224 | |
| 7225 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 7226 | } |
| 7227 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7228 | TemplateName ASTImporter::Import(TemplateName From) { |
| 7229 | switch (From.getKind()) { |
| 7230 | case TemplateName::Template: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7231 | if (auto *ToTemplate = |
| 7232 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7233 | return TemplateName(ToTemplate); |
| 7234 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7235 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7236 | |
| 7237 | case TemplateName::OverloadedTemplate: { |
| 7238 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 7239 | UnresolvedSet<2> ToTemplates; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7240 | for (auto *I : *FromStorage) { |
| 7241 | if (auto *To = cast_or_null<NamedDecl>(Import(I))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7242 | ToTemplates.addDecl(To); |
| 7243 | else |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7244 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7245 | } |
| 7246 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
| 7247 | ToTemplates.end()); |
| 7248 | } |
| 7249 | |
| 7250 | case TemplateName::QualifiedTemplate: { |
| 7251 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| 7252 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); |
| 7253 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7254 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7255 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7256 | if (auto *ToTemplate = |
| 7257 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7258 | return ToContext.getQualifiedTemplateName(Qualifier, |
| 7259 | QTN->hasTemplateKeyword(), |
| 7260 | ToTemplate); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7261 | |
| 7262 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7263 | } |
| 7264 | |
| 7265 | case TemplateName::DependentTemplate: { |
| 7266 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| 7267 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); |
| 7268 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7269 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7270 | |
| 7271 | if (DTN->isIdentifier()) { |
| 7272 | return ToContext.getDependentTemplateName(Qualifier, |
| 7273 | Import(DTN->getIdentifier())); |
| 7274 | } |
| 7275 | |
| 7276 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); |
| 7277 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7278 | |
| 7279 | case TemplateName::SubstTemplateTemplateParm: { |
| 7280 | SubstTemplateTemplateParmStorage *subst |
| 7281 | = From.getAsSubstTemplateTemplateParm(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7282 | auto *param = |
| 7283 | cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7284 | if (!param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7285 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7286 | |
| 7287 | TemplateName replacement = Import(subst->getReplacement()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7288 | if (replacement.isNull()) |
| 7289 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 7290 | |
| 7291 | return ToContext.getSubstTemplateTemplateParm(param, replacement); |
| 7292 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7293 | |
| 7294 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 7295 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 7296 | = From.getAsSubstTemplateTemplateParmPack(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7297 | auto *Param = |
| 7298 | cast_or_null<TemplateTemplateParmDecl>( |
| 7299 | Import(SubstPack->getParameterPack())); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7300 | if (!Param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7301 | return {}; |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7302 | |
| 7303 | ASTNodeImporter Importer(*this); |
| 7304 | TemplateArgument ArgPack |
| 7305 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 7306 | if (ArgPack.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7307 | return {}; |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7308 | |
| 7309 | return ToContext.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 7310 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7311 | } |
| 7312 | |
| 7313 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7314 | } |
| 7315 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7316 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { |
| 7317 | if (FromLoc.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7318 | return {}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7319 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7320 | SourceManager &FromSM = FromContext.getSourceManager(); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7321 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7322 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 7323 | FileID ToFileID = Import(Decomposed.first); |
| 7324 | if (ToFileID.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7325 | return {}; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7326 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 7327 | return ToSM.getComposedLoc(ToFileID, Decomposed.second); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7328 | } |
| 7329 | |
| 7330 | SourceRange ASTImporter::Import(SourceRange FromRange) { |
| 7331 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); |
| 7332 | } |
| 7333 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7334 | FileID ASTImporter::Import(FileID FromID) { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7335 | llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7336 | if (Pos != ImportedFileIDs.end()) |
| 7337 | return Pos->second; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7338 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7339 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 7340 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 7341 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7342 | |
| 7343 | // Map the FromID to the "to" source manager. |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7344 | FileID ToID; |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7345 | if (FromSLoc.isExpansion()) { |
| 7346 | const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion(); |
| 7347 | SourceLocation ToSpLoc = Import(FromEx.getSpellingLoc()); |
| 7348 | SourceLocation ToExLocS = Import(FromEx.getExpansionLocStart()); |
| 7349 | unsigned TokenLen = FromSM.getFileIDSize(FromID); |
| 7350 | SourceLocation MLoc; |
| 7351 | if (FromEx.isMacroArgExpansion()) { |
| 7352 | MLoc = ToSM.createMacroArgExpansionLoc(ToSpLoc, ToExLocS, TokenLen); |
| 7353 | } else { |
| 7354 | SourceLocation ToExLocE = Import(FromEx.getExpansionLocEnd()); |
| 7355 | MLoc = ToSM.createExpansionLoc(ToSpLoc, ToExLocS, ToExLocE, TokenLen, |
| 7356 | FromEx.isExpansionTokenRange()); |
| 7357 | } |
| 7358 | ToID = ToSM.getFileID(MLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7359 | } else { |
Rafael Stahl | 29f37fb | 2018-07-04 13:34:05 +0000 | [diff] [blame] | 7360 | // Include location of this file. |
| 7361 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| 7362 | |
| 7363 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
| 7364 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
| 7365 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 7366 | // disk again |
| 7367 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 7368 | // than mmap the files several times. |
| 7369 | const FileEntry *Entry = |
| 7370 | ToFileManager.getFile(Cache->OrigEntry->getName()); |
| 7371 | if (!Entry) |
| 7372 | return {}; |
| 7373 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, |
| 7374 | FromSLoc.getFile().getFileCharacteristic()); |
| 7375 | } else { |
| 7376 | // FIXME: We want to re-use the existing MemoryBuffer! |
| 7377 | const llvm::MemoryBuffer *FromBuf = |
| 7378 | Cache->getBuffer(FromContext.getDiagnostics(), FromSM); |
| 7379 | std::unique_ptr<llvm::MemoryBuffer> ToBuf = |
| 7380 | llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
| 7381 | FromBuf->getBufferIdentifier()); |
| 7382 | ToID = ToSM.createFileID(std::move(ToBuf), |
| 7383 | FromSLoc.getFile().getFileCharacteristic()); |
| 7384 | } |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7385 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7386 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 7387 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7388 | return ToID; |
| 7389 | } |
| 7390 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7391 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
| 7392 | Expr *ToExpr = Import(From->getInit()); |
| 7393 | if (!ToExpr && From->getInit()) |
| 7394 | return nullptr; |
| 7395 | |
| 7396 | if (From->isBaseInitializer()) { |
| 7397 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 7398 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 7399 | return nullptr; |
| 7400 | |
| 7401 | return new (ToContext) CXXCtorInitializer( |
| 7402 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), |
| 7403 | ToExpr, Import(From->getRParenLoc()), |
| 7404 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) |
| 7405 | : SourceLocation()); |
| 7406 | } else if (From->isMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7407 | auto *ToField = cast_or_null<FieldDecl>(Import(From->getMember())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7408 | if (!ToField && From->getMember()) |
| 7409 | return nullptr; |
| 7410 | |
| 7411 | return new (ToContext) CXXCtorInitializer( |
| 7412 | ToContext, ToField, Import(From->getMemberLocation()), |
| 7413 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 7414 | } else if (From->isIndirectMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7415 | auto *ToIField = cast_or_null<IndirectFieldDecl>( |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7416 | Import(From->getIndirectMember())); |
| 7417 | if (!ToIField && From->getIndirectMember()) |
| 7418 | return nullptr; |
| 7419 | |
| 7420 | return new (ToContext) CXXCtorInitializer( |
| 7421 | ToContext, ToIField, Import(From->getMemberLocation()), |
| 7422 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 7423 | } else if (From->isDelegatingInitializer()) { |
| 7424 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 7425 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 7426 | return nullptr; |
| 7427 | |
| 7428 | return new (ToContext) |
| 7429 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), |
| 7430 | ToExpr, Import(From->getRParenLoc())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7431 | } else { |
| 7432 | return nullptr; |
| 7433 | } |
| 7434 | } |
| 7435 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7436 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| 7437 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 7438 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 7439 | return Pos->second; |
| 7440 | |
| 7441 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| 7442 | Import(BaseSpec->getSourceRange()), |
| 7443 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 7444 | BaseSpec->getAccessSpecifierAsWritten(), |
| 7445 | Import(BaseSpec->getTypeSourceInfo()), |
| 7446 | Import(BaseSpec->getEllipsisLoc())); |
| 7447 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 7448 | return Imported; |
| 7449 | } |
| 7450 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7451 | void ASTImporter::ImportDefinition(Decl *From) { |
| 7452 | Decl *To = Import(From); |
| 7453 | if (!To) |
| 7454 | return; |
| 7455 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7456 | if (auto *FromDC = cast<DeclContext>(From)) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7457 | ASTNodeImporter Importer(*this); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7458 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7459 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7460 | if (!ToRecord->getDefinition()) { |
| 7461 | Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7462 | ASTNodeImporter::IDK_Everything); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7463 | return; |
| 7464 | } |
| 7465 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7466 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7467 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7468 | if (!ToEnum->getDefinition()) { |
| 7469 | Importer.ImportDefinition(cast<EnumDecl>(FromDC), ToEnum, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7470 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7471 | return; |
| 7472 | } |
| 7473 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7474 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7475 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7476 | if (!ToIFace->getDefinition()) { |
| 7477 | Importer.ImportDefinition(cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7478 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7479 | return; |
| 7480 | } |
| 7481 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7482 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7483 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7484 | if (!ToProto->getDefinition()) { |
| 7485 | Importer.ImportDefinition(cast<ObjCProtocolDecl>(FromDC), ToProto, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7486 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7487 | return; |
| 7488 | } |
| 7489 | } |
| 7490 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7491 | Importer.ImportDeclContext(FromDC, true); |
| 7492 | } |
| 7493 | } |
| 7494 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7495 | DeclarationName ASTImporter::Import(DeclarationName FromName) { |
| 7496 | if (!FromName) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7497 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7498 | |
| 7499 | switch (FromName.getNameKind()) { |
| 7500 | case DeclarationName::Identifier: |
| 7501 | return Import(FromName.getAsIdentifierInfo()); |
| 7502 | |
| 7503 | case DeclarationName::ObjCZeroArgSelector: |
| 7504 | case DeclarationName::ObjCOneArgSelector: |
| 7505 | case DeclarationName::ObjCMultiArgSelector: |
| 7506 | return Import(FromName.getObjCSelector()); |
| 7507 | |
| 7508 | case DeclarationName::CXXConstructorName: { |
| 7509 | QualType T = Import(FromName.getCXXNameType()); |
| 7510 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7511 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7512 | |
| 7513 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 7514 | ToContext.getCanonicalType(T)); |
| 7515 | } |
| 7516 | |
| 7517 | case DeclarationName::CXXDestructorName: { |
| 7518 | QualType T = Import(FromName.getCXXNameType()); |
| 7519 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7520 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7521 | |
| 7522 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 7523 | ToContext.getCanonicalType(T)); |
| 7524 | } |
| 7525 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7526 | case DeclarationName::CXXDeductionGuideName: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7527 | auto *Template = cast_or_null<TemplateDecl>( |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7528 | Import(FromName.getCXXDeductionGuideTemplate())); |
| 7529 | if (!Template) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7530 | return {}; |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7531 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); |
| 7532 | } |
| 7533 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7534 | case DeclarationName::CXXConversionFunctionName: { |
| 7535 | QualType T = Import(FromName.getCXXNameType()); |
| 7536 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7537 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7538 | |
| 7539 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 7540 | ToContext.getCanonicalType(T)); |
| 7541 | } |
| 7542 | |
| 7543 | case DeclarationName::CXXOperatorName: |
| 7544 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 7545 | FromName.getCXXOverloadedOperator()); |
| 7546 | |
| 7547 | case DeclarationName::CXXLiteralOperatorName: |
| 7548 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| 7549 | Import(FromName.getCXXLiteralIdentifier())); |
| 7550 | |
| 7551 | case DeclarationName::CXXUsingDirective: |
| 7552 | // FIXME: STATICS! |
| 7553 | return DeclarationName::getUsingDirectiveName(); |
| 7554 | } |
| 7555 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 7556 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7557 | } |
| 7558 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7559 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7560 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7561 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7562 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 7563 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 7564 | |
| 7565 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 7566 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 7567 | |
| 7568 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7569 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7570 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7571 | Selector ASTImporter::Import(Selector FromSel) { |
| 7572 | if (FromSel.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7573 | return {}; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7574 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 7575 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7576 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 7577 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 7578 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 7579 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 7580 | } |
| 7581 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7582 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 7583 | DeclContext *DC, |
| 7584 | unsigned IDNS, |
| 7585 | NamedDecl **Decls, |
| 7586 | unsigned NumDecls) { |
| 7587 | return Name; |
| 7588 | } |
| 7589 | |
| 7590 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 7591 | if (LastDiagFromFrom) |
| 7592 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 7593 | FromContext.getDiagnostics()); |
| 7594 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7595 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7596 | } |
| 7597 | |
| 7598 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 7599 | if (!LastDiagFromFrom) |
| 7600 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 7601 | ToContext.getDiagnostics()); |
| 7602 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7603 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7604 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7605 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7606 | void ASTImporter::CompleteDecl (Decl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7607 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7608 | if (!ID->getDefinition()) |
| 7609 | ID->startDefinition(); |
| 7610 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7611 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7612 | if (!PD->getDefinition()) |
| 7613 | PD->startDefinition(); |
| 7614 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7615 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7616 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 7617 | TD->startDefinition(); |
| 7618 | TD->setCompleteDefinition(true); |
| 7619 | } |
| 7620 | } |
| 7621 | else { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7622 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7623 | } |
| 7624 | } |
| 7625 | |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7626 | Decl *ASTImporter::MapImported(Decl *From, Decl *To) { |
| 7627 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From); |
| 7628 | assert((Pos == ImportedDecls.end() || Pos->second == To) && |
| 7629 | "Try to import an already imported Decl"); |
| 7630 | if (Pos != ImportedDecls.end()) |
| 7631 | return Pos->second; |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7632 | ImportedDecls[From] = To; |
| 7633 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 7634 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7635 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 7636 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 7637 | bool Complain) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7638 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7639 | = ImportedTypes.find(From.getTypePtr()); |
| 7640 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) |
| 7641 | return true; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 7642 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 7643 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
Gabor Marton | 26f72a9 | 2018-07-12 09:42:05 +0000 | [diff] [blame] | 7644 | getStructuralEquivalenceKind(*this), false, |
| 7645 | Complain); |
Gabor Marton | 950fb57 | 2018-07-17 12:39:27 +0000 | [diff] [blame] | 7646 | return Ctx.IsEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7647 | } |