113113import com .oracle .graal .python .nodes .util .CastToByteNode ;
114114import com .oracle .graal .python .nodes .util .CastToJavaByteNode ;
115115import com .oracle .graal .python .nodes .util .CastToJavaIntExactNode ;
116- import com .oracle .graal .python .nodes .util .CastToJavaIntLossyNode ;
117116import com .oracle .graal .python .nodes .util .CastToJavaStringNode ;
118117import com .oracle .graal .python .runtime .PythonContext ;
119118import com .oracle .graal .python .runtime .PythonCore ;
@@ -774,8 +773,8 @@ static BytesNodes.ToBytesNode createToBytesFromTuple() {
774773 // bytes.startswith(prefix[, start[, end]])
775774 // bytearray.startswith(prefix[, start[, end]])
776775 @ 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 )
779778 @ GenerateNodeFactory
780779 public abstract static class StartsWithNode extends PrefixSuffixBaseNode {
781780
@@ -784,14 +783,6 @@ protected ArgumentClinicProvider getArgumentClinic() {
784783 return BytesBuiltinsClinicProviders .StartsWithNodeClinicProviderGen .INSTANCE ;
785784 }
786785
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-
795786 @ Override
796787 protected boolean doIt (byte [] bytes , byte [] prefix , int start , int end ) {
797788 // start and end must be normalized indices for 'bytes'
@@ -813,8 +804,8 @@ protected boolean doIt(byte[] bytes, byte[] prefix, int start, int end) {
813804 // bytes.endswith(suffix[, start[, end]])
814805 // bytearray.endswith(suffix[, start[, end]])
815806 @ 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 )
818809 @ GenerateNodeFactory
819810 public abstract static class EndsWithNode extends PrefixSuffixBaseNode {
820811
@@ -823,14 +814,6 @@ protected ArgumentClinicProvider getArgumentClinic() {
823814 return BytesBuiltinsClinicProviders .EndsWithNodeClinicProviderGen .INSTANCE ;
824815 }
825816
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-
834817 @ Override
835818 protected boolean doIt (byte [] bytes , byte [] suffix , int start , int end ) {
836819 // start and end must be normalized indices for 'bytes'
@@ -853,23 +836,15 @@ protected boolean doIt(byte[] bytes, byte[] suffix, int start, int end) {
853836 // bytes.index(x)
854837 // bytearray.index(x)
855838 @ 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 )
858841 @ GenerateNodeFactory
859842 public abstract static class IndexNode extends PythonQuaternaryClinicBuiltinNode {
860843 @ Override
861844 protected ArgumentClinicProvider getArgumentClinic () {
862845 return BytesBuiltinsClinicProviders .IndexNodeClinicProviderGen .INSTANCE ;
863846 }
864847
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-
873848 @ Specialization
874849 int index (PBytesLike self , Object arg , int start , int end ,
875850 @ Cached SequenceStorageNodes .LenNode lenNode ,
@@ -891,23 +866,15 @@ private int checkResult(int result) {
891866 // bytes.rindex(x)
892867 // bytearray.rindex(x)
893868 @ 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 )
896871 @ GenerateNodeFactory
897872 public abstract static class RIndexNode extends PythonQuaternaryClinicBuiltinNode {
898873 @ Override
899874 protected ArgumentClinicProvider getArgumentClinic () {
900875 return BytesBuiltinsClinicProviders .RIndexNodeClinicProviderGen .INSTANCE ;
901876 }
902877
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-
911878 @ Specialization
912879 int indexWithStartEnd (PBytesLike self , Object arg , int start , int end ,
913880 @ Cached SequenceStorageNodes .LenNode lenNode ,
@@ -1024,8 +991,8 @@ protected int find(VirtualFrame frame, SequenceStorage storage, PBytesLike sep,
1024991 // bytes.count(x)
1025992 // bytearray.count(x)
1026993 @ 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 )
1029996 @ GenerateNodeFactory
1030997 @ ImportStatic (SpecialMethodNames .class )
1031998 public abstract static class CountNode extends PythonQuaternaryClinicBuiltinNode {
@@ -1035,14 +1002,6 @@ protected ArgumentClinicProvider getArgumentClinic() {
10351002 return BytesBuiltinsClinicProviders .CountNodeClinicProviderGen .INSTANCE ;
10361003 }
10371004
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-
10461005 @ Specialization
10471006 static int count (PBytesLike self , int sub , int start , int end ,
10481007 @ Cached .Shared ("castNode" ) @ Cached CastToJavaByteNode cast ,
@@ -1151,23 +1110,15 @@ private static int countMulti(SequenceStorage bytes, int start, int end, Object
11511110 // bytes.find(bytes[, start[, end]])
11521111 // bytearray.find(bytes[, start[, end]])
11531112 @ 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 )
11561115 @ GenerateNodeFactory
11571116 abstract static class FindNode extends PythonQuaternaryClinicBuiltinNode {
11581117 @ Override
11591118 protected ArgumentClinicProvider getArgumentClinic () {
11601119 return BytesBuiltinsClinicProviders .FindNodeClinicProviderGen .INSTANCE ;
11611120 }
11621121
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-
11711122 @ Specialization
11721123 static int find (PBytesLike self , Object sub , int start , int end ,
11731124 @ Cached SequenceStorageNodes .LenNode lenNode ,
@@ -1182,23 +1133,15 @@ static int find(PBytesLike self, Object sub, int start, int end,
11821133 // bytes.rfind(bytes[, start[, end]])
11831134 // bytearray.rfind(bytes[, start[, end]])
11841135 @ 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 )
11871138 @ GenerateNodeFactory
11881139 abstract static class RFindNode extends PythonQuaternaryClinicBuiltinNode {
11891140 @ Override
11901141 protected ArgumentClinicProvider getArgumentClinic () {
11911142 return BytesBuiltinsClinicProviders .RFindNodeClinicProviderGen .INSTANCE ;
11921143 }
11931144
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-
12021145 @ Specialization
12031146 static int find (PBytesLike self , Object sub , int start , int end ,
12041147 @ Cached SequenceStorageNodes .LenNode lenNode ,
@@ -2798,38 +2741,6 @@ protected final String getErrorMessage() {
27982741
27992742 }
28002743
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-
28332744 protected static int adjustStartIndex (int startIn , int len ) {
28342745 if (startIn < 0 ) {
28352746 int start = startIn + len ;
0 commit comments