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/parser.h" | 5 #include "vm/parser.h" |
6 | 6 |
7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
9 #include "vm/bootstrap.h" | 9 #include "vm/bootstrap.h" |
10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 if (script.HasSource()) { | 57 if (script.HasSource()) { |
58 intptr_t line, column; | 58 intptr_t line, column; |
59 script.GetTokenLocation(token_pos, &line, &column); | 59 script.GetTokenLocation(token_pos, &line, &column); |
60 PrintIndent(); | 60 PrintIndent(); |
61 OS::Print("%s (line %" Pd ", col %" Pd ", token %" Pd ")\n", | 61 OS::Print("%s (line %" Pd ", col %" Pd ", token %" Pd ")\n", |
62 msg, line, column, token_pos); | 62 msg, line, column, token_pos); |
63 } | 63 } |
64 indent_++; | 64 indent_++; |
65 } | 65 } |
66 } | 66 } |
67 ~TraceParser() { indent_--; } | 67 ~TraceParser() { if (FLAG_trace_parser) indent_--; } |
68 private: | 68 private: |
69 void PrintIndent() { | 69 void PrintIndent() { |
70 for (int i = 0; i < indent_; i++) { OS::Print(". "); } | 70 for (int i = 0; i < indent_; i++) { OS::Print(". "); } |
71 } | 71 } |
72 static int indent_; | 72 static int indent_; |
73 }; | 73 }; |
74 | 74 |
75 int TraceParser::indent_ = 0; | 75 int TraceParser::indent_ = 0; |
76 | 76 |
77 #define TRACE_PARSER(s) \ | 77 #define TRACE_PARSER(s) \ |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 } | 338 } |
339 | 339 |
340 | 340 |
341 void Parser::set_current_class(const Class& value) { | 341 void Parser::set_current_class(const Class& value) { |
342 current_class_ = value.raw(); | 342 current_class_ = value.raw(); |
343 } | 343 } |
344 | 344 |
345 | 345 |
346 void Parser::SetPosition(intptr_t position) { | 346 void Parser::SetPosition(intptr_t position) { |
347 if (position < TokenPos() && position != 0) { | 347 if (position < TokenPos() && position != 0) { |
348 CompilerStats::num_tokens_rewind += (TokenPos() - position); | 348 if (FLAG_compiler_stats) { |
| 349 CompilerStats::num_tokens_rewind += (TokenPos() - position); |
| 350 } |
349 } | 351 } |
350 tokens_iterator_.SetCurrentPosition(position); | 352 tokens_iterator_.SetCurrentPosition(position); |
351 token_kind_ = Token::kILLEGAL; | 353 token_kind_ = Token::kILLEGAL; |
352 } | 354 } |
353 | 355 |
354 | 356 |
355 void Parser::ParseCompilationUnit(const Library& library, | 357 void Parser::ParseCompilationUnit(const Library& library, |
356 const Script& script) { | 358 const Script& script) { |
357 ASSERT(Isolate::Current()->long_jump_base()->IsSafeToJump()); | 359 ASSERT(Isolate::Current()->long_jump_base()->IsSafeToJump()); |
358 TimerScope timer(FLAG_compiler_stats, &CompilerStats::parser_timer); | 360 TimerScope timer(FLAG_compiler_stats, &CompilerStats::parser_timer); |
359 Parser parser(script, library, 0); | 361 Parser parser(script, library, 0); |
360 parser.ParseTopLevel(); | 362 parser.ParseTopLevel(); |
361 } | 363 } |
362 | 364 |
363 | 365 |
364 Token::Kind Parser::CurrentToken() { | 366 Token::Kind Parser::CurrentToken() { |
365 if (token_kind_ == Token::kILLEGAL) { | 367 if (token_kind_ == Token::kILLEGAL) { |
366 token_kind_ = tokens_iterator_.CurrentTokenKind(); | 368 token_kind_ = tokens_iterator_.CurrentTokenKind(); |
367 if (token_kind_ == Token::kERROR) { | 369 if (token_kind_ == Token::kERROR) { |
368 ErrorMsg(TokenPos(), "%s", CurrentLiteral()->ToCString()); | 370 ErrorMsg(TokenPos(), "%s", CurrentLiteral()->ToCString()); |
369 } | 371 } |
370 } | 372 } |
371 CompilerStats::num_token_checks++; | 373 if (FLAG_compiler_stats) { |
| 374 CompilerStats::num_token_checks++; |
| 375 } |
372 return token_kind_; | 376 return token_kind_; |
373 } | 377 } |
374 | 378 |
375 | 379 |
376 Token::Kind Parser::LookaheadToken(int num_tokens) { | 380 Token::Kind Parser::LookaheadToken(int num_tokens) { |
377 CompilerStats::num_tokens_lookahead++; | 381 if (FLAG_compiler_stats) { |
378 CompilerStats::num_token_checks++; | 382 CompilerStats::num_tokens_lookahead++; |
| 383 CompilerStats::num_token_checks++; |
| 384 } |
379 return tokens_iterator_.LookaheadTokenKind(num_tokens); | 385 return tokens_iterator_.LookaheadTokenKind(num_tokens); |
380 } | 386 } |
381 | 387 |
382 | 388 |
383 String* Parser::CurrentLiteral() const { | 389 String* Parser::CurrentLiteral() const { |
384 String& result = String::ZoneHandle(); | 390 String& result = String::ZoneHandle(); |
385 result = tokens_iterator_.CurrentLiteral(); | 391 result = tokens_iterator_.CurrentLiteral(); |
386 return &result; | 392 return &result; |
387 } | 393 } |
388 | 394 |
(...skipping 10114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10503 void Parser::SkipQualIdent() { | 10509 void Parser::SkipQualIdent() { |
10504 ASSERT(IsIdentifier()); | 10510 ASSERT(IsIdentifier()); |
10505 ConsumeToken(); | 10511 ConsumeToken(); |
10506 if (CurrentToken() == Token::kPERIOD) { | 10512 if (CurrentToken() == Token::kPERIOD) { |
10507 ConsumeToken(); // Consume the kPERIOD token. | 10513 ConsumeToken(); // Consume the kPERIOD token. |
10508 ExpectIdentifier("identifier expected after '.'"); | 10514 ExpectIdentifier("identifier expected after '.'"); |
10509 } | 10515 } |
10510 } | 10516 } |
10511 | 10517 |
10512 } // namespace dart | 10518 } // namespace dart |
OLD | NEW |