@@ -3,7 +3,7 @@ package tastyreflect
3
3
4
4
import dotty .tools .dotc .ast .{Trees , tpd , untpd }
5
5
import dotty .tools .dotc .ast .tpd .TreeOps
6
- import dotty .tools .dotc .core .{Constants , NameKinds , Types }
6
+ import dotty .tools .dotc .core .{Constants , NameKinds , Names , Types }
7
7
import dotty .tools .dotc .core .Flags ._
8
8
import dotty .tools .dotc .core .StdNames .nme
9
9
import dotty .tools .dotc .core .quoted .PickledQuotes
@@ -957,13 +957,27 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
957
957
958
958
type NoPrefix = Types .NoPrefix .type
959
959
960
+ def isNoPrefix (x : TypeOrBounds )(implicit ctx : Context ): Option [NoPrefix ] =
961
+ if (x == Types .NoPrefix ) Some (Types .NoPrefix ) else None
962
+
960
963
type TypeBounds = Types .TypeBounds
961
964
965
+ def isTypeBounds (x : TypeOrBounds )(implicit ctx : Context ): Option [TypeBounds ] = x match {
966
+ case x : Types .TypeBounds => Some (x)
967
+ case _ => None
968
+ }
969
+
962
970
def TypeBounds_low (self : TypeBounds )(implicit ctx : Context ): Type = self.lo
963
971
def TypeBounds_hi (self : TypeBounds )(implicit ctx : Context ): Type = self.hi
964
972
965
973
type Type = Types .Type
966
974
975
+ def isType (x : TypeOrBounds )(implicit ctx : Context ): Option [Type ] = x match {
976
+ case x : TypeBounds => None
977
+ case x if x == Types .NoPrefix => None
978
+ case _ => Some (x)
979
+ }
980
+
967
981
def `Type_=:=` (self : Type )(that : Type )(implicit ctx : Context ): Boolean = self =:= that
968
982
969
983
def `Type_<:<` (self : Type )(that : Type )(implicit ctx : Context ): Boolean = self <:< that
@@ -991,84 +1005,196 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
991
1005
992
1006
type ConstantType = Types .ConstantType
993
1007
994
- def ConstantType_value (self : ConstantType )(implicit ctx : Context ): Any = self.value
1008
+ def isConstantType (tpe : TypeOrBounds )(implicit ctx : Context ): Option [ConstantType ] = tpe match {
1009
+ case tpe : Types .ConstantType => Some (tpe)
1010
+ case _ => None
1011
+ }
1012
+
1013
+ def ConstantType_constant (self : ConstantType )(implicit ctx : Context ): Constant = self.value
995
1014
996
1015
type SymRef = Types .NamedType
997
1016
1017
+ def isSymRef (tpe : TypeOrBounds )(implicit ctx : Context ): Option [SymRef ] = tpe match {
1018
+ case tp : Types .NamedType =>
1019
+ tp.designator match {
1020
+ case sym : Symbol => Some (tp)
1021
+ case _ => None
1022
+ }
1023
+ case _ => None
1024
+ }
1025
+
998
1026
def SymRef_qualifier (self : SymRef )(implicit ctx : Context ): TypeOrBounds = self.prefix
999
1027
1028
+ // TODO remove this method. May require splitting SymRef into TypeSymRef and TermSymRef
1029
+ def isSymRef_unapply (tpe : TypeOrBounds )(implicit ctx : Context ): Option [(Symbol , TypeOrBounds /* Type | NoPrefix */ )] = tpe match {
1030
+ case tpe : Types .NamedType =>
1031
+ tpe.designator match {
1032
+ case sym : Symbol => Some ((sym, tpe.prefix))
1033
+ case _ => None
1034
+ }
1035
+ case _ => None
1036
+ }
1037
+
1000
1038
type TermRef = Types .NamedType
1001
1039
1040
+ def isTermRef (tpe : TypeOrBounds )(implicit ctx : Context ): Option [TermRef ] = tpe match {
1041
+ case tpe : Types .NamedType =>
1042
+ tpe.designator match {
1043
+ case name : Names .TermName => Some (tpe)
1044
+ case _ => None
1045
+ }
1046
+ case _ => None
1047
+ }
1048
+
1049
+ def TermRef_name (self : TermRef )(implicit ctx : Context ): String = self.name.toString
1002
1050
def TermRef_qualifier (self : TermRef )(implicit ctx : Context ): TypeOrBounds = self.prefix
1003
1051
1052
+ def TermRef_apply (qual : TypeOrBounds , name : String )(implicit ctx : Context ): TermRef =
1053
+ Types .TermRef (qual, name.toTermName)
1054
+
1004
1055
type TypeRef = Types .NamedType
1005
1056
1057
+ def isTypeRef (tpe : TypeOrBounds )(implicit ctx : Context ): Option [TypeRef ] = tpe match {
1058
+ case tpe : Types .NamedType =>
1059
+ tpe.designator match {
1060
+ case name : Names .TypeName => Some (tpe)
1061
+ case _ => None
1062
+ }
1063
+ case _ => None
1064
+ }
1065
+
1006
1066
def TypeRef_name (self : TypeRef )(implicit ctx : Context ): String = self.name.toString
1007
1067
def TypeRef_qualifier (self : TypeRef )(implicit ctx : Context ): TypeOrBounds = self.prefix
1008
1068
1009
1069
type SuperType = Types .SuperType
1010
1070
1071
+ def isSuperType (tpe : TypeOrBounds )(implicit ctx : Context ): Option [SuperType ] = tpe match {
1072
+ case tpe : Types .SuperType => Some (tpe)
1073
+ case _ => None
1074
+ }
1075
+
1011
1076
def SuperType_thistpe (self : SuperType )(implicit ctx : Context ): Type = self.thistpe
1012
1077
def SuperType_supertpe (self : SuperType )(implicit ctx : Context ): Type = self.supertpe
1013
1078
1014
1079
type Refinement = Types .RefinedType
1015
1080
1081
+ def isRefinement (tpe : TypeOrBounds )(implicit ctx : Context ): Option [Refinement ] = tpe match {
1082
+ case tpe : Types .RefinedType => Some (tpe)
1083
+ case _ => None
1084
+ }
1085
+
1016
1086
def Refinement_parent (self : Refinement )(implicit ctx : Context ): Type = self.parent
1017
1087
def Refinement_name (self : Refinement )(implicit ctx : Context ): String = self.refinedName.toString
1018
1088
def Refinement_info (self : Refinement )(implicit ctx : Context ): TypeOrBounds = self.refinedInfo
1019
1089
1020
1090
type AppliedType = Types .AppliedType
1021
1091
1092
+ def isAppliedType (tpe : TypeOrBounds )(implicit ctx : Context ): Option [AppliedType ] = tpe match {
1093
+ case tpe : Types .AppliedType => Some (tpe)
1094
+ case _ => None
1095
+ }
1096
+
1022
1097
def AppliedType_tycon (self : AppliedType )(implicit ctx : Context ): Type = self.tycon
1023
1098
def AppliedType_args (self : AppliedType )(implicit ctx : Context ): List [TypeOrBounds ] = self.args
1024
1099
1025
1100
type AnnotatedType = Types .AnnotatedType
1026
1101
1102
+ def isAnnotatedType (tpe : TypeOrBounds )(implicit ctx : Context ): Option [AnnotatedType ] = tpe match {
1103
+ case tpe : Types .AnnotatedType => Some (tpe)
1104
+ case _ => None
1105
+ }
1106
+
1027
1107
def AnnotatedType_underlying (self : AnnotatedType )(implicit ctx : Context ): Type = self.underlying.stripTypeVar
1028
1108
def AnnotatedType_annot (self : AnnotatedType )(implicit ctx : Context ): Term = self.annot.tree
1029
1109
1030
1110
type AndType = Types .AndType
1031
1111
1112
+ def isAndType (tpe : TypeOrBounds )(implicit ctx : Context ): Option [AndType ] = tpe match {
1113
+ case tpe : Types .AndType => Some (tpe)
1114
+ case _ => None
1115
+ }
1116
+
1032
1117
def AndType_left (self : AndType )(implicit ctx : Context ): Type = self.tp1.stripTypeVar
1033
1118
def AndType_right (self : AndType )(implicit ctx : Context ): Type = self.tp2.stripTypeVar
1034
1119
1035
1120
type OrType = Types .OrType
1036
1121
1122
+ def isOrType (tpe : TypeOrBounds )(implicit ctx : Context ): Option [OrType ] = tpe match {
1123
+ case tpe : Types .OrType => Some (tpe)
1124
+ case _ => None
1125
+ }
1126
+
1037
1127
def OrType_left (self : OrType )(implicit ctx : Context ): Type = self.tp1.stripTypeVar
1038
1128
def OrType_right (self : OrType )(implicit ctx : Context ): Type = self.tp2.stripTypeVar
1039
1129
1040
1130
type MatchType = Types .MatchType
1041
1131
1132
+ def isMatchType (tpe : TypeOrBounds )(implicit ctx : Context ): Option [MatchType ] = tpe match {
1133
+ case tpe : Types .MatchType => Some (tpe)
1134
+ case _ => None
1135
+ }
1136
+
1042
1137
def MatchType_bound (self : MatchType )(implicit ctx : Context ): Type = self.bound
1043
1138
def MatchType_scrutinee (self : MatchType )(implicit ctx : Context ): Type = self.scrutinee
1044
1139
def MatchType_cases (self : MatchType )(implicit ctx : Context ): List [Type ] = self.cases
1045
1140
1046
1141
type ByNameType = Types .ExprType
1047
1142
1143
+ def isByNameType (tpe : TypeOrBounds )(implicit ctx : Context ): Option [ByNameType ] = tpe match {
1144
+ case tpe : Types .ExprType => Some (tpe)
1145
+ case _ => None
1146
+ }
1147
+
1048
1148
def ByNameType_underlying (self : ByNameType )(implicit ctx : Context ): Type = self.resType.stripTypeVar
1049
1149
1050
1150
type ParamRef = Types .ParamRef
1051
1151
1152
+ def isParamRef (tpe : TypeOrBounds )(implicit ctx : Context ): Option [ParamRef ] = tpe match {
1153
+ case tpe : Types .TypeParamRef => Some (tpe)
1154
+ case tpe : Types .TermParamRef => Some (tpe)
1155
+ case _ => None
1156
+ }
1157
+
1052
1158
def ParamRef_binder (self : ParamRef )(implicit ctx : Context ): LambdaType [TypeOrBounds ] =
1053
1159
self.binder.asInstanceOf [LambdaType [TypeOrBounds ]] // Cast to tpd
1054
1160
def ParamRef_paramNum (self : ParamRef )(implicit ctx : Context ): Int = self.paramNum
1055
1161
1056
1162
type ThisType = Types .ThisType
1057
1163
1058
- def ThisType_underlying (self : ThisType )(implicit ctx : Context ): Type = self.underlying
1164
+ def isThisType (tpe : TypeOrBounds )(implicit ctx : Context ): Option [ThisType ] = tpe match {
1165
+ case tpe : Types .ThisType => Some (tpe)
1166
+ case _ => None
1167
+ }
1168
+
1169
+ def ThisType_tref (self : ThisType )(implicit ctx : Context ): Type = self.tref
1059
1170
1060
1171
type RecursiveThis = Types .RecThis
1061
1172
1173
+ def isRecursiveThis (tpe : TypeOrBounds )(implicit ctx : Context ): Option [RecursiveThis ] = tpe match {
1174
+ case tpe : Types .RecThis => Some (tpe)
1175
+ case _ => None
1176
+ }
1177
+
1062
1178
def RecursiveThis_binder (self : RecursiveThis )(implicit ctx : Context ): RecursiveType = self.binder
1063
1179
1064
1180
type RecursiveType = Types .RecType
1065
1181
1182
+ def isRecursiveType (tpe : TypeOrBounds )(implicit ctx : Context ): Option [RecursiveType ] = tpe match {
1183
+ case tpe : Types .RecType => Some (tpe)
1184
+ case _ => None
1185
+ }
1186
+
1066
1187
def RecursiveType_underlying (self : RecursiveType )(implicit ctx : Context ): Type = self.underlying.stripTypeVar
1067
1188
1068
1189
type LambdaType [ParamInfo ] = Types .LambdaType { type PInfo = ParamInfo }
1069
1190
1070
1191
type MethodType = Types .MethodType
1071
1192
1193
+ def isMethodType (tpe : TypeOrBounds )(implicit ctx : Context ): Option [MethodType ] = tpe match {
1194
+ case tpe : Types .MethodType => Some (tpe)
1195
+ case _ => None
1196
+ }
1197
+
1072
1198
def MethodType_isErased (self : MethodType ): Boolean = self.isErasedMethod
1073
1199
def MethodType_isImplicit (self : MethodType ): Boolean = self.isImplicitMethod
1074
1200
def MethodType_paramNames (self : MethodType )(implicit ctx : Context ): List [String ] = self.paramNames.map(_.toString)
@@ -1077,12 +1203,22 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
1077
1203
1078
1204
type PolyType = Types .PolyType
1079
1205
1206
+ def isPolyType (tpe : TypeOrBounds )(implicit ctx : Context ): Option [PolyType ] = tpe match {
1207
+ case tpe : Types .PolyType => Some (tpe)
1208
+ case _ => None
1209
+ }
1210
+
1080
1211
def PolyType_paramNames (self : PolyType )(implicit ctx : Context ): List [String ] = self.paramNames.map(_.toString)
1081
1212
def PolyType_paramBounds (self : PolyType )(implicit ctx : Context ): List [TypeBounds ] = self.paramInfos
1082
1213
def PolyType_resType (self : PolyType )(implicit ctx : Context ): Type = self.resType
1083
1214
1084
1215
type TypeLambda = Types .TypeLambda
1085
1216
1217
+ def isTypeLambda (tpe : TypeOrBounds )(implicit ctx : Context ): Option [TypeLambda ] = tpe match {
1218
+ case tpe : Types .TypeLambda => Some (tpe)
1219
+ case _ => None
1220
+ }
1221
+
1086
1222
def TypeLambda_paramNames (self : TypeLambda )(implicit ctx : Context ): List [String ] = self.paramNames.map(_.toString)
1087
1223
def TypeLambda_paramBounds (self : TypeLambda )(implicit ctx : Context ): List [TypeBounds ] = self.paramInfos
1088
1224
def TypeLambda_resType (self : TypeLambda )(implicit ctx : Context ): Type = self.resType
0 commit comments