Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: runtime/vm/scanner.cc

Issue 11368138: Add some support for the code-point code-unit distinction. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Implemented feedback from patch set 3 Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/scanner.h" 5 #include "vm/scanner.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/flags.h" 8 #include "vm/flags.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/object_store.h" 10 #include "vm/object_store.h"
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 } 491 }
492 if (is_valid && 492 if (is_valid &&
493 ((*code_point > 0x10FFFF) || 493 ((*code_point > 0x10FFFF) ||
494 ((*code_point & 0xFFFFF800) == 0xD800))) { 494 ((*code_point & 0xFFFFF800) == 0xD800))) {
495 ErrorMsg("invalid code point"); 495 ErrorMsg("invalid code point");
496 } 496 }
497 } 497 }
498 498
499 499
500 void Scanner::ScanLiteralStringChars(bool is_raw) { 500 void Scanner::ScanLiteralStringChars(bool is_raw) {
501 GrowableArray<uint32_t> string_chars(64); 501 GrowableArray<uint16_t> string_chars(64);
502 502
503 ASSERT(IsScanningString()); 503 ASSERT(IsScanningString());
504 // We are at the first character of a string literal piece. A string literal 504 // We are at the first character of a string literal piece. A string literal
505 // can be broken up into multiple pieces by string interpolation. 505 // can be broken up into multiple pieces by string interpolation.
506 while (true) { 506 while (true) {
507 if ((c0_ == '\0') || ((c0_ == '\n') && !string_is_multiline_)) { 507 if ((c0_ == '\0') || ((c0_ == '\n') && !string_is_multiline_)) {
508 ErrorMsg("unterminated string literal"); 508 ErrorMsg("unterminated string literal");
509 EndStringLiteral(); 509 EndStringLiteral();
510 return; 510 return;
511 } 511 }
(...skipping 15 matching lines...) Expand all
527 escape_char = '\t'; 527 escape_char = '\t';
528 break; 528 break;
529 case 'b': 529 case 'b':
530 escape_char = '\b'; 530 escape_char = '\b';
531 break; 531 break;
532 case 'v': 532 case 'v':
533 escape_char = '\v'; 533 escape_char = '\v';
534 break; 534 break;
535 case 'u': 535 case 'u':
536 case 'x': { 536 case 'x': {
537 ScanEscapedCodePoint(&escape_char); 537 uint32_t ch;
538 ScanEscapedCodePoint(&ch);
539 int32_t code_point = ch;
540 if (code_point > Utf16::kMaxCodeUnit) {
541 string_chars.Add(Utf16::LeadFromCodePoint(code_point));
542 escape_char = Utf16::TrailFromCodePoint(code_point);
543 } else {
544 escape_char = code_point;
545 }
538 break; 546 break;
539 } 547 }
540 default: 548 default:
541 if ((c0_ == '\0') || ((c0_ == '\n') && !string_is_multiline_)) { 549 if ((c0_ == '\0') || ((c0_ == '\n') && !string_is_multiline_)) {
542 ErrorMsg("unterminated string literal"); 550 ErrorMsg("unterminated string literal");
543 EndStringLiteral(); 551 EndStringLiteral();
544 return; 552 return;
545 } 553 }
546 escape_char = c0_; 554 escape_char = c0_;
547 break; 555 break;
548 } 556 }
549 string_chars.Add(escape_char); 557 string_chars.Add(escape_char);
550 } else if (c0_ == '$' && !is_raw) { 558 } else if (c0_ == '$' && !is_raw) {
551 // Scanned a string piece. 559 // Scanned a string piece.
552 ASSERT(string_chars.data() != NULL); 560 ASSERT(string_chars.data() != NULL);
553 // Strings are canonicalized: Allocate a symbol. 561 // Strings are canonicalized: Allocate a symbol.
554 current_token_.literal = &String::ZoneHandle( 562 current_token_.literal = &String::ZoneHandle(
555 Symbols::New(string_chars.data(), string_chars.length())); 563 Symbols::New(string_chars.data(), string_chars.length()));
siva 2012/11/20 00:48:00 Is the change above necessary considering that thi
556 // Preserve error tokens. 564 // Preserve error tokens.
557 if (current_token_.kind != Token::kERROR) { 565 if (current_token_.kind != Token::kERROR) {
558 current_token_.kind = Token::kSTRING; 566 current_token_.kind = Token::kSTRING;
559 } 567 }
560 return; 568 return;
561 } else if (c0_ == string_delimiter_) { 569 } else if (c0_ == string_delimiter_) {
562 // Check if we are at the end of the string literal. 570 // Check if we are at the end of the string literal.
563 if (!string_is_multiline_ || 571 if (!string_is_multiline_ ||
564 ((LookaheadChar(1) == string_delimiter_) && 572 ((LookaheadChar(1) == string_delimiter_) &&
565 (LookaheadChar(2) == string_delimiter_))) { 573 (LookaheadChar(2) == string_delimiter_))) {
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 "%c%#"Px"", kPrivateKeySeparator, key_value); 960 "%c%#"Px"", kPrivateKeySeparator, key_value);
953 const String& result = String::Handle(String::New(private_key, Heap::kOld)); 961 const String& result = String::Handle(String::New(private_key, Heap::kOld));
954 return result.raw(); 962 return result.raw();
955 } 963 }
956 964
957 965
958 void Scanner::InitOnce() { 966 void Scanner::InitOnce() {
959 } 967 }
960 968
961 } // namespace dart 969 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/scanner.h ('k') | runtime/vm/symbols.cc » ('j') | runtime/vm/unicode.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698