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

Side by Side Diff: vm/scanner.cc

Issue 10783035: Create frequently used symbols in the vm isolate (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 5 months 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
« no previous file with comments | « vm/runtime_entry_test.cc ('k') | vm/scopes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "vm/symbols.h"
11 #include "vm/thread.h" 12 #include "vm/thread.h"
12 #include "vm/token.h" 13 #include "vm/token.h"
13 14
14 namespace dart { 15 namespace dart {
15 16
16 DEFINE_FLAG(bool, disable_privacy, false, "Disable library privacy."); 17 DEFINE_FLAG(bool, disable_privacy, false, "Disable library privacy.");
17 DEFINE_FLAG(bool, print_tokens, false, "Print scanned tokens."); 18 DEFINE_FLAG(bool, print_tokens, false, "Print scanned tokens.");
18 19
19 void Scanner::InitKeywordTable() { 20 void Scanner::InitKeywordTable() {
20 ObjectStore* object_store = Isolate::Current()->object_store(); 21 ObjectStore* object_store = Isolate::Current()->object_store();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 while (saved_context_ != NULL) { 68 while (saved_context_ != NULL) {
68 ScanContext* ctx = saved_context_; 69 ScanContext* ctx = saved_context_;
69 saved_context_ = ctx->next; 70 saved_context_ = ctx->next;
70 delete ctx; 71 delete ctx;
71 } 72 }
72 } 73 }
73 74
74 75
75 void Scanner::ErrorMsg(const char* msg) { 76 void Scanner::ErrorMsg(const char* msg) {
76 current_token_.kind = Token::kERROR; 77 current_token_.kind = Token::kERROR;
77 current_token_.literal = &String::ZoneHandle(String::NewSymbol(msg)); 78 current_token_.literal = &String::ZoneHandle(Symbols::New(msg));
78 current_token_.position = c0_pos_; 79 current_token_.position = c0_pos_;
79 token_start_ = lookahead_pos_; 80 token_start_ = lookahead_pos_;
80 current_token_.offset = lookahead_pos_; 81 current_token_.offset = lookahead_pos_;
81 } 82 }
82 83
83 84
84 void Scanner::PushContext() { 85 void Scanner::PushContext() {
85 ScanContext* ctx = new ScanContext; 86 ScanContext* ctx = new ScanContext;
86 ctx->next = saved_context_; 87 ctx->next = saved_context_;
87 saved_context_ = ctx; 88 saved_context_ = ctx;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 int char_pos = 0; 270 int char_pos = 0;
270 while ((char_pos < ident_length) && 271 while ((char_pos < ident_length) &&
271 (keyword[char_pos] == source_.CharAt(ident_pos + char_pos))) { 272 (keyword[char_pos] == source_.CharAt(ident_pos + char_pos))) {
272 char_pos++; 273 char_pos++;
273 } 274 }
274 if (char_pos == ident_length) { 275 if (char_pos == ident_length) {
275 if (keywords_[i].keyword_symbol == NULL) { 276 if (keywords_[i].keyword_symbol == NULL) {
276 String& symbol = String::ZoneHandle(); 277 String& symbol = String::ZoneHandle();
277 symbol ^= keyword_symbol_table_.At(i); 278 symbol ^= keyword_symbol_table_.At(i);
278 if (symbol.IsNull()) { 279 if (symbol.IsNull()) {
279 symbol = String::NewSymbol(source_, ident_pos, ident_length); 280 symbol = Symbols::New(source_, ident_pos, ident_length);
280 keyword_symbol_table_.SetAt(i, symbol); 281 keyword_symbol_table_.SetAt(i, symbol);
281 } 282 }
282 keywords_[i].keyword_symbol = &symbol; 283 keywords_[i].keyword_symbol = &symbol;
283 } 284 }
284 current_token_.literal = keywords_[i].keyword_symbol; 285 current_token_.literal = keywords_[i].keyword_symbol;
285 current_token_.kind = keywords_[i].kind; 286 current_token_.kind = keywords_[i].kind;
286 return; 287 return;
287 } 288 }
288 } 289 }
289 i++; 290 i++;
290 } 291 }
291 292
292 // We did not read a keyword. 293 // We did not read a keyword.
293 current_token_.kind = Token::kIDENT; 294 current_token_.kind = Token::kIDENT;
294 String& literal = 295 String& literal =
295 String::ZoneHandle(String::NewSymbol(source_, ident_pos, ident_length)); 296 String::ZoneHandle(Symbols::New(source_, ident_pos, ident_length));
296 if ((ident_char0 == kPrivateIdentifierStart) && !FLAG_disable_privacy) { 297 if ((ident_char0 == kPrivateIdentifierStart) && !FLAG_disable_privacy) {
297 // Private identifiers are mangled on a per script basis. 298 // Private identifiers are mangled on a per script basis.
298 literal = String::Concat(literal, private_key_); 299 literal = String::Concat(literal, private_key_);
299 literal = String::NewSymbol(literal); 300 literal = Symbols::New(literal);
300 } 301 }
301 current_token_.literal = &literal; 302 current_token_.literal = &literal;
302 } 303 }
303 304
304 305
305 // Parse integer or double number literal of format: 306 // Parse integer or double number literal of format:
306 // NUMBER = INTEGER | DOUBLE 307 // NUMBER = INTEGER | DOUBLE
307 // INTEGER = D+ | (("0x" | "0X") H+) 308 // INTEGER = D+ | (("0x" | "0X") H+)
308 // DOUBLE = ((D+ ["." D*]) | ("." D+)) [ EXPONENT ] 309 // DOUBLE = ((D+ ["." D*]) | ("." D+)) [ EXPONENT ]
309 // EXPONENT = ("e" | "E") ["+" | "-"] D+ 310 // EXPONENT = ("e" | "E") ["+" | "-"] D+
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 360
360 RawString* Scanner::ConsumeIdentChars(bool allow_dollar) { 361 RawString* Scanner::ConsumeIdentChars(bool allow_dollar) {
361 ASSERT(IsIdentStartChar(c0_)); 362 ASSERT(IsIdentStartChar(c0_));
362 ASSERT(allow_dollar || (c0_ != '$')); 363 ASSERT(allow_dollar || (c0_ != '$'));
363 int ident_length = 0; 364 int ident_length = 0;
364 int32_t ident_pos = lookahead_pos_; 365 int32_t ident_pos = lookahead_pos_;
365 while (IsIdentChar(c0_) && (allow_dollar || (c0_ != '$'))) { 366 while (IsIdentChar(c0_) && (allow_dollar || (c0_ != '$'))) {
366 ReadChar(); 367 ReadChar();
367 ident_length++; 368 ident_length++;
368 } 369 }
369 return String::NewSymbol(source_, ident_pos, ident_length); 370 return Symbols::New(source_, ident_pos, ident_length);
370 } 371 }
371 372
372 373
373 void Scanner::SkipLine() { 374 void Scanner::SkipLine() {
374 while (c0_ != '\n' && c0_ != '\0') { 375 while (c0_ != '\n' && c0_ != '\0') {
375 ReadChar(); 376 ReadChar();
376 } 377 }
377 } 378 }
378 379
379 380
380 void Scanner::ScanLibraryTag() { 381 void Scanner::ScanLibraryTag() {
381 ReadChar(); 382 ReadChar();
382 if (c0_ == '!') { 383 if (c0_ == '!') {
383 Recognize(Token::kSCRIPTTAG); 384 Recognize(Token::kSCRIPTTAG);
384 // The script tag extends to the end of the line. Just treat this 385 // The script tag extends to the end of the line. Just treat this
385 // similar to a line comment. 386 // similar to a line comment.
386 SkipLine(); 387 SkipLine();
387 return; 388 return;
388 } 389 }
389 if (!IsLetter(c0_)) { 390 if (!IsLetter(c0_)) {
390 ErrorMsg("Unrecognized library tag"); 391 ErrorMsg("Unrecognized library tag");
391 SkipLine(); 392 SkipLine();
392 return; 393 return;
393 } 394 }
394 const String& kLibrary = String::Handle(String::NewSymbol("library")); 395 const String& kLibrary = String::Handle(Symbols::New("library"));
395 const String& kImport = String::Handle(String::NewSymbol("import")); 396 const String& kImport = String::Handle(Symbols::New("import"));
396 const String& kSource = String::Handle(String::NewSymbol("source")); 397 const String& kSource = String::Handle(Symbols::New("source"));
397 const String& kResource = String::Handle(String::NewSymbol("resource")); 398 const String& kResource = String::Handle(Symbols::New("resource"));
398 const String& ident = String::Handle(ConsumeIdentChars(false)); 399 const String& ident = String::Handle(ConsumeIdentChars(false));
399 if (ident.Equals(kLibrary)) { 400 if (ident.Equals(kLibrary)) {
400 current_token_.kind = Token::kLIBRARY; 401 current_token_.kind = Token::kLIBRARY;
401 return; 402 return;
402 } 403 }
403 if (ident.Equals(kImport)) { 404 if (ident.Equals(kImport)) {
404 current_token_.kind = Token::kIMPORT; 405 current_token_.kind = Token::kIMPORT;
405 return; 406 return;
406 } 407 }
407 if (ident.Equals(kSource)) { 408 if (ident.Equals(kSource)) {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 } 547 }
547 escape_char = c0_; 548 escape_char = c0_;
548 break; 549 break;
549 } 550 }
550 string_chars.Add(escape_char); 551 string_chars.Add(escape_char);
551 } else if (c0_ == '$' && !is_raw) { 552 } else if (c0_ == '$' && !is_raw) {
552 // Scanned a string piece. 553 // Scanned a string piece.
553 ASSERT(string_chars.data() != NULL); 554 ASSERT(string_chars.data() != NULL);
554 // Strings are canonicalized: Allocate a symbol. 555 // Strings are canonicalized: Allocate a symbol.
555 current_token_.literal = &String::ZoneHandle( 556 current_token_.literal = &String::ZoneHandle(
556 String::NewSymbol(string_chars.data(), string_chars.length())); 557 Symbols::New(string_chars.data(), string_chars.length()));
557 // Preserve error tokens. 558 // Preserve error tokens.
558 if (current_token_.kind != Token::kERROR) { 559 if (current_token_.kind != Token::kERROR) {
559 current_token_.kind = Token::kSTRING; 560 current_token_.kind = Token::kSTRING;
560 } 561 }
561 return; 562 return;
562 } else if (c0_ == string_delimiter_) { 563 } else if (c0_ == string_delimiter_) {
563 // Check if we are at the end of the string literal. 564 // Check if we are at the end of the string literal.
564 if (!string_is_multiline_ || 565 if (!string_is_multiline_ ||
565 ((LookaheadChar(1) == string_delimiter_) && 566 ((LookaheadChar(1) == string_delimiter_) &&
566 (LookaheadChar(2) == string_delimiter_))) { 567 (LookaheadChar(2) == string_delimiter_))) {
567 if (string_is_multiline_) { 568 if (string_is_multiline_) {
568 ReadChar(); // Skip two string delimiters. 569 ReadChar(); // Skip two string delimiters.
569 ReadChar(); 570 ReadChar();
570 } 571 }
571 // Preserve error tokens. 572 // Preserve error tokens.
572 if (current_token_.kind == Token::kERROR) { 573 if (current_token_.kind == Token::kERROR) {
573 ReadChar(); 574 ReadChar();
574 } else { 575 } else {
575 Recognize(Token::kSTRING); 576 Recognize(Token::kSTRING);
576 ASSERT(string_chars.data() != NULL); 577 ASSERT(string_chars.data() != NULL);
577 // Strings are canonicalized: Allocate a symbol. 578 // Strings are canonicalized: Allocate a symbol.
578 current_token_.literal = &String::ZoneHandle( 579 current_token_.literal = &String::ZoneHandle(
579 String::NewSymbol(string_chars.data(), string_chars.length())); 580 Symbols::New(string_chars.data(), string_chars.length()));
580 } 581 }
581 EndStringLiteral(); 582 EndStringLiteral();
582 return; 583 return;
583 } else { 584 } else {
584 string_chars.Add(string_delimiter_); 585 string_chars.Add(string_delimiter_);
585 } 586 }
586 } else { 587 } else {
587 string_chars.Add(c0_); 588 string_chars.Add(c0_);
588 } 589 }
589 ReadChar(); 590 ReadChar();
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 "%c%"PRIxPTR, kPrivateKeySeparator, key_value); 945 "%c%"PRIxPTR, kPrivateKeySeparator, key_value);
945 const String& result = String::Handle(String::New(private_key, Heap::kOld)); 946 const String& result = String::Handle(String::New(private_key, Heap::kOld));
946 return result.raw(); 947 return result.raw();
947 } 948 }
948 949
949 950
950 void Scanner::InitOnce() { 951 void Scanner::InitOnce() {
951 } 952 }
952 953
953 } // namespace dart 954 } // namespace dart
OLDNEW
« no previous file with comments | « vm/runtime_entry_test.cc ('k') | vm/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698