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

Side by Side Diff: vm/parser.h

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
« no previous file with comments | « vm/object_test.cc ('k') | vm/parser.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 #ifndef VM_PARSER_H_ 5 #ifndef VM_PARSER_H_
6 #define VM_PARSER_H_ 6 #define VM_PARSER_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 9
10 #include "vm/ast.h" 10 #include "vm/ast.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 int first_parameter_index_; 99 int first_parameter_index_;
100 int first_stack_local_index_; 100 int first_stack_local_index_;
101 int copied_parameter_count_; 101 int copied_parameter_count_;
102 int stack_local_count_; 102 int stack_local_count_;
103 103
104 DISALLOW_COPY_AND_ASSIGN(ParsedFunction); 104 DISALLOW_COPY_AND_ASSIGN(ParsedFunction);
105 }; 105 };
106 106
107 107
108 // The class TokenStreamIterator encapsulates iteration over the TokenStream
109 // object. The parser uses this to iterate over tokens while parsing a script
110 // or a function.
111 class TokenStreamIterator : ValueObject {
112 public:
113 TokenStreamIterator(const TokenStream& tokens, intptr_t token_pos)
114 : tokens_(tokens), token_position_(token_pos) { }
115
116 intptr_t NumberOfTokens() const { return tokens_.Length(); }
117 bool IsValid() const;
118
119 inline Token::Kind CurrentTokenKind() const;
120 Token::Kind LookaheadTokenKind(intptr_t num_tokens) const;
121
122 intptr_t CurrentPosition() const { return token_position_; }
123 void SetCurrentPosition(intptr_t value) { token_position_ = value; }
124
125 void Advance() { token_position_ += 1; }
126
127 RawObject* CurrentToken() const;
128 RawString* CurrentLiteral() const;
129
130 private:
131 const TokenStream& tokens_;
132 intptr_t token_position_;
133 };
134
135
136 class Parser : ValueObject { 108 class Parser : ValueObject {
137 public: 109 public:
138 Parser(const Script& script, const Library& library); 110 Parser(const Script& script, const Library& library);
139 Parser(const Script& script, const Function& function, intptr_t token_pos); 111 Parser(const Script& script, const Function& function, intptr_t token_pos);
140 112
141 // Parse the top level of a whole script file and register declared classes 113 // Parse the top level of a whole script file and register declared classes
142 // and interfaces in the given library. 114 // and interfaces in the given library.
143 static void ParseCompilationUnit(const Library& library, 115 static void ParseCompilationUnit(const Library& library,
144 const Script& script); 116 const Script& script);
145 117
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 AstNode* InsertClosureCallNodes(AstNode* condition); 505 AstNode* InsertClosureCallNodes(AstNode* condition);
534 506
535 ConstructorCallNode* CreateConstructorCallNode( 507 ConstructorCallNode* CreateConstructorCallNode(
536 intptr_t token_pos, 508 intptr_t token_pos,
537 const AbstractTypeArguments& type_arguments, 509 const AbstractTypeArguments& type_arguments,
538 const Function& constructor, 510 const Function& constructor,
539 ArgumentListNode* arguments); 511 ArgumentListNode* arguments);
540 512
541 513
542 const Script& script_; 514 const Script& script_;
543 TokenStreamIterator tokens_iterator_; 515 TokenStream::Iterator tokens_iterator_;
544 Token::Kind token_kind_; // Cached token kind for current token. 516 Token::Kind token_kind_; // Cached token kind for current token.
545 Block* current_block_; 517 Block* current_block_;
546 518
547 // is_top_level_ is true if parsing the "top level" of a compilation unit, 519 // is_top_level_ is true if parsing the "top level" of a compilation unit,
548 // that is interface and class definitions. 520 // that is interface and class definitions.
549 bool is_top_level_; 521 bool is_top_level_;
550 522
551 // The member currently being parsed during "top level" parsing. 523 // The member currently being parsed during "top level" parsing.
552 MemberDesc* current_member_; 524 MemberDesc* current_member_;
553 525
(...skipping 22 matching lines...) Expand all
576 548
577 // Allocate temporary only once per function. 549 // Allocate temporary only once per function.
578 LocalVariable* expression_temp_; 550 LocalVariable* expression_temp_;
579 551
580 DISALLOW_COPY_AND_ASSIGN(Parser); 552 DISALLOW_COPY_AND_ASSIGN(Parser);
581 }; 553 };
582 554
583 } // namespace dart 555 } // namespace dart
584 556
585 #endif // VM_PARSER_H_ 557 #endif // VM_PARSER_H_
OLDNEW
« no previous file with comments | « vm/object_test.cc ('k') | vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698