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 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 74 | class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, QualType>, |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 75 | public DeclVisitor<ASTNodeImporter, Decl *>, |
| 76 | public StmtVisitor<ASTNodeImporter, Stmt *> { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 77 | ASTImporter &Importer; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 78 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 79 | public: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 80 | explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {} |
Gabor Marton | 344b099 | 2018-05-16 11:48:11 +0000 | [diff] [blame] | 81 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 82 | using TypeVisitor<ASTNodeImporter, QualType>::Visit; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 83 | using DeclVisitor<ASTNodeImporter, Decl *>::Visit; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 84 | using StmtVisitor<ASTNodeImporter, Stmt *>::Visit; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 85 | |
| 86 | // Importing types |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 87 | QualType VisitType(const Type *T); |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 88 | QualType VisitAtomicType(const AtomicType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 89 | QualType VisitBuiltinType(const BuiltinType *T); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 90 | QualType VisitDecayedType(const DecayedType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 91 | QualType VisitComplexType(const ComplexType *T); |
| 92 | QualType VisitPointerType(const PointerType *T); |
| 93 | QualType VisitBlockPointerType(const BlockPointerType *T); |
| 94 | QualType VisitLValueReferenceType(const LValueReferenceType *T); |
| 95 | QualType VisitRValueReferenceType(const RValueReferenceType *T); |
| 96 | QualType VisitMemberPointerType(const MemberPointerType *T); |
| 97 | QualType VisitConstantArrayType(const ConstantArrayType *T); |
| 98 | QualType VisitIncompleteArrayType(const IncompleteArrayType *T); |
| 99 | QualType VisitVariableArrayType(const VariableArrayType *T); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 100 | QualType VisitDependentSizedArrayType(const DependentSizedArrayType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 101 | // FIXME: DependentSizedExtVectorType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 102 | QualType VisitVectorType(const VectorType *T); |
| 103 | QualType VisitExtVectorType(const ExtVectorType *T); |
| 104 | QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T); |
| 105 | QualType VisitFunctionProtoType(const FunctionProtoType *T); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 106 | QualType VisitUnresolvedUsingType(const UnresolvedUsingType *T); |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 107 | QualType VisitParenType(const ParenType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 108 | QualType VisitTypedefType(const TypedefType *T); |
| 109 | QualType VisitTypeOfExprType(const TypeOfExprType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 110 | // FIXME: DependentTypeOfExprType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 111 | QualType VisitTypeOfType(const TypeOfType *T); |
| 112 | QualType VisitDecltypeType(const DecltypeType *T); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 113 | QualType VisitUnaryTransformType(const UnaryTransformType *T); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 114 | QualType VisitAutoType(const AutoType *T); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 115 | QualType VisitInjectedClassNameType(const InjectedClassNameType *T); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 116 | // FIXME: DependentDecltypeType |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 117 | QualType VisitRecordType(const RecordType *T); |
| 118 | QualType VisitEnumType(const EnumType *T); |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 119 | QualType VisitAttributedType(const AttributedType *T); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 120 | QualType VisitTemplateTypeParmType(const TemplateTypeParmType *T); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 121 | QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 122 | QualType VisitTemplateSpecializationType(const TemplateSpecializationType *T); |
| 123 | QualType VisitElaboratedType(const ElaboratedType *T); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 124 | QualType VisitDependentNameType(const DependentNameType *T); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 125 | QualType VisitPackExpansionType(const PackExpansionType *T); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 126 | QualType VisitDependentTemplateSpecializationType( |
| 127 | const DependentTemplateSpecializationType *T); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 128 | QualType VisitObjCInterfaceType(const ObjCInterfaceType *T); |
| 129 | QualType VisitObjCObjectType(const ObjCObjectType *T); |
| 130 | QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 131 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 132 | // Importing declarations |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 133 | bool ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 134 | DeclContext *&LexicalDC, DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 135 | NamedDecl *&ToD, SourceLocation &Loc); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 136 | void ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 137 | void ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 138 | DeclarationNameInfo& To); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 139 | void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 140 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 141 | bool ImportCastPath(CastExpr *E, CXXCastPath &Path); |
| 142 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 143 | using Designator = DesignatedInitExpr::Designator; |
| 144 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 145 | Designator ImportDesignator(const Designator &D); |
| 146 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 147 | Optional<LambdaCapture> ImportLambdaCapture(const LambdaCapture &From); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 148 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 149 | /// What we should import from the definition. |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 150 | enum ImportDefinitionKind { |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 151 | /// Import the default subset of the definition, which might be |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 152 | /// nothing (if minimal import is set) or might be everything (if minimal |
| 153 | /// import is not set). |
| 154 | IDK_Default, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 155 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 156 | /// Import everything. |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 157 | IDK_Everything, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 158 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 159 | /// Import only the bare bones needed to establish a valid |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 160 | /// DeclContext. |
| 161 | IDK_Basic |
| 162 | }; |
| 163 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 164 | bool shouldForceImportDeclContext(ImportDefinitionKind IDK) { |
| 165 | return IDK == IDK_Everything || |
| 166 | (IDK == IDK_Default && !Importer.isMinimalImport()); |
| 167 | } |
| 168 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 169 | bool ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 170 | ImportDefinitionKind Kind = IDK_Default); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 171 | bool ImportDefinition(VarDecl *From, VarDecl *To, |
| 172 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 173 | bool ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 174 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 175 | bool ImportDefinition(ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 176 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 177 | bool ImportDefinition(ObjCProtocolDecl *From, ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 178 | ImportDefinitionKind Kind = IDK_Default); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 179 | TemplateParameterList *ImportTemplateParameterList( |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 180 | TemplateParameterList *Params); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 181 | TemplateArgument ImportTemplateArgument(const TemplateArgument &From); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 182 | Optional<TemplateArgumentLoc> ImportTemplateArgumentLoc( |
| 183 | const TemplateArgumentLoc &TALoc); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 184 | bool ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 185 | unsigned NumFromArgs, |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 186 | SmallVectorImpl<TemplateArgument> &ToArgs); |
| 187 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 188 | template <typename InContainerTy> |
| 189 | bool ImportTemplateArgumentListInfo(const InContainerTy &Container, |
| 190 | TemplateArgumentListInfo &ToTAInfo); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 191 | |
| 192 | template<typename InContainerTy> |
| 193 | bool ImportTemplateArgumentListInfo(SourceLocation FromLAngleLoc, |
| 194 | SourceLocation FromRAngleLoc, |
| 195 | const InContainerTy &Container, |
| 196 | TemplateArgumentListInfo &Result); |
| 197 | |
| 198 | bool ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD); |
| 199 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 200 | bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, |
| 201 | bool Complain = true); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 202 | bool IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 203 | bool Complain = true); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 204 | bool IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToRecord); |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 205 | bool IsStructuralMatch(EnumConstantDecl *FromEC, EnumConstantDecl *ToEC); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 206 | bool IsStructuralMatch(FunctionTemplateDecl *From, |
| 207 | FunctionTemplateDecl *To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 208 | bool IsStructuralMatch(ClassTemplateDecl *From, ClassTemplateDecl *To); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 209 | bool IsStructuralMatch(VarTemplateDecl *From, VarTemplateDecl *To); |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 210 | Decl *VisitDecl(Decl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 211 | Decl *VisitEmptyDecl(EmptyDecl *D); |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 212 | Decl *VisitAccessSpecDecl(AccessSpecDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 213 | Decl *VisitStaticAssertDecl(StaticAssertDecl *D); |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 214 | Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 215 | Decl *VisitNamespaceDecl(NamespaceDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 216 | Decl *VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 217 | Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 218 | Decl *VisitTypedefDecl(TypedefDecl *D); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 219 | Decl *VisitTypeAliasDecl(TypeAliasDecl *D); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 220 | Decl *VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 221 | Decl *VisitLabelDecl(LabelDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 222 | Decl *VisitEnumDecl(EnumDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 223 | Decl *VisitRecordDecl(RecordDecl *D); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 224 | Decl *VisitEnumConstantDecl(EnumConstantDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 225 | Decl *VisitFunctionDecl(FunctionDecl *D); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 226 | Decl *VisitCXXMethodDecl(CXXMethodDecl *D); |
| 227 | Decl *VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 228 | Decl *VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 229 | Decl *VisitCXXConversionDecl(CXXConversionDecl *D); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 230 | Decl *VisitFieldDecl(FieldDecl *D); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 231 | Decl *VisitIndirectFieldDecl(IndirectFieldDecl *D); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 232 | Decl *VisitFriendDecl(FriendDecl *D); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 233 | Decl *VisitObjCIvarDecl(ObjCIvarDecl *D); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 234 | Decl *VisitVarDecl(VarDecl *D); |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 235 | Decl *VisitImplicitParamDecl(ImplicitParamDecl *D); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 236 | Decl *VisitParmVarDecl(ParmVarDecl *D); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 237 | Decl *VisitObjCMethodDecl(ObjCMethodDecl *D); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 238 | Decl *VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 239 | Decl *VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 240 | Decl *VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 241 | Decl *VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 242 | Decl *VisitUsingDecl(UsingDecl *D); |
| 243 | Decl *VisitUsingShadowDecl(UsingShadowDecl *D); |
| 244 | Decl *VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 245 | Decl *VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
| 246 | Decl *VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
| 247 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 248 | ObjCTypeParamList *ImportObjCTypeParamList(ObjCTypeParamList *list); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 249 | Decl *VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 250 | Decl *VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 251 | Decl *VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 252 | Decl *VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 253 | Decl *VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 254 | Decl *VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
| 255 | Decl *VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 256 | Decl *VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
| 257 | Decl *VisitClassTemplateDecl(ClassTemplateDecl *D); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 258 | Decl *VisitClassTemplateSpecializationDecl( |
| 259 | ClassTemplateSpecializationDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 260 | Decl *VisitVarTemplateDecl(VarTemplateDecl *D); |
| 261 | Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 262 | Decl *VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 263 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 264 | // Importing statements |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 265 | DeclGroupRef ImportDeclGroup(DeclGroupRef DG); |
| 266 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 267 | Stmt *VisitStmt(Stmt *S); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 268 | Stmt *VisitGCCAsmStmt(GCCAsmStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 269 | Stmt *VisitDeclStmt(DeclStmt *S); |
| 270 | Stmt *VisitNullStmt(NullStmt *S); |
| 271 | Stmt *VisitCompoundStmt(CompoundStmt *S); |
| 272 | Stmt *VisitCaseStmt(CaseStmt *S); |
| 273 | Stmt *VisitDefaultStmt(DefaultStmt *S); |
| 274 | Stmt *VisitLabelStmt(LabelStmt *S); |
| 275 | Stmt *VisitAttributedStmt(AttributedStmt *S); |
| 276 | Stmt *VisitIfStmt(IfStmt *S); |
| 277 | Stmt *VisitSwitchStmt(SwitchStmt *S); |
| 278 | Stmt *VisitWhileStmt(WhileStmt *S); |
| 279 | Stmt *VisitDoStmt(DoStmt *S); |
| 280 | Stmt *VisitForStmt(ForStmt *S); |
| 281 | Stmt *VisitGotoStmt(GotoStmt *S); |
| 282 | Stmt *VisitIndirectGotoStmt(IndirectGotoStmt *S); |
| 283 | Stmt *VisitContinueStmt(ContinueStmt *S); |
| 284 | Stmt *VisitBreakStmt(BreakStmt *S); |
| 285 | Stmt *VisitReturnStmt(ReturnStmt *S); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 286 | // FIXME: MSAsmStmt |
| 287 | // FIXME: SEHExceptStmt |
| 288 | // FIXME: SEHFinallyStmt |
| 289 | // FIXME: SEHTryStmt |
| 290 | // FIXME: SEHLeaveStmt |
| 291 | // FIXME: CapturedStmt |
| 292 | Stmt *VisitCXXCatchStmt(CXXCatchStmt *S); |
| 293 | Stmt *VisitCXXTryStmt(CXXTryStmt *S); |
| 294 | Stmt *VisitCXXForRangeStmt(CXXForRangeStmt *S); |
| 295 | // FIXME: MSDependentExistsStmt |
| 296 | Stmt *VisitObjCForCollectionStmt(ObjCForCollectionStmt *S); |
| 297 | Stmt *VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); |
| 298 | Stmt *VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S); |
| 299 | Stmt *VisitObjCAtTryStmt(ObjCAtTryStmt *S); |
| 300 | Stmt *VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); |
| 301 | Stmt *VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); |
| 302 | Stmt *VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 303 | |
| 304 | // Importing expressions |
| 305 | Expr *VisitExpr(Expr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 306 | Expr *VisitVAArgExpr(VAArgExpr *E); |
| 307 | Expr *VisitGNUNullExpr(GNUNullExpr *E); |
| 308 | Expr *VisitPredefinedExpr(PredefinedExpr *E); |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 309 | Expr *VisitDeclRefExpr(DeclRefExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 310 | Expr *VisitImplicitValueInitExpr(ImplicitValueInitExpr *ILE); |
| 311 | Expr *VisitDesignatedInitExpr(DesignatedInitExpr *E); |
| 312 | Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 313 | Expr *VisitIntegerLiteral(IntegerLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 314 | Expr *VisitFloatingLiteral(FloatingLiteral *E); |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 315 | Expr *VisitCharacterLiteral(CharacterLiteral *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 316 | Expr *VisitStringLiteral(StringLiteral *E); |
| 317 | Expr *VisitCompoundLiteralExpr(CompoundLiteralExpr *E); |
| 318 | Expr *VisitAtomicExpr(AtomicExpr *E); |
| 319 | Expr *VisitAddrLabelExpr(AddrLabelExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 320 | Expr *VisitParenExpr(ParenExpr *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 321 | Expr *VisitParenListExpr(ParenListExpr *E); |
| 322 | Expr *VisitStmtExpr(StmtExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 323 | Expr *VisitUnaryOperator(UnaryOperator *E); |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 324 | Expr *VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 325 | Expr *VisitBinaryOperator(BinaryOperator *E); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 326 | Expr *VisitConditionalOperator(ConditionalOperator *E); |
| 327 | Expr *VisitBinaryConditionalOperator(BinaryConditionalOperator *E); |
| 328 | Expr *VisitOpaqueValueExpr(OpaqueValueExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 329 | Expr *VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E); |
| 330 | Expr *VisitExpressionTraitExpr(ExpressionTraitExpr *E); |
| 331 | Expr *VisitArraySubscriptExpr(ArraySubscriptExpr *E); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 332 | Expr *VisitCompoundAssignOperator(CompoundAssignOperator *E); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 333 | Expr *VisitImplicitCastExpr(ImplicitCastExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 334 | Expr *VisitExplicitCastExpr(ExplicitCastExpr *E); |
| 335 | Expr *VisitOffsetOfExpr(OffsetOfExpr *OE); |
| 336 | Expr *VisitCXXThrowExpr(CXXThrowExpr *E); |
| 337 | Expr *VisitCXXNoexceptExpr(CXXNoexceptExpr *E); |
| 338 | Expr *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E); |
| 339 | Expr *VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E); |
| 340 | Expr *VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E); |
| 341 | Expr *VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE); |
| 342 | Expr *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 343 | Expr *VisitPackExpansionExpr(PackExpansionExpr *E); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 344 | Expr *VisitSizeOfPackExpr(SizeOfPackExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 345 | Expr *VisitCXXNewExpr(CXXNewExpr *CE); |
| 346 | Expr *VisitCXXDeleteExpr(CXXDeleteExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 347 | Expr *VisitCXXConstructExpr(CXXConstructExpr *E); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 348 | Expr *VisitCXXMemberCallExpr(CXXMemberCallExpr *E); |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 349 | Expr *VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 350 | Expr *VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 351 | Expr *VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *CE); |
| 352 | Expr *VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 353 | Expr *VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 354 | Expr *VisitExprWithCleanups(ExprWithCleanups *EWC); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 355 | Expr *VisitCXXThisExpr(CXXThisExpr *E); |
| 356 | Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 357 | Expr *VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 358 | Expr *VisitMemberExpr(MemberExpr *E); |
| 359 | Expr *VisitCallExpr(CallExpr *E); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 360 | Expr *VisitLambdaExpr(LambdaExpr *LE); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 361 | Expr *VisitInitListExpr(InitListExpr *E); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 362 | Expr *VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 363 | Expr *VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 364 | Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 365 | Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 366 | Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 367 | Expr *VisitTypeTraitExpr(TypeTraitExpr *E); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 368 | Expr *VisitCXXTypeidExpr(CXXTypeidExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 369 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 370 | template<typename IIter, typename OIter> |
| 371 | void ImportArray(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 372 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; |
| 373 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 374 | ASTImporter &ImporterRef = Importer; |
| 375 | std::transform(Ibegin, Iend, Obegin, |
| 376 | [&ImporterRef](ItemT From) -> ItemT { |
| 377 | return ImporterRef.Import(From); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 378 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | template<typename IIter, typename OIter> |
| 382 | bool ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 383 | using ItemT = typename std::remove_reference<decltype(**Obegin)>::type; |
| 384 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 385 | ASTImporter &ImporterRef = Importer; |
| 386 | bool Failed = false; |
| 387 | std::transform(Ibegin, Iend, Obegin, |
| 388 | [&ImporterRef, &Failed](ItemT *From) -> ItemT * { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 389 | auto *To = cast_or_null<ItemT>(ImporterRef.Import(From)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 390 | if (!To && From) |
| 391 | Failed = true; |
| 392 | return To; |
| 393 | }); |
| 394 | return Failed; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 395 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 396 | |
| 397 | template<typename InContainerTy, typename OutContainerTy> |
| 398 | bool ImportContainerChecked(const InContainerTy &InContainer, |
| 399 | OutContainerTy &OutContainer) { |
| 400 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), |
| 401 | OutContainer.begin()); |
| 402 | } |
| 403 | |
| 404 | template<typename InContainerTy, typename OIter> |
| 405 | bool ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
| 406 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 407 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 408 | |
| 409 | // Importing overrides. |
| 410 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 411 | }; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 412 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 413 | template <typename InContainerTy> |
| 414 | bool ASTNodeImporter::ImportTemplateArgumentListInfo( |
| 415 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 416 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
| 417 | TemplateArgumentListInfo ToTAInfo(Importer.Import(FromLAngleLoc), |
| 418 | Importer.Import(FromRAngleLoc)); |
| 419 | if (ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 420 | return true; |
| 421 | Result = ToTAInfo; |
| 422 | return false; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 423 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 424 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 425 | template <> |
| 426 | bool ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
| 427 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 428 | return ImportTemplateArgumentListInfo( |
| 429 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 430 | } |
| 431 | |
| 432 | template <> |
| 433 | bool ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 434 | ASTTemplateArgumentListInfo>(const ASTTemplateArgumentListInfo &From, |
| 435 | TemplateArgumentListInfo &Result) { |
| 436 | return ImportTemplateArgumentListInfo(From.LAngleLoc, From.RAngleLoc, |
| 437 | From.arguments(), Result); |
| 438 | } |
| 439 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 440 | } // namespace clang |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 441 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 442 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 443 | // Import Types |
| 444 | //---------------------------------------------------------------------------- |
| 445 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 446 | using namespace clang; |
| 447 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 448 | QualType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 449 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 450 | << T->getTypeClassName(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 451 | return {}; |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 454 | QualType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 455 | QualType UnderlyingType = Importer.Import(T->getValueType()); |
| 456 | if(UnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 457 | return {}; |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 458 | |
| 459 | return Importer.getToContext().getAtomicType(UnderlyingType); |
| 460 | } |
| 461 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 462 | QualType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 463 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 464 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 465 | case BuiltinType::Id: \ |
| 466 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 467 | #include "clang/Basic/OpenCLImageTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 468 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 469 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 470 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 471 | #include "clang/AST/BuiltinTypes.def" |
| 472 | |
| 473 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 474 | // context supports C++. |
| 475 | |
| 476 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 477 | // context supports ObjC. |
| 478 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 479 | case BuiltinType::Char_U: |
| 480 | // The context we're importing from has an unsigned 'char'. If we're |
| 481 | // importing into a context with a signed 'char', translate to |
| 482 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 483 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 484 | return Importer.getToContext().UnsignedCharTy; |
| 485 | |
| 486 | return Importer.getToContext().CharTy; |
| 487 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 488 | case BuiltinType::Char_S: |
| 489 | // The context we're importing from has an unsigned 'char'. If we're |
| 490 | // importing into a context with a signed 'char', translate to |
| 491 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 492 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 493 | return Importer.getToContext().SignedCharTy; |
| 494 | |
| 495 | return Importer.getToContext().CharTy; |
| 496 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 497 | case BuiltinType::WChar_S: |
| 498 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 499 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 500 | // wchar_t? |
| 501 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 502 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 503 | |
| 504 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 505 | } |
| 506 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 507 | QualType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 508 | QualType OrigT = Importer.Import(T->getOriginalType()); |
| 509 | if (OrigT.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 510 | return {}; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 511 | |
| 512 | return Importer.getToContext().getDecayedType(OrigT); |
| 513 | } |
| 514 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 515 | QualType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 516 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 517 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 518 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 519 | |
| 520 | return Importer.getToContext().getComplexType(ToElementType); |
| 521 | } |
| 522 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 523 | QualType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 524 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 525 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 526 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 527 | |
| 528 | return Importer.getToContext().getPointerType(ToPointeeType); |
| 529 | } |
| 530 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 531 | QualType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 532 | // FIXME: Check for blocks support in "to" context. |
| 533 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 534 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 535 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 536 | |
| 537 | return Importer.getToContext().getBlockPointerType(ToPointeeType); |
| 538 | } |
| 539 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 540 | QualType |
| 541 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 542 | // FIXME: Check for C++ support in "to" context. |
| 543 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 544 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 545 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 546 | |
| 547 | return Importer.getToContext().getLValueReferenceType(ToPointeeType); |
| 548 | } |
| 549 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 550 | QualType |
| 551 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 552 | // FIXME: Check for C++0x support in "to" context. |
| 553 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 554 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 555 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 556 | |
| 557 | return Importer.getToContext().getRValueReferenceType(ToPointeeType); |
| 558 | } |
| 559 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 560 | QualType ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 561 | // FIXME: Check for C++ support in "to" context. |
| 562 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 563 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 564 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 565 | |
| 566 | QualType ClassType = Importer.Import(QualType(T->getClass(), 0)); |
| 567 | return Importer.getToContext().getMemberPointerType(ToPointeeType, |
| 568 | ClassType.getTypePtr()); |
| 569 | } |
| 570 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 571 | QualType ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 572 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 573 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 574 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 575 | |
| 576 | return Importer.getToContext().getConstantArrayType(ToElementType, |
| 577 | T->getSize(), |
| 578 | T->getSizeModifier(), |
| 579 | T->getIndexTypeCVRQualifiers()); |
| 580 | } |
| 581 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 582 | QualType |
| 583 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 584 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 585 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 586 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 587 | |
| 588 | return Importer.getToContext().getIncompleteArrayType(ToElementType, |
| 589 | T->getSizeModifier(), |
| 590 | T->getIndexTypeCVRQualifiers()); |
| 591 | } |
| 592 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 593 | QualType ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 594 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 595 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 596 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 597 | |
| 598 | Expr *Size = Importer.Import(T->getSizeExpr()); |
| 599 | if (!Size) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 600 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 601 | |
| 602 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); |
| 603 | return Importer.getToContext().getVariableArrayType(ToElementType, Size, |
| 604 | T->getSizeModifier(), |
| 605 | T->getIndexTypeCVRQualifiers(), |
| 606 | Brackets); |
| 607 | } |
| 608 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 609 | QualType ASTNodeImporter::VisitDependentSizedArrayType( |
| 610 | const DependentSizedArrayType *T) { |
| 611 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 612 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 613 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 614 | |
| 615 | // SizeExpr may be null if size is not specified directly. |
| 616 | // For example, 'int a[]'. |
| 617 | Expr *Size = Importer.Import(T->getSizeExpr()); |
| 618 | if (!Size && T->getSizeExpr()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 619 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 620 | |
| 621 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); |
| 622 | return Importer.getToContext().getDependentSizedArrayType( |
| 623 | ToElementType, Size, T->getSizeModifier(), T->getIndexTypeCVRQualifiers(), |
| 624 | Brackets); |
| 625 | } |
| 626 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 627 | QualType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 628 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 629 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 630 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 631 | |
| 632 | return Importer.getToContext().getVectorType(ToElementType, |
| 633 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 634 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 635 | } |
| 636 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 637 | QualType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 638 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 639 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 640 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 641 | |
| 642 | return Importer.getToContext().getExtVectorType(ToElementType, |
| 643 | T->getNumElements()); |
| 644 | } |
| 645 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 646 | QualType |
| 647 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 648 | // FIXME: What happens if we're importing a function without a prototype |
| 649 | // into C++? Should we make it variadic? |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 650 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 651 | if (ToResultType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 652 | return {}; |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 653 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 654 | return Importer.getToContext().getFunctionNoProtoType(ToResultType, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 655 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 656 | } |
| 657 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 658 | QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 659 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 660 | if (ToResultType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 661 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 662 | |
| 663 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 664 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 665 | for (const auto &A : T->param_types()) { |
| 666 | QualType ArgType = Importer.Import(A); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 667 | if (ArgType.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 | ArgTypes.push_back(ArgType); |
| 670 | } |
| 671 | |
| 672 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 673 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 674 | for (const auto &E : T->exceptions()) { |
| 675 | QualType ExceptionType = Importer.Import(E); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 676 | if (ExceptionType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 677 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 678 | ExceptionTypes.push_back(ExceptionType); |
| 679 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 680 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 681 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 682 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 683 | |
| 684 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 685 | ToEPI.Variadic = FromEPI.Variadic; |
| 686 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 687 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 688 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 689 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 690 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
| 691 | ToEPI.ExceptionSpec.NoexceptExpr = |
| 692 | Importer.Import(FromEPI.ExceptionSpec.NoexceptExpr); |
| 693 | ToEPI.ExceptionSpec.SourceDecl = cast_or_null<FunctionDecl>( |
| 694 | Importer.Import(FromEPI.ExceptionSpec.SourceDecl)); |
| 695 | ToEPI.ExceptionSpec.SourceTemplate = cast_or_null<FunctionDecl>( |
| 696 | Importer.Import(FromEPI.ExceptionSpec.SourceTemplate)); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 697 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 698 | return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 699 | } |
| 700 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 701 | QualType ASTNodeImporter::VisitUnresolvedUsingType( |
| 702 | const UnresolvedUsingType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 703 | const auto *ToD = |
| 704 | cast_or_null<UnresolvedUsingTypenameDecl>(Importer.Import(T->getDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 705 | if (!ToD) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 706 | return {}; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 707 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 708 | auto *ToPrevD = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 709 | cast_or_null<UnresolvedUsingTypenameDecl>( |
| 710 | Importer.Import(T->getDecl()->getPreviousDecl())); |
| 711 | if (!ToPrevD && T->getDecl()->getPreviousDecl()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 712 | return {}; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 713 | |
| 714 | return Importer.getToContext().getTypeDeclType(ToD, ToPrevD); |
| 715 | } |
| 716 | |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 717 | QualType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 718 | QualType ToInnerType = Importer.Import(T->getInnerType()); |
| 719 | if (ToInnerType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 720 | return {}; |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 721 | |
| 722 | return Importer.getToContext().getParenType(ToInnerType); |
| 723 | } |
| 724 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 725 | QualType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 726 | auto *ToDecl = |
| 727 | dyn_cast_or_null<TypedefNameDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 728 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 729 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 730 | |
| 731 | return Importer.getToContext().getTypeDeclType(ToDecl); |
| 732 | } |
| 733 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 734 | QualType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 735 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 736 | if (!ToExpr) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 737 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 738 | |
| 739 | return Importer.getToContext().getTypeOfExprType(ToExpr); |
| 740 | } |
| 741 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 742 | QualType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 743 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 744 | if (ToUnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 745 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 746 | |
| 747 | return Importer.getToContext().getTypeOfType(ToUnderlyingType); |
| 748 | } |
| 749 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 750 | QualType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 751 | // FIXME: Make sure that the "to" context supports C++0x! |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 752 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 753 | if (!ToExpr) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 754 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 755 | |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 756 | QualType UnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 757 | if (UnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 758 | return {}; |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 759 | |
| 760 | return Importer.getToContext().getDecltypeType(ToExpr, UnderlyingType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 761 | } |
| 762 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 763 | QualType ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 764 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 765 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 766 | if (ToBaseType.isNull() || ToUnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 767 | return {}; |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 768 | |
| 769 | return Importer.getToContext().getUnaryTransformType(ToBaseType, |
| 770 | ToUnderlyingType, |
| 771 | T->getUTTKind()); |
| 772 | } |
| 773 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 774 | QualType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 775 | // FIXME: Make sure that the "to" context supports C++11! |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 776 | QualType FromDeduced = T->getDeducedType(); |
| 777 | QualType ToDeduced; |
| 778 | if (!FromDeduced.isNull()) { |
| 779 | ToDeduced = Importer.Import(FromDeduced); |
| 780 | if (ToDeduced.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 781 | return {}; |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 782 | } |
| 783 | |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 784 | return Importer.getToContext().getAutoType(ToDeduced, T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 785 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 786 | } |
| 787 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 788 | QualType ASTNodeImporter::VisitInjectedClassNameType( |
| 789 | const InjectedClassNameType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 790 | auto *D = cast_or_null<CXXRecordDecl>(Importer.Import(T->getDecl())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 791 | if (!D) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 792 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 793 | |
| 794 | QualType InjType = Importer.Import(T->getInjectedSpecializationType()); |
| 795 | if (InjType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 796 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 797 | |
| 798 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 799 | // See comments in InjectedClassNameType definition for details |
| 800 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 801 | enum { |
| 802 | TypeAlignmentInBits = 4, |
| 803 | TypeAlignment = 1 << TypeAlignmentInBits |
| 804 | }; |
| 805 | |
| 806 | return QualType(new (Importer.getToContext(), TypeAlignment) |
| 807 | InjectedClassNameType(D, InjType), 0); |
| 808 | } |
| 809 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 810 | QualType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 811 | auto *ToDecl = dyn_cast_or_null<RecordDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 812 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 813 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 814 | |
| 815 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 816 | } |
| 817 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 818 | QualType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 819 | auto *ToDecl = dyn_cast_or_null<EnumDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 820 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 821 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 822 | |
| 823 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 824 | } |
| 825 | |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 826 | QualType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 827 | QualType FromModifiedType = T->getModifiedType(); |
| 828 | QualType FromEquivalentType = T->getEquivalentType(); |
| 829 | QualType ToModifiedType; |
| 830 | QualType ToEquivalentType; |
| 831 | |
| 832 | if (!FromModifiedType.isNull()) { |
| 833 | ToModifiedType = Importer.Import(FromModifiedType); |
| 834 | if (ToModifiedType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 835 | return {}; |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 836 | } |
| 837 | if (!FromEquivalentType.isNull()) { |
| 838 | ToEquivalentType = Importer.Import(FromEquivalentType); |
| 839 | if (ToEquivalentType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 840 | return {}; |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
| 844 | ToModifiedType, ToEquivalentType); |
| 845 | } |
| 846 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 847 | QualType ASTNodeImporter::VisitTemplateTypeParmType( |
| 848 | const TemplateTypeParmType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 849 | auto *ParmDecl = |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 850 | cast_or_null<TemplateTypeParmDecl>(Importer.Import(T->getDecl())); |
| 851 | if (!ParmDecl && T->getDecl()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 852 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 853 | |
| 854 | return Importer.getToContext().getTemplateTypeParmType( |
| 855 | T->getDepth(), T->getIndex(), T->isParameterPack(), ParmDecl); |
| 856 | } |
| 857 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 858 | QualType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
| 859 | const SubstTemplateTypeParmType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 860 | const auto *Replaced = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 861 | cast_or_null<TemplateTypeParmType>(Importer.Import( |
| 862 | QualType(T->getReplacedParameter(), 0)).getTypePtr()); |
| 863 | if (!Replaced) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 864 | return {}; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 865 | |
| 866 | QualType Replacement = Importer.Import(T->getReplacementType()); |
| 867 | if (Replacement.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 868 | return {}; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 869 | Replacement = Replacement.getCanonicalType(); |
| 870 | |
| 871 | return Importer.getToContext().getSubstTemplateTypeParmType( |
| 872 | Replaced, Replacement); |
| 873 | } |
| 874 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 875 | QualType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 876 | const TemplateSpecializationType *T) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 877 | TemplateName ToTemplate = Importer.Import(T->getTemplateName()); |
| 878 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 879 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 880 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 881 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 882 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 883 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 884 | |
| 885 | QualType ToCanonType; |
| 886 | if (!QualType(T, 0).isCanonical()) { |
| 887 | QualType FromCanonType |
| 888 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
| 889 | ToCanonType =Importer.Import(FromCanonType); |
| 890 | if (ToCanonType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 891 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 892 | } |
| 893 | return Importer.getToContext().getTemplateSpecializationType(ToTemplate, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 894 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 895 | ToCanonType); |
| 896 | } |
| 897 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 898 | QualType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 899 | NestedNameSpecifier *ToQualifier = nullptr; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 900 | // Note: the qualifier in an ElaboratedType is optional. |
| 901 | if (T->getQualifier()) { |
| 902 | ToQualifier = Importer.Import(T->getQualifier()); |
| 903 | if (!ToQualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 904 | return {}; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 905 | } |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 906 | |
| 907 | QualType ToNamedType = Importer.Import(T->getNamedType()); |
| 908 | if (ToNamedType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 909 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 910 | |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 911 | TagDecl *OwnedTagDecl = |
| 912 | cast_or_null<TagDecl>(Importer.Import(T->getOwnedTagDecl())); |
| 913 | if (!OwnedTagDecl && T->getOwnedTagDecl()) |
| 914 | return {}; |
| 915 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 916 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 917 | ToQualifier, ToNamedType, |
| 918 | OwnedTagDecl); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 921 | QualType ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 922 | QualType Pattern = Importer.Import(T->getPattern()); |
| 923 | if (Pattern.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 924 | return {}; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 925 | |
| 926 | return Importer.getToContext().getPackExpansionType(Pattern, |
| 927 | T->getNumExpansions()); |
| 928 | } |
| 929 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 930 | QualType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
| 931 | const DependentTemplateSpecializationType *T) { |
| 932 | NestedNameSpecifier *Qualifier = Importer.Import(T->getQualifier()); |
| 933 | if (!Qualifier && T->getQualifier()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 934 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 935 | |
| 936 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
| 937 | if (!Name && T->getIdentifier()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 938 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 939 | |
| 940 | SmallVector<TemplateArgument, 2> ToPack; |
| 941 | ToPack.reserve(T->getNumArgs()); |
| 942 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToPack)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 943 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 944 | |
| 945 | return Importer.getToContext().getDependentTemplateSpecializationType( |
| 946 | T->getKeyword(), Qualifier, Name, ToPack); |
| 947 | } |
| 948 | |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 949 | QualType ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) { |
| 950 | NestedNameSpecifier *NNS = Importer.Import(T->getQualifier()); |
| 951 | if (!NNS && T->getQualifier()) |
| 952 | return QualType(); |
| 953 | |
| 954 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
| 955 | if (!Name && T->getIdentifier()) |
| 956 | return QualType(); |
| 957 | |
| 958 | QualType Canon = (T == T->getCanonicalTypeInternal().getTypePtr()) |
| 959 | ? QualType() |
| 960 | : Importer.Import(T->getCanonicalTypeInternal()); |
| 961 | if (!Canon.isNull()) |
| 962 | Canon = Canon.getCanonicalType(); |
| 963 | |
| 964 | return Importer.getToContext().getDependentNameType(T->getKeyword(), NNS, |
| 965 | Name, Canon); |
| 966 | } |
| 967 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 968 | QualType ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 969 | auto *Class = |
| 970 | dyn_cast_or_null<ObjCInterfaceDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 971 | if (!Class) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 972 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 973 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 974 | return Importer.getToContext().getObjCInterfaceType(Class); |
| 975 | } |
| 976 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 977 | QualType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 978 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 979 | if (ToBaseType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 980 | return {}; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 981 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 982 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 983 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 984 | QualType ImportedTypeArg = Importer.Import(TypeArg); |
| 985 | if (ImportedTypeArg.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 986 | return {}; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 987 | |
| 988 | TypeArgs.push_back(ImportedTypeArg); |
| 989 | } |
| 990 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 991 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 992 | for (auto *P : T->quals()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 993 | auto *Protocol = dyn_cast_or_null<ObjCProtocolDecl>(Importer.Import(P)); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 994 | if (!Protocol) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 995 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 996 | Protocols.push_back(Protocol); |
| 997 | } |
| 998 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 999 | return Importer.getToContext().getObjCObjectType(ToBaseType, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 1000 | Protocols, |
| 1001 | T->isKindOfTypeAsWritten()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 1004 | QualType |
| 1005 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1006 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 1007 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1008 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1009 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1010 | return Importer.getToContext().getObjCObjectPointerType(ToPointeeType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 1011 | } |
| 1012 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 1013 | //---------------------------------------------------------------------------- |
| 1014 | // Import Declarations |
| 1015 | //---------------------------------------------------------------------------- |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1016 | bool ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 1017 | DeclContext *&LexicalDC, |
| 1018 | DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1019 | NamedDecl *&ToD, |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1020 | SourceLocation &Loc) { |
| 1021 | // Import the context of this declaration. |
| 1022 | DC = Importer.ImportContext(D->getDeclContext()); |
| 1023 | if (!DC) |
| 1024 | return true; |
| 1025 | |
| 1026 | LexicalDC = DC; |
| 1027 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 1028 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 1029 | if (!LexicalDC) |
| 1030 | return true; |
| 1031 | } |
| 1032 | |
| 1033 | // Import the name of this declaration. |
| 1034 | Name = Importer.Import(D->getDeclName()); |
| 1035 | if (D->getDeclName() && !Name) |
| 1036 | return true; |
| 1037 | |
| 1038 | // Import the location of this declaration. |
| 1039 | Loc = Importer.Import(D->getLocation()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1040 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1041 | return false; |
| 1042 | } |
| 1043 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1044 | void ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
| 1045 | if (!FromD) |
| 1046 | return; |
| 1047 | |
| 1048 | if (!ToD) { |
| 1049 | ToD = Importer.Import(FromD); |
| 1050 | if (!ToD) |
| 1051 | return; |
| 1052 | } |
| 1053 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1054 | if (auto *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1055 | if (auto *ToRecord = cast_or_null<RecordDecl>(ToD)) { |
Sean Callanan | 19dfc93 | 2013-01-11 23:17:47 +0000 | [diff] [blame] | 1056 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && !ToRecord->getDefinition()) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1057 | ImportDefinition(FromRecord, ToRecord); |
| 1058 | } |
| 1059 | } |
| 1060 | return; |
| 1061 | } |
| 1062 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1063 | if (auto *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1064 | if (auto *ToEnum = cast_or_null<EnumDecl>(ToD)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1065 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
| 1066 | ImportDefinition(FromEnum, ToEnum); |
| 1067 | } |
| 1068 | } |
| 1069 | return; |
| 1070 | } |
| 1071 | } |
| 1072 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1073 | void |
| 1074 | ASTNodeImporter::ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 1075 | DeclarationNameInfo& To) { |
| 1076 | // NOTE: To.Name and To.Loc are already imported. |
| 1077 | // We only have to import To.LocInfo. |
| 1078 | switch (To.getName().getNameKind()) { |
| 1079 | case DeclarationName::Identifier: |
| 1080 | case DeclarationName::ObjCZeroArgSelector: |
| 1081 | case DeclarationName::ObjCOneArgSelector: |
| 1082 | case DeclarationName::ObjCMultiArgSelector: |
| 1083 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1084 | case DeclarationName::CXXDeductionGuideName: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1085 | return; |
| 1086 | |
| 1087 | case DeclarationName::CXXOperatorName: { |
| 1088 | SourceRange Range = From.getCXXOperatorNameRange(); |
| 1089 | To.setCXXOperatorNameRange(Importer.Import(Range)); |
| 1090 | return; |
| 1091 | } |
| 1092 | case DeclarationName::CXXLiteralOperatorName: { |
| 1093 | SourceLocation Loc = From.getCXXLiteralOperatorNameLoc(); |
| 1094 | To.setCXXLiteralOperatorNameLoc(Importer.Import(Loc)); |
| 1095 | return; |
| 1096 | } |
| 1097 | case DeclarationName::CXXConstructorName: |
| 1098 | case DeclarationName::CXXDestructorName: |
| 1099 | case DeclarationName::CXXConversionFunctionName: { |
| 1100 | TypeSourceInfo *FromTInfo = From.getNamedTypeInfo(); |
| 1101 | To.setNamedTypeInfo(Importer.Import(FromTInfo)); |
| 1102 | return; |
| 1103 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1104 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1105 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1108 | void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1109 | if (Importer.isMinimalImport() && !ForceImport) { |
Sean Callanan | 81d577c | 2011-07-22 23:46:03 +0000 | [diff] [blame] | 1110 | Importer.ImportContext(FromDC); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1111 | return; |
| 1112 | } |
| 1113 | |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 1114 | for (auto *From : FromDC->decls()) |
| 1115 | Importer.Import(From); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1118 | static void setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1119 | ASTImporter &Importer) { |
| 1120 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
| 1121 | auto *ToTypedef = |
| 1122 | cast_or_null<TypedefNameDecl>(Importer.Import(FromTypedef)); |
| 1123 | assert (ToTypedef && "Failed to import typedef of an anonymous structure"); |
| 1124 | |
| 1125 | To->setTypedefNameForAnonDecl(ToTypedef); |
| 1126 | } |
| 1127 | } |
| 1128 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1129 | bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1130 | ImportDefinitionKind Kind) { |
| 1131 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1132 | if (Kind == IDK_Everything) |
| 1133 | ImportDeclContext(From, /*ForceImport=*/true); |
| 1134 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1135 | return false; |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1136 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1137 | |
| 1138 | To->startDefinition(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1139 | |
| 1140 | setTypedefNameForAnonDecl(From, To, Importer); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1141 | |
| 1142 | // Add base classes. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1143 | if (auto *ToCXX = dyn_cast<CXXRecordDecl>(To)) { |
| 1144 | auto *FromCXX = cast<CXXRecordDecl>(From); |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1145 | |
| 1146 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1147 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 1148 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1149 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1150 | ToData.Aggregate = FromData.Aggregate; |
| 1151 | ToData.PlainOldData = FromData.PlainOldData; |
| 1152 | ToData.Empty = FromData.Empty; |
| 1153 | ToData.Polymorphic = FromData.Polymorphic; |
| 1154 | ToData.Abstract = FromData.Abstract; |
| 1155 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1156 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; |
| 1157 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; |
| 1158 | ToData.HasBasesWithNonStaticDataMembers = |
| 1159 | FromData.HasBasesWithNonStaticDataMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1160 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 1161 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 1162 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 1163 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1164 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1165 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1166 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1167 | ToData.HasUninitializedReferenceMember |
| 1168 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1169 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1170 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1171 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1172 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1173 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1174 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1175 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1176 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1177 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1178 | ToData.NeedOverloadResolutionForDestructor |
| 1179 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1180 | ToData.DefaultedCopyConstructorIsDeleted |
| 1181 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1182 | ToData.DefaultedMoveConstructorIsDeleted |
| 1183 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1184 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1185 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1186 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1187 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1188 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1189 | ToData.HasConstexprNonCopyMoveConstructor |
| 1190 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1191 | ToData.HasDefaultedDefaultConstructor |
| 1192 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1193 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1194 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1195 | ToData.HasConstexprDefaultConstructor |
| 1196 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1197 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1198 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1199 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1200 | ToData.UserProvidedDefaultConstructor |
| 1201 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1202 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1203 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1204 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1205 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1206 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1207 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1208 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1209 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1210 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1211 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1212 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1213 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1214 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1215 | for (const auto &Base1 : FromCXX->bases()) { |
| 1216 | QualType T = Importer.Import(Base1.getType()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1217 | if (T.isNull()) |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1218 | return true; |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1219 | |
| 1220 | SourceLocation EllipsisLoc; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1221 | if (Base1.isPackExpansion()) |
| 1222 | EllipsisLoc = Importer.Import(Base1.getEllipsisLoc()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1223 | |
| 1224 | // Ensure that we have a definition for the base. |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1225 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1226 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1227 | Bases.push_back( |
| 1228 | new (Importer.getToContext()) |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1229 | CXXBaseSpecifier(Importer.Import(Base1.getSourceRange()), |
| 1230 | Base1.isVirtual(), |
| 1231 | Base1.isBaseOfClass(), |
| 1232 | Base1.getAccessSpecifierAsWritten(), |
| 1233 | Importer.Import(Base1.getTypeSourceInfo()), |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1234 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1235 | } |
| 1236 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1237 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1240 | if (shouldForceImportDeclContext(Kind)) |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1241 | ImportDeclContext(From, /*ForceImport=*/true); |
| 1242 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1243 | To->completeDefinition(); |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1244 | return false; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1247 | bool ASTNodeImporter::ImportDefinition(VarDecl *From, VarDecl *To, |
| 1248 | ImportDefinitionKind Kind) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1249 | if (To->getAnyInitializer()) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1250 | return false; |
| 1251 | |
| 1252 | // FIXME: Can we really import any initializer? Alternatively, we could force |
| 1253 | // ourselves to import every declaration of a variable and then only use |
| 1254 | // getInit() here. |
| 1255 | To->setInit(Importer.Import(const_cast<Expr *>(From->getAnyInitializer()))); |
| 1256 | |
| 1257 | // FIXME: Other bits to merge? |
| 1258 | |
| 1259 | return false; |
| 1260 | } |
| 1261 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1262 | bool ASTNodeImporter::ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1263 | ImportDefinitionKind Kind) { |
| 1264 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1265 | if (Kind == IDK_Everything) |
| 1266 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1267 | return false; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1268 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1269 | |
| 1270 | To->startDefinition(); |
| 1271 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1272 | setTypedefNameForAnonDecl(From, To, Importer); |
| 1273 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1274 | QualType T = Importer.Import(Importer.getFromContext().getTypeDeclType(From)); |
| 1275 | if (T.isNull()) |
| 1276 | return true; |
| 1277 | |
| 1278 | QualType ToPromotionType = Importer.Import(From->getPromotionType()); |
| 1279 | if (ToPromotionType.isNull()) |
| 1280 | return true; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1281 | |
| 1282 | if (shouldForceImportDeclContext(Kind)) |
| 1283 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1284 | |
| 1285 | // FIXME: we might need to merge the number of positive or negative bits |
| 1286 | // if the enumerator lists don't match. |
| 1287 | To->completeDefinition(T, ToPromotionType, |
| 1288 | From->getNumPositiveBits(), |
| 1289 | From->getNumNegativeBits()); |
| 1290 | return false; |
| 1291 | } |
| 1292 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1293 | TemplateParameterList *ASTNodeImporter::ImportTemplateParameterList( |
| 1294 | TemplateParameterList *Params) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1295 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); |
| 1296 | if (ImportContainerChecked(*Params, ToParams)) |
| 1297 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1298 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1299 | Expr *ToRequiresClause; |
| 1300 | if (Expr *const R = Params->getRequiresClause()) { |
| 1301 | ToRequiresClause = Importer.Import(R); |
| 1302 | if (!ToRequiresClause) |
| 1303 | return nullptr; |
| 1304 | } else { |
| 1305 | ToRequiresClause = nullptr; |
| 1306 | } |
| 1307 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1308 | return TemplateParameterList::Create(Importer.getToContext(), |
| 1309 | Importer.Import(Params->getTemplateLoc()), |
| 1310 | Importer.Import(Params->getLAngleLoc()), |
David Majnemer | 902f8c6 | 2015-12-27 07:16:27 +0000 | [diff] [blame] | 1311 | ToParams, |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1312 | Importer.Import(Params->getRAngleLoc()), |
| 1313 | ToRequiresClause); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1314 | } |
| 1315 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1316 | TemplateArgument |
| 1317 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1318 | switch (From.getKind()) { |
| 1319 | case TemplateArgument::Null: |
| 1320 | return TemplateArgument(); |
| 1321 | |
| 1322 | case TemplateArgument::Type: { |
| 1323 | QualType ToType = Importer.Import(From.getAsType()); |
| 1324 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1325 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1326 | return TemplateArgument(ToType); |
| 1327 | } |
| 1328 | |
| 1329 | case TemplateArgument::Integral: { |
| 1330 | QualType ToType = Importer.Import(From.getIntegralType()); |
| 1331 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1332 | return {}; |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 1333 | return TemplateArgument(From, ToType); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1334 | } |
| 1335 | |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1336 | case TemplateArgument::Declaration: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1337 | auto *To = cast_or_null<ValueDecl>(Importer.Import(From.getAsDecl())); |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1338 | QualType ToType = Importer.Import(From.getParamTypeForDecl()); |
| 1339 | if (!To || ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1340 | return {}; |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1341 | return TemplateArgument(To, ToType); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | case TemplateArgument::NullPtr: { |
| 1345 | QualType ToType = Importer.Import(From.getNullPtrType()); |
| 1346 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1347 | return {}; |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1348 | return TemplateArgument(ToType, /*isNullPtr*/true); |
| 1349 | } |
| 1350 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1351 | case TemplateArgument::Template: { |
| 1352 | TemplateName ToTemplate = Importer.Import(From.getAsTemplate()); |
| 1353 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1354 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1355 | |
| 1356 | return TemplateArgument(ToTemplate); |
| 1357 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1358 | |
| 1359 | case TemplateArgument::TemplateExpansion: { |
| 1360 | TemplateName ToTemplate |
| 1361 | = Importer.Import(From.getAsTemplateOrTemplatePattern()); |
| 1362 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1363 | return {}; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1364 | |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 1365 | return TemplateArgument(ToTemplate, From.getNumTemplateExpansions()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1368 | case TemplateArgument::Expression: |
| 1369 | if (Expr *ToExpr = Importer.Import(From.getAsExpr())) |
| 1370 | return TemplateArgument(ToExpr); |
| 1371 | return TemplateArgument(); |
| 1372 | |
| 1373 | case TemplateArgument::Pack: { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1374 | SmallVector<TemplateArgument, 2> ToPack; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1375 | ToPack.reserve(From.pack_size()); |
| 1376 | if (ImportTemplateArguments(From.pack_begin(), From.pack_size(), ToPack)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1377 | return {}; |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 1378 | |
| 1379 | return TemplateArgument( |
| 1380 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | llvm_unreachable("Invalid template argument kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1385 | } |
| 1386 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1387 | Optional<TemplateArgumentLoc> |
| 1388 | ASTNodeImporter::ImportTemplateArgumentLoc(const TemplateArgumentLoc &TALoc) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1389 | TemplateArgument Arg = ImportTemplateArgument(TALoc.getArgument()); |
| 1390 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 1391 | TemplateArgumentLocInfo ToInfo; |
| 1392 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 1393 | Expr *E = Importer.Import(FromInfo.getAsExpr()); |
| 1394 | ToInfo = TemplateArgumentLocInfo(E); |
| 1395 | if (!E) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1396 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1397 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 1398 | if (TypeSourceInfo *TSI = Importer.Import(FromInfo.getAsTypeSourceInfo())) |
| 1399 | ToInfo = TemplateArgumentLocInfo(TSI); |
| 1400 | else |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1401 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1402 | } else { |
| 1403 | ToInfo = TemplateArgumentLocInfo( |
| 1404 | Importer.Import(FromInfo.getTemplateQualifierLoc()), |
| 1405 | Importer.Import(FromInfo.getTemplateNameLoc()), |
| 1406 | Importer.Import(FromInfo.getTemplateEllipsisLoc())); |
| 1407 | } |
| 1408 | return TemplateArgumentLoc(Arg, ToInfo); |
| 1409 | } |
| 1410 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1411 | bool ASTNodeImporter::ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 1412 | unsigned NumFromArgs, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1413 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1414 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
| 1415 | TemplateArgument To = ImportTemplateArgument(FromArgs[I]); |
| 1416 | if (To.isNull() && !FromArgs[I].isNull()) |
| 1417 | return true; |
| 1418 | |
| 1419 | ToArgs.push_back(To); |
| 1420 | } |
| 1421 | |
| 1422 | return false; |
| 1423 | } |
| 1424 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 1425 | // We cannot use Optional<> pattern here and below because |
| 1426 | // TemplateArgumentListInfo's operator new is declared as deleted so it cannot |
| 1427 | // be stored in Optional. |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1428 | template <typename InContainerTy> |
| 1429 | bool ASTNodeImporter::ImportTemplateArgumentListInfo( |
| 1430 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1431 | for (const auto &FromLoc : Container) { |
| 1432 | if (auto ToLoc = ImportTemplateArgumentLoc(FromLoc)) |
| 1433 | ToTAInfo.addArgument(*ToLoc); |
| 1434 | else |
| 1435 | return true; |
| 1436 | } |
| 1437 | return false; |
| 1438 | } |
| 1439 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1440 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1441 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1442 | // Eliminate a potential failure point where we attempt to re-import |
| 1443 | // something we're trying to import while completing ToRecord. |
| 1444 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1445 | if (ToOrigin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1446 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1447 | if (ToOriginRecord) |
| 1448 | ToRecord = ToOriginRecord; |
| 1449 | } |
| 1450 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1451 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1452 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1453 | Importer.getNonEquivalentDecls(), |
| 1454 | false, Complain); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1455 | return Ctx.IsStructurallyEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1458 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 1459 | bool Complain) { |
| 1460 | StructuralEquivalenceContext Ctx( |
| 1461 | Importer.getFromContext(), Importer.getToContext(), |
| 1462 | Importer.getNonEquivalentDecls(), false, Complain); |
| 1463 | return Ctx.IsStructurallyEquivalent(FromVar, ToVar); |
| 1464 | } |
| 1465 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1466 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1467 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1468 | Importer.getToContext(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1469 | Importer.getNonEquivalentDecls()); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1470 | return Ctx.IsStructurallyEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1473 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 1474 | FunctionTemplateDecl *To) { |
| 1475 | StructuralEquivalenceContext Ctx( |
| 1476 | Importer.getFromContext(), Importer.getToContext(), |
| 1477 | Importer.getNonEquivalentDecls(), false, false); |
| 1478 | return Ctx.IsStructurallyEquivalent(From, To); |
| 1479 | } |
| 1480 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1481 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1482 | EnumConstantDecl *ToEC) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1483 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 1484 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 1485 | |
| 1486 | return FromVal.isSigned() == ToVal.isSigned() && |
| 1487 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 1488 | FromVal == ToVal; |
| 1489 | } |
| 1490 | |
| 1491 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1492 | ClassTemplateDecl *To) { |
| 1493 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1494 | Importer.getToContext(), |
| 1495 | Importer.getNonEquivalentDecls()); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1496 | return Ctx.IsStructurallyEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1497 | } |
| 1498 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1499 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 1500 | VarTemplateDecl *To) { |
| 1501 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1502 | Importer.getToContext(), |
| 1503 | Importer.getNonEquivalentDecls()); |
| 1504 | return Ctx.IsStructurallyEquivalent(From, To); |
| 1505 | } |
| 1506 | |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1507 | Decl *ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 1508 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1509 | << D->getDeclKindName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1510 | return nullptr; |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1513 | Decl *ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 1514 | // Import the context of this declaration. |
| 1515 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1516 | if (!DC) |
| 1517 | return nullptr; |
| 1518 | |
| 1519 | DeclContext *LexicalDC = DC; |
| 1520 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 1521 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 1522 | if (!LexicalDC) |
| 1523 | return nullptr; |
| 1524 | } |
| 1525 | |
| 1526 | // Import the location of this declaration. |
| 1527 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1528 | |
| 1529 | EmptyDecl *ToD = EmptyDecl::Create(Importer.getToContext(), DC, Loc); |
| 1530 | ToD->setLexicalDeclContext(LexicalDC); |
| 1531 | Importer.Imported(D, ToD); |
| 1532 | LexicalDC->addDeclInternal(ToD); |
| 1533 | return ToD; |
| 1534 | } |
| 1535 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 1536 | Decl *ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 1537 | TranslationUnitDecl *ToD = |
| 1538 | Importer.getToContext().getTranslationUnitDecl(); |
| 1539 | |
| 1540 | Importer.Imported(D, ToD); |
| 1541 | |
| 1542 | return ToD; |
| 1543 | } |
| 1544 | |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1545 | Decl *ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1546 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1547 | SourceLocation ColonLoc = Importer.Import(D->getColonLoc()); |
| 1548 | |
| 1549 | // Import the context of this declaration. |
| 1550 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1551 | if (!DC) |
| 1552 | return nullptr; |
| 1553 | |
| 1554 | AccessSpecDecl *accessSpecDecl |
| 1555 | = AccessSpecDecl::Create(Importer.getToContext(), D->getAccess(), |
| 1556 | DC, Loc, ColonLoc); |
| 1557 | |
| 1558 | if (!accessSpecDecl) |
| 1559 | return nullptr; |
| 1560 | |
| 1561 | // Lexical DeclContext and Semantic DeclContext |
| 1562 | // is always the same for the accessSpec. |
| 1563 | accessSpecDecl->setLexicalDeclContext(DC); |
| 1564 | DC->addDeclInternal(accessSpecDecl); |
| 1565 | |
| 1566 | return accessSpecDecl; |
| 1567 | } |
| 1568 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1569 | Decl *ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 1570 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1571 | if (!DC) |
| 1572 | return nullptr; |
| 1573 | |
| 1574 | DeclContext *LexicalDC = DC; |
| 1575 | |
| 1576 | // Import the location of this declaration. |
| 1577 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1578 | |
| 1579 | Expr *AssertExpr = Importer.Import(D->getAssertExpr()); |
| 1580 | if (!AssertExpr) |
| 1581 | return nullptr; |
| 1582 | |
| 1583 | StringLiteral *FromMsg = D->getMessage(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1584 | auto *ToMsg = cast_or_null<StringLiteral>(Importer.Import(FromMsg)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1585 | if (!ToMsg && FromMsg) |
| 1586 | return nullptr; |
| 1587 | |
| 1588 | StaticAssertDecl *ToD = StaticAssertDecl::Create( |
| 1589 | Importer.getToContext(), DC, Loc, AssertExpr, ToMsg, |
| 1590 | Importer.Import(D->getRParenLoc()), D->isFailed()); |
| 1591 | |
| 1592 | ToD->setLexicalDeclContext(LexicalDC); |
| 1593 | LexicalDC->addDeclInternal(ToD); |
| 1594 | Importer.Imported(D, ToD); |
| 1595 | return ToD; |
| 1596 | } |
| 1597 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1598 | Decl *ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
| 1599 | // Import the major distinguishing characteristics of this namespace. |
| 1600 | DeclContext *DC, *LexicalDC; |
| 1601 | DeclarationName Name; |
| 1602 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1603 | NamedDecl *ToD; |
| 1604 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1605 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1606 | if (ToD) |
| 1607 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1608 | |
| 1609 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1610 | if (!Name) { |
| 1611 | // This is an anonymous namespace. Adopt an existing anonymous |
| 1612 | // namespace if we can. |
| 1613 | // FIXME: Not testable. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1614 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1615 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 1616 | else |
| 1617 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 1618 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1619 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1620 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1621 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1622 | for (auto *FoundDecl : FoundDecls) { |
| 1623 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1624 | continue; |
| 1625 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1626 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1627 | MergeWithNamespace = FoundNS; |
| 1628 | ConflictingDecls.clear(); |
| 1629 | break; |
| 1630 | } |
| 1631 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1632 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 1636 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1637 | ConflictingDecls.data(), |
| 1638 | ConflictingDecls.size()); |
| 1639 | } |
| 1640 | } |
| 1641 | |
| 1642 | // Create the "to" namespace, if needed. |
| 1643 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 1644 | if (!ToNamespace) { |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 1645 | ToNamespace = NamespaceDecl::Create(Importer.getToContext(), DC, |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1646 | D->isInline(), |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 1647 | Importer.Import(D->getLocStart()), |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1648 | Loc, Name.getAsIdentifierInfo(), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1649 | /*PrevDecl=*/nullptr); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1650 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1651 | LexicalDC->addDeclInternal(ToNamespace); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1652 | |
| 1653 | // If this is an anonymous namespace, register it as the anonymous |
| 1654 | // namespace within its context. |
| 1655 | if (!Name) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1656 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1657 | TU->setAnonymousNamespace(ToNamespace); |
| 1658 | else |
| 1659 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 1660 | } |
| 1661 | } |
| 1662 | Importer.Imported(D, ToNamespace); |
| 1663 | |
| 1664 | ImportDeclContext(D); |
| 1665 | |
| 1666 | return ToNamespace; |
| 1667 | } |
| 1668 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1669 | Decl *ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 1670 | // Import the major distinguishing characteristics of this namespace. |
| 1671 | DeclContext *DC, *LexicalDC; |
| 1672 | DeclarationName Name; |
| 1673 | SourceLocation Loc; |
| 1674 | NamedDecl *LookupD; |
| 1675 | if (ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 1676 | return nullptr; |
| 1677 | if (LookupD) |
| 1678 | return LookupD; |
| 1679 | |
| 1680 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 1681 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1682 | auto *TargetDecl = cast_or_null<NamespaceDecl>( |
| 1683 | Importer.Import(D->getNamespace())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1684 | if (!TargetDecl) |
| 1685 | return nullptr; |
| 1686 | |
| 1687 | IdentifierInfo *ToII = Importer.Import(D->getIdentifier()); |
| 1688 | if (!ToII) |
| 1689 | return nullptr; |
| 1690 | |
| 1691 | NestedNameSpecifierLoc ToQLoc = Importer.Import(D->getQualifierLoc()); |
| 1692 | if (D->getQualifierLoc() && !ToQLoc) |
| 1693 | return nullptr; |
| 1694 | |
| 1695 | NamespaceAliasDecl *ToD = NamespaceAliasDecl::Create( |
| 1696 | Importer.getToContext(), DC, Importer.Import(D->getNamespaceLoc()), |
| 1697 | Importer.Import(D->getAliasLoc()), ToII, ToQLoc, |
| 1698 | Importer.Import(D->getTargetNameLoc()), TargetDecl); |
| 1699 | |
| 1700 | ToD->setLexicalDeclContext(LexicalDC); |
| 1701 | Importer.Imported(D, ToD); |
| 1702 | LexicalDC->addDeclInternal(ToD); |
| 1703 | |
| 1704 | return ToD; |
| 1705 | } |
| 1706 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1707 | Decl *ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1708 | // Import the major distinguishing characteristics of this typedef. |
| 1709 | DeclContext *DC, *LexicalDC; |
| 1710 | DeclarationName Name; |
| 1711 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1712 | NamedDecl *ToD; |
| 1713 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1714 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1715 | if (ToD) |
| 1716 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1717 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1718 | // If this typedef is not in block scope, determine whether we've |
| 1719 | // seen a typedef with the same name (that we can merge with) or any |
| 1720 | // other entity by that name (which name lookup could conflict with). |
| 1721 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1722 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1723 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1724 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1725 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1726 | for (auto *FoundDecl : FoundDecls) { |
| 1727 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1728 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1729 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1730 | if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(), |
| 1731 | FoundTypedef->getUnderlyingType())) |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1732 | return Importer.Imported(D, FoundTypedef); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1733 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1734 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1735 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1736 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1737 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1738 | if (!ConflictingDecls.empty()) { |
| 1739 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1740 | ConflictingDecls.data(), |
| 1741 | ConflictingDecls.size()); |
| 1742 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1743 | return nullptr; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1744 | } |
| 1745 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1746 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1747 | // Import the underlying type of this typedef; |
| 1748 | QualType T = Importer.Import(D->getUnderlyingType()); |
| 1749 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1750 | return nullptr; |
| 1751 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1752 | // Some nodes (like anonymous tags referred by typedefs) are allowed to |
| 1753 | // import their enclosing typedef directly. Check if this is the case. |
| 1754 | if (Decl *AlreadyImported = Importer.GetAlreadyImportedOrNull(D)) |
| 1755 | return AlreadyImported; |
| 1756 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1757 | // Create the new typedef node. |
| 1758 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 1759 | SourceLocation StartL = Importer.Import(D->getLocStart()); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1760 | TypedefNameDecl *ToTypedef; |
| 1761 | if (IsAlias) |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1762 | ToTypedef = TypeAliasDecl::Create(Importer.getToContext(), DC, StartL, Loc, |
| 1763 | Name.getAsIdentifierInfo(), TInfo); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 1764 | else |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1765 | ToTypedef = TypedefDecl::Create(Importer.getToContext(), DC, |
| 1766 | StartL, Loc, |
| 1767 | Name.getAsIdentifierInfo(), |
| 1768 | TInfo); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1769 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1770 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1771 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1772 | Importer.Imported(D, ToTypedef); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1773 | |
| 1774 | // Templated declarations should not appear in DeclContext. |
| 1775 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 1776 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 1777 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1778 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1779 | return ToTypedef; |
| 1780 | } |
| 1781 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1782 | Decl *ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
| 1783 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 1784 | } |
| 1785 | |
| 1786 | Decl *ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| 1787 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 1788 | } |
| 1789 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1790 | Decl *ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| 1791 | // Import the major distinguishing characteristics of this typedef. |
| 1792 | DeclContext *DC, *LexicalDC; |
| 1793 | DeclarationName Name; |
| 1794 | SourceLocation Loc; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1795 | NamedDecl *FoundD; |
| 1796 | if (ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1797 | return nullptr; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1798 | if (FoundD) |
| 1799 | return FoundD; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1800 | |
| 1801 | // If this typedef is not in block scope, determine whether we've |
| 1802 | // seen a typedef with the same name (that we can merge with) or any |
| 1803 | // other entity by that name (which name lookup could conflict with). |
| 1804 | if (!DC->isFunctionOrMethod()) { |
| 1805 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 1806 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 1807 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 1808 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1809 | for (auto *FoundDecl : FoundDecls) { |
| 1810 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1811 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1812 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1813 | return Importer.Imported(D, FoundAlias); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1814 | ConflictingDecls.push_back(FoundDecl); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | if (!ConflictingDecls.empty()) { |
| 1818 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1819 | ConflictingDecls.data(), |
| 1820 | ConflictingDecls.size()); |
| 1821 | if (!Name) |
| 1822 | return nullptr; |
| 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | TemplateParameterList *Params = ImportTemplateParameterList( |
| 1827 | D->getTemplateParameters()); |
| 1828 | if (!Params) |
| 1829 | return nullptr; |
| 1830 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1831 | auto *TemplDecl = cast_or_null<TypeAliasDecl>( |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1832 | Importer.Import(D->getTemplatedDecl())); |
| 1833 | if (!TemplDecl) |
| 1834 | return nullptr; |
| 1835 | |
| 1836 | TypeAliasTemplateDecl *ToAlias = TypeAliasTemplateDecl::Create( |
| 1837 | Importer.getToContext(), DC, Loc, Name, Params, TemplDecl); |
| 1838 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1839 | TemplDecl->setDescribedAliasTemplate(ToAlias); |
| 1840 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1841 | ToAlias->setAccess(D->getAccess()); |
| 1842 | ToAlias->setLexicalDeclContext(LexicalDC); |
| 1843 | Importer.Imported(D, ToAlias); |
| 1844 | LexicalDC->addDeclInternal(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1845 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1846 | } |
| 1847 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1848 | Decl *ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
| 1849 | // Import the major distinguishing characteristics of this label. |
| 1850 | DeclContext *DC, *LexicalDC; |
| 1851 | DeclarationName Name; |
| 1852 | SourceLocation Loc; |
| 1853 | NamedDecl *ToD; |
| 1854 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 1855 | return nullptr; |
| 1856 | if (ToD) |
| 1857 | return ToD; |
| 1858 | |
| 1859 | assert(LexicalDC->isFunctionOrMethod()); |
| 1860 | |
| 1861 | LabelDecl *ToLabel = D->isGnuLocal() |
| 1862 | ? LabelDecl::Create(Importer.getToContext(), |
| 1863 | DC, Importer.Import(D->getLocation()), |
| 1864 | Name.getAsIdentifierInfo(), |
| 1865 | Importer.Import(D->getLocStart())) |
| 1866 | : LabelDecl::Create(Importer.getToContext(), |
| 1867 | DC, Importer.Import(D->getLocation()), |
| 1868 | Name.getAsIdentifierInfo()); |
| 1869 | Importer.Imported(D, ToLabel); |
| 1870 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1871 | auto *Label = cast_or_null<LabelStmt>(Importer.Import(D->getStmt())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1872 | if (!Label) |
| 1873 | return nullptr; |
| 1874 | |
| 1875 | ToLabel->setStmt(Label); |
| 1876 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 1877 | LexicalDC->addDeclInternal(ToLabel); |
| 1878 | return ToLabel; |
| 1879 | } |
| 1880 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1881 | Decl *ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
| 1882 | // Import the major distinguishing characteristics of this enum. |
| 1883 | DeclContext *DC, *LexicalDC; |
| 1884 | DeclarationName Name; |
| 1885 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1886 | NamedDecl *ToD; |
| 1887 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1888 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1889 | if (ToD) |
| 1890 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1891 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1892 | // Figure out what enum name we're looking for. |
| 1893 | unsigned IDNS = Decl::IDNS_Tag; |
| 1894 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1895 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 1896 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1897 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1898 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1899 | IDNS |= Decl::IDNS_Ordinary; |
| 1900 | |
| 1901 | // We may already have an enum of the same name; try to find and match it. |
| 1902 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1903 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1904 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 1905 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1906 | for (auto *FoundDecl : FoundDecls) { |
| 1907 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1908 | continue; |
| 1909 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1910 | Decl *Found = FoundDecl; |
| 1911 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 1912 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1913 | Found = Tag->getDecl(); |
| 1914 | } |
| 1915 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1916 | if (auto *FoundEnum = dyn_cast<EnumDecl>(Found)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1917 | if (IsStructuralMatch(D, FoundEnum)) |
| 1918 | return Importer.Imported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1919 | } |
| 1920 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1921 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | if (!ConflictingDecls.empty()) { |
| 1925 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1926 | ConflictingDecls.data(), |
| 1927 | ConflictingDecls.size()); |
| 1928 | } |
| 1929 | } |
| 1930 | |
| 1931 | // Create the enum declaration. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 1932 | EnumDecl *D2 = EnumDecl::Create(Importer.getToContext(), DC, |
| 1933 | Importer.Import(D->getLocStart()), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1934 | Loc, Name.getAsIdentifierInfo(), nullptr, |
Abramo Bagnara | 0e05e24 | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 1935 | D->isScoped(), D->isScopedUsingClassTag(), |
| 1936 | D->isFixed()); |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 1937 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 1938 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1939 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1940 | D2->setLexicalDeclContext(LexicalDC); |
| 1941 | Importer.Imported(D, D2); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1942 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1943 | |
| 1944 | // Import the integer type. |
| 1945 | QualType ToIntegerType = Importer.Import(D->getIntegerType()); |
| 1946 | if (ToIntegerType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1947 | return nullptr; |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1948 | D2->setIntegerType(ToIntegerType); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1949 | |
| 1950 | // Import the definition |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 1951 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1952 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1953 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1954 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1955 | } |
| 1956 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1957 | Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
| 1958 | // If this record has a definition in the translation unit we're coming from, |
| 1959 | // but this particular declaration is not that definition, import the |
| 1960 | // definition and map to that. |
Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 1961 | TagDecl *Definition = D->getDefinition(); |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame^] | 1962 | if (Definition && Definition != D && |
| 1963 | // In contrast to a normal CXXRecordDecl, the implicit |
| 1964 | // CXXRecordDecl of ClassTemplateSpecializationDecl is its redeclaration. |
| 1965 | // The definition of the implicit CXXRecordDecl in this case is the |
| 1966 | // ClassTemplateSpecializationDecl itself. Thus, we start with an extra |
| 1967 | // condition in order to be able to import the implict Decl. |
| 1968 | !D->isImplicit()) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1969 | Decl *ImportedDef = Importer.Import(Definition); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1970 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1971 | return nullptr; |
| 1972 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1973 | return Importer.Imported(D, ImportedDef); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1974 | } |
Gabor Marton | a3af567 | 2018-05-23 14:24:02 +0000 | [diff] [blame^] | 1975 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1976 | // Import the major distinguishing characteristics of this record. |
| 1977 | DeclContext *DC, *LexicalDC; |
| 1978 | DeclarationName Name; |
| 1979 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1980 | NamedDecl *ToD; |
| 1981 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1982 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1983 | if (ToD) |
| 1984 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1985 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1986 | // Figure out what structure name we're looking for. |
| 1987 | unsigned IDNS = Decl::IDNS_Tag; |
| 1988 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1989 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 1990 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1991 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1992 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1993 | IDNS |= Decl::IDNS_Ordinary; |
| 1994 | |
| 1995 | // 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] | 1996 | RecordDecl *AdoptDecl = nullptr; |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 1997 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1998 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1999 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2000 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 2001 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2002 | |
| 2003 | if (!FoundDecls.empty()) { |
| 2004 | // We're going to have to compare D against potentially conflicting Decls, so complete it. |
| 2005 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 2006 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2007 | } |
| 2008 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2009 | for (auto *FoundDecl : FoundDecls) { |
| 2010 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2011 | continue; |
| 2012 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2013 | Decl *Found = FoundDecl; |
| 2014 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 2015 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2016 | Found = Tag->getDecl(); |
| 2017 | } |
| 2018 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2019 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Aleksei Sidorin | 499de6c | 2018-04-05 15:31:49 +0000 | [diff] [blame] | 2020 | if (!SearchName) { |
| 2021 | // If both unnamed structs/unions are in a record context, make sure |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2022 | // they occur in the same location in the context records. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2023 | if (Optional<unsigned> Index1 = |
| 2024 | StructuralEquivalenceContext::findUntaggedStructOrUnionIndex( |
| 2025 | D)) { |
| 2026 | if (Optional<unsigned> Index2 = StructuralEquivalenceContext:: |
Sean Callanan | 488f861 | 2016-07-14 19:53:44 +0000 | [diff] [blame] | 2027 | findUntaggedStructOrUnionIndex(FoundRecord)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2028 | if (*Index1 != *Index2) |
| 2029 | continue; |
| 2030 | } |
| 2031 | } |
| 2032 | } |
| 2033 | |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2034 | PrevDecl = FoundRecord; |
| 2035 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2036 | if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2037 | if ((SearchName && !D->isCompleteDefinition()) |
| 2038 | || (D->isCompleteDefinition() && |
| 2039 | D->isAnonymousStructOrUnion() |
| 2040 | == FoundDef->isAnonymousStructOrUnion() && |
| 2041 | IsStructuralMatch(D, FoundDef))) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2042 | // The record types structurally match, or the "from" translation |
| 2043 | // unit only had a forward declaration anyway; call it the same |
| 2044 | // function. |
| 2045 | // FIXME: For C++, we should also merge methods here. |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2046 | return Importer.Imported(D, FoundDef); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2047 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2048 | } else if (!D->isCompleteDefinition()) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2049 | // We have a forward declaration of this type, so adopt that forward |
| 2050 | // declaration rather than building a new one. |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2051 | |
| 2052 | // If one or both can be completed from external storage then try one |
| 2053 | // last time to complete and compare them before doing this. |
| 2054 | |
| 2055 | if (FoundRecord->hasExternalLexicalStorage() && |
| 2056 | !FoundRecord->isCompleteDefinition()) |
| 2057 | FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord); |
| 2058 | if (D->hasExternalLexicalStorage()) |
| 2059 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2060 | |
| 2061 | if (FoundRecord->isCompleteDefinition() && |
| 2062 | D->isCompleteDefinition() && |
| 2063 | !IsStructuralMatch(D, FoundRecord)) |
| 2064 | continue; |
| 2065 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2066 | AdoptDecl = FoundRecord; |
| 2067 | continue; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2068 | } else if (!SearchName) { |
| 2069 | continue; |
| 2070 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2071 | } |
| 2072 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2073 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2074 | } |
| 2075 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2076 | if (!ConflictingDecls.empty() && SearchName) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2077 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2078 | ConflictingDecls.data(), |
| 2079 | ConflictingDecls.size()); |
| 2080 | } |
| 2081 | } |
| 2082 | |
| 2083 | // Create the record declaration. |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2084 | RecordDecl *D2 = AdoptDecl; |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 2085 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2086 | if (!D2) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2087 | CXXRecordDecl *D2CXX = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2088 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2089 | if (DCXX->isLambda()) { |
| 2090 | TypeSourceInfo *TInfo = Importer.Import(DCXX->getLambdaTypeInfo()); |
| 2091 | D2CXX = CXXRecordDecl::CreateLambda(Importer.getToContext(), |
| 2092 | DC, TInfo, Loc, |
| 2093 | DCXX->isDependentLambda(), |
| 2094 | DCXX->isGenericLambda(), |
| 2095 | DCXX->getLambdaCaptureDefault()); |
| 2096 | Decl *CDecl = Importer.Import(DCXX->getLambdaContextDecl()); |
| 2097 | if (DCXX->getLambdaContextDecl() && !CDecl) |
| 2098 | return nullptr; |
Sean Callanan | 041cceb | 2016-05-14 05:43:57 +0000 | [diff] [blame] | 2099 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), CDecl); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2100 | } else if (DCXX->isInjectedClassName()) { |
| 2101 | // We have to be careful to do a similar dance to the one in |
| 2102 | // Sema::ActOnStartCXXMemberDeclarations |
| 2103 | CXXRecordDecl *const PrevDecl = nullptr; |
| 2104 | const bool DelayTypeCreation = true; |
| 2105 | D2CXX = CXXRecordDecl::Create( |
| 2106 | Importer.getToContext(), D->getTagKind(), DC, StartLoc, Loc, |
| 2107 | Name.getAsIdentifierInfo(), PrevDecl, DelayTypeCreation); |
| 2108 | Importer.getToContext().getTypeDeclType( |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2109 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2110 | } else { |
| 2111 | D2CXX = CXXRecordDecl::Create(Importer.getToContext(), |
| 2112 | D->getTagKind(), |
| 2113 | DC, StartLoc, Loc, |
| 2114 | Name.getAsIdentifierInfo()); |
| 2115 | } |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2116 | D2 = D2CXX; |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2117 | D2->setAccess(D->getAccess()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2118 | D2->setLexicalDeclContext(LexicalDC); |
Gabor Marton | de8bf26 | 2018-05-17 09:46:07 +0000 | [diff] [blame] | 2119 | if (!DCXX->getDescribedClassTemplate() || DCXX->isImplicit()) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2120 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2121 | |
| 2122 | Importer.Imported(D, D2); |
| 2123 | |
| 2124 | if (ClassTemplateDecl *FromDescribed = |
| 2125 | DCXX->getDescribedClassTemplate()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2126 | auto *ToDescribed = cast_or_null<ClassTemplateDecl>( |
| 2127 | Importer.Import(FromDescribed)); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2128 | if (!ToDescribed) |
| 2129 | return nullptr; |
| 2130 | D2CXX->setDescribedClassTemplate(ToDescribed); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2131 | } else if (MemberSpecializationInfo *MemberInfo = |
| 2132 | DCXX->getMemberSpecializationInfo()) { |
| 2133 | TemplateSpecializationKind SK = |
| 2134 | MemberInfo->getTemplateSpecializationKind(); |
| 2135 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2136 | auto *ToInst = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2137 | cast_or_null<CXXRecordDecl>(Importer.Import(FromInst)); |
| 2138 | if (FromInst && !ToInst) |
| 2139 | return nullptr; |
| 2140 | D2CXX->setInstantiationOfMemberClass(ToInst, SK); |
| 2141 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2142 | Importer.Import(MemberInfo->getPointOfInstantiation())); |
| 2143 | } |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2144 | } else { |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2145 | D2 = RecordDecl::Create(Importer.getToContext(), D->getTagKind(), |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 2146 | DC, StartLoc, Loc, Name.getAsIdentifierInfo()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2147 | D2->setLexicalDeclContext(LexicalDC); |
| 2148 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2149 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2150 | |
| 2151 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2152 | if (D->isAnonymousStructOrUnion()) |
| 2153 | D2->setAnonymousStructOrUnion(true); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2154 | if (PrevDecl) { |
| 2155 | // FIXME: do this for all Redeclarables, not just RecordDecls. |
| 2156 | D2->setPreviousDecl(PrevDecl); |
| 2157 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2158 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2159 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2160 | Importer.Imported(D, D2); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2161 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 2162 | if (D->isCompleteDefinition() && ImportDefinition(D, D2, IDK_Default)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2163 | return nullptr; |
| 2164 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2165 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2166 | } |
| 2167 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2168 | Decl *ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| 2169 | // Import the major distinguishing characteristics of this enumerator. |
| 2170 | DeclContext *DC, *LexicalDC; |
| 2171 | DeclarationName Name; |
| 2172 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2173 | NamedDecl *ToD; |
| 2174 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2175 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2176 | if (ToD) |
| 2177 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2178 | |
| 2179 | QualType T = Importer.Import(D->getType()); |
| 2180 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2181 | return nullptr; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2182 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2183 | // Determine whether there are any other declarations with the same name and |
| 2184 | // in the same context. |
| 2185 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2186 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2187 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2188 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2189 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2190 | for (auto *FoundDecl : FoundDecls) { |
| 2191 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2192 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2193 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2194 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2195 | if (IsStructuralMatch(D, FoundEnumConstant)) |
| 2196 | return Importer.Imported(D, FoundEnumConstant); |
| 2197 | } |
| 2198 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2199 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | if (!ConflictingDecls.empty()) { |
| 2203 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2204 | ConflictingDecls.data(), |
| 2205 | ConflictingDecls.size()); |
| 2206 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2207 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | Expr *Init = Importer.Import(D->getInitExpr()); |
| 2212 | if (D->getInitExpr() && !Init) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2213 | return nullptr; |
| 2214 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2215 | EnumConstantDecl *ToEnumerator |
| 2216 | = EnumConstantDecl::Create(Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
| 2217 | Name.getAsIdentifierInfo(), T, |
| 2218 | Init, D->getInitVal()); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2219 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2220 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2221 | Importer.Imported(D, ToEnumerator); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2222 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2223 | return ToEnumerator; |
| 2224 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2225 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2226 | bool ASTNodeImporter::ImportTemplateInformation(FunctionDecl *FromFD, |
| 2227 | FunctionDecl *ToFD) { |
| 2228 | switch (FromFD->getTemplatedKind()) { |
| 2229 | case FunctionDecl::TK_NonTemplate: |
| 2230 | case FunctionDecl::TK_FunctionTemplate: |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2231 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2232 | |
| 2233 | case FunctionDecl::TK_MemberSpecialization: { |
| 2234 | auto *InstFD = cast_or_null<FunctionDecl>( |
| 2235 | Importer.Import(FromFD->getInstantiatedFromMemberFunction())); |
| 2236 | if (!InstFD) |
| 2237 | return true; |
| 2238 | |
| 2239 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
| 2240 | SourceLocation POI = Importer.Import( |
| 2241 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation()); |
| 2242 | ToFD->setInstantiationOfMemberFunction(InstFD, TSK); |
| 2243 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2244 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
| 2248 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
| 2249 | auto *Template = cast_or_null<FunctionTemplateDecl>( |
| 2250 | Importer.Import(FTSInfo->getTemplate())); |
| 2251 | if (!Template) |
| 2252 | return true; |
| 2253 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
| 2254 | |
| 2255 | // Import template arguments. |
| 2256 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
| 2257 | SmallVector<TemplateArgument, 8> ToTemplArgs; |
| 2258 | if (ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 2259 | ToTemplArgs)) |
| 2260 | return true; |
| 2261 | |
| 2262 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
| 2263 | Importer.getToContext(), ToTemplArgs); |
| 2264 | |
| 2265 | TemplateArgumentListInfo ToTAInfo; |
| 2266 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2267 | if (FromTAArgsAsWritten) |
| 2268 | if (ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2269 | return true; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2270 | |
| 2271 | SourceLocation POI = Importer.Import(FTSInfo->getPointOfInstantiation()); |
| 2272 | |
| 2273 | ToFD->setFunctionTemplateSpecialization( |
| 2274 | Template, ToTAList, /* InsertPos= */ nullptr, |
| 2275 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, POI); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2276 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 2280 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 2281 | UnresolvedSet<8> TemplDecls; |
| 2282 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 2283 | for (unsigned I = 0; I < NumTemplates; I++) { |
| 2284 | if (auto *ToFTD = cast_or_null<FunctionTemplateDecl>( |
| 2285 | Importer.Import(FromInfo->getTemplate(I)))) |
| 2286 | TemplDecls.addDecl(ToFTD); |
| 2287 | else |
| 2288 | return true; |
| 2289 | } |
| 2290 | |
| 2291 | // Import TemplateArgumentListInfo. |
| 2292 | TemplateArgumentListInfo ToTAInfo; |
| 2293 | if (ImportTemplateArgumentListInfo( |
| 2294 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 2295 | llvm::makeArrayRef(FromInfo->getTemplateArgs(), |
| 2296 | FromInfo->getNumTemplateArgs()), |
| 2297 | ToTAInfo)) |
| 2298 | return true; |
| 2299 | |
| 2300 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 2301 | TemplDecls, ToTAInfo); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2302 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2303 | } |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2304 | } |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2305 | llvm_unreachable("All cases should be covered!"); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2306 | } |
| 2307 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2308 | Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
| 2309 | // Import the major distinguishing characteristics of this function. |
| 2310 | DeclContext *DC, *LexicalDC; |
| 2311 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2312 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2313 | NamedDecl *ToD; |
| 2314 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2315 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2316 | if (ToD) |
| 2317 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2318 | |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2319 | const FunctionDecl *FoundWithoutBody = nullptr; |
| 2320 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2321 | // Try to find a function in our own ("to") context with the same name, same |
| 2322 | // type, and in the same context as the function we're importing. |
| 2323 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2324 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2325 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2326 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2327 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2328 | for (auto *FoundDecl : FoundDecls) { |
| 2329 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2330 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2331 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2332 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 2333 | if (FoundFunction->hasExternalFormalLinkage() && |
| 2334 | D->hasExternalFormalLinkage()) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2335 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| 2336 | FoundFunction->getType())) { |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2337 | // FIXME: Actually try to merge the body and other attributes. |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2338 | const FunctionDecl *FromBodyDecl = nullptr; |
| 2339 | D->hasBody(FromBodyDecl); |
| 2340 | if (D == FromBodyDecl && !FoundFunction->hasBody()) { |
| 2341 | // This function is needed to merge completely. |
| 2342 | FoundWithoutBody = FoundFunction; |
| 2343 | break; |
| 2344 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2345 | return Importer.Imported(D, FoundFunction); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2346 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2347 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2348 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 2349 | // Sema::IsOverload out to the AST library. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2350 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2351 | // Function overloading is okay in C++. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2352 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2353 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2354 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2355 | // Complain about inconsistent function types. |
| 2356 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2357 | << Name << D->getType() << FoundFunction->getType(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2358 | Importer.ToDiag(FoundFunction->getLocation(), |
| 2359 | diag::note_odr_value_here) |
| 2360 | << FoundFunction->getType(); |
| 2361 | } |
| 2362 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2363 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2364 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2365 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2366 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2367 | if (!ConflictingDecls.empty()) { |
| 2368 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2369 | ConflictingDecls.data(), |
| 2370 | ConflictingDecls.size()); |
| 2371 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2372 | return nullptr; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2373 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2374 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2375 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2376 | DeclarationNameInfo NameInfo(Name, Loc); |
| 2377 | // Import additional name location/type info. |
| 2378 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 2379 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2380 | QualType FromTy = D->getType(); |
| 2381 | bool usedDifferentExceptionSpec = false; |
| 2382 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2383 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2384 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 2385 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 2386 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 2387 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 2388 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 2389 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 2390 | FromEPI.ExceptionSpec.SourceTemplate || |
| 2391 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2392 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 2393 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2394 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2395 | usedDifferentExceptionSpec = true; |
| 2396 | } |
| 2397 | } |
| 2398 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2399 | // Import the type. |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2400 | QualType T = Importer.Import(FromTy); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2401 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2402 | return nullptr; |
| 2403 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2404 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2405 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2406 | for (auto P : D->parameters()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2407 | auto *ToP = cast_or_null<ParmVarDecl>(Importer.Import(P)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2408 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2409 | return nullptr; |
| 2410 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2411 | Parameters.push_back(ToP); |
| 2412 | } |
| 2413 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2414 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2415 | if (D->getTypeSourceInfo() && !TInfo) |
| 2416 | return nullptr; |
| 2417 | |
| 2418 | // Create the imported function. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2419 | FunctionDecl *ToFunction = nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2420 | SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2421 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2422 | ToFunction = CXXConstructorDecl::Create(Importer.getToContext(), |
| 2423 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2424 | InnerLocStart, |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2425 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2426 | FromConstructor->isExplicit(), |
| 2427 | D->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2428 | D->isImplicit(), |
| 2429 | D->isConstexpr()); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2430 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 2431 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2432 | for (auto *I : FromConstructor->inits()) { |
| 2433 | auto *ToI = cast_or_null<CXXCtorInitializer>(Importer.Import(I)); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2434 | if (!ToI && I) |
| 2435 | return nullptr; |
| 2436 | CtorInitializers.push_back(ToI); |
| 2437 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2438 | auto **Memory = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2439 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 2440 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2441 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2442 | ToCtor->setCtorInitializers(Memory); |
| 2443 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 2444 | } |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2445 | } else if (isa<CXXDestructorDecl>(D)) { |
| 2446 | ToFunction = CXXDestructorDecl::Create(Importer.getToContext(), |
| 2447 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2448 | InnerLocStart, |
Craig Silverstein | af8808d | 2010-10-21 00:44:50 +0000 | [diff] [blame] | 2449 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2450 | D->isInlineSpecified(), |
| 2451 | D->isImplicit()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2452 | } else if (auto *FromConversion = dyn_cast<CXXConversionDecl>(D)) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2453 | ToFunction = CXXConversionDecl::Create(Importer.getToContext(), |
| 2454 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2455 | InnerLocStart, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2456 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2457 | D->isInlineSpecified(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2458 | FromConversion->isExplicit(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2459 | D->isConstexpr(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2460 | Importer.Import(D->getLocEnd())); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2461 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
Douglas Gregor | a50ad13 | 2010-11-29 16:04:58 +0000 | [diff] [blame] | 2462 | ToFunction = CXXMethodDecl::Create(Importer.getToContext(), |
| 2463 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2464 | InnerLocStart, |
Douglas Gregor | a50ad13 | 2010-11-29 16:04:58 +0000 | [diff] [blame] | 2465 | NameInfo, T, TInfo, |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 2466 | Method->getStorageClass(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2467 | Method->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2468 | D->isConstexpr(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2469 | Importer.Import(D->getLocEnd())); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2470 | } else { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2471 | ToFunction = FunctionDecl::Create(Importer.getToContext(), DC, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2472 | InnerLocStart, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2473 | NameInfo, T, TInfo, D->getStorageClass(), |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2474 | D->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2475 | D->hasWrittenPrototype(), |
| 2476 | D->isConstexpr()); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2477 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 2478 | |
| 2479 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2480 | ToFunction->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2481 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2482 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 2483 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 2484 | ToFunction->setTrivial(D->isTrivial()); |
| 2485 | ToFunction->setPure(D->isPure()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2486 | Importer.Imported(D, ToFunction); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2487 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2488 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2489 | for (auto *Param : Parameters) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2490 | Param->setOwningFunction(ToFunction); |
| 2491 | ToFunction->addDeclInternal(Param); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2492 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 2493 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2494 | |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2495 | if (FoundWithoutBody) { |
| 2496 | auto *Recent = const_cast<FunctionDecl *>( |
| 2497 | FoundWithoutBody->getMostRecentDecl()); |
| 2498 | ToFunction->setPreviousDecl(Recent); |
| 2499 | } |
| 2500 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2501 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 2502 | // params it refers to. |
| 2503 | if (TInfo) { |
| 2504 | if (auto ProtoLoc = |
| 2505 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 2506 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 2507 | ProtoLoc.setParam(I, Parameters[I]); |
| 2508 | } |
| 2509 | } |
| 2510 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2511 | if (usedDifferentExceptionSpec) { |
| 2512 | // Update FunctionProtoType::ExtProtoInfo. |
| 2513 | QualType T = Importer.Import(D->getType()); |
| 2514 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2515 | return nullptr; |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2516 | ToFunction->setType(T); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 2517 | } |
| 2518 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2519 | // Import the body, if any. |
| 2520 | if (Stmt *FromBody = D->getBody()) { |
| 2521 | if (Stmt *ToBody = Importer.Import(FromBody)) { |
| 2522 | ToFunction->setBody(ToBody); |
| 2523 | } |
| 2524 | } |
| 2525 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2526 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2527 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2528 | // If it is a template, import all related things. |
| 2529 | if (ImportTemplateInformation(D, ToFunction)) |
| 2530 | return nullptr; |
| 2531 | |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2532 | // Add this function to the lexical context. |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2533 | // NOTE: If the function is templated declaration, it should be not added into |
| 2534 | // LexicalDC. But described template is imported during import of |
| 2535 | // FunctionTemplateDecl (it happens later). So, we use source declaration |
| 2536 | // to determine if we should add the result function. |
| 2537 | if (!D->getDescribedFunctionTemplate()) |
| 2538 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2539 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 2540 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 2541 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 2542 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2543 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2544 | } |
| 2545 | |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2546 | Decl *ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| 2547 | return VisitFunctionDecl(D); |
| 2548 | } |
| 2549 | |
| 2550 | Decl *ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| 2551 | return VisitCXXMethodDecl(D); |
| 2552 | } |
| 2553 | |
| 2554 | Decl *ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| 2555 | return VisitCXXMethodDecl(D); |
| 2556 | } |
| 2557 | |
| 2558 | Decl *ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| 2559 | return VisitCXXMethodDecl(D); |
| 2560 | } |
| 2561 | |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2562 | static unsigned getFieldIndex(Decl *F) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2563 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2564 | if (!Owner) |
| 2565 | return 0; |
| 2566 | |
| 2567 | unsigned Index = 1; |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2568 | for (const auto *D : Owner->noload_decls()) { |
| 2569 | if (D == F) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2570 | return Index; |
| 2571 | |
| 2572 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 2573 | ++Index; |
| 2574 | } |
| 2575 | |
| 2576 | return Index; |
| 2577 | } |
| 2578 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2579 | Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
| 2580 | // Import the major distinguishing characteristics of a variable. |
| 2581 | DeclContext *DC, *LexicalDC; |
| 2582 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2583 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2584 | NamedDecl *ToD; |
| 2585 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2586 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2587 | if (ToD) |
| 2588 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2589 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2590 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2591 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2592 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2593 | for (auto *FoundDecl : FoundDecls) { |
| 2594 | if (auto *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2595 | // For anonymous fields, match up by index. |
| 2596 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2597 | continue; |
| 2598 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2599 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2600 | FoundField->getType())) { |
| 2601 | Importer.Imported(D, FoundField); |
| 2602 | return FoundField; |
| 2603 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2604 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2605 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2606 | << Name << D->getType() << FoundField->getType(); |
| 2607 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2608 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2609 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2610 | } |
| 2611 | } |
| 2612 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2613 | // Import the type. |
| 2614 | QualType T = Importer.Import(D->getType()); |
| 2615 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2616 | return nullptr; |
| 2617 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2618 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2619 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 2620 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2621 | return nullptr; |
| 2622 | |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2623 | FieldDecl *ToField = FieldDecl::Create(Importer.getToContext(), DC, |
| 2624 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2625 | Loc, Name.getAsIdentifierInfo(), |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2626 | T, TInfo, BitWidth, D->isMutable(), |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2627 | D->getInClassInitStyle()); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2628 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2629 | ToField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 3a83ea7 | 2016-03-03 02:22:05 +0000 | [diff] [blame] | 2630 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
Sean Callanan | bb33f58 | 2016-03-03 01:21:28 +0000 | [diff] [blame] | 2631 | Expr *ToInitializer = Importer.Import(FromInitializer); |
| 2632 | if (ToInitializer) |
| 2633 | ToField->setInClassInitializer(ToInitializer); |
| 2634 | else |
| 2635 | return nullptr; |
| 2636 | } |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2637 | ToField->setImplicit(D->isImplicit()); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2638 | Importer.Imported(D, ToField); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2639 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2640 | return ToField; |
| 2641 | } |
| 2642 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2643 | Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| 2644 | // Import the major distinguishing characteristics of a variable. |
| 2645 | DeclContext *DC, *LexicalDC; |
| 2646 | DeclarationName Name; |
| 2647 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2648 | NamedDecl *ToD; |
| 2649 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2650 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2651 | if (ToD) |
| 2652 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2653 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2654 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2655 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2656 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2657 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2658 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2659 | // For anonymous indirect fields, match up by index. |
| 2660 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2661 | continue; |
| 2662 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2663 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2664 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 2665 | !Name.isEmpty())) { |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2666 | Importer.Imported(D, FoundField); |
| 2667 | return FoundField; |
| 2668 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2669 | |
| 2670 | // If there are more anonymous fields to check, continue. |
| 2671 | if (!Name && I < N-1) |
| 2672 | continue; |
| 2673 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2674 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2675 | << Name << D->getType() << FoundField->getType(); |
| 2676 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2677 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2678 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2679 | } |
| 2680 | } |
| 2681 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2682 | // Import the type. |
| 2683 | QualType T = Importer.Import(D->getType()); |
| 2684 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2685 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2686 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2687 | auto **NamedChain = |
| 2688 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2689 | |
| 2690 | unsigned i = 0; |
Aaron Ballman | 29c9460 | 2014-03-07 18:36:15 +0000 | [diff] [blame] | 2691 | for (auto *PI : D->chain()) { |
Aaron Ballman | 1391608 | 2014-03-07 18:11:58 +0000 | [diff] [blame] | 2692 | Decl *D = Importer.Import(PI); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2693 | if (!D) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2694 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2695 | NamedChain[i++] = cast<NamedDecl>(D); |
| 2696 | } |
| 2697 | |
| 2698 | IndirectFieldDecl *ToIndirectField = IndirectFieldDecl::Create( |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2699 | Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T, |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2700 | {NamedChain, D->getChainingSize()}); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2701 | |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 2702 | for (const auto *A : D->attrs()) |
| 2703 | ToIndirectField->addAttr(Importer.Import(A)); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2704 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2705 | ToIndirectField->setAccess(D->getAccess()); |
| 2706 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
| 2707 | Importer.Imported(D, ToIndirectField); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2708 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2709 | return ToIndirectField; |
| 2710 | } |
| 2711 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2712 | Decl *ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
| 2713 | // Import the major distinguishing characteristics of a declaration. |
| 2714 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 2715 | DeclContext *LexicalDC = D->getDeclContext() == D->getLexicalDeclContext() |
| 2716 | ? DC : Importer.ImportContext(D->getLexicalDeclContext()); |
| 2717 | if (!DC || !LexicalDC) |
| 2718 | return nullptr; |
| 2719 | |
| 2720 | // Determine whether we've already imported this decl. |
| 2721 | // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup. |
| 2722 | auto *RD = cast<CXXRecordDecl>(DC); |
| 2723 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
| 2724 | StructuralEquivalenceContext Context( |
| 2725 | Importer.getFromContext(), Importer.getToContext(), |
| 2726 | Importer.getNonEquivalentDecls(), false, false); |
| 2727 | |
| 2728 | while (ImportedFriend) { |
| 2729 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
| 2730 | if (Context.IsStructurallyEquivalent(D->getFriendDecl(), |
| 2731 | ImportedFriend->getFriendDecl())) |
| 2732 | return Importer.Imported(D, ImportedFriend); |
| 2733 | |
| 2734 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 2735 | if (Importer.IsStructurallyEquivalent( |
| 2736 | D->getFriendType()->getType(), |
| 2737 | ImportedFriend->getFriendType()->getType(), true)) |
| 2738 | return Importer.Imported(D, ImportedFriend); |
| 2739 | } |
| 2740 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 2741 | } |
| 2742 | |
| 2743 | // Not found. Create it. |
| 2744 | FriendDecl::FriendUnion ToFU; |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 2745 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
| 2746 | auto *ToFriendD = cast_or_null<NamedDecl>(Importer.Import(FriendD)); |
| 2747 | if (ToFriendD && FriendD->getFriendObjectKind() != Decl::FOK_None && |
| 2748 | !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator))) |
| 2749 | ToFriendD->setObjectOfFriendDecl(false); |
| 2750 | |
| 2751 | ToFU = ToFriendD; |
| 2752 | } else // The friend is a type, not a decl. |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2753 | ToFU = Importer.Import(D->getFriendType()); |
| 2754 | if (!ToFU) |
| 2755 | return nullptr; |
| 2756 | |
| 2757 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2758 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2759 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
| 2760 | TemplateParameterList *List = ImportTemplateParameterList(FromTPLists[I]); |
| 2761 | if (!List) |
| 2762 | return nullptr; |
| 2763 | ToTPLists[I] = List; |
| 2764 | } |
| 2765 | |
| 2766 | FriendDecl *FrD = FriendDecl::Create(Importer.getToContext(), DC, |
| 2767 | Importer.Import(D->getLocation()), |
| 2768 | ToFU, Importer.Import(D->getFriendLoc()), |
| 2769 | ToTPLists); |
| 2770 | |
| 2771 | Importer.Imported(D, FrD); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2772 | |
| 2773 | FrD->setAccess(D->getAccess()); |
| 2774 | FrD->setLexicalDeclContext(LexicalDC); |
| 2775 | LexicalDC->addDeclInternal(FrD); |
| 2776 | return FrD; |
| 2777 | } |
| 2778 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2779 | Decl *ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| 2780 | // Import the major distinguishing characteristics of an ivar. |
| 2781 | DeclContext *DC, *LexicalDC; |
| 2782 | DeclarationName Name; |
| 2783 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2784 | NamedDecl *ToD; |
| 2785 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2786 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2787 | if (ToD) |
| 2788 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2789 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2790 | // Determine whether we've already imported this ivar |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2791 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2792 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2793 | for (auto *FoundDecl : FoundDecls) { |
| 2794 | if (auto *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2795 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2796 | FoundIvar->getType())) { |
| 2797 | Importer.Imported(D, FoundIvar); |
| 2798 | return FoundIvar; |
| 2799 | } |
| 2800 | |
| 2801 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) |
| 2802 | << Name << D->getType() << FoundIvar->getType(); |
| 2803 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 2804 | << FoundIvar->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2805 | return nullptr; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2806 | } |
| 2807 | } |
| 2808 | |
| 2809 | // Import the type. |
| 2810 | QualType T = Importer.Import(D->getType()); |
| 2811 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2812 | return nullptr; |
| 2813 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2814 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2815 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 2816 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2817 | return nullptr; |
| 2818 | |
Daniel Dunbar | fe3ead7 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 2819 | ObjCIvarDecl *ToIvar = ObjCIvarDecl::Create(Importer.getToContext(), |
| 2820 | cast<ObjCContainerDecl>(DC), |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2821 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2822 | Loc, Name.getAsIdentifierInfo(), |
| 2823 | T, TInfo, D->getAccessControl(), |
Argyrios Kyrtzidis | 2080d90 | 2014-01-03 18:32:18 +0000 | [diff] [blame] | 2824 | BitWidth, D->getSynthesize()); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2825 | ToIvar->setLexicalDeclContext(LexicalDC); |
| 2826 | Importer.Imported(D, ToIvar); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2827 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2828 | return ToIvar; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2829 | } |
| 2830 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2831 | Decl *ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
| 2832 | // Import the major distinguishing characteristics of a variable. |
| 2833 | DeclContext *DC, *LexicalDC; |
| 2834 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2835 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2836 | NamedDecl *ToD; |
| 2837 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2838 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2839 | if (ToD) |
| 2840 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2841 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2842 | // Try to find a variable in our own ("to") context with the same name and |
| 2843 | // in the same context as the variable we're importing. |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2844 | if (D->isFileVarDecl()) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2845 | VarDecl *MergeWithVar = nullptr; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2846 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2847 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2848 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2849 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2850 | for (auto *FoundDecl : FoundDecls) { |
| 2851 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2852 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2853 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2854 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2855 | // 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] | 2856 | if (FoundVar->hasExternalFormalLinkage() && |
| 2857 | D->hasExternalFormalLinkage()) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2858 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2859 | FoundVar->getType())) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2860 | MergeWithVar = FoundVar; |
| 2861 | break; |
| 2862 | } |
| 2863 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2864 | const ArrayType *FoundArray |
| 2865 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 2866 | const ArrayType *TArray |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2867 | = Importer.getToContext().getAsArrayType(D->getType()); |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2868 | if (FoundArray && TArray) { |
| 2869 | if (isa<IncompleteArrayType>(FoundArray) && |
| 2870 | isa<ConstantArrayType>(TArray)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2871 | // Import the type. |
| 2872 | QualType T = Importer.Import(D->getType()); |
| 2873 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2874 | return nullptr; |
| 2875 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2876 | FoundVar->setType(T); |
| 2877 | MergeWithVar = FoundVar; |
| 2878 | break; |
| 2879 | } else if (isa<IncompleteArrayType>(TArray) && |
| 2880 | isa<ConstantArrayType>(FoundArray)) { |
| 2881 | MergeWithVar = FoundVar; |
| 2882 | break; |
Douglas Gregor | 2fbe558 | 2010-02-10 17:16:49 +0000 | [diff] [blame] | 2883 | } |
| 2884 | } |
| 2885 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2886 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2887 | << Name << D->getType() << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2888 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 2889 | << FoundVar->getType(); |
| 2890 | } |
| 2891 | } |
| 2892 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2893 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2894 | } |
| 2895 | |
| 2896 | if (MergeWithVar) { |
| 2897 | // An equivalent variable with external linkage has been found. Link |
| 2898 | // the two declarations, then merge them. |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2899 | Importer.Imported(D, MergeWithVar); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2900 | |
| 2901 | if (VarDecl *DDef = D->getDefinition()) { |
| 2902 | if (VarDecl *ExistingDef = MergeWithVar->getDefinition()) { |
| 2903 | Importer.ToDiag(ExistingDef->getLocation(), |
| 2904 | diag::err_odr_variable_multiple_def) |
| 2905 | << Name; |
| 2906 | Importer.FromDiag(DDef->getLocation(), diag::note_odr_defined_here); |
| 2907 | } else { |
| 2908 | Expr *Init = Importer.Import(DDef->getInit()); |
Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 2909 | MergeWithVar->setInit(Init); |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 2910 | if (DDef->isInitKnownICE()) { |
| 2911 | EvaluatedStmt *Eval = MergeWithVar->ensureEvaluatedStmt(); |
| 2912 | Eval->CheckedICE = true; |
| 2913 | Eval->IsICE = DDef->isInitICE(); |
| 2914 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2915 | } |
| 2916 | } |
| 2917 | |
| 2918 | return MergeWithVar; |
| 2919 | } |
| 2920 | |
| 2921 | if (!ConflictingDecls.empty()) { |
| 2922 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2923 | ConflictingDecls.data(), |
| 2924 | ConflictingDecls.size()); |
| 2925 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2926 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2927 | } |
| 2928 | } |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2929 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2930 | // Import the type. |
| 2931 | QualType T = Importer.Import(D->getType()); |
| 2932 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2933 | return nullptr; |
| 2934 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2935 | // Create the imported variable. |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2936 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2937 | VarDecl *ToVar = VarDecl::Create(Importer.getToContext(), DC, |
| 2938 | Importer.Import(D->getInnerLocStart()), |
| 2939 | Loc, Name.getAsIdentifierInfo(), |
| 2940 | T, TInfo, |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 2941 | D->getStorageClass()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2942 | ToVar->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2943 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2944 | ToVar->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2945 | Importer.Imported(D, ToVar); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2946 | |
| 2947 | // Templated declarations should never appear in the enclosing DeclContext. |
| 2948 | if (!D->getDescribedVarTemplate()) |
| 2949 | LexicalDC->addDeclInternal(ToVar); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2950 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2951 | if (!D->isFileVarDecl() && |
| 2952 | D->isUsed()) |
| 2953 | ToVar->setIsUsed(); |
| 2954 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2955 | // Merge the initializer. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2956 | if (ImportDefinition(D, ToVar)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2957 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2958 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 2959 | if (D->isConstexpr()) |
| 2960 | ToVar->setConstexpr(true); |
| 2961 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2962 | return ToVar; |
| 2963 | } |
| 2964 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2965 | Decl *ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| 2966 | // Parameters are created in the translation unit's context, then moved |
| 2967 | // into the function declaration's context afterward. |
| 2968 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 2969 | |
| 2970 | // Import the name of this declaration. |
| 2971 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 2972 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2973 | return nullptr; |
| 2974 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2975 | // Import the location of this declaration. |
| 2976 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 2977 | |
| 2978 | // Import the parameter's type. |
| 2979 | QualType T = Importer.Import(D->getType()); |
| 2980 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2981 | return nullptr; |
| 2982 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2983 | // Create the imported parameter. |
Alexey Bataev | 5622323 | 2017-06-09 13:40:18 +0000 | [diff] [blame] | 2984 | auto *ToParm = ImplicitParamDecl::Create(Importer.getToContext(), DC, Loc, |
| 2985 | Name.getAsIdentifierInfo(), T, |
| 2986 | D->getParameterKind()); |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2987 | return Importer.Imported(D, ToParm); |
| 2988 | } |
| 2989 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2990 | Decl *ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
| 2991 | // Parameters are created in the translation unit's context, then moved |
| 2992 | // into the function declaration's context afterward. |
| 2993 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 2994 | |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2995 | // Import the name of this declaration. |
| 2996 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 2997 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2998 | return nullptr; |
| 2999 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3000 | // Import the location of this declaration. |
| 3001 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 3002 | |
| 3003 | // Import the parameter's type. |
| 3004 | QualType T = Importer.Import(D->getType()); |
| 3005 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3006 | return nullptr; |
| 3007 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3008 | // Create the imported parameter. |
| 3009 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3010 | ParmVarDecl *ToParm = ParmVarDecl::Create(Importer.getToContext(), DC, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 3011 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3012 | Loc, Name.getAsIdentifierInfo(), |
| 3013 | T, TInfo, D->getStorageClass(), |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3014 | /*DefaultArg*/ nullptr); |
| 3015 | |
| 3016 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 3017 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 3018 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 3019 | |
| 3020 | Expr *ToDefArg = nullptr; |
| 3021 | Expr *FromDefArg = nullptr; |
| 3022 | if (D->hasUninstantiatedDefaultArg()) { |
| 3023 | FromDefArg = D->getUninstantiatedDefaultArg(); |
| 3024 | ToDefArg = Importer.Import(FromDefArg); |
| 3025 | ToParm->setUninstantiatedDefaultArg(ToDefArg); |
| 3026 | } else if (D->hasUnparsedDefaultArg()) { |
| 3027 | ToParm->setUnparsedDefaultArg(); |
| 3028 | } else if (D->hasDefaultArg()) { |
| 3029 | FromDefArg = D->getDefaultArg(); |
| 3030 | ToDefArg = Importer.Import(FromDefArg); |
| 3031 | ToParm->setDefaultArg(ToDefArg); |
| 3032 | } |
| 3033 | if (FromDefArg && !ToDefArg) |
| 3034 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3035 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 3036 | if (D->isObjCMethodParameter()) { |
| 3037 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3038 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3039 | } else { |
| 3040 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3041 | D->getFunctionScopeIndex()); |
| 3042 | } |
| 3043 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3044 | if (D->isUsed()) |
| 3045 | ToParm->setIsUsed(); |
| 3046 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 3047 | return Importer.Imported(D, ToParm); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3048 | } |
| 3049 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3050 | Decl *ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| 3051 | // Import the major distinguishing characteristics of a method. |
| 3052 | DeclContext *DC, *LexicalDC; |
| 3053 | DeclarationName Name; |
| 3054 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3055 | NamedDecl *ToD; |
| 3056 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3057 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3058 | if (ToD) |
| 3059 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3060 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3061 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3062 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3063 | for (auto *FoundDecl : FoundDecls) { |
| 3064 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3065 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3066 | continue; |
| 3067 | |
| 3068 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3069 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3070 | FoundMethod->getReturnType())) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3071 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3072 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3073 | << FoundMethod->getReturnType(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3074 | Importer.ToDiag(FoundMethod->getLocation(), |
| 3075 | diag::note_odr_objc_method_here) |
| 3076 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3077 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3078 | } |
| 3079 | |
| 3080 | // Check the number of parameters. |
| 3081 | if (D->param_size() != FoundMethod->param_size()) { |
| 3082 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) |
| 3083 | << D->isInstanceMethod() << Name |
| 3084 | << D->param_size() << FoundMethod->param_size(); |
| 3085 | Importer.ToDiag(FoundMethod->getLocation(), |
| 3086 | diag::note_odr_objc_method_here) |
| 3087 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3088 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3089 | } |
| 3090 | |
| 3091 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3092 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3093 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3094 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3095 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3096 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3097 | Importer.FromDiag((*P)->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3098 | diag::err_odr_objc_method_param_type_inconsistent) |
| 3099 | << D->isInstanceMethod() << Name |
| 3100 | << (*P)->getType() << (*FoundP)->getType(); |
| 3101 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3102 | << (*FoundP)->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3103 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3104 | } |
| 3105 | } |
| 3106 | |
| 3107 | // Check variadic/non-variadic. |
| 3108 | // Check the number of parameters. |
| 3109 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| 3110 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) |
| 3111 | << D->isInstanceMethod() << Name; |
| 3112 | Importer.ToDiag(FoundMethod->getLocation(), |
| 3113 | diag::note_odr_objc_method_here) |
| 3114 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3115 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3116 | } |
| 3117 | |
| 3118 | // FIXME: Any other bits we need to merge? |
| 3119 | return Importer.Imported(D, FoundMethod); |
| 3120 | } |
| 3121 | } |
| 3122 | |
| 3123 | // Import the result type. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3124 | QualType ResultTy = Importer.Import(D->getReturnType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3125 | if (ResultTy.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3126 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3127 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3128 | TypeSourceInfo *ReturnTInfo = Importer.Import(D->getReturnTypeSourceInfo()); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3129 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3130 | ObjCMethodDecl *ToMethod = ObjCMethodDecl::Create( |
| 3131 | Importer.getToContext(), Loc, Importer.Import(D->getLocEnd()), |
| 3132 | Name.getObjCSelector(), ResultTy, ReturnTInfo, DC, D->isInstanceMethod(), |
| 3133 | D->isVariadic(), D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3134 | D->getImplementationControl(), D->hasRelatedResultType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3135 | |
| 3136 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3137 | // deal with implicit parameters. |
| 3138 | |
| 3139 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3140 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3141 | for (auto *FromP : D->parameters()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3142 | auto *ToP = cast_or_null<ParmVarDecl>(Importer.Import(FromP)); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3143 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3144 | return nullptr; |
| 3145 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3146 | ToParams.push_back(ToP); |
| 3147 | } |
| 3148 | |
| 3149 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3150 | for (auto *ToParam : ToParams) { |
| 3151 | ToParam->setOwningFunction(ToMethod); |
| 3152 | ToMethod->addDeclInternal(ToParam); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3153 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3154 | |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 3155 | SmallVector<SourceLocation, 12> SelLocs; |
| 3156 | D->getSelectorLocs(SelLocs); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3157 | for (auto &Loc : SelLocs) |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3158 | Loc = Importer.Import(Loc); |
| 3159 | |
| 3160 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, SelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3161 | |
| 3162 | ToMethod->setLexicalDeclContext(LexicalDC); |
| 3163 | Importer.Imported(D, ToMethod); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3164 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3165 | return ToMethod; |
| 3166 | } |
| 3167 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3168 | Decl *ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| 3169 | // Import the major distinguishing characteristics of a category. |
| 3170 | DeclContext *DC, *LexicalDC; |
| 3171 | DeclarationName Name; |
| 3172 | SourceLocation Loc; |
| 3173 | NamedDecl *ToD; |
| 3174 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3175 | return nullptr; |
| 3176 | if (ToD) |
| 3177 | return ToD; |
| 3178 | |
| 3179 | TypeSourceInfo *BoundInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3180 | if (!BoundInfo) |
| 3181 | return nullptr; |
| 3182 | |
| 3183 | ObjCTypeParamDecl *Result = ObjCTypeParamDecl::Create( |
| 3184 | Importer.getToContext(), DC, |
Douglas Gregor | 1ac1b63 | 2015-07-07 03:58:54 +0000 | [diff] [blame] | 3185 | D->getVariance(), |
| 3186 | Importer.Import(D->getVarianceLoc()), |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 3187 | D->getIndex(), |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3188 | Importer.Import(D->getLocation()), |
| 3189 | Name.getAsIdentifierInfo(), |
| 3190 | Importer.Import(D->getColonLoc()), |
| 3191 | BoundInfo); |
| 3192 | Importer.Imported(D, Result); |
| 3193 | Result->setLexicalDeclContext(LexicalDC); |
| 3194 | return Result; |
| 3195 | } |
| 3196 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3197 | Decl *ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| 3198 | // Import the major distinguishing characteristics of a category. |
| 3199 | DeclContext *DC, *LexicalDC; |
| 3200 | DeclarationName Name; |
| 3201 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3202 | NamedDecl *ToD; |
| 3203 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3204 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3205 | if (ToD) |
| 3206 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3207 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3208 | auto *ToInterface = |
| 3209 | cast_or_null<ObjCInterfaceDecl>(Importer.Import(D->getClassInterface())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3210 | if (!ToInterface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3211 | return nullptr; |
| 3212 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3213 | // Determine if we've already encountered this category. |
| 3214 | ObjCCategoryDecl *MergeWithCategory |
| 3215 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3216 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3217 | if (!ToCategory) { |
| 3218 | ToCategory = ObjCCategoryDecl::Create(Importer.getToContext(), DC, |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3219 | Importer.Import(D->getAtStartLoc()), |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3220 | Loc, |
| 3221 | Importer.Import(D->getCategoryNameLoc()), |
Argyrios Kyrtzidis | 3a5094b | 2011-08-30 19:43:26 +0000 | [diff] [blame] | 3222 | Name.getAsIdentifierInfo(), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3223 | ToInterface, |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3224 | /*TypeParamList=*/nullptr, |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3225 | Importer.Import(D->getIvarLBraceLoc()), |
| 3226 | Importer.Import(D->getIvarRBraceLoc())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3227 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3228 | LexicalDC->addDeclInternal(ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3229 | Importer.Imported(D, ToCategory); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3230 | // Import the type parameter list after calling Imported, to avoid |
| 3231 | // loops when bringing in their DeclContext. |
| 3232 | ToCategory->setTypeParamList(ImportObjCTypeParamList( |
| 3233 | D->getTypeParamList())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3234 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3235 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3236 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3237 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3238 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 3239 | = D->protocol_loc_begin(); |
| 3240 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 3241 | FromProtoEnd = D->protocol_end(); |
| 3242 | FromProto != FromProtoEnd; |
| 3243 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3244 | auto *ToProto = |
| 3245 | cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3246 | if (!ToProto) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3247 | return nullptr; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3248 | Protocols.push_back(ToProto); |
| 3249 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3250 | } |
| 3251 | |
| 3252 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3253 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 3254 | ProtocolLocs.data(), Importer.getToContext()); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3255 | } else { |
| 3256 | Importer.Imported(D, ToCategory); |
| 3257 | } |
| 3258 | |
| 3259 | // Import all of the members of this category. |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 3260 | ImportDeclContext(D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3261 | |
| 3262 | // If we have an implementation, import it as well. |
| 3263 | if (D->getImplementation()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3264 | auto *Impl = |
| 3265 | cast_or_null<ObjCCategoryImplDecl>( |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3266 | Importer.Import(D->getImplementation())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3267 | if (!Impl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3268 | return nullptr; |
| 3269 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3270 | ToCategory->setImplementation(Impl); |
| 3271 | } |
| 3272 | |
| 3273 | return ToCategory; |
| 3274 | } |
| 3275 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3276 | bool ASTNodeImporter::ImportDefinition(ObjCProtocolDecl *From, |
| 3277 | ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3278 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3279 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3280 | if (shouldForceImportDeclContext(Kind)) |
| 3281 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3282 | return false; |
| 3283 | } |
| 3284 | |
| 3285 | // Start the protocol definition |
| 3286 | To->startDefinition(); |
| 3287 | |
| 3288 | // Import protocols |
| 3289 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3290 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 3291 | ObjCProtocolDecl::protocol_loc_iterator |
| 3292 | FromProtoLoc = From->protocol_loc_begin(); |
| 3293 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3294 | FromProtoEnd = From->protocol_end(); |
| 3295 | FromProto != FromProtoEnd; |
| 3296 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3297 | auto *ToProto = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3298 | if (!ToProto) |
| 3299 | return true; |
| 3300 | Protocols.push_back(ToProto); |
| 3301 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3302 | } |
| 3303 | |
| 3304 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3305 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3306 | ProtocolLocs.data(), Importer.getToContext()); |
| 3307 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3308 | if (shouldForceImportDeclContext(Kind)) { |
| 3309 | // Import all of the members of this protocol. |
| 3310 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3311 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3312 | return false; |
| 3313 | } |
| 3314 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3315 | Decl *ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3316 | // If this protocol has a definition in the translation unit we're coming |
| 3317 | // from, but this particular declaration is not that definition, import the |
| 3318 | // definition and map to that. |
| 3319 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 3320 | if (Definition && Definition != D) { |
| 3321 | Decl *ImportedDef = Importer.Import(Definition); |
| 3322 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3323 | return nullptr; |
| 3324 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3325 | return Importer.Imported(D, ImportedDef); |
| 3326 | } |
| 3327 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3328 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3329 | DeclContext *DC, *LexicalDC; |
| 3330 | DeclarationName Name; |
| 3331 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3332 | NamedDecl *ToD; |
| 3333 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3334 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3335 | if (ToD) |
| 3336 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3337 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3338 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3339 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3340 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3341 | for (auto *FoundDecl : FoundDecls) { |
| 3342 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3343 | continue; |
| 3344 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3345 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3346 | break; |
| 3347 | } |
| 3348 | |
| 3349 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3350 | if (!ToProto) { |
| 3351 | ToProto = ObjCProtocolDecl::Create(Importer.getToContext(), DC, |
| 3352 | Name.getAsIdentifierInfo(), Loc, |
| 3353 | Importer.Import(D->getAtStartLoc()), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3354 | /*PrevDecl=*/nullptr); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3355 | ToProto->setLexicalDeclContext(LexicalDC); |
| 3356 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3357 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3358 | |
| 3359 | Importer.Imported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3360 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3361 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToProto)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3362 | return nullptr; |
| 3363 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3364 | return ToProto; |
| 3365 | } |
| 3366 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3367 | Decl *ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 3368 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3369 | DeclContext *LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3370 | |
| 3371 | SourceLocation ExternLoc = Importer.Import(D->getExternLoc()); |
| 3372 | SourceLocation LangLoc = Importer.Import(D->getLocation()); |
| 3373 | |
| 3374 | bool HasBraces = D->hasBraces(); |
| 3375 | |
Sean Callanan | b12a855 | 2014-12-10 21:22:20 +0000 | [diff] [blame] | 3376 | LinkageSpecDecl *ToLinkageSpec = |
| 3377 | LinkageSpecDecl::Create(Importer.getToContext(), |
| 3378 | DC, |
| 3379 | ExternLoc, |
| 3380 | LangLoc, |
| 3381 | D->getLanguage(), |
| 3382 | HasBraces); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3383 | |
| 3384 | if (HasBraces) { |
| 3385 | SourceLocation RBraceLoc = Importer.Import(D->getRBraceLoc()); |
| 3386 | ToLinkageSpec->setRBraceLoc(RBraceLoc); |
| 3387 | } |
| 3388 | |
| 3389 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 3390 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 3391 | |
| 3392 | Importer.Imported(D, ToLinkageSpec); |
| 3393 | |
| 3394 | return ToLinkageSpec; |
| 3395 | } |
| 3396 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3397 | Decl *ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
| 3398 | DeclContext *DC, *LexicalDC; |
| 3399 | DeclarationName Name; |
| 3400 | SourceLocation Loc; |
| 3401 | NamedDecl *ToD = nullptr; |
| 3402 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3403 | return nullptr; |
| 3404 | if (ToD) |
| 3405 | return ToD; |
| 3406 | |
| 3407 | DeclarationNameInfo NameInfo(Name, |
| 3408 | Importer.Import(D->getNameInfo().getLoc())); |
| 3409 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3410 | |
| 3411 | UsingDecl *ToUsing = UsingDecl::Create(Importer.getToContext(), DC, |
| 3412 | Importer.Import(D->getUsingLoc()), |
| 3413 | Importer.Import(D->getQualifierLoc()), |
| 3414 | NameInfo, D->hasTypename()); |
| 3415 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3416 | LexicalDC->addDeclInternal(ToUsing); |
| 3417 | Importer.Imported(D, ToUsing); |
| 3418 | |
| 3419 | if (NamedDecl *FromPattern = |
| 3420 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3421 | if (auto *ToPattern = |
| 3422 | dyn_cast_or_null<NamedDecl>(Importer.Import(FromPattern))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3423 | Importer.getToContext().setInstantiatedFromUsingDecl(ToUsing, ToPattern); |
| 3424 | else |
| 3425 | return nullptr; |
| 3426 | } |
| 3427 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3428 | for (auto *FromShadow : D->shadows()) { |
| 3429 | if (auto *ToShadow = |
| 3430 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromShadow))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3431 | ToUsing->addShadowDecl(ToShadow); |
| 3432 | else |
| 3433 | // FIXME: We return a nullptr here but the definition is already created |
| 3434 | // and available with lookups. How to fix this?.. |
| 3435 | return nullptr; |
| 3436 | } |
| 3437 | return ToUsing; |
| 3438 | } |
| 3439 | |
| 3440 | Decl *ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| 3441 | DeclContext *DC, *LexicalDC; |
| 3442 | DeclarationName Name; |
| 3443 | SourceLocation Loc; |
| 3444 | NamedDecl *ToD = nullptr; |
| 3445 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3446 | return nullptr; |
| 3447 | if (ToD) |
| 3448 | return ToD; |
| 3449 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3450 | auto *ToUsing = dyn_cast_or_null<UsingDecl>( |
| 3451 | Importer.Import(D->getUsingDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3452 | if (!ToUsing) |
| 3453 | return nullptr; |
| 3454 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3455 | auto *ToTarget = dyn_cast_or_null<NamedDecl>( |
| 3456 | Importer.Import(D->getTargetDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3457 | if (!ToTarget) |
| 3458 | return nullptr; |
| 3459 | |
| 3460 | UsingShadowDecl *ToShadow = UsingShadowDecl::Create( |
| 3461 | Importer.getToContext(), DC, Loc, ToUsing, ToTarget); |
| 3462 | |
| 3463 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 3464 | ToShadow->setAccess(D->getAccess()); |
| 3465 | Importer.Imported(D, ToShadow); |
| 3466 | |
| 3467 | if (UsingShadowDecl *FromPattern = |
| 3468 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3469 | if (auto *ToPattern = |
| 3470 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromPattern))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3471 | Importer.getToContext().setInstantiatedFromUsingShadowDecl(ToShadow, |
| 3472 | ToPattern); |
| 3473 | else |
| 3474 | // FIXME: We return a nullptr here but the definition is already created |
| 3475 | // and available with lookups. How to fix this?.. |
| 3476 | return nullptr; |
| 3477 | } |
| 3478 | |
| 3479 | LexicalDC->addDeclInternal(ToShadow); |
| 3480 | |
| 3481 | return ToShadow; |
| 3482 | } |
| 3483 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3484 | Decl *ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 3485 | DeclContext *DC, *LexicalDC; |
| 3486 | DeclarationName Name; |
| 3487 | SourceLocation Loc; |
| 3488 | NamedDecl *ToD = nullptr; |
| 3489 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3490 | return nullptr; |
| 3491 | if (ToD) |
| 3492 | return ToD; |
| 3493 | |
| 3494 | DeclContext *ToComAncestor = Importer.ImportContext(D->getCommonAncestor()); |
| 3495 | if (!ToComAncestor) |
| 3496 | return nullptr; |
| 3497 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3498 | auto *ToNominated = cast_or_null<NamespaceDecl>( |
| 3499 | Importer.Import(D->getNominatedNamespace())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3500 | if (!ToNominated) |
| 3501 | return nullptr; |
| 3502 | |
| 3503 | UsingDirectiveDecl *ToUsingDir = UsingDirectiveDecl::Create( |
| 3504 | Importer.getToContext(), DC, Importer.Import(D->getUsingLoc()), |
| 3505 | Importer.Import(D->getNamespaceKeyLocation()), |
| 3506 | Importer.Import(D->getQualifierLoc()), |
| 3507 | Importer.Import(D->getIdentLocation()), ToNominated, ToComAncestor); |
| 3508 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 3509 | LexicalDC->addDeclInternal(ToUsingDir); |
| 3510 | Importer.Imported(D, ToUsingDir); |
| 3511 | |
| 3512 | return ToUsingDir; |
| 3513 | } |
| 3514 | |
| 3515 | Decl *ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
| 3516 | UnresolvedUsingValueDecl *D) { |
| 3517 | DeclContext *DC, *LexicalDC; |
| 3518 | DeclarationName Name; |
| 3519 | SourceLocation Loc; |
| 3520 | NamedDecl *ToD = nullptr; |
| 3521 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3522 | return nullptr; |
| 3523 | if (ToD) |
| 3524 | return ToD; |
| 3525 | |
| 3526 | DeclarationNameInfo NameInfo(Name, Importer.Import(D->getNameInfo().getLoc())); |
| 3527 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3528 | |
| 3529 | UnresolvedUsingValueDecl *ToUsingValue = UnresolvedUsingValueDecl::Create( |
| 3530 | Importer.getToContext(), DC, Importer.Import(D->getUsingLoc()), |
| 3531 | Importer.Import(D->getQualifierLoc()), NameInfo, |
| 3532 | Importer.Import(D->getEllipsisLoc())); |
| 3533 | |
| 3534 | Importer.Imported(D, ToUsingValue); |
| 3535 | ToUsingValue->setAccess(D->getAccess()); |
| 3536 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 3537 | LexicalDC->addDeclInternal(ToUsingValue); |
| 3538 | |
| 3539 | return ToUsingValue; |
| 3540 | } |
| 3541 | |
| 3542 | Decl *ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
| 3543 | UnresolvedUsingTypenameDecl *D) { |
| 3544 | DeclContext *DC, *LexicalDC; |
| 3545 | DeclarationName Name; |
| 3546 | SourceLocation Loc; |
| 3547 | NamedDecl *ToD = nullptr; |
| 3548 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3549 | return nullptr; |
| 3550 | if (ToD) |
| 3551 | return ToD; |
| 3552 | |
| 3553 | UnresolvedUsingTypenameDecl *ToUsing = UnresolvedUsingTypenameDecl::Create( |
| 3554 | Importer.getToContext(), DC, Importer.Import(D->getUsingLoc()), |
| 3555 | Importer.Import(D->getTypenameLoc()), |
| 3556 | Importer.Import(D->getQualifierLoc()), Loc, Name, |
| 3557 | Importer.Import(D->getEllipsisLoc())); |
| 3558 | |
| 3559 | Importer.Imported(D, ToUsing); |
| 3560 | ToUsing->setAccess(D->getAccess()); |
| 3561 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3562 | LexicalDC->addDeclInternal(ToUsing); |
| 3563 | |
| 3564 | return ToUsing; |
| 3565 | } |
| 3566 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3567 | bool ASTNodeImporter::ImportDefinition(ObjCInterfaceDecl *From, |
| 3568 | ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3569 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3570 | if (To->getDefinition()) { |
| 3571 | // Check consistency of superclass. |
| 3572 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 3573 | if (FromSuper) { |
| 3574 | FromSuper = cast_or_null<ObjCInterfaceDecl>(Importer.Import(FromSuper)); |
| 3575 | if (!FromSuper) |
| 3576 | return true; |
| 3577 | } |
| 3578 | |
| 3579 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
| 3580 | if ((bool)FromSuper != (bool)ToSuper || |
| 3581 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
| 3582 | Importer.ToDiag(To->getLocation(), |
| 3583 | diag::err_odr_objc_superclass_inconsistent) |
| 3584 | << To->getDeclName(); |
| 3585 | if (ToSuper) |
| 3586 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 3587 | << To->getSuperClass()->getDeclName(); |
| 3588 | else |
| 3589 | Importer.ToDiag(To->getLocation(), |
| 3590 | diag::note_odr_objc_missing_superclass); |
| 3591 | if (From->getSuperClass()) |
| 3592 | Importer.FromDiag(From->getSuperClassLoc(), |
| 3593 | diag::note_odr_objc_superclass) |
| 3594 | << From->getSuperClass()->getDeclName(); |
| 3595 | else |
| 3596 | Importer.FromDiag(From->getLocation(), |
| 3597 | diag::note_odr_objc_missing_superclass); |
| 3598 | } |
| 3599 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3600 | if (shouldForceImportDeclContext(Kind)) |
| 3601 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3602 | return false; |
| 3603 | } |
| 3604 | |
| 3605 | // Start the definition. |
| 3606 | To->startDefinition(); |
| 3607 | |
| 3608 | // If this class has a superclass, import it. |
| 3609 | if (From->getSuperClass()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3610 | TypeSourceInfo *SuperTInfo = Importer.Import(From->getSuperClassTInfo()); |
| 3611 | if (!SuperTInfo) |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3612 | return true; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3613 | |
| 3614 | To->setSuperClass(SuperTInfo); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3615 | } |
| 3616 | |
| 3617 | // Import protocols |
| 3618 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3619 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 3620 | ObjCInterfaceDecl::protocol_loc_iterator |
| 3621 | FromProtoLoc = From->protocol_loc_begin(); |
| 3622 | |
| 3623 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3624 | FromProtoEnd = From->protocol_end(); |
| 3625 | FromProto != FromProtoEnd; |
| 3626 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3627 | auto *ToProto = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3628 | if (!ToProto) |
| 3629 | return true; |
| 3630 | Protocols.push_back(ToProto); |
| 3631 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3632 | } |
| 3633 | |
| 3634 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3635 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3636 | ProtocolLocs.data(), Importer.getToContext()); |
| 3637 | |
| 3638 | // Import categories. When the categories themselves are imported, they'll |
| 3639 | // hook themselves into this interface. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 3640 | for (auto *Cat : From->known_categories()) |
| 3641 | Importer.Import(Cat); |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 3642 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3643 | // If we have an @implementation, import it as well. |
| 3644 | if (From->getImplementation()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3645 | auto *Impl = cast_or_null<ObjCImplementationDecl>( |
| 3646 | Importer.Import(From->getImplementation())); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3647 | if (!Impl) |
| 3648 | return true; |
| 3649 | |
| 3650 | To->setImplementation(Impl); |
| 3651 | } |
| 3652 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3653 | if (shouldForceImportDeclContext(Kind)) { |
| 3654 | // Import all of the members of this class. |
| 3655 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3656 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3657 | return false; |
| 3658 | } |
| 3659 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3660 | ObjCTypeParamList * |
| 3661 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 3662 | if (!list) |
| 3663 | return nullptr; |
| 3664 | |
| 3665 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
| 3666 | for (auto fromTypeParam : *list) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3667 | auto *toTypeParam = cast_or_null<ObjCTypeParamDecl>( |
| 3668 | Importer.Import(fromTypeParam)); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3669 | if (!toTypeParam) |
| 3670 | return nullptr; |
| 3671 | |
| 3672 | toTypeParams.push_back(toTypeParam); |
| 3673 | } |
| 3674 | |
| 3675 | return ObjCTypeParamList::create(Importer.getToContext(), |
| 3676 | Importer.Import(list->getLAngleLoc()), |
| 3677 | toTypeParams, |
| 3678 | Importer.Import(list->getRAngleLoc())); |
| 3679 | } |
| 3680 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3681 | Decl *ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3682 | // If this class has a definition in the translation unit we're coming from, |
| 3683 | // but this particular declaration is not that definition, import the |
| 3684 | // definition and map to that. |
| 3685 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 3686 | if (Definition && Definition != D) { |
| 3687 | Decl *ImportedDef = Importer.Import(Definition); |
| 3688 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3689 | return nullptr; |
| 3690 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3691 | return Importer.Imported(D, ImportedDef); |
| 3692 | } |
| 3693 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3694 | // Import the major distinguishing characteristics of an @interface. |
| 3695 | DeclContext *DC, *LexicalDC; |
| 3696 | DeclarationName Name; |
| 3697 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3698 | NamedDecl *ToD; |
| 3699 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3700 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3701 | if (ToD) |
| 3702 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3703 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3704 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3705 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3706 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3707 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3708 | for (auto *FoundDecl : FoundDecls) { |
| 3709 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3710 | continue; |
| 3711 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3712 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3713 | break; |
| 3714 | } |
| 3715 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3716 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3717 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3718 | if (!ToIface) { |
| 3719 | ToIface = ObjCInterfaceDecl::Create(Importer.getToContext(), DC, |
| 3720 | Importer.Import(D->getAtStartLoc()), |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3721 | Name.getAsIdentifierInfo(), |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3722 | /*TypeParamList=*/nullptr, |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3723 | /*PrevDecl=*/nullptr, Loc, |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3724 | D->isImplicitInterfaceDecl()); |
| 3725 | ToIface->setLexicalDeclContext(LexicalDC); |
| 3726 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3727 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3728 | Importer.Imported(D, ToIface); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3729 | // Import the type parameter list after calling Imported, to avoid |
| 3730 | // loops when bringing in their DeclContext. |
| 3731 | ToIface->setTypeParamList(ImportObjCTypeParamList( |
| 3732 | D->getTypeParamListAsWritten())); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3733 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3734 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToIface)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3735 | return nullptr; |
| 3736 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3737 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3738 | } |
| 3739 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3740 | Decl *ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3741 | auto *Category = cast_or_null<ObjCCategoryDecl>( |
| 3742 | Importer.Import(D->getCategoryDecl())); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3743 | if (!Category) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3744 | return nullptr; |
| 3745 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3746 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 3747 | if (!ToImpl) { |
| 3748 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3749 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3750 | return nullptr; |
| 3751 | |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 3752 | SourceLocation CategoryNameLoc = Importer.Import(D->getCategoryNameLoc()); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3753 | ToImpl = ObjCCategoryImplDecl::Create(Importer.getToContext(), DC, |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3754 | Importer.Import(D->getIdentifier()), |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3755 | Category->getClassInterface(), |
| 3756 | Importer.Import(D->getLocation()), |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 3757 | Importer.Import(D->getAtStartLoc()), |
| 3758 | CategoryNameLoc); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3759 | |
| 3760 | DeclContext *LexicalDC = DC; |
| 3761 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3762 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3763 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3764 | return nullptr; |
| 3765 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3766 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 3767 | } |
| 3768 | |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3769 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3770 | Category->setImplementation(ToImpl); |
| 3771 | } |
| 3772 | |
| 3773 | Importer.Imported(D, ToImpl); |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3774 | ImportDeclContext(D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3775 | return ToImpl; |
| 3776 | } |
| 3777 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3778 | Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 3779 | // Find the corresponding interface. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3780 | auto *Iface = cast_or_null<ObjCInterfaceDecl>( |
| 3781 | Importer.Import(D->getClassInterface())); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3782 | if (!Iface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3783 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3784 | |
| 3785 | // Import the superclass, if any. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3786 | ObjCInterfaceDecl *Super = nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3787 | if (D->getSuperClass()) { |
| 3788 | Super = cast_or_null<ObjCInterfaceDecl>( |
| 3789 | Importer.Import(D->getSuperClass())); |
| 3790 | if (!Super) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3791 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3792 | } |
| 3793 | |
| 3794 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 3795 | if (!Impl) { |
| 3796 | // We haven't imported an implementation yet. Create a new @implementation |
| 3797 | // now. |
| 3798 | Impl = ObjCImplementationDecl::Create(Importer.getToContext(), |
| 3799 | Importer.ImportContext(D->getDeclContext()), |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3800 | Iface, Super, |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3801 | Importer.Import(D->getLocation()), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3802 | Importer.Import(D->getAtStartLoc()), |
Argyrios Kyrtzidis | 5d2ce84 | 2013-05-03 22:31:26 +0000 | [diff] [blame] | 3803 | Importer.Import(D->getSuperClassLoc()), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3804 | Importer.Import(D->getIvarLBraceLoc()), |
| 3805 | Importer.Import(D->getIvarRBraceLoc())); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3806 | |
| 3807 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3808 | DeclContext *LexicalDC |
| 3809 | = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3810 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3811 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3812 | Impl->setLexicalDeclContext(LexicalDC); |
| 3813 | } |
| 3814 | |
| 3815 | // Associate the implementation with the class it implements. |
| 3816 | Iface->setImplementation(Impl); |
| 3817 | Importer.Imported(D, Iface->getImplementation()); |
| 3818 | } else { |
| 3819 | Importer.Imported(D, Iface->getImplementation()); |
| 3820 | |
| 3821 | // Verify that the existing @implementation has the same superclass. |
| 3822 | if ((Super && !Impl->getSuperClass()) || |
| 3823 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 3824 | (Super && Impl->getSuperClass() && |
| 3825 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 3826 | Impl->getSuperClass()))) { |
| 3827 | Importer.ToDiag(Impl->getLocation(), |
| 3828 | diag::err_odr_objc_superclass_inconsistent) |
| 3829 | << Iface->getDeclName(); |
| 3830 | // FIXME: It would be nice to have the location of the superclass |
| 3831 | // below. |
| 3832 | if (Impl->getSuperClass()) |
| 3833 | Importer.ToDiag(Impl->getLocation(), |
| 3834 | diag::note_odr_objc_superclass) |
| 3835 | << Impl->getSuperClass()->getDeclName(); |
| 3836 | else |
| 3837 | Importer.ToDiag(Impl->getLocation(), |
| 3838 | diag::note_odr_objc_missing_superclass); |
| 3839 | if (D->getSuperClass()) |
| 3840 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3841 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 3842 | << D->getSuperClass()->getDeclName(); |
| 3843 | else |
| 3844 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3845 | diag::note_odr_objc_missing_superclass); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3846 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3847 | } |
| 3848 | } |
| 3849 | |
| 3850 | // Import all of the members of this @implementation. |
| 3851 | ImportDeclContext(D); |
| 3852 | |
| 3853 | return Impl; |
| 3854 | } |
| 3855 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3856 | Decl *ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 3857 | // Import the major distinguishing characteristics of an @property. |
| 3858 | DeclContext *DC, *LexicalDC; |
| 3859 | DeclarationName Name; |
| 3860 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3861 | NamedDecl *ToD; |
| 3862 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3863 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3864 | if (ToD) |
| 3865 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3866 | |
| 3867 | // Check whether we have already imported this property. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3868 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3869 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3870 | for (auto *FoundDecl : FoundDecls) { |
| 3871 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3872 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3873 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3874 | FoundProp->getType())) { |
| 3875 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) |
| 3876 | << Name << D->getType() << FoundProp->getType(); |
| 3877 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 3878 | << FoundProp->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3879 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3880 | } |
| 3881 | |
| 3882 | // FIXME: Check property attributes, getters, setters, etc.? |
| 3883 | |
| 3884 | // Consider these properties to be equivalent. |
| 3885 | Importer.Imported(D, FoundProp); |
| 3886 | return FoundProp; |
| 3887 | } |
| 3888 | } |
| 3889 | |
| 3890 | // Import the type. |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 3891 | TypeSourceInfo *TSI = Importer.Import(D->getTypeSourceInfo()); |
| 3892 | if (!TSI) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3893 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3894 | |
| 3895 | // Create the new property. |
| 3896 | ObjCPropertyDecl *ToProperty |
| 3897 | = ObjCPropertyDecl::Create(Importer.getToContext(), DC, Loc, |
| 3898 | Name.getAsIdentifierInfo(), |
| 3899 | Importer.Import(D->getAtLoc()), |
Fariborz Jahanian | 86c2f5c | 2012-02-29 22:18:55 +0000 | [diff] [blame] | 3900 | Importer.Import(D->getLParenLoc()), |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 3901 | Importer.Import(D->getType()), |
| 3902 | TSI, |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3903 | D->getPropertyImplementation()); |
| 3904 | Importer.Imported(D, ToProperty); |
| 3905 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3906 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3907 | |
| 3908 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 3909 | ToProperty->setPropertyAttributesAsWritten( |
| 3910 | D->getPropertyAttributesAsWritten()); |
Argyrios Kyrtzidis | 194b28e | 2017-03-16 18:25:40 +0000 | [diff] [blame] | 3911 | ToProperty->setGetterName(Importer.Import(D->getGetterName()), |
| 3912 | Importer.Import(D->getGetterNameLoc())); |
| 3913 | ToProperty->setSetterName(Importer.Import(D->getSetterName()), |
| 3914 | Importer.Import(D->getSetterNameLoc())); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3915 | ToProperty->setGetterMethodDecl( |
| 3916 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getGetterMethodDecl()))); |
| 3917 | ToProperty->setSetterMethodDecl( |
| 3918 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getSetterMethodDecl()))); |
| 3919 | ToProperty->setPropertyIvarDecl( |
| 3920 | cast_or_null<ObjCIvarDecl>(Importer.Import(D->getPropertyIvarDecl()))); |
| 3921 | return ToProperty; |
| 3922 | } |
| 3923 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3924 | Decl *ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3925 | auto *Property = cast_or_null<ObjCPropertyDecl>( |
| 3926 | Importer.Import(D->getPropertyDecl())); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3927 | if (!Property) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3928 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3929 | |
| 3930 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3931 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3932 | return nullptr; |
| 3933 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3934 | // Import the lexical declaration context. |
| 3935 | DeclContext *LexicalDC = DC; |
| 3936 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3937 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3938 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3939 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3940 | } |
| 3941 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3942 | auto *InImpl = dyn_cast<ObjCImplDecl>(LexicalDC); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3943 | if (!InImpl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3944 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3945 | |
| 3946 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3947 | ObjCIvarDecl *Ivar = nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3948 | if (D->getPropertyIvarDecl()) { |
| 3949 | Ivar = cast_or_null<ObjCIvarDecl>( |
| 3950 | Importer.Import(D->getPropertyIvarDecl())); |
| 3951 | if (!Ivar) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3952 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 3956 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 3957 | Property->getQueryKind()); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3958 | if (!ToImpl) { |
| 3959 | ToImpl = ObjCPropertyImplDecl::Create(Importer.getToContext(), DC, |
| 3960 | Importer.Import(D->getLocStart()), |
| 3961 | Importer.Import(D->getLocation()), |
| 3962 | Property, |
| 3963 | D->getPropertyImplementation(), |
| 3964 | Ivar, |
| 3965 | Importer.Import(D->getPropertyIvarDeclLoc())); |
| 3966 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 3967 | Importer.Imported(D, ToImpl); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3968 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3969 | } else { |
| 3970 | // Check that we have the same kind of property implementation (@synthesize |
| 3971 | // vs. @dynamic). |
| 3972 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
| 3973 | Importer.ToDiag(ToImpl->getLocation(), |
| 3974 | diag::err_odr_objc_property_impl_kind_inconsistent) |
| 3975 | << Property->getDeclName() |
| 3976 | << (ToImpl->getPropertyImplementation() |
| 3977 | == ObjCPropertyImplDecl::Dynamic); |
| 3978 | Importer.FromDiag(D->getLocation(), |
| 3979 | diag::note_odr_objc_property_impl_kind) |
| 3980 | << D->getPropertyDecl()->getDeclName() |
| 3981 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3982 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3983 | } |
| 3984 | |
| 3985 | // For @synthesize, check that we have the same |
| 3986 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 3987 | Ivar != ToImpl->getPropertyIvarDecl()) { |
| 3988 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
| 3989 | diag::err_odr_objc_synthesize_ivar_inconsistent) |
| 3990 | << Property->getDeclName() |
| 3991 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 3992 | << Ivar->getDeclName(); |
| 3993 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
| 3994 | diag::note_odr_objc_synthesize_ivar_here) |
| 3995 | << D->getPropertyIvarDecl()->getDeclName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3996 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3997 | } |
| 3998 | |
| 3999 | // Merge the existing implementation with the new implementation. |
| 4000 | Importer.Imported(D, ToImpl); |
| 4001 | } |
| 4002 | |
| 4003 | return ToImpl; |
| 4004 | } |
| 4005 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4006 | Decl *ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 4007 | // For template arguments, we adopt the translation unit as our declaration |
| 4008 | // context. This context will be fixed when the actual template declaration |
| 4009 | // is created. |
| 4010 | |
| 4011 | // FIXME: Import default argument. |
| 4012 | return TemplateTypeParmDecl::Create(Importer.getToContext(), |
| 4013 | Importer.getToContext().getTranslationUnitDecl(), |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 4014 | Importer.Import(D->getLocStart()), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4015 | Importer.Import(D->getLocation()), |
| 4016 | D->getDepth(), |
| 4017 | D->getIndex(), |
| 4018 | Importer.Import(D->getIdentifier()), |
| 4019 | D->wasDeclaredWithTypename(), |
| 4020 | D->isParameterPack()); |
| 4021 | } |
| 4022 | |
| 4023 | Decl * |
| 4024 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 4025 | // Import the name of this declaration. |
| 4026 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 4027 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4028 | return nullptr; |
| 4029 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4030 | // Import the location of this declaration. |
| 4031 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 4032 | |
| 4033 | // Import the type of this declaration. |
| 4034 | QualType T = Importer.Import(D->getType()); |
| 4035 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4036 | return nullptr; |
| 4037 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4038 | // Import type-source information. |
| 4039 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 4040 | if (D->getTypeSourceInfo() && !TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4041 | return nullptr; |
| 4042 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4043 | // FIXME: Import default argument. |
| 4044 | |
| 4045 | return NonTypeTemplateParmDecl::Create(Importer.getToContext(), |
| 4046 | Importer.getToContext().getTranslationUnitDecl(), |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 4047 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4048 | Loc, D->getDepth(), D->getPosition(), |
| 4049 | Name.getAsIdentifierInfo(), |
Douglas Gregor | da3cc0d | 2010-12-23 23:51:58 +0000 | [diff] [blame] | 4050 | T, D->isParameterPack(), TInfo); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | Decl * |
| 4054 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 4055 | // Import the name of this declaration. |
| 4056 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 4057 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4058 | return nullptr; |
| 4059 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4060 | // Import the location of this declaration. |
| 4061 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 4062 | |
| 4063 | // Import template parameters. |
| 4064 | TemplateParameterList *TemplateParams |
| 4065 | = ImportTemplateParameterList(D->getTemplateParameters()); |
| 4066 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4067 | return nullptr; |
| 4068 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4069 | // FIXME: Import default argument. |
| 4070 | |
| 4071 | return TemplateTemplateParmDecl::Create(Importer.getToContext(), |
| 4072 | Importer.getToContext().getTranslationUnitDecl(), |
| 4073 | Loc, D->getDepth(), D->getPosition(), |
Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 4074 | D->isParameterPack(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4075 | Name.getAsIdentifierInfo(), |
| 4076 | TemplateParams); |
| 4077 | } |
| 4078 | |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4079 | // Returns the definition for a (forward) declaration of a ClassTemplateDecl, if |
| 4080 | // it has any definition in the redecl chain. |
| 4081 | static ClassTemplateDecl *getDefinition(ClassTemplateDecl *D) { |
| 4082 | CXXRecordDecl *ToTemplatedDef = D->getTemplatedDecl()->getDefinition(); |
| 4083 | if (!ToTemplatedDef) |
| 4084 | return nullptr; |
| 4085 | ClassTemplateDecl *TemplateWithDef = |
| 4086 | ToTemplatedDef->getDescribedClassTemplate(); |
| 4087 | return TemplateWithDef; |
| 4088 | } |
| 4089 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4090 | Decl *ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 4091 | // If this record has a definition in the translation unit we're coming from, |
| 4092 | // but this particular declaration is not that definition, import the |
| 4093 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4094 | auto *Definition = |
| 4095 | cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4096 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 4097 | Decl *ImportedDef |
| 4098 | = Importer.Import(Definition->getDescribedClassTemplate()); |
| 4099 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4100 | return nullptr; |
| 4101 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4102 | return Importer.Imported(D, ImportedDef); |
| 4103 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4104 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4105 | // Import the major distinguishing characteristics of this class template. |
| 4106 | DeclContext *DC, *LexicalDC; |
| 4107 | DeclarationName Name; |
| 4108 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4109 | NamedDecl *ToD; |
| 4110 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4111 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4112 | if (ToD) |
| 4113 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4114 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4115 | // We may already have a template of the same name; try to find and match it. |
| 4116 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4117 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4118 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4119 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4120 | for (auto *FoundDecl : FoundDecls) { |
| 4121 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4122 | continue; |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4123 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4124 | Decl *Found = FoundDecl; |
| 4125 | if (auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found)) { |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4126 | |
| 4127 | // The class to be imported is a definition. |
| 4128 | if (D->isThisDeclarationADefinition()) { |
| 4129 | // Lookup will find the fwd decl only if that is more recent than the |
| 4130 | // definition. So, try to get the definition if that is available in |
| 4131 | // the redecl chain. |
| 4132 | ClassTemplateDecl *TemplateWithDef = getDefinition(FoundTemplate); |
| 4133 | if (!TemplateWithDef) |
| 4134 | continue; |
| 4135 | FoundTemplate = TemplateWithDef; // Continue with the definition. |
| 4136 | } |
| 4137 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4138 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 4139 | // The class templates structurally match; call it the same template. |
Aleksei Sidorin | 761c224 | 2018-05-15 11:09:07 +0000 | [diff] [blame] | 4140 | |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4141 | Importer.Imported(D->getTemplatedDecl(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4142 | FoundTemplate->getTemplatedDecl()); |
| 4143 | return Importer.Imported(D, FoundTemplate); |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4144 | } |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4145 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4146 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4147 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4148 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4149 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4150 | if (!ConflictingDecls.empty()) { |
| 4151 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4152 | ConflictingDecls.data(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4153 | ConflictingDecls.size()); |
| 4154 | } |
Gabor Marton | 9581c33 | 2018-05-23 13:53:36 +0000 | [diff] [blame] | 4155 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4156 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4157 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4158 | } |
| 4159 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4160 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 4161 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4162 | // Create the declaration that is being templated. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4163 | auto *ToTemplated = cast_or_null<CXXRecordDecl>( |
| 4164 | Importer.Import(FromTemplated)); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4165 | if (!ToTemplated) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4166 | return nullptr; |
| 4167 | |
| 4168 | // Resolve possible cyclic import. |
| 4169 | if (Decl *AlreadyImported = Importer.GetAlreadyImportedOrNull(D)) |
| 4170 | return AlreadyImported; |
| 4171 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4172 | // Create the class template declaration itself. |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4173 | TemplateParameterList *TemplateParams = |
| 4174 | ImportTemplateParameterList(D->getTemplateParameters()); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4175 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4176 | return nullptr; |
| 4177 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4178 | ClassTemplateDecl *D2 = ClassTemplateDecl::Create(Importer.getToContext(), DC, |
| 4179 | Loc, Name, TemplateParams, |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4180 | ToTemplated); |
| 4181 | ToTemplated->setDescribedClassTemplate(D2); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4182 | |
| 4183 | D2->setAccess(D->getAccess()); |
| 4184 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4185 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4186 | |
| 4187 | // Note the relationship between the class templates. |
| 4188 | Importer.Imported(D, D2); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4189 | Importer.Imported(FromTemplated, ToTemplated); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4190 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4191 | if (FromTemplated->isCompleteDefinition() && |
| 4192 | !ToTemplated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4193 | // FIXME: Import definition! |
| 4194 | } |
| 4195 | |
| 4196 | return D2; |
| 4197 | } |
| 4198 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4199 | Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
| 4200 | ClassTemplateSpecializationDecl *D) { |
| 4201 | // If this record has a definition in the translation unit we're coming from, |
| 4202 | // but this particular declaration is not that definition, import the |
| 4203 | // definition and map to that. |
| 4204 | TagDecl *Definition = D->getDefinition(); |
| 4205 | if (Definition && Definition != D) { |
| 4206 | Decl *ImportedDef = Importer.Import(Definition); |
| 4207 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4208 | return nullptr; |
| 4209 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4210 | return Importer.Imported(D, ImportedDef); |
| 4211 | } |
| 4212 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4213 | auto *ClassTemplate = |
| 4214 | cast_or_null<ClassTemplateDecl>(Importer.Import( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4215 | D->getSpecializedTemplate())); |
| 4216 | if (!ClassTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4217 | return nullptr; |
| 4218 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4219 | // Import the context of this declaration. |
| 4220 | DeclContext *DC = ClassTemplate->getDeclContext(); |
| 4221 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4222 | return nullptr; |
| 4223 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4224 | DeclContext *LexicalDC = DC; |
| 4225 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4226 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4227 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4228 | return nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4229 | } |
| 4230 | |
| 4231 | // Import the location of this declaration. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 4232 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 4233 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4234 | |
| 4235 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4236 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4237 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 4238 | D->getTemplateArgs().size(), |
| 4239 | TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4240 | return nullptr; |
| 4241 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4242 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4243 | void *InsertPos = nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4244 | ClassTemplateSpecializationDecl *D2 |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 4245 | = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4246 | if (D2) { |
| 4247 | // We already have a class template specialization with these template |
| 4248 | // arguments. |
| 4249 | |
| 4250 | // FIXME: Check for specialization vs. instantiation errors. |
| 4251 | |
| 4252 | if (RecordDecl *FoundDef = D2->getDefinition()) { |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4253 | if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4254 | // The record types structurally match, or the "from" translation |
| 4255 | // unit only had a forward declaration anyway; call it the same |
| 4256 | // function. |
| 4257 | return Importer.Imported(D, FoundDef); |
| 4258 | } |
| 4259 | } |
| 4260 | } else { |
| 4261 | // Create a new specialization. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4262 | if (auto *PartialSpec = |
| 4263 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4264 | // Import TemplateArgumentListInfo |
| 4265 | TemplateArgumentListInfo ToTAInfo; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4266 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 4267 | if (ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4268 | return nullptr; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4269 | |
| 4270 | QualType CanonInjType = Importer.Import( |
| 4271 | PartialSpec->getInjectedSpecializationType()); |
| 4272 | if (CanonInjType.isNull()) |
| 4273 | return nullptr; |
| 4274 | CanonInjType = CanonInjType.getCanonicalType(); |
| 4275 | |
| 4276 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 4277 | PartialSpec->getTemplateParameters()); |
| 4278 | if (!ToTPList && PartialSpec->getTemplateParameters()) |
| 4279 | return nullptr; |
| 4280 | |
| 4281 | D2 = ClassTemplatePartialSpecializationDecl::Create( |
| 4282 | Importer.getToContext(), D->getTagKind(), DC, StartLoc, IdLoc, |
| 4283 | ToTPList, ClassTemplate, |
| 4284 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 4285 | ToTAInfo, CanonInjType, nullptr); |
| 4286 | |
| 4287 | } else { |
| 4288 | D2 = ClassTemplateSpecializationDecl::Create(Importer.getToContext(), |
| 4289 | D->getTagKind(), DC, |
| 4290 | StartLoc, IdLoc, |
| 4291 | ClassTemplate, |
| 4292 | TemplateArgs, |
| 4293 | /*PrevDecl=*/nullptr); |
| 4294 | } |
| 4295 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4296 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 4297 | |
| 4298 | // Add this specialization to the class template. |
| 4299 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 4300 | |
| 4301 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4302 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4303 | |
| 4304 | Importer.Imported(D, D2); |
| 4305 | |
| 4306 | if (auto *TSI = D->getTypeAsWritten()) { |
| 4307 | TypeSourceInfo *TInfo = Importer.Import(TSI); |
| 4308 | if (!TInfo) |
| 4309 | return nullptr; |
| 4310 | D2->setTypeAsWritten(TInfo); |
| 4311 | D2->setTemplateKeywordLoc(Importer.Import(D->getTemplateKeywordLoc())); |
| 4312 | D2->setExternLoc(Importer.Import(D->getExternLoc())); |
| 4313 | } |
| 4314 | |
| 4315 | SourceLocation POI = Importer.Import(D->getPointOfInstantiation()); |
| 4316 | if (POI.isValid()) |
| 4317 | D2->setPointOfInstantiation(POI); |
| 4318 | else if (D->getPointOfInstantiation().isValid()) |
| 4319 | return nullptr; |
| 4320 | |
| 4321 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 4322 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4323 | // Add the specialization to this context. |
| 4324 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4325 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4326 | } |
| 4327 | Importer.Imported(D, D2); |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4328 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4329 | return nullptr; |
| 4330 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4331 | return D2; |
| 4332 | } |
| 4333 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4334 | Decl *ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| 4335 | // If this variable has a definition in the translation unit we're coming |
| 4336 | // from, |
| 4337 | // but this particular declaration is not that definition, import the |
| 4338 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4339 | auto *Definition = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4340 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 4341 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 4342 | Decl *ImportedDef = Importer.Import(Definition->getDescribedVarTemplate()); |
| 4343 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4344 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4345 | |
| 4346 | return Importer.Imported(D, ImportedDef); |
| 4347 | } |
| 4348 | |
| 4349 | // Import the major distinguishing characteristics of this variable template. |
| 4350 | DeclContext *DC, *LexicalDC; |
| 4351 | DeclarationName Name; |
| 4352 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4353 | NamedDecl *ToD; |
| 4354 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4355 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4356 | if (ToD) |
| 4357 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4358 | |
| 4359 | // We may already have a template of the same name; try to find and match it. |
| 4360 | assert(!DC->isFunctionOrMethod() && |
| 4361 | "Variable templates cannot be declared at function scope"); |
| 4362 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 4363 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4364 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4365 | for (auto *FoundDecl : FoundDecls) { |
| 4366 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4367 | continue; |
| 4368 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4369 | Decl *Found = FoundDecl; |
| 4370 | if (auto *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4371 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 4372 | // The variable templates structurally match; call it the same template. |
| 4373 | Importer.Imported(D->getTemplatedDecl(), |
| 4374 | FoundTemplate->getTemplatedDecl()); |
| 4375 | return Importer.Imported(D, FoundTemplate); |
| 4376 | } |
| 4377 | } |
| 4378 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4379 | ConflictingDecls.push_back(FoundDecl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4380 | } |
| 4381 | |
| 4382 | if (!ConflictingDecls.empty()) { |
| 4383 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 4384 | ConflictingDecls.data(), |
| 4385 | ConflictingDecls.size()); |
| 4386 | } |
| 4387 | |
| 4388 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4389 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4390 | |
| 4391 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 4392 | |
| 4393 | // Import the type. |
| 4394 | QualType T = Importer.Import(DTemplated->getType()); |
| 4395 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4396 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4397 | |
| 4398 | // Create the declaration that is being templated. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4399 | auto *ToTemplated = dyn_cast_or_null<VarDecl>(Importer.Import(DTemplated)); |
| 4400 | if (!ToTemplated) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4401 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4402 | |
| 4403 | // Create the variable template declaration itself. |
| 4404 | TemplateParameterList *TemplateParams = |
| 4405 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4406 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4407 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4408 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4409 | VarTemplateDecl *ToVarTD = VarTemplateDecl::Create( |
| 4410 | Importer.getToContext(), DC, Loc, Name, TemplateParams, ToTemplated); |
| 4411 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4412 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4413 | ToVarTD->setAccess(D->getAccess()); |
| 4414 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 4415 | LexicalDC->addDeclInternal(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4416 | |
| 4417 | // Note the relationship between the variable templates. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4418 | Importer.Imported(D, ToVarTD); |
| 4419 | Importer.Imported(DTemplated, ToTemplated); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4420 | |
| 4421 | if (DTemplated->isThisDeclarationADefinition() && |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4422 | !ToTemplated->isThisDeclarationADefinition()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4423 | // FIXME: Import definition! |
| 4424 | } |
| 4425 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4426 | return ToVarTD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4427 | } |
| 4428 | |
| 4429 | Decl *ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
| 4430 | VarTemplateSpecializationDecl *D) { |
| 4431 | // If this record has a definition in the translation unit we're coming from, |
| 4432 | // but this particular declaration is not that definition, import the |
| 4433 | // definition and map to that. |
| 4434 | VarDecl *Definition = D->getDefinition(); |
| 4435 | if (Definition && Definition != D) { |
| 4436 | Decl *ImportedDef = Importer.Import(Definition); |
| 4437 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4438 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4439 | |
| 4440 | return Importer.Imported(D, ImportedDef); |
| 4441 | } |
| 4442 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4443 | auto *VarTemplate = cast_or_null<VarTemplateDecl>( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4444 | Importer.Import(D->getSpecializedTemplate())); |
| 4445 | if (!VarTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4446 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4447 | |
| 4448 | // Import the context of this declaration. |
| 4449 | DeclContext *DC = VarTemplate->getDeclContext(); |
| 4450 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4451 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4452 | |
| 4453 | DeclContext *LexicalDC = DC; |
| 4454 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4455 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4456 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4457 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4458 | } |
| 4459 | |
| 4460 | // Import the location of this declaration. |
| 4461 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 4462 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
| 4463 | |
| 4464 | // Import template arguments. |
| 4465 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| 4466 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 4467 | D->getTemplateArgs().size(), TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4468 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4469 | |
| 4470 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4471 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4472 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 4473 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4474 | if (D2) { |
| 4475 | // We already have a variable template specialization with these template |
| 4476 | // arguments. |
| 4477 | |
| 4478 | // FIXME: Check for specialization vs. instantiation errors. |
| 4479 | |
| 4480 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 4481 | if (!D->isThisDeclarationADefinition() || |
| 4482 | IsStructuralMatch(D, FoundDef)) { |
| 4483 | // The record types structurally match, or the "from" translation |
| 4484 | // unit only had a forward declaration anyway; call it the same |
| 4485 | // variable. |
| 4486 | return Importer.Imported(D, FoundDef); |
| 4487 | } |
| 4488 | } |
| 4489 | } else { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4490 | // Import the type. |
| 4491 | QualType T = Importer.Import(D->getType()); |
| 4492 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4493 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4494 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4495 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 4496 | if (D->getTypeSourceInfo() && !TInfo) |
| 4497 | return nullptr; |
| 4498 | |
| 4499 | TemplateArgumentListInfo ToTAInfo; |
| 4500 | if (ImportTemplateArgumentListInfo(D->getTemplateArgsInfo(), ToTAInfo)) |
| 4501 | return nullptr; |
| 4502 | |
| 4503 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4504 | // Create a new specialization. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4505 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 4506 | // Import TemplateArgumentListInfo |
| 4507 | TemplateArgumentListInfo ArgInfos; |
| 4508 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 4509 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
| 4510 | if (ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ArgInfos)) |
| 4511 | return nullptr; |
| 4512 | |
| 4513 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 4514 | FromPartial->getTemplateParameters()); |
| 4515 | if (!ToTPList) |
| 4516 | return nullptr; |
| 4517 | |
| 4518 | auto *ToPartial = PartVarSpecDecl::Create( |
| 4519 | Importer.getToContext(), DC, StartLoc, IdLoc, ToTPList, VarTemplate, |
| 4520 | T, TInfo, D->getStorageClass(), TemplateArgs, ArgInfos); |
| 4521 | |
| 4522 | auto *FromInst = FromPartial->getInstantiatedFromMember(); |
| 4523 | auto *ToInst = cast_or_null<PartVarSpecDecl>(Importer.Import(FromInst)); |
| 4524 | if (FromInst && !ToInst) |
| 4525 | return nullptr; |
| 4526 | |
| 4527 | ToPartial->setInstantiatedFromMember(ToInst); |
| 4528 | if (FromPartial->isMemberSpecialization()) |
| 4529 | ToPartial->setMemberSpecialization(); |
| 4530 | |
| 4531 | D2 = ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4532 | } else { // Full specialization |
| 4533 | D2 = VarTemplateSpecializationDecl::Create( |
| 4534 | Importer.getToContext(), DC, StartLoc, IdLoc, VarTemplate, T, TInfo, |
| 4535 | D->getStorageClass(), TemplateArgs); |
| 4536 | } |
| 4537 | |
| 4538 | SourceLocation POI = D->getPointOfInstantiation(); |
| 4539 | if (POI.isValid()) |
| 4540 | D2->setPointOfInstantiation(Importer.Import(POI)); |
| 4541 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4542 | D2->setSpecializationKind(D->getSpecializationKind()); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4543 | D2->setTemplateArgsInfo(ToTAInfo); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4544 | |
| 4545 | // Add this specialization to the class template. |
| 4546 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 4547 | |
| 4548 | // Import the qualifier, if any. |
| 4549 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
| 4550 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4551 | if (D->isConstexpr()) |
| 4552 | D2->setConstexpr(true); |
| 4553 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4554 | // Add the specialization to this context. |
| 4555 | D2->setLexicalDeclContext(LexicalDC); |
| 4556 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4557 | |
| 4558 | D2->setAccess(D->getAccess()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4559 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4560 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4561 | Importer.Imported(D, D2); |
| 4562 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4563 | // NOTE: isThisDeclarationADefinition() can return DeclarationOnly even if |
| 4564 | // declaration has initializer. Should this be fixed in the AST?.. Anyway, |
| 4565 | // we have to check the declaration for initializer - otherwise, it won't be |
| 4566 | // imported. |
| 4567 | if ((D->isThisDeclarationADefinition() || D->hasInit()) && |
| 4568 | ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4569 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4570 | |
| 4571 | return D2; |
| 4572 | } |
| 4573 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4574 | Decl *ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 4575 | DeclContext *DC, *LexicalDC; |
| 4576 | DeclarationName Name; |
| 4577 | SourceLocation Loc; |
| 4578 | NamedDecl *ToD; |
| 4579 | |
| 4580 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4581 | return nullptr; |
| 4582 | |
| 4583 | if (ToD) |
| 4584 | return ToD; |
| 4585 | |
| 4586 | // Try to find a function in our own ("to") context with the same name, same |
| 4587 | // type, and in the same context as the function we're importing. |
| 4588 | if (!LexicalDC->isFunctionOrMethod()) { |
| 4589 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 4590 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 4591 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4592 | for (auto *FoundDecl : FoundDecls) { |
| 4593 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4594 | continue; |
| 4595 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4596 | if (auto *FoundFunction = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4597 | if (FoundFunction->hasExternalFormalLinkage() && |
| 4598 | D->hasExternalFormalLinkage()) { |
| 4599 | if (IsStructuralMatch(D, FoundFunction)) { |
| 4600 | Importer.Imported(D, FoundFunction); |
| 4601 | // FIXME: Actually try to merge the body and other attributes. |
| 4602 | return FoundFunction; |
| 4603 | } |
| 4604 | } |
| 4605 | } |
| 4606 | } |
| 4607 | } |
| 4608 | |
| 4609 | TemplateParameterList *Params = |
| 4610 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4611 | if (!Params) |
| 4612 | return nullptr; |
| 4613 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4614 | auto *TemplatedFD = |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4615 | cast_or_null<FunctionDecl>(Importer.Import(D->getTemplatedDecl())); |
| 4616 | if (!TemplatedFD) |
| 4617 | return nullptr; |
| 4618 | |
| 4619 | FunctionTemplateDecl *ToFunc = FunctionTemplateDecl::Create( |
| 4620 | Importer.getToContext(), DC, Loc, Name, Params, TemplatedFD); |
| 4621 | |
| 4622 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| 4623 | ToFunc->setAccess(D->getAccess()); |
| 4624 | ToFunc->setLexicalDeclContext(LexicalDC); |
| 4625 | Importer.Imported(D, ToFunc); |
| 4626 | |
| 4627 | LexicalDC->addDeclInternal(ToFunc); |
| 4628 | return ToFunc; |
| 4629 | } |
| 4630 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4631 | //---------------------------------------------------------------------------- |
| 4632 | // Import Statements |
| 4633 | //---------------------------------------------------------------------------- |
| 4634 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4635 | DeclGroupRef ASTNodeImporter::ImportDeclGroup(DeclGroupRef DG) { |
| 4636 | if (DG.isNull()) |
| 4637 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 4638 | size_t NumDecls = DG.end() - DG.begin(); |
| 4639 | SmallVector<Decl *, 1> ToDecls(NumDecls); |
| 4640 | auto &_Importer = this->Importer; |
| 4641 | std::transform(DG.begin(), DG.end(), ToDecls.begin(), |
| 4642 | [&_Importer](Decl *D) -> Decl * { |
| 4643 | return _Importer.Import(D); |
| 4644 | }); |
| 4645 | return DeclGroupRef::Create(Importer.getToContext(), |
| 4646 | ToDecls.begin(), |
| 4647 | NumDecls); |
| 4648 | } |
| 4649 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4650 | Stmt *ASTNodeImporter::VisitStmt(Stmt *S) { |
| 4651 | Importer.FromDiag(S->getLocStart(), diag::err_unsupported_ast_node) |
| 4652 | << S->getStmtClassName(); |
| 4653 | return nullptr; |
| 4654 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4655 | |
| 4656 | Stmt *ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
| 4657 | SmallVector<IdentifierInfo *, 4> Names; |
| 4658 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 4659 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 4660 | // ToII is nullptr when no symbolic name is given for output operand |
| 4661 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 4662 | if (!ToII && S->getOutputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4663 | return nullptr; |
| 4664 | Names.push_back(ToII); |
| 4665 | } |
| 4666 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 4667 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 4668 | // ToII is nullptr when no symbolic name is given for input operand |
| 4669 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 4670 | if (!ToII && S->getInputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4671 | return nullptr; |
| 4672 | Names.push_back(ToII); |
| 4673 | } |
| 4674 | |
| 4675 | SmallVector<StringLiteral *, 4> Clobbers; |
| 4676 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4677 | auto *Clobber = cast_or_null<StringLiteral>( |
| 4678 | Importer.Import(S->getClobberStringLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4679 | if (!Clobber) |
| 4680 | return nullptr; |
| 4681 | Clobbers.push_back(Clobber); |
| 4682 | } |
| 4683 | |
| 4684 | SmallVector<StringLiteral *, 4> Constraints; |
| 4685 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4686 | auto *Output = cast_or_null<StringLiteral>( |
| 4687 | Importer.Import(S->getOutputConstraintLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4688 | if (!Output) |
| 4689 | return nullptr; |
| 4690 | Constraints.push_back(Output); |
| 4691 | } |
| 4692 | |
| 4693 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4694 | auto *Input = cast_or_null<StringLiteral>( |
| 4695 | Importer.Import(S->getInputConstraintLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4696 | if (!Input) |
| 4697 | return nullptr; |
| 4698 | Constraints.push_back(Input); |
| 4699 | } |
| 4700 | |
| 4701 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4702 | if (ImportContainerChecked(S->outputs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4703 | return nullptr; |
| 4704 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4705 | if (ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4706 | return nullptr; |
| 4707 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4708 | auto *AsmStr = cast_or_null<StringLiteral>( |
| 4709 | Importer.Import(S->getAsmString())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4710 | if (!AsmStr) |
| 4711 | return nullptr; |
| 4712 | |
| 4713 | return new (Importer.getToContext()) GCCAsmStmt( |
| 4714 | Importer.getToContext(), |
| 4715 | Importer.Import(S->getAsmLoc()), |
| 4716 | S->isSimple(), |
| 4717 | S->isVolatile(), |
| 4718 | S->getNumOutputs(), |
| 4719 | S->getNumInputs(), |
| 4720 | Names.data(), |
| 4721 | Constraints.data(), |
| 4722 | Exprs.data(), |
| 4723 | AsmStr, |
| 4724 | S->getNumClobbers(), |
| 4725 | Clobbers.data(), |
| 4726 | Importer.Import(S->getRParenLoc())); |
| 4727 | } |
| 4728 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4729 | Stmt *ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 4730 | DeclGroupRef ToDG = ImportDeclGroup(S->getDeclGroup()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4731 | for (auto *ToD : ToDG) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4732 | if (!ToD) |
| 4733 | return nullptr; |
| 4734 | } |
| 4735 | SourceLocation ToStartLoc = Importer.Import(S->getStartLoc()); |
| 4736 | SourceLocation ToEndLoc = Importer.Import(S->getEndLoc()); |
| 4737 | return new (Importer.getToContext()) DeclStmt(ToDG, ToStartLoc, ToEndLoc); |
| 4738 | } |
| 4739 | |
| 4740 | Stmt *ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 4741 | SourceLocation ToSemiLoc = Importer.Import(S->getSemiLoc()); |
| 4742 | return new (Importer.getToContext()) NullStmt(ToSemiLoc, |
| 4743 | S->hasLeadingEmptyMacro()); |
| 4744 | } |
| 4745 | |
| 4746 | Stmt *ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4747 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4748 | |
| 4749 | if (ImportContainerChecked(S->body(), ToStmts)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 4750 | return nullptr; |
| 4751 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4752 | SourceLocation ToLBraceLoc = Importer.Import(S->getLBracLoc()); |
| 4753 | SourceLocation ToRBraceLoc = Importer.Import(S->getRBracLoc()); |
Benjamin Kramer | 0742090 | 2017-12-24 16:24:20 +0000 | [diff] [blame] | 4754 | return CompoundStmt::Create(Importer.getToContext(), ToStmts, ToLBraceLoc, |
| 4755 | ToRBraceLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4756 | } |
| 4757 | |
| 4758 | Stmt *ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 4759 | Expr *ToLHS = Importer.Import(S->getLHS()); |
| 4760 | if (!ToLHS) |
| 4761 | return nullptr; |
| 4762 | Expr *ToRHS = Importer.Import(S->getRHS()); |
| 4763 | if (!ToRHS && S->getRHS()) |
| 4764 | return nullptr; |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 4765 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4766 | if (!ToSubStmt && S->getSubStmt()) |
| 4767 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4768 | SourceLocation ToCaseLoc = Importer.Import(S->getCaseLoc()); |
| 4769 | SourceLocation ToEllipsisLoc = Importer.Import(S->getEllipsisLoc()); |
| 4770 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4771 | auto *ToStmt = new (Importer.getToContext()) |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 4772 | CaseStmt(ToLHS, ToRHS, ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
| 4773 | ToStmt->setSubStmt(ToSubStmt); |
| 4774 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4775 | } |
| 4776 | |
| 4777 | Stmt *ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 4778 | SourceLocation ToDefaultLoc = Importer.Import(S->getDefaultLoc()); |
| 4779 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 4780 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4781 | if (!ToSubStmt && S->getSubStmt()) |
| 4782 | return nullptr; |
| 4783 | return new (Importer.getToContext()) DefaultStmt(ToDefaultLoc, ToColonLoc, |
| 4784 | ToSubStmt); |
| 4785 | } |
| 4786 | |
| 4787 | Stmt *ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 4788 | SourceLocation ToIdentLoc = Importer.Import(S->getIdentLoc()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4789 | auto *ToLabelDecl = cast_or_null<LabelDecl>(Importer.Import(S->getDecl())); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4790 | if (!ToLabelDecl && S->getDecl()) |
| 4791 | return nullptr; |
| 4792 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4793 | if (!ToSubStmt && S->getSubStmt()) |
| 4794 | return nullptr; |
| 4795 | return new (Importer.getToContext()) LabelStmt(ToIdentLoc, ToLabelDecl, |
| 4796 | ToSubStmt); |
| 4797 | } |
| 4798 | |
| 4799 | Stmt *ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 4800 | SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc()); |
| 4801 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 4802 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 4803 | if (ImportContainerChecked(FromAttrs, ToAttrs)) |
| 4804 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4805 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4806 | if (!ToSubStmt && S->getSubStmt()) |
| 4807 | return nullptr; |
| 4808 | return AttributedStmt::Create(Importer.getToContext(), ToAttrLoc, |
| 4809 | ToAttrs, ToSubStmt); |
| 4810 | } |
| 4811 | |
| 4812 | Stmt *ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 4813 | SourceLocation ToIfLoc = Importer.Import(S->getIfLoc()); |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4814 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4815 | if (!ToInit && S->getInit()) |
| 4816 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4817 | VarDecl *ToConditionVariable = nullptr; |
| 4818 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4819 | ToConditionVariable = |
| 4820 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4821 | if (!ToConditionVariable) |
| 4822 | return nullptr; |
| 4823 | } |
| 4824 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4825 | if (!ToCondition && S->getCond()) |
| 4826 | return nullptr; |
| 4827 | Stmt *ToThenStmt = Importer.Import(S->getThen()); |
| 4828 | if (!ToThenStmt && S->getThen()) |
| 4829 | return nullptr; |
| 4830 | SourceLocation ToElseLoc = Importer.Import(S->getElseLoc()); |
| 4831 | Stmt *ToElseStmt = Importer.Import(S->getElse()); |
| 4832 | if (!ToElseStmt && S->getElse()) |
| 4833 | return nullptr; |
| 4834 | return new (Importer.getToContext()) IfStmt(Importer.getToContext(), |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 4835 | ToIfLoc, S->isConstexpr(), |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4836 | ToInit, |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 4837 | ToConditionVariable, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4838 | ToCondition, ToThenStmt, |
| 4839 | ToElseLoc, ToElseStmt); |
| 4840 | } |
| 4841 | |
| 4842 | Stmt *ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4843 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4844 | if (!ToInit && S->getInit()) |
| 4845 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4846 | VarDecl *ToConditionVariable = nullptr; |
| 4847 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4848 | ToConditionVariable = |
| 4849 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4850 | if (!ToConditionVariable) |
| 4851 | return nullptr; |
| 4852 | } |
| 4853 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4854 | if (!ToCondition && S->getCond()) |
| 4855 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4856 | auto *ToStmt = new (Importer.getToContext()) SwitchStmt( |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4857 | Importer.getToContext(), ToInit, |
| 4858 | ToConditionVariable, ToCondition); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4859 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4860 | if (!ToBody && S->getBody()) |
| 4861 | return nullptr; |
| 4862 | ToStmt->setBody(ToBody); |
| 4863 | ToStmt->setSwitchLoc(Importer.Import(S->getSwitchLoc())); |
| 4864 | // Now we have to re-chain the cases. |
| 4865 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 4866 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 4867 | SC = SC->getNextSwitchCase()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4868 | auto *ToSC = dyn_cast_or_null<SwitchCase>(Importer.Import(SC)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4869 | if (!ToSC) |
| 4870 | return nullptr; |
| 4871 | if (LastChainedSwitchCase) |
| 4872 | LastChainedSwitchCase->setNextSwitchCase(ToSC); |
| 4873 | else |
| 4874 | ToStmt->setSwitchCaseList(ToSC); |
| 4875 | LastChainedSwitchCase = ToSC; |
| 4876 | } |
| 4877 | return ToStmt; |
| 4878 | } |
| 4879 | |
| 4880 | Stmt *ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 4881 | VarDecl *ToConditionVariable = nullptr; |
| 4882 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4883 | ToConditionVariable = |
| 4884 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4885 | if (!ToConditionVariable) |
| 4886 | return nullptr; |
| 4887 | } |
| 4888 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4889 | if (!ToCondition && S->getCond()) |
| 4890 | return nullptr; |
| 4891 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4892 | if (!ToBody && S->getBody()) |
| 4893 | return nullptr; |
| 4894 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 4895 | return new (Importer.getToContext()) WhileStmt(Importer.getToContext(), |
| 4896 | ToConditionVariable, |
| 4897 | ToCondition, ToBody, |
| 4898 | ToWhileLoc); |
| 4899 | } |
| 4900 | |
| 4901 | Stmt *ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 4902 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4903 | if (!ToBody && S->getBody()) |
| 4904 | return nullptr; |
| 4905 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4906 | if (!ToCondition && S->getCond()) |
| 4907 | return nullptr; |
| 4908 | SourceLocation ToDoLoc = Importer.Import(S->getDoLoc()); |
| 4909 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 4910 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4911 | return new (Importer.getToContext()) DoStmt(ToBody, ToCondition, |
| 4912 | ToDoLoc, ToWhileLoc, |
| 4913 | ToRParenLoc); |
| 4914 | } |
| 4915 | |
| 4916 | Stmt *ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 4917 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4918 | if (!ToInit && S->getInit()) |
| 4919 | return nullptr; |
| 4920 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4921 | if (!ToCondition && S->getCond()) |
| 4922 | return nullptr; |
| 4923 | VarDecl *ToConditionVariable = nullptr; |
| 4924 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4925 | ToConditionVariable = |
| 4926 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4927 | if (!ToConditionVariable) |
| 4928 | return nullptr; |
| 4929 | } |
| 4930 | Expr *ToInc = Importer.Import(S->getInc()); |
| 4931 | if (!ToInc && S->getInc()) |
| 4932 | return nullptr; |
| 4933 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4934 | if (!ToBody && S->getBody()) |
| 4935 | return nullptr; |
| 4936 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 4937 | SourceLocation ToLParenLoc = Importer.Import(S->getLParenLoc()); |
| 4938 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4939 | return new (Importer.getToContext()) ForStmt(Importer.getToContext(), |
| 4940 | ToInit, ToCondition, |
| 4941 | ToConditionVariable, |
| 4942 | ToInc, ToBody, |
| 4943 | ToForLoc, ToLParenLoc, |
| 4944 | ToRParenLoc); |
| 4945 | } |
| 4946 | |
| 4947 | Stmt *ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 4948 | LabelDecl *ToLabel = nullptr; |
| 4949 | if (LabelDecl *FromLabel = S->getLabel()) { |
| 4950 | ToLabel = dyn_cast_or_null<LabelDecl>(Importer.Import(FromLabel)); |
| 4951 | if (!ToLabel) |
| 4952 | return nullptr; |
| 4953 | } |
| 4954 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 4955 | SourceLocation ToLabelLoc = Importer.Import(S->getLabelLoc()); |
| 4956 | return new (Importer.getToContext()) GotoStmt(ToLabel, |
| 4957 | ToGotoLoc, ToLabelLoc); |
| 4958 | } |
| 4959 | |
| 4960 | Stmt *ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 4961 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 4962 | SourceLocation ToStarLoc = Importer.Import(S->getStarLoc()); |
| 4963 | Expr *ToTarget = Importer.Import(S->getTarget()); |
| 4964 | if (!ToTarget && S->getTarget()) |
| 4965 | return nullptr; |
| 4966 | return new (Importer.getToContext()) IndirectGotoStmt(ToGotoLoc, ToStarLoc, |
| 4967 | ToTarget); |
| 4968 | } |
| 4969 | |
| 4970 | Stmt *ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 4971 | SourceLocation ToContinueLoc = Importer.Import(S->getContinueLoc()); |
| 4972 | return new (Importer.getToContext()) ContinueStmt(ToContinueLoc); |
| 4973 | } |
| 4974 | |
| 4975 | Stmt *ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 4976 | SourceLocation ToBreakLoc = Importer.Import(S->getBreakLoc()); |
| 4977 | return new (Importer.getToContext()) BreakStmt(ToBreakLoc); |
| 4978 | } |
| 4979 | |
| 4980 | Stmt *ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 4981 | SourceLocation ToRetLoc = Importer.Import(S->getReturnLoc()); |
| 4982 | Expr *ToRetExpr = Importer.Import(S->getRetValue()); |
| 4983 | if (!ToRetExpr && S->getRetValue()) |
| 4984 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4985 | auto *NRVOCandidate = const_cast<VarDecl *>(S->getNRVOCandidate()); |
| 4986 | auto *ToNRVOCandidate = cast_or_null<VarDecl>(Importer.Import(NRVOCandidate)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4987 | if (!ToNRVOCandidate && NRVOCandidate) |
| 4988 | return nullptr; |
| 4989 | return new (Importer.getToContext()) ReturnStmt(ToRetLoc, ToRetExpr, |
| 4990 | ToNRVOCandidate); |
| 4991 | } |
| 4992 | |
| 4993 | Stmt *ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 4994 | SourceLocation ToCatchLoc = Importer.Import(S->getCatchLoc()); |
| 4995 | VarDecl *ToExceptionDecl = nullptr; |
| 4996 | if (VarDecl *FromExceptionDecl = S->getExceptionDecl()) { |
| 4997 | ToExceptionDecl = |
| 4998 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 4999 | if (!ToExceptionDecl) |
| 5000 | return nullptr; |
| 5001 | } |
| 5002 | Stmt *ToHandlerBlock = Importer.Import(S->getHandlerBlock()); |
| 5003 | if (!ToHandlerBlock && S->getHandlerBlock()) |
| 5004 | return nullptr; |
| 5005 | return new (Importer.getToContext()) CXXCatchStmt(ToCatchLoc, |
| 5006 | ToExceptionDecl, |
| 5007 | ToHandlerBlock); |
| 5008 | } |
| 5009 | |
| 5010 | Stmt *ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 5011 | SourceLocation ToTryLoc = Importer.Import(S->getTryLoc()); |
| 5012 | Stmt *ToTryBlock = Importer.Import(S->getTryBlock()); |
| 5013 | if (!ToTryBlock && S->getTryBlock()) |
| 5014 | return nullptr; |
| 5015 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 5016 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 5017 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
| 5018 | if (Stmt *ToHandler = Importer.Import(FromHandler)) |
| 5019 | ToHandlers[HI] = ToHandler; |
| 5020 | else |
| 5021 | return nullptr; |
| 5022 | } |
| 5023 | return CXXTryStmt::Create(Importer.getToContext(), ToTryLoc, ToTryBlock, |
| 5024 | ToHandlers); |
| 5025 | } |
| 5026 | |
| 5027 | Stmt *ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5028 | auto *ToRange = |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5029 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getRangeStmt())); |
| 5030 | if (!ToRange && S->getRangeStmt()) |
| 5031 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5032 | auto *ToBegin = |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5033 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getBeginStmt())); |
| 5034 | if (!ToBegin && S->getBeginStmt()) |
| 5035 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5036 | auto *ToEnd = |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5037 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getEndStmt())); |
| 5038 | if (!ToEnd && S->getEndStmt()) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5039 | return nullptr; |
| 5040 | Expr *ToCond = Importer.Import(S->getCond()); |
| 5041 | if (!ToCond && S->getCond()) |
| 5042 | return nullptr; |
| 5043 | Expr *ToInc = Importer.Import(S->getInc()); |
| 5044 | if (!ToInc && S->getInc()) |
| 5045 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5046 | auto *ToLoopVar = |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5047 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getLoopVarStmt())); |
| 5048 | if (!ToLoopVar && S->getLoopVarStmt()) |
| 5049 | return nullptr; |
| 5050 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5051 | if (!ToBody && S->getBody()) |
| 5052 | return nullptr; |
| 5053 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 5054 | SourceLocation ToCoawaitLoc = Importer.Import(S->getCoawaitLoc()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5055 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 5056 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5057 | return new (Importer.getToContext()) CXXForRangeStmt(ToRange, ToBegin, ToEnd, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5058 | ToCond, ToInc, |
| 5059 | ToLoopVar, ToBody, |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 5060 | ToForLoc, ToCoawaitLoc, |
| 5061 | ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5062 | } |
| 5063 | |
| 5064 | Stmt *ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 5065 | Stmt *ToElem = Importer.Import(S->getElement()); |
| 5066 | if (!ToElem && S->getElement()) |
| 5067 | return nullptr; |
| 5068 | Expr *ToCollect = Importer.Import(S->getCollection()); |
| 5069 | if (!ToCollect && S->getCollection()) |
| 5070 | return nullptr; |
| 5071 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5072 | if (!ToBody && S->getBody()) |
| 5073 | return nullptr; |
| 5074 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 5075 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5076 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElem, |
| 5077 | ToCollect, |
| 5078 | ToBody, ToForLoc, |
| 5079 | ToRParenLoc); |
| 5080 | } |
| 5081 | |
| 5082 | Stmt *ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 5083 | SourceLocation ToAtCatchLoc = Importer.Import(S->getAtCatchLoc()); |
| 5084 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5085 | VarDecl *ToExceptionDecl = nullptr; |
| 5086 | if (VarDecl *FromExceptionDecl = S->getCatchParamDecl()) { |
| 5087 | ToExceptionDecl = |
| 5088 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 5089 | if (!ToExceptionDecl) |
| 5090 | return nullptr; |
| 5091 | } |
| 5092 | Stmt *ToBody = Importer.Import(S->getCatchBody()); |
| 5093 | if (!ToBody && S->getCatchBody()) |
| 5094 | return nullptr; |
| 5095 | return new (Importer.getToContext()) ObjCAtCatchStmt(ToAtCatchLoc, |
| 5096 | ToRParenLoc, |
| 5097 | ToExceptionDecl, |
| 5098 | ToBody); |
| 5099 | } |
| 5100 | |
| 5101 | Stmt *ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 5102 | SourceLocation ToAtFinallyLoc = Importer.Import(S->getAtFinallyLoc()); |
| 5103 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyBody()); |
| 5104 | if (!ToAtFinallyStmt && S->getFinallyBody()) |
| 5105 | return nullptr; |
| 5106 | return new (Importer.getToContext()) ObjCAtFinallyStmt(ToAtFinallyLoc, |
| 5107 | ToAtFinallyStmt); |
| 5108 | } |
| 5109 | |
| 5110 | Stmt *ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 5111 | SourceLocation ToAtTryLoc = Importer.Import(S->getAtTryLoc()); |
| 5112 | Stmt *ToAtTryStmt = Importer.Import(S->getTryBody()); |
| 5113 | if (!ToAtTryStmt && S->getTryBody()) |
| 5114 | return nullptr; |
| 5115 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 5116 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 5117 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
| 5118 | if (Stmt *ToCatchStmt = Importer.Import(FromCatchStmt)) |
| 5119 | ToCatchStmts[CI] = ToCatchStmt; |
| 5120 | else |
| 5121 | return nullptr; |
| 5122 | } |
| 5123 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyStmt()); |
| 5124 | if (!ToAtFinallyStmt && S->getFinallyStmt()) |
| 5125 | return nullptr; |
| 5126 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
| 5127 | ToAtTryLoc, ToAtTryStmt, |
| 5128 | ToCatchStmts.begin(), ToCatchStmts.size(), |
| 5129 | ToAtFinallyStmt); |
| 5130 | } |
| 5131 | |
| 5132 | Stmt *ASTNodeImporter::VisitObjCAtSynchronizedStmt |
| 5133 | (ObjCAtSynchronizedStmt *S) { |
| 5134 | SourceLocation ToAtSynchronizedLoc = |
| 5135 | Importer.Import(S->getAtSynchronizedLoc()); |
| 5136 | Expr *ToSynchExpr = Importer.Import(S->getSynchExpr()); |
| 5137 | if (!ToSynchExpr && S->getSynchExpr()) |
| 5138 | return nullptr; |
| 5139 | Stmt *ToSynchBody = Importer.Import(S->getSynchBody()); |
| 5140 | if (!ToSynchBody && S->getSynchBody()) |
| 5141 | return nullptr; |
| 5142 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 5143 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 5144 | } |
| 5145 | |
| 5146 | Stmt *ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 5147 | SourceLocation ToAtThrowLoc = Importer.Import(S->getThrowLoc()); |
| 5148 | Expr *ToThrow = Importer.Import(S->getThrowExpr()); |
| 5149 | if (!ToThrow && S->getThrowExpr()) |
| 5150 | return nullptr; |
| 5151 | return new (Importer.getToContext()) ObjCAtThrowStmt(ToAtThrowLoc, ToThrow); |
| 5152 | } |
| 5153 | |
| 5154 | Stmt *ASTNodeImporter::VisitObjCAutoreleasePoolStmt |
| 5155 | (ObjCAutoreleasePoolStmt *S) { |
| 5156 | SourceLocation ToAtLoc = Importer.Import(S->getAtLoc()); |
| 5157 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5158 | if (!ToSubStmt && S->getSubStmt()) |
| 5159 | return nullptr; |
| 5160 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(ToAtLoc, |
| 5161 | ToSubStmt); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5162 | } |
| 5163 | |
| 5164 | //---------------------------------------------------------------------------- |
| 5165 | // Import Expressions |
| 5166 | //---------------------------------------------------------------------------- |
| 5167 | Expr *ASTNodeImporter::VisitExpr(Expr *E) { |
| 5168 | Importer.FromDiag(E->getLocStart(), diag::err_unsupported_ast_node) |
| 5169 | << E->getStmtClassName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5170 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5171 | } |
| 5172 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5173 | Expr *ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 5174 | QualType T = Importer.Import(E->getType()); |
| 5175 | if (T.isNull()) |
| 5176 | return nullptr; |
| 5177 | |
| 5178 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5179 | if (!SubExpr && E->getSubExpr()) |
| 5180 | return nullptr; |
| 5181 | |
| 5182 | TypeSourceInfo *TInfo = Importer.Import(E->getWrittenTypeInfo()); |
| 5183 | if (!TInfo) |
| 5184 | return nullptr; |
| 5185 | |
| 5186 | return new (Importer.getToContext()) VAArgExpr( |
| 5187 | Importer.Import(E->getBuiltinLoc()), SubExpr, TInfo, |
| 5188 | Importer.Import(E->getRParenLoc()), T, E->isMicrosoftABI()); |
| 5189 | } |
| 5190 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5191 | Expr *ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 5192 | QualType T = Importer.Import(E->getType()); |
| 5193 | if (T.isNull()) |
| 5194 | return nullptr; |
| 5195 | |
| 5196 | return new (Importer.getToContext()) GNUNullExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5197 | T, Importer.Import(E->getLocStart())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5198 | } |
| 5199 | |
| 5200 | Expr *ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 5201 | QualType T = Importer.Import(E->getType()); |
| 5202 | if (T.isNull()) |
| 5203 | return nullptr; |
| 5204 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5205 | auto *SL = cast_or_null<StringLiteral>(Importer.Import(E->getFunctionName())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5206 | if (!SL && E->getFunctionName()) |
| 5207 | return nullptr; |
| 5208 | |
| 5209 | return new (Importer.getToContext()) PredefinedExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5210 | Importer.Import(E->getLocStart()), T, E->getIdentType(), SL); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5211 | } |
| 5212 | |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5213 | Expr *ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5214 | auto *ToD = cast_or_null<ValueDecl>(Importer.Import(E->getDecl())); |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5215 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5216 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5217 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5218 | NamedDecl *FoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5219 | if (E->getDecl() != E->getFoundDecl()) { |
| 5220 | FoundD = cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl())); |
| 5221 | if (!FoundD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5222 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5223 | } |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5224 | |
| 5225 | QualType T = Importer.Import(E->getType()); |
| 5226 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5227 | return nullptr; |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5228 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5229 | TemplateArgumentListInfo ToTAInfo; |
| 5230 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 5231 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5232 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 5233 | return nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5234 | ResInfo = &ToTAInfo; |
| 5235 | } |
| 5236 | |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5237 | DeclRefExpr *DRE = DeclRefExpr::Create(Importer.getToContext(), |
| 5238 | Importer.Import(E->getQualifierLoc()), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 5239 | Importer.Import(E->getTemplateKeywordLoc()), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5240 | ToD, |
Alexey Bataev | 19acc3d | 2015-01-12 10:17:46 +0000 | [diff] [blame] | 5241 | E->refersToEnclosingVariableOrCapture(), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5242 | Importer.Import(E->getLocation()), |
| 5243 | T, E->getValueKind(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5244 | FoundD, ResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5245 | if (E->hadMultipleCandidates()) |
| 5246 | DRE->setHadMultipleCandidates(true); |
| 5247 | return DRE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5248 | } |
| 5249 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5250 | Expr *ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 5251 | QualType T = Importer.Import(E->getType()); |
| 5252 | if (T.isNull()) |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5253 | return nullptr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5254 | |
| 5255 | return new (Importer.getToContext()) ImplicitValueInitExpr(T); |
| 5256 | } |
| 5257 | |
| 5258 | ASTNodeImporter::Designator |
| 5259 | ASTNodeImporter::ImportDesignator(const Designator &D) { |
| 5260 | if (D.isFieldDesignator()) { |
| 5261 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 5262 | // Caller checks for import error |
| 5263 | return Designator(ToFieldName, Importer.Import(D.getDotLoc()), |
| 5264 | Importer.Import(D.getFieldLoc())); |
| 5265 | } |
| 5266 | if (D.isArrayDesignator()) |
| 5267 | return Designator(D.getFirstExprIndex(), |
| 5268 | Importer.Import(D.getLBracketLoc()), |
| 5269 | Importer.Import(D.getRBracketLoc())); |
| 5270 | |
| 5271 | assert(D.isArrayRangeDesignator()); |
| 5272 | return Designator(D.getFirstExprIndex(), |
| 5273 | Importer.Import(D.getLBracketLoc()), |
| 5274 | Importer.Import(D.getEllipsisLoc()), |
| 5275 | Importer.Import(D.getRBracketLoc())); |
| 5276 | } |
| 5277 | |
| 5278 | |
| 5279 | Expr *ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *DIE) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5280 | auto *Init = cast_or_null<Expr>(Importer.Import(DIE->getInit())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5281 | if (!Init) |
| 5282 | return nullptr; |
| 5283 | |
| 5284 | SmallVector<Expr *, 4> IndexExprs(DIE->getNumSubExprs() - 1); |
| 5285 | // List elements from the second, the first is Init itself |
| 5286 | for (unsigned I = 1, E = DIE->getNumSubExprs(); I < E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5287 | if (auto *Arg = cast_or_null<Expr>(Importer.Import(DIE->getSubExpr(I)))) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5288 | IndexExprs[I - 1] = Arg; |
| 5289 | else |
| 5290 | return nullptr; |
| 5291 | } |
| 5292 | |
| 5293 | SmallVector<Designator, 4> Designators(DIE->size()); |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5294 | llvm::transform(DIE->designators(), Designators.begin(), |
| 5295 | [this](const Designator &D) -> Designator { |
| 5296 | return ImportDesignator(D); |
| 5297 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5298 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5299 | for (const auto &D : DIE->designators()) |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5300 | if (D.isFieldDesignator() && !D.getFieldName()) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5301 | return nullptr; |
| 5302 | |
| 5303 | return DesignatedInitExpr::Create( |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5304 | Importer.getToContext(), Designators, |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5305 | IndexExprs, Importer.Import(DIE->getEqualOrColonLoc()), |
| 5306 | DIE->usesGNUSyntax(), Init); |
| 5307 | } |
| 5308 | |
| 5309 | Expr *ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 5310 | QualType T = Importer.Import(E->getType()); |
| 5311 | if (T.isNull()) |
| 5312 | return nullptr; |
| 5313 | |
| 5314 | return new (Importer.getToContext()) |
| 5315 | CXXNullPtrLiteralExpr(T, Importer.Import(E->getLocation())); |
| 5316 | } |
| 5317 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5318 | Expr *ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 5319 | QualType T = Importer.Import(E->getType()); |
| 5320 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5321 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5322 | |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 5323 | return IntegerLiteral::Create(Importer.getToContext(), |
| 5324 | E->getValue(), T, |
| 5325 | Importer.Import(E->getLocation())); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5326 | } |
| 5327 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5328 | Expr *ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 5329 | QualType T = Importer.Import(E->getType()); |
| 5330 | if (T.isNull()) |
| 5331 | return nullptr; |
| 5332 | |
| 5333 | return FloatingLiteral::Create(Importer.getToContext(), |
| 5334 | E->getValue(), E->isExact(), T, |
| 5335 | Importer.Import(E->getLocation())); |
| 5336 | } |
| 5337 | |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5338 | Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 5339 | QualType T = Importer.Import(E->getType()); |
| 5340 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5341 | return nullptr; |
| 5342 | |
Douglas Gregor | fb65e59 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 5343 | return new (Importer.getToContext()) CharacterLiteral(E->getValue(), |
| 5344 | E->getKind(), T, |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5345 | Importer.Import(E->getLocation())); |
| 5346 | } |
| 5347 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5348 | Expr *ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 5349 | QualType T = Importer.Import(E->getType()); |
| 5350 | if (T.isNull()) |
| 5351 | return nullptr; |
| 5352 | |
| 5353 | SmallVector<SourceLocation, 4> Locations(E->getNumConcatenated()); |
| 5354 | ImportArray(E->tokloc_begin(), E->tokloc_end(), Locations.begin()); |
| 5355 | |
| 5356 | return StringLiteral::Create(Importer.getToContext(), E->getBytes(), |
| 5357 | E->getKind(), E->isPascal(), T, |
| 5358 | Locations.data(), Locations.size()); |
| 5359 | } |
| 5360 | |
| 5361 | Expr *ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 5362 | QualType T = Importer.Import(E->getType()); |
| 5363 | if (T.isNull()) |
| 5364 | return nullptr; |
| 5365 | |
| 5366 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeSourceInfo()); |
| 5367 | if (!TInfo) |
| 5368 | return nullptr; |
| 5369 | |
| 5370 | Expr *Init = Importer.Import(E->getInitializer()); |
| 5371 | if (!Init) |
| 5372 | return nullptr; |
| 5373 | |
| 5374 | return new (Importer.getToContext()) CompoundLiteralExpr( |
| 5375 | Importer.Import(E->getLParenLoc()), TInfo, T, E->getValueKind(), |
| 5376 | Init, E->isFileScope()); |
| 5377 | } |
| 5378 | |
| 5379 | Expr *ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 5380 | QualType T = Importer.Import(E->getType()); |
| 5381 | if (T.isNull()) |
| 5382 | return nullptr; |
| 5383 | |
| 5384 | SmallVector<Expr *, 6> Exprs(E->getNumSubExprs()); |
| 5385 | if (ImportArrayChecked( |
| 5386 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 5387 | Exprs.begin())) |
| 5388 | return nullptr; |
| 5389 | |
| 5390 | return new (Importer.getToContext()) AtomicExpr( |
| 5391 | Importer.Import(E->getBuiltinLoc()), Exprs, T, E->getOp(), |
| 5392 | Importer.Import(E->getRParenLoc())); |
| 5393 | } |
| 5394 | |
| 5395 | Expr *ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 5396 | QualType T = Importer.Import(E->getType()); |
| 5397 | if (T.isNull()) |
| 5398 | return nullptr; |
| 5399 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5400 | auto *ToLabel = cast_or_null<LabelDecl>(Importer.Import(E->getLabel())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5401 | if (!ToLabel) |
| 5402 | return nullptr; |
| 5403 | |
| 5404 | return new (Importer.getToContext()) AddrLabelExpr( |
| 5405 | Importer.Import(E->getAmpAmpLoc()), Importer.Import(E->getLabelLoc()), |
| 5406 | ToLabel, T); |
| 5407 | } |
| 5408 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5409 | Expr *ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 5410 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5411 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5412 | return nullptr; |
| 5413 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5414 | return new (Importer.getToContext()) |
| 5415 | ParenExpr(Importer.Import(E->getLParen()), |
| 5416 | Importer.Import(E->getRParen()), |
| 5417 | SubExpr); |
| 5418 | } |
| 5419 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5420 | Expr *ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 5421 | SmallVector<Expr *, 4> Exprs(E->getNumExprs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5422 | if (ImportContainerChecked(E->exprs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5423 | return nullptr; |
| 5424 | |
| 5425 | return new (Importer.getToContext()) ParenListExpr( |
| 5426 | Importer.getToContext(), Importer.Import(E->getLParenLoc()), |
| 5427 | Exprs, Importer.Import(E->getLParenLoc())); |
| 5428 | } |
| 5429 | |
| 5430 | Expr *ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 5431 | QualType T = Importer.Import(E->getType()); |
| 5432 | if (T.isNull()) |
| 5433 | return nullptr; |
| 5434 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5435 | auto *ToSubStmt = cast_or_null<CompoundStmt>( |
| 5436 | Importer.Import(E->getSubStmt())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5437 | if (!ToSubStmt && E->getSubStmt()) |
| 5438 | return nullptr; |
| 5439 | |
| 5440 | return new (Importer.getToContext()) StmtExpr(ToSubStmt, T, |
| 5441 | Importer.Import(E->getLParenLoc()), Importer.Import(E->getRParenLoc())); |
| 5442 | } |
| 5443 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5444 | Expr *ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 5445 | QualType T = Importer.Import(E->getType()); |
| 5446 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5447 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5448 | |
| 5449 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5450 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5451 | return nullptr; |
| 5452 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5453 | return new (Importer.getToContext()) UnaryOperator( |
| 5454 | SubExpr, E->getOpcode(), T, E->getValueKind(), E->getObjectKind(), |
| 5455 | Importer.Import(E->getOperatorLoc()), E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5456 | } |
| 5457 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5458 | Expr * |
| 5459 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5460 | QualType ResultType = Importer.Import(E->getType()); |
| 5461 | |
| 5462 | if (E->isArgumentType()) { |
| 5463 | TypeSourceInfo *TInfo = Importer.Import(E->getArgumentTypeInfo()); |
| 5464 | if (!TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5465 | return nullptr; |
| 5466 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5467 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5468 | TInfo, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5469 | Importer.Import(E->getOperatorLoc()), |
| 5470 | Importer.Import(E->getRParenLoc())); |
| 5471 | } |
| 5472 | |
| 5473 | Expr *SubExpr = Importer.Import(E->getArgumentExpr()); |
| 5474 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5475 | return nullptr; |
| 5476 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5477 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5478 | SubExpr, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5479 | Importer.Import(E->getOperatorLoc()), |
| 5480 | Importer.Import(E->getRParenLoc())); |
| 5481 | } |
| 5482 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5483 | Expr *ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 5484 | QualType T = Importer.Import(E->getType()); |
| 5485 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5486 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5487 | |
| 5488 | Expr *LHS = Importer.Import(E->getLHS()); |
| 5489 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5490 | return nullptr; |
| 5491 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5492 | Expr *RHS = Importer.Import(E->getRHS()); |
| 5493 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5494 | return nullptr; |
| 5495 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5496 | return new (Importer.getToContext()) BinaryOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 5497 | T, E->getValueKind(), |
| 5498 | E->getObjectKind(), |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 5499 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 5500 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5501 | } |
| 5502 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5503 | Expr *ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 5504 | QualType T = Importer.Import(E->getType()); |
| 5505 | if (T.isNull()) |
| 5506 | return nullptr; |
| 5507 | |
| 5508 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5509 | if (!ToLHS) |
| 5510 | return nullptr; |
| 5511 | |
| 5512 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5513 | if (!ToRHS) |
| 5514 | return nullptr; |
| 5515 | |
| 5516 | Expr *ToCond = Importer.Import(E->getCond()); |
| 5517 | if (!ToCond) |
| 5518 | return nullptr; |
| 5519 | |
| 5520 | return new (Importer.getToContext()) ConditionalOperator( |
| 5521 | ToCond, Importer.Import(E->getQuestionLoc()), |
| 5522 | ToLHS, Importer.Import(E->getColonLoc()), |
| 5523 | ToRHS, T, E->getValueKind(), E->getObjectKind()); |
| 5524 | } |
| 5525 | |
| 5526 | Expr *ASTNodeImporter::VisitBinaryConditionalOperator( |
| 5527 | BinaryConditionalOperator *E) { |
| 5528 | QualType T = Importer.Import(E->getType()); |
| 5529 | if (T.isNull()) |
| 5530 | return nullptr; |
| 5531 | |
| 5532 | Expr *Common = Importer.Import(E->getCommon()); |
| 5533 | if (!Common) |
| 5534 | return nullptr; |
| 5535 | |
| 5536 | Expr *Cond = Importer.Import(E->getCond()); |
| 5537 | if (!Cond) |
| 5538 | return nullptr; |
| 5539 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5540 | auto *OpaqueValue = cast_or_null<OpaqueValueExpr>( |
| 5541 | Importer.Import(E->getOpaqueValue())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5542 | if (!OpaqueValue) |
| 5543 | return nullptr; |
| 5544 | |
| 5545 | Expr *TrueExpr = Importer.Import(E->getTrueExpr()); |
| 5546 | if (!TrueExpr) |
| 5547 | return nullptr; |
| 5548 | |
| 5549 | Expr *FalseExpr = Importer.Import(E->getFalseExpr()); |
| 5550 | if (!FalseExpr) |
| 5551 | return nullptr; |
| 5552 | |
| 5553 | return new (Importer.getToContext()) BinaryConditionalOperator( |
| 5554 | Common, OpaqueValue, Cond, TrueExpr, FalseExpr, |
| 5555 | Importer.Import(E->getQuestionLoc()), Importer.Import(E->getColonLoc()), |
| 5556 | T, E->getValueKind(), E->getObjectKind()); |
| 5557 | } |
| 5558 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5559 | Expr *ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 5560 | QualType T = Importer.Import(E->getType()); |
| 5561 | if (T.isNull()) |
| 5562 | return nullptr; |
| 5563 | |
| 5564 | TypeSourceInfo *ToQueried = Importer.Import(E->getQueriedTypeSourceInfo()); |
| 5565 | if (!ToQueried) |
| 5566 | return nullptr; |
| 5567 | |
| 5568 | Expr *Dim = Importer.Import(E->getDimensionExpression()); |
| 5569 | if (!Dim && E->getDimensionExpression()) |
| 5570 | return nullptr; |
| 5571 | |
| 5572 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
| 5573 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 5574 | E->getValue(), Dim, Importer.Import(E->getLocEnd()), T); |
| 5575 | } |
| 5576 | |
| 5577 | Expr *ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 5578 | QualType T = Importer.Import(E->getType()); |
| 5579 | if (T.isNull()) |
| 5580 | return nullptr; |
| 5581 | |
| 5582 | Expr *ToQueried = Importer.Import(E->getQueriedExpression()); |
| 5583 | if (!ToQueried) |
| 5584 | return nullptr; |
| 5585 | |
| 5586 | return new (Importer.getToContext()) ExpressionTraitExpr( |
| 5587 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 5588 | E->getValue(), Importer.Import(E->getLocEnd()), T); |
| 5589 | } |
| 5590 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5591 | Expr *ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 5592 | QualType T = Importer.Import(E->getType()); |
| 5593 | if (T.isNull()) |
| 5594 | return nullptr; |
| 5595 | |
| 5596 | Expr *SourceExpr = Importer.Import(E->getSourceExpr()); |
| 5597 | if (!SourceExpr && E->getSourceExpr()) |
| 5598 | return nullptr; |
| 5599 | |
| 5600 | return new (Importer.getToContext()) OpaqueValueExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5601 | Importer.Import(E->getLocation()), T, E->getValueKind(), |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5602 | E->getObjectKind(), SourceExpr); |
| 5603 | } |
| 5604 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5605 | Expr *ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 5606 | QualType T = Importer.Import(E->getType()); |
| 5607 | if (T.isNull()) |
| 5608 | return nullptr; |
| 5609 | |
| 5610 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5611 | if (!ToLHS) |
| 5612 | return nullptr; |
| 5613 | |
| 5614 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5615 | if (!ToRHS) |
| 5616 | return nullptr; |
| 5617 | |
| 5618 | return new (Importer.getToContext()) ArraySubscriptExpr( |
| 5619 | ToLHS, ToRHS, T, E->getValueKind(), E->getObjectKind(), |
| 5620 | Importer.Import(E->getRBracketLoc())); |
| 5621 | } |
| 5622 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5623 | Expr *ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 5624 | QualType T = Importer.Import(E->getType()); |
| 5625 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5626 | return nullptr; |
| 5627 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5628 | QualType CompLHSType = Importer.Import(E->getComputationLHSType()); |
| 5629 | if (CompLHSType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5630 | return nullptr; |
| 5631 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5632 | QualType CompResultType = Importer.Import(E->getComputationResultType()); |
| 5633 | if (CompResultType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5634 | return nullptr; |
| 5635 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5636 | Expr *LHS = Importer.Import(E->getLHS()); |
| 5637 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5638 | return nullptr; |
| 5639 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5640 | Expr *RHS = Importer.Import(E->getRHS()); |
| 5641 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5642 | return nullptr; |
| 5643 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5644 | return new (Importer.getToContext()) |
| 5645 | CompoundAssignOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 5646 | T, E->getValueKind(), |
| 5647 | E->getObjectKind(), |
| 5648 | CompLHSType, CompResultType, |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 5649 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 5650 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5651 | } |
| 5652 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5653 | bool ASTNodeImporter::ImportCastPath(CastExpr *CE, CXXCastPath &Path) { |
| 5654 | for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) { |
| 5655 | if (CXXBaseSpecifier *Spec = Importer.Import(*I)) |
| 5656 | Path.push_back(Spec); |
| 5657 | else |
| 5658 | return true; |
| 5659 | } |
| 5660 | return false; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5661 | } |
| 5662 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5663 | Expr *ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 5664 | QualType T = Importer.Import(E->getType()); |
| 5665 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5666 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5667 | |
| 5668 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5669 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5670 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5671 | |
| 5672 | CXXCastPath BasePath; |
| 5673 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5674 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5675 | |
| 5676 | return ImplicitCastExpr::Create(Importer.getToContext(), T, E->getCastKind(), |
John McCall | 2536c6d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 5677 | SubExpr, &BasePath, E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5678 | } |
| 5679 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5680 | Expr *ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5681 | QualType T = Importer.Import(E->getType()); |
| 5682 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5683 | return nullptr; |
| 5684 | |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5685 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5686 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5687 | return nullptr; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5688 | |
| 5689 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeInfoAsWritten()); |
| 5690 | if (!TInfo && E->getTypeInfoAsWritten()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5691 | return nullptr; |
| 5692 | |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5693 | CXXCastPath BasePath; |
| 5694 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5695 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5696 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5697 | switch (E->getStmtClass()) { |
| 5698 | case Stmt::CStyleCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5699 | auto *CCE = cast<CStyleCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5700 | return CStyleCastExpr::Create(Importer.getToContext(), T, |
| 5701 | E->getValueKind(), E->getCastKind(), |
| 5702 | SubExpr, &BasePath, TInfo, |
| 5703 | Importer.Import(CCE->getLParenLoc()), |
| 5704 | Importer.Import(CCE->getRParenLoc())); |
| 5705 | } |
| 5706 | |
| 5707 | case Stmt::CXXFunctionalCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5708 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5709 | return CXXFunctionalCastExpr::Create(Importer.getToContext(), T, |
| 5710 | E->getValueKind(), TInfo, |
| 5711 | E->getCastKind(), SubExpr, &BasePath, |
| 5712 | Importer.Import(FCE->getLParenLoc()), |
| 5713 | Importer.Import(FCE->getRParenLoc())); |
| 5714 | } |
| 5715 | |
| 5716 | case Stmt::ObjCBridgedCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5717 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5718 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 5719 | Importer.Import(OCE->getLParenLoc()), OCE->getBridgeKind(), |
| 5720 | E->getCastKind(), Importer.Import(OCE->getBridgeKeywordLoc()), |
| 5721 | TInfo, SubExpr); |
| 5722 | } |
| 5723 | default: |
| 5724 | break; // just fall through |
| 5725 | } |
| 5726 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5727 | auto *Named = cast<CXXNamedCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5728 | SourceLocation ExprLoc = Importer.Import(Named->getOperatorLoc()), |
| 5729 | RParenLoc = Importer.Import(Named->getRParenLoc()); |
| 5730 | SourceRange Brackets = Importer.Import(Named->getAngleBrackets()); |
| 5731 | |
| 5732 | switch (E->getStmtClass()) { |
| 5733 | case Stmt::CXXStaticCastExprClass: |
| 5734 | return CXXStaticCastExpr::Create(Importer.getToContext(), T, |
| 5735 | E->getValueKind(), E->getCastKind(), |
| 5736 | SubExpr, &BasePath, TInfo, |
| 5737 | ExprLoc, RParenLoc, Brackets); |
| 5738 | |
| 5739 | case Stmt::CXXDynamicCastExprClass: |
| 5740 | return CXXDynamicCastExpr::Create(Importer.getToContext(), T, |
| 5741 | E->getValueKind(), E->getCastKind(), |
| 5742 | SubExpr, &BasePath, TInfo, |
| 5743 | ExprLoc, RParenLoc, Brackets); |
| 5744 | |
| 5745 | case Stmt::CXXReinterpretCastExprClass: |
| 5746 | return CXXReinterpretCastExpr::Create(Importer.getToContext(), T, |
| 5747 | E->getValueKind(), E->getCastKind(), |
| 5748 | SubExpr, &BasePath, TInfo, |
| 5749 | ExprLoc, RParenLoc, Brackets); |
| 5750 | |
| 5751 | case Stmt::CXXConstCastExprClass: |
| 5752 | return CXXConstCastExpr::Create(Importer.getToContext(), T, |
| 5753 | E->getValueKind(), SubExpr, TInfo, ExprLoc, |
| 5754 | RParenLoc, Brackets); |
| 5755 | default: |
| 5756 | llvm_unreachable("Cast expression of unsupported type!"); |
| 5757 | return nullptr; |
| 5758 | } |
| 5759 | } |
| 5760 | |
| 5761 | Expr *ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *OE) { |
| 5762 | QualType T = Importer.Import(OE->getType()); |
| 5763 | if (T.isNull()) |
| 5764 | return nullptr; |
| 5765 | |
| 5766 | SmallVector<OffsetOfNode, 4> Nodes; |
| 5767 | for (int I = 0, E = OE->getNumComponents(); I < E; ++I) { |
| 5768 | const OffsetOfNode &Node = OE->getComponent(I); |
| 5769 | |
| 5770 | switch (Node.getKind()) { |
| 5771 | case OffsetOfNode::Array: |
| 5772 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), |
| 5773 | Node.getArrayExprIndex(), |
| 5774 | Importer.Import(Node.getLocEnd()))); |
| 5775 | break; |
| 5776 | |
| 5777 | case OffsetOfNode::Base: { |
| 5778 | CXXBaseSpecifier *BS = Importer.Import(Node.getBase()); |
| 5779 | if (!BS && Node.getBase()) |
| 5780 | return nullptr; |
| 5781 | Nodes.push_back(OffsetOfNode(BS)); |
| 5782 | break; |
| 5783 | } |
| 5784 | case OffsetOfNode::Field: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5785 | auto *FD = cast_or_null<FieldDecl>(Importer.Import(Node.getField())); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5786 | if (!FD) |
| 5787 | return nullptr; |
| 5788 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), FD, |
| 5789 | Importer.Import(Node.getLocEnd()))); |
| 5790 | break; |
| 5791 | } |
| 5792 | case OffsetOfNode::Identifier: { |
| 5793 | IdentifierInfo *ToII = Importer.Import(Node.getFieldName()); |
| 5794 | if (!ToII) |
| 5795 | return nullptr; |
| 5796 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), ToII, |
| 5797 | Importer.Import(Node.getLocEnd()))); |
| 5798 | break; |
| 5799 | } |
| 5800 | } |
| 5801 | } |
| 5802 | |
| 5803 | SmallVector<Expr *, 4> Exprs(OE->getNumExpressions()); |
| 5804 | for (int I = 0, E = OE->getNumExpressions(); I < E; ++I) { |
| 5805 | Expr *ToIndexExpr = Importer.Import(OE->getIndexExpr(I)); |
| 5806 | if (!ToIndexExpr) |
| 5807 | return nullptr; |
| 5808 | Exprs[I] = ToIndexExpr; |
| 5809 | } |
| 5810 | |
| 5811 | TypeSourceInfo *TInfo = Importer.Import(OE->getTypeSourceInfo()); |
| 5812 | if (!TInfo && OE->getTypeSourceInfo()) |
| 5813 | return nullptr; |
| 5814 | |
| 5815 | return OffsetOfExpr::Create(Importer.getToContext(), T, |
| 5816 | Importer.Import(OE->getOperatorLoc()), |
| 5817 | TInfo, Nodes, Exprs, |
| 5818 | Importer.Import(OE->getRParenLoc())); |
| 5819 | } |
| 5820 | |
| 5821 | Expr *ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 5822 | QualType T = Importer.Import(E->getType()); |
| 5823 | if (T.isNull()) |
| 5824 | return nullptr; |
| 5825 | |
| 5826 | Expr *Operand = Importer.Import(E->getOperand()); |
| 5827 | if (!Operand) |
| 5828 | return nullptr; |
| 5829 | |
| 5830 | CanThrowResult CanThrow; |
| 5831 | if (E->isValueDependent()) |
| 5832 | CanThrow = CT_Dependent; |
| 5833 | else |
| 5834 | CanThrow = E->getValue() ? CT_Can : CT_Cannot; |
| 5835 | |
| 5836 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 5837 | T, Operand, CanThrow, |
| 5838 | Importer.Import(E->getLocStart()), Importer.Import(E->getLocEnd())); |
| 5839 | } |
| 5840 | |
| 5841 | Expr *ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 5842 | QualType T = Importer.Import(E->getType()); |
| 5843 | if (T.isNull()) |
| 5844 | return nullptr; |
| 5845 | |
| 5846 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5847 | if (!SubExpr && E->getSubExpr()) |
| 5848 | return nullptr; |
| 5849 | |
| 5850 | return new (Importer.getToContext()) CXXThrowExpr( |
| 5851 | SubExpr, T, Importer.Import(E->getThrowLoc()), |
| 5852 | E->isThrownVariableInScope()); |
| 5853 | } |
| 5854 | |
| 5855 | Expr *ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5856 | auto *Param = cast_or_null<ParmVarDecl>(Importer.Import(E->getParam())); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5857 | if (!Param) |
| 5858 | return nullptr; |
| 5859 | |
| 5860 | return CXXDefaultArgExpr::Create( |
| 5861 | Importer.getToContext(), Importer.Import(E->getUsedLocation()), Param); |
| 5862 | } |
| 5863 | |
| 5864 | Expr *ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 5865 | QualType T = Importer.Import(E->getType()); |
| 5866 | if (T.isNull()) |
| 5867 | return nullptr; |
| 5868 | |
| 5869 | TypeSourceInfo *TypeInfo = Importer.Import(E->getTypeSourceInfo()); |
| 5870 | if (!TypeInfo) |
| 5871 | return nullptr; |
| 5872 | |
| 5873 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
| 5874 | T, TypeInfo, Importer.Import(E->getRParenLoc())); |
| 5875 | } |
| 5876 | |
| 5877 | Expr *ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 5878 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5879 | if (!SubExpr) |
| 5880 | return nullptr; |
| 5881 | |
| 5882 | auto *Dtor = cast_or_null<CXXDestructorDecl>( |
| 5883 | Importer.Import(const_cast<CXXDestructorDecl *>( |
| 5884 | E->getTemporary()->getDestructor()))); |
| 5885 | if (!Dtor) |
| 5886 | return nullptr; |
| 5887 | |
| 5888 | ASTContext &ToCtx = Importer.getToContext(); |
| 5889 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, Dtor); |
| 5890 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, SubExpr); |
| 5891 | } |
| 5892 | |
| 5893 | Expr *ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE) { |
| 5894 | QualType T = Importer.Import(CE->getType()); |
| 5895 | if (T.isNull()) |
| 5896 | return nullptr; |
| 5897 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 5898 | TypeSourceInfo *TInfo = Importer.Import(CE->getTypeSourceInfo()); |
| 5899 | if (!TInfo) |
| 5900 | return nullptr; |
| 5901 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5902 | SmallVector<Expr *, 8> Args(CE->getNumArgs()); |
| 5903 | if (ImportContainerChecked(CE->arguments(), Args)) |
| 5904 | return nullptr; |
| 5905 | |
| 5906 | auto *Ctor = cast_or_null<CXXConstructorDecl>( |
| 5907 | Importer.Import(CE->getConstructor())); |
| 5908 | if (!Ctor) |
| 5909 | return nullptr; |
| 5910 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 5911 | return new (Importer.getToContext()) CXXTemporaryObjectExpr( |
| 5912 | Importer.getToContext(), Ctor, T, TInfo, Args, |
| 5913 | Importer.Import(CE->getParenOrBraceRange()), CE->hadMultipleCandidates(), |
| 5914 | CE->isListInitialization(), CE->isStdInitListInitialization(), |
| 5915 | CE->requiresZeroInitialization()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5916 | } |
| 5917 | |
| 5918 | Expr * |
| 5919 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
| 5920 | QualType T = Importer.Import(E->getType()); |
| 5921 | if (T.isNull()) |
| 5922 | return nullptr; |
| 5923 | |
| 5924 | Expr *TempE = Importer.Import(E->GetTemporaryExpr()); |
| 5925 | if (!TempE) |
| 5926 | return nullptr; |
| 5927 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5928 | auto *ExtendedBy = cast_or_null<ValueDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5929 | Importer.Import(const_cast<ValueDecl *>(E->getExtendingDecl()))); |
| 5930 | if (!ExtendedBy && E->getExtendingDecl()) |
| 5931 | return nullptr; |
| 5932 | |
| 5933 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
| 5934 | T, TempE, E->isBoundToLvalueReference()); |
| 5935 | |
| 5936 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
| 5937 | ToMTE->setExtendingDecl(ExtendedBy, E->getManglingNumber()); |
| 5938 | return ToMTE; |
| 5939 | } |
| 5940 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 5941 | Expr *ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 5942 | QualType T = Importer.Import(E->getType()); |
| 5943 | if (T.isNull()) |
| 5944 | return nullptr; |
| 5945 | |
| 5946 | Expr *Pattern = Importer.Import(E->getPattern()); |
| 5947 | if (!Pattern) |
| 5948 | return nullptr; |
| 5949 | |
| 5950 | return new (Importer.getToContext()) PackExpansionExpr( |
| 5951 | T, Pattern, Importer.Import(E->getEllipsisLoc()), |
| 5952 | E->getNumExpansions()); |
| 5953 | } |
| 5954 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 5955 | Expr *ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 5956 | auto *Pack = cast_or_null<NamedDecl>(Importer.Import(E->getPack())); |
| 5957 | if (!Pack) |
| 5958 | return nullptr; |
| 5959 | |
| 5960 | Optional<unsigned> Length; |
| 5961 | |
| 5962 | if (!E->isValueDependent()) |
| 5963 | Length = E->getPackLength(); |
| 5964 | |
| 5965 | SmallVector<TemplateArgument, 8> PartialArguments; |
| 5966 | if (E->isPartiallySubstituted()) { |
| 5967 | if (ImportTemplateArguments(E->getPartialArguments().data(), |
| 5968 | E->getPartialArguments().size(), |
| 5969 | PartialArguments)) |
| 5970 | return nullptr; |
| 5971 | } |
| 5972 | |
| 5973 | return SizeOfPackExpr::Create( |
| 5974 | Importer.getToContext(), Importer.Import(E->getOperatorLoc()), Pack, |
| 5975 | Importer.Import(E->getPackLoc()), Importer.Import(E->getRParenLoc()), |
| 5976 | Length, PartialArguments); |
| 5977 | } |
| 5978 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5979 | Expr *ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *CE) { |
| 5980 | QualType T = Importer.Import(CE->getType()); |
| 5981 | if (T.isNull()) |
| 5982 | return nullptr; |
| 5983 | |
| 5984 | SmallVector<Expr *, 4> PlacementArgs(CE->getNumPlacementArgs()); |
| 5985 | if (ImportContainerChecked(CE->placement_arguments(), PlacementArgs)) |
| 5986 | return nullptr; |
| 5987 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5988 | auto *OperatorNewDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5989 | Importer.Import(CE->getOperatorNew())); |
| 5990 | if (!OperatorNewDecl && CE->getOperatorNew()) |
| 5991 | return nullptr; |
| 5992 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5993 | auto *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5994 | Importer.Import(CE->getOperatorDelete())); |
| 5995 | if (!OperatorDeleteDecl && CE->getOperatorDelete()) |
| 5996 | return nullptr; |
| 5997 | |
| 5998 | Expr *ToInit = Importer.Import(CE->getInitializer()); |
| 5999 | if (!ToInit && CE->getInitializer()) |
| 6000 | return nullptr; |
| 6001 | |
| 6002 | TypeSourceInfo *TInfo = Importer.Import(CE->getAllocatedTypeSourceInfo()); |
| 6003 | if (!TInfo) |
| 6004 | return nullptr; |
| 6005 | |
| 6006 | Expr *ToArrSize = Importer.Import(CE->getArraySize()); |
| 6007 | if (!ToArrSize && CE->getArraySize()) |
| 6008 | return nullptr; |
| 6009 | |
| 6010 | return new (Importer.getToContext()) CXXNewExpr( |
| 6011 | Importer.getToContext(), |
| 6012 | CE->isGlobalNew(), |
| 6013 | OperatorNewDecl, OperatorDeleteDecl, |
Richard Smith | b2f0f05 | 2016-10-10 18:54:32 +0000 | [diff] [blame] | 6014 | CE->passAlignment(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6015 | CE->doesUsualArrayDeleteWantSize(), |
| 6016 | PlacementArgs, |
| 6017 | Importer.Import(CE->getTypeIdParens()), |
| 6018 | ToArrSize, CE->getInitializationStyle(), ToInit, T, TInfo, |
| 6019 | Importer.Import(CE->getSourceRange()), |
| 6020 | Importer.Import(CE->getDirectInitRange())); |
| 6021 | } |
| 6022 | |
| 6023 | Expr *ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 6024 | QualType T = Importer.Import(E->getType()); |
| 6025 | if (T.isNull()) |
| 6026 | return nullptr; |
| 6027 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6028 | auto *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6029 | Importer.Import(E->getOperatorDelete())); |
| 6030 | if (!OperatorDeleteDecl && E->getOperatorDelete()) |
| 6031 | return nullptr; |
| 6032 | |
| 6033 | Expr *ToArg = Importer.Import(E->getArgument()); |
| 6034 | if (!ToArg && E->getArgument()) |
| 6035 | return nullptr; |
| 6036 | |
| 6037 | return new (Importer.getToContext()) CXXDeleteExpr( |
| 6038 | T, E->isGlobalDelete(), |
| 6039 | E->isArrayForm(), |
| 6040 | E->isArrayFormAsWritten(), |
| 6041 | E->doesUsualArrayDeleteWantSize(), |
| 6042 | OperatorDeleteDecl, |
| 6043 | ToArg, |
| 6044 | Importer.Import(E->getLocStart())); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 6045 | } |
| 6046 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6047 | Expr *ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 6048 | QualType T = Importer.Import(E->getType()); |
| 6049 | if (T.isNull()) |
| 6050 | return nullptr; |
| 6051 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6052 | auto *ToCCD = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6053 | dyn_cast_or_null<CXXConstructorDecl>(Importer.Import(E->getConstructor())); |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 6054 | if (!ToCCD) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6055 | return nullptr; |
| 6056 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6057 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6058 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6059 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6060 | |
| 6061 | return CXXConstructExpr::Create(Importer.getToContext(), T, |
| 6062 | Importer.Import(E->getLocation()), |
Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 6063 | ToCCD, E->isElidable(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6064 | ToArgs, E->hadMultipleCandidates(), |
| 6065 | E->isListInitialization(), |
| 6066 | E->isStdInitListInitialization(), |
| 6067 | E->requiresZeroInitialization(), |
| 6068 | E->getConstructionKind(), |
| 6069 | Importer.Import(E->getParenOrBraceRange())); |
| 6070 | } |
| 6071 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6072 | Expr *ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *EWC) { |
| 6073 | Expr *SubExpr = Importer.Import(EWC->getSubExpr()); |
| 6074 | if (!SubExpr && EWC->getSubExpr()) |
| 6075 | return nullptr; |
| 6076 | |
| 6077 | SmallVector<ExprWithCleanups::CleanupObject, 8> Objs(EWC->getNumObjects()); |
| 6078 | for (unsigned I = 0, E = EWC->getNumObjects(); I < E; I++) |
| 6079 | if (ExprWithCleanups::CleanupObject Obj = |
| 6080 | cast_or_null<BlockDecl>(Importer.Import(EWC->getObject(I)))) |
| 6081 | Objs[I] = Obj; |
| 6082 | else |
| 6083 | return nullptr; |
| 6084 | |
| 6085 | return ExprWithCleanups::Create(Importer.getToContext(), |
| 6086 | SubExpr, EWC->cleanupsHaveSideEffects(), |
| 6087 | Objs); |
| 6088 | } |
| 6089 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6090 | Expr *ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6091 | QualType T = Importer.Import(E->getType()); |
| 6092 | if (T.isNull()) |
| 6093 | return nullptr; |
| 6094 | |
| 6095 | Expr *ToFn = Importer.Import(E->getCallee()); |
| 6096 | if (!ToFn) |
| 6097 | return nullptr; |
| 6098 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6099 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6100 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6101 | return nullptr; |
| 6102 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6103 | return new (Importer.getToContext()) CXXMemberCallExpr( |
| 6104 | Importer.getToContext(), ToFn, ToArgs, T, E->getValueKind(), |
| 6105 | Importer.Import(E->getRParenLoc())); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6106 | } |
| 6107 | |
| 6108 | Expr *ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 6109 | QualType T = Importer.Import(E->getType()); |
| 6110 | if (T.isNull()) |
| 6111 | return nullptr; |
| 6112 | |
| 6113 | return new (Importer.getToContext()) |
| 6114 | CXXThisExpr(Importer.Import(E->getLocation()), T, E->isImplicit()); |
| 6115 | } |
| 6116 | |
| 6117 | Expr *ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 6118 | QualType T = Importer.Import(E->getType()); |
| 6119 | if (T.isNull()) |
| 6120 | return nullptr; |
| 6121 | |
| 6122 | return new (Importer.getToContext()) |
| 6123 | CXXBoolLiteralExpr(E->getValue(), T, Importer.Import(E->getLocation())); |
| 6124 | } |
| 6125 | |
| 6126 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6127 | Expr *ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 6128 | QualType T = Importer.Import(E->getType()); |
| 6129 | if (T.isNull()) |
| 6130 | return nullptr; |
| 6131 | |
| 6132 | Expr *ToBase = Importer.Import(E->getBase()); |
| 6133 | if (!ToBase && E->getBase()) |
| 6134 | return nullptr; |
| 6135 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6136 | auto *ToMember = dyn_cast<ValueDecl>(Importer.Import(E->getMemberDecl())); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6137 | if (!ToMember && E->getMemberDecl()) |
| 6138 | return nullptr; |
| 6139 | |
Peter Szecsi | ef97252 | 2018-05-02 11:52:54 +0000 | [diff] [blame] | 6140 | auto *ToDecl = |
| 6141 | dyn_cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl().getDecl())); |
| 6142 | if (!ToDecl && E->getFoundDecl().getDecl()) |
| 6143 | return nullptr; |
| 6144 | |
| 6145 | DeclAccessPair ToFoundDecl = |
| 6146 | DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6147 | |
| 6148 | DeclarationNameInfo ToMemberNameInfo( |
| 6149 | Importer.Import(E->getMemberNameInfo().getName()), |
| 6150 | Importer.Import(E->getMemberNameInfo().getLoc())); |
| 6151 | |
| 6152 | if (E->hasExplicitTemplateArgs()) { |
| 6153 | return nullptr; // FIXME: handle template arguments |
| 6154 | } |
| 6155 | |
| 6156 | return MemberExpr::Create(Importer.getToContext(), ToBase, |
| 6157 | E->isArrow(), |
| 6158 | Importer.Import(E->getOperatorLoc()), |
| 6159 | Importer.Import(E->getQualifierLoc()), |
| 6160 | Importer.Import(E->getTemplateKeywordLoc()), |
| 6161 | ToMember, ToFoundDecl, ToMemberNameInfo, |
| 6162 | nullptr, T, E->getValueKind(), |
| 6163 | E->getObjectKind()); |
| 6164 | } |
| 6165 | |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 6166 | Expr *ASTNodeImporter::VisitCXXPseudoDestructorExpr( |
| 6167 | CXXPseudoDestructorExpr *E) { |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 6168 | Expr *BaseE = Importer.Import(E->getBase()); |
| 6169 | if (!BaseE) |
| 6170 | return nullptr; |
| 6171 | |
| 6172 | TypeSourceInfo *ScopeInfo = Importer.Import(E->getScopeTypeInfo()); |
| 6173 | if (!ScopeInfo && E->getScopeTypeInfo()) |
| 6174 | return nullptr; |
| 6175 | |
| 6176 | PseudoDestructorTypeStorage Storage; |
| 6177 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 6178 | IdentifierInfo *ToII = Importer.Import(FromII); |
| 6179 | if (!ToII) |
| 6180 | return nullptr; |
| 6181 | Storage = PseudoDestructorTypeStorage( |
| 6182 | ToII, Importer.Import(E->getDestroyedTypeLoc())); |
| 6183 | } else { |
| 6184 | TypeSourceInfo *TI = Importer.Import(E->getDestroyedTypeInfo()); |
| 6185 | if (!TI) |
| 6186 | return nullptr; |
| 6187 | Storage = PseudoDestructorTypeStorage(TI); |
| 6188 | } |
| 6189 | |
| 6190 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
| 6191 | Importer.getToContext(), BaseE, E->isArrow(), |
| 6192 | Importer.Import(E->getOperatorLoc()), |
| 6193 | Importer.Import(E->getQualifierLoc()), |
| 6194 | ScopeInfo, Importer.Import(E->getColonColonLoc()), |
| 6195 | Importer.Import(E->getTildeLoc()), Storage); |
| 6196 | } |
| 6197 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6198 | Expr *ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
| 6199 | CXXDependentScopeMemberExpr *E) { |
| 6200 | Expr *Base = nullptr; |
| 6201 | if (!E->isImplicitAccess()) { |
| 6202 | Base = Importer.Import(E->getBase()); |
| 6203 | if (!Base) |
| 6204 | return nullptr; |
| 6205 | } |
| 6206 | |
| 6207 | QualType BaseType = Importer.Import(E->getBaseType()); |
| 6208 | if (BaseType.isNull()) |
| 6209 | return nullptr; |
| 6210 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6211 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6212 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6213 | if (ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6214 | E->template_arguments(), ToTAInfo)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6215 | return nullptr; |
| 6216 | ResInfo = &ToTAInfo; |
| 6217 | } |
| 6218 | |
| 6219 | DeclarationName Name = Importer.Import(E->getMember()); |
| 6220 | if (!E->getMember().isEmpty() && Name.isEmpty()) |
| 6221 | return nullptr; |
| 6222 | |
| 6223 | DeclarationNameInfo MemberNameInfo(Name, Importer.Import(E->getMemberLoc())); |
| 6224 | // Import additional name location/type info. |
| 6225 | ImportDeclarationNameLoc(E->getMemberNameInfo(), MemberNameInfo); |
| 6226 | auto ToFQ = Importer.Import(E->getFirstQualifierFoundInScope()); |
| 6227 | if (!ToFQ && E->getFirstQualifierFoundInScope()) |
| 6228 | return nullptr; |
| 6229 | |
| 6230 | return CXXDependentScopeMemberExpr::Create( |
| 6231 | Importer.getToContext(), Base, BaseType, E->isArrow(), |
| 6232 | Importer.Import(E->getOperatorLoc()), |
| 6233 | Importer.Import(E->getQualifierLoc()), |
| 6234 | Importer.Import(E->getTemplateKeywordLoc()), |
| 6235 | cast_or_null<NamedDecl>(ToFQ), MemberNameInfo, ResInfo); |
| 6236 | } |
| 6237 | |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 6238 | Expr * |
| 6239 | ASTNodeImporter::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) { |
| 6240 | DeclarationName Name = Importer.Import(E->getDeclName()); |
| 6241 | if (!E->getDeclName().isEmpty() && Name.isEmpty()) |
| 6242 | return nullptr; |
| 6243 | |
| 6244 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getExprLoc())); |
| 6245 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6246 | |
| 6247 | TemplateArgumentListInfo ToTAInfo(Importer.Import(E->getLAngleLoc()), |
| 6248 | Importer.Import(E->getRAngleLoc())); |
| 6249 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 6250 | if (E->hasExplicitTemplateArgs()) { |
| 6251 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6252 | return nullptr; |
| 6253 | ResInfo = &ToTAInfo; |
| 6254 | } |
| 6255 | |
| 6256 | return DependentScopeDeclRefExpr::Create( |
| 6257 | Importer.getToContext(), Importer.Import(E->getQualifierLoc()), |
| 6258 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, ResInfo); |
| 6259 | } |
| 6260 | |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6261 | Expr *ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 6262 | CXXUnresolvedConstructExpr *CE) { |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6263 | unsigned NumArgs = CE->arg_size(); |
| 6264 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6265 | SmallVector<Expr *, 8> ToArgs(NumArgs); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6266 | if (ImportArrayChecked(CE->arg_begin(), CE->arg_end(), ToArgs.begin())) |
| 6267 | return nullptr; |
| 6268 | |
| 6269 | return CXXUnresolvedConstructExpr::Create( |
| 6270 | Importer.getToContext(), Importer.Import(CE->getTypeSourceInfo()), |
| 6271 | Importer.Import(CE->getLParenLoc()), llvm::makeArrayRef(ToArgs), |
| 6272 | Importer.Import(CE->getRParenLoc())); |
| 6273 | } |
| 6274 | |
| 6275 | Expr *ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6276 | auto *NamingClass = |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6277 | cast_or_null<CXXRecordDecl>(Importer.Import(E->getNamingClass())); |
| 6278 | if (E->getNamingClass() && !NamingClass) |
| 6279 | return nullptr; |
| 6280 | |
| 6281 | DeclarationName Name = Importer.Import(E->getName()); |
| 6282 | if (E->getName() && !Name) |
| 6283 | return nullptr; |
| 6284 | |
| 6285 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getNameLoc())); |
| 6286 | // Import additional name location/type info. |
| 6287 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6288 | |
| 6289 | UnresolvedSet<8> ToDecls; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6290 | for (auto *D : E->decls()) { |
| 6291 | if (auto *To = cast_or_null<NamedDecl>(Importer.Import(D))) |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6292 | ToDecls.addDecl(To); |
| 6293 | else |
| 6294 | return nullptr; |
| 6295 | } |
| 6296 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6297 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6298 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6299 | if (ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6300 | E->template_arguments(), ToTAInfo)) |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6301 | return nullptr; |
| 6302 | ResInfo = &ToTAInfo; |
| 6303 | } |
| 6304 | |
| 6305 | if (ResInfo || E->getTemplateKeywordLoc().isValid()) |
| 6306 | return UnresolvedLookupExpr::Create( |
| 6307 | Importer.getToContext(), NamingClass, |
| 6308 | Importer.Import(E->getQualifierLoc()), |
| 6309 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, E->requiresADL(), |
| 6310 | ResInfo, ToDecls.begin(), ToDecls.end()); |
| 6311 | |
| 6312 | return UnresolvedLookupExpr::Create( |
| 6313 | Importer.getToContext(), NamingClass, |
| 6314 | Importer.Import(E->getQualifierLoc()), NameInfo, E->requiresADL(), |
| 6315 | E->isOverloaded(), ToDecls.begin(), ToDecls.end()); |
| 6316 | } |
| 6317 | |
Peter Szecsi | ce7f318 | 2018-05-07 12:08:27 +0000 | [diff] [blame] | 6318 | Expr *ASTNodeImporter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { |
| 6319 | DeclarationName Name = Importer.Import(E->getName()); |
| 6320 | if (!E->getName().isEmpty() && Name.isEmpty()) |
| 6321 | return nullptr; |
| 6322 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getNameLoc())); |
| 6323 | // Import additional name location/type info. |
| 6324 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6325 | |
| 6326 | QualType BaseType = Importer.Import(E->getType()); |
| 6327 | if (!E->getType().isNull() && BaseType.isNull()) |
| 6328 | return nullptr; |
| 6329 | |
| 6330 | UnresolvedSet<8> ToDecls; |
| 6331 | for (Decl *D : E->decls()) { |
| 6332 | if (NamedDecl *To = cast_or_null<NamedDecl>(Importer.Import(D))) |
| 6333 | ToDecls.addDecl(To); |
| 6334 | else |
| 6335 | return nullptr; |
| 6336 | } |
| 6337 | |
| 6338 | TemplateArgumentListInfo ToTAInfo; |
| 6339 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 6340 | if (E->hasExplicitTemplateArgs()) { |
| 6341 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 6342 | return nullptr; |
| 6343 | ResInfo = &ToTAInfo; |
| 6344 | } |
| 6345 | |
| 6346 | Expr *BaseE = E->isImplicitAccess() ? nullptr : Importer.Import(E->getBase()); |
| 6347 | if (!BaseE && !E->isImplicitAccess() && E->getBase()) { |
| 6348 | return nullptr; |
| 6349 | } |
| 6350 | |
| 6351 | return UnresolvedMemberExpr::Create( |
| 6352 | Importer.getToContext(), E->hasUnresolvedUsing(), BaseE, BaseType, |
| 6353 | E->isArrow(), Importer.Import(E->getOperatorLoc()), |
| 6354 | Importer.Import(E->getQualifierLoc()), |
| 6355 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, ResInfo, |
| 6356 | ToDecls.begin(), ToDecls.end()); |
| 6357 | } |
| 6358 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6359 | Expr *ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 6360 | QualType T = Importer.Import(E->getType()); |
| 6361 | if (T.isNull()) |
| 6362 | return nullptr; |
| 6363 | |
| 6364 | Expr *ToCallee = Importer.Import(E->getCallee()); |
| 6365 | if (!ToCallee && E->getCallee()) |
| 6366 | return nullptr; |
| 6367 | |
| 6368 | unsigned NumArgs = E->getNumArgs(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6369 | SmallVector<Expr *, 2> ToArgs(NumArgs); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6370 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
| 6371 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6372 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6373 | auto **ToArgs_Copied = new (Importer.getToContext()) Expr*[NumArgs]; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6374 | |
| 6375 | for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) |
| 6376 | ToArgs_Copied[ai] = ToArgs[ai]; |
| 6377 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6378 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| 6379 | return new (Importer.getToContext()) CXXOperatorCallExpr( |
| 6380 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, T, |
| 6381 | OCE->getValueKind(), Importer.Import(OCE->getRParenLoc()), |
| 6382 | OCE->getFPFeatures()); |
| 6383 | } |
| 6384 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6385 | return new (Importer.getToContext()) |
| 6386 | CallExpr(Importer.getToContext(), ToCallee, |
Craig Topper | c005cc0 | 2015-09-27 03:44:08 +0000 | [diff] [blame] | 6387 | llvm::makeArrayRef(ToArgs_Copied, NumArgs), T, E->getValueKind(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6388 | Importer.Import(E->getRParenLoc())); |
| 6389 | } |
| 6390 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6391 | Optional<LambdaCapture> |
| 6392 | ASTNodeImporter::ImportLambdaCapture(const LambdaCapture &From) { |
| 6393 | VarDecl *Var = nullptr; |
| 6394 | if (From.capturesVariable()) { |
| 6395 | Var = cast_or_null<VarDecl>(Importer.Import(From.getCapturedVar())); |
| 6396 | if (!Var) |
| 6397 | return None; |
| 6398 | } |
| 6399 | |
| 6400 | return LambdaCapture(Importer.Import(From.getLocation()), From.isImplicit(), |
| 6401 | From.getCaptureKind(), Var, |
| 6402 | From.isPackExpansion() |
| 6403 | ? Importer.Import(From.getEllipsisLoc()) |
| 6404 | : SourceLocation()); |
| 6405 | } |
| 6406 | |
| 6407 | Expr *ASTNodeImporter::VisitLambdaExpr(LambdaExpr *LE) { |
| 6408 | CXXRecordDecl *FromClass = LE->getLambdaClass(); |
| 6409 | auto *ToClass = dyn_cast_or_null<CXXRecordDecl>(Importer.Import(FromClass)); |
| 6410 | if (!ToClass) |
| 6411 | return nullptr; |
| 6412 | |
| 6413 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 6414 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 6415 | // manually. |
| 6416 | if (ToClass->isBeingDefined()) { |
| 6417 | for (auto FromField : FromClass->fields()) { |
| 6418 | auto *ToField = cast_or_null<FieldDecl>(Importer.Import(FromField)); |
| 6419 | if (!ToField) |
| 6420 | return nullptr; |
| 6421 | } |
| 6422 | } |
| 6423 | |
| 6424 | auto *ToCallOp = dyn_cast_or_null<CXXMethodDecl>( |
| 6425 | Importer.Import(LE->getCallOperator())); |
| 6426 | if (!ToCallOp) |
| 6427 | return nullptr; |
| 6428 | |
| 6429 | ToClass->completeDefinition(); |
| 6430 | |
| 6431 | unsigned NumCaptures = LE->capture_size(); |
| 6432 | SmallVector<LambdaCapture, 8> Captures; |
| 6433 | Captures.reserve(NumCaptures); |
| 6434 | for (const auto &FromCapture : LE->captures()) { |
| 6435 | if (auto ToCapture = ImportLambdaCapture(FromCapture)) |
| 6436 | Captures.push_back(*ToCapture); |
| 6437 | else |
| 6438 | return nullptr; |
| 6439 | } |
| 6440 | |
| 6441 | SmallVector<Expr *, 8> InitCaptures(NumCaptures); |
| 6442 | if (ImportContainerChecked(LE->capture_inits(), InitCaptures)) |
| 6443 | return nullptr; |
| 6444 | |
| 6445 | return LambdaExpr::Create(Importer.getToContext(), ToClass, |
| 6446 | Importer.Import(LE->getIntroducerRange()), |
| 6447 | LE->getCaptureDefault(), |
| 6448 | Importer.Import(LE->getCaptureDefaultLoc()), |
| 6449 | Captures, |
| 6450 | LE->hasExplicitParameters(), |
| 6451 | LE->hasExplicitResultType(), |
| 6452 | InitCaptures, |
| 6453 | Importer.Import(LE->getLocEnd()), |
| 6454 | LE->containsUnexpandedParameterPack()); |
| 6455 | } |
| 6456 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6457 | Expr *ASTNodeImporter::VisitInitListExpr(InitListExpr *ILE) { |
| 6458 | QualType T = Importer.Import(ILE->getType()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6459 | if (T.isNull()) |
| 6460 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6461 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6462 | SmallVector<Expr *, 4> Exprs(ILE->getNumInits()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6463 | if (ImportContainerChecked(ILE->inits(), Exprs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6464 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6465 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6466 | ASTContext &ToCtx = Importer.getToContext(); |
| 6467 | InitListExpr *To = new (ToCtx) InitListExpr( |
| 6468 | ToCtx, Importer.Import(ILE->getLBraceLoc()), |
| 6469 | Exprs, Importer.Import(ILE->getLBraceLoc())); |
| 6470 | To->setType(T); |
| 6471 | |
| 6472 | if (ILE->hasArrayFiller()) { |
| 6473 | Expr *Filler = Importer.Import(ILE->getArrayFiller()); |
| 6474 | if (!Filler) |
| 6475 | return nullptr; |
| 6476 | To->setArrayFiller(Filler); |
| 6477 | } |
| 6478 | |
| 6479 | if (FieldDecl *FromFD = ILE->getInitializedFieldInUnion()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6480 | auto *ToFD = cast_or_null<FieldDecl>(Importer.Import(FromFD)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6481 | if (!ToFD) |
| 6482 | return nullptr; |
| 6483 | To->setInitializedFieldInUnion(ToFD); |
| 6484 | } |
| 6485 | |
| 6486 | if (InitListExpr *SyntForm = ILE->getSyntacticForm()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6487 | auto *ToSyntForm = cast_or_null<InitListExpr>(Importer.Import(SyntForm)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6488 | if (!ToSyntForm) |
| 6489 | return nullptr; |
| 6490 | To->setSyntacticForm(ToSyntForm); |
| 6491 | } |
| 6492 | |
| 6493 | To->sawArrayRangeDesignator(ILE->hadArrayRangeDesignator()); |
| 6494 | To->setValueDependent(ILE->isValueDependent()); |
| 6495 | To->setInstantiationDependent(ILE->isInstantiationDependent()); |
| 6496 | |
| 6497 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6498 | } |
| 6499 | |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 6500 | Expr *ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 6501 | QualType ToType = Importer.Import(E->getType()); |
| 6502 | if (ToType.isNull()) |
| 6503 | return nullptr; |
| 6504 | |
| 6505 | Expr *ToCommon = Importer.Import(E->getCommonExpr()); |
| 6506 | if (!ToCommon && E->getCommonExpr()) |
| 6507 | return nullptr; |
| 6508 | |
| 6509 | Expr *ToSubExpr = Importer.Import(E->getSubExpr()); |
| 6510 | if (!ToSubExpr && E->getSubExpr()) |
| 6511 | return nullptr; |
| 6512 | |
| 6513 | return new (Importer.getToContext()) |
| 6514 | ArrayInitLoopExpr(ToType, ToCommon, ToSubExpr); |
| 6515 | } |
| 6516 | |
| 6517 | Expr *ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 6518 | QualType ToType = Importer.Import(E->getType()); |
| 6519 | if (ToType.isNull()) |
| 6520 | return nullptr; |
| 6521 | return new (Importer.getToContext()) ArrayInitIndexExpr(ToType); |
| 6522 | } |
| 6523 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6524 | Expr *ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6525 | auto *ToField = dyn_cast_or_null<FieldDecl>(Importer.Import(DIE->getField())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6526 | if (!ToField && DIE->getField()) |
| 6527 | return nullptr; |
| 6528 | |
| 6529 | return CXXDefaultInitExpr::Create( |
| 6530 | Importer.getToContext(), Importer.Import(DIE->getLocStart()), ToField); |
| 6531 | } |
| 6532 | |
| 6533 | Expr *ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 6534 | QualType ToType = Importer.Import(E->getType()); |
| 6535 | if (ToType.isNull() && !E->getType().isNull()) |
| 6536 | return nullptr; |
| 6537 | ExprValueKind VK = E->getValueKind(); |
| 6538 | CastKind CK = E->getCastKind(); |
| 6539 | Expr *ToOp = Importer.Import(E->getSubExpr()); |
| 6540 | if (!ToOp && E->getSubExpr()) |
| 6541 | return nullptr; |
| 6542 | CXXCastPath BasePath; |
| 6543 | if (ImportCastPath(E, BasePath)) |
| 6544 | return nullptr; |
| 6545 | TypeSourceInfo *ToWritten = Importer.Import(E->getTypeInfoAsWritten()); |
| 6546 | SourceLocation ToOperatorLoc = Importer.Import(E->getOperatorLoc()); |
| 6547 | SourceLocation ToRParenLoc = Importer.Import(E->getRParenLoc()); |
| 6548 | SourceRange ToAngleBrackets = Importer.Import(E->getAngleBrackets()); |
| 6549 | |
| 6550 | if (isa<CXXStaticCastExpr>(E)) { |
| 6551 | return CXXStaticCastExpr::Create( |
| 6552 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6553 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6554 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 6555 | return CXXDynamicCastExpr::Create( |
| 6556 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6557 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6558 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 6559 | return CXXReinterpretCastExpr::Create( |
| 6560 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6561 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6562 | } else { |
| 6563 | return nullptr; |
| 6564 | } |
| 6565 | } |
| 6566 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6567 | Expr *ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
| 6568 | SubstNonTypeTemplateParmExpr *E) { |
| 6569 | QualType T = Importer.Import(E->getType()); |
| 6570 | if (T.isNull()) |
| 6571 | return nullptr; |
| 6572 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6573 | auto *Param = cast_or_null<NonTypeTemplateParmDecl>( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6574 | Importer.Import(E->getParameter())); |
| 6575 | if (!Param) |
| 6576 | return nullptr; |
| 6577 | |
| 6578 | Expr *Replacement = Importer.Import(E->getReplacement()); |
| 6579 | if (!Replacement) |
| 6580 | return nullptr; |
| 6581 | |
| 6582 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
| 6583 | T, E->getValueKind(), Importer.Import(E->getExprLoc()), Param, |
| 6584 | Replacement); |
| 6585 | } |
| 6586 | |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 6587 | Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 6588 | QualType ToType = Importer.Import(E->getType()); |
| 6589 | if (ToType.isNull()) |
| 6590 | return nullptr; |
| 6591 | |
| 6592 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
| 6593 | if (ImportContainerChecked(E->getArgs(), ToArgs)) |
| 6594 | return nullptr; |
| 6595 | |
| 6596 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 6597 | // Value is always false. |
| 6598 | bool ToValue = false; |
| 6599 | if (!E->isValueDependent()) |
| 6600 | ToValue = E->getValue(); |
| 6601 | |
| 6602 | return TypeTraitExpr::Create( |
| 6603 | Importer.getToContext(), ToType, Importer.Import(E->getLocStart()), |
| 6604 | E->getTrait(), ToArgs, Importer.Import(E->getLocEnd()), ToValue); |
| 6605 | } |
| 6606 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6607 | Expr *ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 6608 | QualType ToType = Importer.Import(E->getType()); |
| 6609 | if (ToType.isNull()) |
| 6610 | return nullptr; |
| 6611 | |
| 6612 | if (E->isTypeOperand()) { |
| 6613 | TypeSourceInfo *TSI = Importer.Import(E->getTypeOperandSourceInfo()); |
| 6614 | if (!TSI) |
| 6615 | return nullptr; |
| 6616 | |
| 6617 | return new (Importer.getToContext()) |
| 6618 | CXXTypeidExpr(ToType, TSI, Importer.Import(E->getSourceRange())); |
| 6619 | } |
| 6620 | |
| 6621 | Expr *Op = Importer.Import(E->getExprOperand()); |
| 6622 | if (!Op) |
| 6623 | return nullptr; |
| 6624 | |
| 6625 | return new (Importer.getToContext()) |
| 6626 | CXXTypeidExpr(ToType, Op, Importer.Import(E->getSourceRange())); |
| 6627 | } |
| 6628 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 6629 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 6630 | CXXMethodDecl *FromMethod) { |
| 6631 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) |
| 6632 | ToMethod->addOverriddenMethod( |
| 6633 | cast<CXXMethodDecl>(Importer.Import(const_cast<CXXMethodDecl*>( |
| 6634 | FromOverriddenMethod)))); |
| 6635 | } |
| 6636 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6637 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6638 | ASTContext &FromContext, FileManager &FromFileManager, |
| 6639 | bool MinimalImport) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6640 | : ToContext(ToContext), FromContext(FromContext), |
| 6641 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| 6642 | Minimal(MinimalImport) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6643 | ImportedDecls[FromContext.getTranslationUnitDecl()] |
| 6644 | = ToContext.getTranslationUnitDecl(); |
| 6645 | } |
| 6646 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6647 | ASTImporter::~ASTImporter() = default; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6648 | |
| 6649 | QualType ASTImporter::Import(QualType FromT) { |
| 6650 | if (FromT.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6651 | return {}; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6652 | |
| 6653 | const Type *fromTy = FromT.getTypePtr(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6654 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6655 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6656 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
| 6657 | = ImportedTypes.find(fromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6658 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6659 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6660 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6661 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6662 | ASTNodeImporter Importer(*this); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6663 | QualType ToT = Importer.Visit(fromTy); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6664 | if (ToT.isNull()) |
| 6665 | return ToT; |
| 6666 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6667 | // Record the imported type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6668 | ImportedTypes[fromTy] = ToT.getTypePtr(); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6669 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6670 | return ToContext.getQualifiedType(ToT, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6671 | } |
| 6672 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6673 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 6674 | if (!FromTSI) |
| 6675 | return FromTSI; |
| 6676 | |
| 6677 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 6678 | // 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] | 6679 | QualType T = Import(FromTSI->getType()); |
| 6680 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6681 | return nullptr; |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 6682 | |
| 6683 | return ToContext.getTrivialTypeSourceInfo(T, |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6684 | Import(FromTSI->getTypeLoc().getLocStart())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6685 | } |
| 6686 | |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 6687 | Attr *ASTImporter::Import(const Attr *FromAttr) { |
| 6688 | Attr *ToAttr = FromAttr->clone(ToContext); |
| 6689 | ToAttr->setRange(Import(FromAttr->getRange())); |
| 6690 | return ToAttr; |
| 6691 | } |
| 6692 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6693 | Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) { |
| 6694 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
| 6695 | if (Pos != ImportedDecls.end()) { |
| 6696 | Decl *ToD = Pos->second; |
| 6697 | ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD); |
| 6698 | return ToD; |
| 6699 | } else { |
| 6700 | return nullptr; |
| 6701 | } |
| 6702 | } |
| 6703 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6704 | Decl *ASTImporter::Import(Decl *FromD) { |
| 6705 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6706 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6707 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6708 | ASTNodeImporter Importer(*this); |
| 6709 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6710 | // Check whether we've already imported this declaration. |
| 6711 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6712 | if (Pos != ImportedDecls.end()) { |
| 6713 | Decl *ToD = Pos->second; |
| 6714 | Importer.ImportDefinitionIfNeeded(FromD, ToD); |
| 6715 | return ToD; |
| 6716 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6717 | |
| 6718 | // Import the type |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6719 | Decl *ToD = Importer.Visit(FromD); |
| 6720 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6721 | return nullptr; |
| 6722 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6723 | // Record the imported declaration. |
| 6724 | ImportedDecls[FromD] = ToD; |
Peter Szecsi | b180eeb | 2018-04-25 17:28:03 +0000 | [diff] [blame] | 6725 | ToD->IdentifierNamespace = FromD->IdentifierNamespace; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6726 | return ToD; |
| 6727 | } |
| 6728 | |
| 6729 | DeclContext *ASTImporter::ImportContext(DeclContext *FromDC) { |
| 6730 | if (!FromDC) |
| 6731 | return FromDC; |
| 6732 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6733 | auto *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6734 | if (!ToDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6735 | return nullptr; |
| 6736 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6737 | // When we're using a record/enum/Objective-C class/protocol as a context, we |
| 6738 | // need it to have a definition. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6739 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 6740 | auto *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6741 | if (ToRecord->isCompleteDefinition()) { |
| 6742 | // Do nothing. |
| 6743 | } else if (FromRecord->isCompleteDefinition()) { |
| 6744 | ASTNodeImporter(*this).ImportDefinition(FromRecord, ToRecord, |
| 6745 | ASTNodeImporter::IDK_Basic); |
| 6746 | } else { |
| 6747 | CompleteDecl(ToRecord); |
| 6748 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6749 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 6750 | auto *FromEnum = cast<EnumDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6751 | if (ToEnum->isCompleteDefinition()) { |
| 6752 | // Do nothing. |
| 6753 | } else if (FromEnum->isCompleteDefinition()) { |
| 6754 | ASTNodeImporter(*this).ImportDefinition(FromEnum, ToEnum, |
| 6755 | ASTNodeImporter::IDK_Basic); |
| 6756 | } else { |
| 6757 | CompleteDecl(ToEnum); |
| 6758 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6759 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 6760 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6761 | if (ToClass->getDefinition()) { |
| 6762 | // Do nothing. |
| 6763 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
| 6764 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToClass, |
| 6765 | ASTNodeImporter::IDK_Basic); |
| 6766 | } else { |
| 6767 | CompleteDecl(ToClass); |
| 6768 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6769 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 6770 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6771 | if (ToProto->getDefinition()) { |
| 6772 | // Do nothing. |
| 6773 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
| 6774 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToProto, |
| 6775 | ASTNodeImporter::IDK_Basic); |
| 6776 | } else { |
| 6777 | CompleteDecl(ToProto); |
| 6778 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 6779 | } |
| 6780 | |
| 6781 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6782 | } |
| 6783 | |
| 6784 | Expr *ASTImporter::Import(Expr *FromE) { |
| 6785 | if (!FromE) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6786 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6787 | |
| 6788 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); |
| 6789 | } |
| 6790 | |
| 6791 | Stmt *ASTImporter::Import(Stmt *FromS) { |
| 6792 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6793 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6794 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6795 | // Check whether we've already imported this declaration. |
| 6796 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 6797 | if (Pos != ImportedStmts.end()) |
| 6798 | return Pos->second; |
| 6799 | |
| 6800 | // Import the type |
| 6801 | ASTNodeImporter Importer(*this); |
| 6802 | Stmt *ToS = Importer.Visit(FromS); |
| 6803 | if (!ToS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6804 | return nullptr; |
| 6805 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6806 | // Record the imported declaration. |
| 6807 | ImportedStmts[FromS] = ToS; |
| 6808 | return ToS; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6809 | } |
| 6810 | |
| 6811 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| 6812 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6813 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6814 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6815 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); |
| 6816 | |
| 6817 | switch (FromNNS->getKind()) { |
| 6818 | case NestedNameSpecifier::Identifier: |
| 6819 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { |
| 6820 | return NestedNameSpecifier::Create(ToContext, prefix, II); |
| 6821 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6822 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6823 | |
| 6824 | case NestedNameSpecifier::Namespace: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6825 | if (auto *NS = |
| 6826 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6827 | return NestedNameSpecifier::Create(ToContext, prefix, NS); |
| 6828 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6829 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6830 | |
| 6831 | case NestedNameSpecifier::NamespaceAlias: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6832 | if (auto *NSAD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6833 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6834 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); |
| 6835 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6836 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6837 | |
| 6838 | case NestedNameSpecifier::Global: |
| 6839 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 6840 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 6841 | case NestedNameSpecifier::Super: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6842 | if (auto *RD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6843 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 6844 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); |
| 6845 | } |
| 6846 | return nullptr; |
| 6847 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6848 | case NestedNameSpecifier::TypeSpec: |
| 6849 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 6850 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); |
| 6851 | if (!T.isNull()) { |
| 6852 | bool bTemplate = FromNNS->getKind() == |
| 6853 | NestedNameSpecifier::TypeSpecWithTemplate; |
| 6854 | return NestedNameSpecifier::Create(ToContext, prefix, |
| 6855 | bTemplate, T.getTypePtr()); |
| 6856 | } |
| 6857 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6858 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6859 | } |
| 6860 | |
| 6861 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6862 | } |
| 6863 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 6864 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6865 | // Copied from NestedNameSpecifier mostly. |
| 6866 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 6867 | NestedNameSpecifierLoc NNS = FromNNS; |
| 6868 | |
| 6869 | // Push each of the nested-name-specifiers's onto a stack for |
| 6870 | // serialization in reverse order. |
| 6871 | while (NNS) { |
| 6872 | NestedNames.push_back(NNS); |
| 6873 | NNS = NNS.getPrefix(); |
| 6874 | } |
| 6875 | |
| 6876 | NestedNameSpecifierLocBuilder Builder; |
| 6877 | |
| 6878 | while (!NestedNames.empty()) { |
| 6879 | NNS = NestedNames.pop_back_val(); |
| 6880 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); |
| 6881 | if (!Spec) |
| 6882 | return NestedNameSpecifierLoc(); |
| 6883 | |
| 6884 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| 6885 | switch (Kind) { |
| 6886 | case NestedNameSpecifier::Identifier: |
| 6887 | Builder.Extend(getToContext(), |
| 6888 | Spec->getAsIdentifier(), |
| 6889 | Import(NNS.getLocalBeginLoc()), |
| 6890 | Import(NNS.getLocalEndLoc())); |
| 6891 | break; |
| 6892 | |
| 6893 | case NestedNameSpecifier::Namespace: |
| 6894 | Builder.Extend(getToContext(), |
| 6895 | Spec->getAsNamespace(), |
| 6896 | Import(NNS.getLocalBeginLoc()), |
| 6897 | Import(NNS.getLocalEndLoc())); |
| 6898 | break; |
| 6899 | |
| 6900 | case NestedNameSpecifier::NamespaceAlias: |
| 6901 | Builder.Extend(getToContext(), |
| 6902 | Spec->getAsNamespaceAlias(), |
| 6903 | Import(NNS.getLocalBeginLoc()), |
| 6904 | Import(NNS.getLocalEndLoc())); |
| 6905 | break; |
| 6906 | |
| 6907 | case NestedNameSpecifier::TypeSpec: |
| 6908 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 6909 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| 6910 | QualType(Spec->getAsType(), 0)); |
| 6911 | Builder.Extend(getToContext(), |
| 6912 | Import(NNS.getLocalBeginLoc()), |
| 6913 | TSI->getTypeLoc(), |
| 6914 | Import(NNS.getLocalEndLoc())); |
| 6915 | break; |
| 6916 | } |
| 6917 | |
| 6918 | case NestedNameSpecifier::Global: |
| 6919 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); |
| 6920 | break; |
| 6921 | |
| 6922 | case NestedNameSpecifier::Super: { |
| 6923 | SourceRange ToRange = Import(NNS.getSourceRange()); |
| 6924 | Builder.MakeSuper(getToContext(), |
| 6925 | Spec->getAsRecordDecl(), |
| 6926 | ToRange.getBegin(), |
| 6927 | ToRange.getEnd()); |
| 6928 | } |
| 6929 | } |
| 6930 | } |
| 6931 | |
| 6932 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 6933 | } |
| 6934 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6935 | TemplateName ASTImporter::Import(TemplateName From) { |
| 6936 | switch (From.getKind()) { |
| 6937 | case TemplateName::Template: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6938 | if (auto *ToTemplate = |
| 6939 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6940 | return TemplateName(ToTemplate); |
| 6941 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6942 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6943 | |
| 6944 | case TemplateName::OverloadedTemplate: { |
| 6945 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 6946 | UnresolvedSet<2> ToTemplates; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6947 | for (auto *I : *FromStorage) { |
| 6948 | if (auto *To = cast_or_null<NamedDecl>(Import(I))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6949 | ToTemplates.addDecl(To); |
| 6950 | else |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6951 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6952 | } |
| 6953 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
| 6954 | ToTemplates.end()); |
| 6955 | } |
| 6956 | |
| 6957 | case TemplateName::QualifiedTemplate: { |
| 6958 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| 6959 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); |
| 6960 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6961 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6962 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6963 | if (auto *ToTemplate = |
| 6964 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6965 | return ToContext.getQualifiedTemplateName(Qualifier, |
| 6966 | QTN->hasTemplateKeyword(), |
| 6967 | ToTemplate); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6968 | |
| 6969 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6970 | } |
| 6971 | |
| 6972 | case TemplateName::DependentTemplate: { |
| 6973 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| 6974 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); |
| 6975 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6976 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6977 | |
| 6978 | if (DTN->isIdentifier()) { |
| 6979 | return ToContext.getDependentTemplateName(Qualifier, |
| 6980 | Import(DTN->getIdentifier())); |
| 6981 | } |
| 6982 | |
| 6983 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); |
| 6984 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6985 | |
| 6986 | case TemplateName::SubstTemplateTemplateParm: { |
| 6987 | SubstTemplateTemplateParmStorage *subst |
| 6988 | = From.getAsSubstTemplateTemplateParm(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6989 | auto *param = |
| 6990 | cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6991 | if (!param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6992 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6993 | |
| 6994 | TemplateName replacement = Import(subst->getReplacement()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6995 | if (replacement.isNull()) |
| 6996 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6997 | |
| 6998 | return ToContext.getSubstTemplateTemplateParm(param, replacement); |
| 6999 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7000 | |
| 7001 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 7002 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 7003 | = From.getAsSubstTemplateTemplateParmPack(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7004 | auto *Param = |
| 7005 | cast_or_null<TemplateTemplateParmDecl>( |
| 7006 | Import(SubstPack->getParameterPack())); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7007 | if (!Param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7008 | return {}; |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7009 | |
| 7010 | ASTNodeImporter Importer(*this); |
| 7011 | TemplateArgument ArgPack |
| 7012 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 7013 | if (ArgPack.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7014 | return {}; |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 7015 | |
| 7016 | return ToContext.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 7017 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7018 | } |
| 7019 | |
| 7020 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7021 | } |
| 7022 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7023 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { |
| 7024 | if (FromLoc.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7025 | return {}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7026 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7027 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 7028 | |
Sean Callanan | 24c5fe6 | 2016-11-07 20:42:25 +0000 | [diff] [blame] | 7029 | // For now, map everything down to its file location, so that we |
Chandler Carruth | 2536641 | 2011-07-15 00:04:35 +0000 | [diff] [blame] | 7030 | // don't have to import macro expansions. |
| 7031 | // FIXME: Import macro expansions! |
Sean Callanan | 24c5fe6 | 2016-11-07 20:42:25 +0000 | [diff] [blame] | 7032 | FromLoc = FromSM.getFileLoc(FromLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7033 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
| 7034 | SourceManager &ToSM = ToContext.getSourceManager(); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 7035 | FileID ToFileID = Import(Decomposed.first); |
| 7036 | if (ToFileID.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7037 | return {}; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 7038 | SourceLocation ret = ToSM.getLocForStartOfFile(ToFileID) |
| 7039 | .getLocWithOffset(Decomposed.second); |
| 7040 | return ret; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 7041 | } |
| 7042 | |
| 7043 | SourceRange ASTImporter::Import(SourceRange FromRange) { |
| 7044 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); |
| 7045 | } |
| 7046 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7047 | FileID ASTImporter::Import(FileID FromID) { |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 7048 | llvm::DenseMap<FileID, FileID>::iterator Pos |
| 7049 | = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7050 | if (Pos != ImportedFileIDs.end()) |
| 7051 | return Pos->second; |
| 7052 | |
| 7053 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 7054 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 7055 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Chandler Carruth | 2536641 | 2011-07-15 00:04:35 +0000 | [diff] [blame] | 7056 | assert(FromSLoc.isFile() && "Cannot handle macro expansions yet"); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7057 | |
| 7058 | // Include location of this file. |
| 7059 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| 7060 | |
| 7061 | // Map the FileID for to the "to" source manager. |
| 7062 | FileID ToID; |
| 7063 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
Sean Callanan | 25d34af | 2015-04-30 00:44:21 +0000 | [diff] [blame] | 7064 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7065 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 7066 | // disk again |
| 7067 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 7068 | // than mmap the files several times. |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 7069 | const FileEntry *Entry = ToFileManager.getFile(Cache->OrigEntry->getName()); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 7070 | if (!Entry) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7071 | return {}; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7072 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, |
| 7073 | FromSLoc.getFile().getFileCharacteristic()); |
| 7074 | } else { |
| 7075 | // FIXME: We want to re-use the existing MemoryBuffer! |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7076 | const llvm::MemoryBuffer * |
| 7077 | FromBuf = Cache->getBuffer(FromContext.getDiagnostics(), FromSM); |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 7078 | std::unique_ptr<llvm::MemoryBuffer> ToBuf |
Chris Lattner | 58c7934 | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 7079 | = llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7080 | FromBuf->getBufferIdentifier()); |
David Blaikie | 50a5f97 | 2014-08-29 07:59:55 +0000 | [diff] [blame] | 7081 | ToID = ToSM.createFileID(std::move(ToBuf), |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 7082 | FromSLoc.getFile().getFileCharacteristic()); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7083 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7084 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 7085 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 7086 | return ToID; |
| 7087 | } |
| 7088 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7089 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
| 7090 | Expr *ToExpr = Import(From->getInit()); |
| 7091 | if (!ToExpr && From->getInit()) |
| 7092 | return nullptr; |
| 7093 | |
| 7094 | if (From->isBaseInitializer()) { |
| 7095 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 7096 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 7097 | return nullptr; |
| 7098 | |
| 7099 | return new (ToContext) CXXCtorInitializer( |
| 7100 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), |
| 7101 | ToExpr, Import(From->getRParenLoc()), |
| 7102 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) |
| 7103 | : SourceLocation()); |
| 7104 | } else if (From->isMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7105 | auto *ToField = cast_or_null<FieldDecl>(Import(From->getMember())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7106 | if (!ToField && From->getMember()) |
| 7107 | return nullptr; |
| 7108 | |
| 7109 | return new (ToContext) CXXCtorInitializer( |
| 7110 | ToContext, ToField, Import(From->getMemberLocation()), |
| 7111 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 7112 | } else if (From->isIndirectMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7113 | auto *ToIField = cast_or_null<IndirectFieldDecl>( |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7114 | Import(From->getIndirectMember())); |
| 7115 | if (!ToIField && From->getIndirectMember()) |
| 7116 | return nullptr; |
| 7117 | |
| 7118 | return new (ToContext) CXXCtorInitializer( |
| 7119 | ToContext, ToIField, Import(From->getMemberLocation()), |
| 7120 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 7121 | } else if (From->isDelegatingInitializer()) { |
| 7122 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 7123 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 7124 | return nullptr; |
| 7125 | |
| 7126 | return new (ToContext) |
| 7127 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), |
| 7128 | ToExpr, Import(From->getRParenLoc())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7129 | } else { |
| 7130 | return nullptr; |
| 7131 | } |
| 7132 | } |
| 7133 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7134 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| 7135 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 7136 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 7137 | return Pos->second; |
| 7138 | |
| 7139 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| 7140 | Import(BaseSpec->getSourceRange()), |
| 7141 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 7142 | BaseSpec->getAccessSpecifierAsWritten(), |
| 7143 | Import(BaseSpec->getTypeSourceInfo()), |
| 7144 | Import(BaseSpec->getEllipsisLoc())); |
| 7145 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 7146 | return Imported; |
| 7147 | } |
| 7148 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7149 | void ASTImporter::ImportDefinition(Decl *From) { |
| 7150 | Decl *To = Import(From); |
| 7151 | if (!To) |
| 7152 | return; |
| 7153 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7154 | if (auto *FromDC = cast<DeclContext>(From)) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7155 | ASTNodeImporter Importer(*this); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7156 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7157 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7158 | if (!ToRecord->getDefinition()) { |
| 7159 | Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7160 | ASTNodeImporter::IDK_Everything); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7161 | return; |
| 7162 | } |
| 7163 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7164 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7165 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7166 | if (!ToEnum->getDefinition()) { |
| 7167 | Importer.ImportDefinition(cast<EnumDecl>(FromDC), ToEnum, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7168 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7169 | return; |
| 7170 | } |
| 7171 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7172 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7173 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7174 | if (!ToIFace->getDefinition()) { |
| 7175 | Importer.ImportDefinition(cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7176 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7177 | return; |
| 7178 | } |
| 7179 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7180 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7181 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7182 | if (!ToProto->getDefinition()) { |
| 7183 | Importer.ImportDefinition(cast<ObjCProtocolDecl>(FromDC), ToProto, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7184 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7185 | return; |
| 7186 | } |
| 7187 | } |
| 7188 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7189 | Importer.ImportDeclContext(FromDC, true); |
| 7190 | } |
| 7191 | } |
| 7192 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7193 | DeclarationName ASTImporter::Import(DeclarationName FromName) { |
| 7194 | if (!FromName) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7195 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7196 | |
| 7197 | switch (FromName.getNameKind()) { |
| 7198 | case DeclarationName::Identifier: |
| 7199 | return Import(FromName.getAsIdentifierInfo()); |
| 7200 | |
| 7201 | case DeclarationName::ObjCZeroArgSelector: |
| 7202 | case DeclarationName::ObjCOneArgSelector: |
| 7203 | case DeclarationName::ObjCMultiArgSelector: |
| 7204 | return Import(FromName.getObjCSelector()); |
| 7205 | |
| 7206 | case DeclarationName::CXXConstructorName: { |
| 7207 | QualType T = Import(FromName.getCXXNameType()); |
| 7208 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7209 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7210 | |
| 7211 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 7212 | ToContext.getCanonicalType(T)); |
| 7213 | } |
| 7214 | |
| 7215 | case DeclarationName::CXXDestructorName: { |
| 7216 | QualType T = Import(FromName.getCXXNameType()); |
| 7217 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7218 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7219 | |
| 7220 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 7221 | ToContext.getCanonicalType(T)); |
| 7222 | } |
| 7223 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7224 | case DeclarationName::CXXDeductionGuideName: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7225 | auto *Template = cast_or_null<TemplateDecl>( |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7226 | Import(FromName.getCXXDeductionGuideTemplate())); |
| 7227 | if (!Template) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7228 | return {}; |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7229 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); |
| 7230 | } |
| 7231 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7232 | case DeclarationName::CXXConversionFunctionName: { |
| 7233 | QualType T = Import(FromName.getCXXNameType()); |
| 7234 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7235 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7236 | |
| 7237 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 7238 | ToContext.getCanonicalType(T)); |
| 7239 | } |
| 7240 | |
| 7241 | case DeclarationName::CXXOperatorName: |
| 7242 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 7243 | FromName.getCXXOverloadedOperator()); |
| 7244 | |
| 7245 | case DeclarationName::CXXLiteralOperatorName: |
| 7246 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| 7247 | Import(FromName.getCXXLiteralIdentifier())); |
| 7248 | |
| 7249 | case DeclarationName::CXXUsingDirective: |
| 7250 | // FIXME: STATICS! |
| 7251 | return DeclarationName::getUsingDirectiveName(); |
| 7252 | } |
| 7253 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 7254 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7255 | } |
| 7256 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7257 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7258 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7259 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7260 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 7261 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 7262 | |
| 7263 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 7264 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 7265 | |
| 7266 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7267 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7268 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7269 | Selector ASTImporter::Import(Selector FromSel) { |
| 7270 | if (FromSel.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7271 | return {}; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7272 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 7273 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7274 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 7275 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 7276 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 7277 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 7278 | } |
| 7279 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7280 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 7281 | DeclContext *DC, |
| 7282 | unsigned IDNS, |
| 7283 | NamedDecl **Decls, |
| 7284 | unsigned NumDecls) { |
| 7285 | return Name; |
| 7286 | } |
| 7287 | |
| 7288 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 7289 | if (LastDiagFromFrom) |
| 7290 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 7291 | FromContext.getDiagnostics()); |
| 7292 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7293 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7294 | } |
| 7295 | |
| 7296 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 7297 | if (!LastDiagFromFrom) |
| 7298 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 7299 | ToContext.getDiagnostics()); |
| 7300 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7301 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7302 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7303 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7304 | void ASTImporter::CompleteDecl (Decl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7305 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7306 | if (!ID->getDefinition()) |
| 7307 | ID->startDefinition(); |
| 7308 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7309 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7310 | if (!PD->getDefinition()) |
| 7311 | PD->startDefinition(); |
| 7312 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7313 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7314 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 7315 | TD->startDefinition(); |
| 7316 | TD->setCompleteDefinition(true); |
| 7317 | } |
| 7318 | } |
| 7319 | else { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7320 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7321 | } |
| 7322 | } |
| 7323 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7324 | Decl *ASTImporter::Imported(Decl *From, Decl *To) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7325 | if (From->hasAttrs()) { |
Aleksei Sidorin | 8f266db | 2018-05-08 12:45:21 +0000 | [diff] [blame] | 7326 | for (const auto *FromAttr : From->getAttrs()) |
| 7327 | To->addAttr(Import(FromAttr)); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7328 | } |
| 7329 | if (From->isUsed()) { |
| 7330 | To->setIsUsed(); |
| 7331 | } |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7332 | if (From->isImplicit()) { |
| 7333 | To->setImplicit(); |
| 7334 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7335 | ImportedDecls[From] = To; |
| 7336 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 7337 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7338 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 7339 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 7340 | bool Complain) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7341 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7342 | = ImportedTypes.find(From.getTypePtr()); |
| 7343 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) |
| 7344 | return true; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 7345 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 7346 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
| 7347 | false, Complain); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 7348 | return Ctx.IsStructurallyEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7349 | } |