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

Side by Side Diff: vm/parser.cc

Issue 10697055: Represent tokens as a compressed stream instead of an array. (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
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/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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 scope->AddVariable(context_var); 189 scope->AddVariable(context_var);
190 set_saved_context_var(context_var); 190 set_saved_context_var(context_var);
191 } 191 }
192 192
193 // Frame indices are relative to the frame pointer and are decreasing. 193 // Frame indices are relative to the frame pointer and are decreasing.
194 ASSERT(next_free_frame_index <= first_stack_local_index_); 194 ASSERT(next_free_frame_index <= first_stack_local_index_);
195 stack_local_count_ = first_stack_local_index_ - next_free_frame_index; 195 stack_local_count_ = first_stack_local_index_ - next_free_frame_index;
196 } 196 }
197 197
198 198
199 bool TokenStreamIterator::IsValid() const {
200 return !tokens_.IsNull();
201 }
202
203
204 Token::Kind TokenStreamIterator::CurrentTokenKind() const {
205 return tokens_.KindAt(token_position_);
206 }
207
208
209 Token::Kind TokenStreamIterator::LookaheadTokenKind(intptr_t num_tokens) const {
210 return tokens_.KindAt(token_position_ + num_tokens);
211 }
212
213
214 RawObject* TokenStreamIterator::CurrentToken() const {
215 return tokens_.TokenAt(token_position_);
216 }
217
218
219 RawString* TokenStreamIterator::CurrentLiteral() const {
220 return tokens_.LiteralAt(token_position_);
221 }
222
223
224 struct Parser::Block : public ZoneAllocated { 199 struct Parser::Block : public ZoneAllocated {
225 Block(Block* outer_block, LocalScope* local_scope, SequenceNode* seq) 200 Block(Block* outer_block, LocalScope* local_scope, SequenceNode* seq)
226 : parent(outer_block), scope(local_scope), statements(seq) { 201 : parent(outer_block), scope(local_scope), statements(seq) {
227 ASSERT(scope != NULL); 202 ASSERT(scope != NULL);
228 ASSERT(statements != NULL); 203 ASSERT(statements != NULL);
229 } 204 }
230 Block* parent; // Enclosing block, or NULL if outermost. 205 Block* parent; // Enclosing block, or NULL if outermost.
231 LocalScope* scope; 206 LocalScope* scope;
232 SequenceNode* statements; 207 SequenceNode* statements;
233 }; 208 };
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 token_kind_ = Token::kILLEGAL; 324 token_kind_ = Token::kILLEGAL;
350 } 325 }
351 326
352 327
353 void Parser::ParseCompilationUnit(const Library& library, 328 void Parser::ParseCompilationUnit(const Library& library,
354 const Script& script) { 329 const Script& script) {
355 ASSERT(Isolate::Current()->long_jump_base()->IsSafeToJump()); 330 ASSERT(Isolate::Current()->long_jump_base()->IsSafeToJump());
356 TimerScope timer(FLAG_compiler_stats, &CompilerStats::parser_timer); 331 TimerScope timer(FLAG_compiler_stats, &CompilerStats::parser_timer);
357 Parser parser(script, library); 332 Parser parser(script, library);
358 parser.ParseTopLevel(); 333 parser.ParseTopLevel();
359 if (FLAG_compiler_stats) {
360 CompilerStats::num_tokens_total += parser.tokens_iterator_.NumberOfTokens();
361 }
362 } 334 }
363 335
364 336
365 Token::Kind Parser::CurrentToken() { 337 Token::Kind Parser::CurrentToken() {
366 if (token_kind_ == Token::kILLEGAL) { 338 if (token_kind_ == Token::kILLEGAL) {
367 token_kind_ = tokens_iterator_.CurrentTokenKind(); 339 token_kind_ = tokens_iterator_.CurrentTokenKind();
368 if (token_kind_ == Token::kERROR) { 340 if (token_kind_ == Token::kERROR) {
369 ErrorMsg(TokenPos(), CurrentLiteral()->ToCString()); 341 ErrorMsg(TokenPos(), CurrentLiteral()->ToCString());
370 } 342 }
371 } 343 }
(...skipping 8261 matching lines...) Expand 10 before | Expand all | Expand 10 after
8633 void Parser::SkipQualIdent() { 8605 void Parser::SkipQualIdent() {
8634 ASSERT(IsIdentifier()); 8606 ASSERT(IsIdentifier());
8635 ConsumeToken(); 8607 ConsumeToken();
8636 if (CurrentToken() == Token::kPERIOD) { 8608 if (CurrentToken() == Token::kPERIOD) {
8637 ConsumeToken(); // Consume the kPERIOD token. 8609 ConsumeToken(); // Consume the kPERIOD token.
8638 ExpectIdentifier("identifier expected after '.'"); 8610 ExpectIdentifier("identifier expected after '.'");
8639 } 8611 }
8640 } 8612 }
8641 8613
8642 } // namespace dart 8614 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698