1 /* |
1 /* |
2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
299 reader.scanChar(); |
299 reader.scanChar(); |
300 } |
300 } |
301 } |
301 } |
302 |
302 |
303 /** Read a number. |
303 /** Read a number. |
304 * @param radix The radix of the number; one of 2, j8, 10, 16. |
304 * @param radix The radix of the number; one of 2, 8, 10, 16. |
305 */ |
305 */ |
306 private void scanNumber(int pos, int radix) { |
306 private void scanNumber(int pos, int radix) { |
307 // for octal, allow base-10 digit in case it's a float literal |
307 // for octal, allow base-10 digit in case it's a float literal |
308 this.radix = radix; |
308 this.radix = radix; |
309 int digitRadix = (radix == 8 ? 10 : radix); |
309 int digitRadix = (radix == 8 ? 10 : radix); |
310 boolean seendigit = false; |
310 int firstDigit = reader.digit(pos, Math.max(10, digitRadix)); |
311 if (reader.digit(pos, digitRadix) >= 0) { |
311 boolean seendigit = firstDigit >= 0; |
312 seendigit = true; |
312 boolean seenValidDigit = firstDigit >= 0 && firstDigit < digitRadix; |
|
313 if (seendigit) { |
313 scanDigits(pos, digitRadix); |
314 scanDigits(pos, digitRadix); |
314 } |
315 } |
315 if (radix == 16 && reader.ch == '.') { |
316 if (radix == 16 && reader.ch == '.') { |
316 scanHexFractionAndSuffix(pos, seendigit); |
317 scanHexFractionAndSuffix(pos, seendigit); |
317 } else if (seendigit && radix == 16 && (reader.ch == 'p' || reader.ch == 'P')) { |
318 } else if (seendigit && radix == 16 && (reader.ch == 'p' || reader.ch == 'P')) { |
323 (reader.ch == 'e' || reader.ch == 'E' || |
324 (reader.ch == 'e' || reader.ch == 'E' || |
324 reader.ch == 'f' || reader.ch == 'F' || |
325 reader.ch == 'f' || reader.ch == 'F' || |
325 reader.ch == 'd' || reader.ch == 'D')) { |
326 reader.ch == 'd' || reader.ch == 'D')) { |
326 scanFractionAndSuffix(pos); |
327 scanFractionAndSuffix(pos); |
327 } else { |
328 } else { |
|
329 if (!seenValidDigit) { |
|
330 switch (radix) { |
|
331 case 2: |
|
332 lexError(pos, "invalid.binary.number"); |
|
333 break; |
|
334 case 16: |
|
335 lexError(pos, "invalid.hex.number"); |
|
336 break; |
|
337 } |
|
338 } |
328 if (reader.ch == 'l' || reader.ch == 'L') { |
339 if (reader.ch == 'l' || reader.ch == 'L') { |
329 reader.scanChar(); |
340 reader.scanChar(); |
330 tk = TokenKind.LONGLITERAL; |
341 tk = TokenKind.LONGLITERAL; |
331 } else { |
342 } else { |
332 tk = TokenKind.INTLITERAL; |
343 tk = TokenKind.INTLITERAL; |
489 case '0': |
500 case '0': |
490 reader.scanChar(); |
501 reader.scanChar(); |
491 if (reader.ch == 'x' || reader.ch == 'X') { |
502 if (reader.ch == 'x' || reader.ch == 'X') { |
492 reader.scanChar(); |
503 reader.scanChar(); |
493 skipIllegalUnderscores(); |
504 skipIllegalUnderscores(); |
494 if (reader.ch == '.') { |
505 scanNumber(pos, 16); |
495 scanHexFractionAndSuffix(pos, false); |
|
496 } else if (reader.digit(pos, 16) < 0) { |
|
497 lexError(pos, "invalid.hex.number"); |
|
498 } else { |
|
499 scanNumber(pos, 16); |
|
500 } |
|
501 } else if (reader.ch == 'b' || reader.ch == 'B') { |
506 } else if (reader.ch == 'b' || reader.ch == 'B') { |
502 if (!allowBinaryLiterals) { |
507 if (!allowBinaryLiterals) { |
503 lexError(pos, "unsupported.binary.lit", source.name); |
508 lexError(pos, "unsupported.binary.lit", source.name); |
504 allowBinaryLiterals = true; |
509 allowBinaryLiterals = true; |
505 } |
510 } |
506 reader.scanChar(); |
511 reader.scanChar(); |
507 skipIllegalUnderscores(); |
512 skipIllegalUnderscores(); |
508 if (reader.digit(pos, 2) < 0) { |
513 scanNumber(pos, 2); |
509 lexError(pos, "invalid.binary.number"); |
|
510 } else { |
|
511 scanNumber(pos, 2); |
|
512 } |
|
513 } else { |
514 } else { |
514 reader.putChar('0'); |
515 reader.putChar('0'); |
515 if (reader.ch == '_') { |
516 if (reader.ch == '_') { |
516 int savePos = reader.bp; |
517 int savePos = reader.bp; |
517 do { |
518 do { |