Lines 30-79
Link Here
|
30 |
public void computeConstant() { |
30 |
public void computeConstant() { |
31 |
//the overflow (when radix=10) is tested using the fact that |
31 |
//the overflow (when radix=10) is tested using the fact that |
32 |
//the value should always grow during its computation |
32 |
//the value should always grow during its computation |
33 |
|
|
|
34 |
int length = source.length - 1; //minus one because the last char is 'l' or 'L' |
33 |
int length = source.length - 1; //minus one because the last char is 'l' or 'L' |
35 |
|
34 |
|
36 |
long computedValue ; |
35 |
long computedValue ; |
37 |
if (source[0] == '0') |
36 |
if (source[0] == '0') { |
38 |
{ if (length == 1) { constant = Constant.fromValue(0L); return; } |
37 |
if (length == 1) { |
|
|
38 |
constant = Constant.fromValue(0L); |
39 |
return; |
40 |
} |
39 |
final int shift,radix; |
41 |
final int shift,radix; |
40 |
int j ; |
42 |
int j ; |
41 |
if ( (source[1] == 'x') || (source[1] == 'X') ) |
43 |
if ( (source[1] == 'x') || (source[1] == 'X') ) { |
42 |
{ shift = 4 ; j = 2; radix = 16;} |
44 |
shift = 4 ; j = 2; radix = 16; |
43 |
else |
45 |
} else { |
44 |
{ shift = 3 ; j = 1; radix = 8;} |
46 |
shift = 3 ; j = 1; radix = 8; |
|
|
47 |
} |
45 |
int nbDigit = 0; |
48 |
int nbDigit = 0; |
46 |
while (source[j]=='0') |
49 |
while (source[j]=='0') { |
47 |
{ j++; //jump over redondant zero |
50 |
j++; //jump over redondant zero |
48 |
if ( j == length) |
51 |
if ( j == length) { |
49 |
{ //watch for 0000000000000L |
52 |
//watch for 0000000000000L |
50 |
constant = Constant.fromValue(value = 0L); |
53 |
constant = Constant.fromValue(value = 0L); |
51 |
return ;}} |
54 |
return ; |
|
|
55 |
} |
56 |
} |
52 |
|
57 |
|
53 |
int digitValue ; |
58 |
int digitValue ; |
54 |
if ((digitValue = Character.digit(source[j++],radix)) < 0 ) |
59 |
if ((digitValue = Character.digit(source[j++],radix)) < 0 ) { |
55 |
{ constant = FORMAT_ERROR; return ;} |
60 |
constant = FORMAT_ERROR; return ; |
56 |
if (digitValue >= 8) nbDigit = 4; |
61 |
} |
57 |
else if (digitValue >= 4) nbDigit = 3; |
62 |
if (digitValue >= 8) |
58 |
else if (digitValue >= 2) nbDigit = 2; |
63 |
nbDigit = 4; |
59 |
else nbDigit = 1; //digitValue is not 0 |
64 |
else if (digitValue >= 4) |
|
|
65 |
nbDigit = 3; |
66 |
else if (digitValue >= 2) |
67 |
nbDigit = 2; |
68 |
else |
69 |
nbDigit = 1; //digitValue is not 0 |
60 |
computedValue = digitValue ; |
70 |
computedValue = digitValue ; |
61 |
while (j<length) |
71 |
while (j<length) { |
62 |
{ if ((digitValue = Character.digit(source[j++],radix)) < 0 ) |
72 |
if ((digitValue = Character.digit(source[j++],radix)) < 0) { |
63 |
{ constant = FORMAT_ERROR; return ;} |
73 |
constant = FORMAT_ERROR; return ; |
64 |
if ((nbDigit += shift) > 64) return /*constant stays null*/ ; |
74 |
} |
65 |
computedValue = (computedValue<<shift) | digitValue ;}} |
75 |
if ((nbDigit += shift) > 64) |
66 |
|
76 |
return /*constant stays null*/ ; |
67 |
else |
77 |
computedValue = (computedValue<<shift) | digitValue ; |
68 |
{ //-----------case radix=10----------------- |
78 |
} |
69 |
long previous = computedValue = 0; |
79 |
} else { |
70 |
for (int i = 0 ; i < length; i++) |
80 |
//-----------case radix=10----------------- |
71 |
{ int digitValue ; |
81 |
long previous = 0; |
72 |
if ((digitValue = Character.digit(source[i], 10)) < 0 ) return /*constant stays null*/ ; |
82 |
computedValue = 0; |
|
|
83 |
final long limit = Long.MAX_VALUE / 10; // needed to check prior to the multiplication |
84 |
for (int i = 0 ; i < length; i++) { |
85 |
int digitValue ; |
86 |
if ((digitValue = Character.digit(source[i], 10)) < 0 ) return /*constant stays null*/; |
73 |
previous = computedValue; |
87 |
previous = computedValue; |
74 |
computedValue = 10 * computedValue + digitValue ; |
88 |
if (computedValue > limit) |
75 |
if (previous > computedValue) return /*constant stays null*/;}} |
89 |
return /*constant stays null*/; |
76 |
|
90 |
computedValue *= 10; |
|
|
91 |
if ((computedValue + digitValue) > Long.MAX_VALUE) |
92 |
return /*constant stays null*/; |
93 |
computedValue += digitValue; |
94 |
if (previous > computedValue) |
95 |
return /*constant stays null*/; |
96 |
} |
97 |
} |
77 |
constant = Constant.fromValue(value = computedValue); |
98 |
constant = Constant.fromValue(value = computedValue); |
78 |
} |
99 |
} |
79 |
/** |
100 |
/** |
Lines 118-124
Link Here
|
118 |
(source[15] == '5') && |
139 |
(source[15] == '5') && |
119 |
(source[16] == '8') && |
140 |
(source[16] == '8') && |
120 |
(source[17] == '0') && |
141 |
(source[17] == '0') && |
121 |
(source[18] == '8'));} |
142 |
(source[18] == '8')); |
|
|
143 |
} |
122 |
public TypeBinding resolveType(BlockScope scope) { |
144 |
public TypeBinding resolveType(BlockScope scope) { |
123 |
// the format may be incorrect while the scanner could detect |
145 |
// the format may be incorrect while the scanner could detect |
124 |
// such error only on painfull tests...easier and faster here |
146 |
// such error only on painfull tests...easier and faster here |