@@ -48,37 +48,41 @@ class IntegerLiteral extends NumericLiteral, TIntegerLiteral {
48
48
}
49
49
50
50
private int parseInteger ( Ruby:: Integer i ) {
51
- exists ( string s , string values , string str |
52
- s = i .getValue ( ) .toLowerCase ( ) and
53
- (
51
+ exists ( string s | s = i .getValue ( ) .toLowerCase ( ) .replaceAll ( "_" , "" ) |
52
+ s .charAt ( 0 ) != "0" and
53
+ result = s .toInt ( )
54
+ or
55
+ exists ( string str , string values , int shift |
54
56
s .matches ( "0b%" ) and
55
57
values = "01" and
56
- str = s .suffix ( 2 )
58
+ str = s .suffix ( 2 ) and
59
+ shift = 1
57
60
or
58
61
s .matches ( "0x%" ) and
59
62
values = "0123456789abcdef" and
60
- str = s .suffix ( 2 )
63
+ str = s .suffix ( 2 ) and
64
+ shift = 4
61
65
or
62
66
s .charAt ( 0 ) = "0" and
63
67
not s .charAt ( 1 ) = [ "b" , "x" , "o" ] and
64
68
values = "01234567" and
65
- str = s .suffix ( 1 )
69
+ str = s .suffix ( 1 ) and
70
+ shift = 3
66
71
or
67
72
s .matches ( "0o%" ) and
68
73
values = "01234567" and
69
- str = s .suffix ( 2 )
70
- or
71
- s .charAt ( 0 ) != "0" and values = "0123456789" and str = s
74
+ str = s .suffix ( 2 ) and
75
+ shift = 3
76
+ |
77
+ result =
78
+ sum ( int index , string c , int v , int exp |
79
+ c = str .charAt ( index ) and
80
+ v = values .indexOf ( c .toLowerCase ( ) ) and
81
+ exp = str .length ( ) - index - 1
82
+ |
83
+ v .bitShiftLeft ( ( str .length ( ) - index - 1 ) * shift )
84
+ )
72
85
)
73
- |
74
- result =
75
- sum ( int index , string c , int v , int exp |
76
- c = str .replaceAll ( "_" , "" ) .charAt ( index ) and
77
- v = values .indexOf ( c .toLowerCase ( ) ) and
78
- exp = str .replaceAll ( "_" , "" ) .length ( ) - index - 1
79
- |
80
- v * values .length ( ) .pow ( exp ) .floor ( )
81
- )
82
86
)
83
87
}
84
88
0 commit comments