| 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 "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 scope->AddVariable(context_var); | 191 scope->AddVariable(context_var); |
| 192 set_saved_context_var(context_var); | 192 set_saved_context_var(context_var); |
| 193 } | 193 } |
| 194 | 194 |
| 195 // Frame indices are relative to the frame pointer and are decreasing. | 195 // Frame indices are relative to the frame pointer and are decreasing. |
| 196 ASSERT(next_free_frame_index <= first_stack_local_index_); | 196 ASSERT(next_free_frame_index <= first_stack_local_index_); |
| 197 stack_local_count_ = first_stack_local_index_ - next_free_frame_index; | 197 stack_local_count_ = first_stack_local_index_ - next_free_frame_index; |
| 198 } | 198 } |
| 199 | 199 |
| 200 | 200 |
| 201 bool TokenStreamIterator::IsValid() const { | |
| 202 return !tokens_.IsNull(); | |
| 203 } | |
| 204 | |
| 205 | |
| 206 Token::Kind TokenStreamIterator::CurrentTokenKind() const { | |
| 207 return tokens_.KindAt(token_position_); | |
| 208 } | |
| 209 | |
| 210 | |
| 211 Token::Kind TokenStreamIterator::LookaheadTokenKind(intptr_t num_tokens) const { | |
| 212 return tokens_.KindAt(token_position_ + num_tokens); | |
| 213 } | |
| 214 | |
| 215 | |
| 216 RawObject* TokenStreamIterator::CurrentToken() const { | |
| 217 return tokens_.TokenAt(token_position_); | |
| 218 } | |
| 219 | |
| 220 | |
| 221 RawString* TokenStreamIterator::CurrentLiteral() const { | |
| 222 return tokens_.LiteralAt(token_position_); | |
| 223 } | |
| 224 | |
| 225 | |
| 226 struct Parser::Block : public ZoneAllocated { | 201 struct Parser::Block : public ZoneAllocated { |
| 227 Block(Block* outer_block, LocalScope* local_scope, SequenceNode* seq) | 202 Block(Block* outer_block, LocalScope* local_scope, SequenceNode* seq) |
| 228 : parent(outer_block), scope(local_scope), statements(seq) { | 203 : parent(outer_block), scope(local_scope), statements(seq) { |
| 229 ASSERT(scope != NULL); | 204 ASSERT(scope != NULL); |
| 230 ASSERT(statements != NULL); | 205 ASSERT(statements != NULL); |
| 231 } | 206 } |
| 232 Block* parent; // Enclosing block, or NULL if outermost. | 207 Block* parent; // Enclosing block, or NULL if outermost. |
| 233 LocalScope* scope; | 208 LocalScope* scope; |
| 234 SequenceNode* statements; | 209 SequenceNode* statements; |
| 235 }; | 210 }; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 token_kind_ = Token::kILLEGAL; | 326 token_kind_ = Token::kILLEGAL; |
| 352 } | 327 } |
| 353 | 328 |
| 354 | 329 |
| 355 void Parser::ParseCompilationUnit(const Library& library, | 330 void Parser::ParseCompilationUnit(const Library& library, |
| 356 const Script& script) { | 331 const Script& script) { |
| 357 ASSERT(Isolate::Current()->long_jump_base()->IsSafeToJump()); | 332 ASSERT(Isolate::Current()->long_jump_base()->IsSafeToJump()); |
| 358 TimerScope timer(FLAG_compiler_stats, &CompilerStats::parser_timer); | 333 TimerScope timer(FLAG_compiler_stats, &CompilerStats::parser_timer); |
| 359 Parser parser(script, library); | 334 Parser parser(script, library); |
| 360 parser.ParseTopLevel(); | 335 parser.ParseTopLevel(); |
| 361 if (FLAG_compiler_stats) { | |
| 362 CompilerStats::num_tokens_total += parser.tokens_iterator_.NumberOfTokens(); | |
| 363 } | |
| 364 } | 336 } |
| 365 | 337 |
| 366 | 338 |
| 367 Token::Kind Parser::CurrentToken() { | 339 Token::Kind Parser::CurrentToken() { |
| 368 if (token_kind_ == Token::kILLEGAL) { | 340 if (token_kind_ == Token::kILLEGAL) { |
| 369 token_kind_ = tokens_iterator_.CurrentTokenKind(); | 341 token_kind_ = tokens_iterator_.CurrentTokenKind(); |
| 370 if (token_kind_ == Token::kERROR) { | 342 if (token_kind_ == Token::kERROR) { |
| 371 ErrorMsg(TokenPos(), CurrentLiteral()->ToCString()); | 343 ErrorMsg(TokenPos(), CurrentLiteral()->ToCString()); |
| 372 } | 344 } |
| 373 } | 345 } |
| (...skipping 8278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8652 void Parser::SkipQualIdent() { | 8624 void Parser::SkipQualIdent() { |
| 8653 ASSERT(IsIdentifier()); | 8625 ASSERT(IsIdentifier()); |
| 8654 ConsumeToken(); | 8626 ConsumeToken(); |
| 8655 if (CurrentToken() == Token::kPERIOD) { | 8627 if (CurrentToken() == Token::kPERIOD) { |
| 8656 ConsumeToken(); // Consume the kPERIOD token. | 8628 ConsumeToken(); // Consume the kPERIOD token. |
| 8657 ExpectIdentifier("identifier expected after '.'"); | 8629 ExpectIdentifier("identifier expected after '.'"); |
| 8658 } | 8630 } |
| 8659 } | 8631 } |
| 8660 | 8632 |
| 8661 } // namespace dart | 8633 } // namespace dart |
| OLD | NEW |