113
113
import com .oracle .graal .python .nodes .util .CastToByteNode ;
114
114
import com .oracle .graal .python .nodes .util .CastToJavaByteNode ;
115
115
import com .oracle .graal .python .nodes .util .CastToJavaIntExactNode ;
116
- import com .oracle .graal .python .nodes .util .CastToJavaIntLossyNode ;
117
116
import com .oracle .graal .python .nodes .util .CastToJavaStringNode ;
118
117
import com .oracle .graal .python .runtime .PythonContext ;
119
118
import com .oracle .graal .python .runtime .PythonCore ;
@@ -774,8 +773,8 @@ static BytesNodes.ToBytesNode createToBytesFromTuple() {
774
773
// bytes.startswith(prefix[, start[, end]])
775
774
// bytearray.startswith(prefix[, start[, end]])
776
775
@ Builtin (name = "startswith" , minNumOfPositionalArgs = 2 , parameterNames = {"$self" , "prefix" , "start" , "end" })
777
- @ ArgumentClinic (name = "start" , customConversion = "createSliceIndexStart " , shortCircuitPrimitive = ArgumentClinic . PrimitiveType . Int )
778
- @ ArgumentClinic (name = "end" , customConversion = "createSliceIndexEnd " , shortCircuitPrimitive = ArgumentClinic . PrimitiveType . Int )
776
+ @ ArgumentClinic (name = "start" , conversion = ArgumentClinic . ClinicConversion . SliceIndex , defaultValue = "0 " , useDefaultForNone = true )
777
+ @ ArgumentClinic (name = "end" , conversion = ArgumentClinic . ClinicConversion . SliceIndex , defaultValue = "Integer.MAX_VALUE " , useDefaultForNone = true )
779
778
@ GenerateNodeFactory
780
779
public abstract static class StartsWithNode extends PrefixSuffixBaseNode {
781
780
@@ -784,14 +783,6 @@ protected ArgumentClinicProvider getArgumentClinic() {
784
783
return BytesBuiltinsClinicProviders .StartsWithNodeClinicProviderGen .INSTANCE ;
785
784
}
786
785
787
- public static SliceIndexNode createSliceIndexStart () {
788
- return BytesBuiltinsFactory .SliceIndexNodeGen .create (0 );
789
- }
790
-
791
- public static SliceIndexNode createSliceIndexEnd () {
792
- return BytesBuiltinsFactory .SliceIndexNodeGen .create (Integer .MAX_VALUE );
793
- }
794
-
795
786
@ Override
796
787
protected boolean doIt (byte [] bytes , byte [] prefix , int start , int end ) {
797
788
// start and end must be normalized indices for 'bytes'
@@ -813,8 +804,8 @@ protected boolean doIt(byte[] bytes, byte[] prefix, int start, int end) {
813
804
// bytes.endswith(suffix[, start[, end]])
814
805
// bytearray.endswith(suffix[, start[, end]])
815
806
@ Builtin (name = "endswith" , minNumOfPositionalArgs = 2 , parameterNames = {"$self" , "suffix" , "start" , "end" })
816
- @ ArgumentClinic (name = "start" , customConversion = "createSliceIndexStart " , shortCircuitPrimitive = ArgumentClinic . PrimitiveType . Int )
817
- @ ArgumentClinic (name = "end" , customConversion = "createSliceIndexEnd " , shortCircuitPrimitive = ArgumentClinic . PrimitiveType . Int )
807
+ @ ArgumentClinic (name = "start" , conversion = ArgumentClinic . ClinicConversion . SliceIndex , defaultValue = "0 " , useDefaultForNone = true )
808
+ @ ArgumentClinic (name = "end" , conversion = ArgumentClinic . ClinicConversion . SliceIndex , defaultValue = "Integer.MAX_VALUE " , useDefaultForNone = true )
818
809
@ GenerateNodeFactory
819
810
public abstract static class EndsWithNode extends PrefixSuffixBaseNode {
820
811
@@ -823,14 +814,6 @@ protected ArgumentClinicProvider getArgumentClinic() {
823
814
return BytesBuiltinsClinicProviders .EndsWithNodeClinicProviderGen .INSTANCE ;
824
815
}
825
816
826
- public static SliceIndexNode createSliceIndexStart () {
827
- return BytesBuiltinsFactory .SliceIndexNodeGen .create (0 );
828
- }
829
-
830
- public static SliceIndexNode createSliceIndexEnd () {
831
- return BytesBuiltinsFactory .SliceIndexNodeGen .create (Integer .MAX_VALUE );
832
- }
833
-
834
817
@ Override
835
818
protected boolean doIt (byte [] bytes , byte [] suffix , int start , int end ) {
836
819
// start and end must be normalized indices for 'bytes'
@@ -853,23 +836,15 @@ protected boolean doIt(byte[] bytes, byte[] suffix, int start, int end) {
853
836
// bytes.index(x)
854
837
// bytearray.index(x)
855
838
@ Builtin (name = "index" , minNumOfPositionalArgs = 2 , parameterNames = {"$self" , "sub" , "start" , "end" })
856
- @ ArgumentClinic (name = "start" , customConversion = "createSliceIndexStart " , shortCircuitPrimitive = ArgumentClinic . PrimitiveType . Int )
857
- @ ArgumentClinic (name = "end" , customConversion = "createSliceIndexEnd " , shortCircuitPrimitive = ArgumentClinic . PrimitiveType . Int )
839
+ @ ArgumentClinic (name = "start" , conversion = ArgumentClinic . ClinicConversion . SliceIndex , defaultValue = "0 " , useDefaultForNone = true )
840
+ @ ArgumentClinic (name = "end" , conversion = ArgumentClinic . ClinicConversion . SliceIndex , defaultValue = "Integer.MAX_VALUE " , useDefaultForNone = true )
858
841
@ GenerateNodeFactory
859
842
public abstract static class IndexNode extends PythonQuaternaryClinicBuiltinNode {
860
843
@ Override
861
844
protected ArgumentClinicProvider getArgumentClinic () {
862
845
return BytesBuiltinsClinicProviders .IndexNodeClinicProviderGen .INSTANCE ;
863
846
}
864
847
865
- public static SliceIndexNode createSliceIndexStart () {
866
- return BytesBuiltinsFactory .SliceIndexNodeGen .create (0 );
867
- }
868
-
869
- public static SliceIndexNode createSliceIndexEnd () {
870
- return BytesBuiltinsFactory .SliceIndexNodeGen .create (Integer .MAX_VALUE );
871
- }
872
-
873
848
@ Specialization
874
849
int index (PBytesLike self , Object arg , int start , int end ,
875
850
@ Cached SequenceStorageNodes .LenNode lenNode ,
@@ -891,23 +866,15 @@ private int checkResult(int result) {
891
866
// bytes.rindex(x)
892
867
// bytearray.rindex(x)
893
868
@ Builtin (name = "rindex" , minNumOfPositionalArgs = 2 , parameterNames = {"$self" , "sub" , "start" , "end" })
894
- @ ArgumentClinic (name = "start" , customConversion = "createSliceIndexStart " , shortCircuitPrimitive = ArgumentClinic . PrimitiveType . Int )
895
- @ ArgumentClinic (name = "end" , customConversion = "createSliceIndexEnd " , shortCircuitPrimitive = ArgumentClinic . PrimitiveType . Int )
869
+ @ ArgumentClinic (name = "start" , conversion = ArgumentClinic . ClinicConversion . SliceIndex , defaultValue = "0 " , useDefaultForNone = true )
870
+ @ ArgumentClinic (name = "end" , conversion = ArgumentClinic . ClinicConversion . SliceIndex , defaultValue = "Integer.MAX_VALUE " , useDefaultForNone = true )
896
871
@ GenerateNodeFactory
897
872
public abstract static class RIndexNode extends PythonQuaternaryClinicBuiltinNode {
898
873
@ Override
899
874
protected ArgumentClinicProvider getArgumentClinic () {
900
875
return BytesBuiltinsClinicProviders .RIndexNodeClinicProviderGen .INSTANCE ;
901
876
}
902
877
903
- public static SliceIndexNode createSliceIndexStart () {
904
- return BytesBuiltinsFactory .SliceIndexNodeGen .create (0 );
905
- }
906
-
907
- public static SliceIndexNode createSliceIndexEnd () {
908
- return BytesBuiltinsFactory .SliceIndexNodeGen .create (Integer .MAX_VALUE );
909
- }
910
-
911
878
@ Specialization
912
879
int indexWithStartEnd (PBytesLike self , Object arg , int start , int end ,
913
880
@ Cached SequenceStorageNodes .LenNode lenNode ,
@@ -1024,8 +991,8 @@ protected int find(VirtualFrame frame, SequenceStorage storage, PBytesLike sep,
1024
991
// bytes.count(x)
1025
992
// bytearray.count(x)
1026
993
@ Builtin (name = "count" , minNumOfPositionalArgs = 2 , parameterNames = {"$self" , "sub" , "start" , "end" })
1027
- @ ArgumentClinic (name = "start" , customConversion = "createSliceIndexStart " , shortCircuitPrimitive = ArgumentClinic . PrimitiveType . Int )
1028
- @ ArgumentClinic (name = "end" , customConversion = "createSliceIndexEnd " , shortCircuitPrimitive = ArgumentClinic . PrimitiveType . Int )
994
+ @ ArgumentClinic (name = "start" , conversion = ArgumentClinic . ClinicConversion . SliceIndex , defaultValue = "0 " , useDefaultForNone = true )
995
+ @ ArgumentClinic (name = "end" , conversion = ArgumentClinic . ClinicConversion . SliceIndex , defaultValue = "Integer.MAX_VALUE " , useDefaultForNone = true )
1029
996
@ GenerateNodeFactory
1030
997
@ ImportStatic (SpecialMethodNames .class )
1031
998
public abstract static class CountNode extends PythonQuaternaryClinicBuiltinNode {
@@ -1035,14 +1002,6 @@ protected ArgumentClinicProvider getArgumentClinic() {
1035
1002
return BytesBuiltinsClinicProviders .CountNodeClinicProviderGen .INSTANCE ;
1036
1003
}
1037
1004
1038
- public static SliceIndexNode createSliceIndexStart () {
1039
- return BytesBuiltinsFactory .SliceIndexNodeGen .create (0 );
1040
- }
1041
-
1042
- public static SliceIndexNode createSliceIndexEnd () {
1043
- return BytesBuiltinsFactory .SliceIndexNodeGen .create (Integer .MAX_VALUE );
1044
- }
1045
-
1046
1005
@ Specialization
1047
1006
static int count (PBytesLike self , int sub , int start , int end ,
1048
1007
@ Cached .Shared ("castNode" ) @ Cached CastToJavaByteNode cast ,
@@ -1151,23 +1110,15 @@ private static int countMulti(SequenceStorage bytes, int start, int end, Object
1151
1110
// bytes.find(bytes[, start[, end]])
1152
1111
// bytearray.find(bytes[, start[, end]])
1153
1112
@ Builtin (name = "find" , minNumOfPositionalArgs = 2 , parameterNames = {"$self" , "sub" , "start" , "end" })
1154
- @ ArgumentClinic (name = "start" , customConversion = "createSliceIndexStart " , shortCircuitPrimitive = ArgumentClinic . PrimitiveType . Int )
1155
- @ ArgumentClinic (name = "end" , customConversion = "createSliceIndexEnd " , shortCircuitPrimitive = ArgumentClinic . PrimitiveType . Int )
1113
+ @ ArgumentClinic (name = "start" , conversion = ArgumentClinic . ClinicConversion . SliceIndex , defaultValue = "0 " , useDefaultForNone = true )
1114
+ @ ArgumentClinic (name = "end" , conversion = ArgumentClinic . ClinicConversion . SliceIndex , defaultValue = "Integer.MAX_VALUE " , useDefaultForNone = true )
1156
1115
@ GenerateNodeFactory
1157
1116
abstract static class FindNode extends PythonQuaternaryClinicBuiltinNode {
1158
1117
@ Override
1159
1118
protected ArgumentClinicProvider getArgumentClinic () {
1160
1119
return BytesBuiltinsClinicProviders .FindNodeClinicProviderGen .INSTANCE ;
1161
1120
}
1162
1121
1163
- public static SliceIndexNode createSliceIndexStart () {
1164
- return BytesBuiltinsFactory .SliceIndexNodeGen .create (0 );
1165
- }
1166
-
1167
- public static SliceIndexNode createSliceIndexEnd () {
1168
- return BytesBuiltinsFactory .SliceIndexNodeGen .create (Integer .MAX_VALUE );
1169
- }
1170
-
1171
1122
@ Specialization
1172
1123
static int find (PBytesLike self , Object sub , int start , int end ,
1173
1124
@ Cached SequenceStorageNodes .LenNode lenNode ,
@@ -1182,23 +1133,15 @@ static int find(PBytesLike self, Object sub, int start, int end,
1182
1133
// bytes.rfind(bytes[, start[, end]])
1183
1134
// bytearray.rfind(bytes[, start[, end]])
1184
1135
@ Builtin (name = "rfind" , minNumOfPositionalArgs = 2 , parameterNames = {"$self" , "sub" , "start" , "end" })
1185
- @ ArgumentClinic (name = "start" , customConversion = "createSliceIndexStart " , shortCircuitPrimitive = ArgumentClinic . PrimitiveType . Int )
1186
- @ ArgumentClinic (name = "end" , customConversion = "createSliceIndexEnd " , shortCircuitPrimitive = ArgumentClinic . PrimitiveType . Int )
1136
+ @ ArgumentClinic (name = "start" , conversion = ArgumentClinic . ClinicConversion . SliceIndex , defaultValue = "0 " , useDefaultForNone = true )
1137
+ @ ArgumentClinic (name = "end" , conversion = ArgumentClinic . ClinicConversion . SliceIndex , defaultValue = "Integer.MAX_VALUE " , useDefaultForNone = true )
1187
1138
@ GenerateNodeFactory
1188
1139
abstract static class RFindNode extends PythonQuaternaryClinicBuiltinNode {
1189
1140
@ Override
1190
1141
protected ArgumentClinicProvider getArgumentClinic () {
1191
1142
return BytesBuiltinsClinicProviders .RFindNodeClinicProviderGen .INSTANCE ;
1192
1143
}
1193
1144
1194
- public static SliceIndexNode createSliceIndexStart () {
1195
- return BytesBuiltinsFactory .SliceIndexNodeGen .create (0 );
1196
- }
1197
-
1198
- public static SliceIndexNode createSliceIndexEnd () {
1199
- return BytesBuiltinsFactory .SliceIndexNodeGen .create (Integer .MAX_VALUE );
1200
- }
1201
-
1202
1145
@ Specialization
1203
1146
static int find (PBytesLike self , Object sub , int start , int end ,
1204
1147
@ Cached SequenceStorageNodes .LenNode lenNode ,
@@ -2798,38 +2741,6 @@ protected final String getErrorMessage() {
2798
2741
2799
2742
}
2800
2743
2801
- public abstract static class SliceIndexNode extends ArgumentCastNode .ArgumentCastNodeWithRaise {
2802
- private final int defaultValue ;
2803
-
2804
- protected SliceIndexNode (int defaultValue ) {
2805
- this .defaultValue = defaultValue ;
2806
- }
2807
-
2808
- @ Override
2809
- public abstract Object execute (VirtualFrame frame , Object value );
2810
-
2811
- @ Specialization
2812
- int handleNone (@ SuppressWarnings ("unused" ) PNone none ) {
2813
- return defaultValue ;
2814
- }
2815
-
2816
- @ Specialization
2817
- static int doInt (int i ) {
2818
- // fast-path for the most common case
2819
- return i ;
2820
- }
2821
-
2822
- @ Specialization (guards = "!isPNone(value)" , limit = "3" )
2823
- int doOthers (VirtualFrame frame , Object value ,
2824
- @ Cached CastToJavaIntLossyNode castToInt ,
2825
- @ CachedLibrary ("value" ) PythonObjectLibrary lib ) {
2826
- if (lib .canBeIndex (value )) {
2827
- return castToInt .execute (lib .asIndexWithFrame (value , frame ));
2828
- }
2829
- throw raise (TypeError , ErrorMessages .SLICE_INDICES_TYPE_ERROR );
2830
- }
2831
- }
2832
-
2833
2744
protected static int adjustStartIndex (int startIn , int len ) {
2834
2745
if (startIn < 0 ) {
2835
2746
int start = startIn + len ;
0 commit comments