@@ -801,35 +801,19 @@ template <> bool Equivalent<ConstString>(ConstString l, ConstString r) {
801
801
return l == r;
802
802
}
803
803
804
- // / A list of testcases for which the validation is disabled.
805
- bool Whitelisted (SwiftASTContext &swift_ast_context) {
806
- auto *sym_file = swift_ast_context.GetSymbolFile ();
807
- if (!sym_file)
808
- return false ;
809
- auto *obj_file = sym_file->GetObjectFile ();
810
- if (!obj_file)
811
- return false ;
812
- auto &file_spec = obj_file->GetFileSpec ();
813
- std::string path = file_spec.GetPath (false );
814
- llvm::StringRef p (path);
815
- return p.contains (" lang/swift/clangimporter/include_conflict/"
816
- " TestSwiftIncludeConflict" ) ||
817
- p.contains (" lang/swift/clangimporter/headermap_conflict/"
818
- " TestSwiftHeadermapConflict" ) ||
819
- p.contains (" lang/swift/clangimporter/extra_clang_flags/"
820
- " TestSwiftExtraClangFlags" );
821
- }
822
804
}
823
805
#endif
824
806
825
807
// This can be removed once the transition is complete.
826
- #define VALIDATE_AND_RETURN (IMPL, EXPECTED ) \
808
+ #define VALIDATE_AND_RETURN (IMPL, REFERENCE, TYPE, ...) \
827
809
do { \
828
810
auto result = IMPL (); \
829
811
if (m_swift_ast_context) \
830
- assert ((Equivalent (result, (EXPECTED)) || \
831
- Whitelisted (*m_swift_ast_context)) && \
832
- " TypeSystemSwiftTypeRef diverges from SwiftASTContext" ); \
812
+ assert ( \
813
+ !ReconstructType (TYPE) /* missing .swiftmodule */ || \
814
+ (Equivalent (result, m_swift_ast_context->REFERENCE ( \
815
+ ReconstructType (TYPE), ##__VA_ARGS__))) && \
816
+ " TypeSystemSwiftTypeRef diverges from SwiftASTContext" ); \
833
817
return result; \
834
818
} while (0 )
835
819
@@ -912,13 +896,40 @@ bool TypeSystemSwiftTypeRef::IsArrayType(opaque_compiler_type_t type,
912
896
913
897
return true ;
914
898
};
915
- VALIDATE_AND_RETURN (
916
- impl, m_swift_ast_context->IsArrayType (ReconstructType (type), nullptr ,
917
- nullptr , nullptr ));
899
+ VALIDATE_AND_RETURN (impl, IsArrayType, type, nullptr , nullptr , nullptr );
918
900
}
901
+
919
902
bool TypeSystemSwiftTypeRef::IsAggregateType (opaque_compiler_type_t type) {
920
- return m_swift_ast_context->IsAggregateType (ReconstructType (type));
903
+ auto impl = [&]() -> bool {
904
+ using namespace swift ::Demangle;
905
+ Demangler Dem;
906
+ NodePointer node = DemangleCanonicalType (Dem, type);
907
+
908
+ if (!node)
909
+ return false ;
910
+ switch (node->getKind ()) {
911
+ case Node::Kind::Structure:
912
+ case Node::Kind::Class:
913
+ case Node::Kind::Enum:
914
+ case Node::Kind::Tuple:
915
+ case Node::Kind::Protocol:
916
+ case Node::Kind::ProtocolList:
917
+ case Node::Kind::ProtocolListWithClass:
918
+ case Node::Kind::ProtocolListWithAnyObject:
919
+ case Node::Kind::BoundGenericClass:
920
+ case Node::Kind::BoundGenericEnum:
921
+ case Node::Kind::BoundGenericStructure:
922
+ case Node::Kind::BoundGenericProtocol:
923
+ case Node::Kind::BoundGenericOtherNominalType:
924
+ case Node::Kind::BoundGenericTypeAlias:
925
+ return true ;
926
+ default :
927
+ return false ;
928
+ }
929
+ };
930
+ VALIDATE_AND_RETURN (impl, IsAggregateType, type);
921
931
}
932
+
922
933
bool TypeSystemSwiftTypeRef::IsDefined (opaque_compiler_type_t type) {
923
934
return m_swift_ast_context->IsDefined (ReconstructType (type));
924
935
}
@@ -938,8 +949,7 @@ bool TypeSystemSwiftTypeRef::IsFunctionType(opaque_compiler_type_t type,
938
949
return node && (node->getKind () == Node::Kind::FunctionType ||
939
950
node->getKind () == Node::Kind::ImplFunctionType);
940
951
};
941
- VALIDATE_AND_RETURN (impl, m_swift_ast_context->IsFunctionType (
942
- ReconstructType (type), nullptr ));
952
+ VALIDATE_AND_RETURN (impl, IsFunctionType, type, nullptr );
943
953
}
944
954
size_t TypeSystemSwiftTypeRef::GetNumberOfFunctionArguments (
945
955
opaque_compiler_type_t type) {
@@ -966,8 +976,7 @@ size_t TypeSystemSwiftTypeRef::GetNumberOfFunctionArguments(
966
976
}
967
977
return num_args;
968
978
};
969
- VALIDATE_AND_RETURN (impl, m_swift_ast_context->GetNumberOfFunctionArguments (
970
- ReconstructType (type)));
979
+ VALIDATE_AND_RETURN (impl, GetNumberOfFunctionArguments, type);
971
980
}
972
981
CompilerType
973
982
TypeSystemSwiftTypeRef::GetFunctionArgumentAtIndex (opaque_compiler_type_t type,
@@ -1008,14 +1017,12 @@ TypeSystemSwiftTypeRef::GetFunctionArgumentAtIndex(opaque_compiler_type_t type,
1008
1017
}
1009
1018
return {};
1010
1019
};
1011
- VALIDATE_AND_RETURN (impl, m_swift_ast_context->GetFunctionArgumentAtIndex (
1012
- ReconstructType (type), index));
1020
+ VALIDATE_AND_RETURN (impl, GetFunctionArgumentAtIndex, type, index);
1013
1021
}
1014
1022
bool TypeSystemSwiftTypeRef::IsFunctionPointerType (
1015
1023
opaque_compiler_type_t type) {
1016
1024
auto impl = [&]() -> bool { return IsFunctionType (type, nullptr ); };
1017
- VALIDATE_AND_RETURN (
1018
- impl, m_swift_ast_context->IsFunctionPointerType (ReconstructType (type)));
1025
+ VALIDATE_AND_RETURN (impl, IsFunctionPointerType, type);
1019
1026
}
1020
1027
bool TypeSystemSwiftTypeRef::IsIntegerType (opaque_compiler_type_t type,
1021
1028
bool &is_signed) {
@@ -1042,8 +1049,7 @@ bool TypeSystemSwiftTypeRef::IsPointerType(opaque_compiler_type_t type,
1042
1049
(node->getText () == swift::BUILTIN_TYPE_NAME_NATIVEOBJECT) ||
1043
1050
(node->getText () == swift::BUILTIN_TYPE_NAME_BRIDGEOBJECT));
1044
1051
};
1045
- VALIDATE_AND_RETURN (impl, m_swift_ast_context->IsPointerType (
1046
- ReconstructType (type), pointee_type));
1052
+ VALIDATE_AND_RETURN (impl, IsPointerType, type, pointee_type);
1047
1053
}
1048
1054
bool TypeSystemSwiftTypeRef::IsScalarType (opaque_compiler_type_t type) {
1049
1055
return m_swift_ast_context->IsScalarType (ReconstructType (type));
@@ -1056,8 +1062,7 @@ bool TypeSystemSwiftTypeRef::IsVoidType(opaque_compiler_type_t type) {
1056
1062
return node && node->getNumChildren () == 0 &&
1057
1063
node->getKind () == Node::Kind::Tuple;
1058
1064
};
1059
- VALIDATE_AND_RETURN (impl,
1060
- m_swift_ast_context->IsVoidType (ReconstructType (type)));
1065
+ VALIDATE_AND_RETURN (impl, IsVoidType, type);
1061
1066
}
1062
1067
// Type Completion
1063
1068
bool TypeSystemSwiftTypeRef::GetCompleteType (opaque_compiler_type_t type) {
@@ -1083,8 +1088,7 @@ ConstString TypeSystemSwiftTypeRef::GetTypeName(opaque_compiler_type_t type) {
1083
1088
return ConstString (SwiftLanguageRuntime::DemangleSymbolAsString (
1084
1089
remangled, SwiftLanguageRuntime::eTypeName));
1085
1090
};
1086
- VALIDATE_AND_RETURN (impl,
1087
- m_swift_ast_context->GetTypeName (ReconstructType (type)));
1091
+ VALIDATE_AND_RETURN (impl, GetTypeName, type);
1088
1092
}
1089
1093
ConstString
1090
1094
TypeSystemSwiftTypeRef::GetDisplayTypeName (opaque_compiler_type_t type,
@@ -1103,8 +1107,7 @@ TypeSystemSwiftTypeRef::GetDisplayTypeName(opaque_compiler_type_t type,
1103
1107
return ConstString (SwiftLanguageRuntime::DemangleSymbolAsString (
1104
1108
remangled, SwiftLanguageRuntime::eDisplayTypeName, sc));
1105
1109
};
1106
- VALIDATE_AND_RETURN (
1107
- impl, m_swift_ast_context->GetDisplayTypeName (ReconstructType (type), sc));
1110
+ VALIDATE_AND_RETURN (impl, GetDisplayTypeName, type, sc);
1108
1111
}
1109
1112
uint32_t TypeSystemSwiftTypeRef::GetTypeInfo (
1110
1113
opaque_compiler_type_t type, CompilerType *pointee_or_element_clang_type) {
@@ -1129,8 +1132,7 @@ TypeSystemSwiftTypeRef::GetArrayElementType(opaque_compiler_type_t type,
1129
1132
IsArrayType (type, &element_type, nullptr , nullptr );
1130
1133
return element_type;
1131
1134
};
1132
- VALIDATE_AND_RETURN (impl, m_swift_ast_context->GetArrayElementType (
1133
- ReconstructType (type), nullptr ));
1135
+ VALIDATE_AND_RETURN (impl, GetArrayElementType, type, nullptr );
1134
1136
}
1135
1137
CompilerType
1136
1138
TypeSystemSwiftTypeRef::GetCanonicalType (opaque_compiler_type_t type) {
@@ -1139,14 +1141,12 @@ TypeSystemSwiftTypeRef::GetCanonicalType(opaque_compiler_type_t type) {
1139
1141
int TypeSystemSwiftTypeRef::GetFunctionArgumentCount (
1140
1142
opaque_compiler_type_t type) {
1141
1143
auto impl = [&]() -> int { return GetNumberOfFunctionArguments (type); };
1142
- VALIDATE_AND_RETURN (impl, m_swift_ast_context->GetFunctionArgumentCount (
1143
- ReconstructType (type)));
1144
+ VALIDATE_AND_RETURN (impl, GetFunctionArgumentCount, type);
1144
1145
}
1145
1146
CompilerType TypeSystemSwiftTypeRef::GetFunctionArgumentTypeAtIndex (
1146
1147
opaque_compiler_type_t type, size_t idx) {
1147
1148
auto impl = [&] { return GetFunctionArgumentAtIndex (type, idx); };
1148
- VALIDATE_AND_RETURN (impl, m_swift_ast_context->GetFunctionArgumentTypeAtIndex (
1149
- ReconstructType (type), idx));
1149
+ VALIDATE_AND_RETURN (impl, GetFunctionArgumentTypeAtIndex, type, idx);
1150
1150
}
1151
1151
CompilerType
1152
1152
TypeSystemSwiftTypeRef::GetFunctionReturnType (opaque_compiler_type_t type) {
@@ -1177,8 +1177,7 @@ TypeSystemSwiftTypeRef::GetFunctionReturnType(opaque_compiler_type_t type) {
1177
1177
type->addChild (tuple, Dem);
1178
1178
return RemangleAsType (Dem, type);
1179
1179
};
1180
- VALIDATE_AND_RETURN (
1181
- impl, m_swift_ast_context->GetFunctionReturnType (ReconstructType (type)));
1180
+ VALIDATE_AND_RETURN (impl, GetFunctionReturnType, type);
1182
1181
}
1183
1182
size_t
1184
1183
TypeSystemSwiftTypeRef::GetNumMemberFunctions (opaque_compiler_type_t type) {
@@ -1438,9 +1437,7 @@ bool TypeSystemSwiftTypeRef::IsReferenceType(opaque_compiler_type_t type,
1438
1437
return true ;
1439
1438
};
1440
1439
1441
- VALIDATE_AND_RETURN (
1442
- impl, m_swift_ast_context->IsReferenceType (ReconstructType (type),
1443
- pointee_type, is_rvalue));
1440
+ VALIDATE_AND_RETURN (impl, IsReferenceType, type, pointee_type, is_rvalue);
1444
1441
}
1445
1442
bool TypeSystemSwiftTypeRef::ShouldTreatScalarValueAsAddress (
1446
1443
opaque_compiler_type_t type) {
0 commit comments