| OLD | NEW |
| 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/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 4458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4469 } | 4469 } |
| 4470 return result.raw(); | 4470 return result.raw(); |
| 4471 } | 4471 } |
| 4472 | 4472 |
| 4473 | 4473 |
| 4474 const char* TokenStream::ToCString() const { | 4474 const char* TokenStream::ToCString() const { |
| 4475 return "TokenStream"; | 4475 return "TokenStream"; |
| 4476 } | 4476 } |
| 4477 | 4477 |
| 4478 | 4478 |
| 4479 RawString* Script::source() const { | 4479 bool Script::HasSource() const { |
| 4480 return raw_ptr()->source_ != String::null(); |
| 4481 } |
| 4482 |
| 4483 |
| 4484 RawString* Script::Source() const { |
| 4480 String& source = String::Handle(raw_ptr()->source_); | 4485 String& source = String::Handle(raw_ptr()->source_); |
| 4481 if (source.IsNull()) { | 4486 if (source.IsNull()) { |
| 4482 const TokenStream& token_stream = TokenStream::Handle(tokens()); | 4487 const TokenStream& token_stream = TokenStream::Handle(tokens()); |
| 4483 return token_stream.GenerateSource(); | 4488 return token_stream.GenerateSource(); |
| 4484 } else { | 4489 } else { |
| 4485 return raw_ptr()->source_; | 4490 return raw_ptr()->source_; |
| 4486 } | 4491 } |
| 4487 } | 4492 } |
| 4488 | 4493 |
| 4489 | 4494 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 4509 | 4514 |
| 4510 void Script::Tokenize(const String& private_key) const { | 4515 void Script::Tokenize(const String& private_key) const { |
| 4511 const TokenStream& tkns = TokenStream::Handle(tokens()); | 4516 const TokenStream& tkns = TokenStream::Handle(tokens()); |
| 4512 if (!tkns.IsNull()) { | 4517 if (!tkns.IsNull()) { |
| 4513 // Already tokenized. | 4518 // Already tokenized. |
| 4514 return; | 4519 return; |
| 4515 } | 4520 } |
| 4516 | 4521 |
| 4517 // Get the source, scan and allocate the token stream. | 4522 // Get the source, scan and allocate the token stream. |
| 4518 TimerScope timer(FLAG_compiler_stats, &CompilerStats::scanner_timer); | 4523 TimerScope timer(FLAG_compiler_stats, &CompilerStats::scanner_timer); |
| 4519 const String& src = String::Handle(source()); | 4524 const String& src = String::Handle(Source()); |
| 4520 Scanner scanner(src, private_key); | 4525 Scanner scanner(src, private_key); |
| 4521 set_tokens(TokenStream::Handle(TokenStream::New(scanner.GetStream()))); | 4526 set_tokens(TokenStream::Handle(TokenStream::New(scanner.GetStream()))); |
| 4522 if (FLAG_compiler_stats) { | 4527 if (FLAG_compiler_stats) { |
| 4523 CompilerStats::src_length += src.Length(); | 4528 CompilerStats::src_length += src.Length(); |
| 4524 } | 4529 } |
| 4525 } | 4530 } |
| 4526 | 4531 |
| 4527 | 4532 |
| 4528 void Script::GetTokenLocation(intptr_t token_pos, | 4533 void Script::GetTokenLocation(intptr_t token_pos, |
| 4529 intptr_t* line, | 4534 intptr_t* line, |
| 4530 intptr_t* column) const { | 4535 intptr_t* column) const { |
| 4531 const String& src = String::Handle(source()); | 4536 const String& src = String::Handle(Source()); |
| 4532 const String& dummy_key = String::Handle(String::New("")); | 4537 const String& dummy_key = String::Handle(String::New("")); |
| 4533 Scanner scanner(src, dummy_key); | 4538 Scanner scanner(src, dummy_key); |
| 4534 scanner.ScanTo(token_pos); | 4539 scanner.ScanTo(token_pos); |
| 4535 *line = scanner.CurrentPosition().line; | 4540 *line = scanner.CurrentPosition().line; |
| 4536 *column = scanner.CurrentPosition().column; | 4541 *column = scanner.CurrentPosition().column; |
| 4537 } | 4542 } |
| 4538 | 4543 |
| 4539 | 4544 |
| 4540 void Script::TokenRangeAtLine(intptr_t line_number, | 4545 void Script::TokenRangeAtLine(intptr_t line_number, |
| 4541 intptr_t* first_token_index, | 4546 intptr_t* first_token_index, |
| 4542 intptr_t* last_token_index) const { | 4547 intptr_t* last_token_index) const { |
| 4543 const String& src = String::Handle(source()); | 4548 const String& src = String::Handle(Source()); |
| 4544 const String& dummy_key = String::Handle(String::New("")); | 4549 const String& dummy_key = String::Handle(String::New("")); |
| 4545 Scanner scanner(src, dummy_key); | 4550 Scanner scanner(src, dummy_key); |
| 4546 scanner.TokenRangeAtLine(line_number, first_token_index, last_token_index); | 4551 scanner.TokenRangeAtLine(line_number, first_token_index, last_token_index); |
| 4547 } | 4552 } |
| 4548 | 4553 |
| 4549 | 4554 |
| 4550 RawString* Script::GetLine(intptr_t line_number) const { | 4555 RawString* Script::GetLine(intptr_t line_number) const { |
| 4551 const String& src = String::Handle(source()); | 4556 const String& src = String::Handle(Source()); |
| 4552 intptr_t current_line = 1; | 4557 intptr_t current_line = 1; |
| 4553 intptr_t line_start = -1; | 4558 intptr_t line_start = -1; |
| 4554 intptr_t last_char = -1; | 4559 intptr_t last_char = -1; |
| 4555 for (intptr_t ix = 0; | 4560 for (intptr_t ix = 0; |
| 4556 (ix < src.Length()) && (current_line <= line_number); | 4561 (ix < src.Length()) && (current_line <= line_number); |
| 4557 ix++) { | 4562 ix++) { |
| 4558 if ((current_line == line_number) && (line_start < 0)) { | 4563 if ((current_line == line_number) && (line_start < 0)) { |
| 4559 line_start = ix; | 4564 line_start = ix; |
| 4560 } | 4565 } |
| 4561 if (src.CharAt(ix) == '\n') { | 4566 if (src.CharAt(ix) == '\n') { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4574 line = String::SubString(src, line_start, last_char - line_start + 1); | 4579 line = String::SubString(src, line_start, last_char - line_start + 1); |
| 4575 } | 4580 } |
| 4576 return line.raw(); | 4581 return line.raw(); |
| 4577 } | 4582 } |
| 4578 | 4583 |
| 4579 | 4584 |
| 4580 RawString* Script::GetSnippet(intptr_t from_line, | 4585 RawString* Script::GetSnippet(intptr_t from_line, |
| 4581 intptr_t from_column, | 4586 intptr_t from_column, |
| 4582 intptr_t to_line, | 4587 intptr_t to_line, |
| 4583 intptr_t to_column) const { | 4588 intptr_t to_column) const { |
| 4584 const String& src = String::Handle(source()); | 4589 const String& src = String::Handle(Source()); |
| 4585 intptr_t length = src.Length(); | 4590 intptr_t length = src.Length(); |
| 4586 intptr_t line = 1; | 4591 intptr_t line = 1; |
| 4587 intptr_t column = 1; | 4592 intptr_t column = 1; |
| 4588 intptr_t lookahead = 0; | 4593 intptr_t lookahead = 0; |
| 4589 intptr_t snippet_start = -1; | 4594 intptr_t snippet_start = -1; |
| 4590 intptr_t snippet_end = -1; | 4595 intptr_t snippet_end = -1; |
| 4591 char c = src.CharAt(lookahead); | 4596 char c = src.CharAt(lookahead); |
| 4592 while (lookahead != length) { | 4597 while (lookahead != length) { |
| 4593 if (snippet_start == -1) { | 4598 if (snippet_start == -1) { |
| 4594 if ((line == from_line) && (column == from_column)) { | 4599 if ((line == from_line) && (column == from_column)) { |
| (...skipping 5613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10208 const String& str = String::Handle(pattern()); | 10213 const String& str = String::Handle(pattern()); |
| 10209 const char* format = "JSRegExp: pattern=%s flags=%s"; | 10214 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 10210 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 10215 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 10211 char* chars = reinterpret_cast<char*>( | 10216 char* chars = reinterpret_cast<char*>( |
| 10212 Isolate::Current()->current_zone()->Allocate(len + 1)); | 10217 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 10213 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 10218 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 10214 return chars; | 10219 return chars; |
| 10215 } | 10220 } |
| 10216 | 10221 |
| 10217 } // namespace dart | 10222 } // namespace dart |
| OLD | NEW |