OLD | NEW |
---|---|
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
509 } | 509 } |
510 } | 510 } |
511 literal.Complete(); | 511 literal.Complete(); |
512 Advance(); | 512 Advance(); |
513 return Token::STRING; | 513 return Token::STRING; |
514 } | 514 } |
515 | 515 |
516 | 516 |
517 Token::Value JsonScanner::ScanJsonNumber() { | 517 Token::Value JsonScanner::ScanJsonNumber() { |
518 LiteralScope literal(this); | 518 LiteralScope literal(this); |
519 if (c0_ == '-') AddLiteralCharAdvance(); | 519 bool sign = (c0_ == '-'); |
Lasse Reichstein
2011/02/04 13:53:36
Call the variable "negative".
It's not obvious wh
sandholm
2011/02/04 14:26:37
Done.
| |
520 | |
521 if (sign) AddLiteralCharAdvance(); | |
Lasse Reichstein
2011/02/04 13:53:36
I would prefer:
bool negative = false;
if (c0_ ==
sandholm
2011/02/04 14:26:37
Done.
| |
520 if (c0_ == '0') { | 522 if (c0_ == '0') { |
521 AddLiteralCharAdvance(); | 523 AddLiteralCharAdvance(); |
522 // Prefix zero is only allowed if it's the only digit before | 524 // Prefix zero is only allowed if it's the only digit before |
523 // a decimal point or exponent. | 525 // a decimal point or exponent. |
524 if ('0' <= c0_ && c0_ <= '9') return Token::ILLEGAL; | 526 if ('0' <= c0_ && c0_ <= '9') return Token::ILLEGAL; |
525 } else { | 527 } else { |
528 int i = 0; | |
529 int digits = 0; | |
526 if (c0_ < '1' || c0_ > '9') return Token::ILLEGAL; | 530 if (c0_ < '1' || c0_ > '9') return Token::ILLEGAL; |
527 do { | 531 do { |
532 i = i * 10 + c0_ - '0'; | |
533 digits++; | |
528 AddLiteralCharAdvance(); | 534 AddLiteralCharAdvance(); |
529 } while (c0_ >= '0' && c0_ <= '9'); | 535 } while (c0_ >= '0' && c0_ <= '9'); |
536 if (c0_ != '.' && c0_ != 'e' && c0_ != 'E' && digits < 10) { | |
537 number = (sign ? -i : i); | |
538 return Token::NUMBER; | |
539 } | |
530 } | 540 } |
531 if (c0_ == '.') { | 541 if (c0_ == '.') { |
532 AddLiteralCharAdvance(); | 542 AddLiteralCharAdvance(); |
533 if (c0_ < '0' || c0_ > '9') return Token::ILLEGAL; | 543 if (c0_ < '0' || c0_ > '9') return Token::ILLEGAL; |
534 do { | 544 do { |
535 AddLiteralCharAdvance(); | 545 AddLiteralCharAdvance(); |
536 } while (c0_ >= '0' && c0_ <= '9'); | 546 } while (c0_ >= '0' && c0_ <= '9'); |
537 } | 547 } |
538 if (AsciiAlphaToLower(c0_) == 'e') { | 548 if (AsciiAlphaToLower(c0_) == 'e') { |
539 AddLiteralCharAdvance(); | 549 AddLiteralCharAdvance(); |
540 if (c0_ == '-' || c0_ == '+') AddLiteralCharAdvance(); | 550 if (c0_ == '-' || c0_ == '+') AddLiteralCharAdvance(); |
541 if (c0_ < '0' || c0_ > '9') return Token::ILLEGAL; | 551 if (c0_ < '0' || c0_ > '9') return Token::ILLEGAL; |
542 do { | 552 do { |
543 AddLiteralCharAdvance(); | 553 AddLiteralCharAdvance(); |
544 } while (c0_ >= '0' && c0_ <= '9'); | 554 } while (c0_ >= '0' && c0_ <= '9'); |
545 } | 555 } |
546 literal.Complete(); | 556 literal.Complete(); |
557 ASSERT_NOT_NULL(next_.literal_chars); | |
558 number = StringToDouble(next_.literal_chars->ascii_literal(), | |
559 NO_FLAGS, // Hex, octal or trailing junk. | |
560 OS::nan_value()); | |
547 return Token::NUMBER; | 561 return Token::NUMBER; |
548 } | 562 } |
549 | 563 |
550 | 564 |
551 Token::Value JsonScanner::ScanJsonIdentifier(const char* text, | 565 Token::Value JsonScanner::ScanJsonIdentifier(const char* text, |
552 Token::Value token) { | 566 Token::Value token) { |
553 LiteralScope literal(this); | 567 LiteralScope literal(this); |
554 while (*text != '\0') { | 568 while (*text != '\0') { |
555 if (c0_ != *text) return Token::ILLEGAL; | 569 if (c0_ != *text) return Token::ILLEGAL; |
556 Advance(); | 570 Advance(); |
557 text++; | 571 text++; |
558 } | 572 } |
559 if (ScannerConstants::kIsIdentifierPart.get(c0_)) return Token::ILLEGAL; | 573 if (ScannerConstants::kIsIdentifierPart.get(c0_)) return Token::ILLEGAL; |
560 literal.Complete(); | 574 literal.Complete(); |
561 return token; | 575 return token; |
562 } | 576 } |
563 | 577 |
564 | 578 |
565 | 579 |
566 } } // namespace v8::internal | 580 } } // namespace v8::internal |
OLD | NEW |