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) {} |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 81 | |
| 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); |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 124 | // FIXME: DependentNameType |
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 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 149 | /// \brief What we should import from the definition. |
| 150 | enum ImportDefinitionKind { |
| 151 | /// \brief Import the default subset of the definition, which might be |
| 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 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 156 | /// \brief Import everything. |
| 157 | IDK_Everything, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 158 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 159 | /// \brief Import only the bare bones needed to establish a valid |
| 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); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 350 | Expr *VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *CE); |
| 351 | Expr *VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 352 | Expr *VisitExprWithCleanups(ExprWithCleanups *EWC); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 353 | Expr *VisitCXXThisExpr(CXXThisExpr *E); |
| 354 | Expr *VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 355 | Expr *VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 356 | Expr *VisitMemberExpr(MemberExpr *E); |
| 357 | Expr *VisitCallExpr(CallExpr *E); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 358 | Expr *VisitLambdaExpr(LambdaExpr *LE); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 359 | Expr *VisitInitListExpr(InitListExpr *E); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 360 | Expr *VisitArrayInitLoopExpr(ArrayInitLoopExpr *E); |
| 361 | Expr *VisitArrayInitIndexExpr(ArrayInitIndexExpr *E); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 362 | Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E); |
| 363 | Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 364 | Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E); |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 365 | Expr *VisitTypeTraitExpr(TypeTraitExpr *E); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 366 | Expr *VisitCXXTypeidExpr(CXXTypeidExpr *E); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 367 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 368 | template<typename IIter, typename OIter> |
| 369 | void ImportArray(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 370 | using ItemT = typename std::remove_reference<decltype(*Obegin)>::type; |
| 371 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 372 | ASTImporter &ImporterRef = Importer; |
| 373 | std::transform(Ibegin, Iend, Obegin, |
| 374 | [&ImporterRef](ItemT From) -> ItemT { |
| 375 | return ImporterRef.Import(From); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 376 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | template<typename IIter, typename OIter> |
| 380 | bool ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 381 | using ItemT = typename std::remove_reference<decltype(**Obegin)>::type; |
| 382 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 383 | ASTImporter &ImporterRef = Importer; |
| 384 | bool Failed = false; |
| 385 | std::transform(Ibegin, Iend, Obegin, |
| 386 | [&ImporterRef, &Failed](ItemT *From) -> ItemT * { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 387 | auto *To = cast_or_null<ItemT>(ImporterRef.Import(From)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 388 | if (!To && From) |
| 389 | Failed = true; |
| 390 | return To; |
| 391 | }); |
| 392 | return Failed; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 393 | } |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 394 | |
| 395 | template<typename InContainerTy, typename OutContainerTy> |
| 396 | bool ImportContainerChecked(const InContainerTy &InContainer, |
| 397 | OutContainerTy &OutContainer) { |
| 398 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), |
| 399 | OutContainer.begin()); |
| 400 | } |
| 401 | |
| 402 | template<typename InContainerTy, typename OIter> |
| 403 | bool ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) { |
| 404 | return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin); |
| 405 | } |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 406 | |
| 407 | // Importing overrides. |
| 408 | void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 409 | }; |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 410 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 411 | template <typename InContainerTy> |
| 412 | bool ASTNodeImporter::ImportTemplateArgumentListInfo( |
| 413 | SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc, |
| 414 | const InContainerTy &Container, TemplateArgumentListInfo &Result) { |
| 415 | TemplateArgumentListInfo ToTAInfo(Importer.Import(FromLAngleLoc), |
| 416 | Importer.Import(FromRAngleLoc)); |
| 417 | if (ImportTemplateArgumentListInfo(Container, ToTAInfo)) |
| 418 | return true; |
| 419 | Result = ToTAInfo; |
| 420 | return false; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 421 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 422 | |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 423 | template <> |
| 424 | bool ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>( |
| 425 | const TemplateArgumentListInfo &From, TemplateArgumentListInfo &Result) { |
| 426 | return ImportTemplateArgumentListInfo( |
| 427 | From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result); |
| 428 | } |
| 429 | |
| 430 | template <> |
| 431 | bool ASTNodeImporter::ImportTemplateArgumentListInfo< |
| 432 | ASTTemplateArgumentListInfo>(const ASTTemplateArgumentListInfo &From, |
| 433 | TemplateArgumentListInfo &Result) { |
| 434 | return ImportTemplateArgumentListInfo(From.LAngleLoc, From.RAngleLoc, |
| 435 | From.arguments(), Result); |
| 436 | } |
| 437 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 438 | } // namespace clang |
Aleksei Sidorin | 782bfcf | 2018-02-14 11:39:33 +0000 | [diff] [blame] | 439 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 440 | //---------------------------------------------------------------------------- |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 441 | // Import Types |
| 442 | //---------------------------------------------------------------------------- |
| 443 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 444 | using namespace clang; |
| 445 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 446 | QualType ASTNodeImporter::VisitType(const Type *T) { |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 447 | Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node) |
| 448 | << T->getTypeClassName(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 449 | return {}; |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 450 | } |
| 451 | |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 452 | QualType ASTNodeImporter::VisitAtomicType(const AtomicType *T){ |
| 453 | QualType UnderlyingType = Importer.Import(T->getValueType()); |
| 454 | if(UnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 455 | return {}; |
Gabor Horvath | 0866c2f | 2016-11-23 15:24:23 +0000 | [diff] [blame] | 456 | |
| 457 | return Importer.getToContext().getAtomicType(UnderlyingType); |
| 458 | } |
| 459 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 460 | QualType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 461 | switch (T->getKind()) { |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 462 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 463 | case BuiltinType::Id: \ |
| 464 | return Importer.getToContext().SingletonId; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 465 | #include "clang/Basic/OpenCLImageTypes.def" |
John McCall | e314e27 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 466 | #define SHARED_SINGLETON_TYPE(Expansion) |
| 467 | #define BUILTIN_TYPE(Id, SingletonId) \ |
| 468 | case BuiltinType::Id: return Importer.getToContext().SingletonId; |
| 469 | #include "clang/AST/BuiltinTypes.def" |
| 470 | |
| 471 | // FIXME: for Char16, Char32, and NullPtr, make sure that the "to" |
| 472 | // context supports C++. |
| 473 | |
| 474 | // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to" |
| 475 | // context supports ObjC. |
| 476 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 477 | case BuiltinType::Char_U: |
| 478 | // The context we're importing from has an unsigned 'char'. If we're |
| 479 | // importing into a context with a signed 'char', translate to |
| 480 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 481 | if (Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 482 | return Importer.getToContext().UnsignedCharTy; |
| 483 | |
| 484 | return Importer.getToContext().CharTy; |
| 485 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 486 | case BuiltinType::Char_S: |
| 487 | // The context we're importing from has an unsigned 'char'. If we're |
| 488 | // importing into a context with a signed 'char', translate to |
| 489 | // 'unsigned char' instead. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 490 | if (!Importer.getToContext().getLangOpts().CharIsSigned) |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 491 | return Importer.getToContext().SignedCharTy; |
| 492 | |
| 493 | return Importer.getToContext().CharTy; |
| 494 | |
Chris Lattner | ad3467e | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 495 | case BuiltinType::WChar_S: |
| 496 | case BuiltinType::WChar_U: |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 497 | // FIXME: If not in C++, shall we translate to the C equivalent of |
| 498 | // wchar_t? |
| 499 | return Importer.getToContext().WCharTy; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 500 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 501 | |
| 502 | llvm_unreachable("Invalid BuiltinType Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 503 | } |
| 504 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 505 | QualType ASTNodeImporter::VisitDecayedType(const DecayedType *T) { |
| 506 | QualType OrigT = Importer.Import(T->getOriginalType()); |
| 507 | if (OrigT.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 508 | return {}; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 509 | |
| 510 | return Importer.getToContext().getDecayedType(OrigT); |
| 511 | } |
| 512 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 513 | QualType ASTNodeImporter::VisitComplexType(const ComplexType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 514 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 515 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 516 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 517 | |
| 518 | return Importer.getToContext().getComplexType(ToElementType); |
| 519 | } |
| 520 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 521 | QualType ASTNodeImporter::VisitPointerType(const PointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 522 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 523 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 524 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 525 | |
| 526 | return Importer.getToContext().getPointerType(ToPointeeType); |
| 527 | } |
| 528 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 529 | QualType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 530 | // FIXME: Check for blocks support in "to" context. |
| 531 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 532 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 533 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 534 | |
| 535 | return Importer.getToContext().getBlockPointerType(ToPointeeType); |
| 536 | } |
| 537 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 538 | QualType |
| 539 | ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 540 | // FIXME: Check for C++ support in "to" context. |
| 541 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 542 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 543 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 544 | |
| 545 | return Importer.getToContext().getLValueReferenceType(ToPointeeType); |
| 546 | } |
| 547 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 548 | QualType |
| 549 | ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 550 | // FIXME: Check for C++0x support in "to" context. |
| 551 | QualType ToPointeeType = Importer.Import(T->getPointeeTypeAsWritten()); |
| 552 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 553 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 554 | |
| 555 | return Importer.getToContext().getRValueReferenceType(ToPointeeType); |
| 556 | } |
| 557 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 558 | QualType ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 559 | // FIXME: Check for C++ support in "to" context. |
| 560 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 561 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 562 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 563 | |
| 564 | QualType ClassType = Importer.Import(QualType(T->getClass(), 0)); |
| 565 | return Importer.getToContext().getMemberPointerType(ToPointeeType, |
| 566 | ClassType.getTypePtr()); |
| 567 | } |
| 568 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 569 | QualType ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 570 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 571 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 572 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 573 | |
| 574 | return Importer.getToContext().getConstantArrayType(ToElementType, |
| 575 | T->getSize(), |
| 576 | T->getSizeModifier(), |
| 577 | T->getIndexTypeCVRQualifiers()); |
| 578 | } |
| 579 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 580 | QualType |
| 581 | ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 582 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 583 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 584 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 585 | |
| 586 | return Importer.getToContext().getIncompleteArrayType(ToElementType, |
| 587 | T->getSizeModifier(), |
| 588 | T->getIndexTypeCVRQualifiers()); |
| 589 | } |
| 590 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 591 | QualType ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 592 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 593 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 594 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 595 | |
| 596 | Expr *Size = Importer.Import(T->getSizeExpr()); |
| 597 | if (!Size) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 598 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 599 | |
| 600 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); |
| 601 | return Importer.getToContext().getVariableArrayType(ToElementType, Size, |
| 602 | T->getSizeModifier(), |
| 603 | T->getIndexTypeCVRQualifiers(), |
| 604 | Brackets); |
| 605 | } |
| 606 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 607 | QualType ASTNodeImporter::VisitDependentSizedArrayType( |
| 608 | const DependentSizedArrayType *T) { |
| 609 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 610 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 611 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 612 | |
| 613 | // SizeExpr may be null if size is not specified directly. |
| 614 | // For example, 'int a[]'. |
| 615 | Expr *Size = Importer.Import(T->getSizeExpr()); |
| 616 | if (!Size && T->getSizeExpr()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 617 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 618 | |
| 619 | SourceRange Brackets = Importer.Import(T->getBracketsRange()); |
| 620 | return Importer.getToContext().getDependentSizedArrayType( |
| 621 | ToElementType, Size, T->getSizeModifier(), T->getIndexTypeCVRQualifiers(), |
| 622 | Brackets); |
| 623 | } |
| 624 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 625 | QualType ASTNodeImporter::VisitVectorType(const VectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 626 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 627 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 628 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 629 | |
| 630 | return Importer.getToContext().getVectorType(ToElementType, |
| 631 | T->getNumElements(), |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 632 | T->getVectorKind()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 633 | } |
| 634 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 635 | QualType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 636 | QualType ToElementType = Importer.Import(T->getElementType()); |
| 637 | if (ToElementType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 638 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 639 | |
| 640 | return Importer.getToContext().getExtVectorType(ToElementType, |
| 641 | T->getNumElements()); |
| 642 | } |
| 643 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 644 | QualType |
| 645 | ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 646 | // FIXME: What happens if we're importing a function without a prototype |
| 647 | // into C++? Should we make it variadic? |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 648 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 649 | if (ToResultType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 650 | return {}; |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 651 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 652 | return Importer.getToContext().getFunctionNoProtoType(ToResultType, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 653 | T->getExtInfo()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 656 | QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) { |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 657 | QualType ToResultType = Importer.Import(T->getReturnType()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 658 | if (ToResultType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 659 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 660 | |
| 661 | // Import argument types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 662 | SmallVector<QualType, 4> ArgTypes; |
Aaron Ballman | 40bd0aa | 2014-03-17 15:23:01 +0000 | [diff] [blame] | 663 | for (const auto &A : T->param_types()) { |
| 664 | QualType ArgType = Importer.Import(A); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 665 | if (ArgType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 666 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 667 | ArgTypes.push_back(ArgType); |
| 668 | } |
| 669 | |
| 670 | // Import exception types |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 671 | SmallVector<QualType, 4> ExceptionTypes; |
Aaron Ballman | b088fbe | 2014-03-17 15:38:09 +0000 | [diff] [blame] | 672 | for (const auto &E : T->exceptions()) { |
| 673 | QualType ExceptionType = Importer.Import(E); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 674 | if (ExceptionType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 675 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 676 | ExceptionTypes.push_back(ExceptionType); |
| 677 | } |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 678 | |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 679 | FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo(); |
| 680 | FunctionProtoType::ExtProtoInfo ToEPI; |
| 681 | |
| 682 | ToEPI.ExtInfo = FromEPI.ExtInfo; |
| 683 | ToEPI.Variadic = FromEPI.Variadic; |
| 684 | ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn; |
| 685 | ToEPI.TypeQuals = FromEPI.TypeQuals; |
| 686 | ToEPI.RefQualifier = FromEPI.RefQualifier; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 687 | ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type; |
| 688 | ToEPI.ExceptionSpec.Exceptions = ExceptionTypes; |
| 689 | ToEPI.ExceptionSpec.NoexceptExpr = |
| 690 | Importer.Import(FromEPI.ExceptionSpec.NoexceptExpr); |
| 691 | ToEPI.ExceptionSpec.SourceDecl = cast_or_null<FunctionDecl>( |
| 692 | Importer.Import(FromEPI.ExceptionSpec.SourceDecl)); |
| 693 | ToEPI.ExceptionSpec.SourceTemplate = cast_or_null<FunctionDecl>( |
| 694 | Importer.Import(FromEPI.ExceptionSpec.SourceTemplate)); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 695 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 696 | return Importer.getToContext().getFunctionType(ToResultType, ArgTypes, ToEPI); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 697 | } |
| 698 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 699 | QualType ASTNodeImporter::VisitUnresolvedUsingType( |
| 700 | const UnresolvedUsingType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 701 | const auto *ToD = |
| 702 | cast_or_null<UnresolvedUsingTypenameDecl>(Importer.Import(T->getDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 703 | if (!ToD) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 704 | return {}; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 705 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 706 | auto *ToPrevD = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 707 | cast_or_null<UnresolvedUsingTypenameDecl>( |
| 708 | Importer.Import(T->getDecl()->getPreviousDecl())); |
| 709 | if (!ToPrevD && T->getDecl()->getPreviousDecl()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 710 | return {}; |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 711 | |
| 712 | return Importer.getToContext().getTypeDeclType(ToD, ToPrevD); |
| 713 | } |
| 714 | |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 715 | QualType ASTNodeImporter::VisitParenType(const ParenType *T) { |
| 716 | QualType ToInnerType = Importer.Import(T->getInnerType()); |
| 717 | if (ToInnerType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 718 | return {}; |
Sean Callanan | da6df8a | 2011-08-11 16:56:07 +0000 | [diff] [blame] | 719 | |
| 720 | return Importer.getToContext().getParenType(ToInnerType); |
| 721 | } |
| 722 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 723 | QualType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 724 | auto *ToDecl = |
| 725 | dyn_cast_or_null<TypedefNameDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 726 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 727 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 728 | |
| 729 | return Importer.getToContext().getTypeDeclType(ToDecl); |
| 730 | } |
| 731 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 732 | QualType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 733 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 734 | if (!ToExpr) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 735 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 736 | |
| 737 | return Importer.getToContext().getTypeOfExprType(ToExpr); |
| 738 | } |
| 739 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 740 | QualType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 741 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 742 | if (ToUnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 743 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 744 | |
| 745 | return Importer.getToContext().getTypeOfType(ToUnderlyingType); |
| 746 | } |
| 747 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 748 | QualType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) { |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 749 | // FIXME: Make sure that the "to" context supports C++0x! |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 750 | Expr *ToExpr = Importer.Import(T->getUnderlyingExpr()); |
| 751 | if (!ToExpr) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 752 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 753 | |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 754 | QualType UnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 755 | if (UnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 756 | return {}; |
Douglas Gregor | 81495f3 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 757 | |
| 758 | return Importer.getToContext().getDecltypeType(ToExpr, UnderlyingType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 759 | } |
| 760 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 761 | QualType ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) { |
| 762 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 763 | QualType ToUnderlyingType = Importer.Import(T->getUnderlyingType()); |
| 764 | if (ToBaseType.isNull() || ToUnderlyingType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 765 | return {}; |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 766 | |
| 767 | return Importer.getToContext().getUnaryTransformType(ToBaseType, |
| 768 | ToUnderlyingType, |
| 769 | T->getUTTKind()); |
| 770 | } |
| 771 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 772 | QualType ASTNodeImporter::VisitAutoType(const AutoType *T) { |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 773 | // FIXME: Make sure that the "to" context supports C++11! |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 774 | QualType FromDeduced = T->getDeducedType(); |
| 775 | QualType ToDeduced; |
| 776 | if (!FromDeduced.isNull()) { |
| 777 | ToDeduced = Importer.Import(FromDeduced); |
| 778 | if (ToDeduced.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 779 | return {}; |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 780 | } |
| 781 | |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 782 | return Importer.getToContext().getAutoType(ToDeduced, T->getKeyword(), |
Faisal Vali | 2b391ab | 2013-09-26 19:54:12 +0000 | [diff] [blame] | 783 | /*IsDependent*/false); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 784 | } |
| 785 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 786 | QualType ASTNodeImporter::VisitInjectedClassNameType( |
| 787 | const InjectedClassNameType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 788 | auto *D = cast_or_null<CXXRecordDecl>(Importer.Import(T->getDecl())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 789 | if (!D) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 790 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 791 | |
| 792 | QualType InjType = Importer.Import(T->getInjectedSpecializationType()); |
| 793 | if (InjType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 794 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 795 | |
| 796 | // FIXME: ASTContext::getInjectedClassNameType is not suitable for AST reading |
| 797 | // See comments in InjectedClassNameType definition for details |
| 798 | // return Importer.getToContext().getInjectedClassNameType(D, InjType); |
| 799 | enum { |
| 800 | TypeAlignmentInBits = 4, |
| 801 | TypeAlignment = 1 << TypeAlignmentInBits |
| 802 | }; |
| 803 | |
| 804 | return QualType(new (Importer.getToContext(), TypeAlignment) |
| 805 | InjectedClassNameType(D, InjType), 0); |
| 806 | } |
| 807 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 808 | QualType ASTNodeImporter::VisitRecordType(const RecordType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 809 | auto *ToDecl = dyn_cast_or_null<RecordDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 810 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 811 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 812 | |
| 813 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 814 | } |
| 815 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 816 | QualType ASTNodeImporter::VisitEnumType(const EnumType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 817 | auto *ToDecl = dyn_cast_or_null<EnumDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 818 | if (!ToDecl) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 819 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 820 | |
| 821 | return Importer.getToContext().getTagDeclType(ToDecl); |
| 822 | } |
| 823 | |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 824 | QualType ASTNodeImporter::VisitAttributedType(const AttributedType *T) { |
| 825 | QualType FromModifiedType = T->getModifiedType(); |
| 826 | QualType FromEquivalentType = T->getEquivalentType(); |
| 827 | QualType ToModifiedType; |
| 828 | QualType ToEquivalentType; |
| 829 | |
| 830 | if (!FromModifiedType.isNull()) { |
| 831 | ToModifiedType = Importer.Import(FromModifiedType); |
| 832 | if (ToModifiedType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 833 | return {}; |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 834 | } |
| 835 | if (!FromEquivalentType.isNull()) { |
| 836 | ToEquivalentType = Importer.Import(FromEquivalentType); |
| 837 | if (ToEquivalentType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 838 | return {}; |
Sean Callanan | 72fe085 | 2015-04-02 23:50:08 +0000 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | return Importer.getToContext().getAttributedType(T->getAttrKind(), |
| 842 | ToModifiedType, ToEquivalentType); |
| 843 | } |
| 844 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 845 | QualType ASTNodeImporter::VisitTemplateTypeParmType( |
| 846 | const TemplateTypeParmType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 847 | auto *ParmDecl = |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 848 | cast_or_null<TemplateTypeParmDecl>(Importer.Import(T->getDecl())); |
| 849 | if (!ParmDecl && T->getDecl()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 850 | return {}; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 851 | |
| 852 | return Importer.getToContext().getTemplateTypeParmType( |
| 853 | T->getDepth(), T->getIndex(), T->isParameterPack(), ParmDecl); |
| 854 | } |
| 855 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 856 | QualType ASTNodeImporter::VisitSubstTemplateTypeParmType( |
| 857 | const SubstTemplateTypeParmType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 858 | const auto *Replaced = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 859 | cast_or_null<TemplateTypeParmType>(Importer.Import( |
| 860 | QualType(T->getReplacedParameter(), 0)).getTypePtr()); |
| 861 | if (!Replaced) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 862 | return {}; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 863 | |
| 864 | QualType Replacement = Importer.Import(T->getReplacementType()); |
| 865 | if (Replacement.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 866 | return {}; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 867 | Replacement = Replacement.getCanonicalType(); |
| 868 | |
| 869 | return Importer.getToContext().getSubstTemplateTypeParmType( |
| 870 | Replaced, Replacement); |
| 871 | } |
| 872 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 873 | QualType ASTNodeImporter::VisitTemplateSpecializationType( |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 874 | const TemplateSpecializationType *T) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 875 | TemplateName ToTemplate = Importer.Import(T->getTemplateName()); |
| 876 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 877 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 878 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 879 | SmallVector<TemplateArgument, 2> ToTemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 880 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToTemplateArgs)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 881 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 882 | |
| 883 | QualType ToCanonType; |
| 884 | if (!QualType(T, 0).isCanonical()) { |
| 885 | QualType FromCanonType |
| 886 | = Importer.getFromContext().getCanonicalType(QualType(T, 0)); |
| 887 | ToCanonType =Importer.Import(FromCanonType); |
| 888 | if (ToCanonType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 889 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 890 | } |
| 891 | return Importer.getToContext().getTemplateSpecializationType(ToTemplate, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 892 | ToTemplateArgs, |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 893 | ToCanonType); |
| 894 | } |
| 895 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 896 | QualType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 897 | NestedNameSpecifier *ToQualifier = nullptr; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 898 | // Note: the qualifier in an ElaboratedType is optional. |
| 899 | if (T->getQualifier()) { |
| 900 | ToQualifier = Importer.Import(T->getQualifier()); |
| 901 | if (!ToQualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 902 | return {}; |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 903 | } |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 904 | |
| 905 | QualType ToNamedType = Importer.Import(T->getNamedType()); |
| 906 | if (ToNamedType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 907 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 908 | |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 909 | return Importer.getToContext().getElaboratedType(T->getKeyword(), |
| 910 | ToQualifier, ToNamedType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 911 | } |
| 912 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 913 | QualType ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) { |
| 914 | QualType Pattern = Importer.Import(T->getPattern()); |
| 915 | if (Pattern.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 916 | return {}; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 917 | |
| 918 | return Importer.getToContext().getPackExpansionType(Pattern, |
| 919 | T->getNumExpansions()); |
| 920 | } |
| 921 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 922 | QualType ASTNodeImporter::VisitDependentTemplateSpecializationType( |
| 923 | const DependentTemplateSpecializationType *T) { |
| 924 | NestedNameSpecifier *Qualifier = Importer.Import(T->getQualifier()); |
| 925 | if (!Qualifier && T->getQualifier()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 926 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 927 | |
| 928 | IdentifierInfo *Name = Importer.Import(T->getIdentifier()); |
| 929 | if (!Name && T->getIdentifier()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 930 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 931 | |
| 932 | SmallVector<TemplateArgument, 2> ToPack; |
| 933 | ToPack.reserve(T->getNumArgs()); |
| 934 | if (ImportTemplateArguments(T->getArgs(), T->getNumArgs(), ToPack)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 935 | return {}; |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 936 | |
| 937 | return Importer.getToContext().getDependentTemplateSpecializationType( |
| 938 | T->getKeyword(), Qualifier, Name, ToPack); |
| 939 | } |
| 940 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 941 | QualType ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 942 | auto *Class = |
| 943 | dyn_cast_or_null<ObjCInterfaceDecl>(Importer.Import(T->getDecl())); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 944 | if (!Class) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 945 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 946 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 947 | return Importer.getToContext().getObjCInterfaceType(Class); |
| 948 | } |
| 949 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 950 | QualType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 951 | QualType ToBaseType = Importer.Import(T->getBaseType()); |
| 952 | if (ToBaseType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 953 | return {}; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 954 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 955 | SmallVector<QualType, 4> TypeArgs; |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 956 | for (auto TypeArg : T->getTypeArgsAsWritten()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 957 | QualType ImportedTypeArg = Importer.Import(TypeArg); |
| 958 | if (ImportedTypeArg.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 959 | return {}; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 960 | |
| 961 | TypeArgs.push_back(ImportedTypeArg); |
| 962 | } |
| 963 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 964 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
Aaron Ballman | 1683f7b | 2014-03-17 15:55:30 +0000 | [diff] [blame] | 965 | for (auto *P : T->quals()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 966 | auto *Protocol = dyn_cast_or_null<ObjCProtocolDecl>(Importer.Import(P)); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 967 | if (!Protocol) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 968 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 969 | Protocols.push_back(Protocol); |
| 970 | } |
| 971 | |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 972 | return Importer.getToContext().getObjCObjectType(ToBaseType, TypeArgs, |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 973 | Protocols, |
| 974 | T->isKindOfTypeAsWritten()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 975 | } |
| 976 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 977 | QualType |
| 978 | ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 979 | QualType ToPointeeType = Importer.Import(T->getPointeeType()); |
| 980 | if (ToPointeeType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 981 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 982 | |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 983 | return Importer.getToContext().getObjCObjectPointerType(ToPointeeType); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 984 | } |
| 985 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 986 | //---------------------------------------------------------------------------- |
| 987 | // Import Declarations |
| 988 | //---------------------------------------------------------------------------- |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 989 | bool ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclContext *&DC, |
| 990 | DeclContext *&LexicalDC, |
| 991 | DeclarationName &Name, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 992 | NamedDecl *&ToD, |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 993 | SourceLocation &Loc) { |
| 994 | // Import the context of this declaration. |
| 995 | DC = Importer.ImportContext(D->getDeclContext()); |
| 996 | if (!DC) |
| 997 | return true; |
| 998 | |
| 999 | LexicalDC = DC; |
| 1000 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 1001 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 1002 | if (!LexicalDC) |
| 1003 | return true; |
| 1004 | } |
| 1005 | |
| 1006 | // Import the name of this declaration. |
| 1007 | Name = Importer.Import(D->getDeclName()); |
| 1008 | if (D->getDeclName() && !Name) |
| 1009 | return true; |
| 1010 | |
| 1011 | // Import the location of this declaration. |
| 1012 | Loc = Importer.Import(D->getLocation()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1013 | ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 1014 | return false; |
| 1015 | } |
| 1016 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1017 | void ASTNodeImporter::ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD) { |
| 1018 | if (!FromD) |
| 1019 | return; |
| 1020 | |
| 1021 | if (!ToD) { |
| 1022 | ToD = Importer.Import(FromD); |
| 1023 | if (!ToD) |
| 1024 | return; |
| 1025 | } |
| 1026 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1027 | if (auto *FromRecord = dyn_cast<RecordDecl>(FromD)) { |
| 1028 | if (auto *ToRecord = cast_or_null<RecordDecl>(ToD)) { |
Sean Callanan | 19dfc93 | 2013-01-11 23:17:47 +0000 | [diff] [blame] | 1029 | if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && !ToRecord->getDefinition()) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1030 | ImportDefinition(FromRecord, ToRecord); |
| 1031 | } |
| 1032 | } |
| 1033 | return; |
| 1034 | } |
| 1035 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1036 | if (auto *FromEnum = dyn_cast<EnumDecl>(FromD)) { |
| 1037 | if (auto *ToEnum = cast_or_null<EnumDecl>(ToD)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1038 | if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { |
| 1039 | ImportDefinition(FromEnum, ToEnum); |
| 1040 | } |
| 1041 | } |
| 1042 | return; |
| 1043 | } |
| 1044 | } |
| 1045 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1046 | void |
| 1047 | ASTNodeImporter::ImportDeclarationNameLoc(const DeclarationNameInfo &From, |
| 1048 | DeclarationNameInfo& To) { |
| 1049 | // NOTE: To.Name and To.Loc are already imported. |
| 1050 | // We only have to import To.LocInfo. |
| 1051 | switch (To.getName().getNameKind()) { |
| 1052 | case DeclarationName::Identifier: |
| 1053 | case DeclarationName::ObjCZeroArgSelector: |
| 1054 | case DeclarationName::ObjCOneArgSelector: |
| 1055 | case DeclarationName::ObjCMultiArgSelector: |
| 1056 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1057 | case DeclarationName::CXXDeductionGuideName: |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1058 | return; |
| 1059 | |
| 1060 | case DeclarationName::CXXOperatorName: { |
| 1061 | SourceRange Range = From.getCXXOperatorNameRange(); |
| 1062 | To.setCXXOperatorNameRange(Importer.Import(Range)); |
| 1063 | return; |
| 1064 | } |
| 1065 | case DeclarationName::CXXLiteralOperatorName: { |
| 1066 | SourceLocation Loc = From.getCXXLiteralOperatorNameLoc(); |
| 1067 | To.setCXXLiteralOperatorNameLoc(Importer.Import(Loc)); |
| 1068 | return; |
| 1069 | } |
| 1070 | case DeclarationName::CXXConstructorName: |
| 1071 | case DeclarationName::CXXDestructorName: |
| 1072 | case DeclarationName::CXXConversionFunctionName: { |
| 1073 | TypeSourceInfo *FromTInfo = From.getNamedTypeInfo(); |
| 1074 | To.setNamedTypeInfo(Importer.Import(FromTInfo)); |
| 1075 | return; |
| 1076 | } |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1077 | } |
Douglas Gregor | 07216d1 | 2011-11-02 20:52:01 +0000 | [diff] [blame] | 1078 | llvm_unreachable("Unknown name kind."); |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1081 | void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1082 | if (Importer.isMinimalImport() && !ForceImport) { |
Sean Callanan | 81d577c | 2011-07-22 23:46:03 +0000 | [diff] [blame] | 1083 | Importer.ImportContext(FromDC); |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 1084 | return; |
| 1085 | } |
| 1086 | |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 1087 | for (auto *From : FromDC->decls()) |
| 1088 | Importer.Import(From); |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1091 | static void setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, |
| 1092 | ASTImporter &Importer) { |
| 1093 | if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) { |
| 1094 | auto *ToTypedef = |
| 1095 | cast_or_null<TypedefNameDecl>(Importer.Import(FromTypedef)); |
| 1096 | assert (ToTypedef && "Failed to import typedef of an anonymous structure"); |
| 1097 | |
| 1098 | To->setTypedefNameForAnonDecl(ToTypedef); |
| 1099 | } |
| 1100 | } |
| 1101 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1102 | bool ASTNodeImporter::ImportDefinition(RecordDecl *From, RecordDecl *To, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1103 | ImportDefinitionKind Kind) { |
| 1104 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1105 | if (Kind == IDK_Everything) |
| 1106 | ImportDeclContext(From, /*ForceImport=*/true); |
| 1107 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1108 | return false; |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1109 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1110 | |
| 1111 | To->startDefinition(); |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1112 | |
| 1113 | setTypedefNameForAnonDecl(From, To, Importer); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1114 | |
| 1115 | // Add base classes. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1116 | if (auto *ToCXX = dyn_cast<CXXRecordDecl>(To)) { |
| 1117 | auto *FromCXX = cast<CXXRecordDecl>(From); |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1118 | |
| 1119 | struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); |
| 1120 | struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); |
| 1121 | ToData.UserDeclaredConstructor = FromData.UserDeclaredConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1122 | ToData.UserDeclaredSpecialMembers = FromData.UserDeclaredSpecialMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1123 | ToData.Aggregate = FromData.Aggregate; |
| 1124 | ToData.PlainOldData = FromData.PlainOldData; |
| 1125 | ToData.Empty = FromData.Empty; |
| 1126 | ToData.Polymorphic = FromData.Polymorphic; |
| 1127 | ToData.Abstract = FromData.Abstract; |
| 1128 | ToData.IsStandardLayout = FromData.IsStandardLayout; |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1129 | ToData.IsCXX11StandardLayout = FromData.IsCXX11StandardLayout; |
| 1130 | ToData.HasBasesWithFields = FromData.HasBasesWithFields; |
| 1131 | ToData.HasBasesWithNonStaticDataMembers = |
| 1132 | FromData.HasBasesWithNonStaticDataMembers; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1133 | ToData.HasPrivateFields = FromData.HasPrivateFields; |
| 1134 | ToData.HasProtectedFields = FromData.HasProtectedFields; |
| 1135 | ToData.HasPublicFields = FromData.HasPublicFields; |
| 1136 | ToData.HasMutableFields = FromData.HasMutableFields; |
Richard Smith | ab44d5b | 2013-12-10 08:25:00 +0000 | [diff] [blame] | 1137 | ToData.HasVariantMembers = FromData.HasVariantMembers; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1138 | ToData.HasOnlyCMembers = FromData.HasOnlyCMembers; |
Richard Smith | e2648ba | 2012-05-07 01:07:30 +0000 | [diff] [blame] | 1139 | ToData.HasInClassInitializer = FromData.HasInClassInitializer; |
Richard Smith | 593f993 | 2012-12-08 02:01:17 +0000 | [diff] [blame] | 1140 | ToData.HasUninitializedReferenceMember |
| 1141 | = FromData.HasUninitializedReferenceMember; |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1142 | ToData.HasUninitializedFields = FromData.HasUninitializedFields; |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1143 | ToData.HasInheritedConstructor = FromData.HasInheritedConstructor; |
| 1144 | ToData.HasInheritedAssignment = FromData.HasInheritedAssignment; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1145 | ToData.NeedOverloadResolutionForCopyConstructor |
| 1146 | = FromData.NeedOverloadResolutionForCopyConstructor; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1147 | ToData.NeedOverloadResolutionForMoveConstructor |
| 1148 | = FromData.NeedOverloadResolutionForMoveConstructor; |
| 1149 | ToData.NeedOverloadResolutionForMoveAssignment |
| 1150 | = FromData.NeedOverloadResolutionForMoveAssignment; |
| 1151 | ToData.NeedOverloadResolutionForDestructor |
| 1152 | = FromData.NeedOverloadResolutionForDestructor; |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1153 | ToData.DefaultedCopyConstructorIsDeleted |
| 1154 | = FromData.DefaultedCopyConstructorIsDeleted; |
Richard Smith | 6b02d46 | 2012-12-08 08:32:28 +0000 | [diff] [blame] | 1155 | ToData.DefaultedMoveConstructorIsDeleted |
| 1156 | = FromData.DefaultedMoveConstructorIsDeleted; |
| 1157 | ToData.DefaultedMoveAssignmentIsDeleted |
| 1158 | = FromData.DefaultedMoveAssignmentIsDeleted; |
| 1159 | ToData.DefaultedDestructorIsDeleted = FromData.DefaultedDestructorIsDeleted; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1160 | ToData.HasTrivialSpecialMembers = FromData.HasTrivialSpecialMembers; |
| 1161 | ToData.HasIrrelevantDestructor = FromData.HasIrrelevantDestructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1162 | ToData.HasConstexprNonCopyMoveConstructor |
| 1163 | = FromData.HasConstexprNonCopyMoveConstructor; |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1164 | ToData.HasDefaultedDefaultConstructor |
| 1165 | = FromData.HasDefaultedDefaultConstructor; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1166 | ToData.DefaultedDefaultConstructorIsConstexpr |
| 1167 | = FromData.DefaultedDefaultConstructorIsConstexpr; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1168 | ToData.HasConstexprDefaultConstructor |
| 1169 | = FromData.HasConstexprDefaultConstructor; |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1170 | ToData.HasNonLiteralTypeFieldsOrBases |
| 1171 | = FromData.HasNonLiteralTypeFieldsOrBases; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1172 | // ComputedVisibleConversions not imported. |
Douglas Gregor | 3c2404b | 2011-11-03 18:07:07 +0000 | [diff] [blame] | 1173 | ToData.UserProvidedDefaultConstructor |
| 1174 | = FromData.UserProvidedDefaultConstructor; |
Richard Smith | 328aae5 | 2012-11-30 05:11:39 +0000 | [diff] [blame] | 1175 | ToData.DeclaredSpecialMembers = FromData.DeclaredSpecialMembers; |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1176 | ToData.ImplicitCopyConstructorCanHaveConstParamForVBase |
| 1177 | = FromData.ImplicitCopyConstructorCanHaveConstParamForVBase; |
| 1178 | ToData.ImplicitCopyConstructorCanHaveConstParamForNonVBase |
| 1179 | = FromData.ImplicitCopyConstructorCanHaveConstParamForNonVBase; |
Richard Smith | 1c33fe8 | 2012-11-28 06:23:12 +0000 | [diff] [blame] | 1180 | ToData.ImplicitCopyAssignmentHasConstParam |
| 1181 | = FromData.ImplicitCopyAssignmentHasConstParam; |
| 1182 | ToData.HasDeclaredCopyConstructorWithConstParam |
| 1183 | = FromData.HasDeclaredCopyConstructorWithConstParam; |
| 1184 | ToData.HasDeclaredCopyAssignmentWithConstParam |
| 1185 | = FromData.HasDeclaredCopyAssignmentWithConstParam; |
Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 1186 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1187 | SmallVector<CXXBaseSpecifier *, 4> Bases; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1188 | for (const auto &Base1 : FromCXX->bases()) { |
| 1189 | QualType T = Importer.Import(Base1.getType()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1190 | if (T.isNull()) |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1191 | return true; |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1192 | |
| 1193 | SourceLocation EllipsisLoc; |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1194 | if (Base1.isPackExpansion()) |
| 1195 | EllipsisLoc = Importer.Import(Base1.getEllipsisLoc()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1196 | |
| 1197 | // Ensure that we have a definition for the base. |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1198 | ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1199 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1200 | Bases.push_back( |
| 1201 | new (Importer.getToContext()) |
Aaron Ballman | 574705e | 2014-03-13 15:41:46 +0000 | [diff] [blame] | 1202 | CXXBaseSpecifier(Importer.Import(Base1.getSourceRange()), |
| 1203 | Base1.isVirtual(), |
| 1204 | Base1.isBaseOfClass(), |
| 1205 | Base1.getAccessSpecifierAsWritten(), |
| 1206 | Importer.Import(Base1.getTypeSourceInfo()), |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 1207 | EllipsisLoc)); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1208 | } |
| 1209 | if (!Bases.empty()) |
Craig Topper | e6337e1 | 2015-12-25 00:36:02 +0000 | [diff] [blame] | 1210 | ToCXX->setBases(Bases.data(), Bases.size()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1213 | if (shouldForceImportDeclContext(Kind)) |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 1214 | ImportDeclContext(From, /*ForceImport=*/true); |
| 1215 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1216 | To->completeDefinition(); |
Douglas Gregor | 96303ea | 2010-12-02 19:33:37 +0000 | [diff] [blame] | 1217 | return false; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1220 | bool ASTNodeImporter::ImportDefinition(VarDecl *From, VarDecl *To, |
| 1221 | ImportDefinitionKind Kind) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1222 | if (To->getAnyInitializer()) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1223 | return false; |
| 1224 | |
| 1225 | // FIXME: Can we really import any initializer? Alternatively, we could force |
| 1226 | // ourselves to import every declaration of a variable and then only use |
| 1227 | // getInit() here. |
| 1228 | To->setInit(Importer.Import(const_cast<Expr *>(From->getAnyInitializer()))); |
| 1229 | |
| 1230 | // FIXME: Other bits to merge? |
| 1231 | |
| 1232 | return false; |
| 1233 | } |
| 1234 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1235 | bool ASTNodeImporter::ImportDefinition(EnumDecl *From, EnumDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1236 | ImportDefinitionKind Kind) { |
| 1237 | if (To->getDefinition() || To->isBeingDefined()) { |
| 1238 | if (Kind == IDK_Everything) |
| 1239 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1240 | return false; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1241 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1242 | |
| 1243 | To->startDefinition(); |
| 1244 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1245 | setTypedefNameForAnonDecl(From, To, Importer); |
| 1246 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1247 | QualType T = Importer.Import(Importer.getFromContext().getTypeDeclType(From)); |
| 1248 | if (T.isNull()) |
| 1249 | return true; |
| 1250 | |
| 1251 | QualType ToPromotionType = Importer.Import(From->getPromotionType()); |
| 1252 | if (ToPromotionType.isNull()) |
| 1253 | return true; |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 1254 | |
| 1255 | if (shouldForceImportDeclContext(Kind)) |
| 1256 | ImportDeclContext(From, /*ForceImport=*/true); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 1257 | |
| 1258 | // FIXME: we might need to merge the number of positive or negative bits |
| 1259 | // if the enumerator lists don't match. |
| 1260 | To->completeDefinition(T, ToPromotionType, |
| 1261 | From->getNumPositiveBits(), |
| 1262 | From->getNumNegativeBits()); |
| 1263 | return false; |
| 1264 | } |
| 1265 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1266 | TemplateParameterList *ASTNodeImporter::ImportTemplateParameterList( |
| 1267 | TemplateParameterList *Params) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1268 | SmallVector<NamedDecl *, 4> ToParams(Params->size()); |
| 1269 | if (ImportContainerChecked(*Params, ToParams)) |
| 1270 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1271 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1272 | Expr *ToRequiresClause; |
| 1273 | if (Expr *const R = Params->getRequiresClause()) { |
| 1274 | ToRequiresClause = Importer.Import(R); |
| 1275 | if (!ToRequiresClause) |
| 1276 | return nullptr; |
| 1277 | } else { |
| 1278 | ToRequiresClause = nullptr; |
| 1279 | } |
| 1280 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1281 | return TemplateParameterList::Create(Importer.getToContext(), |
| 1282 | Importer.Import(Params->getTemplateLoc()), |
| 1283 | Importer.Import(Params->getLAngleLoc()), |
David Majnemer | 902f8c6 | 2015-12-27 07:16:27 +0000 | [diff] [blame] | 1284 | ToParams, |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 1285 | Importer.Import(Params->getRAngleLoc()), |
| 1286 | ToRequiresClause); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1287 | } |
| 1288 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1289 | TemplateArgument |
| 1290 | ASTNodeImporter::ImportTemplateArgument(const TemplateArgument &From) { |
| 1291 | switch (From.getKind()) { |
| 1292 | case TemplateArgument::Null: |
| 1293 | return TemplateArgument(); |
| 1294 | |
| 1295 | case TemplateArgument::Type: { |
| 1296 | QualType ToType = Importer.Import(From.getAsType()); |
| 1297 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1298 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1299 | return TemplateArgument(ToType); |
| 1300 | } |
| 1301 | |
| 1302 | case TemplateArgument::Integral: { |
| 1303 | QualType ToType = Importer.Import(From.getIntegralType()); |
| 1304 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1305 | return {}; |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 1306 | return TemplateArgument(From, ToType); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1309 | case TemplateArgument::Declaration: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1310 | auto *To = cast_or_null<ValueDecl>(Importer.Import(From.getAsDecl())); |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1311 | QualType ToType = Importer.Import(From.getParamTypeForDecl()); |
| 1312 | if (!To || ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1313 | return {}; |
David Blaikie | 3c7dd6b | 2014-10-22 19:54:16 +0000 | [diff] [blame] | 1314 | return TemplateArgument(To, ToType); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | case TemplateArgument::NullPtr: { |
| 1318 | QualType ToType = Importer.Import(From.getNullPtrType()); |
| 1319 | if (ToType.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1320 | return {}; |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 1321 | return TemplateArgument(ToType, /*isNullPtr*/true); |
| 1322 | } |
| 1323 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1324 | case TemplateArgument::Template: { |
| 1325 | TemplateName ToTemplate = Importer.Import(From.getAsTemplate()); |
| 1326 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1327 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1328 | |
| 1329 | return TemplateArgument(ToTemplate); |
| 1330 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1331 | |
| 1332 | case TemplateArgument::TemplateExpansion: { |
| 1333 | TemplateName ToTemplate |
| 1334 | = Importer.Import(From.getAsTemplateOrTemplatePattern()); |
| 1335 | if (ToTemplate.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1336 | return {}; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1337 | |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 1338 | return TemplateArgument(ToTemplate, From.getNumTemplateExpansions()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1341 | case TemplateArgument::Expression: |
| 1342 | if (Expr *ToExpr = Importer.Import(From.getAsExpr())) |
| 1343 | return TemplateArgument(ToExpr); |
| 1344 | return TemplateArgument(); |
| 1345 | |
| 1346 | case TemplateArgument::Pack: { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1347 | SmallVector<TemplateArgument, 2> ToPack; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1348 | ToPack.reserve(From.pack_size()); |
| 1349 | if (ImportTemplateArguments(From.pack_begin(), From.pack_size(), ToPack)) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1350 | return {}; |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 1351 | |
| 1352 | return TemplateArgument( |
| 1353 | llvm::makeArrayRef(ToPack).copy(Importer.getToContext())); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | llvm_unreachable("Invalid template argument kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1358 | } |
| 1359 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1360 | Optional<TemplateArgumentLoc> |
| 1361 | ASTNodeImporter::ImportTemplateArgumentLoc(const TemplateArgumentLoc &TALoc) { |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1362 | TemplateArgument Arg = ImportTemplateArgument(TALoc.getArgument()); |
| 1363 | TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo(); |
| 1364 | TemplateArgumentLocInfo ToInfo; |
| 1365 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 1366 | Expr *E = Importer.Import(FromInfo.getAsExpr()); |
| 1367 | ToInfo = TemplateArgumentLocInfo(E); |
| 1368 | if (!E) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1369 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1370 | } else if (Arg.getKind() == TemplateArgument::Type) { |
| 1371 | if (TypeSourceInfo *TSI = Importer.Import(FromInfo.getAsTypeSourceInfo())) |
| 1372 | ToInfo = TemplateArgumentLocInfo(TSI); |
| 1373 | else |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1374 | return None; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1375 | } else { |
| 1376 | ToInfo = TemplateArgumentLocInfo( |
| 1377 | Importer.Import(FromInfo.getTemplateQualifierLoc()), |
| 1378 | Importer.Import(FromInfo.getTemplateNameLoc()), |
| 1379 | Importer.Import(FromInfo.getTemplateEllipsisLoc())); |
| 1380 | } |
| 1381 | return TemplateArgumentLoc(Arg, ToInfo); |
| 1382 | } |
| 1383 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1384 | bool ASTNodeImporter::ImportTemplateArguments(const TemplateArgument *FromArgs, |
| 1385 | unsigned NumFromArgs, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1386 | SmallVectorImpl<TemplateArgument> &ToArgs) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 1387 | for (unsigned I = 0; I != NumFromArgs; ++I) { |
| 1388 | TemplateArgument To = ImportTemplateArgument(FromArgs[I]); |
| 1389 | if (To.isNull() && !FromArgs[I].isNull()) |
| 1390 | return true; |
| 1391 | |
| 1392 | ToArgs.push_back(To); |
| 1393 | } |
| 1394 | |
| 1395 | return false; |
| 1396 | } |
| 1397 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 1398 | // We cannot use Optional<> pattern here and below because |
| 1399 | // TemplateArgumentListInfo's operator new is declared as deleted so it cannot |
| 1400 | // be stored in Optional. |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1401 | template <typename InContainerTy> |
| 1402 | bool ASTNodeImporter::ImportTemplateArgumentListInfo( |
| 1403 | const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) { |
| 1404 | for (const auto &FromLoc : Container) { |
| 1405 | if (auto ToLoc = ImportTemplateArgumentLoc(FromLoc)) |
| 1406 | ToTAInfo.addArgument(*ToLoc); |
| 1407 | else |
| 1408 | return true; |
| 1409 | } |
| 1410 | return false; |
| 1411 | } |
| 1412 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1413 | bool ASTNodeImporter::IsStructuralMatch(RecordDecl *FromRecord, |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1414 | RecordDecl *ToRecord, bool Complain) { |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1415 | // Eliminate a potential failure point where we attempt to re-import |
| 1416 | // something we're trying to import while completing ToRecord. |
| 1417 | Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); |
| 1418 | if (ToOrigin) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1419 | auto *ToOriginRecord = dyn_cast<RecordDecl>(ToOrigin); |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1420 | if (ToOriginRecord) |
| 1421 | ToRecord = ToOriginRecord; |
| 1422 | } |
| 1423 | |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1424 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Sean Callanan | c665c9e | 2013-10-09 21:45:11 +0000 | [diff] [blame] | 1425 | ToRecord->getASTContext(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1426 | Importer.getNonEquivalentDecls(), |
| 1427 | false, Complain); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1428 | return Ctx.IsStructurallyEquivalent(FromRecord, ToRecord); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1431 | bool ASTNodeImporter::IsStructuralMatch(VarDecl *FromVar, VarDecl *ToVar, |
| 1432 | bool Complain) { |
| 1433 | StructuralEquivalenceContext Ctx( |
| 1434 | Importer.getFromContext(), Importer.getToContext(), |
| 1435 | Importer.getNonEquivalentDecls(), false, Complain); |
| 1436 | return Ctx.IsStructurallyEquivalent(FromVar, ToVar); |
| 1437 | } |
| 1438 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1439 | bool ASTNodeImporter::IsStructuralMatch(EnumDecl *FromEnum, EnumDecl *ToEnum) { |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1440 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1441 | Importer.getToContext(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1442 | Importer.getNonEquivalentDecls()); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 1443 | return Ctx.IsStructurallyEquivalent(FromEnum, ToEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 1446 | bool ASTNodeImporter::IsStructuralMatch(FunctionTemplateDecl *From, |
| 1447 | FunctionTemplateDecl *To) { |
| 1448 | StructuralEquivalenceContext Ctx( |
| 1449 | Importer.getFromContext(), Importer.getToContext(), |
| 1450 | Importer.getNonEquivalentDecls(), false, false); |
| 1451 | return Ctx.IsStructurallyEquivalent(From, To); |
| 1452 | } |
| 1453 | |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1454 | bool ASTNodeImporter::IsStructuralMatch(EnumConstantDecl *FromEC, |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1455 | EnumConstantDecl *ToEC) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 1456 | const llvm::APSInt &FromVal = FromEC->getInitVal(); |
| 1457 | const llvm::APSInt &ToVal = ToEC->getInitVal(); |
| 1458 | |
| 1459 | return FromVal.isSigned() == ToVal.isSigned() && |
| 1460 | FromVal.getBitWidth() == ToVal.getBitWidth() && |
| 1461 | FromVal == ToVal; |
| 1462 | } |
| 1463 | |
| 1464 | bool ASTNodeImporter::IsStructuralMatch(ClassTemplateDecl *From, |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1465 | ClassTemplateDecl *To) { |
| 1466 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1467 | Importer.getToContext(), |
| 1468 | Importer.getNonEquivalentDecls()); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1469 | return Ctx.IsStructurallyEquivalent(From, To); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 1470 | } |
| 1471 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1472 | bool ASTNodeImporter::IsStructuralMatch(VarTemplateDecl *From, |
| 1473 | VarTemplateDecl *To) { |
| 1474 | StructuralEquivalenceContext Ctx(Importer.getFromContext(), |
| 1475 | Importer.getToContext(), |
| 1476 | Importer.getNonEquivalentDecls()); |
| 1477 | return Ctx.IsStructurallyEquivalent(From, To); |
| 1478 | } |
| 1479 | |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1480 | Decl *ASTNodeImporter::VisitDecl(Decl *D) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 1481 | Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node) |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1482 | << D->getDeclKindName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1483 | return nullptr; |
Douglas Gregor | e4c83e4 | 2010-02-09 22:48:33 +0000 | [diff] [blame] | 1484 | } |
| 1485 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1486 | Decl *ASTNodeImporter::VisitEmptyDecl(EmptyDecl *D) { |
| 1487 | // Import the context of this declaration. |
| 1488 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1489 | if (!DC) |
| 1490 | return nullptr; |
| 1491 | |
| 1492 | DeclContext *LexicalDC = DC; |
| 1493 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 1494 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 1495 | if (!LexicalDC) |
| 1496 | return nullptr; |
| 1497 | } |
| 1498 | |
| 1499 | // Import the location of this declaration. |
| 1500 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1501 | |
| 1502 | EmptyDecl *ToD = EmptyDecl::Create(Importer.getToContext(), DC, Loc); |
| 1503 | ToD->setLexicalDeclContext(LexicalDC); |
| 1504 | Importer.Imported(D, ToD); |
| 1505 | LexicalDC->addDeclInternal(ToD); |
| 1506 | return ToD; |
| 1507 | } |
| 1508 | |
Sean Callanan | 6519827 | 2011-11-17 23:20:56 +0000 | [diff] [blame] | 1509 | Decl *ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
| 1510 | TranslationUnitDecl *ToD = |
| 1511 | Importer.getToContext().getTranslationUnitDecl(); |
| 1512 | |
| 1513 | Importer.Imported(D, ToD); |
| 1514 | |
| 1515 | return ToD; |
| 1516 | } |
| 1517 | |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1518 | Decl *ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
Argyrios Kyrtzidis | 544ea71 | 2016-02-18 23:08:36 +0000 | [diff] [blame] | 1519 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1520 | SourceLocation ColonLoc = Importer.Import(D->getColonLoc()); |
| 1521 | |
| 1522 | // Import the context of this declaration. |
| 1523 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1524 | if (!DC) |
| 1525 | return nullptr; |
| 1526 | |
| 1527 | AccessSpecDecl *accessSpecDecl |
| 1528 | = AccessSpecDecl::Create(Importer.getToContext(), D->getAccess(), |
| 1529 | DC, Loc, ColonLoc); |
| 1530 | |
| 1531 | if (!accessSpecDecl) |
| 1532 | return nullptr; |
| 1533 | |
| 1534 | // Lexical DeclContext and Semantic DeclContext |
| 1535 | // is always the same for the accessSpec. |
| 1536 | accessSpecDecl->setLexicalDeclContext(DC); |
| 1537 | DC->addDeclInternal(accessSpecDecl); |
| 1538 | |
| 1539 | return accessSpecDecl; |
| 1540 | } |
| 1541 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1542 | Decl *ASTNodeImporter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
| 1543 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 1544 | if (!DC) |
| 1545 | return nullptr; |
| 1546 | |
| 1547 | DeclContext *LexicalDC = DC; |
| 1548 | |
| 1549 | // Import the location of this declaration. |
| 1550 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 1551 | |
| 1552 | Expr *AssertExpr = Importer.Import(D->getAssertExpr()); |
| 1553 | if (!AssertExpr) |
| 1554 | return nullptr; |
| 1555 | |
| 1556 | StringLiteral *FromMsg = D->getMessage(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1557 | auto *ToMsg = cast_or_null<StringLiteral>(Importer.Import(FromMsg)); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 1558 | if (!ToMsg && FromMsg) |
| 1559 | return nullptr; |
| 1560 | |
| 1561 | StaticAssertDecl *ToD = StaticAssertDecl::Create( |
| 1562 | Importer.getToContext(), DC, Loc, AssertExpr, ToMsg, |
| 1563 | Importer.Import(D->getRParenLoc()), D->isFailed()); |
| 1564 | |
| 1565 | ToD->setLexicalDeclContext(LexicalDC); |
| 1566 | LexicalDC->addDeclInternal(ToD); |
| 1567 | Importer.Imported(D, ToD); |
| 1568 | return ToD; |
| 1569 | } |
| 1570 | |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1571 | Decl *ASTNodeImporter::VisitNamespaceDecl(NamespaceDecl *D) { |
| 1572 | // Import the major distinguishing characteristics of this namespace. |
| 1573 | DeclContext *DC, *LexicalDC; |
| 1574 | DeclarationName Name; |
| 1575 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1576 | NamedDecl *ToD; |
| 1577 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1578 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1579 | if (ToD) |
| 1580 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1581 | |
| 1582 | NamespaceDecl *MergeWithNamespace = nullptr; |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1583 | if (!Name) { |
| 1584 | // This is an anonymous namespace. Adopt an existing anonymous |
| 1585 | // namespace if we can. |
| 1586 | // FIXME: Not testable. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1587 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1588 | MergeWithNamespace = TU->getAnonymousNamespace(); |
| 1589 | else |
| 1590 | MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace(); |
| 1591 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1592 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1593 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1594 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1595 | for (auto *FoundDecl : FoundDecls) { |
| 1596 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Namespace)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1597 | continue; |
| 1598 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1599 | if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) { |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1600 | MergeWithNamespace = FoundNS; |
| 1601 | ConflictingDecls.clear(); |
| 1602 | break; |
| 1603 | } |
| 1604 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1605 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | if (!ConflictingDecls.empty()) { |
John McCall | e87beb2 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 1609 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Namespace, |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1610 | ConflictingDecls.data(), |
| 1611 | ConflictingDecls.size()); |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | // Create the "to" namespace, if needed. |
| 1616 | NamespaceDecl *ToNamespace = MergeWithNamespace; |
| 1617 | if (!ToNamespace) { |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 1618 | ToNamespace = NamespaceDecl::Create(Importer.getToContext(), DC, |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1619 | D->isInline(), |
Abramo Bagnara | b5545be | 2011-03-08 12:38:20 +0000 | [diff] [blame] | 1620 | Importer.Import(D->getLocStart()), |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1621 | Loc, Name.getAsIdentifierInfo(), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1622 | /*PrevDecl=*/nullptr); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1623 | ToNamespace->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1624 | LexicalDC->addDeclInternal(ToNamespace); |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1625 | |
| 1626 | // If this is an anonymous namespace, register it as the anonymous |
| 1627 | // namespace within its context. |
| 1628 | if (!Name) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1629 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
Douglas Gregor | f18a2c7 | 2010-02-21 18:26:36 +0000 | [diff] [blame] | 1630 | TU->setAnonymousNamespace(ToNamespace); |
| 1631 | else |
| 1632 | cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace); |
| 1633 | } |
| 1634 | } |
| 1635 | Importer.Imported(D, ToNamespace); |
| 1636 | |
| 1637 | ImportDeclContext(D); |
| 1638 | |
| 1639 | return ToNamespace; |
| 1640 | } |
| 1641 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1642 | Decl *ASTNodeImporter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 1643 | // Import the major distinguishing characteristics of this namespace. |
| 1644 | DeclContext *DC, *LexicalDC; |
| 1645 | DeclarationName Name; |
| 1646 | SourceLocation Loc; |
| 1647 | NamedDecl *LookupD; |
| 1648 | if (ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc)) |
| 1649 | return nullptr; |
| 1650 | if (LookupD) |
| 1651 | return LookupD; |
| 1652 | |
| 1653 | // NOTE: No conflict resolution is done for namespace aliases now. |
| 1654 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1655 | auto *TargetDecl = cast_or_null<NamespaceDecl>( |
| 1656 | Importer.Import(D->getNamespace())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 1657 | if (!TargetDecl) |
| 1658 | return nullptr; |
| 1659 | |
| 1660 | IdentifierInfo *ToII = Importer.Import(D->getIdentifier()); |
| 1661 | if (!ToII) |
| 1662 | return nullptr; |
| 1663 | |
| 1664 | NestedNameSpecifierLoc ToQLoc = Importer.Import(D->getQualifierLoc()); |
| 1665 | if (D->getQualifierLoc() && !ToQLoc) |
| 1666 | return nullptr; |
| 1667 | |
| 1668 | NamespaceAliasDecl *ToD = NamespaceAliasDecl::Create( |
| 1669 | Importer.getToContext(), DC, Importer.Import(D->getNamespaceLoc()), |
| 1670 | Importer.Import(D->getAliasLoc()), ToII, ToQLoc, |
| 1671 | Importer.Import(D->getTargetNameLoc()), TargetDecl); |
| 1672 | |
| 1673 | ToD->setLexicalDeclContext(LexicalDC); |
| 1674 | Importer.Imported(D, ToD); |
| 1675 | LexicalDC->addDeclInternal(ToD); |
| 1676 | |
| 1677 | return ToD; |
| 1678 | } |
| 1679 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1680 | Decl *ASTNodeImporter::VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias) { |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1681 | // Import the major distinguishing characteristics of this typedef. |
| 1682 | DeclContext *DC, *LexicalDC; |
| 1683 | DeclarationName Name; |
| 1684 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1685 | NamedDecl *ToD; |
| 1686 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1687 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1688 | if (ToD) |
| 1689 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1690 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1691 | // If this typedef is not in block scope, determine whether we've |
| 1692 | // seen a typedef with the same name (that we can merge with) or any |
| 1693 | // other entity by that name (which name lookup could conflict with). |
| 1694 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1695 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1696 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1697 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 1698 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1699 | for (auto *FoundDecl : FoundDecls) { |
| 1700 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1701 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1702 | if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1703 | if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(), |
| 1704 | FoundTypedef->getUnderlyingType())) |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1705 | return Importer.Imported(D, FoundTypedef); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1706 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1707 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1708 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1709 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1710 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1711 | if (!ConflictingDecls.empty()) { |
| 1712 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1713 | ConflictingDecls.data(), |
| 1714 | ConflictingDecls.size()); |
| 1715 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1716 | return nullptr; |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1717 | } |
| 1718 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1719 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 1720 | // Import the underlying type of this typedef; |
| 1721 | QualType T = Importer.Import(D->getUnderlyingType()); |
| 1722 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1723 | return nullptr; |
| 1724 | |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 1725 | // Some nodes (like anonymous tags referred by typedefs) are allowed to |
| 1726 | // import their enclosing typedef directly. Check if this is the case. |
| 1727 | if (Decl *AlreadyImported = Importer.GetAlreadyImportedOrNull(D)) |
| 1728 | return AlreadyImported; |
| 1729 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1730 | // Create the new typedef node. |
| 1731 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 1732 | SourceLocation StartL = Importer.Import(D->getLocStart()); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1733 | TypedefNameDecl *ToTypedef; |
| 1734 | if (IsAlias) |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1735 | ToTypedef = TypeAliasDecl::Create(Importer.getToContext(), DC, StartL, Loc, |
| 1736 | Name.getAsIdentifierInfo(), TInfo); |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 1737 | else |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1738 | ToTypedef = TypedefDecl::Create(Importer.getToContext(), DC, |
| 1739 | StartL, Loc, |
| 1740 | Name.getAsIdentifierInfo(), |
| 1741 | TInfo); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1742 | |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1743 | ToTypedef->setAccess(D->getAccess()); |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1744 | ToTypedef->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1745 | Importer.Imported(D, ToTypedef); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1746 | |
| 1747 | // Templated declarations should not appear in DeclContext. |
| 1748 | TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr; |
| 1749 | if (!FromAlias || !FromAlias->getDescribedAliasTemplate()) |
| 1750 | LexicalDC->addDeclInternal(ToTypedef); |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1751 | |
Douglas Gregor | 5fa74c3 | 2010-02-10 21:10:29 +0000 | [diff] [blame] | 1752 | return ToTypedef; |
| 1753 | } |
| 1754 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1755 | Decl *ASTNodeImporter::VisitTypedefDecl(TypedefDecl *D) { |
| 1756 | return VisitTypedefNameDecl(D, /*IsAlias=*/false); |
| 1757 | } |
| 1758 | |
| 1759 | Decl *ASTNodeImporter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
| 1760 | return VisitTypedefNameDecl(D, /*IsAlias=*/true); |
| 1761 | } |
| 1762 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1763 | Decl *ASTNodeImporter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| 1764 | // Import the major distinguishing characteristics of this typedef. |
| 1765 | DeclContext *DC, *LexicalDC; |
| 1766 | DeclarationName Name; |
| 1767 | SourceLocation Loc; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1768 | NamedDecl *FoundD; |
| 1769 | if (ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1770 | return nullptr; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1771 | if (FoundD) |
| 1772 | return FoundD; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1773 | |
| 1774 | // If this typedef is not in block scope, determine whether we've |
| 1775 | // seen a typedef with the same name (that we can merge with) or any |
| 1776 | // other entity by that name (which name lookup could conflict with). |
| 1777 | if (!DC->isFunctionOrMethod()) { |
| 1778 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 1779 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 1780 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 1781 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1782 | for (auto *FoundDecl : FoundDecls) { |
| 1783 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1784 | continue; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1785 | if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1786 | return Importer.Imported(D, FoundAlias); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1787 | ConflictingDecls.push_back(FoundDecl); |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | if (!ConflictingDecls.empty()) { |
| 1791 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1792 | ConflictingDecls.data(), |
| 1793 | ConflictingDecls.size()); |
| 1794 | if (!Name) |
| 1795 | return nullptr; |
| 1796 | } |
| 1797 | } |
| 1798 | |
| 1799 | TemplateParameterList *Params = ImportTemplateParameterList( |
| 1800 | D->getTemplateParameters()); |
| 1801 | if (!Params) |
| 1802 | return nullptr; |
| 1803 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1804 | auto *TemplDecl = cast_or_null<TypeAliasDecl>( |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1805 | Importer.Import(D->getTemplatedDecl())); |
| 1806 | if (!TemplDecl) |
| 1807 | return nullptr; |
| 1808 | |
| 1809 | TypeAliasTemplateDecl *ToAlias = TypeAliasTemplateDecl::Create( |
| 1810 | Importer.getToContext(), DC, Loc, Name, Params, TemplDecl); |
| 1811 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1812 | TemplDecl->setDescribedAliasTemplate(ToAlias); |
| 1813 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1814 | ToAlias->setAccess(D->getAccess()); |
| 1815 | ToAlias->setLexicalDeclContext(LexicalDC); |
| 1816 | Importer.Imported(D, ToAlias); |
| 1817 | LexicalDC->addDeclInternal(ToAlias); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 1818 | return ToAlias; |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 1819 | } |
| 1820 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1821 | Decl *ASTNodeImporter::VisitLabelDecl(LabelDecl *D) { |
| 1822 | // Import the major distinguishing characteristics of this label. |
| 1823 | DeclContext *DC, *LexicalDC; |
| 1824 | DeclarationName Name; |
| 1825 | SourceLocation Loc; |
| 1826 | NamedDecl *ToD; |
| 1827 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 1828 | return nullptr; |
| 1829 | if (ToD) |
| 1830 | return ToD; |
| 1831 | |
| 1832 | assert(LexicalDC->isFunctionOrMethod()); |
| 1833 | |
| 1834 | LabelDecl *ToLabel = D->isGnuLocal() |
| 1835 | ? LabelDecl::Create(Importer.getToContext(), |
| 1836 | DC, Importer.Import(D->getLocation()), |
| 1837 | Name.getAsIdentifierInfo(), |
| 1838 | Importer.Import(D->getLocStart())) |
| 1839 | : LabelDecl::Create(Importer.getToContext(), |
| 1840 | DC, Importer.Import(D->getLocation()), |
| 1841 | Name.getAsIdentifierInfo()); |
| 1842 | Importer.Imported(D, ToLabel); |
| 1843 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1844 | auto *Label = cast_or_null<LabelStmt>(Importer.Import(D->getStmt())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 1845 | if (!Label) |
| 1846 | return nullptr; |
| 1847 | |
| 1848 | ToLabel->setStmt(Label); |
| 1849 | ToLabel->setLexicalDeclContext(LexicalDC); |
| 1850 | LexicalDC->addDeclInternal(ToLabel); |
| 1851 | return ToLabel; |
| 1852 | } |
| 1853 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1854 | Decl *ASTNodeImporter::VisitEnumDecl(EnumDecl *D) { |
| 1855 | // Import the major distinguishing characteristics of this enum. |
| 1856 | DeclContext *DC, *LexicalDC; |
| 1857 | DeclarationName Name; |
| 1858 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1859 | NamedDecl *ToD; |
| 1860 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1861 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1862 | if (ToD) |
| 1863 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1864 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1865 | // Figure out what enum name we're looking for. |
| 1866 | unsigned IDNS = Decl::IDNS_Tag; |
| 1867 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1868 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 1869 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1870 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1871 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1872 | IDNS |= Decl::IDNS_Ordinary; |
| 1873 | |
| 1874 | // We may already have an enum of the same name; try to find and match it. |
| 1875 | if (!DC->isFunctionOrMethod() && SearchName) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1876 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1877 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 1878 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1879 | for (auto *FoundDecl : FoundDecls) { |
| 1880 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1881 | continue; |
| 1882 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1883 | Decl *Found = FoundDecl; |
| 1884 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 1885 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1886 | Found = Tag->getDecl(); |
| 1887 | } |
| 1888 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1889 | if (auto *FoundEnum = dyn_cast<EnumDecl>(Found)) { |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1890 | if (IsStructuralMatch(D, FoundEnum)) |
| 1891 | return Importer.Imported(D, FoundEnum); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1892 | } |
| 1893 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1894 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | if (!ConflictingDecls.empty()) { |
| 1898 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 1899 | ConflictingDecls.data(), |
| 1900 | ConflictingDecls.size()); |
| 1901 | } |
| 1902 | } |
| 1903 | |
| 1904 | // Create the enum declaration. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 1905 | EnumDecl *D2 = EnumDecl::Create(Importer.getToContext(), DC, |
| 1906 | Importer.Import(D->getLocStart()), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1907 | Loc, Name.getAsIdentifierInfo(), nullptr, |
Abramo Bagnara | 0e05e24 | 2010-12-03 18:54:17 +0000 | [diff] [blame] | 1908 | D->isScoped(), D->isScopedUsingClassTag(), |
| 1909 | D->isFixed()); |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 1910 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 1911 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 1912 | D2->setAccess(D->getAccess()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1913 | D2->setLexicalDeclContext(LexicalDC); |
| 1914 | Importer.Imported(D, D2); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 1915 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1916 | |
| 1917 | // Import the integer type. |
| 1918 | QualType ToIntegerType = Importer.Import(D->getIntegerType()); |
| 1919 | if (ToIntegerType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1920 | return nullptr; |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1921 | D2->setIntegerType(ToIntegerType); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1922 | |
| 1923 | // Import the definition |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 1924 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1925 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1926 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 1927 | return D2; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 1928 | } |
| 1929 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1930 | Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { |
| 1931 | // If this record has a definition in the translation unit we're coming from, |
| 1932 | // but this particular declaration is not that definition, import the |
| 1933 | // definition and map to that. |
Douglas Gregor | 0a5a221 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 1934 | TagDecl *Definition = D->getDefinition(); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1935 | if (Definition && Definition != D) { |
| 1936 | Decl *ImportedDef = Importer.Import(Definition); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1937 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1938 | return nullptr; |
| 1939 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 1940 | return Importer.Imported(D, ImportedDef); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1941 | } |
| 1942 | |
| 1943 | // Import the major distinguishing characteristics of this record. |
| 1944 | DeclContext *DC, *LexicalDC; |
| 1945 | DeclarationName Name; |
| 1946 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1947 | NamedDecl *ToD; |
| 1948 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1949 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 1950 | if (ToD) |
| 1951 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1952 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1953 | // Figure out what structure name we're looking for. |
| 1954 | unsigned IDNS = Decl::IDNS_Tag; |
| 1955 | DeclarationName SearchName = Name; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 1956 | if (!SearchName && D->getTypedefNameForAnonDecl()) { |
| 1957 | SearchName = Importer.Import(D->getTypedefNameForAnonDecl()->getDeclName()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1958 | IDNS = Decl::IDNS_Ordinary; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1959 | } else if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1960 | IDNS |= Decl::IDNS_Ordinary; |
| 1961 | |
| 1962 | // 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] | 1963 | RecordDecl *AdoptDecl = nullptr; |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 1964 | RecordDecl *PrevDecl = nullptr; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 1965 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1966 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1967 | SmallVector<NamedDecl *, 2> FoundDecls; |
Gabor Horvath | 5558ba2 | 2017-04-03 09:30:20 +0000 | [diff] [blame] | 1968 | DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 1969 | |
| 1970 | if (!FoundDecls.empty()) { |
| 1971 | // We're going to have to compare D against potentially conflicting Decls, so complete it. |
| 1972 | if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition()) |
| 1973 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 1974 | } |
| 1975 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1976 | for (auto *FoundDecl : FoundDecls) { |
| 1977 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1978 | continue; |
| 1979 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1980 | Decl *Found = FoundDecl; |
| 1981 | if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) { |
| 1982 | if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 1983 | Found = Tag->getDecl(); |
| 1984 | } |
| 1985 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 1986 | if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { |
Aleksei Sidorin | 499de6c | 2018-04-05 15:31:49 +0000 | [diff] [blame] | 1987 | if (!SearchName) { |
| 1988 | // If both unnamed structs/unions are in a record context, make sure |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 1989 | // they occur in the same location in the context records. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 1990 | if (Optional<unsigned> Index1 = |
| 1991 | StructuralEquivalenceContext::findUntaggedStructOrUnionIndex( |
| 1992 | D)) { |
| 1993 | if (Optional<unsigned> Index2 = StructuralEquivalenceContext:: |
Sean Callanan | 488f861 | 2016-07-14 19:53:44 +0000 | [diff] [blame] | 1994 | findUntaggedStructOrUnionIndex(FoundRecord)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 1995 | if (*Index1 != *Index2) |
| 1996 | continue; |
| 1997 | } |
| 1998 | } |
| 1999 | } |
| 2000 | |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2001 | PrevDecl = FoundRecord; |
| 2002 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2003 | if (RecordDecl *FoundDef = FoundRecord->getDefinition()) { |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2004 | if ((SearchName && !D->isCompleteDefinition()) |
| 2005 | || (D->isCompleteDefinition() && |
| 2006 | D->isAnonymousStructOrUnion() |
| 2007 | == FoundDef->isAnonymousStructOrUnion() && |
| 2008 | IsStructuralMatch(D, FoundDef))) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2009 | // The record types structurally match, or the "from" translation |
| 2010 | // unit only had a forward declaration anyway; call it the same |
| 2011 | // function. |
| 2012 | // FIXME: For C++, we should also merge methods here. |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2013 | return Importer.Imported(D, FoundDef); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2014 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2015 | } else if (!D->isCompleteDefinition()) { |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2016 | // We have a forward declaration of this type, so adopt that forward |
| 2017 | // declaration rather than building a new one. |
Sean Callanan | c94711c | 2014-03-04 18:11:50 +0000 | [diff] [blame] | 2018 | |
| 2019 | // If one or both can be completed from external storage then try one |
| 2020 | // last time to complete and compare them before doing this. |
| 2021 | |
| 2022 | if (FoundRecord->hasExternalLexicalStorage() && |
| 2023 | !FoundRecord->isCompleteDefinition()) |
| 2024 | FoundRecord->getASTContext().getExternalSource()->CompleteType(FoundRecord); |
| 2025 | if (D->hasExternalLexicalStorage()) |
| 2026 | D->getASTContext().getExternalSource()->CompleteType(D); |
| 2027 | |
| 2028 | if (FoundRecord->isCompleteDefinition() && |
| 2029 | D->isCompleteDefinition() && |
| 2030 | !IsStructuralMatch(D, FoundRecord)) |
| 2031 | continue; |
| 2032 | |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2033 | AdoptDecl = FoundRecord; |
| 2034 | continue; |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2035 | } else if (!SearchName) { |
| 2036 | continue; |
| 2037 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2040 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2041 | } |
| 2042 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2043 | if (!ConflictingDecls.empty() && SearchName) { |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2044 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2045 | ConflictingDecls.data(), |
| 2046 | ConflictingDecls.size()); |
| 2047 | } |
| 2048 | } |
| 2049 | |
| 2050 | // Create the record declaration. |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2051 | RecordDecl *D2 = AdoptDecl; |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 2052 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2053 | if (!D2) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2054 | CXXRecordDecl *D2CXX = nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2055 | if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2056 | if (DCXX->isLambda()) { |
| 2057 | TypeSourceInfo *TInfo = Importer.Import(DCXX->getLambdaTypeInfo()); |
| 2058 | D2CXX = CXXRecordDecl::CreateLambda(Importer.getToContext(), |
| 2059 | DC, TInfo, Loc, |
| 2060 | DCXX->isDependentLambda(), |
| 2061 | DCXX->isGenericLambda(), |
| 2062 | DCXX->getLambdaCaptureDefault()); |
| 2063 | Decl *CDecl = Importer.Import(DCXX->getLambdaContextDecl()); |
| 2064 | if (DCXX->getLambdaContextDecl() && !CDecl) |
| 2065 | return nullptr; |
Sean Callanan | 041cceb | 2016-05-14 05:43:57 +0000 | [diff] [blame] | 2066 | D2CXX->setLambdaMangling(DCXX->getLambdaManglingNumber(), CDecl); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2067 | } else if (DCXX->isInjectedClassName()) { |
| 2068 | // We have to be careful to do a similar dance to the one in |
| 2069 | // Sema::ActOnStartCXXMemberDeclarations |
| 2070 | CXXRecordDecl *const PrevDecl = nullptr; |
| 2071 | const bool DelayTypeCreation = true; |
| 2072 | D2CXX = CXXRecordDecl::Create( |
| 2073 | Importer.getToContext(), D->getTagKind(), DC, StartLoc, Loc, |
| 2074 | Name.getAsIdentifierInfo(), PrevDecl, DelayTypeCreation); |
| 2075 | Importer.getToContext().getTypeDeclType( |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2076 | D2CXX, dyn_cast<CXXRecordDecl>(DC)); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 2077 | } else { |
| 2078 | D2CXX = CXXRecordDecl::Create(Importer.getToContext(), |
| 2079 | D->getTagKind(), |
| 2080 | DC, StartLoc, Loc, |
| 2081 | Name.getAsIdentifierInfo()); |
| 2082 | } |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2083 | D2 = D2CXX; |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2084 | D2->setAccess(D->getAccess()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2085 | D2->setLexicalDeclContext(LexicalDC); |
| 2086 | if (!DCXX->getDescribedClassTemplate()) |
| 2087 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2088 | |
| 2089 | Importer.Imported(D, D2); |
| 2090 | |
| 2091 | if (ClassTemplateDecl *FromDescribed = |
| 2092 | DCXX->getDescribedClassTemplate()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2093 | auto *ToDescribed = cast_or_null<ClassTemplateDecl>( |
| 2094 | Importer.Import(FromDescribed)); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2095 | if (!ToDescribed) |
| 2096 | return nullptr; |
| 2097 | D2CXX->setDescribedClassTemplate(ToDescribed); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2098 | } else if (MemberSpecializationInfo *MemberInfo = |
| 2099 | DCXX->getMemberSpecializationInfo()) { |
| 2100 | TemplateSpecializationKind SK = |
| 2101 | MemberInfo->getTemplateSpecializationKind(); |
| 2102 | CXXRecordDecl *FromInst = DCXX->getInstantiatedFromMemberClass(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2103 | auto *ToInst = |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 2104 | cast_or_null<CXXRecordDecl>(Importer.Import(FromInst)); |
| 2105 | if (FromInst && !ToInst) |
| 2106 | return nullptr; |
| 2107 | D2CXX->setInstantiationOfMemberClass(ToInst, SK); |
| 2108 | D2CXX->getMemberSpecializationInfo()->setPointOfInstantiation( |
| 2109 | Importer.Import(MemberInfo->getPointOfInstantiation())); |
| 2110 | } |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2111 | } else { |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2112 | D2 = RecordDecl::Create(Importer.getToContext(), D->getTagKind(), |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 2113 | DC, StartLoc, Loc, Name.getAsIdentifierInfo()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2114 | D2->setLexicalDeclContext(LexicalDC); |
| 2115 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2116 | } |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2117 | |
| 2118 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2119 | if (D->isAnonymousStructOrUnion()) |
| 2120 | D2->setAnonymousStructOrUnion(true); |
Sean Callanan | 9092d47 | 2017-05-13 00:46:33 +0000 | [diff] [blame] | 2121 | if (PrevDecl) { |
| 2122 | // FIXME: do this for all Redeclarables, not just RecordDecls. |
| 2123 | D2->setPreviousDecl(PrevDecl); |
| 2124 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2125 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2126 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2127 | Importer.Imported(D, D2); |
Douglas Gregor | 2579105 | 2010-02-12 00:09:27 +0000 | [diff] [blame] | 2128 | |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 2129 | if (D->isCompleteDefinition() && ImportDefinition(D, D2, IDK_Default)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2130 | return nullptr; |
| 2131 | |
Douglas Gregor | 3996e24 | 2010-02-15 22:01:00 +0000 | [diff] [blame] | 2132 | return D2; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2133 | } |
| 2134 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2135 | Decl *ASTNodeImporter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
| 2136 | // Import the major distinguishing characteristics of this enumerator. |
| 2137 | DeclContext *DC, *LexicalDC; |
| 2138 | DeclarationName Name; |
| 2139 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2140 | NamedDecl *ToD; |
| 2141 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2142 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2143 | if (ToD) |
| 2144 | return ToD; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2145 | |
| 2146 | QualType T = Importer.Import(D->getType()); |
| 2147 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2148 | return nullptr; |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2149 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2150 | // Determine whether there are any other declarations with the same name and |
| 2151 | // in the same context. |
| 2152 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2153 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2154 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2155 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2156 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2157 | for (auto *FoundDecl : FoundDecls) { |
| 2158 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2159 | continue; |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2160 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2161 | if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) { |
Douglas Gregor | 9115508 | 2012-11-14 22:29:20 +0000 | [diff] [blame] | 2162 | if (IsStructuralMatch(D, FoundEnumConstant)) |
| 2163 | return Importer.Imported(D, FoundEnumConstant); |
| 2164 | } |
| 2165 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2166 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2167 | } |
| 2168 | |
| 2169 | if (!ConflictingDecls.empty()) { |
| 2170 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2171 | ConflictingDecls.data(), |
| 2172 | ConflictingDecls.size()); |
| 2173 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2174 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2175 | } |
| 2176 | } |
| 2177 | |
| 2178 | Expr *Init = Importer.Import(D->getInitExpr()); |
| 2179 | if (D->getInitExpr() && !Init) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2180 | return nullptr; |
| 2181 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2182 | EnumConstantDecl *ToEnumerator |
| 2183 | = EnumConstantDecl::Create(Importer.getToContext(), cast<EnumDecl>(DC), Loc, |
| 2184 | Name.getAsIdentifierInfo(), T, |
| 2185 | Init, D->getInitVal()); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2186 | ToEnumerator->setAccess(D->getAccess()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2187 | ToEnumerator->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2188 | Importer.Imported(D, ToEnumerator); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2189 | LexicalDC->addDeclInternal(ToEnumerator); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 2190 | return ToEnumerator; |
| 2191 | } |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2192 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2193 | bool ASTNodeImporter::ImportTemplateInformation(FunctionDecl *FromFD, |
| 2194 | FunctionDecl *ToFD) { |
| 2195 | switch (FromFD->getTemplatedKind()) { |
| 2196 | case FunctionDecl::TK_NonTemplate: |
| 2197 | case FunctionDecl::TK_FunctionTemplate: |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2198 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2199 | |
| 2200 | case FunctionDecl::TK_MemberSpecialization: { |
| 2201 | auto *InstFD = cast_or_null<FunctionDecl>( |
| 2202 | Importer.Import(FromFD->getInstantiatedFromMemberFunction())); |
| 2203 | if (!InstFD) |
| 2204 | return true; |
| 2205 | |
| 2206 | TemplateSpecializationKind TSK = FromFD->getTemplateSpecializationKind(); |
| 2207 | SourceLocation POI = Importer.Import( |
| 2208 | FromFD->getMemberSpecializationInfo()->getPointOfInstantiation()); |
| 2209 | ToFD->setInstantiationOfMemberFunction(InstFD, TSK); |
| 2210 | ToFD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2211 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
| 2215 | auto *FTSInfo = FromFD->getTemplateSpecializationInfo(); |
| 2216 | auto *Template = cast_or_null<FunctionTemplateDecl>( |
| 2217 | Importer.Import(FTSInfo->getTemplate())); |
| 2218 | if (!Template) |
| 2219 | return true; |
| 2220 | TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind(); |
| 2221 | |
| 2222 | // Import template arguments. |
| 2223 | auto TemplArgs = FTSInfo->TemplateArguments->asArray(); |
| 2224 | SmallVector<TemplateArgument, 8> ToTemplArgs; |
| 2225 | if (ImportTemplateArguments(TemplArgs.data(), TemplArgs.size(), |
| 2226 | ToTemplArgs)) |
| 2227 | return true; |
| 2228 | |
| 2229 | TemplateArgumentList *ToTAList = TemplateArgumentList::CreateCopy( |
| 2230 | Importer.getToContext(), ToTemplArgs); |
| 2231 | |
| 2232 | TemplateArgumentListInfo ToTAInfo; |
| 2233 | const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2234 | if (FromTAArgsAsWritten) |
| 2235 | if (ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2236 | return true; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2237 | |
| 2238 | SourceLocation POI = Importer.Import(FTSInfo->getPointOfInstantiation()); |
| 2239 | |
| 2240 | ToFD->setFunctionTemplateSpecialization( |
| 2241 | Template, ToTAList, /* InsertPos= */ nullptr, |
| 2242 | TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, POI); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2243 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 2247 | auto *FromInfo = FromFD->getDependentSpecializationInfo(); |
| 2248 | UnresolvedSet<8> TemplDecls; |
| 2249 | unsigned NumTemplates = FromInfo->getNumTemplates(); |
| 2250 | for (unsigned I = 0; I < NumTemplates; I++) { |
| 2251 | if (auto *ToFTD = cast_or_null<FunctionTemplateDecl>( |
| 2252 | Importer.Import(FromInfo->getTemplate(I)))) |
| 2253 | TemplDecls.addDecl(ToFTD); |
| 2254 | else |
| 2255 | return true; |
| 2256 | } |
| 2257 | |
| 2258 | // Import TemplateArgumentListInfo. |
| 2259 | TemplateArgumentListInfo ToTAInfo; |
| 2260 | if (ImportTemplateArgumentListInfo( |
| 2261 | FromInfo->getLAngleLoc(), FromInfo->getRAngleLoc(), |
| 2262 | llvm::makeArrayRef(FromInfo->getTemplateArgs(), |
| 2263 | FromInfo->getNumTemplateArgs()), |
| 2264 | ToTAInfo)) |
| 2265 | return true; |
| 2266 | |
| 2267 | ToFD->setDependentTemplateSpecialization(Importer.getToContext(), |
| 2268 | TemplDecls, ToTAInfo); |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2269 | return false; |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2270 | } |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2271 | } |
Sam McCall | fdc3207 | 2018-01-26 12:06:44 +0000 | [diff] [blame] | 2272 | llvm_unreachable("All cases should be covered!"); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2273 | } |
| 2274 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2275 | Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) { |
| 2276 | // Import the major distinguishing characteristics of this function. |
| 2277 | DeclContext *DC, *LexicalDC; |
| 2278 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2279 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2280 | NamedDecl *ToD; |
| 2281 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2282 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2283 | if (ToD) |
| 2284 | return ToD; |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2285 | |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2286 | const FunctionDecl *FoundWithoutBody = nullptr; |
| 2287 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2288 | // Try to find a function in our own ("to") context with the same name, same |
| 2289 | // type, and in the same context as the function we're importing. |
| 2290 | if (!LexicalDC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2291 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2292 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2293 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2294 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2295 | for (auto *FoundDecl : FoundDecls) { |
| 2296 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2297 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2298 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2299 | if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) { |
Rafael Espindola | 3ae0005 | 2013-05-13 00:12:11 +0000 | [diff] [blame] | 2300 | if (FoundFunction->hasExternalFormalLinkage() && |
| 2301 | D->hasExternalFormalLinkage()) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2302 | if (Importer.IsStructurallyEquivalent(D->getType(), |
| 2303 | FoundFunction->getType())) { |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2304 | // FIXME: Actually try to merge the body and other attributes. |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2305 | const FunctionDecl *FromBodyDecl = nullptr; |
| 2306 | D->hasBody(FromBodyDecl); |
| 2307 | if (D == FromBodyDecl && !FoundFunction->hasBody()) { |
| 2308 | // This function is needed to merge completely. |
| 2309 | FoundWithoutBody = FoundFunction; |
| 2310 | break; |
| 2311 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2312 | return Importer.Imported(D, FoundFunction); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2313 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2314 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2315 | // FIXME: Check for overloading more carefully, e.g., by boosting |
| 2316 | // Sema::IsOverload out to the AST library. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2317 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2318 | // Function overloading is okay in C++. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2319 | if (Importer.getToContext().getLangOpts().CPlusPlus) |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2320 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2321 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2322 | // Complain about inconsistent function types. |
| 2323 | Importer.ToDiag(Loc, diag::err_odr_function_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2324 | << Name << D->getType() << FoundFunction->getType(); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2325 | Importer.ToDiag(FoundFunction->getLocation(), |
| 2326 | diag::note_odr_value_here) |
| 2327 | << FoundFunction->getType(); |
| 2328 | } |
| 2329 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2330 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2331 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2332 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2333 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2334 | if (!ConflictingDecls.empty()) { |
| 2335 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2336 | ConflictingDecls.data(), |
| 2337 | ConflictingDecls.size()); |
| 2338 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2339 | return nullptr; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2340 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2341 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2342 | |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2343 | DeclarationNameInfo NameInfo(Name, Loc); |
| 2344 | // Import additional name location/type info. |
| 2345 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 2346 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2347 | QualType FromTy = D->getType(); |
| 2348 | bool usedDifferentExceptionSpec = false; |
| 2349 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2350 | if (const auto *FromFPT = D->getType()->getAs<FunctionProtoType>()) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2351 | FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); |
| 2352 | // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the |
| 2353 | // FunctionDecl that we are importing the FunctionProtoType for. |
| 2354 | // To avoid an infinite recursion when importing, create the FunctionDecl |
| 2355 | // with a simplified function type and update it afterwards. |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 2356 | if (FromEPI.ExceptionSpec.SourceDecl || |
| 2357 | FromEPI.ExceptionSpec.SourceTemplate || |
| 2358 | FromEPI.ExceptionSpec.NoexceptExpr) { |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2359 | FunctionProtoType::ExtProtoInfo DefaultEPI; |
| 2360 | FromTy = Importer.getFromContext().getFunctionType( |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 2361 | FromFPT->getReturnType(), FromFPT->getParamTypes(), DefaultEPI); |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2362 | usedDifferentExceptionSpec = true; |
| 2363 | } |
| 2364 | } |
| 2365 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2366 | // Import the type. |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2367 | QualType T = Importer.Import(FromTy); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2368 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2369 | return nullptr; |
| 2370 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2371 | // Import the function parameters. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2372 | SmallVector<ParmVarDecl *, 8> Parameters; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2373 | for (auto P : D->parameters()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2374 | auto *ToP = cast_or_null<ParmVarDecl>(Importer.Import(P)); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2375 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2376 | return nullptr; |
| 2377 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2378 | Parameters.push_back(ToP); |
| 2379 | } |
| 2380 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2381 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2382 | if (D->getTypeSourceInfo() && !TInfo) |
| 2383 | return nullptr; |
| 2384 | |
| 2385 | // Create the imported function. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2386 | FunctionDecl *ToFunction = nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2387 | SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2388 | if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2389 | ToFunction = CXXConstructorDecl::Create(Importer.getToContext(), |
| 2390 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2391 | InnerLocStart, |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2392 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2393 | FromConstructor->isExplicit(), |
| 2394 | D->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2395 | D->isImplicit(), |
| 2396 | D->isConstexpr()); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2397 | if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { |
| 2398 | SmallVector<CXXCtorInitializer *, 4> CtorInitializers; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2399 | for (auto *I : FromConstructor->inits()) { |
| 2400 | auto *ToI = cast_or_null<CXXCtorInitializer>(Importer.Import(I)); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2401 | if (!ToI && I) |
| 2402 | return nullptr; |
| 2403 | CtorInitializers.push_back(ToI); |
| 2404 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2405 | auto **Memory = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2406 | new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; |
| 2407 | std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2408 | auto *ToCtor = cast<CXXConstructorDecl>(ToFunction); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 2409 | ToCtor->setCtorInitializers(Memory); |
| 2410 | ToCtor->setNumCtorInitializers(NumInitializers); |
| 2411 | } |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2412 | } else if (isa<CXXDestructorDecl>(D)) { |
| 2413 | ToFunction = CXXDestructorDecl::Create(Importer.getToContext(), |
| 2414 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2415 | InnerLocStart, |
Craig Silverstein | af8808d | 2010-10-21 00:44:50 +0000 | [diff] [blame] | 2416 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2417 | D->isInlineSpecified(), |
| 2418 | D->isImplicit()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2419 | } else if (auto *FromConversion = dyn_cast<CXXConversionDecl>(D)) { |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2420 | ToFunction = CXXConversionDecl::Create(Importer.getToContext(), |
| 2421 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2422 | InnerLocStart, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2423 | NameInfo, T, TInfo, |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2424 | D->isInlineSpecified(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2425 | FromConversion->isExplicit(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2426 | D->isConstexpr(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2427 | Importer.Import(D->getLocEnd())); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2428 | } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
Douglas Gregor | a50ad13 | 2010-11-29 16:04:58 +0000 | [diff] [blame] | 2429 | ToFunction = CXXMethodDecl::Create(Importer.getToContext(), |
| 2430 | cast<CXXRecordDecl>(DC), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2431 | InnerLocStart, |
Douglas Gregor | a50ad13 | 2010-11-29 16:04:58 +0000 | [diff] [blame] | 2432 | NameInfo, T, TInfo, |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 2433 | Method->getStorageClass(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2434 | Method->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2435 | D->isConstexpr(), |
Douglas Gregor | f2f0806 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 2436 | Importer.Import(D->getLocEnd())); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2437 | } else { |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2438 | ToFunction = FunctionDecl::Create(Importer.getToContext(), DC, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2439 | InnerLocStart, |
Abramo Bagnara | d6d2f18 | 2010-08-11 22:01:17 +0000 | [diff] [blame] | 2440 | NameInfo, T, TInfo, D->getStorageClass(), |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2441 | D->isInlineSpecified(), |
Richard Smith | a77a0a6 | 2011-08-15 21:04:07 +0000 | [diff] [blame] | 2442 | D->hasWrittenPrototype(), |
| 2443 | D->isConstexpr()); |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2444 | } |
John McCall | 3e11ebe | 2010-03-15 10:12:16 +0000 | [diff] [blame] | 2445 | |
| 2446 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2447 | ToFunction->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2448 | ToFunction->setAccess(D->getAccess()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2449 | ToFunction->setLexicalDeclContext(LexicalDC); |
John McCall | 08432c8 | 2011-01-27 02:37:01 +0000 | [diff] [blame] | 2450 | ToFunction->setVirtualAsWritten(D->isVirtualAsWritten()); |
| 2451 | ToFunction->setTrivial(D->isTrivial()); |
| 2452 | ToFunction->setPure(D->isPure()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2453 | Importer.Imported(D, ToFunction); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2454 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2455 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2456 | for (auto *Param : Parameters) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2457 | Param->setOwningFunction(ToFunction); |
| 2458 | ToFunction->addDeclInternal(Param); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2459 | } |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 2460 | ToFunction->setParams(Parameters); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2461 | |
Gabor Horvath | e350b0a | 2017-09-22 11:11:01 +0000 | [diff] [blame] | 2462 | if (FoundWithoutBody) { |
| 2463 | auto *Recent = const_cast<FunctionDecl *>( |
| 2464 | FoundWithoutBody->getMostRecentDecl()); |
| 2465 | ToFunction->setPreviousDecl(Recent); |
| 2466 | } |
| 2467 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2468 | // We need to complete creation of FunctionProtoTypeLoc manually with setting |
| 2469 | // params it refers to. |
| 2470 | if (TInfo) { |
| 2471 | if (auto ProtoLoc = |
| 2472 | TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) { |
| 2473 | for (unsigned I = 0, N = Parameters.size(); I != N; ++I) |
| 2474 | ProtoLoc.setParam(I, Parameters[I]); |
| 2475 | } |
| 2476 | } |
| 2477 | |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2478 | if (usedDifferentExceptionSpec) { |
| 2479 | // Update FunctionProtoType::ExtProtoInfo. |
| 2480 | QualType T = Importer.Import(D->getType()); |
| 2481 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2482 | return nullptr; |
Argyrios Kyrtzidis | 2f45853 | 2012-09-25 19:26:39 +0000 | [diff] [blame] | 2483 | ToFunction->setType(T); |
Argyrios Kyrtzidis | b41791d | 2012-09-22 01:58:06 +0000 | [diff] [blame] | 2484 | } |
| 2485 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2486 | // Import the body, if any. |
| 2487 | if (Stmt *FromBody = D->getBody()) { |
| 2488 | if (Stmt *ToBody = Importer.Import(FromBody)) { |
| 2489 | ToFunction->setBody(ToBody); |
| 2490 | } |
| 2491 | } |
| 2492 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2493 | // FIXME: Other bits to merge? |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2494 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2495 | // If it is a template, import all related things. |
| 2496 | if (ImportTemplateInformation(D, ToFunction)) |
| 2497 | return nullptr; |
| 2498 | |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2499 | // Add this function to the lexical context. |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2500 | // NOTE: If the function is templated declaration, it should be not added into |
| 2501 | // LexicalDC. But described template is imported during import of |
| 2502 | // FunctionTemplateDecl (it happens later). So, we use source declaration |
| 2503 | // to determine if we should add the result function. |
| 2504 | if (!D->getDescribedFunctionTemplate()) |
| 2505 | LexicalDC->addDeclInternal(ToFunction); |
Douglas Gregor | 0eaa2bf | 2010-10-01 23:55:07 +0000 | [diff] [blame] | 2506 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 2507 | if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D)) |
| 2508 | ImportOverrides(cast<CXXMethodDecl>(ToFunction), FromCXXMethod); |
| 2509 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 2510 | return ToFunction; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2511 | } |
| 2512 | |
Douglas Gregor | 00eace1 | 2010-02-21 18:29:16 +0000 | [diff] [blame] | 2513 | Decl *ASTNodeImporter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
| 2514 | return VisitFunctionDecl(D); |
| 2515 | } |
| 2516 | |
| 2517 | Decl *ASTNodeImporter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
| 2518 | return VisitCXXMethodDecl(D); |
| 2519 | } |
| 2520 | |
| 2521 | Decl *ASTNodeImporter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
| 2522 | return VisitCXXMethodDecl(D); |
| 2523 | } |
| 2524 | |
| 2525 | Decl *ASTNodeImporter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
| 2526 | return VisitCXXMethodDecl(D); |
| 2527 | } |
| 2528 | |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2529 | static unsigned getFieldIndex(Decl *F) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2530 | auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext()); |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2531 | if (!Owner) |
| 2532 | return 0; |
| 2533 | |
| 2534 | unsigned Index = 1; |
Aaron Ballman | 629afae | 2014-03-07 19:56:05 +0000 | [diff] [blame] | 2535 | for (const auto *D : Owner->noload_decls()) { |
| 2536 | if (D == F) |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2537 | return Index; |
| 2538 | |
| 2539 | if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D)) |
| 2540 | ++Index; |
| 2541 | } |
| 2542 | |
| 2543 | return Index; |
| 2544 | } |
| 2545 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2546 | Decl *ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { |
| 2547 | // Import the major distinguishing characteristics of a variable. |
| 2548 | DeclContext *DC, *LexicalDC; |
| 2549 | DeclarationName Name; |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2550 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2551 | NamedDecl *ToD; |
| 2552 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2553 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2554 | if (ToD) |
| 2555 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2556 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2557 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2558 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2559 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2560 | for (auto *FoundDecl : FoundDecls) { |
| 2561 | if (auto *FoundField = dyn_cast<FieldDecl>(FoundDecl)) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2562 | // For anonymous fields, match up by index. |
| 2563 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2564 | continue; |
| 2565 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2566 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2567 | FoundField->getType())) { |
| 2568 | Importer.Imported(D, FoundField); |
| 2569 | return FoundField; |
| 2570 | } |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2571 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2572 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2573 | << Name << D->getType() << FoundField->getType(); |
| 2574 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2575 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2576 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2577 | } |
| 2578 | } |
| 2579 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2580 | // Import the type. |
| 2581 | QualType T = Importer.Import(D->getType()); |
| 2582 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2583 | return nullptr; |
| 2584 | |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2585 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2586 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 2587 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2588 | return nullptr; |
| 2589 | |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2590 | FieldDecl *ToField = FieldDecl::Create(Importer.getToContext(), DC, |
| 2591 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2592 | Loc, Name.getAsIdentifierInfo(), |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 2593 | T, TInfo, BitWidth, D->isMutable(), |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 2594 | D->getInClassInitStyle()); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2595 | ToField->setAccess(D->getAccess()); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2596 | ToField->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 3a83ea7 | 2016-03-03 02:22:05 +0000 | [diff] [blame] | 2597 | if (Expr *FromInitializer = D->getInClassInitializer()) { |
Sean Callanan | bb33f58 | 2016-03-03 01:21:28 +0000 | [diff] [blame] | 2598 | Expr *ToInitializer = Importer.Import(FromInitializer); |
| 2599 | if (ToInitializer) |
| 2600 | ToField->setInClassInitializer(ToInitializer); |
| 2601 | else |
| 2602 | return nullptr; |
| 2603 | } |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2604 | ToField->setImplicit(D->isImplicit()); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2605 | Importer.Imported(D, ToField); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2606 | LexicalDC->addDeclInternal(ToField); |
Douglas Gregor | 5c73e91 | 2010-02-11 00:48:18 +0000 | [diff] [blame] | 2607 | return ToField; |
| 2608 | } |
| 2609 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2610 | Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
| 2611 | // Import the major distinguishing characteristics of a variable. |
| 2612 | DeclContext *DC, *LexicalDC; |
| 2613 | DeclarationName Name; |
| 2614 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2615 | NamedDecl *ToD; |
| 2616 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2617 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2618 | if (ToD) |
| 2619 | return ToD; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2620 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2621 | // Determine whether we've already imported this field. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2622 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2623 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Douglas Gregor | 9e0a5b3 | 2011-10-15 00:10:27 +0000 | [diff] [blame] | 2624 | for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2625 | if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) { |
Douglas Gregor | ceb32bf | 2012-10-26 16:45:11 +0000 | [diff] [blame] | 2626 | // For anonymous indirect fields, match up by index. |
| 2627 | if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) |
| 2628 | continue; |
| 2629 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2630 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2631 | FoundField->getType(), |
David Blaikie | 7d17010 | 2013-05-15 07:37:26 +0000 | [diff] [blame] | 2632 | !Name.isEmpty())) { |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2633 | Importer.Imported(D, FoundField); |
| 2634 | return FoundField; |
| 2635 | } |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 2636 | |
| 2637 | // If there are more anonymous fields to check, continue. |
| 2638 | if (!Name && I < N-1) |
| 2639 | continue; |
| 2640 | |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2641 | Importer.ToDiag(Loc, diag::err_odr_field_type_inconsistent) |
| 2642 | << Name << D->getType() << FoundField->getType(); |
| 2643 | Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here) |
| 2644 | << FoundField->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2645 | return nullptr; |
Douglas Gregor | 03d1ed3 | 2011-10-14 21:54:42 +0000 | [diff] [blame] | 2646 | } |
| 2647 | } |
| 2648 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2649 | // Import the type. |
| 2650 | QualType T = Importer.Import(D->getType()); |
| 2651 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2652 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2653 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2654 | auto **NamedChain = |
| 2655 | new (Importer.getToContext()) NamedDecl*[D->getChainingSize()]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2656 | |
| 2657 | unsigned i = 0; |
Aaron Ballman | 29c9460 | 2014-03-07 18:36:15 +0000 | [diff] [blame] | 2658 | for (auto *PI : D->chain()) { |
Aaron Ballman | 1391608 | 2014-03-07 18:11:58 +0000 | [diff] [blame] | 2659 | Decl *D = Importer.Import(PI); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2660 | if (!D) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2661 | return nullptr; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2662 | NamedChain[i++] = cast<NamedDecl>(D); |
| 2663 | } |
| 2664 | |
| 2665 | IndirectFieldDecl *ToIndirectField = IndirectFieldDecl::Create( |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2666 | Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T, |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 2667 | {NamedChain, D->getChainingSize()}); |
Aaron Ballman | 260995b | 2014-10-15 16:58:18 +0000 | [diff] [blame] | 2668 | |
| 2669 | for (const auto *Attr : D->attrs()) |
| 2670 | ToIndirectField->addAttr(Attr->clone(Importer.getToContext())); |
| 2671 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2672 | ToIndirectField->setAccess(D->getAccess()); |
| 2673 | ToIndirectField->setLexicalDeclContext(LexicalDC); |
| 2674 | Importer.Imported(D, ToIndirectField); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2675 | LexicalDC->addDeclInternal(ToIndirectField); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 2676 | return ToIndirectField; |
| 2677 | } |
| 2678 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2679 | Decl *ASTNodeImporter::VisitFriendDecl(FriendDecl *D) { |
| 2680 | // Import the major distinguishing characteristics of a declaration. |
| 2681 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 2682 | DeclContext *LexicalDC = D->getDeclContext() == D->getLexicalDeclContext() |
| 2683 | ? DC : Importer.ImportContext(D->getLexicalDeclContext()); |
| 2684 | if (!DC || !LexicalDC) |
| 2685 | return nullptr; |
| 2686 | |
| 2687 | // Determine whether we've already imported this decl. |
| 2688 | // FriendDecl is not a NamedDecl so we cannot use localUncachedLookup. |
| 2689 | auto *RD = cast<CXXRecordDecl>(DC); |
| 2690 | FriendDecl *ImportedFriend = RD->getFirstFriend(); |
| 2691 | StructuralEquivalenceContext Context( |
| 2692 | Importer.getFromContext(), Importer.getToContext(), |
| 2693 | Importer.getNonEquivalentDecls(), false, false); |
| 2694 | |
| 2695 | while (ImportedFriend) { |
| 2696 | if (D->getFriendDecl() && ImportedFriend->getFriendDecl()) { |
| 2697 | if (Context.IsStructurallyEquivalent(D->getFriendDecl(), |
| 2698 | ImportedFriend->getFriendDecl())) |
| 2699 | return Importer.Imported(D, ImportedFriend); |
| 2700 | |
| 2701 | } else if (D->getFriendType() && ImportedFriend->getFriendType()) { |
| 2702 | if (Importer.IsStructurallyEquivalent( |
| 2703 | D->getFriendType()->getType(), |
| 2704 | ImportedFriend->getFriendType()->getType(), true)) |
| 2705 | return Importer.Imported(D, ImportedFriend); |
| 2706 | } |
| 2707 | ImportedFriend = ImportedFriend->getNextFriend(); |
| 2708 | } |
| 2709 | |
| 2710 | // Not found. Create it. |
| 2711 | FriendDecl::FriendUnion ToFU; |
| 2712 | if (NamedDecl *FriendD = D->getFriendDecl()) |
| 2713 | ToFU = cast_or_null<NamedDecl>(Importer.Import(FriendD)); |
| 2714 | else |
| 2715 | ToFU = Importer.Import(D->getFriendType()); |
| 2716 | if (!ToFU) |
| 2717 | return nullptr; |
| 2718 | |
| 2719 | SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2720 | auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>(); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 2721 | for (unsigned I = 0; I < D->NumTPLists; I++) { |
| 2722 | TemplateParameterList *List = ImportTemplateParameterList(FromTPLists[I]); |
| 2723 | if (!List) |
| 2724 | return nullptr; |
| 2725 | ToTPLists[I] = List; |
| 2726 | } |
| 2727 | |
| 2728 | FriendDecl *FrD = FriendDecl::Create(Importer.getToContext(), DC, |
| 2729 | Importer.Import(D->getLocation()), |
| 2730 | ToFU, Importer.Import(D->getFriendLoc()), |
| 2731 | ToTPLists); |
| 2732 | |
| 2733 | Importer.Imported(D, FrD); |
| 2734 | RD->pushFriendDecl(FrD); |
| 2735 | |
| 2736 | FrD->setAccess(D->getAccess()); |
| 2737 | FrD->setLexicalDeclContext(LexicalDC); |
| 2738 | LexicalDC->addDeclInternal(FrD); |
| 2739 | return FrD; |
| 2740 | } |
| 2741 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2742 | Decl *ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
| 2743 | // Import the major distinguishing characteristics of an ivar. |
| 2744 | DeclContext *DC, *LexicalDC; |
| 2745 | DeclarationName Name; |
| 2746 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2747 | NamedDecl *ToD; |
| 2748 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2749 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2750 | if (ToD) |
| 2751 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2752 | |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2753 | // Determine whether we've already imported this ivar |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2754 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2755 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2756 | for (auto *FoundDecl : FoundDecls) { |
| 2757 | if (auto *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2758 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2759 | FoundIvar->getType())) { |
| 2760 | Importer.Imported(D, FoundIvar); |
| 2761 | return FoundIvar; |
| 2762 | } |
| 2763 | |
| 2764 | Importer.ToDiag(Loc, diag::err_odr_ivar_type_inconsistent) |
| 2765 | << Name << D->getType() << FoundIvar->getType(); |
| 2766 | Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here) |
| 2767 | << FoundIvar->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2768 | return nullptr; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2769 | } |
| 2770 | } |
| 2771 | |
| 2772 | // Import the type. |
| 2773 | QualType T = Importer.Import(D->getType()); |
| 2774 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2775 | return nullptr; |
| 2776 | |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2777 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2778 | Expr *BitWidth = Importer.Import(D->getBitWidth()); |
| 2779 | if (!BitWidth && D->getBitWidth()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2780 | return nullptr; |
| 2781 | |
Daniel Dunbar | fe3ead7 | 2010-04-02 20:10:03 +0000 | [diff] [blame] | 2782 | ObjCIvarDecl *ToIvar = ObjCIvarDecl::Create(Importer.getToContext(), |
| 2783 | cast<ObjCContainerDecl>(DC), |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2784 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2785 | Loc, Name.getAsIdentifierInfo(), |
| 2786 | T, TInfo, D->getAccessControl(), |
Argyrios Kyrtzidis | 2080d90 | 2014-01-03 18:32:18 +0000 | [diff] [blame] | 2787 | BitWidth, D->getSynthesize()); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2788 | ToIvar->setLexicalDeclContext(LexicalDC); |
| 2789 | Importer.Imported(D, ToIvar); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 2790 | LexicalDC->addDeclInternal(ToIvar); |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2791 | return ToIvar; |
Douglas Gregor | 7244b0b | 2010-02-17 00:34:30 +0000 | [diff] [blame] | 2792 | } |
| 2793 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2794 | Decl *ASTNodeImporter::VisitVarDecl(VarDecl *D) { |
| 2795 | // Import the major distinguishing characteristics of a variable. |
| 2796 | DeclContext *DC, *LexicalDC; |
| 2797 | DeclarationName Name; |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2798 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2799 | NamedDecl *ToD; |
| 2800 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2801 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2802 | if (ToD) |
| 2803 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2804 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2805 | // Try to find a variable in our own ("to") context with the same name and |
| 2806 | // in the same context as the variable we're importing. |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2807 | if (D->isFileVarDecl()) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2808 | VarDecl *MergeWithVar = nullptr; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2809 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2810 | unsigned IDNS = Decl::IDNS_Ordinary; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2811 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 2812 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2813 | for (auto *FoundDecl : FoundDecls) { |
| 2814 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2815 | continue; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2816 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2817 | if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2818 | // 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] | 2819 | if (FoundVar->hasExternalFormalLinkage() && |
| 2820 | D->hasExternalFormalLinkage()) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 2821 | if (Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2822 | FoundVar->getType())) { |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2823 | MergeWithVar = FoundVar; |
| 2824 | break; |
| 2825 | } |
| 2826 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2827 | const ArrayType *FoundArray |
| 2828 | = Importer.getToContext().getAsArrayType(FoundVar->getType()); |
| 2829 | const ArrayType *TArray |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2830 | = Importer.getToContext().getAsArrayType(D->getType()); |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2831 | if (FoundArray && TArray) { |
| 2832 | if (isa<IncompleteArrayType>(FoundArray) && |
| 2833 | isa<ConstantArrayType>(TArray)) { |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2834 | // Import the type. |
| 2835 | QualType T = Importer.Import(D->getType()); |
| 2836 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2837 | return nullptr; |
| 2838 | |
Douglas Gregor | 56521c5 | 2010-02-12 17:23:39 +0000 | [diff] [blame] | 2839 | FoundVar->setType(T); |
| 2840 | MergeWithVar = FoundVar; |
| 2841 | break; |
| 2842 | } else if (isa<IncompleteArrayType>(TArray) && |
| 2843 | isa<ConstantArrayType>(FoundArray)) { |
| 2844 | MergeWithVar = FoundVar; |
| 2845 | break; |
Douglas Gregor | 2fbe558 | 2010-02-10 17:16:49 +0000 | [diff] [blame] | 2846 | } |
| 2847 | } |
| 2848 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2849 | Importer.ToDiag(Loc, diag::err_odr_variable_type_inconsistent) |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2850 | << Name << D->getType() << FoundVar->getType(); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2851 | Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here) |
| 2852 | << FoundVar->getType(); |
| 2853 | } |
| 2854 | } |
| 2855 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 2856 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2857 | } |
| 2858 | |
| 2859 | if (MergeWithVar) { |
| 2860 | // An equivalent variable with external linkage has been found. Link |
| 2861 | // the two declarations, then merge them. |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2862 | Importer.Imported(D, MergeWithVar); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2863 | |
| 2864 | if (VarDecl *DDef = D->getDefinition()) { |
| 2865 | if (VarDecl *ExistingDef = MergeWithVar->getDefinition()) { |
| 2866 | Importer.ToDiag(ExistingDef->getLocation(), |
| 2867 | diag::err_odr_variable_multiple_def) |
| 2868 | << Name; |
| 2869 | Importer.FromDiag(DDef->getLocation(), diag::note_odr_defined_here); |
| 2870 | } else { |
| 2871 | Expr *Init = Importer.Import(DDef->getInit()); |
Douglas Gregor | d505812 | 2010-02-11 01:19:42 +0000 | [diff] [blame] | 2872 | MergeWithVar->setInit(Init); |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 2873 | if (DDef->isInitKnownICE()) { |
| 2874 | EvaluatedStmt *Eval = MergeWithVar->ensureEvaluatedStmt(); |
| 2875 | Eval->CheckedICE = true; |
| 2876 | Eval->IsICE = DDef->isInitICE(); |
| 2877 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2878 | } |
| 2879 | } |
| 2880 | |
| 2881 | return MergeWithVar; |
| 2882 | } |
| 2883 | |
| 2884 | if (!ConflictingDecls.empty()) { |
| 2885 | Name = Importer.HandleNameConflict(Name, DC, IDNS, |
| 2886 | ConflictingDecls.data(), |
| 2887 | ConflictingDecls.size()); |
| 2888 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2889 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2890 | } |
| 2891 | } |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2892 | |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 2893 | // Import the type. |
| 2894 | QualType T = Importer.Import(D->getType()); |
| 2895 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2896 | return nullptr; |
| 2897 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2898 | // Create the imported variable. |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2899 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2900 | VarDecl *ToVar = VarDecl::Create(Importer.getToContext(), DC, |
| 2901 | Importer.Import(D->getInnerLocStart()), |
| 2902 | Loc, Name.getAsIdentifierInfo(), |
| 2903 | T, TInfo, |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 2904 | D->getStorageClass()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 2905 | ToVar->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Douglas Gregor | dd48317 | 2010-02-22 17:42:47 +0000 | [diff] [blame] | 2906 | ToVar->setAccess(D->getAccess()); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2907 | ToVar->setLexicalDeclContext(LexicalDC); |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 2908 | Importer.Imported(D, ToVar); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 2909 | |
| 2910 | // Templated declarations should never appear in the enclosing DeclContext. |
| 2911 | if (!D->getDescribedVarTemplate()) |
| 2912 | LexicalDC->addDeclInternal(ToVar); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 2913 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2914 | if (!D->isFileVarDecl() && |
| 2915 | D->isUsed()) |
| 2916 | ToVar->setIsUsed(); |
| 2917 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2918 | // Merge the initializer. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2919 | if (ImportDefinition(D, ToVar)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2920 | return nullptr; |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2921 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 2922 | if (D->isConstexpr()) |
| 2923 | ToVar->setConstexpr(true); |
| 2924 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 2925 | return ToVar; |
| 2926 | } |
| 2927 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2928 | Decl *ASTNodeImporter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
| 2929 | // Parameters are created in the translation unit's context, then moved |
| 2930 | // into the function declaration's context afterward. |
| 2931 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 2932 | |
| 2933 | // Import the name of this declaration. |
| 2934 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 2935 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2936 | return nullptr; |
| 2937 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2938 | // Import the location of this declaration. |
| 2939 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 2940 | |
| 2941 | // Import the parameter's type. |
| 2942 | QualType T = Importer.Import(D->getType()); |
| 2943 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2944 | return nullptr; |
| 2945 | |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2946 | // Create the imported parameter. |
Alexey Bataev | 5622323 | 2017-06-09 13:40:18 +0000 | [diff] [blame] | 2947 | auto *ToParm = ImplicitParamDecl::Create(Importer.getToContext(), DC, Loc, |
| 2948 | Name.getAsIdentifierInfo(), T, |
| 2949 | D->getParameterKind()); |
Douglas Gregor | 8b228d7 | 2010-02-17 21:22:52 +0000 | [diff] [blame] | 2950 | return Importer.Imported(D, ToParm); |
| 2951 | } |
| 2952 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2953 | Decl *ASTNodeImporter::VisitParmVarDecl(ParmVarDecl *D) { |
| 2954 | // Parameters are created in the translation unit's context, then moved |
| 2955 | // into the function declaration's context afterward. |
| 2956 | DeclContext *DC = Importer.getToContext().getTranslationUnitDecl(); |
| 2957 | |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 2958 | // Import the name of this declaration. |
| 2959 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 2960 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2961 | return nullptr; |
| 2962 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2963 | // Import the location of this declaration. |
| 2964 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 2965 | |
| 2966 | // Import the parameter's type. |
| 2967 | QualType T = Importer.Import(D->getType()); |
| 2968 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 2969 | return nullptr; |
| 2970 | |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2971 | // Create the imported parameter. |
| 2972 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 2973 | ParmVarDecl *ToParm = ParmVarDecl::Create(Importer.getToContext(), DC, |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 2974 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 2975 | Loc, Name.getAsIdentifierInfo(), |
| 2976 | T, TInfo, D->getStorageClass(), |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 2977 | /*DefaultArg*/ nullptr); |
| 2978 | |
| 2979 | // Set the default argument. |
John McCall | f3cd665 | 2010-03-12 18:31:32 +0000 | [diff] [blame] | 2980 | ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg()); |
Aleksei Sidorin | 55a6350 | 2017-02-20 11:57:12 +0000 | [diff] [blame] | 2981 | ToParm->setKNRPromoted(D->isKNRPromoted()); |
| 2982 | |
| 2983 | Expr *ToDefArg = nullptr; |
| 2984 | Expr *FromDefArg = nullptr; |
| 2985 | if (D->hasUninstantiatedDefaultArg()) { |
| 2986 | FromDefArg = D->getUninstantiatedDefaultArg(); |
| 2987 | ToDefArg = Importer.Import(FromDefArg); |
| 2988 | ToParm->setUninstantiatedDefaultArg(ToDefArg); |
| 2989 | } else if (D->hasUnparsedDefaultArg()) { |
| 2990 | ToParm->setUnparsedDefaultArg(); |
| 2991 | } else if (D->hasDefaultArg()) { |
| 2992 | FromDefArg = D->getDefaultArg(); |
| 2993 | ToDefArg = Importer.Import(FromDefArg); |
| 2994 | ToParm->setDefaultArg(ToDefArg); |
| 2995 | } |
| 2996 | if (FromDefArg && !ToDefArg) |
| 2997 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 2998 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 2999 | if (D->isObjCMethodParameter()) { |
| 3000 | ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex()); |
| 3001 | ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier()); |
| 3002 | } else { |
| 3003 | ToParm->setScopeInfo(D->getFunctionScopeDepth(), |
| 3004 | D->getFunctionScopeIndex()); |
| 3005 | } |
| 3006 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3007 | if (D->isUsed()) |
| 3008 | ToParm->setIsUsed(); |
| 3009 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 3010 | return Importer.Imported(D, ToParm); |
Douglas Gregor | bb7930c | 2010-02-10 19:54:31 +0000 | [diff] [blame] | 3011 | } |
| 3012 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3013 | Decl *ASTNodeImporter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
| 3014 | // Import the major distinguishing characteristics of a method. |
| 3015 | DeclContext *DC, *LexicalDC; |
| 3016 | DeclarationName Name; |
| 3017 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3018 | NamedDecl *ToD; |
| 3019 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3020 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3021 | if (ToD) |
| 3022 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3023 | |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3024 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3025 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3026 | for (auto *FoundDecl : FoundDecls) { |
| 3027 | if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3028 | if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) |
| 3029 | continue; |
| 3030 | |
| 3031 | // Check return types. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3032 | if (!Importer.IsStructurallyEquivalent(D->getReturnType(), |
| 3033 | FoundMethod->getReturnType())) { |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3034 | Importer.ToDiag(Loc, diag::err_odr_objc_method_result_type_inconsistent) |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3035 | << D->isInstanceMethod() << Name << D->getReturnType() |
| 3036 | << FoundMethod->getReturnType(); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3037 | Importer.ToDiag(FoundMethod->getLocation(), |
| 3038 | diag::note_odr_objc_method_here) |
| 3039 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3040 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | // Check the number of parameters. |
| 3044 | if (D->param_size() != FoundMethod->param_size()) { |
| 3045 | Importer.ToDiag(Loc, diag::err_odr_objc_method_num_params_inconsistent) |
| 3046 | << D->isInstanceMethod() << Name |
| 3047 | << D->param_size() << FoundMethod->param_size(); |
| 3048 | Importer.ToDiag(FoundMethod->getLocation(), |
| 3049 | diag::note_odr_objc_method_here) |
| 3050 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3051 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3052 | } |
| 3053 | |
| 3054 | // Check parameter types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3055 | for (ObjCMethodDecl::param_iterator P = D->param_begin(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3056 | PEnd = D->param_end(), FoundP = FoundMethod->param_begin(); |
| 3057 | P != PEnd; ++P, ++FoundP) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3058 | if (!Importer.IsStructurallyEquivalent((*P)->getType(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3059 | (*FoundP)->getType())) { |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3060 | Importer.FromDiag((*P)->getLocation(), |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3061 | diag::err_odr_objc_method_param_type_inconsistent) |
| 3062 | << D->isInstanceMethod() << Name |
| 3063 | << (*P)->getType() << (*FoundP)->getType(); |
| 3064 | Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here) |
| 3065 | << (*FoundP)->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3066 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3067 | } |
| 3068 | } |
| 3069 | |
| 3070 | // Check variadic/non-variadic. |
| 3071 | // Check the number of parameters. |
| 3072 | if (D->isVariadic() != FoundMethod->isVariadic()) { |
| 3073 | Importer.ToDiag(Loc, diag::err_odr_objc_method_variadic_inconsistent) |
| 3074 | << D->isInstanceMethod() << Name; |
| 3075 | Importer.ToDiag(FoundMethod->getLocation(), |
| 3076 | diag::note_odr_objc_method_here) |
| 3077 | << D->isInstanceMethod() << Name; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3078 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3079 | } |
| 3080 | |
| 3081 | // FIXME: Any other bits we need to merge? |
| 3082 | return Importer.Imported(D, FoundMethod); |
| 3083 | } |
| 3084 | } |
| 3085 | |
| 3086 | // Import the result type. |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3087 | QualType ResultTy = Importer.Import(D->getReturnType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3088 | if (ResultTy.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3089 | return nullptr; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3090 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3091 | TypeSourceInfo *ReturnTInfo = Importer.Import(D->getReturnTypeSourceInfo()); |
Douglas Gregor | 12852d9 | 2010-03-08 14:59:44 +0000 | [diff] [blame] | 3092 | |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 3093 | ObjCMethodDecl *ToMethod = ObjCMethodDecl::Create( |
| 3094 | Importer.getToContext(), Loc, Importer.Import(D->getLocEnd()), |
| 3095 | Name.getObjCSelector(), ResultTy, ReturnTInfo, DC, D->isInstanceMethod(), |
| 3096 | D->isVariadic(), D->isPropertyAccessor(), D->isImplicit(), D->isDefined(), |
| 3097 | D->getImplementationControl(), D->hasRelatedResultType()); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3098 | |
| 3099 | // FIXME: When we decide to merge method definitions, we'll need to |
| 3100 | // deal with implicit parameters. |
| 3101 | |
| 3102 | // Import the parameters |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3103 | SmallVector<ParmVarDecl *, 5> ToParams; |
David Majnemer | 59f7792 | 2016-06-24 04:05:48 +0000 | [diff] [blame] | 3104 | for (auto *FromP : D->parameters()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3105 | auto *ToP = cast_or_null<ParmVarDecl>(Importer.Import(FromP)); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3106 | if (!ToP) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3107 | return nullptr; |
| 3108 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3109 | ToParams.push_back(ToP); |
| 3110 | } |
| 3111 | |
| 3112 | // Set the parameters. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3113 | for (auto *ToParam : ToParams) { |
| 3114 | ToParam->setOwningFunction(ToMethod); |
| 3115 | ToMethod->addDeclInternal(ToParam); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3116 | } |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3117 | |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 3118 | SmallVector<SourceLocation, 12> SelLocs; |
| 3119 | D->getSelectorLocs(SelLocs); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3120 | for (auto &Loc : SelLocs) |
Aleksei Sidorin | 47dbaf6 | 2018-01-09 14:25:05 +0000 | [diff] [blame] | 3121 | Loc = Importer.Import(Loc); |
| 3122 | |
| 3123 | ToMethod->setMethodParams(Importer.getToContext(), ToParams, SelLocs); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3124 | |
| 3125 | ToMethod->setLexicalDeclContext(LexicalDC); |
| 3126 | Importer.Imported(D, ToMethod); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3127 | LexicalDC->addDeclInternal(ToMethod); |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 3128 | return ToMethod; |
| 3129 | } |
| 3130 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3131 | Decl *ASTNodeImporter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
| 3132 | // Import the major distinguishing characteristics of a category. |
| 3133 | DeclContext *DC, *LexicalDC; |
| 3134 | DeclarationName Name; |
| 3135 | SourceLocation Loc; |
| 3136 | NamedDecl *ToD; |
| 3137 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3138 | return nullptr; |
| 3139 | if (ToD) |
| 3140 | return ToD; |
| 3141 | |
| 3142 | TypeSourceInfo *BoundInfo = Importer.Import(D->getTypeSourceInfo()); |
| 3143 | if (!BoundInfo) |
| 3144 | return nullptr; |
| 3145 | |
| 3146 | ObjCTypeParamDecl *Result = ObjCTypeParamDecl::Create( |
| 3147 | Importer.getToContext(), DC, |
Douglas Gregor | 1ac1b63 | 2015-07-07 03:58:54 +0000 | [diff] [blame] | 3148 | D->getVariance(), |
| 3149 | Importer.Import(D->getVarianceLoc()), |
Douglas Gregor | e83b956 | 2015-07-07 03:57:53 +0000 | [diff] [blame] | 3150 | D->getIndex(), |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3151 | Importer.Import(D->getLocation()), |
| 3152 | Name.getAsIdentifierInfo(), |
| 3153 | Importer.Import(D->getColonLoc()), |
| 3154 | BoundInfo); |
| 3155 | Importer.Imported(D, Result); |
| 3156 | Result->setLexicalDeclContext(LexicalDC); |
| 3157 | return Result; |
| 3158 | } |
| 3159 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3160 | Decl *ASTNodeImporter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
| 3161 | // Import the major distinguishing characteristics of a category. |
| 3162 | DeclContext *DC, *LexicalDC; |
| 3163 | DeclarationName Name; |
| 3164 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3165 | NamedDecl *ToD; |
| 3166 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3167 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3168 | if (ToD) |
| 3169 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3170 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3171 | auto *ToInterface = |
| 3172 | cast_or_null<ObjCInterfaceDecl>(Importer.Import(D->getClassInterface())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3173 | if (!ToInterface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3174 | return nullptr; |
| 3175 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3176 | // Determine if we've already encountered this category. |
| 3177 | ObjCCategoryDecl *MergeWithCategory |
| 3178 | = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); |
| 3179 | ObjCCategoryDecl *ToCategory = MergeWithCategory; |
| 3180 | if (!ToCategory) { |
| 3181 | ToCategory = ObjCCategoryDecl::Create(Importer.getToContext(), DC, |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3182 | Importer.Import(D->getAtStartLoc()), |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3183 | Loc, |
| 3184 | Importer.Import(D->getCategoryNameLoc()), |
Argyrios Kyrtzidis | 3a5094b | 2011-08-30 19:43:26 +0000 | [diff] [blame] | 3185 | Name.getAsIdentifierInfo(), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3186 | ToInterface, |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3187 | /*TypeParamList=*/nullptr, |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3188 | Importer.Import(D->getIvarLBraceLoc()), |
| 3189 | Importer.Import(D->getIvarRBraceLoc())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3190 | ToCategory->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3191 | LexicalDC->addDeclInternal(ToCategory); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3192 | Importer.Imported(D, ToCategory); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3193 | // Import the type parameter list after calling Imported, to avoid |
| 3194 | // loops when bringing in their DeclContext. |
| 3195 | ToCategory->setTypeParamList(ImportObjCTypeParamList( |
| 3196 | D->getTypeParamList())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3197 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3198 | // Import protocols |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3199 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3200 | SmallVector<SourceLocation, 4> ProtocolLocs; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3201 | ObjCCategoryDecl::protocol_loc_iterator FromProtoLoc |
| 3202 | = D->protocol_loc_begin(); |
| 3203 | for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(), |
| 3204 | FromProtoEnd = D->protocol_end(); |
| 3205 | FromProto != FromProtoEnd; |
| 3206 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3207 | auto *ToProto = |
| 3208 | cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3209 | if (!ToProto) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3210 | return nullptr; |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3211 | Protocols.push_back(ToProto); |
| 3212 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3213 | } |
| 3214 | |
| 3215 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3216 | ToCategory->setProtocolList(Protocols.data(), Protocols.size(), |
| 3217 | ProtocolLocs.data(), Importer.getToContext()); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3218 | } else { |
| 3219 | Importer.Imported(D, ToCategory); |
| 3220 | } |
| 3221 | |
| 3222 | // Import all of the members of this category. |
Douglas Gregor | 968d633 | 2010-02-21 18:24:45 +0000 | [diff] [blame] | 3223 | ImportDeclContext(D); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3224 | |
| 3225 | // If we have an implementation, import it as well. |
| 3226 | if (D->getImplementation()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3227 | auto *Impl = |
| 3228 | cast_or_null<ObjCCategoryImplDecl>( |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3229 | Importer.Import(D->getImplementation())); |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3230 | if (!Impl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3231 | return nullptr; |
| 3232 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3233 | ToCategory->setImplementation(Impl); |
| 3234 | } |
| 3235 | |
| 3236 | return ToCategory; |
| 3237 | } |
| 3238 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3239 | bool ASTNodeImporter::ImportDefinition(ObjCProtocolDecl *From, |
| 3240 | ObjCProtocolDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3241 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3242 | if (To->getDefinition()) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3243 | if (shouldForceImportDeclContext(Kind)) |
| 3244 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3245 | return false; |
| 3246 | } |
| 3247 | |
| 3248 | // Start the protocol definition |
| 3249 | To->startDefinition(); |
| 3250 | |
| 3251 | // Import protocols |
| 3252 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3253 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 3254 | ObjCProtocolDecl::protocol_loc_iterator |
| 3255 | FromProtoLoc = From->protocol_loc_begin(); |
| 3256 | for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3257 | FromProtoEnd = From->protocol_end(); |
| 3258 | FromProto != FromProtoEnd; |
| 3259 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3260 | auto *ToProto = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3261 | if (!ToProto) |
| 3262 | return true; |
| 3263 | Protocols.push_back(ToProto); |
| 3264 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3265 | } |
| 3266 | |
| 3267 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3268 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3269 | ProtocolLocs.data(), Importer.getToContext()); |
| 3270 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3271 | if (shouldForceImportDeclContext(Kind)) { |
| 3272 | // Import all of the members of this protocol. |
| 3273 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3274 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3275 | return false; |
| 3276 | } |
| 3277 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3278 | Decl *ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3279 | // If this protocol has a definition in the translation unit we're coming |
| 3280 | // from, but this particular declaration is not that definition, import the |
| 3281 | // definition and map to that. |
| 3282 | ObjCProtocolDecl *Definition = D->getDefinition(); |
| 3283 | if (Definition && Definition != D) { |
| 3284 | Decl *ImportedDef = Importer.Import(Definition); |
| 3285 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3286 | return nullptr; |
| 3287 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3288 | return Importer.Imported(D, ImportedDef); |
| 3289 | } |
| 3290 | |
Douglas Gregor | 84c51c3 | 2010-02-18 01:47:50 +0000 | [diff] [blame] | 3291 | // Import the major distinguishing characteristics of a protocol. |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3292 | DeclContext *DC, *LexicalDC; |
| 3293 | DeclarationName Name; |
| 3294 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3295 | NamedDecl *ToD; |
| 3296 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3297 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3298 | if (ToD) |
| 3299 | return ToD; |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3300 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3301 | ObjCProtocolDecl *MergeWithProtocol = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3302 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3303 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3304 | for (auto *FoundDecl : FoundDecls) { |
| 3305 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_ObjCProtocol)) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3306 | continue; |
| 3307 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3308 | if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl))) |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3309 | break; |
| 3310 | } |
| 3311 | |
| 3312 | ObjCProtocolDecl *ToProto = MergeWithProtocol; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3313 | if (!ToProto) { |
| 3314 | ToProto = ObjCProtocolDecl::Create(Importer.getToContext(), DC, |
| 3315 | Name.getAsIdentifierInfo(), Loc, |
| 3316 | Importer.Import(D->getAtStartLoc()), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3317 | /*PrevDecl=*/nullptr); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3318 | ToProto->setLexicalDeclContext(LexicalDC); |
| 3319 | LexicalDC->addDeclInternal(ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3320 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3321 | |
| 3322 | Importer.Imported(D, ToProto); |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3323 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3324 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToProto)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3325 | return nullptr; |
| 3326 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3327 | return ToProto; |
| 3328 | } |
| 3329 | |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3330 | Decl *ASTNodeImporter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 3331 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3332 | DeclContext *LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3333 | |
| 3334 | SourceLocation ExternLoc = Importer.Import(D->getExternLoc()); |
| 3335 | SourceLocation LangLoc = Importer.Import(D->getLocation()); |
| 3336 | |
| 3337 | bool HasBraces = D->hasBraces(); |
| 3338 | |
Sean Callanan | b12a855 | 2014-12-10 21:22:20 +0000 | [diff] [blame] | 3339 | LinkageSpecDecl *ToLinkageSpec = |
| 3340 | LinkageSpecDecl::Create(Importer.getToContext(), |
| 3341 | DC, |
| 3342 | ExternLoc, |
| 3343 | LangLoc, |
| 3344 | D->getLanguage(), |
| 3345 | HasBraces); |
Sean Callanan | 0aae041 | 2014-12-10 00:00:37 +0000 | [diff] [blame] | 3346 | |
| 3347 | if (HasBraces) { |
| 3348 | SourceLocation RBraceLoc = Importer.Import(D->getRBraceLoc()); |
| 3349 | ToLinkageSpec->setRBraceLoc(RBraceLoc); |
| 3350 | } |
| 3351 | |
| 3352 | ToLinkageSpec->setLexicalDeclContext(LexicalDC); |
| 3353 | LexicalDC->addDeclInternal(ToLinkageSpec); |
| 3354 | |
| 3355 | Importer.Imported(D, ToLinkageSpec); |
| 3356 | |
| 3357 | return ToLinkageSpec; |
| 3358 | } |
| 3359 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3360 | Decl *ASTNodeImporter::VisitUsingDecl(UsingDecl *D) { |
| 3361 | DeclContext *DC, *LexicalDC; |
| 3362 | DeclarationName Name; |
| 3363 | SourceLocation Loc; |
| 3364 | NamedDecl *ToD = nullptr; |
| 3365 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3366 | return nullptr; |
| 3367 | if (ToD) |
| 3368 | return ToD; |
| 3369 | |
| 3370 | DeclarationNameInfo NameInfo(Name, |
| 3371 | Importer.Import(D->getNameInfo().getLoc())); |
| 3372 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3373 | |
| 3374 | UsingDecl *ToUsing = UsingDecl::Create(Importer.getToContext(), DC, |
| 3375 | Importer.Import(D->getUsingLoc()), |
| 3376 | Importer.Import(D->getQualifierLoc()), |
| 3377 | NameInfo, D->hasTypename()); |
| 3378 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3379 | LexicalDC->addDeclInternal(ToUsing); |
| 3380 | Importer.Imported(D, ToUsing); |
| 3381 | |
| 3382 | if (NamedDecl *FromPattern = |
| 3383 | Importer.getFromContext().getInstantiatedFromUsingDecl(D)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3384 | if (auto *ToPattern = |
| 3385 | dyn_cast_or_null<NamedDecl>(Importer.Import(FromPattern))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3386 | Importer.getToContext().setInstantiatedFromUsingDecl(ToUsing, ToPattern); |
| 3387 | else |
| 3388 | return nullptr; |
| 3389 | } |
| 3390 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3391 | for (auto *FromShadow : D->shadows()) { |
| 3392 | if (auto *ToShadow = |
| 3393 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromShadow))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3394 | ToUsing->addShadowDecl(ToShadow); |
| 3395 | else |
| 3396 | // FIXME: We return a nullptr here but the definition is already created |
| 3397 | // and available with lookups. How to fix this?.. |
| 3398 | return nullptr; |
| 3399 | } |
| 3400 | return ToUsing; |
| 3401 | } |
| 3402 | |
| 3403 | Decl *ASTNodeImporter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
| 3404 | DeclContext *DC, *LexicalDC; |
| 3405 | DeclarationName Name; |
| 3406 | SourceLocation Loc; |
| 3407 | NamedDecl *ToD = nullptr; |
| 3408 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3409 | return nullptr; |
| 3410 | if (ToD) |
| 3411 | return ToD; |
| 3412 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3413 | auto *ToUsing = dyn_cast_or_null<UsingDecl>( |
| 3414 | Importer.Import(D->getUsingDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3415 | if (!ToUsing) |
| 3416 | return nullptr; |
| 3417 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3418 | auto *ToTarget = dyn_cast_or_null<NamedDecl>( |
| 3419 | Importer.Import(D->getTargetDecl())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3420 | if (!ToTarget) |
| 3421 | return nullptr; |
| 3422 | |
| 3423 | UsingShadowDecl *ToShadow = UsingShadowDecl::Create( |
| 3424 | Importer.getToContext(), DC, Loc, ToUsing, ToTarget); |
| 3425 | |
| 3426 | ToShadow->setLexicalDeclContext(LexicalDC); |
| 3427 | ToShadow->setAccess(D->getAccess()); |
| 3428 | Importer.Imported(D, ToShadow); |
| 3429 | |
| 3430 | if (UsingShadowDecl *FromPattern = |
| 3431 | Importer.getFromContext().getInstantiatedFromUsingShadowDecl(D)) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3432 | if (auto *ToPattern = |
| 3433 | dyn_cast_or_null<UsingShadowDecl>(Importer.Import(FromPattern))) |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3434 | Importer.getToContext().setInstantiatedFromUsingShadowDecl(ToShadow, |
| 3435 | ToPattern); |
| 3436 | else |
| 3437 | // FIXME: We return a nullptr here but the definition is already created |
| 3438 | // and available with lookups. How to fix this?.. |
| 3439 | return nullptr; |
| 3440 | } |
| 3441 | |
| 3442 | LexicalDC->addDeclInternal(ToShadow); |
| 3443 | |
| 3444 | return ToShadow; |
| 3445 | } |
| 3446 | |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3447 | Decl *ASTNodeImporter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 3448 | DeclContext *DC, *LexicalDC; |
| 3449 | DeclarationName Name; |
| 3450 | SourceLocation Loc; |
| 3451 | NamedDecl *ToD = nullptr; |
| 3452 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3453 | return nullptr; |
| 3454 | if (ToD) |
| 3455 | return ToD; |
| 3456 | |
| 3457 | DeclContext *ToComAncestor = Importer.ImportContext(D->getCommonAncestor()); |
| 3458 | if (!ToComAncestor) |
| 3459 | return nullptr; |
| 3460 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3461 | auto *ToNominated = cast_or_null<NamespaceDecl>( |
| 3462 | Importer.Import(D->getNominatedNamespace())); |
Aleksei Sidorin | 2697f8e | 2017-11-21 16:08:41 +0000 | [diff] [blame] | 3463 | if (!ToNominated) |
| 3464 | return nullptr; |
| 3465 | |
| 3466 | UsingDirectiveDecl *ToUsingDir = UsingDirectiveDecl::Create( |
| 3467 | Importer.getToContext(), DC, Importer.Import(D->getUsingLoc()), |
| 3468 | Importer.Import(D->getNamespaceKeyLocation()), |
| 3469 | Importer.Import(D->getQualifierLoc()), |
| 3470 | Importer.Import(D->getIdentLocation()), ToNominated, ToComAncestor); |
| 3471 | ToUsingDir->setLexicalDeclContext(LexicalDC); |
| 3472 | LexicalDC->addDeclInternal(ToUsingDir); |
| 3473 | Importer.Imported(D, ToUsingDir); |
| 3474 | |
| 3475 | return ToUsingDir; |
| 3476 | } |
| 3477 | |
| 3478 | Decl *ASTNodeImporter::VisitUnresolvedUsingValueDecl( |
| 3479 | UnresolvedUsingValueDecl *D) { |
| 3480 | DeclContext *DC, *LexicalDC; |
| 3481 | DeclarationName Name; |
| 3482 | SourceLocation Loc; |
| 3483 | NamedDecl *ToD = nullptr; |
| 3484 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3485 | return nullptr; |
| 3486 | if (ToD) |
| 3487 | return ToD; |
| 3488 | |
| 3489 | DeclarationNameInfo NameInfo(Name, Importer.Import(D->getNameInfo().getLoc())); |
| 3490 | ImportDeclarationNameLoc(D->getNameInfo(), NameInfo); |
| 3491 | |
| 3492 | UnresolvedUsingValueDecl *ToUsingValue = UnresolvedUsingValueDecl::Create( |
| 3493 | Importer.getToContext(), DC, Importer.Import(D->getUsingLoc()), |
| 3494 | Importer.Import(D->getQualifierLoc()), NameInfo, |
| 3495 | Importer.Import(D->getEllipsisLoc())); |
| 3496 | |
| 3497 | Importer.Imported(D, ToUsingValue); |
| 3498 | ToUsingValue->setAccess(D->getAccess()); |
| 3499 | ToUsingValue->setLexicalDeclContext(LexicalDC); |
| 3500 | LexicalDC->addDeclInternal(ToUsingValue); |
| 3501 | |
| 3502 | return ToUsingValue; |
| 3503 | } |
| 3504 | |
| 3505 | Decl *ASTNodeImporter::VisitUnresolvedUsingTypenameDecl( |
| 3506 | UnresolvedUsingTypenameDecl *D) { |
| 3507 | DeclContext *DC, *LexicalDC; |
| 3508 | DeclarationName Name; |
| 3509 | SourceLocation Loc; |
| 3510 | NamedDecl *ToD = nullptr; |
| 3511 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 3512 | return nullptr; |
| 3513 | if (ToD) |
| 3514 | return ToD; |
| 3515 | |
| 3516 | UnresolvedUsingTypenameDecl *ToUsing = UnresolvedUsingTypenameDecl::Create( |
| 3517 | Importer.getToContext(), DC, Importer.Import(D->getUsingLoc()), |
| 3518 | Importer.Import(D->getTypenameLoc()), |
| 3519 | Importer.Import(D->getQualifierLoc()), Loc, Name, |
| 3520 | Importer.Import(D->getEllipsisLoc())); |
| 3521 | |
| 3522 | Importer.Imported(D, ToUsing); |
| 3523 | ToUsing->setAccess(D->getAccess()); |
| 3524 | ToUsing->setLexicalDeclContext(LexicalDC); |
| 3525 | LexicalDC->addDeclInternal(ToUsing); |
| 3526 | |
| 3527 | return ToUsing; |
| 3528 | } |
| 3529 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3530 | bool ASTNodeImporter::ImportDefinition(ObjCInterfaceDecl *From, |
| 3531 | ObjCInterfaceDecl *To, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3532 | ImportDefinitionKind Kind) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3533 | if (To->getDefinition()) { |
| 3534 | // Check consistency of superclass. |
| 3535 | ObjCInterfaceDecl *FromSuper = From->getSuperClass(); |
| 3536 | if (FromSuper) { |
| 3537 | FromSuper = cast_or_null<ObjCInterfaceDecl>(Importer.Import(FromSuper)); |
| 3538 | if (!FromSuper) |
| 3539 | return true; |
| 3540 | } |
| 3541 | |
| 3542 | ObjCInterfaceDecl *ToSuper = To->getSuperClass(); |
| 3543 | if ((bool)FromSuper != (bool)ToSuper || |
| 3544 | (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) { |
| 3545 | Importer.ToDiag(To->getLocation(), |
| 3546 | diag::err_odr_objc_superclass_inconsistent) |
| 3547 | << To->getDeclName(); |
| 3548 | if (ToSuper) |
| 3549 | Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass) |
| 3550 | << To->getSuperClass()->getDeclName(); |
| 3551 | else |
| 3552 | Importer.ToDiag(To->getLocation(), |
| 3553 | diag::note_odr_objc_missing_superclass); |
| 3554 | if (From->getSuperClass()) |
| 3555 | Importer.FromDiag(From->getSuperClassLoc(), |
| 3556 | diag::note_odr_objc_superclass) |
| 3557 | << From->getSuperClass()->getDeclName(); |
| 3558 | else |
| 3559 | Importer.FromDiag(From->getLocation(), |
| 3560 | diag::note_odr_objc_missing_superclass); |
| 3561 | } |
| 3562 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3563 | if (shouldForceImportDeclContext(Kind)) |
| 3564 | ImportDeclContext(From); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3565 | return false; |
| 3566 | } |
| 3567 | |
| 3568 | // Start the definition. |
| 3569 | To->startDefinition(); |
| 3570 | |
| 3571 | // If this class has a superclass, import it. |
| 3572 | if (From->getSuperClass()) { |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3573 | TypeSourceInfo *SuperTInfo = Importer.Import(From->getSuperClassTInfo()); |
| 3574 | if (!SuperTInfo) |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3575 | return true; |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 3576 | |
| 3577 | To->setSuperClass(SuperTInfo); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3578 | } |
| 3579 | |
| 3580 | // Import protocols |
| 3581 | SmallVector<ObjCProtocolDecl *, 4> Protocols; |
| 3582 | SmallVector<SourceLocation, 4> ProtocolLocs; |
| 3583 | ObjCInterfaceDecl::protocol_loc_iterator |
| 3584 | FromProtoLoc = From->protocol_loc_begin(); |
| 3585 | |
| 3586 | for (ObjCInterfaceDecl::protocol_iterator FromProto = From->protocol_begin(), |
| 3587 | FromProtoEnd = From->protocol_end(); |
| 3588 | FromProto != FromProtoEnd; |
| 3589 | ++FromProto, ++FromProtoLoc) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3590 | auto *ToProto = cast_or_null<ObjCProtocolDecl>(Importer.Import(*FromProto)); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3591 | if (!ToProto) |
| 3592 | return true; |
| 3593 | Protocols.push_back(ToProto); |
| 3594 | ProtocolLocs.push_back(Importer.Import(*FromProtoLoc)); |
| 3595 | } |
| 3596 | |
| 3597 | // FIXME: If we're merging, make sure that the protocol list is the same. |
| 3598 | To->setProtocolList(Protocols.data(), Protocols.size(), |
| 3599 | ProtocolLocs.data(), Importer.getToContext()); |
| 3600 | |
| 3601 | // Import categories. When the categories themselves are imported, they'll |
| 3602 | // hook themselves into this interface. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 3603 | for (auto *Cat : From->known_categories()) |
| 3604 | Importer.Import(Cat); |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 3605 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3606 | // If we have an @implementation, import it as well. |
| 3607 | if (From->getImplementation()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3608 | auto *Impl = cast_or_null<ObjCImplementationDecl>( |
| 3609 | Importer.Import(From->getImplementation())); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3610 | if (!Impl) |
| 3611 | return true; |
| 3612 | |
| 3613 | To->setImplementation(Impl); |
| 3614 | } |
| 3615 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 3616 | if (shouldForceImportDeclContext(Kind)) { |
| 3617 | // Import all of the members of this class. |
| 3618 | ImportDeclContext(From, /*ForceImport=*/true); |
| 3619 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3620 | return false; |
| 3621 | } |
| 3622 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3623 | ObjCTypeParamList * |
| 3624 | ASTNodeImporter::ImportObjCTypeParamList(ObjCTypeParamList *list) { |
| 3625 | if (!list) |
| 3626 | return nullptr; |
| 3627 | |
| 3628 | SmallVector<ObjCTypeParamDecl *, 4> toTypeParams; |
| 3629 | for (auto fromTypeParam : *list) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3630 | auto *toTypeParam = cast_or_null<ObjCTypeParamDecl>( |
| 3631 | Importer.Import(fromTypeParam)); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3632 | if (!toTypeParam) |
| 3633 | return nullptr; |
| 3634 | |
| 3635 | toTypeParams.push_back(toTypeParam); |
| 3636 | } |
| 3637 | |
| 3638 | return ObjCTypeParamList::create(Importer.getToContext(), |
| 3639 | Importer.Import(list->getLAngleLoc()), |
| 3640 | toTypeParams, |
| 3641 | Importer.Import(list->getRAngleLoc())); |
| 3642 | } |
| 3643 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3644 | Decl *ASTNodeImporter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3645 | // If this class has a definition in the translation unit we're coming from, |
| 3646 | // but this particular declaration is not that definition, import the |
| 3647 | // definition and map to that. |
| 3648 | ObjCInterfaceDecl *Definition = D->getDefinition(); |
| 3649 | if (Definition && Definition != D) { |
| 3650 | Decl *ImportedDef = Importer.Import(Definition); |
| 3651 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3652 | return nullptr; |
| 3653 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3654 | return Importer.Imported(D, ImportedDef); |
| 3655 | } |
| 3656 | |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3657 | // Import the major distinguishing characteristics of an @interface. |
| 3658 | DeclContext *DC, *LexicalDC; |
| 3659 | DeclarationName Name; |
| 3660 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3661 | NamedDecl *ToD; |
| 3662 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3663 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3664 | if (ToD) |
| 3665 | return ToD; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3666 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3667 | // Look for an existing interface with the same name. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3668 | ObjCInterfaceDecl *MergeWithIface = nullptr; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3669 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3670 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3671 | for (auto *FoundDecl : FoundDecls) { |
| 3672 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3673 | continue; |
| 3674 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3675 | if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl))) |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3676 | break; |
| 3677 | } |
| 3678 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3679 | // Create an interface declaration, if one does not already exist. |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3680 | ObjCInterfaceDecl *ToIface = MergeWithIface; |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3681 | if (!ToIface) { |
| 3682 | ToIface = ObjCInterfaceDecl::Create(Importer.getToContext(), DC, |
| 3683 | Importer.Import(D->getAtStartLoc()), |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3684 | Name.getAsIdentifierInfo(), |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3685 | /*TypeParamList=*/nullptr, |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3686 | /*PrevDecl=*/nullptr, Loc, |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3687 | D->isImplicitInterfaceDecl()); |
| 3688 | ToIface->setLexicalDeclContext(LexicalDC); |
| 3689 | LexicalDC->addDeclInternal(ToIface); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3690 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3691 | Importer.Imported(D, ToIface); |
Douglas Gregor | ab7f0b3 | 2015-07-07 06:20:12 +0000 | [diff] [blame] | 3692 | // Import the type parameter list after calling Imported, to avoid |
| 3693 | // loops when bringing in their DeclContext. |
| 3694 | ToIface->setTypeParamList(ImportObjCTypeParamList( |
| 3695 | D->getTypeParamListAsWritten())); |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3696 | |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 3697 | if (D->isThisDeclarationADefinition() && ImportDefinition(D, ToIface)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3698 | return nullptr; |
| 3699 | |
Douglas Gregor | 98d156a | 2010-02-17 16:12:00 +0000 | [diff] [blame] | 3700 | return ToIface; |
Douglas Gregor | 4563532 | 2010-02-16 01:20:57 +0000 | [diff] [blame] | 3701 | } |
| 3702 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3703 | Decl *ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3704 | auto *Category = cast_or_null<ObjCCategoryDecl>( |
| 3705 | Importer.Import(D->getCategoryDecl())); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3706 | if (!Category) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3707 | return nullptr; |
| 3708 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3709 | ObjCCategoryImplDecl *ToImpl = Category->getImplementation(); |
| 3710 | if (!ToImpl) { |
| 3711 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3712 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3713 | return nullptr; |
| 3714 | |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 3715 | SourceLocation CategoryNameLoc = Importer.Import(D->getCategoryNameLoc()); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3716 | ToImpl = ObjCCategoryImplDecl::Create(Importer.getToContext(), DC, |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3717 | Importer.Import(D->getIdentifier()), |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3718 | Category->getClassInterface(), |
| 3719 | Importer.Import(D->getLocation()), |
Argyrios Kyrtzidis | 4996f5f | 2011-12-09 00:31:40 +0000 | [diff] [blame] | 3720 | Importer.Import(D->getAtStartLoc()), |
| 3721 | CategoryNameLoc); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3722 | |
| 3723 | DeclContext *LexicalDC = DC; |
| 3724 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3725 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3726 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3727 | return nullptr; |
| 3728 | |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3729 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 3730 | } |
| 3731 | |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3732 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3733 | Category->setImplementation(ToImpl); |
| 3734 | } |
| 3735 | |
| 3736 | Importer.Imported(D, ToImpl); |
Douglas Gregor | 35fd7bc | 2010-12-08 16:41:55 +0000 | [diff] [blame] | 3737 | ImportDeclContext(D); |
Douglas Gregor | 4da9d68 | 2010-12-07 15:32:12 +0000 | [diff] [blame] | 3738 | return ToImpl; |
| 3739 | } |
| 3740 | |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3741 | Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
| 3742 | // Find the corresponding interface. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3743 | auto *Iface = cast_or_null<ObjCInterfaceDecl>( |
| 3744 | Importer.Import(D->getClassInterface())); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3745 | if (!Iface) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3746 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3747 | |
| 3748 | // Import the superclass, if any. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3749 | ObjCInterfaceDecl *Super = nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3750 | if (D->getSuperClass()) { |
| 3751 | Super = cast_or_null<ObjCInterfaceDecl>( |
| 3752 | Importer.Import(D->getSuperClass())); |
| 3753 | if (!Super) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3754 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3755 | } |
| 3756 | |
| 3757 | ObjCImplementationDecl *Impl = Iface->getImplementation(); |
| 3758 | if (!Impl) { |
| 3759 | // We haven't imported an implementation yet. Create a new @implementation |
| 3760 | // now. |
| 3761 | Impl = ObjCImplementationDecl::Create(Importer.getToContext(), |
| 3762 | Importer.ImportContext(D->getDeclContext()), |
Argyrios Kyrtzidis | 52f53fb | 2011-10-04 04:48:02 +0000 | [diff] [blame] | 3763 | Iface, Super, |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3764 | Importer.Import(D->getLocation()), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3765 | Importer.Import(D->getAtStartLoc()), |
Argyrios Kyrtzidis | 5d2ce84 | 2013-05-03 22:31:26 +0000 | [diff] [blame] | 3766 | Importer.Import(D->getSuperClassLoc()), |
Fariborz Jahanian | a7765fe | 2012-02-20 20:09:20 +0000 | [diff] [blame] | 3767 | Importer.Import(D->getIvarLBraceLoc()), |
| 3768 | Importer.Import(D->getIvarRBraceLoc())); |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3769 | |
| 3770 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3771 | DeclContext *LexicalDC |
| 3772 | = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3773 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3774 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3775 | Impl->setLexicalDeclContext(LexicalDC); |
| 3776 | } |
| 3777 | |
| 3778 | // Associate the implementation with the class it implements. |
| 3779 | Iface->setImplementation(Impl); |
| 3780 | Importer.Imported(D, Iface->getImplementation()); |
| 3781 | } else { |
| 3782 | Importer.Imported(D, Iface->getImplementation()); |
| 3783 | |
| 3784 | // Verify that the existing @implementation has the same superclass. |
| 3785 | if ((Super && !Impl->getSuperClass()) || |
| 3786 | (!Super && Impl->getSuperClass()) || |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 3787 | (Super && Impl->getSuperClass() && |
| 3788 | !declaresSameEntity(Super->getCanonicalDecl(), |
| 3789 | Impl->getSuperClass()))) { |
| 3790 | Importer.ToDiag(Impl->getLocation(), |
| 3791 | diag::err_odr_objc_superclass_inconsistent) |
| 3792 | << Iface->getDeclName(); |
| 3793 | // FIXME: It would be nice to have the location of the superclass |
| 3794 | // below. |
| 3795 | if (Impl->getSuperClass()) |
| 3796 | Importer.ToDiag(Impl->getLocation(), |
| 3797 | diag::note_odr_objc_superclass) |
| 3798 | << Impl->getSuperClass()->getDeclName(); |
| 3799 | else |
| 3800 | Importer.ToDiag(Impl->getLocation(), |
| 3801 | diag::note_odr_objc_missing_superclass); |
| 3802 | if (D->getSuperClass()) |
| 3803 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3804 | diag::note_odr_objc_superclass) |
Craig Topper | dcfc60f | 2014-05-07 06:57:44 +0000 | [diff] [blame] | 3805 | << D->getSuperClass()->getDeclName(); |
| 3806 | else |
| 3807 | Importer.FromDiag(D->getLocation(), |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3808 | diag::note_odr_objc_missing_superclass); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3809 | return nullptr; |
Douglas Gregor | da8025c | 2010-12-07 01:26:03 +0000 | [diff] [blame] | 3810 | } |
| 3811 | } |
| 3812 | |
| 3813 | // Import all of the members of this @implementation. |
| 3814 | ImportDeclContext(D); |
| 3815 | |
| 3816 | return Impl; |
| 3817 | } |
| 3818 | |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3819 | Decl *ASTNodeImporter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
| 3820 | // Import the major distinguishing characteristics of an @property. |
| 3821 | DeclContext *DC, *LexicalDC; |
| 3822 | DeclarationName Name; |
| 3823 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3824 | NamedDecl *ToD; |
| 3825 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3826 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 3827 | if (ToD) |
| 3828 | return ToD; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3829 | |
| 3830 | // Check whether we have already imported this property. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3831 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 3832 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3833 | for (auto *FoundDecl : FoundDecls) { |
| 3834 | if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) { |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3835 | // Check property types. |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 3836 | if (!Importer.IsStructurallyEquivalent(D->getType(), |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3837 | FoundProp->getType())) { |
| 3838 | Importer.ToDiag(Loc, diag::err_odr_objc_property_type_inconsistent) |
| 3839 | << Name << D->getType() << FoundProp->getType(); |
| 3840 | Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here) |
| 3841 | << FoundProp->getType(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3842 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3843 | } |
| 3844 | |
| 3845 | // FIXME: Check property attributes, getters, setters, etc.? |
| 3846 | |
| 3847 | // Consider these properties to be equivalent. |
| 3848 | Importer.Imported(D, FoundProp); |
| 3849 | return FoundProp; |
| 3850 | } |
| 3851 | } |
| 3852 | |
| 3853 | // Import the type. |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 3854 | TypeSourceInfo *TSI = Importer.Import(D->getTypeSourceInfo()); |
| 3855 | if (!TSI) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3856 | return nullptr; |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3857 | |
| 3858 | // Create the new property. |
| 3859 | ObjCPropertyDecl *ToProperty |
| 3860 | = ObjCPropertyDecl::Create(Importer.getToContext(), DC, Loc, |
| 3861 | Name.getAsIdentifierInfo(), |
| 3862 | Importer.Import(D->getAtLoc()), |
Fariborz Jahanian | 86c2f5c | 2012-02-29 22:18:55 +0000 | [diff] [blame] | 3863 | Importer.Import(D->getLParenLoc()), |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 3864 | Importer.Import(D->getType()), |
| 3865 | TSI, |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3866 | D->getPropertyImplementation()); |
| 3867 | Importer.Imported(D, ToProperty); |
| 3868 | ToProperty->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3869 | LexicalDC->addDeclInternal(ToProperty); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3870 | |
| 3871 | ToProperty->setPropertyAttributes(D->getPropertyAttributes()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 3872 | ToProperty->setPropertyAttributesAsWritten( |
| 3873 | D->getPropertyAttributesAsWritten()); |
Argyrios Kyrtzidis | 194b28e | 2017-03-16 18:25:40 +0000 | [diff] [blame] | 3874 | ToProperty->setGetterName(Importer.Import(D->getGetterName()), |
| 3875 | Importer.Import(D->getGetterNameLoc())); |
| 3876 | ToProperty->setSetterName(Importer.Import(D->getSetterName()), |
| 3877 | Importer.Import(D->getSetterNameLoc())); |
Douglas Gregor | a11c458 | 2010-02-17 18:02:10 +0000 | [diff] [blame] | 3878 | ToProperty->setGetterMethodDecl( |
| 3879 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getGetterMethodDecl()))); |
| 3880 | ToProperty->setSetterMethodDecl( |
| 3881 | cast_or_null<ObjCMethodDecl>(Importer.Import(D->getSetterMethodDecl()))); |
| 3882 | ToProperty->setPropertyIvarDecl( |
| 3883 | cast_or_null<ObjCIvarDecl>(Importer.Import(D->getPropertyIvarDecl()))); |
| 3884 | return ToProperty; |
| 3885 | } |
| 3886 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3887 | Decl *ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3888 | auto *Property = cast_or_null<ObjCPropertyDecl>( |
| 3889 | Importer.Import(D->getPropertyDecl())); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3890 | if (!Property) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3891 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3892 | |
| 3893 | DeclContext *DC = Importer.ImportContext(D->getDeclContext()); |
| 3894 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3895 | return nullptr; |
| 3896 | |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3897 | // Import the lexical declaration context. |
| 3898 | DeclContext *LexicalDC = DC; |
| 3899 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 3900 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 3901 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3902 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3903 | } |
| 3904 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 3905 | auto *InImpl = dyn_cast<ObjCImplDecl>(LexicalDC); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3906 | if (!InImpl) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3907 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3908 | |
| 3909 | // Import the ivar (for an @synthesize). |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3910 | ObjCIvarDecl *Ivar = nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3911 | if (D->getPropertyIvarDecl()) { |
| 3912 | Ivar = cast_or_null<ObjCIvarDecl>( |
| 3913 | Importer.Import(D->getPropertyIvarDecl())); |
| 3914 | if (!Ivar) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3915 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3916 | } |
| 3917 | |
| 3918 | ObjCPropertyImplDecl *ToImpl |
Manman Ren | 5b78640 | 2016-01-28 18:49:28 +0000 | [diff] [blame] | 3919 | = InImpl->FindPropertyImplDecl(Property->getIdentifier(), |
| 3920 | Property->getQueryKind()); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3921 | if (!ToImpl) { |
| 3922 | ToImpl = ObjCPropertyImplDecl::Create(Importer.getToContext(), DC, |
| 3923 | Importer.Import(D->getLocStart()), |
| 3924 | Importer.Import(D->getLocation()), |
| 3925 | Property, |
| 3926 | D->getPropertyImplementation(), |
| 3927 | Ivar, |
| 3928 | Importer.Import(D->getPropertyIvarDeclLoc())); |
| 3929 | ToImpl->setLexicalDeclContext(LexicalDC); |
| 3930 | Importer.Imported(D, ToImpl); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 3931 | LexicalDC->addDeclInternal(ToImpl); |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3932 | } else { |
| 3933 | // Check that we have the same kind of property implementation (@synthesize |
| 3934 | // vs. @dynamic). |
| 3935 | if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) { |
| 3936 | Importer.ToDiag(ToImpl->getLocation(), |
| 3937 | diag::err_odr_objc_property_impl_kind_inconsistent) |
| 3938 | << Property->getDeclName() |
| 3939 | << (ToImpl->getPropertyImplementation() |
| 3940 | == ObjCPropertyImplDecl::Dynamic); |
| 3941 | Importer.FromDiag(D->getLocation(), |
| 3942 | diag::note_odr_objc_property_impl_kind) |
| 3943 | << D->getPropertyDecl()->getDeclName() |
| 3944 | << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3945 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3946 | } |
| 3947 | |
| 3948 | // For @synthesize, check that we have the same |
| 3949 | if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize && |
| 3950 | Ivar != ToImpl->getPropertyIvarDecl()) { |
| 3951 | Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(), |
| 3952 | diag::err_odr_objc_synthesize_ivar_inconsistent) |
| 3953 | << Property->getDeclName() |
| 3954 | << ToImpl->getPropertyIvarDecl()->getDeclName() |
| 3955 | << Ivar->getDeclName(); |
| 3956 | Importer.FromDiag(D->getPropertyIvarDeclLoc(), |
| 3957 | diag::note_odr_objc_synthesize_ivar_here) |
| 3958 | << D->getPropertyIvarDecl()->getDeclName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3959 | return nullptr; |
Douglas Gregor | 14a49e2 | 2010-12-07 18:32:03 +0000 | [diff] [blame] | 3960 | } |
| 3961 | |
| 3962 | // Merge the existing implementation with the new implementation. |
| 3963 | Importer.Imported(D, ToImpl); |
| 3964 | } |
| 3965 | |
| 3966 | return ToImpl; |
| 3967 | } |
| 3968 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3969 | Decl *ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 3970 | // For template arguments, we adopt the translation unit as our declaration |
| 3971 | // context. This context will be fixed when the actual template declaration |
| 3972 | // is created. |
| 3973 | |
| 3974 | // FIXME: Import default argument. |
| 3975 | return TemplateTypeParmDecl::Create(Importer.getToContext(), |
| 3976 | Importer.getToContext().getTranslationUnitDecl(), |
Abramo Bagnara | b3185b0 | 2011-03-06 15:48:19 +0000 | [diff] [blame] | 3977 | Importer.Import(D->getLocStart()), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3978 | Importer.Import(D->getLocation()), |
| 3979 | D->getDepth(), |
| 3980 | D->getIndex(), |
| 3981 | Importer.Import(D->getIdentifier()), |
| 3982 | D->wasDeclaredWithTypename(), |
| 3983 | D->isParameterPack()); |
| 3984 | } |
| 3985 | |
| 3986 | Decl * |
| 3987 | ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 3988 | // Import the name of this declaration. |
| 3989 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 3990 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3991 | return nullptr; |
| 3992 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 3993 | // Import the location of this declaration. |
| 3994 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 3995 | |
| 3996 | // Import the type of this declaration. |
| 3997 | QualType T = Importer.Import(D->getType()); |
| 3998 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 3999 | return nullptr; |
| 4000 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4001 | // Import type-source information. |
| 4002 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 4003 | if (D->getTypeSourceInfo() && !TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4004 | return nullptr; |
| 4005 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4006 | // FIXME: Import default argument. |
| 4007 | |
| 4008 | return NonTypeTemplateParmDecl::Create(Importer.getToContext(), |
| 4009 | Importer.getToContext().getTranslationUnitDecl(), |
Abramo Bagnara | dff1930 | 2011-03-08 08:55:46 +0000 | [diff] [blame] | 4010 | Importer.Import(D->getInnerLocStart()), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4011 | Loc, D->getDepth(), D->getPosition(), |
| 4012 | Name.getAsIdentifierInfo(), |
Douglas Gregor | da3cc0d | 2010-12-23 23:51:58 +0000 | [diff] [blame] | 4013 | T, D->isParameterPack(), TInfo); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4014 | } |
| 4015 | |
| 4016 | Decl * |
| 4017 | ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 4018 | // Import the name of this declaration. |
| 4019 | DeclarationName Name = Importer.Import(D->getDeclName()); |
| 4020 | if (D->getDeclName() && !Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4021 | return nullptr; |
| 4022 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4023 | // Import the location of this declaration. |
| 4024 | SourceLocation Loc = Importer.Import(D->getLocation()); |
| 4025 | |
| 4026 | // Import template parameters. |
| 4027 | TemplateParameterList *TemplateParams |
| 4028 | = ImportTemplateParameterList(D->getTemplateParameters()); |
| 4029 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4030 | return nullptr; |
| 4031 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4032 | // FIXME: Import default argument. |
| 4033 | |
| 4034 | return TemplateTemplateParmDecl::Create(Importer.getToContext(), |
| 4035 | Importer.getToContext().getTranslationUnitDecl(), |
| 4036 | Loc, D->getDepth(), D->getPosition(), |
Douglas Gregor | f550077 | 2011-01-05 15:48:55 +0000 | [diff] [blame] | 4037 | D->isParameterPack(), |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4038 | Name.getAsIdentifierInfo(), |
| 4039 | TemplateParams); |
| 4040 | } |
| 4041 | |
| 4042 | Decl *ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 4043 | // If this record has a definition in the translation unit we're coming from, |
| 4044 | // but this particular declaration is not that definition, import the |
| 4045 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4046 | auto *Definition = |
| 4047 | cast_or_null<CXXRecordDecl>(D->getTemplatedDecl()->getDefinition()); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4048 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 4049 | Decl *ImportedDef |
| 4050 | = Importer.Import(Definition->getDescribedClassTemplate()); |
| 4051 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4052 | return nullptr; |
| 4053 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4054 | return Importer.Imported(D, ImportedDef); |
| 4055 | } |
| 4056 | |
| 4057 | // Import the major distinguishing characteristics of this class template. |
| 4058 | DeclContext *DC, *LexicalDC; |
| 4059 | DeclarationName Name; |
| 4060 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4061 | NamedDecl *ToD; |
| 4062 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4063 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4064 | if (ToD) |
| 4065 | return ToD; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4066 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4067 | // We may already have a template of the same name; try to find and match it. |
| 4068 | if (!DC->isFunctionOrMethod()) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4069 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4070 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4071 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4072 | for (auto *FoundDecl : FoundDecls) { |
| 4073 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4074 | continue; |
| 4075 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4076 | Decl *Found = FoundDecl; |
| 4077 | if (auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found)) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4078 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 4079 | // The class templates structurally match; call it the same template. |
| 4080 | // FIXME: We may be filling in a forward declaration here. Handle |
| 4081 | // this case! |
| 4082 | Importer.Imported(D->getTemplatedDecl(), |
| 4083 | FoundTemplate->getTemplatedDecl()); |
| 4084 | return Importer.Imported(D, FoundTemplate); |
| 4085 | } |
| 4086 | } |
| 4087 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4088 | ConflictingDecls.push_back(FoundDecl); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4089 | } |
| 4090 | |
| 4091 | if (!ConflictingDecls.empty()) { |
| 4092 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 4093 | ConflictingDecls.data(), |
| 4094 | ConflictingDecls.size()); |
| 4095 | } |
| 4096 | |
| 4097 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4098 | return nullptr; |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4099 | } |
| 4100 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4101 | CXXRecordDecl *FromTemplated = D->getTemplatedDecl(); |
| 4102 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4103 | // Create the declaration that is being templated. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4104 | auto *ToTemplated = cast_or_null<CXXRecordDecl>( |
| 4105 | Importer.Import(FromTemplated)); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4106 | if (!ToTemplated) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4107 | return nullptr; |
| 4108 | |
| 4109 | // Resolve possible cyclic import. |
| 4110 | if (Decl *AlreadyImported = Importer.GetAlreadyImportedOrNull(D)) |
| 4111 | return AlreadyImported; |
| 4112 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4113 | // Create the class template declaration itself. |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4114 | TemplateParameterList *TemplateParams = |
| 4115 | ImportTemplateParameterList(D->getTemplateParameters()); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4116 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4117 | return nullptr; |
| 4118 | |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4119 | ClassTemplateDecl *D2 = ClassTemplateDecl::Create(Importer.getToContext(), DC, |
| 4120 | Loc, Name, TemplateParams, |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4121 | ToTemplated); |
| 4122 | ToTemplated->setDescribedClassTemplate(D2); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4123 | |
| 4124 | D2->setAccess(D->getAccess()); |
| 4125 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4126 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4127 | |
| 4128 | // Note the relationship between the class templates. |
| 4129 | Importer.Imported(D, D2); |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4130 | Importer.Imported(FromTemplated, ToTemplated); |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4131 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4132 | if (FromTemplated->isCompleteDefinition() && |
| 4133 | !ToTemplated->isCompleteDefinition()) { |
Douglas Gregor | a082a49 | 2010-11-30 19:14:50 +0000 | [diff] [blame] | 4134 | // FIXME: Import definition! |
| 4135 | } |
| 4136 | |
| 4137 | return D2; |
| 4138 | } |
| 4139 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4140 | Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl( |
| 4141 | ClassTemplateSpecializationDecl *D) { |
| 4142 | // If this record has a definition in the translation unit we're coming from, |
| 4143 | // but this particular declaration is not that definition, import the |
| 4144 | // definition and map to that. |
| 4145 | TagDecl *Definition = D->getDefinition(); |
| 4146 | if (Definition && Definition != D) { |
| 4147 | Decl *ImportedDef = Importer.Import(Definition); |
| 4148 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4149 | return nullptr; |
| 4150 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4151 | return Importer.Imported(D, ImportedDef); |
| 4152 | } |
| 4153 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4154 | auto *ClassTemplate = |
| 4155 | cast_or_null<ClassTemplateDecl>(Importer.Import( |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4156 | D->getSpecializedTemplate())); |
| 4157 | if (!ClassTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4158 | return nullptr; |
| 4159 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4160 | // Import the context of this declaration. |
| 4161 | DeclContext *DC = ClassTemplate->getDeclContext(); |
| 4162 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4163 | return nullptr; |
| 4164 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4165 | DeclContext *LexicalDC = DC; |
| 4166 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4167 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4168 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4169 | return nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4170 | } |
| 4171 | |
| 4172 | // Import the location of this declaration. |
Abramo Bagnara | 29c2d46 | 2011-03-09 14:09:51 +0000 | [diff] [blame] | 4173 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 4174 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4175 | |
| 4176 | // Import template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4177 | SmallVector<TemplateArgument, 2> TemplateArgs; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4178 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 4179 | D->getTemplateArgs().size(), |
| 4180 | TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4181 | return nullptr; |
| 4182 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4183 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4184 | void *InsertPos = nullptr; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4185 | ClassTemplateSpecializationDecl *D2 |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 4186 | = ClassTemplate->findSpecialization(TemplateArgs, InsertPos); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4187 | if (D2) { |
| 4188 | // We already have a class template specialization with these template |
| 4189 | // arguments. |
| 4190 | |
| 4191 | // FIXME: Check for specialization vs. instantiation errors. |
| 4192 | |
| 4193 | if (RecordDecl *FoundDef = D2->getDefinition()) { |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4194 | if (!D->isCompleteDefinition() || IsStructuralMatch(D, FoundDef)) { |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4195 | // The record types structurally match, or the "from" translation |
| 4196 | // unit only had a forward declaration anyway; call it the same |
| 4197 | // function. |
| 4198 | return Importer.Imported(D, FoundDef); |
| 4199 | } |
| 4200 | } |
| 4201 | } else { |
| 4202 | // Create a new specialization. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4203 | if (auto *PartialSpec = |
| 4204 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4205 | // Import TemplateArgumentListInfo |
| 4206 | TemplateArgumentListInfo ToTAInfo; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4207 | const auto &ASTTemplateArgs = *PartialSpec->getTemplateArgsAsWritten(); |
| 4208 | if (ImportTemplateArgumentListInfo(ASTTemplateArgs, ToTAInfo)) |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 4209 | return nullptr; |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4210 | |
| 4211 | QualType CanonInjType = Importer.Import( |
| 4212 | PartialSpec->getInjectedSpecializationType()); |
| 4213 | if (CanonInjType.isNull()) |
| 4214 | return nullptr; |
| 4215 | CanonInjType = CanonInjType.getCanonicalType(); |
| 4216 | |
| 4217 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 4218 | PartialSpec->getTemplateParameters()); |
| 4219 | if (!ToTPList && PartialSpec->getTemplateParameters()) |
| 4220 | return nullptr; |
| 4221 | |
| 4222 | D2 = ClassTemplatePartialSpecializationDecl::Create( |
| 4223 | Importer.getToContext(), D->getTagKind(), DC, StartLoc, IdLoc, |
| 4224 | ToTPList, ClassTemplate, |
| 4225 | llvm::makeArrayRef(TemplateArgs.data(), TemplateArgs.size()), |
| 4226 | ToTAInfo, CanonInjType, nullptr); |
| 4227 | |
| 4228 | } else { |
| 4229 | D2 = ClassTemplateSpecializationDecl::Create(Importer.getToContext(), |
| 4230 | D->getTagKind(), DC, |
| 4231 | StartLoc, IdLoc, |
| 4232 | ClassTemplate, |
| 4233 | TemplateArgs, |
| 4234 | /*PrevDecl=*/nullptr); |
| 4235 | } |
| 4236 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4237 | D2->setSpecializationKind(D->getSpecializationKind()); |
| 4238 | |
| 4239 | // Add this specialization to the class template. |
| 4240 | ClassTemplate->AddSpecialization(D2, InsertPos); |
| 4241 | |
| 4242 | // Import the qualifier, if any. |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4243 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 4244 | |
| 4245 | Importer.Imported(D, D2); |
| 4246 | |
| 4247 | if (auto *TSI = D->getTypeAsWritten()) { |
| 4248 | TypeSourceInfo *TInfo = Importer.Import(TSI); |
| 4249 | if (!TInfo) |
| 4250 | return nullptr; |
| 4251 | D2->setTypeAsWritten(TInfo); |
| 4252 | D2->setTemplateKeywordLoc(Importer.Import(D->getTemplateKeywordLoc())); |
| 4253 | D2->setExternLoc(Importer.Import(D->getExternLoc())); |
| 4254 | } |
| 4255 | |
| 4256 | SourceLocation POI = Importer.Import(D->getPointOfInstantiation()); |
| 4257 | if (POI.isValid()) |
| 4258 | D2->setPointOfInstantiation(POI); |
| 4259 | else if (D->getPointOfInstantiation().isValid()) |
| 4260 | return nullptr; |
| 4261 | |
| 4262 | D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); |
| 4263 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4264 | // Add the specialization to this context. |
| 4265 | D2->setLexicalDeclContext(LexicalDC); |
Sean Callanan | 95e74be | 2011-10-21 02:57:43 +0000 | [diff] [blame] | 4266 | LexicalDC->addDeclInternal(D2); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4267 | } |
| 4268 | Importer.Imported(D, D2); |
John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 4269 | if (D->isCompleteDefinition() && ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4270 | return nullptr; |
| 4271 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 4272 | return D2; |
| 4273 | } |
| 4274 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4275 | Decl *ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| 4276 | // If this variable has a definition in the translation unit we're coming |
| 4277 | // from, |
| 4278 | // but this particular declaration is not that definition, import the |
| 4279 | // definition and map to that. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4280 | auto *Definition = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4281 | cast_or_null<VarDecl>(D->getTemplatedDecl()->getDefinition()); |
| 4282 | if (Definition && Definition != D->getTemplatedDecl()) { |
| 4283 | Decl *ImportedDef = Importer.Import(Definition->getDescribedVarTemplate()); |
| 4284 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4285 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4286 | |
| 4287 | return Importer.Imported(D, ImportedDef); |
| 4288 | } |
| 4289 | |
| 4290 | // Import the major distinguishing characteristics of this variable template. |
| 4291 | DeclContext *DC, *LexicalDC; |
| 4292 | DeclarationName Name; |
| 4293 | SourceLocation Loc; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4294 | NamedDecl *ToD; |
| 4295 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4296 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4297 | if (ToD) |
| 4298 | return ToD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4299 | |
| 4300 | // We may already have a template of the same name; try to find and match it. |
| 4301 | assert(!DC->isFunctionOrMethod() && |
| 4302 | "Variable templates cannot be declared at function scope"); |
| 4303 | SmallVector<NamedDecl *, 4> ConflictingDecls; |
| 4304 | SmallVector<NamedDecl *, 2> FoundDecls; |
Sean Callanan | 4947532 | 2014-12-10 03:09:41 +0000 | [diff] [blame] | 4305 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4306 | for (auto *FoundDecl : FoundDecls) { |
| 4307 | if (!FoundDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4308 | continue; |
| 4309 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4310 | Decl *Found = FoundDecl; |
| 4311 | if (auto *FoundTemplate = dyn_cast<VarTemplateDecl>(Found)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4312 | if (IsStructuralMatch(D, FoundTemplate)) { |
| 4313 | // The variable templates structurally match; call it the same template. |
| 4314 | Importer.Imported(D->getTemplatedDecl(), |
| 4315 | FoundTemplate->getTemplatedDecl()); |
| 4316 | return Importer.Imported(D, FoundTemplate); |
| 4317 | } |
| 4318 | } |
| 4319 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4320 | ConflictingDecls.push_back(FoundDecl); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4321 | } |
| 4322 | |
| 4323 | if (!ConflictingDecls.empty()) { |
| 4324 | Name = Importer.HandleNameConflict(Name, DC, Decl::IDNS_Ordinary, |
| 4325 | ConflictingDecls.data(), |
| 4326 | ConflictingDecls.size()); |
| 4327 | } |
| 4328 | |
| 4329 | if (!Name) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4330 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4331 | |
| 4332 | VarDecl *DTemplated = D->getTemplatedDecl(); |
| 4333 | |
| 4334 | // Import the type. |
| 4335 | QualType T = Importer.Import(DTemplated->getType()); |
| 4336 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4337 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4338 | |
| 4339 | // Create the declaration that is being templated. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4340 | auto *ToTemplated = dyn_cast_or_null<VarDecl>(Importer.Import(DTemplated)); |
| 4341 | if (!ToTemplated) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4342 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4343 | |
| 4344 | // Create the variable template declaration itself. |
| 4345 | TemplateParameterList *TemplateParams = |
| 4346 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4347 | if (!TemplateParams) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4348 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4349 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4350 | VarTemplateDecl *ToVarTD = VarTemplateDecl::Create( |
| 4351 | Importer.getToContext(), DC, Loc, Name, TemplateParams, ToTemplated); |
| 4352 | ToTemplated->setDescribedVarTemplate(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4353 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4354 | ToVarTD->setAccess(D->getAccess()); |
| 4355 | ToVarTD->setLexicalDeclContext(LexicalDC); |
| 4356 | LexicalDC->addDeclInternal(ToVarTD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4357 | |
| 4358 | // Note the relationship between the variable templates. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4359 | Importer.Imported(D, ToVarTD); |
| 4360 | Importer.Imported(DTemplated, ToTemplated); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4361 | |
| 4362 | if (DTemplated->isThisDeclarationADefinition() && |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4363 | !ToTemplated->isThisDeclarationADefinition()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4364 | // FIXME: Import definition! |
| 4365 | } |
| 4366 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4367 | return ToVarTD; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4368 | } |
| 4369 | |
| 4370 | Decl *ASTNodeImporter::VisitVarTemplateSpecializationDecl( |
| 4371 | VarTemplateSpecializationDecl *D) { |
| 4372 | // If this record has a definition in the translation unit we're coming from, |
| 4373 | // but this particular declaration is not that definition, import the |
| 4374 | // definition and map to that. |
| 4375 | VarDecl *Definition = D->getDefinition(); |
| 4376 | if (Definition && Definition != D) { |
| 4377 | Decl *ImportedDef = Importer.Import(Definition); |
| 4378 | if (!ImportedDef) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4379 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4380 | |
| 4381 | return Importer.Imported(D, ImportedDef); |
| 4382 | } |
| 4383 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4384 | auto *VarTemplate = cast_or_null<VarTemplateDecl>( |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4385 | Importer.Import(D->getSpecializedTemplate())); |
| 4386 | if (!VarTemplate) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4387 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4388 | |
| 4389 | // Import the context of this declaration. |
| 4390 | DeclContext *DC = VarTemplate->getDeclContext(); |
| 4391 | if (!DC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4392 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4393 | |
| 4394 | DeclContext *LexicalDC = DC; |
| 4395 | if (D->getDeclContext() != D->getLexicalDeclContext()) { |
| 4396 | LexicalDC = Importer.ImportContext(D->getLexicalDeclContext()); |
| 4397 | if (!LexicalDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4398 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4399 | } |
| 4400 | |
| 4401 | // Import the location of this declaration. |
| 4402 | SourceLocation StartLoc = Importer.Import(D->getLocStart()); |
| 4403 | SourceLocation IdLoc = Importer.Import(D->getLocation()); |
| 4404 | |
| 4405 | // Import template arguments. |
| 4406 | SmallVector<TemplateArgument, 2> TemplateArgs; |
| 4407 | if (ImportTemplateArguments(D->getTemplateArgs().data(), |
| 4408 | D->getTemplateArgs().size(), TemplateArgs)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4409 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4410 | |
| 4411 | // Try to find an existing specialization with these template arguments. |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4412 | void *InsertPos = nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4413 | VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization( |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 4414 | TemplateArgs, InsertPos); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4415 | if (D2) { |
| 4416 | // We already have a variable template specialization with these template |
| 4417 | // arguments. |
| 4418 | |
| 4419 | // FIXME: Check for specialization vs. instantiation errors. |
| 4420 | |
| 4421 | if (VarDecl *FoundDef = D2->getDefinition()) { |
| 4422 | if (!D->isThisDeclarationADefinition() || |
| 4423 | IsStructuralMatch(D, FoundDef)) { |
| 4424 | // The record types structurally match, or the "from" translation |
| 4425 | // unit only had a forward declaration anyway; call it the same |
| 4426 | // variable. |
| 4427 | return Importer.Imported(D, FoundDef); |
| 4428 | } |
| 4429 | } |
| 4430 | } else { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4431 | // Import the type. |
| 4432 | QualType T = Importer.Import(D->getType()); |
| 4433 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4434 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4435 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4436 | TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); |
| 4437 | if (D->getTypeSourceInfo() && !TInfo) |
| 4438 | return nullptr; |
| 4439 | |
| 4440 | TemplateArgumentListInfo ToTAInfo; |
| 4441 | if (ImportTemplateArgumentListInfo(D->getTemplateArgsInfo(), ToTAInfo)) |
| 4442 | return nullptr; |
| 4443 | |
| 4444 | using PartVarSpecDecl = VarTemplatePartialSpecializationDecl; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4445 | // Create a new specialization. |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4446 | if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) { |
| 4447 | // Import TemplateArgumentListInfo |
| 4448 | TemplateArgumentListInfo ArgInfos; |
| 4449 | const auto *FromTAArgsAsWritten = FromPartial->getTemplateArgsAsWritten(); |
| 4450 | // NOTE: FromTAArgsAsWritten and template parameter list are non-null. |
| 4451 | if (ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ArgInfos)) |
| 4452 | return nullptr; |
| 4453 | |
| 4454 | TemplateParameterList *ToTPList = ImportTemplateParameterList( |
| 4455 | FromPartial->getTemplateParameters()); |
| 4456 | if (!ToTPList) |
| 4457 | return nullptr; |
| 4458 | |
| 4459 | auto *ToPartial = PartVarSpecDecl::Create( |
| 4460 | Importer.getToContext(), DC, StartLoc, IdLoc, ToTPList, VarTemplate, |
| 4461 | T, TInfo, D->getStorageClass(), TemplateArgs, ArgInfos); |
| 4462 | |
| 4463 | auto *FromInst = FromPartial->getInstantiatedFromMember(); |
| 4464 | auto *ToInst = cast_or_null<PartVarSpecDecl>(Importer.Import(FromInst)); |
| 4465 | if (FromInst && !ToInst) |
| 4466 | return nullptr; |
| 4467 | |
| 4468 | ToPartial->setInstantiatedFromMember(ToInst); |
| 4469 | if (FromPartial->isMemberSpecialization()) |
| 4470 | ToPartial->setMemberSpecialization(); |
| 4471 | |
| 4472 | D2 = ToPartial; |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4473 | } else { // Full specialization |
| 4474 | D2 = VarTemplateSpecializationDecl::Create( |
| 4475 | Importer.getToContext(), DC, StartLoc, IdLoc, VarTemplate, T, TInfo, |
| 4476 | D->getStorageClass(), TemplateArgs); |
| 4477 | } |
| 4478 | |
| 4479 | SourceLocation POI = D->getPointOfInstantiation(); |
| 4480 | if (POI.isValid()) |
| 4481 | D2->setPointOfInstantiation(Importer.Import(POI)); |
| 4482 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4483 | D2->setSpecializationKind(D->getSpecializationKind()); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4484 | D2->setTemplateArgsInfo(ToTAInfo); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4485 | |
| 4486 | // Add this specialization to the class template. |
| 4487 | VarTemplate->AddSpecialization(D2, InsertPos); |
| 4488 | |
| 4489 | // Import the qualifier, if any. |
| 4490 | D2->setQualifierInfo(Importer.Import(D->getQualifierLoc())); |
| 4491 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4492 | if (D->isConstexpr()) |
| 4493 | D2->setConstexpr(true); |
| 4494 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4495 | // Add the specialization to this context. |
| 4496 | D2->setLexicalDeclContext(LexicalDC); |
| 4497 | LexicalDC->addDeclInternal(D2); |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4498 | |
| 4499 | D2->setAccess(D->getAccess()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4500 | } |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4501 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4502 | Importer.Imported(D, D2); |
| 4503 | |
Aleksei Sidorin | 4c05f14 | 2018-02-14 11:18:00 +0000 | [diff] [blame] | 4504 | // NOTE: isThisDeclarationADefinition() can return DeclarationOnly even if |
| 4505 | // declaration has initializer. Should this be fixed in the AST?.. Anyway, |
| 4506 | // we have to check the declaration for initializer - otherwise, it won't be |
| 4507 | // imported. |
| 4508 | if ((D->isThisDeclarationADefinition() || D->hasInit()) && |
| 4509 | ImportDefinition(D, D2)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 4510 | return nullptr; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 4511 | |
| 4512 | return D2; |
| 4513 | } |
| 4514 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4515 | Decl *ASTNodeImporter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 4516 | DeclContext *DC, *LexicalDC; |
| 4517 | DeclarationName Name; |
| 4518 | SourceLocation Loc; |
| 4519 | NamedDecl *ToD; |
| 4520 | |
| 4521 | if (ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc)) |
| 4522 | return nullptr; |
| 4523 | |
| 4524 | if (ToD) |
| 4525 | return ToD; |
| 4526 | |
| 4527 | // Try to find a function in our own ("to") context with the same name, same |
| 4528 | // type, and in the same context as the function we're importing. |
| 4529 | if (!LexicalDC->isFunctionOrMethod()) { |
| 4530 | unsigned IDNS = Decl::IDNS_Ordinary; |
| 4531 | SmallVector<NamedDecl *, 2> FoundDecls; |
| 4532 | DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4533 | for (auto *FoundDecl : FoundDecls) { |
| 4534 | if (!FoundDecl->isInIdentifierNamespace(IDNS)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4535 | continue; |
| 4536 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4537 | if (auto *FoundFunction = dyn_cast<FunctionTemplateDecl>(FoundDecl)) { |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4538 | if (FoundFunction->hasExternalFormalLinkage() && |
| 4539 | D->hasExternalFormalLinkage()) { |
| 4540 | if (IsStructuralMatch(D, FoundFunction)) { |
| 4541 | Importer.Imported(D, FoundFunction); |
| 4542 | // FIXME: Actually try to merge the body and other attributes. |
| 4543 | return FoundFunction; |
| 4544 | } |
| 4545 | } |
| 4546 | } |
| 4547 | } |
| 4548 | } |
| 4549 | |
| 4550 | TemplateParameterList *Params = |
| 4551 | ImportTemplateParameterList(D->getTemplateParameters()); |
| 4552 | if (!Params) |
| 4553 | return nullptr; |
| 4554 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4555 | auto *TemplatedFD = |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 4556 | cast_or_null<FunctionDecl>(Importer.Import(D->getTemplatedDecl())); |
| 4557 | if (!TemplatedFD) |
| 4558 | return nullptr; |
| 4559 | |
| 4560 | FunctionTemplateDecl *ToFunc = FunctionTemplateDecl::Create( |
| 4561 | Importer.getToContext(), DC, Loc, Name, Params, TemplatedFD); |
| 4562 | |
| 4563 | TemplatedFD->setDescribedFunctionTemplate(ToFunc); |
| 4564 | ToFunc->setAccess(D->getAccess()); |
| 4565 | ToFunc->setLexicalDeclContext(LexicalDC); |
| 4566 | Importer.Imported(D, ToFunc); |
| 4567 | |
| 4568 | LexicalDC->addDeclInternal(ToFunc); |
| 4569 | return ToFunc; |
| 4570 | } |
| 4571 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 4572 | //---------------------------------------------------------------------------- |
| 4573 | // Import Statements |
| 4574 | //---------------------------------------------------------------------------- |
| 4575 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4576 | DeclGroupRef ASTNodeImporter::ImportDeclGroup(DeclGroupRef DG) { |
| 4577 | if (DG.isNull()) |
| 4578 | return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0); |
| 4579 | size_t NumDecls = DG.end() - DG.begin(); |
| 4580 | SmallVector<Decl *, 1> ToDecls(NumDecls); |
| 4581 | auto &_Importer = this->Importer; |
| 4582 | std::transform(DG.begin(), DG.end(), ToDecls.begin(), |
| 4583 | [&_Importer](Decl *D) -> Decl * { |
| 4584 | return _Importer.Import(D); |
| 4585 | }); |
| 4586 | return DeclGroupRef::Create(Importer.getToContext(), |
| 4587 | ToDecls.begin(), |
| 4588 | NumDecls); |
| 4589 | } |
| 4590 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4591 | Stmt *ASTNodeImporter::VisitStmt(Stmt *S) { |
| 4592 | Importer.FromDiag(S->getLocStart(), diag::err_unsupported_ast_node) |
| 4593 | << S->getStmtClassName(); |
| 4594 | return nullptr; |
| 4595 | } |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4596 | |
| 4597 | Stmt *ASTNodeImporter::VisitGCCAsmStmt(GCCAsmStmt *S) { |
| 4598 | SmallVector<IdentifierInfo *, 4> Names; |
| 4599 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
| 4600 | IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 4601 | // ToII is nullptr when no symbolic name is given for output operand |
| 4602 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 4603 | if (!ToII && S->getOutputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4604 | return nullptr; |
| 4605 | Names.push_back(ToII); |
| 4606 | } |
| 4607 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
| 4608 | IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I)); |
Gabor Horvath | 27f5ff6 | 2017-03-13 15:32:24 +0000 | [diff] [blame] | 4609 | // ToII is nullptr when no symbolic name is given for input operand |
| 4610 | // see ParseStmtAsm::ParseAsmOperandsOpt |
| 4611 | if (!ToII && S->getInputIdentifier(I)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4612 | return nullptr; |
| 4613 | Names.push_back(ToII); |
| 4614 | } |
| 4615 | |
| 4616 | SmallVector<StringLiteral *, 4> Clobbers; |
| 4617 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4618 | auto *Clobber = cast_or_null<StringLiteral>( |
| 4619 | Importer.Import(S->getClobberStringLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4620 | if (!Clobber) |
| 4621 | return nullptr; |
| 4622 | Clobbers.push_back(Clobber); |
| 4623 | } |
| 4624 | |
| 4625 | SmallVector<StringLiteral *, 4> Constraints; |
| 4626 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4627 | auto *Output = cast_or_null<StringLiteral>( |
| 4628 | Importer.Import(S->getOutputConstraintLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4629 | if (!Output) |
| 4630 | return nullptr; |
| 4631 | Constraints.push_back(Output); |
| 4632 | } |
| 4633 | |
| 4634 | for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4635 | auto *Input = cast_or_null<StringLiteral>( |
| 4636 | Importer.Import(S->getInputConstraintLiteral(I))); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4637 | if (!Input) |
| 4638 | return nullptr; |
| 4639 | Constraints.push_back(Input); |
| 4640 | } |
| 4641 | |
| 4642 | SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4643 | if (ImportContainerChecked(S->outputs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4644 | return nullptr; |
| 4645 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4646 | if (ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4647 | return nullptr; |
| 4648 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4649 | auto *AsmStr = cast_or_null<StringLiteral>( |
| 4650 | Importer.Import(S->getAsmString())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 4651 | if (!AsmStr) |
| 4652 | return nullptr; |
| 4653 | |
| 4654 | return new (Importer.getToContext()) GCCAsmStmt( |
| 4655 | Importer.getToContext(), |
| 4656 | Importer.Import(S->getAsmLoc()), |
| 4657 | S->isSimple(), |
| 4658 | S->isVolatile(), |
| 4659 | S->getNumOutputs(), |
| 4660 | S->getNumInputs(), |
| 4661 | Names.data(), |
| 4662 | Constraints.data(), |
| 4663 | Exprs.data(), |
| 4664 | AsmStr, |
| 4665 | S->getNumClobbers(), |
| 4666 | Clobbers.data(), |
| 4667 | Importer.Import(S->getRParenLoc())); |
| 4668 | } |
| 4669 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4670 | Stmt *ASTNodeImporter::VisitDeclStmt(DeclStmt *S) { |
| 4671 | DeclGroupRef ToDG = ImportDeclGroup(S->getDeclGroup()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4672 | for (auto *ToD : ToDG) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4673 | if (!ToD) |
| 4674 | return nullptr; |
| 4675 | } |
| 4676 | SourceLocation ToStartLoc = Importer.Import(S->getStartLoc()); |
| 4677 | SourceLocation ToEndLoc = Importer.Import(S->getEndLoc()); |
| 4678 | return new (Importer.getToContext()) DeclStmt(ToDG, ToStartLoc, ToEndLoc); |
| 4679 | } |
| 4680 | |
| 4681 | Stmt *ASTNodeImporter::VisitNullStmt(NullStmt *S) { |
| 4682 | SourceLocation ToSemiLoc = Importer.Import(S->getSemiLoc()); |
| 4683 | return new (Importer.getToContext()) NullStmt(ToSemiLoc, |
| 4684 | S->hasLeadingEmptyMacro()); |
| 4685 | } |
| 4686 | |
| 4687 | Stmt *ASTNodeImporter::VisitCompoundStmt(CompoundStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4688 | SmallVector<Stmt *, 8> ToStmts(S->size()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 4689 | |
| 4690 | if (ImportContainerChecked(S->body(), ToStmts)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 4691 | return nullptr; |
| 4692 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4693 | SourceLocation ToLBraceLoc = Importer.Import(S->getLBracLoc()); |
| 4694 | SourceLocation ToRBraceLoc = Importer.Import(S->getRBracLoc()); |
Benjamin Kramer | 0742090 | 2017-12-24 16:24:20 +0000 | [diff] [blame] | 4695 | return CompoundStmt::Create(Importer.getToContext(), ToStmts, ToLBraceLoc, |
| 4696 | ToRBraceLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4697 | } |
| 4698 | |
| 4699 | Stmt *ASTNodeImporter::VisitCaseStmt(CaseStmt *S) { |
| 4700 | Expr *ToLHS = Importer.Import(S->getLHS()); |
| 4701 | if (!ToLHS) |
| 4702 | return nullptr; |
| 4703 | Expr *ToRHS = Importer.Import(S->getRHS()); |
| 4704 | if (!ToRHS && S->getRHS()) |
| 4705 | return nullptr; |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 4706 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4707 | if (!ToSubStmt && S->getSubStmt()) |
| 4708 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4709 | SourceLocation ToCaseLoc = Importer.Import(S->getCaseLoc()); |
| 4710 | SourceLocation ToEllipsisLoc = Importer.Import(S->getEllipsisLoc()); |
| 4711 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4712 | auto *ToStmt = new (Importer.getToContext()) |
Gabor Horvath | 480892b | 2017-10-18 09:25:18 +0000 | [diff] [blame] | 4713 | CaseStmt(ToLHS, ToRHS, ToCaseLoc, ToEllipsisLoc, ToColonLoc); |
| 4714 | ToStmt->setSubStmt(ToSubStmt); |
| 4715 | return ToStmt; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4716 | } |
| 4717 | |
| 4718 | Stmt *ASTNodeImporter::VisitDefaultStmt(DefaultStmt *S) { |
| 4719 | SourceLocation ToDefaultLoc = Importer.Import(S->getDefaultLoc()); |
| 4720 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 4721 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4722 | if (!ToSubStmt && S->getSubStmt()) |
| 4723 | return nullptr; |
| 4724 | return new (Importer.getToContext()) DefaultStmt(ToDefaultLoc, ToColonLoc, |
| 4725 | ToSubStmt); |
| 4726 | } |
| 4727 | |
| 4728 | Stmt *ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { |
| 4729 | SourceLocation ToIdentLoc = Importer.Import(S->getIdentLoc()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4730 | auto *ToLabelDecl = cast_or_null<LabelDecl>(Importer.Import(S->getDecl())); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4731 | if (!ToLabelDecl && S->getDecl()) |
| 4732 | return nullptr; |
| 4733 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4734 | if (!ToSubStmt && S->getSubStmt()) |
| 4735 | return nullptr; |
| 4736 | return new (Importer.getToContext()) LabelStmt(ToIdentLoc, ToLabelDecl, |
| 4737 | ToSubStmt); |
| 4738 | } |
| 4739 | |
| 4740 | Stmt *ASTNodeImporter::VisitAttributedStmt(AttributedStmt *S) { |
| 4741 | SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc()); |
| 4742 | ArrayRef<const Attr*> FromAttrs(S->getAttrs()); |
| 4743 | SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size()); |
| 4744 | ASTContext &_ToContext = Importer.getToContext(); |
| 4745 | std::transform(FromAttrs.begin(), FromAttrs.end(), ToAttrs.begin(), |
| 4746 | [&_ToContext](const Attr *A) -> const Attr * { |
| 4747 | return A->clone(_ToContext); |
| 4748 | }); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4749 | for (const auto *ToA : ToAttrs) { |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4750 | if (!ToA) |
| 4751 | return nullptr; |
| 4752 | } |
| 4753 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 4754 | if (!ToSubStmt && S->getSubStmt()) |
| 4755 | return nullptr; |
| 4756 | return AttributedStmt::Create(Importer.getToContext(), ToAttrLoc, |
| 4757 | ToAttrs, ToSubStmt); |
| 4758 | } |
| 4759 | |
| 4760 | Stmt *ASTNodeImporter::VisitIfStmt(IfStmt *S) { |
| 4761 | SourceLocation ToIfLoc = Importer.Import(S->getIfLoc()); |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4762 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4763 | if (!ToInit && S->getInit()) |
| 4764 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4765 | VarDecl *ToConditionVariable = nullptr; |
| 4766 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4767 | ToConditionVariable = |
| 4768 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4769 | if (!ToConditionVariable) |
| 4770 | return nullptr; |
| 4771 | } |
| 4772 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4773 | if (!ToCondition && S->getCond()) |
| 4774 | return nullptr; |
| 4775 | Stmt *ToThenStmt = Importer.Import(S->getThen()); |
| 4776 | if (!ToThenStmt && S->getThen()) |
| 4777 | return nullptr; |
| 4778 | SourceLocation ToElseLoc = Importer.Import(S->getElseLoc()); |
| 4779 | Stmt *ToElseStmt = Importer.Import(S->getElse()); |
| 4780 | if (!ToElseStmt && S->getElse()) |
| 4781 | return nullptr; |
| 4782 | return new (Importer.getToContext()) IfStmt(Importer.getToContext(), |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 4783 | ToIfLoc, S->isConstexpr(), |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4784 | ToInit, |
Richard Smith | b130fe7 | 2016-06-23 19:16:49 +0000 | [diff] [blame] | 4785 | ToConditionVariable, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4786 | ToCondition, ToThenStmt, |
| 4787 | ToElseLoc, ToElseStmt); |
| 4788 | } |
| 4789 | |
| 4790 | Stmt *ASTNodeImporter::VisitSwitchStmt(SwitchStmt *S) { |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4791 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4792 | if (!ToInit && S->getInit()) |
| 4793 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4794 | VarDecl *ToConditionVariable = nullptr; |
| 4795 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4796 | ToConditionVariable = |
| 4797 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4798 | if (!ToConditionVariable) |
| 4799 | return nullptr; |
| 4800 | } |
| 4801 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4802 | if (!ToCondition && S->getCond()) |
| 4803 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4804 | auto *ToStmt = new (Importer.getToContext()) SwitchStmt( |
Richard Smith | a547eb2 | 2016-07-14 00:11:03 +0000 | [diff] [blame] | 4805 | Importer.getToContext(), ToInit, |
| 4806 | ToConditionVariable, ToCondition); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4807 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4808 | if (!ToBody && S->getBody()) |
| 4809 | return nullptr; |
| 4810 | ToStmt->setBody(ToBody); |
| 4811 | ToStmt->setSwitchLoc(Importer.Import(S->getSwitchLoc())); |
| 4812 | // Now we have to re-chain the cases. |
| 4813 | SwitchCase *LastChainedSwitchCase = nullptr; |
| 4814 | for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; |
| 4815 | SC = SC->getNextSwitchCase()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4816 | auto *ToSC = dyn_cast_or_null<SwitchCase>(Importer.Import(SC)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4817 | if (!ToSC) |
| 4818 | return nullptr; |
| 4819 | if (LastChainedSwitchCase) |
| 4820 | LastChainedSwitchCase->setNextSwitchCase(ToSC); |
| 4821 | else |
| 4822 | ToStmt->setSwitchCaseList(ToSC); |
| 4823 | LastChainedSwitchCase = ToSC; |
| 4824 | } |
| 4825 | return ToStmt; |
| 4826 | } |
| 4827 | |
| 4828 | Stmt *ASTNodeImporter::VisitWhileStmt(WhileStmt *S) { |
| 4829 | VarDecl *ToConditionVariable = nullptr; |
| 4830 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4831 | ToConditionVariable = |
| 4832 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4833 | if (!ToConditionVariable) |
| 4834 | return nullptr; |
| 4835 | } |
| 4836 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4837 | if (!ToCondition && S->getCond()) |
| 4838 | return nullptr; |
| 4839 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4840 | if (!ToBody && S->getBody()) |
| 4841 | return nullptr; |
| 4842 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 4843 | return new (Importer.getToContext()) WhileStmt(Importer.getToContext(), |
| 4844 | ToConditionVariable, |
| 4845 | ToCondition, ToBody, |
| 4846 | ToWhileLoc); |
| 4847 | } |
| 4848 | |
| 4849 | Stmt *ASTNodeImporter::VisitDoStmt(DoStmt *S) { |
| 4850 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4851 | if (!ToBody && S->getBody()) |
| 4852 | return nullptr; |
| 4853 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4854 | if (!ToCondition && S->getCond()) |
| 4855 | return nullptr; |
| 4856 | SourceLocation ToDoLoc = Importer.Import(S->getDoLoc()); |
| 4857 | SourceLocation ToWhileLoc = Importer.Import(S->getWhileLoc()); |
| 4858 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4859 | return new (Importer.getToContext()) DoStmt(ToBody, ToCondition, |
| 4860 | ToDoLoc, ToWhileLoc, |
| 4861 | ToRParenLoc); |
| 4862 | } |
| 4863 | |
| 4864 | Stmt *ASTNodeImporter::VisitForStmt(ForStmt *S) { |
| 4865 | Stmt *ToInit = Importer.Import(S->getInit()); |
| 4866 | if (!ToInit && S->getInit()) |
| 4867 | return nullptr; |
| 4868 | Expr *ToCondition = Importer.Import(S->getCond()); |
| 4869 | if (!ToCondition && S->getCond()) |
| 4870 | return nullptr; |
| 4871 | VarDecl *ToConditionVariable = nullptr; |
| 4872 | if (VarDecl *FromConditionVariable = S->getConditionVariable()) { |
| 4873 | ToConditionVariable = |
| 4874 | dyn_cast_or_null<VarDecl>(Importer.Import(FromConditionVariable)); |
| 4875 | if (!ToConditionVariable) |
| 4876 | return nullptr; |
| 4877 | } |
| 4878 | Expr *ToInc = Importer.Import(S->getInc()); |
| 4879 | if (!ToInc && S->getInc()) |
| 4880 | return nullptr; |
| 4881 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4882 | if (!ToBody && S->getBody()) |
| 4883 | return nullptr; |
| 4884 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 4885 | SourceLocation ToLParenLoc = Importer.Import(S->getLParenLoc()); |
| 4886 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 4887 | return new (Importer.getToContext()) ForStmt(Importer.getToContext(), |
| 4888 | ToInit, ToCondition, |
| 4889 | ToConditionVariable, |
| 4890 | ToInc, ToBody, |
| 4891 | ToForLoc, ToLParenLoc, |
| 4892 | ToRParenLoc); |
| 4893 | } |
| 4894 | |
| 4895 | Stmt *ASTNodeImporter::VisitGotoStmt(GotoStmt *S) { |
| 4896 | LabelDecl *ToLabel = nullptr; |
| 4897 | if (LabelDecl *FromLabel = S->getLabel()) { |
| 4898 | ToLabel = dyn_cast_or_null<LabelDecl>(Importer.Import(FromLabel)); |
| 4899 | if (!ToLabel) |
| 4900 | return nullptr; |
| 4901 | } |
| 4902 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 4903 | SourceLocation ToLabelLoc = Importer.Import(S->getLabelLoc()); |
| 4904 | return new (Importer.getToContext()) GotoStmt(ToLabel, |
| 4905 | ToGotoLoc, ToLabelLoc); |
| 4906 | } |
| 4907 | |
| 4908 | Stmt *ASTNodeImporter::VisitIndirectGotoStmt(IndirectGotoStmt *S) { |
| 4909 | SourceLocation ToGotoLoc = Importer.Import(S->getGotoLoc()); |
| 4910 | SourceLocation ToStarLoc = Importer.Import(S->getStarLoc()); |
| 4911 | Expr *ToTarget = Importer.Import(S->getTarget()); |
| 4912 | if (!ToTarget && S->getTarget()) |
| 4913 | return nullptr; |
| 4914 | return new (Importer.getToContext()) IndirectGotoStmt(ToGotoLoc, ToStarLoc, |
| 4915 | ToTarget); |
| 4916 | } |
| 4917 | |
| 4918 | Stmt *ASTNodeImporter::VisitContinueStmt(ContinueStmt *S) { |
| 4919 | SourceLocation ToContinueLoc = Importer.Import(S->getContinueLoc()); |
| 4920 | return new (Importer.getToContext()) ContinueStmt(ToContinueLoc); |
| 4921 | } |
| 4922 | |
| 4923 | Stmt *ASTNodeImporter::VisitBreakStmt(BreakStmt *S) { |
| 4924 | SourceLocation ToBreakLoc = Importer.Import(S->getBreakLoc()); |
| 4925 | return new (Importer.getToContext()) BreakStmt(ToBreakLoc); |
| 4926 | } |
| 4927 | |
| 4928 | Stmt *ASTNodeImporter::VisitReturnStmt(ReturnStmt *S) { |
| 4929 | SourceLocation ToRetLoc = Importer.Import(S->getReturnLoc()); |
| 4930 | Expr *ToRetExpr = Importer.Import(S->getRetValue()); |
| 4931 | if (!ToRetExpr && S->getRetValue()) |
| 4932 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4933 | auto *NRVOCandidate = const_cast<VarDecl *>(S->getNRVOCandidate()); |
| 4934 | auto *ToNRVOCandidate = cast_or_null<VarDecl>(Importer.Import(NRVOCandidate)); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4935 | if (!ToNRVOCandidate && NRVOCandidate) |
| 4936 | return nullptr; |
| 4937 | return new (Importer.getToContext()) ReturnStmt(ToRetLoc, ToRetExpr, |
| 4938 | ToNRVOCandidate); |
| 4939 | } |
| 4940 | |
| 4941 | Stmt *ASTNodeImporter::VisitCXXCatchStmt(CXXCatchStmt *S) { |
| 4942 | SourceLocation ToCatchLoc = Importer.Import(S->getCatchLoc()); |
| 4943 | VarDecl *ToExceptionDecl = nullptr; |
| 4944 | if (VarDecl *FromExceptionDecl = S->getExceptionDecl()) { |
| 4945 | ToExceptionDecl = |
| 4946 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 4947 | if (!ToExceptionDecl) |
| 4948 | return nullptr; |
| 4949 | } |
| 4950 | Stmt *ToHandlerBlock = Importer.Import(S->getHandlerBlock()); |
| 4951 | if (!ToHandlerBlock && S->getHandlerBlock()) |
| 4952 | return nullptr; |
| 4953 | return new (Importer.getToContext()) CXXCatchStmt(ToCatchLoc, |
| 4954 | ToExceptionDecl, |
| 4955 | ToHandlerBlock); |
| 4956 | } |
| 4957 | |
| 4958 | Stmt *ASTNodeImporter::VisitCXXTryStmt(CXXTryStmt *S) { |
| 4959 | SourceLocation ToTryLoc = Importer.Import(S->getTryLoc()); |
| 4960 | Stmt *ToTryBlock = Importer.Import(S->getTryBlock()); |
| 4961 | if (!ToTryBlock && S->getTryBlock()) |
| 4962 | return nullptr; |
| 4963 | SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers()); |
| 4964 | for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) { |
| 4965 | CXXCatchStmt *FromHandler = S->getHandler(HI); |
| 4966 | if (Stmt *ToHandler = Importer.Import(FromHandler)) |
| 4967 | ToHandlers[HI] = ToHandler; |
| 4968 | else |
| 4969 | return nullptr; |
| 4970 | } |
| 4971 | return CXXTryStmt::Create(Importer.getToContext(), ToTryLoc, ToTryBlock, |
| 4972 | ToHandlers); |
| 4973 | } |
| 4974 | |
| 4975 | Stmt *ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4976 | auto *ToRange = |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4977 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getRangeStmt())); |
| 4978 | if (!ToRange && S->getRangeStmt()) |
| 4979 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4980 | auto *ToBegin = |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 4981 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getBeginStmt())); |
| 4982 | if (!ToBegin && S->getBeginStmt()) |
| 4983 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4984 | auto *ToEnd = |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 4985 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getEndStmt())); |
| 4986 | if (!ToEnd && S->getEndStmt()) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4987 | return nullptr; |
| 4988 | Expr *ToCond = Importer.Import(S->getCond()); |
| 4989 | if (!ToCond && S->getCond()) |
| 4990 | return nullptr; |
| 4991 | Expr *ToInc = Importer.Import(S->getInc()); |
| 4992 | if (!ToInc && S->getInc()) |
| 4993 | return nullptr; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 4994 | auto *ToLoopVar = |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 4995 | dyn_cast_or_null<DeclStmt>(Importer.Import(S->getLoopVarStmt())); |
| 4996 | if (!ToLoopVar && S->getLoopVarStmt()) |
| 4997 | return nullptr; |
| 4998 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 4999 | if (!ToBody && S->getBody()) |
| 5000 | return nullptr; |
| 5001 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 5002 | SourceLocation ToCoawaitLoc = Importer.Import(S->getCoawaitLoc()); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5003 | SourceLocation ToColonLoc = Importer.Import(S->getColonLoc()); |
| 5004 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
Richard Smith | 01694c3 | 2016-03-20 10:33:40 +0000 | [diff] [blame] | 5005 | return new (Importer.getToContext()) CXXForRangeStmt(ToRange, ToBegin, ToEnd, |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5006 | ToCond, ToInc, |
| 5007 | ToLoopVar, ToBody, |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 5008 | ToForLoc, ToCoawaitLoc, |
| 5009 | ToColonLoc, ToRParenLoc); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5010 | } |
| 5011 | |
| 5012 | Stmt *ASTNodeImporter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { |
| 5013 | Stmt *ToElem = Importer.Import(S->getElement()); |
| 5014 | if (!ToElem && S->getElement()) |
| 5015 | return nullptr; |
| 5016 | Expr *ToCollect = Importer.Import(S->getCollection()); |
| 5017 | if (!ToCollect && S->getCollection()) |
| 5018 | return nullptr; |
| 5019 | Stmt *ToBody = Importer.Import(S->getBody()); |
| 5020 | if (!ToBody && S->getBody()) |
| 5021 | return nullptr; |
| 5022 | SourceLocation ToForLoc = Importer.Import(S->getForLoc()); |
| 5023 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5024 | return new (Importer.getToContext()) ObjCForCollectionStmt(ToElem, |
| 5025 | ToCollect, |
| 5026 | ToBody, ToForLoc, |
| 5027 | ToRParenLoc); |
| 5028 | } |
| 5029 | |
| 5030 | Stmt *ASTNodeImporter::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 5031 | SourceLocation ToAtCatchLoc = Importer.Import(S->getAtCatchLoc()); |
| 5032 | SourceLocation ToRParenLoc = Importer.Import(S->getRParenLoc()); |
| 5033 | VarDecl *ToExceptionDecl = nullptr; |
| 5034 | if (VarDecl *FromExceptionDecl = S->getCatchParamDecl()) { |
| 5035 | ToExceptionDecl = |
| 5036 | dyn_cast_or_null<VarDecl>(Importer.Import(FromExceptionDecl)); |
| 5037 | if (!ToExceptionDecl) |
| 5038 | return nullptr; |
| 5039 | } |
| 5040 | Stmt *ToBody = Importer.Import(S->getCatchBody()); |
| 5041 | if (!ToBody && S->getCatchBody()) |
| 5042 | return nullptr; |
| 5043 | return new (Importer.getToContext()) ObjCAtCatchStmt(ToAtCatchLoc, |
| 5044 | ToRParenLoc, |
| 5045 | ToExceptionDecl, |
| 5046 | ToBody); |
| 5047 | } |
| 5048 | |
| 5049 | Stmt *ASTNodeImporter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 5050 | SourceLocation ToAtFinallyLoc = Importer.Import(S->getAtFinallyLoc()); |
| 5051 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyBody()); |
| 5052 | if (!ToAtFinallyStmt && S->getFinallyBody()) |
| 5053 | return nullptr; |
| 5054 | return new (Importer.getToContext()) ObjCAtFinallyStmt(ToAtFinallyLoc, |
| 5055 | ToAtFinallyStmt); |
| 5056 | } |
| 5057 | |
| 5058 | Stmt *ASTNodeImporter::VisitObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 5059 | SourceLocation ToAtTryLoc = Importer.Import(S->getAtTryLoc()); |
| 5060 | Stmt *ToAtTryStmt = Importer.Import(S->getTryBody()); |
| 5061 | if (!ToAtTryStmt && S->getTryBody()) |
| 5062 | return nullptr; |
| 5063 | SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts()); |
| 5064 | for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) { |
| 5065 | ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI); |
| 5066 | if (Stmt *ToCatchStmt = Importer.Import(FromCatchStmt)) |
| 5067 | ToCatchStmts[CI] = ToCatchStmt; |
| 5068 | else |
| 5069 | return nullptr; |
| 5070 | } |
| 5071 | Stmt *ToAtFinallyStmt = Importer.Import(S->getFinallyStmt()); |
| 5072 | if (!ToAtFinallyStmt && S->getFinallyStmt()) |
| 5073 | return nullptr; |
| 5074 | return ObjCAtTryStmt::Create(Importer.getToContext(), |
| 5075 | ToAtTryLoc, ToAtTryStmt, |
| 5076 | ToCatchStmts.begin(), ToCatchStmts.size(), |
| 5077 | ToAtFinallyStmt); |
| 5078 | } |
| 5079 | |
| 5080 | Stmt *ASTNodeImporter::VisitObjCAtSynchronizedStmt |
| 5081 | (ObjCAtSynchronizedStmt *S) { |
| 5082 | SourceLocation ToAtSynchronizedLoc = |
| 5083 | Importer.Import(S->getAtSynchronizedLoc()); |
| 5084 | Expr *ToSynchExpr = Importer.Import(S->getSynchExpr()); |
| 5085 | if (!ToSynchExpr && S->getSynchExpr()) |
| 5086 | return nullptr; |
| 5087 | Stmt *ToSynchBody = Importer.Import(S->getSynchBody()); |
| 5088 | if (!ToSynchBody && S->getSynchBody()) |
| 5089 | return nullptr; |
| 5090 | return new (Importer.getToContext()) ObjCAtSynchronizedStmt( |
| 5091 | ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody); |
| 5092 | } |
| 5093 | |
| 5094 | Stmt *ASTNodeImporter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 5095 | SourceLocation ToAtThrowLoc = Importer.Import(S->getThrowLoc()); |
| 5096 | Expr *ToThrow = Importer.Import(S->getThrowExpr()); |
| 5097 | if (!ToThrow && S->getThrowExpr()) |
| 5098 | return nullptr; |
| 5099 | return new (Importer.getToContext()) ObjCAtThrowStmt(ToAtThrowLoc, ToThrow); |
| 5100 | } |
| 5101 | |
| 5102 | Stmt *ASTNodeImporter::VisitObjCAutoreleasePoolStmt |
| 5103 | (ObjCAutoreleasePoolStmt *S) { |
| 5104 | SourceLocation ToAtLoc = Importer.Import(S->getAtLoc()); |
| 5105 | Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); |
| 5106 | if (!ToSubStmt && S->getSubStmt()) |
| 5107 | return nullptr; |
| 5108 | return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(ToAtLoc, |
| 5109 | ToSubStmt); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5110 | } |
| 5111 | |
| 5112 | //---------------------------------------------------------------------------- |
| 5113 | // Import Expressions |
| 5114 | //---------------------------------------------------------------------------- |
| 5115 | Expr *ASTNodeImporter::VisitExpr(Expr *E) { |
| 5116 | Importer.FromDiag(E->getLocStart(), diag::err_unsupported_ast_node) |
| 5117 | << E->getStmtClassName(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5118 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5119 | } |
| 5120 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5121 | Expr *ASTNodeImporter::VisitVAArgExpr(VAArgExpr *E) { |
| 5122 | QualType T = Importer.Import(E->getType()); |
| 5123 | if (T.isNull()) |
| 5124 | return nullptr; |
| 5125 | |
| 5126 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5127 | if (!SubExpr && E->getSubExpr()) |
| 5128 | return nullptr; |
| 5129 | |
| 5130 | TypeSourceInfo *TInfo = Importer.Import(E->getWrittenTypeInfo()); |
| 5131 | if (!TInfo) |
| 5132 | return nullptr; |
| 5133 | |
| 5134 | return new (Importer.getToContext()) VAArgExpr( |
| 5135 | Importer.Import(E->getBuiltinLoc()), SubExpr, TInfo, |
| 5136 | Importer.Import(E->getRParenLoc()), T, E->isMicrosoftABI()); |
| 5137 | } |
| 5138 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5139 | Expr *ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) { |
| 5140 | QualType T = Importer.Import(E->getType()); |
| 5141 | if (T.isNull()) |
| 5142 | return nullptr; |
| 5143 | |
| 5144 | return new (Importer.getToContext()) GNUNullExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5145 | T, Importer.Import(E->getLocStart())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5146 | } |
| 5147 | |
| 5148 | Expr *ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) { |
| 5149 | QualType T = Importer.Import(E->getType()); |
| 5150 | if (T.isNull()) |
| 5151 | return nullptr; |
| 5152 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5153 | auto *SL = cast_or_null<StringLiteral>(Importer.Import(E->getFunctionName())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5154 | if (!SL && E->getFunctionName()) |
| 5155 | return nullptr; |
| 5156 | |
| 5157 | return new (Importer.getToContext()) PredefinedExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5158 | Importer.Import(E->getLocStart()), T, E->getIdentType(), SL); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5159 | } |
| 5160 | |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5161 | Expr *ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5162 | auto *ToD = cast_or_null<ValueDecl>(Importer.Import(E->getDecl())); |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5163 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5164 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5165 | |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5166 | NamedDecl *FoundD = nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5167 | if (E->getDecl() != E->getFoundDecl()) { |
| 5168 | FoundD = cast_or_null<NamedDecl>(Importer.Import(E->getFoundDecl())); |
| 5169 | if (!FoundD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5170 | return nullptr; |
Chandler Carruth | 8d26bb0 | 2011-05-01 23:48:14 +0000 | [diff] [blame] | 5171 | } |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5172 | |
| 5173 | QualType T = Importer.Import(E->getType()); |
| 5174 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5175 | return nullptr; |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5176 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5177 | TemplateArgumentListInfo ToTAInfo; |
| 5178 | TemplateArgumentListInfo *ResInfo = nullptr; |
| 5179 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 5180 | if (ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo)) |
| 5181 | return nullptr; |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5182 | ResInfo = &ToTAInfo; |
| 5183 | } |
| 5184 | |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5185 | DeclRefExpr *DRE = DeclRefExpr::Create(Importer.getToContext(), |
| 5186 | Importer.Import(E->getQualifierLoc()), |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 5187 | Importer.Import(E->getTemplateKeywordLoc()), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5188 | ToD, |
Alexey Bataev | 19acc3d | 2015-01-12 10:17:46 +0000 | [diff] [blame] | 5189 | E->refersToEnclosingVariableOrCapture(), |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5190 | Importer.Import(E->getLocation()), |
| 5191 | T, E->getValueKind(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5192 | FoundD, ResInfo); |
Abramo Bagnara | 635ed24e | 2011-10-05 07:56:41 +0000 | [diff] [blame] | 5193 | if (E->hadMultipleCandidates()) |
| 5194 | DRE->setHadMultipleCandidates(true); |
| 5195 | return DRE; |
Douglas Gregor | 52f820e | 2010-02-19 01:17:02 +0000 | [diff] [blame] | 5196 | } |
| 5197 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5198 | Expr *ASTNodeImporter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 5199 | QualType T = Importer.Import(E->getType()); |
| 5200 | if (T.isNull()) |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5201 | return nullptr; |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5202 | |
| 5203 | return new (Importer.getToContext()) ImplicitValueInitExpr(T); |
| 5204 | } |
| 5205 | |
| 5206 | ASTNodeImporter::Designator |
| 5207 | ASTNodeImporter::ImportDesignator(const Designator &D) { |
| 5208 | if (D.isFieldDesignator()) { |
| 5209 | IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName()); |
| 5210 | // Caller checks for import error |
| 5211 | return Designator(ToFieldName, Importer.Import(D.getDotLoc()), |
| 5212 | Importer.Import(D.getFieldLoc())); |
| 5213 | } |
| 5214 | if (D.isArrayDesignator()) |
| 5215 | return Designator(D.getFirstExprIndex(), |
| 5216 | Importer.Import(D.getLBracketLoc()), |
| 5217 | Importer.Import(D.getRBracketLoc())); |
| 5218 | |
| 5219 | assert(D.isArrayRangeDesignator()); |
| 5220 | return Designator(D.getFirstExprIndex(), |
| 5221 | Importer.Import(D.getLBracketLoc()), |
| 5222 | Importer.Import(D.getEllipsisLoc()), |
| 5223 | Importer.Import(D.getRBracketLoc())); |
| 5224 | } |
| 5225 | |
| 5226 | |
| 5227 | Expr *ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *DIE) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5228 | auto *Init = cast_or_null<Expr>(Importer.Import(DIE->getInit())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5229 | if (!Init) |
| 5230 | return nullptr; |
| 5231 | |
| 5232 | SmallVector<Expr *, 4> IndexExprs(DIE->getNumSubExprs() - 1); |
| 5233 | // List elements from the second, the first is Init itself |
| 5234 | for (unsigned I = 1, E = DIE->getNumSubExprs(); I < E; I++) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5235 | if (auto *Arg = cast_or_null<Expr>(Importer.Import(DIE->getSubExpr(I)))) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5236 | IndexExprs[I - 1] = Arg; |
| 5237 | else |
| 5238 | return nullptr; |
| 5239 | } |
| 5240 | |
| 5241 | SmallVector<Designator, 4> Designators(DIE->size()); |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5242 | llvm::transform(DIE->designators(), Designators.begin(), |
| 5243 | [this](const Designator &D) -> Designator { |
| 5244 | return ImportDesignator(D); |
| 5245 | }); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5246 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5247 | for (const auto &D : DIE->designators()) |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5248 | if (D.isFieldDesignator() && !D.getFieldName()) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5249 | return nullptr; |
| 5250 | |
| 5251 | return DesignatedInitExpr::Create( |
David Majnemer | f7e3609 | 2016-06-23 00:15:04 +0000 | [diff] [blame] | 5252 | Importer.getToContext(), Designators, |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5253 | IndexExprs, Importer.Import(DIE->getEqualOrColonLoc()), |
| 5254 | DIE->usesGNUSyntax(), Init); |
| 5255 | } |
| 5256 | |
| 5257 | Expr *ASTNodeImporter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { |
| 5258 | QualType T = Importer.Import(E->getType()); |
| 5259 | if (T.isNull()) |
| 5260 | return nullptr; |
| 5261 | |
| 5262 | return new (Importer.getToContext()) |
| 5263 | CXXNullPtrLiteralExpr(T, Importer.Import(E->getLocation())); |
| 5264 | } |
| 5265 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5266 | Expr *ASTNodeImporter::VisitIntegerLiteral(IntegerLiteral *E) { |
| 5267 | QualType T = Importer.Import(E->getType()); |
| 5268 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5269 | return nullptr; |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5270 | |
Argyrios Kyrtzidis | 43b2057 | 2010-08-28 09:06:06 +0000 | [diff] [blame] | 5271 | return IntegerLiteral::Create(Importer.getToContext(), |
| 5272 | E->getValue(), T, |
| 5273 | Importer.Import(E->getLocation())); |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 5274 | } |
| 5275 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5276 | Expr *ASTNodeImporter::VisitFloatingLiteral(FloatingLiteral *E) { |
| 5277 | QualType T = Importer.Import(E->getType()); |
| 5278 | if (T.isNull()) |
| 5279 | return nullptr; |
| 5280 | |
| 5281 | return FloatingLiteral::Create(Importer.getToContext(), |
| 5282 | E->getValue(), E->isExact(), T, |
| 5283 | Importer.Import(E->getLocation())); |
| 5284 | } |
| 5285 | |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5286 | Expr *ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) { |
| 5287 | QualType T = Importer.Import(E->getType()); |
| 5288 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5289 | return nullptr; |
| 5290 | |
Douglas Gregor | fb65e59 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 5291 | return new (Importer.getToContext()) CharacterLiteral(E->getValue(), |
| 5292 | E->getKind(), T, |
Douglas Gregor | 623421d | 2010-02-18 02:21:22 +0000 | [diff] [blame] | 5293 | Importer.Import(E->getLocation())); |
| 5294 | } |
| 5295 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5296 | Expr *ASTNodeImporter::VisitStringLiteral(StringLiteral *E) { |
| 5297 | QualType T = Importer.Import(E->getType()); |
| 5298 | if (T.isNull()) |
| 5299 | return nullptr; |
| 5300 | |
| 5301 | SmallVector<SourceLocation, 4> Locations(E->getNumConcatenated()); |
| 5302 | ImportArray(E->tokloc_begin(), E->tokloc_end(), Locations.begin()); |
| 5303 | |
| 5304 | return StringLiteral::Create(Importer.getToContext(), E->getBytes(), |
| 5305 | E->getKind(), E->isPascal(), T, |
| 5306 | Locations.data(), Locations.size()); |
| 5307 | } |
| 5308 | |
| 5309 | Expr *ASTNodeImporter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 5310 | QualType T = Importer.Import(E->getType()); |
| 5311 | if (T.isNull()) |
| 5312 | return nullptr; |
| 5313 | |
| 5314 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeSourceInfo()); |
| 5315 | if (!TInfo) |
| 5316 | return nullptr; |
| 5317 | |
| 5318 | Expr *Init = Importer.Import(E->getInitializer()); |
| 5319 | if (!Init) |
| 5320 | return nullptr; |
| 5321 | |
| 5322 | return new (Importer.getToContext()) CompoundLiteralExpr( |
| 5323 | Importer.Import(E->getLParenLoc()), TInfo, T, E->getValueKind(), |
| 5324 | Init, E->isFileScope()); |
| 5325 | } |
| 5326 | |
| 5327 | Expr *ASTNodeImporter::VisitAtomicExpr(AtomicExpr *E) { |
| 5328 | QualType T = Importer.Import(E->getType()); |
| 5329 | if (T.isNull()) |
| 5330 | return nullptr; |
| 5331 | |
| 5332 | SmallVector<Expr *, 6> Exprs(E->getNumSubExprs()); |
| 5333 | if (ImportArrayChecked( |
| 5334 | E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(), |
| 5335 | Exprs.begin())) |
| 5336 | return nullptr; |
| 5337 | |
| 5338 | return new (Importer.getToContext()) AtomicExpr( |
| 5339 | Importer.Import(E->getBuiltinLoc()), Exprs, T, E->getOp(), |
| 5340 | Importer.Import(E->getRParenLoc())); |
| 5341 | } |
| 5342 | |
| 5343 | Expr *ASTNodeImporter::VisitAddrLabelExpr(AddrLabelExpr *E) { |
| 5344 | QualType T = Importer.Import(E->getType()); |
| 5345 | if (T.isNull()) |
| 5346 | return nullptr; |
| 5347 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5348 | auto *ToLabel = cast_or_null<LabelDecl>(Importer.Import(E->getLabel())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5349 | if (!ToLabel) |
| 5350 | return nullptr; |
| 5351 | |
| 5352 | return new (Importer.getToContext()) AddrLabelExpr( |
| 5353 | Importer.Import(E->getAmpAmpLoc()), Importer.Import(E->getLabelLoc()), |
| 5354 | ToLabel, T); |
| 5355 | } |
| 5356 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5357 | Expr *ASTNodeImporter::VisitParenExpr(ParenExpr *E) { |
| 5358 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5359 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5360 | return nullptr; |
| 5361 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5362 | return new (Importer.getToContext()) |
| 5363 | ParenExpr(Importer.Import(E->getLParen()), |
| 5364 | Importer.Import(E->getRParen()), |
| 5365 | SubExpr); |
| 5366 | } |
| 5367 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5368 | Expr *ASTNodeImporter::VisitParenListExpr(ParenListExpr *E) { |
| 5369 | SmallVector<Expr *, 4> Exprs(E->getNumExprs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5370 | if (ImportContainerChecked(E->exprs(), Exprs)) |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5371 | return nullptr; |
| 5372 | |
| 5373 | return new (Importer.getToContext()) ParenListExpr( |
| 5374 | Importer.getToContext(), Importer.Import(E->getLParenLoc()), |
| 5375 | Exprs, Importer.Import(E->getLParenLoc())); |
| 5376 | } |
| 5377 | |
| 5378 | Expr *ASTNodeImporter::VisitStmtExpr(StmtExpr *E) { |
| 5379 | QualType T = Importer.Import(E->getType()); |
| 5380 | if (T.isNull()) |
| 5381 | return nullptr; |
| 5382 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5383 | auto *ToSubStmt = cast_or_null<CompoundStmt>( |
| 5384 | Importer.Import(E->getSubStmt())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5385 | if (!ToSubStmt && E->getSubStmt()) |
| 5386 | return nullptr; |
| 5387 | |
| 5388 | return new (Importer.getToContext()) StmtExpr(ToSubStmt, T, |
| 5389 | Importer.Import(E->getLParenLoc()), Importer.Import(E->getRParenLoc())); |
| 5390 | } |
| 5391 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5392 | Expr *ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) { |
| 5393 | QualType T = Importer.Import(E->getType()); |
| 5394 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5395 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5396 | |
| 5397 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5398 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5399 | return nullptr; |
| 5400 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5401 | return new (Importer.getToContext()) UnaryOperator( |
| 5402 | SubExpr, E->getOpcode(), T, E->getValueKind(), E->getObjectKind(), |
| 5403 | Importer.Import(E->getOperatorLoc()), E->canOverflow()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5404 | } |
| 5405 | |
Aaron Ballman | a503855 | 2018-01-09 13:07:03 +0000 | [diff] [blame] | 5406 | Expr * |
| 5407 | ASTNodeImporter::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) { |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5408 | QualType ResultType = Importer.Import(E->getType()); |
| 5409 | |
| 5410 | if (E->isArgumentType()) { |
| 5411 | TypeSourceInfo *TInfo = Importer.Import(E->getArgumentTypeInfo()); |
| 5412 | if (!TInfo) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5413 | return nullptr; |
| 5414 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5415 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5416 | TInfo, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5417 | Importer.Import(E->getOperatorLoc()), |
| 5418 | Importer.Import(E->getRParenLoc())); |
| 5419 | } |
| 5420 | |
| 5421 | Expr *SubExpr = Importer.Import(E->getArgumentExpr()); |
| 5422 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5423 | return nullptr; |
| 5424 | |
Peter Collingbourne | e190dee | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 5425 | return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(E->getKind(), |
| 5426 | SubExpr, ResultType, |
Douglas Gregor | d8552cd | 2010-02-19 01:24:23 +0000 | [diff] [blame] | 5427 | Importer.Import(E->getOperatorLoc()), |
| 5428 | Importer.Import(E->getRParenLoc())); |
| 5429 | } |
| 5430 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5431 | Expr *ASTNodeImporter::VisitBinaryOperator(BinaryOperator *E) { |
| 5432 | QualType T = Importer.Import(E->getType()); |
| 5433 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5434 | return nullptr; |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5435 | |
| 5436 | Expr *LHS = Importer.Import(E->getLHS()); |
| 5437 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5438 | return nullptr; |
| 5439 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5440 | Expr *RHS = Importer.Import(E->getRHS()); |
| 5441 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5442 | return nullptr; |
| 5443 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5444 | return new (Importer.getToContext()) BinaryOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 5445 | T, E->getValueKind(), |
| 5446 | E->getObjectKind(), |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 5447 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 5448 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5449 | } |
| 5450 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5451 | Expr *ASTNodeImporter::VisitConditionalOperator(ConditionalOperator *E) { |
| 5452 | QualType T = Importer.Import(E->getType()); |
| 5453 | if (T.isNull()) |
| 5454 | return nullptr; |
| 5455 | |
| 5456 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5457 | if (!ToLHS) |
| 5458 | return nullptr; |
| 5459 | |
| 5460 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5461 | if (!ToRHS) |
| 5462 | return nullptr; |
| 5463 | |
| 5464 | Expr *ToCond = Importer.Import(E->getCond()); |
| 5465 | if (!ToCond) |
| 5466 | return nullptr; |
| 5467 | |
| 5468 | return new (Importer.getToContext()) ConditionalOperator( |
| 5469 | ToCond, Importer.Import(E->getQuestionLoc()), |
| 5470 | ToLHS, Importer.Import(E->getColonLoc()), |
| 5471 | ToRHS, T, E->getValueKind(), E->getObjectKind()); |
| 5472 | } |
| 5473 | |
| 5474 | Expr *ASTNodeImporter::VisitBinaryConditionalOperator( |
| 5475 | BinaryConditionalOperator *E) { |
| 5476 | QualType T = Importer.Import(E->getType()); |
| 5477 | if (T.isNull()) |
| 5478 | return nullptr; |
| 5479 | |
| 5480 | Expr *Common = Importer.Import(E->getCommon()); |
| 5481 | if (!Common) |
| 5482 | return nullptr; |
| 5483 | |
| 5484 | Expr *Cond = Importer.Import(E->getCond()); |
| 5485 | if (!Cond) |
| 5486 | return nullptr; |
| 5487 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5488 | auto *OpaqueValue = cast_or_null<OpaqueValueExpr>( |
| 5489 | Importer.Import(E->getOpaqueValue())); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5490 | if (!OpaqueValue) |
| 5491 | return nullptr; |
| 5492 | |
| 5493 | Expr *TrueExpr = Importer.Import(E->getTrueExpr()); |
| 5494 | if (!TrueExpr) |
| 5495 | return nullptr; |
| 5496 | |
| 5497 | Expr *FalseExpr = Importer.Import(E->getFalseExpr()); |
| 5498 | if (!FalseExpr) |
| 5499 | return nullptr; |
| 5500 | |
| 5501 | return new (Importer.getToContext()) BinaryConditionalOperator( |
| 5502 | Common, OpaqueValue, Cond, TrueExpr, FalseExpr, |
| 5503 | Importer.Import(E->getQuestionLoc()), Importer.Import(E->getColonLoc()), |
| 5504 | T, E->getValueKind(), E->getObjectKind()); |
| 5505 | } |
| 5506 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5507 | Expr *ASTNodeImporter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 5508 | QualType T = Importer.Import(E->getType()); |
| 5509 | if (T.isNull()) |
| 5510 | return nullptr; |
| 5511 | |
| 5512 | TypeSourceInfo *ToQueried = Importer.Import(E->getQueriedTypeSourceInfo()); |
| 5513 | if (!ToQueried) |
| 5514 | return nullptr; |
| 5515 | |
| 5516 | Expr *Dim = Importer.Import(E->getDimensionExpression()); |
| 5517 | if (!Dim && E->getDimensionExpression()) |
| 5518 | return nullptr; |
| 5519 | |
| 5520 | return new (Importer.getToContext()) ArrayTypeTraitExpr( |
| 5521 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 5522 | E->getValue(), Dim, Importer.Import(E->getLocEnd()), T); |
| 5523 | } |
| 5524 | |
| 5525 | Expr *ASTNodeImporter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 5526 | QualType T = Importer.Import(E->getType()); |
| 5527 | if (T.isNull()) |
| 5528 | return nullptr; |
| 5529 | |
| 5530 | Expr *ToQueried = Importer.Import(E->getQueriedExpression()); |
| 5531 | if (!ToQueried) |
| 5532 | return nullptr; |
| 5533 | |
| 5534 | return new (Importer.getToContext()) ExpressionTraitExpr( |
| 5535 | Importer.Import(E->getLocStart()), E->getTrait(), ToQueried, |
| 5536 | E->getValue(), Importer.Import(E->getLocEnd()), T); |
| 5537 | } |
| 5538 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5539 | Expr *ASTNodeImporter::VisitOpaqueValueExpr(OpaqueValueExpr *E) { |
| 5540 | QualType T = Importer.Import(E->getType()); |
| 5541 | if (T.isNull()) |
| 5542 | return nullptr; |
| 5543 | |
| 5544 | Expr *SourceExpr = Importer.Import(E->getSourceExpr()); |
| 5545 | if (!SourceExpr && E->getSourceExpr()) |
| 5546 | return nullptr; |
| 5547 | |
| 5548 | return new (Importer.getToContext()) OpaqueValueExpr( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5549 | Importer.Import(E->getLocation()), T, E->getValueKind(), |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 5550 | E->getObjectKind(), SourceExpr); |
| 5551 | } |
| 5552 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5553 | Expr *ASTNodeImporter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 5554 | QualType T = Importer.Import(E->getType()); |
| 5555 | if (T.isNull()) |
| 5556 | return nullptr; |
| 5557 | |
| 5558 | Expr *ToLHS = Importer.Import(E->getLHS()); |
| 5559 | if (!ToLHS) |
| 5560 | return nullptr; |
| 5561 | |
| 5562 | Expr *ToRHS = Importer.Import(E->getRHS()); |
| 5563 | if (!ToRHS) |
| 5564 | return nullptr; |
| 5565 | |
| 5566 | return new (Importer.getToContext()) ArraySubscriptExpr( |
| 5567 | ToLHS, ToRHS, T, E->getValueKind(), E->getObjectKind(), |
| 5568 | Importer.Import(E->getRBracketLoc())); |
| 5569 | } |
| 5570 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5571 | Expr *ASTNodeImporter::VisitCompoundAssignOperator(CompoundAssignOperator *E) { |
| 5572 | QualType T = Importer.Import(E->getType()); |
| 5573 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5574 | return nullptr; |
| 5575 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5576 | QualType CompLHSType = Importer.Import(E->getComputationLHSType()); |
| 5577 | if (CompLHSType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5578 | return nullptr; |
| 5579 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5580 | QualType CompResultType = Importer.Import(E->getComputationResultType()); |
| 5581 | if (CompResultType.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5582 | return nullptr; |
| 5583 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5584 | Expr *LHS = Importer.Import(E->getLHS()); |
| 5585 | if (!LHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5586 | return nullptr; |
| 5587 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5588 | Expr *RHS = Importer.Import(E->getRHS()); |
| 5589 | if (!RHS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5590 | return nullptr; |
| 5591 | |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5592 | return new (Importer.getToContext()) |
| 5593 | CompoundAssignOperator(LHS, RHS, E->getOpcode(), |
John McCall | 7decc9e | 2010-11-18 06:31:45 +0000 | [diff] [blame] | 5594 | T, E->getValueKind(), |
| 5595 | E->getObjectKind(), |
| 5596 | CompLHSType, CompResultType, |
Lang Hames | 5de91cc | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 5597 | Importer.Import(E->getOperatorLoc()), |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 5598 | E->getFPFeatures()); |
Douglas Gregor | c74247e | 2010-02-19 01:07:06 +0000 | [diff] [blame] | 5599 | } |
| 5600 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5601 | bool ASTNodeImporter::ImportCastPath(CastExpr *CE, CXXCastPath &Path) { |
| 5602 | for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) { |
| 5603 | if (CXXBaseSpecifier *Spec = Importer.Import(*I)) |
| 5604 | Path.push_back(Spec); |
| 5605 | else |
| 5606 | return true; |
| 5607 | } |
| 5608 | return false; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5609 | } |
| 5610 | |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5611 | Expr *ASTNodeImporter::VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 5612 | QualType T = Importer.Import(E->getType()); |
| 5613 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5614 | return nullptr; |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5615 | |
| 5616 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5617 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5618 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5619 | |
| 5620 | CXXCastPath BasePath; |
| 5621 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5622 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5623 | |
| 5624 | return ImplicitCastExpr::Create(Importer.getToContext(), T, E->getCastKind(), |
John McCall | 2536c6d | 2010-08-25 10:28:54 +0000 | [diff] [blame] | 5625 | SubExpr, &BasePath, E->getValueKind()); |
Douglas Gregor | 98c1018 | 2010-02-12 22:17:39 +0000 | [diff] [blame] | 5626 | } |
| 5627 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5628 | Expr *ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5629 | QualType T = Importer.Import(E->getType()); |
| 5630 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5631 | return nullptr; |
| 5632 | |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5633 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5634 | if (!SubExpr) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5635 | return nullptr; |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5636 | |
| 5637 | TypeSourceInfo *TInfo = Importer.Import(E->getTypeInfoAsWritten()); |
| 5638 | if (!TInfo && E->getTypeInfoAsWritten()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5639 | return nullptr; |
| 5640 | |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5641 | CXXCastPath BasePath; |
| 5642 | if (ImportCastPath(E, BasePath)) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 5643 | return nullptr; |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 5644 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5645 | switch (E->getStmtClass()) { |
| 5646 | case Stmt::CStyleCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5647 | auto *CCE = cast<CStyleCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5648 | return CStyleCastExpr::Create(Importer.getToContext(), T, |
| 5649 | E->getValueKind(), E->getCastKind(), |
| 5650 | SubExpr, &BasePath, TInfo, |
| 5651 | Importer.Import(CCE->getLParenLoc()), |
| 5652 | Importer.Import(CCE->getRParenLoc())); |
| 5653 | } |
| 5654 | |
| 5655 | case Stmt::CXXFunctionalCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5656 | auto *FCE = cast<CXXFunctionalCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5657 | return CXXFunctionalCastExpr::Create(Importer.getToContext(), T, |
| 5658 | E->getValueKind(), TInfo, |
| 5659 | E->getCastKind(), SubExpr, &BasePath, |
| 5660 | Importer.Import(FCE->getLParenLoc()), |
| 5661 | Importer.Import(FCE->getRParenLoc())); |
| 5662 | } |
| 5663 | |
| 5664 | case Stmt::ObjCBridgedCastExprClass: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5665 | auto *OCE = cast<ObjCBridgedCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5666 | return new (Importer.getToContext()) ObjCBridgedCastExpr( |
| 5667 | Importer.Import(OCE->getLParenLoc()), OCE->getBridgeKind(), |
| 5668 | E->getCastKind(), Importer.Import(OCE->getBridgeKeywordLoc()), |
| 5669 | TInfo, SubExpr); |
| 5670 | } |
| 5671 | default: |
| 5672 | break; // just fall through |
| 5673 | } |
| 5674 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5675 | auto *Named = cast<CXXNamedCastExpr>(E); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5676 | SourceLocation ExprLoc = Importer.Import(Named->getOperatorLoc()), |
| 5677 | RParenLoc = Importer.Import(Named->getRParenLoc()); |
| 5678 | SourceRange Brackets = Importer.Import(Named->getAngleBrackets()); |
| 5679 | |
| 5680 | switch (E->getStmtClass()) { |
| 5681 | case Stmt::CXXStaticCastExprClass: |
| 5682 | return CXXStaticCastExpr::Create(Importer.getToContext(), T, |
| 5683 | E->getValueKind(), E->getCastKind(), |
| 5684 | SubExpr, &BasePath, TInfo, |
| 5685 | ExprLoc, RParenLoc, Brackets); |
| 5686 | |
| 5687 | case Stmt::CXXDynamicCastExprClass: |
| 5688 | return CXXDynamicCastExpr::Create(Importer.getToContext(), T, |
| 5689 | E->getValueKind(), E->getCastKind(), |
| 5690 | SubExpr, &BasePath, TInfo, |
| 5691 | ExprLoc, RParenLoc, Brackets); |
| 5692 | |
| 5693 | case Stmt::CXXReinterpretCastExprClass: |
| 5694 | return CXXReinterpretCastExpr::Create(Importer.getToContext(), T, |
| 5695 | E->getValueKind(), E->getCastKind(), |
| 5696 | SubExpr, &BasePath, TInfo, |
| 5697 | ExprLoc, RParenLoc, Brackets); |
| 5698 | |
| 5699 | case Stmt::CXXConstCastExprClass: |
| 5700 | return CXXConstCastExpr::Create(Importer.getToContext(), T, |
| 5701 | E->getValueKind(), SubExpr, TInfo, ExprLoc, |
| 5702 | RParenLoc, Brackets); |
| 5703 | default: |
| 5704 | llvm_unreachable("Cast expression of unsupported type!"); |
| 5705 | return nullptr; |
| 5706 | } |
| 5707 | } |
| 5708 | |
| 5709 | Expr *ASTNodeImporter::VisitOffsetOfExpr(OffsetOfExpr *OE) { |
| 5710 | QualType T = Importer.Import(OE->getType()); |
| 5711 | if (T.isNull()) |
| 5712 | return nullptr; |
| 5713 | |
| 5714 | SmallVector<OffsetOfNode, 4> Nodes; |
| 5715 | for (int I = 0, E = OE->getNumComponents(); I < E; ++I) { |
| 5716 | const OffsetOfNode &Node = OE->getComponent(I); |
| 5717 | |
| 5718 | switch (Node.getKind()) { |
| 5719 | case OffsetOfNode::Array: |
| 5720 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), |
| 5721 | Node.getArrayExprIndex(), |
| 5722 | Importer.Import(Node.getLocEnd()))); |
| 5723 | break; |
| 5724 | |
| 5725 | case OffsetOfNode::Base: { |
| 5726 | CXXBaseSpecifier *BS = Importer.Import(Node.getBase()); |
| 5727 | if (!BS && Node.getBase()) |
| 5728 | return nullptr; |
| 5729 | Nodes.push_back(OffsetOfNode(BS)); |
| 5730 | break; |
| 5731 | } |
| 5732 | case OffsetOfNode::Field: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5733 | auto *FD = cast_or_null<FieldDecl>(Importer.Import(Node.getField())); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5734 | if (!FD) |
| 5735 | return nullptr; |
| 5736 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), FD, |
| 5737 | Importer.Import(Node.getLocEnd()))); |
| 5738 | break; |
| 5739 | } |
| 5740 | case OffsetOfNode::Identifier: { |
| 5741 | IdentifierInfo *ToII = Importer.Import(Node.getFieldName()); |
| 5742 | if (!ToII) |
| 5743 | return nullptr; |
| 5744 | Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), ToII, |
| 5745 | Importer.Import(Node.getLocEnd()))); |
| 5746 | break; |
| 5747 | } |
| 5748 | } |
| 5749 | } |
| 5750 | |
| 5751 | SmallVector<Expr *, 4> Exprs(OE->getNumExpressions()); |
| 5752 | for (int I = 0, E = OE->getNumExpressions(); I < E; ++I) { |
| 5753 | Expr *ToIndexExpr = Importer.Import(OE->getIndexExpr(I)); |
| 5754 | if (!ToIndexExpr) |
| 5755 | return nullptr; |
| 5756 | Exprs[I] = ToIndexExpr; |
| 5757 | } |
| 5758 | |
| 5759 | TypeSourceInfo *TInfo = Importer.Import(OE->getTypeSourceInfo()); |
| 5760 | if (!TInfo && OE->getTypeSourceInfo()) |
| 5761 | return nullptr; |
| 5762 | |
| 5763 | return OffsetOfExpr::Create(Importer.getToContext(), T, |
| 5764 | Importer.Import(OE->getOperatorLoc()), |
| 5765 | TInfo, Nodes, Exprs, |
| 5766 | Importer.Import(OE->getRParenLoc())); |
| 5767 | } |
| 5768 | |
| 5769 | Expr *ASTNodeImporter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 5770 | QualType T = Importer.Import(E->getType()); |
| 5771 | if (T.isNull()) |
| 5772 | return nullptr; |
| 5773 | |
| 5774 | Expr *Operand = Importer.Import(E->getOperand()); |
| 5775 | if (!Operand) |
| 5776 | return nullptr; |
| 5777 | |
| 5778 | CanThrowResult CanThrow; |
| 5779 | if (E->isValueDependent()) |
| 5780 | CanThrow = CT_Dependent; |
| 5781 | else |
| 5782 | CanThrow = E->getValue() ? CT_Can : CT_Cannot; |
| 5783 | |
| 5784 | return new (Importer.getToContext()) CXXNoexceptExpr( |
| 5785 | T, Operand, CanThrow, |
| 5786 | Importer.Import(E->getLocStart()), Importer.Import(E->getLocEnd())); |
| 5787 | } |
| 5788 | |
| 5789 | Expr *ASTNodeImporter::VisitCXXThrowExpr(CXXThrowExpr *E) { |
| 5790 | QualType T = Importer.Import(E->getType()); |
| 5791 | if (T.isNull()) |
| 5792 | return nullptr; |
| 5793 | |
| 5794 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5795 | if (!SubExpr && E->getSubExpr()) |
| 5796 | return nullptr; |
| 5797 | |
| 5798 | return new (Importer.getToContext()) CXXThrowExpr( |
| 5799 | SubExpr, T, Importer.Import(E->getThrowLoc()), |
| 5800 | E->isThrownVariableInScope()); |
| 5801 | } |
| 5802 | |
| 5803 | Expr *ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5804 | auto *Param = cast_or_null<ParmVarDecl>(Importer.Import(E->getParam())); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5805 | if (!Param) |
| 5806 | return nullptr; |
| 5807 | |
| 5808 | return CXXDefaultArgExpr::Create( |
| 5809 | Importer.getToContext(), Importer.Import(E->getUsedLocation()), Param); |
| 5810 | } |
| 5811 | |
| 5812 | Expr *ASTNodeImporter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) { |
| 5813 | QualType T = Importer.Import(E->getType()); |
| 5814 | if (T.isNull()) |
| 5815 | return nullptr; |
| 5816 | |
| 5817 | TypeSourceInfo *TypeInfo = Importer.Import(E->getTypeSourceInfo()); |
| 5818 | if (!TypeInfo) |
| 5819 | return nullptr; |
| 5820 | |
| 5821 | return new (Importer.getToContext()) CXXScalarValueInitExpr( |
| 5822 | T, TypeInfo, Importer.Import(E->getRParenLoc())); |
| 5823 | } |
| 5824 | |
| 5825 | Expr *ASTNodeImporter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 5826 | Expr *SubExpr = Importer.Import(E->getSubExpr()); |
| 5827 | if (!SubExpr) |
| 5828 | return nullptr; |
| 5829 | |
| 5830 | auto *Dtor = cast_or_null<CXXDestructorDecl>( |
| 5831 | Importer.Import(const_cast<CXXDestructorDecl *>( |
| 5832 | E->getTemporary()->getDestructor()))); |
| 5833 | if (!Dtor) |
| 5834 | return nullptr; |
| 5835 | |
| 5836 | ASTContext &ToCtx = Importer.getToContext(); |
| 5837 | CXXTemporary *Temp = CXXTemporary::Create(ToCtx, Dtor); |
| 5838 | return CXXBindTemporaryExpr::Create(ToCtx, Temp, SubExpr); |
| 5839 | } |
| 5840 | |
| 5841 | Expr *ASTNodeImporter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE) { |
| 5842 | QualType T = Importer.Import(CE->getType()); |
| 5843 | if (T.isNull()) |
| 5844 | return nullptr; |
| 5845 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 5846 | TypeSourceInfo *TInfo = Importer.Import(CE->getTypeSourceInfo()); |
| 5847 | if (!TInfo) |
| 5848 | return nullptr; |
| 5849 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5850 | SmallVector<Expr *, 8> Args(CE->getNumArgs()); |
| 5851 | if (ImportContainerChecked(CE->arguments(), Args)) |
| 5852 | return nullptr; |
| 5853 | |
| 5854 | auto *Ctor = cast_or_null<CXXConstructorDecl>( |
| 5855 | Importer.Import(CE->getConstructor())); |
| 5856 | if (!Ctor) |
| 5857 | return nullptr; |
| 5858 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 5859 | return new (Importer.getToContext()) CXXTemporaryObjectExpr( |
| 5860 | Importer.getToContext(), Ctor, T, TInfo, Args, |
| 5861 | Importer.Import(CE->getParenOrBraceRange()), CE->hadMultipleCandidates(), |
| 5862 | CE->isListInitialization(), CE->isStdInitListInitialization(), |
| 5863 | CE->requiresZeroInitialization()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5864 | } |
| 5865 | |
| 5866 | Expr * |
| 5867 | ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) { |
| 5868 | QualType T = Importer.Import(E->getType()); |
| 5869 | if (T.isNull()) |
| 5870 | return nullptr; |
| 5871 | |
| 5872 | Expr *TempE = Importer.Import(E->GetTemporaryExpr()); |
| 5873 | if (!TempE) |
| 5874 | return nullptr; |
| 5875 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5876 | auto *ExtendedBy = cast_or_null<ValueDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5877 | Importer.Import(const_cast<ValueDecl *>(E->getExtendingDecl()))); |
| 5878 | if (!ExtendedBy && E->getExtendingDecl()) |
| 5879 | return nullptr; |
| 5880 | |
| 5881 | auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr( |
| 5882 | T, TempE, E->isBoundToLvalueReference()); |
| 5883 | |
| 5884 | // FIXME: Should ManglingNumber get numbers associated with 'to' context? |
| 5885 | ToMTE->setExtendingDecl(ExtendedBy, E->getManglingNumber()); |
| 5886 | return ToMTE; |
| 5887 | } |
| 5888 | |
Gabor Horvath | 7a91c08 | 2017-11-14 11:30:38 +0000 | [diff] [blame] | 5889 | Expr *ASTNodeImporter::VisitPackExpansionExpr(PackExpansionExpr *E) { |
| 5890 | QualType T = Importer.Import(E->getType()); |
| 5891 | if (T.isNull()) |
| 5892 | return nullptr; |
| 5893 | |
| 5894 | Expr *Pattern = Importer.Import(E->getPattern()); |
| 5895 | if (!Pattern) |
| 5896 | return nullptr; |
| 5897 | |
| 5898 | return new (Importer.getToContext()) PackExpansionExpr( |
| 5899 | T, Pattern, Importer.Import(E->getEllipsisLoc()), |
| 5900 | E->getNumExpansions()); |
| 5901 | } |
| 5902 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 5903 | Expr *ASTNodeImporter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { |
| 5904 | auto *Pack = cast_or_null<NamedDecl>(Importer.Import(E->getPack())); |
| 5905 | if (!Pack) |
| 5906 | return nullptr; |
| 5907 | |
| 5908 | Optional<unsigned> Length; |
| 5909 | |
| 5910 | if (!E->isValueDependent()) |
| 5911 | Length = E->getPackLength(); |
| 5912 | |
| 5913 | SmallVector<TemplateArgument, 8> PartialArguments; |
| 5914 | if (E->isPartiallySubstituted()) { |
| 5915 | if (ImportTemplateArguments(E->getPartialArguments().data(), |
| 5916 | E->getPartialArguments().size(), |
| 5917 | PartialArguments)) |
| 5918 | return nullptr; |
| 5919 | } |
| 5920 | |
| 5921 | return SizeOfPackExpr::Create( |
| 5922 | Importer.getToContext(), Importer.Import(E->getOperatorLoc()), Pack, |
| 5923 | Importer.Import(E->getPackLoc()), Importer.Import(E->getRParenLoc()), |
| 5924 | Length, PartialArguments); |
| 5925 | } |
| 5926 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5927 | Expr *ASTNodeImporter::VisitCXXNewExpr(CXXNewExpr *CE) { |
| 5928 | QualType T = Importer.Import(CE->getType()); |
| 5929 | if (T.isNull()) |
| 5930 | return nullptr; |
| 5931 | |
| 5932 | SmallVector<Expr *, 4> PlacementArgs(CE->getNumPlacementArgs()); |
| 5933 | if (ImportContainerChecked(CE->placement_arguments(), PlacementArgs)) |
| 5934 | return nullptr; |
| 5935 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5936 | auto *OperatorNewDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5937 | Importer.Import(CE->getOperatorNew())); |
| 5938 | if (!OperatorNewDecl && CE->getOperatorNew()) |
| 5939 | return nullptr; |
| 5940 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5941 | auto *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5942 | Importer.Import(CE->getOperatorDelete())); |
| 5943 | if (!OperatorDeleteDecl && CE->getOperatorDelete()) |
| 5944 | return nullptr; |
| 5945 | |
| 5946 | Expr *ToInit = Importer.Import(CE->getInitializer()); |
| 5947 | if (!ToInit && CE->getInitializer()) |
| 5948 | return nullptr; |
| 5949 | |
| 5950 | TypeSourceInfo *TInfo = Importer.Import(CE->getAllocatedTypeSourceInfo()); |
| 5951 | if (!TInfo) |
| 5952 | return nullptr; |
| 5953 | |
| 5954 | Expr *ToArrSize = Importer.Import(CE->getArraySize()); |
| 5955 | if (!ToArrSize && CE->getArraySize()) |
| 5956 | return nullptr; |
| 5957 | |
| 5958 | return new (Importer.getToContext()) CXXNewExpr( |
| 5959 | Importer.getToContext(), |
| 5960 | CE->isGlobalNew(), |
| 5961 | OperatorNewDecl, OperatorDeleteDecl, |
Richard Smith | b2f0f05 | 2016-10-10 18:54:32 +0000 | [diff] [blame] | 5962 | CE->passAlignment(), |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5963 | CE->doesUsualArrayDeleteWantSize(), |
| 5964 | PlacementArgs, |
| 5965 | Importer.Import(CE->getTypeIdParens()), |
| 5966 | ToArrSize, CE->getInitializationStyle(), ToInit, T, TInfo, |
| 5967 | Importer.Import(CE->getSourceRange()), |
| 5968 | Importer.Import(CE->getDirectInitRange())); |
| 5969 | } |
| 5970 | |
| 5971 | Expr *ASTNodeImporter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { |
| 5972 | QualType T = Importer.Import(E->getType()); |
| 5973 | if (T.isNull()) |
| 5974 | return nullptr; |
| 5975 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 5976 | auto *OperatorDeleteDecl = cast_or_null<FunctionDecl>( |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 5977 | Importer.Import(E->getOperatorDelete())); |
| 5978 | if (!OperatorDeleteDecl && E->getOperatorDelete()) |
| 5979 | return nullptr; |
| 5980 | |
| 5981 | Expr *ToArg = Importer.Import(E->getArgument()); |
| 5982 | if (!ToArg && E->getArgument()) |
| 5983 | return nullptr; |
| 5984 | |
| 5985 | return new (Importer.getToContext()) CXXDeleteExpr( |
| 5986 | T, E->isGlobalDelete(), |
| 5987 | E->isArrayForm(), |
| 5988 | E->isArrayFormAsWritten(), |
| 5989 | E->doesUsualArrayDeleteWantSize(), |
| 5990 | OperatorDeleteDecl, |
| 5991 | ToArg, |
| 5992 | Importer.Import(E->getLocStart())); |
Douglas Gregor | 5481d32 | 2010-02-19 01:32:14 +0000 | [diff] [blame] | 5993 | } |
| 5994 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 5995 | Expr *ASTNodeImporter::VisitCXXConstructExpr(CXXConstructExpr *E) { |
| 5996 | QualType T = Importer.Import(E->getType()); |
| 5997 | if (T.isNull()) |
| 5998 | return nullptr; |
| 5999 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6000 | auto *ToCCD = |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6001 | dyn_cast_or_null<CXXConstructorDecl>(Importer.Import(E->getConstructor())); |
Richard Smith | c2bebe9 | 2016-05-11 20:37:46 +0000 | [diff] [blame] | 6002 | if (!ToCCD) |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6003 | return nullptr; |
| 6004 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6005 | SmallVector<Expr *, 6> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6006 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6007 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6008 | |
| 6009 | return CXXConstructExpr::Create(Importer.getToContext(), T, |
| 6010 | Importer.Import(E->getLocation()), |
Richard Smith | c83bf82 | 2016-06-10 00:58:19 +0000 | [diff] [blame] | 6011 | ToCCD, E->isElidable(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6012 | ToArgs, E->hadMultipleCandidates(), |
| 6013 | E->isListInitialization(), |
| 6014 | E->isStdInitListInitialization(), |
| 6015 | E->requiresZeroInitialization(), |
| 6016 | E->getConstructionKind(), |
| 6017 | Importer.Import(E->getParenOrBraceRange())); |
| 6018 | } |
| 6019 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6020 | Expr *ASTNodeImporter::VisitExprWithCleanups(ExprWithCleanups *EWC) { |
| 6021 | Expr *SubExpr = Importer.Import(EWC->getSubExpr()); |
| 6022 | if (!SubExpr && EWC->getSubExpr()) |
| 6023 | return nullptr; |
| 6024 | |
| 6025 | SmallVector<ExprWithCleanups::CleanupObject, 8> Objs(EWC->getNumObjects()); |
| 6026 | for (unsigned I = 0, E = EWC->getNumObjects(); I < E; I++) |
| 6027 | if (ExprWithCleanups::CleanupObject Obj = |
| 6028 | cast_or_null<BlockDecl>(Importer.Import(EWC->getObject(I)))) |
| 6029 | Objs[I] = Obj; |
| 6030 | else |
| 6031 | return nullptr; |
| 6032 | |
| 6033 | return ExprWithCleanups::Create(Importer.getToContext(), |
| 6034 | SubExpr, EWC->cleanupsHaveSideEffects(), |
| 6035 | Objs); |
| 6036 | } |
| 6037 | |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6038 | Expr *ASTNodeImporter::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 6039 | QualType T = Importer.Import(E->getType()); |
| 6040 | if (T.isNull()) |
| 6041 | return nullptr; |
| 6042 | |
| 6043 | Expr *ToFn = Importer.Import(E->getCallee()); |
| 6044 | if (!ToFn) |
| 6045 | return nullptr; |
| 6046 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6047 | SmallVector<Expr *, 4> ToArgs(E->getNumArgs()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6048 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6049 | return nullptr; |
| 6050 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6051 | return new (Importer.getToContext()) CXXMemberCallExpr( |
| 6052 | Importer.getToContext(), ToFn, ToArgs, T, E->getValueKind(), |
| 6053 | Importer.Import(E->getRParenLoc())); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6054 | } |
| 6055 | |
| 6056 | Expr *ASTNodeImporter::VisitCXXThisExpr(CXXThisExpr *E) { |
| 6057 | QualType T = Importer.Import(E->getType()); |
| 6058 | if (T.isNull()) |
| 6059 | return nullptr; |
| 6060 | |
| 6061 | return new (Importer.getToContext()) |
| 6062 | CXXThisExpr(Importer.Import(E->getLocation()), T, E->isImplicit()); |
| 6063 | } |
| 6064 | |
| 6065 | Expr *ASTNodeImporter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 6066 | QualType T = Importer.Import(E->getType()); |
| 6067 | if (T.isNull()) |
| 6068 | return nullptr; |
| 6069 | |
| 6070 | return new (Importer.getToContext()) |
| 6071 | CXXBoolLiteralExpr(E->getValue(), T, Importer.Import(E->getLocation())); |
| 6072 | } |
| 6073 | |
| 6074 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6075 | Expr *ASTNodeImporter::VisitMemberExpr(MemberExpr *E) { |
| 6076 | QualType T = Importer.Import(E->getType()); |
| 6077 | if (T.isNull()) |
| 6078 | return nullptr; |
| 6079 | |
| 6080 | Expr *ToBase = Importer.Import(E->getBase()); |
| 6081 | if (!ToBase && E->getBase()) |
| 6082 | return nullptr; |
| 6083 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6084 | auto *ToMember = dyn_cast<ValueDecl>(Importer.Import(E->getMemberDecl())); |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6085 | if (!ToMember && E->getMemberDecl()) |
| 6086 | return nullptr; |
| 6087 | |
| 6088 | DeclAccessPair ToFoundDecl = DeclAccessPair::make( |
| 6089 | dyn_cast<NamedDecl>(Importer.Import(E->getFoundDecl().getDecl())), |
| 6090 | E->getFoundDecl().getAccess()); |
| 6091 | |
| 6092 | DeclarationNameInfo ToMemberNameInfo( |
| 6093 | Importer.Import(E->getMemberNameInfo().getName()), |
| 6094 | Importer.Import(E->getMemberNameInfo().getLoc())); |
| 6095 | |
| 6096 | if (E->hasExplicitTemplateArgs()) { |
| 6097 | return nullptr; // FIXME: handle template arguments |
| 6098 | } |
| 6099 | |
| 6100 | return MemberExpr::Create(Importer.getToContext(), ToBase, |
| 6101 | E->isArrow(), |
| 6102 | Importer.Import(E->getOperatorLoc()), |
| 6103 | Importer.Import(E->getQualifierLoc()), |
| 6104 | Importer.Import(E->getTemplateKeywordLoc()), |
| 6105 | ToMember, ToFoundDecl, ToMemberNameInfo, |
| 6106 | nullptr, T, E->getValueKind(), |
| 6107 | E->getObjectKind()); |
| 6108 | } |
| 6109 | |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 6110 | Expr *ASTNodeImporter::VisitCXXPseudoDestructorExpr( |
| 6111 | CXXPseudoDestructorExpr *E) { |
Aleksei Sidorin | 60ccb7d | 2017-11-27 10:30:00 +0000 | [diff] [blame] | 6112 | Expr *BaseE = Importer.Import(E->getBase()); |
| 6113 | if (!BaseE) |
| 6114 | return nullptr; |
| 6115 | |
| 6116 | TypeSourceInfo *ScopeInfo = Importer.Import(E->getScopeTypeInfo()); |
| 6117 | if (!ScopeInfo && E->getScopeTypeInfo()) |
| 6118 | return nullptr; |
| 6119 | |
| 6120 | PseudoDestructorTypeStorage Storage; |
| 6121 | if (IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) { |
| 6122 | IdentifierInfo *ToII = Importer.Import(FromII); |
| 6123 | if (!ToII) |
| 6124 | return nullptr; |
| 6125 | Storage = PseudoDestructorTypeStorage( |
| 6126 | ToII, Importer.Import(E->getDestroyedTypeLoc())); |
| 6127 | } else { |
| 6128 | TypeSourceInfo *TI = Importer.Import(E->getDestroyedTypeInfo()); |
| 6129 | if (!TI) |
| 6130 | return nullptr; |
| 6131 | Storage = PseudoDestructorTypeStorage(TI); |
| 6132 | } |
| 6133 | |
| 6134 | return new (Importer.getToContext()) CXXPseudoDestructorExpr( |
| 6135 | Importer.getToContext(), BaseE, E->isArrow(), |
| 6136 | Importer.Import(E->getOperatorLoc()), |
| 6137 | Importer.Import(E->getQualifierLoc()), |
| 6138 | ScopeInfo, Importer.Import(E->getColonColonLoc()), |
| 6139 | Importer.Import(E->getTildeLoc()), Storage); |
| 6140 | } |
| 6141 | |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6142 | Expr *ASTNodeImporter::VisitCXXDependentScopeMemberExpr( |
| 6143 | CXXDependentScopeMemberExpr *E) { |
| 6144 | Expr *Base = nullptr; |
| 6145 | if (!E->isImplicitAccess()) { |
| 6146 | Base = Importer.Import(E->getBase()); |
| 6147 | if (!Base) |
| 6148 | return nullptr; |
| 6149 | } |
| 6150 | |
| 6151 | QualType BaseType = Importer.Import(E->getBaseType()); |
| 6152 | if (BaseType.isNull()) |
| 6153 | return nullptr; |
| 6154 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6155 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6156 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6157 | if (ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6158 | E->template_arguments(), ToTAInfo)) |
Aleksei Sidorin | 7f758b6 | 2017-12-27 17:04:42 +0000 | [diff] [blame] | 6159 | return nullptr; |
| 6160 | ResInfo = &ToTAInfo; |
| 6161 | } |
| 6162 | |
| 6163 | DeclarationName Name = Importer.Import(E->getMember()); |
| 6164 | if (!E->getMember().isEmpty() && Name.isEmpty()) |
| 6165 | return nullptr; |
| 6166 | |
| 6167 | DeclarationNameInfo MemberNameInfo(Name, Importer.Import(E->getMemberLoc())); |
| 6168 | // Import additional name location/type info. |
| 6169 | ImportDeclarationNameLoc(E->getMemberNameInfo(), MemberNameInfo); |
| 6170 | auto ToFQ = Importer.Import(E->getFirstQualifierFoundInScope()); |
| 6171 | if (!ToFQ && E->getFirstQualifierFoundInScope()) |
| 6172 | return nullptr; |
| 6173 | |
| 6174 | return CXXDependentScopeMemberExpr::Create( |
| 6175 | Importer.getToContext(), Base, BaseType, E->isArrow(), |
| 6176 | Importer.Import(E->getOperatorLoc()), |
| 6177 | Importer.Import(E->getQualifierLoc()), |
| 6178 | Importer.Import(E->getTemplateKeywordLoc()), |
| 6179 | cast_or_null<NamedDecl>(ToFQ), MemberNameInfo, ResInfo); |
| 6180 | } |
| 6181 | |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6182 | Expr *ASTNodeImporter::VisitCXXUnresolvedConstructExpr( |
| 6183 | CXXUnresolvedConstructExpr *CE) { |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6184 | unsigned NumArgs = CE->arg_size(); |
| 6185 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6186 | SmallVector<Expr *, 8> ToArgs(NumArgs); |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6187 | if (ImportArrayChecked(CE->arg_begin(), CE->arg_end(), ToArgs.begin())) |
| 6188 | return nullptr; |
| 6189 | |
| 6190 | return CXXUnresolvedConstructExpr::Create( |
| 6191 | Importer.getToContext(), Importer.Import(CE->getTypeSourceInfo()), |
| 6192 | Importer.Import(CE->getLParenLoc()), llvm::makeArrayRef(ToArgs), |
| 6193 | Importer.Import(CE->getRParenLoc())); |
| 6194 | } |
| 6195 | |
| 6196 | Expr *ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6197 | auto *NamingClass = |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6198 | cast_or_null<CXXRecordDecl>(Importer.Import(E->getNamingClass())); |
| 6199 | if (E->getNamingClass() && !NamingClass) |
| 6200 | return nullptr; |
| 6201 | |
| 6202 | DeclarationName Name = Importer.Import(E->getName()); |
| 6203 | if (E->getName() && !Name) |
| 6204 | return nullptr; |
| 6205 | |
| 6206 | DeclarationNameInfo NameInfo(Name, Importer.Import(E->getNameLoc())); |
| 6207 | // Import additional name location/type info. |
| 6208 | ImportDeclarationNameLoc(E->getNameInfo(), NameInfo); |
| 6209 | |
| 6210 | UnresolvedSet<8> ToDecls; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6211 | for (auto *D : E->decls()) { |
| 6212 | if (auto *To = cast_or_null<NamedDecl>(Importer.Import(D))) |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6213 | ToDecls.addDecl(To); |
| 6214 | else |
| 6215 | return nullptr; |
| 6216 | } |
| 6217 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6218 | TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr; |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6219 | if (E->hasExplicitTemplateArgs()) { |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6220 | if (ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(), |
| 6221 | E->template_arguments(), ToTAInfo)) |
Aleksei Sidorin | e267a0f | 2018-01-09 16:40:40 +0000 | [diff] [blame] | 6222 | return nullptr; |
| 6223 | ResInfo = &ToTAInfo; |
| 6224 | } |
| 6225 | |
| 6226 | if (ResInfo || E->getTemplateKeywordLoc().isValid()) |
| 6227 | return UnresolvedLookupExpr::Create( |
| 6228 | Importer.getToContext(), NamingClass, |
| 6229 | Importer.Import(E->getQualifierLoc()), |
| 6230 | Importer.Import(E->getTemplateKeywordLoc()), NameInfo, E->requiresADL(), |
| 6231 | ResInfo, ToDecls.begin(), ToDecls.end()); |
| 6232 | |
| 6233 | return UnresolvedLookupExpr::Create( |
| 6234 | Importer.getToContext(), NamingClass, |
| 6235 | Importer.Import(E->getQualifierLoc()), NameInfo, E->requiresADL(), |
| 6236 | E->isOverloaded(), ToDecls.begin(), ToDecls.end()); |
| 6237 | } |
| 6238 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6239 | Expr *ASTNodeImporter::VisitCallExpr(CallExpr *E) { |
| 6240 | QualType T = Importer.Import(E->getType()); |
| 6241 | if (T.isNull()) |
| 6242 | return nullptr; |
| 6243 | |
| 6244 | Expr *ToCallee = Importer.Import(E->getCallee()); |
| 6245 | if (!ToCallee && E->getCallee()) |
| 6246 | return nullptr; |
| 6247 | |
| 6248 | unsigned NumArgs = E->getNumArgs(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6249 | SmallVector<Expr *, 2> ToArgs(NumArgs); |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6250 | if (ImportContainerChecked(E->arguments(), ToArgs)) |
| 6251 | return nullptr; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6252 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6253 | auto **ToArgs_Copied = new (Importer.getToContext()) Expr*[NumArgs]; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6254 | |
| 6255 | for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) |
| 6256 | ToArgs_Copied[ai] = ToArgs[ai]; |
| 6257 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6258 | if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) { |
| 6259 | return new (Importer.getToContext()) CXXOperatorCallExpr( |
| 6260 | Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, T, |
| 6261 | OCE->getValueKind(), Importer.Import(OCE->getRParenLoc()), |
| 6262 | OCE->getFPFeatures()); |
| 6263 | } |
| 6264 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6265 | return new (Importer.getToContext()) |
| 6266 | CallExpr(Importer.getToContext(), ToCallee, |
Craig Topper | c005cc0 | 2015-09-27 03:44:08 +0000 | [diff] [blame] | 6267 | llvm::makeArrayRef(ToArgs_Copied, NumArgs), T, E->getValueKind(), |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6268 | Importer.Import(E->getRParenLoc())); |
| 6269 | } |
| 6270 | |
Aleksei Sidorin | 8fc8510 | 2018-01-26 11:36:54 +0000 | [diff] [blame] | 6271 | Optional<LambdaCapture> |
| 6272 | ASTNodeImporter::ImportLambdaCapture(const LambdaCapture &From) { |
| 6273 | VarDecl *Var = nullptr; |
| 6274 | if (From.capturesVariable()) { |
| 6275 | Var = cast_or_null<VarDecl>(Importer.Import(From.getCapturedVar())); |
| 6276 | if (!Var) |
| 6277 | return None; |
| 6278 | } |
| 6279 | |
| 6280 | return LambdaCapture(Importer.Import(From.getLocation()), From.isImplicit(), |
| 6281 | From.getCaptureKind(), Var, |
| 6282 | From.isPackExpansion() |
| 6283 | ? Importer.Import(From.getEllipsisLoc()) |
| 6284 | : SourceLocation()); |
| 6285 | } |
| 6286 | |
| 6287 | Expr *ASTNodeImporter::VisitLambdaExpr(LambdaExpr *LE) { |
| 6288 | CXXRecordDecl *FromClass = LE->getLambdaClass(); |
| 6289 | auto *ToClass = dyn_cast_or_null<CXXRecordDecl>(Importer.Import(FromClass)); |
| 6290 | if (!ToClass) |
| 6291 | return nullptr; |
| 6292 | |
| 6293 | // NOTE: lambda classes are created with BeingDefined flag set up. |
| 6294 | // It means that ImportDefinition doesn't work for them and we should fill it |
| 6295 | // manually. |
| 6296 | if (ToClass->isBeingDefined()) { |
| 6297 | for (auto FromField : FromClass->fields()) { |
| 6298 | auto *ToField = cast_or_null<FieldDecl>(Importer.Import(FromField)); |
| 6299 | if (!ToField) |
| 6300 | return nullptr; |
| 6301 | } |
| 6302 | } |
| 6303 | |
| 6304 | auto *ToCallOp = dyn_cast_or_null<CXXMethodDecl>( |
| 6305 | Importer.Import(LE->getCallOperator())); |
| 6306 | if (!ToCallOp) |
| 6307 | return nullptr; |
| 6308 | |
| 6309 | ToClass->completeDefinition(); |
| 6310 | |
| 6311 | unsigned NumCaptures = LE->capture_size(); |
| 6312 | SmallVector<LambdaCapture, 8> Captures; |
| 6313 | Captures.reserve(NumCaptures); |
| 6314 | for (const auto &FromCapture : LE->captures()) { |
| 6315 | if (auto ToCapture = ImportLambdaCapture(FromCapture)) |
| 6316 | Captures.push_back(*ToCapture); |
| 6317 | else |
| 6318 | return nullptr; |
| 6319 | } |
| 6320 | |
| 6321 | SmallVector<Expr *, 8> InitCaptures(NumCaptures); |
| 6322 | if (ImportContainerChecked(LE->capture_inits(), InitCaptures)) |
| 6323 | return nullptr; |
| 6324 | |
| 6325 | return LambdaExpr::Create(Importer.getToContext(), ToClass, |
| 6326 | Importer.Import(LE->getIntroducerRange()), |
| 6327 | LE->getCaptureDefault(), |
| 6328 | Importer.Import(LE->getCaptureDefaultLoc()), |
| 6329 | Captures, |
| 6330 | LE->hasExplicitParameters(), |
| 6331 | LE->hasExplicitResultType(), |
| 6332 | InitCaptures, |
| 6333 | Importer.Import(LE->getLocEnd()), |
| 6334 | LE->containsUnexpandedParameterPack()); |
| 6335 | } |
| 6336 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6337 | Expr *ASTNodeImporter::VisitInitListExpr(InitListExpr *ILE) { |
| 6338 | QualType T = Importer.Import(ILE->getType()); |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6339 | if (T.isNull()) |
| 6340 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6341 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6342 | SmallVector<Expr *, 4> Exprs(ILE->getNumInits()); |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 6343 | if (ImportContainerChecked(ILE->inits(), Exprs)) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6344 | return nullptr; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6345 | |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6346 | ASTContext &ToCtx = Importer.getToContext(); |
| 6347 | InitListExpr *To = new (ToCtx) InitListExpr( |
| 6348 | ToCtx, Importer.Import(ILE->getLBraceLoc()), |
| 6349 | Exprs, Importer.Import(ILE->getLBraceLoc())); |
| 6350 | To->setType(T); |
| 6351 | |
| 6352 | if (ILE->hasArrayFiller()) { |
| 6353 | Expr *Filler = Importer.Import(ILE->getArrayFiller()); |
| 6354 | if (!Filler) |
| 6355 | return nullptr; |
| 6356 | To->setArrayFiller(Filler); |
| 6357 | } |
| 6358 | |
| 6359 | if (FieldDecl *FromFD = ILE->getInitializedFieldInUnion()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6360 | auto *ToFD = cast_or_null<FieldDecl>(Importer.Import(FromFD)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6361 | if (!ToFD) |
| 6362 | return nullptr; |
| 6363 | To->setInitializedFieldInUnion(ToFD); |
| 6364 | } |
| 6365 | |
| 6366 | if (InitListExpr *SyntForm = ILE->getSyntacticForm()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6367 | auto *ToSyntForm = cast_or_null<InitListExpr>(Importer.Import(SyntForm)); |
Artem Dergachev | 4e7c6fd | 2016-04-14 11:51:27 +0000 | [diff] [blame] | 6368 | if (!ToSyntForm) |
| 6369 | return nullptr; |
| 6370 | To->setSyntacticForm(ToSyntForm); |
| 6371 | } |
| 6372 | |
| 6373 | To->sawArrayRangeDesignator(ILE->hadArrayRangeDesignator()); |
| 6374 | To->setValueDependent(ILE->isValueDependent()); |
| 6375 | To->setInstantiationDependent(ILE->isInstantiationDependent()); |
| 6376 | |
| 6377 | return To; |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 6378 | } |
| 6379 | |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 6380 | Expr *ASTNodeImporter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 6381 | QualType ToType = Importer.Import(E->getType()); |
| 6382 | if (ToType.isNull()) |
| 6383 | return nullptr; |
| 6384 | |
| 6385 | Expr *ToCommon = Importer.Import(E->getCommonExpr()); |
| 6386 | if (!ToCommon && E->getCommonExpr()) |
| 6387 | return nullptr; |
| 6388 | |
| 6389 | Expr *ToSubExpr = Importer.Import(E->getSubExpr()); |
| 6390 | if (!ToSubExpr && E->getSubExpr()) |
| 6391 | return nullptr; |
| 6392 | |
| 6393 | return new (Importer.getToContext()) |
| 6394 | ArrayInitLoopExpr(ToType, ToCommon, ToSubExpr); |
| 6395 | } |
| 6396 | |
| 6397 | Expr *ASTNodeImporter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 6398 | QualType ToType = Importer.Import(E->getType()); |
| 6399 | if (ToType.isNull()) |
| 6400 | return nullptr; |
| 6401 | return new (Importer.getToContext()) ArrayInitIndexExpr(ToType); |
| 6402 | } |
| 6403 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6404 | Expr *ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6405 | auto *ToField = dyn_cast_or_null<FieldDecl>(Importer.Import(DIE->getField())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6406 | if (!ToField && DIE->getField()) |
| 6407 | return nullptr; |
| 6408 | |
| 6409 | return CXXDefaultInitExpr::Create( |
| 6410 | Importer.getToContext(), Importer.Import(DIE->getLocStart()), ToField); |
| 6411 | } |
| 6412 | |
| 6413 | Expr *ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 6414 | QualType ToType = Importer.Import(E->getType()); |
| 6415 | if (ToType.isNull() && !E->getType().isNull()) |
| 6416 | return nullptr; |
| 6417 | ExprValueKind VK = E->getValueKind(); |
| 6418 | CastKind CK = E->getCastKind(); |
| 6419 | Expr *ToOp = Importer.Import(E->getSubExpr()); |
| 6420 | if (!ToOp && E->getSubExpr()) |
| 6421 | return nullptr; |
| 6422 | CXXCastPath BasePath; |
| 6423 | if (ImportCastPath(E, BasePath)) |
| 6424 | return nullptr; |
| 6425 | TypeSourceInfo *ToWritten = Importer.Import(E->getTypeInfoAsWritten()); |
| 6426 | SourceLocation ToOperatorLoc = Importer.Import(E->getOperatorLoc()); |
| 6427 | SourceLocation ToRParenLoc = Importer.Import(E->getRParenLoc()); |
| 6428 | SourceRange ToAngleBrackets = Importer.Import(E->getAngleBrackets()); |
| 6429 | |
| 6430 | if (isa<CXXStaticCastExpr>(E)) { |
| 6431 | return CXXStaticCastExpr::Create( |
| 6432 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6433 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6434 | } else if (isa<CXXDynamicCastExpr>(E)) { |
| 6435 | return CXXDynamicCastExpr::Create( |
| 6436 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6437 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6438 | } else if (isa<CXXReinterpretCastExpr>(E)) { |
| 6439 | return CXXReinterpretCastExpr::Create( |
| 6440 | Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, |
| 6441 | ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); |
| 6442 | } else { |
| 6443 | return nullptr; |
| 6444 | } |
| 6445 | } |
| 6446 | |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6447 | Expr *ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr( |
| 6448 | SubstNonTypeTemplateParmExpr *E) { |
| 6449 | QualType T = Importer.Import(E->getType()); |
| 6450 | if (T.isNull()) |
| 6451 | return nullptr; |
| 6452 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6453 | auto *Param = cast_or_null<NonTypeTemplateParmDecl>( |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6454 | Importer.Import(E->getParameter())); |
| 6455 | if (!Param) |
| 6456 | return nullptr; |
| 6457 | |
| 6458 | Expr *Replacement = Importer.Import(E->getReplacement()); |
| 6459 | if (!Replacement) |
| 6460 | return nullptr; |
| 6461 | |
| 6462 | return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr( |
| 6463 | T, E->getValueKind(), Importer.Import(E->getExprLoc()), Param, |
| 6464 | Replacement); |
| 6465 | } |
| 6466 | |
Aleksei Sidorin | b05f37a | 2017-11-26 17:04:06 +0000 | [diff] [blame] | 6467 | Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) { |
| 6468 | QualType ToType = Importer.Import(E->getType()); |
| 6469 | if (ToType.isNull()) |
| 6470 | return nullptr; |
| 6471 | |
| 6472 | SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs()); |
| 6473 | if (ImportContainerChecked(E->getArgs(), ToArgs)) |
| 6474 | return nullptr; |
| 6475 | |
| 6476 | // According to Sema::BuildTypeTrait(), if E is value-dependent, |
| 6477 | // Value is always false. |
| 6478 | bool ToValue = false; |
| 6479 | if (!E->isValueDependent()) |
| 6480 | ToValue = E->getValue(); |
| 6481 | |
| 6482 | return TypeTraitExpr::Create( |
| 6483 | Importer.getToContext(), ToType, Importer.Import(E->getLocStart()), |
| 6484 | E->getTrait(), ToArgs, Importer.Import(E->getLocEnd()), ToValue); |
| 6485 | } |
| 6486 | |
Gabor Horvath | c78d99a | 2018-01-27 16:11:45 +0000 | [diff] [blame] | 6487 | Expr *ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) { |
| 6488 | QualType ToType = Importer.Import(E->getType()); |
| 6489 | if (ToType.isNull()) |
| 6490 | return nullptr; |
| 6491 | |
| 6492 | if (E->isTypeOperand()) { |
| 6493 | TypeSourceInfo *TSI = Importer.Import(E->getTypeOperandSourceInfo()); |
| 6494 | if (!TSI) |
| 6495 | return nullptr; |
| 6496 | |
| 6497 | return new (Importer.getToContext()) |
| 6498 | CXXTypeidExpr(ToType, TSI, Importer.Import(E->getSourceRange())); |
| 6499 | } |
| 6500 | |
| 6501 | Expr *Op = Importer.Import(E->getExprOperand()); |
| 6502 | if (!Op) |
| 6503 | return nullptr; |
| 6504 | |
| 6505 | return new (Importer.getToContext()) |
| 6506 | CXXTypeidExpr(ToType, Op, Importer.Import(E->getSourceRange())); |
| 6507 | } |
| 6508 | |
Lang Hames | 19e07e1 | 2017-06-20 21:06:00 +0000 | [diff] [blame] | 6509 | void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod, |
| 6510 | CXXMethodDecl *FromMethod) { |
| 6511 | for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) |
| 6512 | ToMethod->addOverriddenMethod( |
| 6513 | cast<CXXMethodDecl>(Importer.Import(const_cast<CXXMethodDecl*>( |
| 6514 | FromOverriddenMethod)))); |
| 6515 | } |
| 6516 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6517 | ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 6518 | ASTContext &FromContext, FileManager &FromFileManager, |
| 6519 | bool MinimalImport) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6520 | : ToContext(ToContext), FromContext(FromContext), |
| 6521 | ToFileManager(ToFileManager), FromFileManager(FromFileManager), |
| 6522 | Minimal(MinimalImport) { |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6523 | ImportedDecls[FromContext.getTranslationUnitDecl()] |
| 6524 | = ToContext.getTranslationUnitDecl(); |
| 6525 | } |
| 6526 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6527 | ASTImporter::~ASTImporter() = default; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6528 | |
| 6529 | QualType ASTImporter::Import(QualType FromT) { |
| 6530 | if (FromT.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6531 | return {}; |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6532 | |
| 6533 | const Type *fromTy = FromT.getTypePtr(); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6534 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6535 | // Check whether we've already imported this type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6536 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
| 6537 | = ImportedTypes.find(fromTy); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6538 | if (Pos != ImportedTypes.end()) |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6539 | return ToContext.getQualifiedType(Pos->second, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6540 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6541 | // Import the type |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6542 | ASTNodeImporter Importer(*this); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6543 | QualType ToT = Importer.Visit(fromTy); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6544 | if (ToT.isNull()) |
| 6545 | return ToT; |
| 6546 | |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6547 | // Record the imported type. |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6548 | ImportedTypes[fromTy] = ToT.getTypePtr(); |
Douglas Gregor | f65bbb3 | 2010-02-08 15:18:58 +0000 | [diff] [blame] | 6549 | |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 6550 | return ToContext.getQualifiedType(ToT, FromT.getLocalQualifiers()); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 6551 | } |
| 6552 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6553 | TypeSourceInfo *ASTImporter::Import(TypeSourceInfo *FromTSI) { |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 6554 | if (!FromTSI) |
| 6555 | return FromTSI; |
| 6556 | |
| 6557 | // FIXME: For now we just create a "trivial" type source info based |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 6558 | // 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] | 6559 | QualType T = Import(FromTSI->getType()); |
| 6560 | if (T.isNull()) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6561 | return nullptr; |
Douglas Gregor | fa7a0e5 | 2010-02-10 17:47:19 +0000 | [diff] [blame] | 6562 | |
| 6563 | return ToContext.getTrivialTypeSourceInfo(T, |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6564 | Import(FromTSI->getTypeLoc().getLocStart())); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6565 | } |
| 6566 | |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6567 | Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) { |
| 6568 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
| 6569 | if (Pos != ImportedDecls.end()) { |
| 6570 | Decl *ToD = Pos->second; |
| 6571 | ASTNodeImporter(*this).ImportDefinitionIfNeeded(FromD, ToD); |
| 6572 | return ToD; |
| 6573 | } else { |
| 6574 | return nullptr; |
| 6575 | } |
| 6576 | } |
| 6577 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6578 | Decl *ASTImporter::Import(Decl *FromD) { |
| 6579 | if (!FromD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6580 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6581 | |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6582 | ASTNodeImporter Importer(*this); |
| 6583 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6584 | // Check whether we've already imported this declaration. |
| 6585 | llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(FromD); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 6586 | if (Pos != ImportedDecls.end()) { |
| 6587 | Decl *ToD = Pos->second; |
| 6588 | Importer.ImportDefinitionIfNeeded(FromD, ToD); |
| 6589 | return ToD; |
| 6590 | } |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6591 | |
| 6592 | // Import the type |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6593 | Decl *ToD = Importer.Visit(FromD); |
| 6594 | if (!ToD) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6595 | return nullptr; |
| 6596 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6597 | // Record the imported declaration. |
| 6598 | ImportedDecls[FromD] = ToD; |
Aleksei Sidorin | 04fbffc | 2018-04-24 10:11:53 +0000 | [diff] [blame] | 6599 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6600 | return ToD; |
| 6601 | } |
| 6602 | |
| 6603 | DeclContext *ASTImporter::ImportContext(DeclContext *FromDC) { |
| 6604 | if (!FromDC) |
| 6605 | return FromDC; |
| 6606 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6607 | auto *ToDC = cast_or_null<DeclContext>(Import(cast<Decl>(FromDC))); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6608 | if (!ToDC) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6609 | return nullptr; |
| 6610 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6611 | // When we're using a record/enum/Objective-C class/protocol as a context, we |
| 6612 | // need it to have a definition. |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6613 | if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) { |
| 6614 | auto *FromRecord = cast<RecordDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6615 | if (ToRecord->isCompleteDefinition()) { |
| 6616 | // Do nothing. |
| 6617 | } else if (FromRecord->isCompleteDefinition()) { |
| 6618 | ASTNodeImporter(*this).ImportDefinition(FromRecord, ToRecord, |
| 6619 | ASTNodeImporter::IDK_Basic); |
| 6620 | } else { |
| 6621 | CompleteDecl(ToRecord); |
| 6622 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6623 | } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) { |
| 6624 | auto *FromEnum = cast<EnumDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6625 | if (ToEnum->isCompleteDefinition()) { |
| 6626 | // Do nothing. |
| 6627 | } else if (FromEnum->isCompleteDefinition()) { |
| 6628 | ASTNodeImporter(*this).ImportDefinition(FromEnum, ToEnum, |
| 6629 | ASTNodeImporter::IDK_Basic); |
| 6630 | } else { |
| 6631 | CompleteDecl(ToEnum); |
| 6632 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6633 | } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) { |
| 6634 | auto *FromClass = cast<ObjCInterfaceDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6635 | if (ToClass->getDefinition()) { |
| 6636 | // Do nothing. |
| 6637 | } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { |
| 6638 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToClass, |
| 6639 | ASTNodeImporter::IDK_Basic); |
| 6640 | } else { |
| 6641 | CompleteDecl(ToClass); |
| 6642 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6643 | } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) { |
| 6644 | auto *FromProto = cast<ObjCProtocolDecl>(FromDC); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 6645 | if (ToProto->getDefinition()) { |
| 6646 | // Do nothing. |
| 6647 | } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { |
| 6648 | ASTNodeImporter(*this).ImportDefinition(FromDef, ToProto, |
| 6649 | ASTNodeImporter::IDK_Basic); |
| 6650 | } else { |
| 6651 | CompleteDecl(ToProto); |
| 6652 | } |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 6653 | } |
| 6654 | |
| 6655 | return ToDC; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6656 | } |
| 6657 | |
| 6658 | Expr *ASTImporter::Import(Expr *FromE) { |
| 6659 | if (!FromE) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6660 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6661 | |
| 6662 | return cast_or_null<Expr>(Import(cast<Stmt>(FromE))); |
| 6663 | } |
| 6664 | |
| 6665 | Stmt *ASTImporter::Import(Stmt *FromS) { |
| 6666 | if (!FromS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6667 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6668 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6669 | // Check whether we've already imported this declaration. |
| 6670 | llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS); |
| 6671 | if (Pos != ImportedStmts.end()) |
| 6672 | return Pos->second; |
| 6673 | |
| 6674 | // Import the type |
| 6675 | ASTNodeImporter Importer(*this); |
| 6676 | Stmt *ToS = Importer.Visit(FromS); |
| 6677 | if (!ToS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6678 | return nullptr; |
| 6679 | |
Douglas Gregor | 7eeb597 | 2010-02-11 19:21:55 +0000 | [diff] [blame] | 6680 | // Record the imported declaration. |
| 6681 | ImportedStmts[FromS] = ToS; |
| 6682 | return ToS; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6683 | } |
| 6684 | |
| 6685 | NestedNameSpecifier *ASTImporter::Import(NestedNameSpecifier *FromNNS) { |
| 6686 | if (!FromNNS) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6687 | return nullptr; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6688 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6689 | NestedNameSpecifier *prefix = Import(FromNNS->getPrefix()); |
| 6690 | |
| 6691 | switch (FromNNS->getKind()) { |
| 6692 | case NestedNameSpecifier::Identifier: |
| 6693 | if (IdentifierInfo *II = Import(FromNNS->getAsIdentifier())) { |
| 6694 | return NestedNameSpecifier::Create(ToContext, prefix, II); |
| 6695 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6696 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6697 | |
| 6698 | case NestedNameSpecifier::Namespace: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6699 | if (auto *NS = |
| 6700 | cast_or_null<NamespaceDecl>(Import(FromNNS->getAsNamespace()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6701 | return NestedNameSpecifier::Create(ToContext, prefix, NS); |
| 6702 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6703 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6704 | |
| 6705 | case NestedNameSpecifier::NamespaceAlias: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6706 | if (auto *NSAD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6707 | cast_or_null<NamespaceAliasDecl>(Import(FromNNS->getAsNamespaceAlias()))) { |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6708 | return NestedNameSpecifier::Create(ToContext, prefix, NSAD); |
| 6709 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6710 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6711 | |
| 6712 | case NestedNameSpecifier::Global: |
| 6713 | return NestedNameSpecifier::GlobalSpecifier(ToContext); |
| 6714 | |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 6715 | case NestedNameSpecifier::Super: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6716 | if (auto *RD = |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6717 | cast_or_null<CXXRecordDecl>(Import(FromNNS->getAsRecordDecl()))) { |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 6718 | return NestedNameSpecifier::SuperSpecifier(ToContext, RD); |
| 6719 | } |
| 6720 | return nullptr; |
| 6721 | |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6722 | case NestedNameSpecifier::TypeSpec: |
| 6723 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 6724 | QualType T = Import(QualType(FromNNS->getAsType(), 0u)); |
| 6725 | if (!T.isNull()) { |
| 6726 | bool bTemplate = FromNNS->getKind() == |
| 6727 | NestedNameSpecifier::TypeSpecWithTemplate; |
| 6728 | return NestedNameSpecifier::Create(ToContext, prefix, |
| 6729 | bTemplate, T.getTypePtr()); |
| 6730 | } |
| 6731 | } |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 6732 | return nullptr; |
Douglas Gregor | 90ebf25 | 2011-04-27 16:48:40 +0000 | [diff] [blame] | 6733 | } |
| 6734 | |
| 6735 | llvm_unreachable("Invalid nested name specifier kind"); |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6736 | } |
| 6737 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 6738 | NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) { |
Aleksei Sidorin | 855086d | 2017-01-23 09:30:36 +0000 | [diff] [blame] | 6739 | // Copied from NestedNameSpecifier mostly. |
| 6740 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; |
| 6741 | NestedNameSpecifierLoc NNS = FromNNS; |
| 6742 | |
| 6743 | // Push each of the nested-name-specifiers's onto a stack for |
| 6744 | // serialization in reverse order. |
| 6745 | while (NNS) { |
| 6746 | NestedNames.push_back(NNS); |
| 6747 | NNS = NNS.getPrefix(); |
| 6748 | } |
| 6749 | |
| 6750 | NestedNameSpecifierLocBuilder Builder; |
| 6751 | |
| 6752 | while (!NestedNames.empty()) { |
| 6753 | NNS = NestedNames.pop_back_val(); |
| 6754 | NestedNameSpecifier *Spec = Import(NNS.getNestedNameSpecifier()); |
| 6755 | if (!Spec) |
| 6756 | return NestedNameSpecifierLoc(); |
| 6757 | |
| 6758 | NestedNameSpecifier::SpecifierKind Kind = Spec->getKind(); |
| 6759 | switch (Kind) { |
| 6760 | case NestedNameSpecifier::Identifier: |
| 6761 | Builder.Extend(getToContext(), |
| 6762 | Spec->getAsIdentifier(), |
| 6763 | Import(NNS.getLocalBeginLoc()), |
| 6764 | Import(NNS.getLocalEndLoc())); |
| 6765 | break; |
| 6766 | |
| 6767 | case NestedNameSpecifier::Namespace: |
| 6768 | Builder.Extend(getToContext(), |
| 6769 | Spec->getAsNamespace(), |
| 6770 | Import(NNS.getLocalBeginLoc()), |
| 6771 | Import(NNS.getLocalEndLoc())); |
| 6772 | break; |
| 6773 | |
| 6774 | case NestedNameSpecifier::NamespaceAlias: |
| 6775 | Builder.Extend(getToContext(), |
| 6776 | Spec->getAsNamespaceAlias(), |
| 6777 | Import(NNS.getLocalBeginLoc()), |
| 6778 | Import(NNS.getLocalEndLoc())); |
| 6779 | break; |
| 6780 | |
| 6781 | case NestedNameSpecifier::TypeSpec: |
| 6782 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 6783 | TypeSourceInfo *TSI = getToContext().getTrivialTypeSourceInfo( |
| 6784 | QualType(Spec->getAsType(), 0)); |
| 6785 | Builder.Extend(getToContext(), |
| 6786 | Import(NNS.getLocalBeginLoc()), |
| 6787 | TSI->getTypeLoc(), |
| 6788 | Import(NNS.getLocalEndLoc())); |
| 6789 | break; |
| 6790 | } |
| 6791 | |
| 6792 | case NestedNameSpecifier::Global: |
| 6793 | Builder.MakeGlobal(getToContext(), Import(NNS.getLocalBeginLoc())); |
| 6794 | break; |
| 6795 | |
| 6796 | case NestedNameSpecifier::Super: { |
| 6797 | SourceRange ToRange = Import(NNS.getSourceRange()); |
| 6798 | Builder.MakeSuper(getToContext(), |
| 6799 | Spec->getAsRecordDecl(), |
| 6800 | ToRange.getBegin(), |
| 6801 | ToRange.getEnd()); |
| 6802 | } |
| 6803 | } |
| 6804 | } |
| 6805 | |
| 6806 | return Builder.getWithLocInContext(getToContext()); |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 6807 | } |
| 6808 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6809 | TemplateName ASTImporter::Import(TemplateName From) { |
| 6810 | switch (From.getKind()) { |
| 6811 | case TemplateName::Template: |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6812 | if (auto *ToTemplate = |
| 6813 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6814 | return TemplateName(ToTemplate); |
| 6815 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6816 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6817 | |
| 6818 | case TemplateName::OverloadedTemplate: { |
| 6819 | OverloadedTemplateStorage *FromStorage = From.getAsOverloadedTemplate(); |
| 6820 | UnresolvedSet<2> ToTemplates; |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6821 | for (auto *I : *FromStorage) { |
| 6822 | if (auto *To = cast_or_null<NamedDecl>(Import(I))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6823 | ToTemplates.addDecl(To); |
| 6824 | else |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6825 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6826 | } |
| 6827 | return ToContext.getOverloadedTemplateName(ToTemplates.begin(), |
| 6828 | ToTemplates.end()); |
| 6829 | } |
| 6830 | |
| 6831 | case TemplateName::QualifiedTemplate: { |
| 6832 | QualifiedTemplateName *QTN = From.getAsQualifiedTemplateName(); |
| 6833 | NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); |
| 6834 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6835 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6836 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6837 | if (auto *ToTemplate = |
| 6838 | cast_or_null<TemplateDecl>(Import(From.getAsTemplateDecl()))) |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6839 | return ToContext.getQualifiedTemplateName(Qualifier, |
| 6840 | QTN->hasTemplateKeyword(), |
| 6841 | ToTemplate); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6842 | |
| 6843 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6844 | } |
| 6845 | |
| 6846 | case TemplateName::DependentTemplate: { |
| 6847 | DependentTemplateName *DTN = From.getAsDependentTemplateName(); |
| 6848 | NestedNameSpecifier *Qualifier = Import(DTN->getQualifier()); |
| 6849 | if (!Qualifier) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6850 | return {}; |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6851 | |
| 6852 | if (DTN->isIdentifier()) { |
| 6853 | return ToContext.getDependentTemplateName(Qualifier, |
| 6854 | Import(DTN->getIdentifier())); |
| 6855 | } |
| 6856 | |
| 6857 | return ToContext.getDependentTemplateName(Qualifier, DTN->getOperator()); |
| 6858 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6859 | |
| 6860 | case TemplateName::SubstTemplateTemplateParm: { |
| 6861 | SubstTemplateTemplateParmStorage *subst |
| 6862 | = From.getAsSubstTemplateTemplateParm(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6863 | auto *param = |
| 6864 | cast_or_null<TemplateTemplateParmDecl>(Import(subst->getParameter())); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6865 | if (!param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6866 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6867 | |
| 6868 | TemplateName replacement = Import(subst->getReplacement()); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6869 | if (replacement.isNull()) |
| 6870 | return {}; |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 6871 | |
| 6872 | return ToContext.getSubstTemplateTemplateParm(param, replacement); |
| 6873 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6874 | |
| 6875 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 6876 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 6877 | = From.getAsSubstTemplateTemplateParmPack(); |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6878 | auto *Param = |
| 6879 | cast_or_null<TemplateTemplateParmDecl>( |
| 6880 | Import(SubstPack->getParameterPack())); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6881 | if (!Param) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6882 | return {}; |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6883 | |
| 6884 | ASTNodeImporter Importer(*this); |
| 6885 | TemplateArgument ArgPack |
| 6886 | = Importer.ImportTemplateArgument(SubstPack->getArgumentPack()); |
| 6887 | if (ArgPack.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6888 | return {}; |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6889 | |
| 6890 | return ToContext.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 6891 | } |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6892 | } |
| 6893 | |
| 6894 | llvm_unreachable("Invalid template name kind"); |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 6895 | } |
| 6896 | |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6897 | SourceLocation ASTImporter::Import(SourceLocation FromLoc) { |
| 6898 | if (FromLoc.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6899 | return {}; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6900 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6901 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 6902 | |
Sean Callanan | 24c5fe6 | 2016-11-07 20:42:25 +0000 | [diff] [blame] | 6903 | // For now, map everything down to its file location, so that we |
Chandler Carruth | 2536641 | 2011-07-15 00:04:35 +0000 | [diff] [blame] | 6904 | // don't have to import macro expansions. |
| 6905 | // FIXME: Import macro expansions! |
Sean Callanan | 24c5fe6 | 2016-11-07 20:42:25 +0000 | [diff] [blame] | 6906 | FromLoc = FromSM.getFileLoc(FromLoc); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6907 | std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc); |
| 6908 | SourceManager &ToSM = ToContext.getSourceManager(); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 6909 | FileID ToFileID = Import(Decomposed.first); |
| 6910 | if (ToFileID.isInvalid()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6911 | return {}; |
Sean Callanan | 59721b3 | 2015-04-28 18:41:46 +0000 | [diff] [blame] | 6912 | SourceLocation ret = ToSM.getLocForStartOfFile(ToFileID) |
| 6913 | .getLocWithOffset(Decomposed.second); |
| 6914 | return ret; |
Douglas Gregor | 62d311f | 2010-02-09 19:21:46 +0000 | [diff] [blame] | 6915 | } |
| 6916 | |
| 6917 | SourceRange ASTImporter::Import(SourceRange FromRange) { |
| 6918 | return SourceRange(Import(FromRange.getBegin()), Import(FromRange.getEnd())); |
| 6919 | } |
| 6920 | |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6921 | FileID ASTImporter::Import(FileID FromID) { |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 6922 | llvm::DenseMap<FileID, FileID>::iterator Pos |
| 6923 | = ImportedFileIDs.find(FromID); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6924 | if (Pos != ImportedFileIDs.end()) |
| 6925 | return Pos->second; |
| 6926 | |
| 6927 | SourceManager &FromSM = FromContext.getSourceManager(); |
| 6928 | SourceManager &ToSM = ToContext.getSourceManager(); |
| 6929 | const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID); |
Chandler Carruth | 2536641 | 2011-07-15 00:04:35 +0000 | [diff] [blame] | 6930 | assert(FromSLoc.isFile() && "Cannot handle macro expansions yet"); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6931 | |
| 6932 | // Include location of this file. |
| 6933 | SourceLocation ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc()); |
| 6934 | |
| 6935 | // Map the FileID for to the "to" source manager. |
| 6936 | FileID ToID; |
| 6937 | const SrcMgr::ContentCache *Cache = FromSLoc.getFile().getContentCache(); |
Sean Callanan | 25d34af | 2015-04-30 00:44:21 +0000 | [diff] [blame] | 6938 | if (Cache->OrigEntry && Cache->OrigEntry->getDir()) { |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6939 | // FIXME: We probably want to use getVirtualFile(), so we don't hit the |
| 6940 | // disk again |
| 6941 | // FIXME: We definitely want to re-use the existing MemoryBuffer, rather |
| 6942 | // than mmap the files several times. |
Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 6943 | const FileEntry *Entry = ToFileManager.getFile(Cache->OrigEntry->getName()); |
Sean Callanan | 238d897 | 2014-12-10 01:26:39 +0000 | [diff] [blame] | 6944 | if (!Entry) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6945 | return {}; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6946 | ToID = ToSM.createFileID(Entry, ToIncludeLoc, |
| 6947 | FromSLoc.getFile().getFileCharacteristic()); |
| 6948 | } else { |
| 6949 | // FIXME: We want to re-use the existing MemoryBuffer! |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6950 | const llvm::MemoryBuffer * |
| 6951 | FromBuf = Cache->getBuffer(FromContext.getDiagnostics(), FromSM); |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 6952 | std::unique_ptr<llvm::MemoryBuffer> ToBuf |
Chris Lattner | 58c7934 | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 6953 | = llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6954 | FromBuf->getBufferIdentifier()); |
David Blaikie | 50a5f97 | 2014-08-29 07:59:55 +0000 | [diff] [blame] | 6955 | ToID = ToSM.createFileID(std::move(ToBuf), |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 6956 | FromSLoc.getFile().getFileCharacteristic()); |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6957 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6958 | |
Sebastian Redl | 99219f1 | 2010-09-30 01:03:06 +0000 | [diff] [blame] | 6959 | ImportedFileIDs[FromID] = ToID; |
Douglas Gregor | 811663e | 2010-02-10 00:15:17 +0000 | [diff] [blame] | 6960 | return ToID; |
| 6961 | } |
| 6962 | |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6963 | CXXCtorInitializer *ASTImporter::Import(CXXCtorInitializer *From) { |
| 6964 | Expr *ToExpr = Import(From->getInit()); |
| 6965 | if (!ToExpr && From->getInit()) |
| 6966 | return nullptr; |
| 6967 | |
| 6968 | if (From->isBaseInitializer()) { |
| 6969 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 6970 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 6971 | return nullptr; |
| 6972 | |
| 6973 | return new (ToContext) CXXCtorInitializer( |
| 6974 | ToContext, ToTInfo, From->isBaseVirtual(), Import(From->getLParenLoc()), |
| 6975 | ToExpr, Import(From->getRParenLoc()), |
| 6976 | From->isPackExpansion() ? Import(From->getEllipsisLoc()) |
| 6977 | : SourceLocation()); |
| 6978 | } else if (From->isMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6979 | auto *ToField = cast_or_null<FieldDecl>(Import(From->getMember())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6980 | if (!ToField && From->getMember()) |
| 6981 | return nullptr; |
| 6982 | |
| 6983 | return new (ToContext) CXXCtorInitializer( |
| 6984 | ToContext, ToField, Import(From->getMemberLocation()), |
| 6985 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 6986 | } else if (From->isIndirectMemberInitializer()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 6987 | auto *ToIField = cast_or_null<IndirectFieldDecl>( |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 6988 | Import(From->getIndirectMember())); |
| 6989 | if (!ToIField && From->getIndirectMember()) |
| 6990 | return nullptr; |
| 6991 | |
| 6992 | return new (ToContext) CXXCtorInitializer( |
| 6993 | ToContext, ToIField, Import(From->getMemberLocation()), |
| 6994 | Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); |
| 6995 | } else if (From->isDelegatingInitializer()) { |
| 6996 | TypeSourceInfo *ToTInfo = Import(From->getTypeSourceInfo()); |
| 6997 | if (!ToTInfo && From->getTypeSourceInfo()) |
| 6998 | return nullptr; |
| 6999 | |
| 7000 | return new (ToContext) |
| 7001 | CXXCtorInitializer(ToContext, ToTInfo, Import(From->getLParenLoc()), |
| 7002 | ToExpr, Import(From->getRParenLoc())); |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7003 | } else { |
| 7004 | return nullptr; |
| 7005 | } |
| 7006 | } |
| 7007 | |
Aleksei Sidorin | a693b37 | 2016-09-28 10:16:56 +0000 | [diff] [blame] | 7008 | CXXBaseSpecifier *ASTImporter::Import(const CXXBaseSpecifier *BaseSpec) { |
| 7009 | auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec); |
| 7010 | if (Pos != ImportedCXXBaseSpecifiers.end()) |
| 7011 | return Pos->second; |
| 7012 | |
| 7013 | CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier( |
| 7014 | Import(BaseSpec->getSourceRange()), |
| 7015 | BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(), |
| 7016 | BaseSpec->getAccessSpecifierAsWritten(), |
| 7017 | Import(BaseSpec->getTypeSourceInfo()), |
| 7018 | Import(BaseSpec->getEllipsisLoc())); |
| 7019 | ImportedCXXBaseSpecifiers[BaseSpec] = Imported; |
| 7020 | return Imported; |
| 7021 | } |
| 7022 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7023 | void ASTImporter::ImportDefinition(Decl *From) { |
| 7024 | Decl *To = Import(From); |
| 7025 | if (!To) |
| 7026 | return; |
| 7027 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7028 | if (auto *FromDC = cast<DeclContext>(From)) { |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7029 | ASTNodeImporter Importer(*this); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7030 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7031 | if (auto *ToRecord = dyn_cast<RecordDecl>(To)) { |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7032 | if (!ToRecord->getDefinition()) { |
| 7033 | Importer.ImportDefinition(cast<RecordDecl>(FromDC), ToRecord, |
Douglas Gregor | 95d8283 | 2012-01-24 18:36:04 +0000 | [diff] [blame] | 7034 | ASTNodeImporter::IDK_Everything); |
Sean Callanan | 53a6bff | 2011-07-19 22:38:25 +0000 | [diff] [blame] | 7035 | return; |
| 7036 | } |
| 7037 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7038 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7039 | if (auto *ToEnum = dyn_cast<EnumDecl>(To)) { |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7040 | if (!ToEnum->getDefinition()) { |
| 7041 | Importer.ImportDefinition(cast<EnumDecl>(FromDC), ToEnum, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7042 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7043 | return; |
| 7044 | } |
| 7045 | } |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7046 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7047 | if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7048 | if (!ToIFace->getDefinition()) { |
| 7049 | Importer.ImportDefinition(cast<ObjCInterfaceDecl>(FromDC), ToIFace, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7050 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7051 | return; |
| 7052 | } |
| 7053 | } |
Douglas Gregor | d451ea9 | 2011-07-29 23:31:30 +0000 | [diff] [blame] | 7054 | |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7055 | if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) { |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7056 | if (!ToProto->getDefinition()) { |
| 7057 | Importer.ImportDefinition(cast<ObjCProtocolDecl>(FromDC), ToProto, |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7058 | ASTNodeImporter::IDK_Everything); |
Douglas Gregor | 2aa5377 | 2012-01-24 17:42:07 +0000 | [diff] [blame] | 7059 | return; |
| 7060 | } |
| 7061 | } |
| 7062 | |
Douglas Gregor | 0a79167 | 2011-01-18 03:11:38 +0000 | [diff] [blame] | 7063 | Importer.ImportDeclContext(FromDC, true); |
| 7064 | } |
| 7065 | } |
| 7066 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7067 | DeclarationName ASTImporter::Import(DeclarationName FromName) { |
| 7068 | if (!FromName) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7069 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7070 | |
| 7071 | switch (FromName.getNameKind()) { |
| 7072 | case DeclarationName::Identifier: |
| 7073 | return Import(FromName.getAsIdentifierInfo()); |
| 7074 | |
| 7075 | case DeclarationName::ObjCZeroArgSelector: |
| 7076 | case DeclarationName::ObjCOneArgSelector: |
| 7077 | case DeclarationName::ObjCMultiArgSelector: |
| 7078 | return Import(FromName.getObjCSelector()); |
| 7079 | |
| 7080 | case DeclarationName::CXXConstructorName: { |
| 7081 | QualType T = Import(FromName.getCXXNameType()); |
| 7082 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7083 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7084 | |
| 7085 | return ToContext.DeclarationNames.getCXXConstructorName( |
| 7086 | ToContext.getCanonicalType(T)); |
| 7087 | } |
| 7088 | |
| 7089 | case DeclarationName::CXXDestructorName: { |
| 7090 | QualType T = Import(FromName.getCXXNameType()); |
| 7091 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7092 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7093 | |
| 7094 | return ToContext.DeclarationNames.getCXXDestructorName( |
| 7095 | ToContext.getCanonicalType(T)); |
| 7096 | } |
| 7097 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7098 | case DeclarationName::CXXDeductionGuideName: { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7099 | auto *Template = cast_or_null<TemplateDecl>( |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7100 | Import(FromName.getCXXDeductionGuideTemplate())); |
| 7101 | if (!Template) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7102 | return {}; |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 7103 | return ToContext.DeclarationNames.getCXXDeductionGuideName(Template); |
| 7104 | } |
| 7105 | |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7106 | case DeclarationName::CXXConversionFunctionName: { |
| 7107 | QualType T = Import(FromName.getCXXNameType()); |
| 7108 | if (T.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7109 | return {}; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7110 | |
| 7111 | return ToContext.DeclarationNames.getCXXConversionFunctionName( |
| 7112 | ToContext.getCanonicalType(T)); |
| 7113 | } |
| 7114 | |
| 7115 | case DeclarationName::CXXOperatorName: |
| 7116 | return ToContext.DeclarationNames.getCXXOperatorName( |
| 7117 | FromName.getCXXOverloadedOperator()); |
| 7118 | |
| 7119 | case DeclarationName::CXXLiteralOperatorName: |
| 7120 | return ToContext.DeclarationNames.getCXXLiteralOperatorName( |
| 7121 | Import(FromName.getCXXLiteralIdentifier())); |
| 7122 | |
| 7123 | case DeclarationName::CXXUsingDirective: |
| 7124 | // FIXME: STATICS! |
| 7125 | return DeclarationName::getUsingDirectiveName(); |
| 7126 | } |
| 7127 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 7128 | llvm_unreachable("Invalid DeclarationName Kind!"); |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7129 | } |
| 7130 | |
Douglas Gregor | e2e50d33 | 2010-12-01 01:36:18 +0000 | [diff] [blame] | 7131 | IdentifierInfo *ASTImporter::Import(const IdentifierInfo *FromId) { |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7132 | if (!FromId) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 7133 | return nullptr; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7134 | |
Sean Callanan | f94ef1d | 2016-05-14 06:11:19 +0000 | [diff] [blame] | 7135 | IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName()); |
| 7136 | |
| 7137 | if (!ToId->getBuiltinID() && FromId->getBuiltinID()) |
| 7138 | ToId->setBuiltinID(FromId->getBuiltinID()); |
| 7139 | |
| 7140 | return ToId; |
Douglas Gregor | 96e578d | 2010-02-05 17:54:41 +0000 | [diff] [blame] | 7141 | } |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7142 | |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7143 | Selector ASTImporter::Import(Selector FromSel) { |
| 7144 | if (FromSel.isNull()) |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7145 | return {}; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7146 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 7147 | SmallVector<IdentifierInfo *, 4> Idents; |
Douglas Gregor | 43f5479 | 2010-02-17 02:12:47 +0000 | [diff] [blame] | 7148 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0))); |
| 7149 | for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I) |
| 7150 | Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I))); |
| 7151 | return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data()); |
| 7152 | } |
| 7153 | |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7154 | DeclarationName ASTImporter::HandleNameConflict(DeclarationName Name, |
| 7155 | DeclContext *DC, |
| 7156 | unsigned IDNS, |
| 7157 | NamedDecl **Decls, |
| 7158 | unsigned NumDecls) { |
| 7159 | return Name; |
| 7160 | } |
| 7161 | |
| 7162 | DiagnosticBuilder ASTImporter::ToDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 7163 | if (LastDiagFromFrom) |
| 7164 | ToContext.getDiagnostics().notePriorDiagnosticFrom( |
| 7165 | FromContext.getDiagnostics()); |
| 7166 | LastDiagFromFrom = false; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7167 | return ToContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7168 | } |
| 7169 | |
| 7170 | DiagnosticBuilder ASTImporter::FromDiag(SourceLocation Loc, unsigned DiagID) { |
Richard Smith | 5bb4cdf | 2012-12-20 02:22:15 +0000 | [diff] [blame] | 7171 | if (!LastDiagFromFrom) |
| 7172 | FromContext.getDiagnostics().notePriorDiagnosticFrom( |
| 7173 | ToContext.getDiagnostics()); |
| 7174 | LastDiagFromFrom = true; |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 7175 | return FromContext.getDiagnostics().Report(Loc, DiagID); |
Douglas Gregor | 3aed6cd | 2010-02-08 21:09:39 +0000 | [diff] [blame] | 7176 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7177 | |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7178 | void ASTImporter::CompleteDecl (Decl *D) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7179 | if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7180 | if (!ID->getDefinition()) |
| 7181 | ID->startDefinition(); |
| 7182 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7183 | else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7184 | if (!PD->getDefinition()) |
| 7185 | PD->startDefinition(); |
| 7186 | } |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7187 | else if (auto *TD = dyn_cast<TagDecl>(D)) { |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7188 | if (!TD->getDefinition() && !TD->isBeingDefined()) { |
| 7189 | TD->startDefinition(); |
| 7190 | TD->setCompleteDefinition(true); |
| 7191 | } |
| 7192 | } |
| 7193 | else { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7194 | assert(0 && "CompleteDecl called on a Decl that can't be completed"); |
Douglas Gregor | 2e15c84 | 2012-02-01 21:00:38 +0000 | [diff] [blame] | 7195 | } |
| 7196 | } |
| 7197 | |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7198 | Decl *ASTImporter::Imported(Decl *From, Decl *To) { |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7199 | if (From->hasAttrs()) { |
Eugene Zelenko | 9a9c823 | 2018-04-09 21:54:38 +0000 | [diff] [blame] | 7200 | for (auto *FromAttr : From->getAttrs()) |
Sean Callanan | 8bca996 | 2016-03-28 21:43:01 +0000 | [diff] [blame] | 7201 | To->addAttr(FromAttr->clone(To->getASTContext())); |
| 7202 | } |
| 7203 | if (From->isUsed()) { |
| 7204 | To->setIsUsed(); |
| 7205 | } |
Sean Callanan | dd2c174 | 2016-05-16 20:48:03 +0000 | [diff] [blame] | 7206 | if (From->isImplicit()) { |
| 7207 | To->setImplicit(); |
| 7208 | } |
Douglas Gregor | 8cdbe64 | 2010-02-12 23:44:20 +0000 | [diff] [blame] | 7209 | ImportedDecls[From] = To; |
| 7210 | return To; |
Daniel Dunbar | 9ced542 | 2010-02-13 20:24:39 +0000 | [diff] [blame] | 7211 | } |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7212 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 7213 | bool ASTImporter::IsStructurallyEquivalent(QualType From, QualType To, |
| 7214 | bool Complain) { |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 7215 | llvm::DenseMap<const Type *, const Type *>::iterator Pos |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7216 | = ImportedTypes.find(From.getTypePtr()); |
| 7217 | if (Pos != ImportedTypes.end() && ToContext.hasSameType(Import(From), To)) |
| 7218 | return true; |
Bruno Cardoso Lopes | 95ff11b | 2017-04-28 00:31:30 +0000 | [diff] [blame] | 7219 | |
Douglas Gregor | dd6006f | 2012-07-17 21:16:27 +0000 | [diff] [blame] | 7220 | StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls, |
| 7221 | false, Complain); |
Benjamin Kramer | 26d19c5 | 2010-02-18 13:02:13 +0000 | [diff] [blame] | 7222 | return Ctx.IsStructurallyEquivalent(From, To); |
Douglas Gregor | b4964f7 | 2010-02-15 23:54:17 +0000 | [diff] [blame] | 7223 | } |