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

Side by Side Diff: vm/parser.h

Issue 10632009: Make the parser agnostic to the TokenStream implementation. This is the first step towards compacti… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 6 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 #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_index)
114 : tokens_(tokens), token_index_(token_index) { }
115
116 intptr_t Length() const { return tokens_.Length(); }
hausner 2012/06/22 00:02:27 What is the "Length" of an iterator? Do you mean t
siva 2012/06/22 17:59:02 Renamed Length() to NumberOfTokens() basically it
117 bool IsNull() const;
118
119 inline Token::Kind CurrentTokenKind() const;
120 Token::Kind LookaheadTokenKind(intptr_t num_tokens) const;
121
122 intptr_t CurrentIndex() const { return token_index_; }
hausner 2012/06/22 00:02:27 I would not call it an index anymore. What you abs
siva 2012/06/22 17:59:02 Renamed this to CurrentPosition On 2012/06/22 00:
123 void SetCurrentIndex(intptr_t value) { token_index_ = value; }
124
125 void AdvanceToNextToken() { token_index_ += 1; }
126
127 RawObject* CurrentToken() const;
128 RawString* CurrentLiteral() const;
129
130 private:
131 const TokenStream& tokens_;
132 intptr_t token_index_;
133 };
134
135
108 class Parser : ValueObject { 136 class Parser : ValueObject {
109 public: 137 public:
110 Parser(const Script& script, const Library& library); 138 Parser(const Script& script, const Library& library);
111 Parser(const Script& script, 139 Parser(const Script& script,
112 const Function& function, 140 const Function& function,
113 intptr_t token_index); 141 intptr_t token_index);
114 142
115 // Parse the top level of a whole script file and register declared classes 143 // Parse the top level of a whole script file and register declared classes
116 // and interfaces in the given library. 144 // and interfaces in the given library.
117 static void ParseCompilationUnit(const Library& library, 145 static void ParseCompilationUnit(const Library& library,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // The class or interface being parsed. 191 // The class or interface being parsed.
164 const Class& current_class() const; 192 const Class& current_class() const;
165 void set_current_class(const Class& value); 193 void set_current_class(const Class& value);
166 194
167 // Parsing a library or a regular source script. 195 // Parsing a library or a regular source script.
168 bool is_library_source() const { 196 bool is_library_source() const {
169 return (script_.kind() == RawScript::kScript) || 197 return (script_.kind() == RawScript::kScript) ||
170 (script_.kind() == RawScript::kLibrary); 198 (script_.kind() == RawScript::kLibrary);
171 } 199 }
172 200
201 intptr_t TokenIndex() const { return tokens_iterator_.CurrentIndex(); }
173 inline Token::Kind CurrentToken(); 202 inline Token::Kind CurrentToken();
174 Token::Kind LookaheadToken(int num_tokens); 203 Token::Kind LookaheadToken(int num_tokens);
175 String* CurrentLiteral() const; 204 String* CurrentLiteral() const;
176 RawDouble* CurrentDoubleLiteral() const; 205 RawDouble* CurrentDoubleLiteral() const;
177 RawInteger* CurrentIntegerLiteral() const; 206 RawInteger* CurrentIntegerLiteral() const;
178 207
179 // Sets parser to given token position in the stream. 208 // Sets parser to given token position in the stream.
180 void SetPosition(intptr_t position); 209 void SetPosition(intptr_t position);
181 210
182 void ConsumeToken() { 211 void ConsumeToken() {
183 // Reset cache and advance the token. 212 // Reset cache and advance the token.
184 token_kind_ = Token::kILLEGAL; 213 token_kind_ = Token::kILLEGAL;
185 token_index_++; 214 tokens_iterator_.AdvanceToNextToken();
186 CompilerStats::num_tokens_consumed++; 215 CompilerStats::num_tokens_consumed++;
187 } 216 }
188 void ConsumeRightAngleBracket(); 217 void ConsumeRightAngleBracket();
189 void ExpectToken(Token::Kind token_expected); 218 void ExpectToken(Token::Kind token_expected);
190 void ExpectSemicolon(); 219 void ExpectSemicolon();
191 void UnexpectedToken(); 220 void UnexpectedToken();
192 String* ExpectTypeIdentifier(const char* msg); 221 String* ExpectTypeIdentifier(const char* msg);
193 String* ExpectIdentifier(const char* msg); 222 String* ExpectIdentifier(const char* msg);
194 bool IsLiteral(const char* literal); 223 bool IsLiteral(const char* literal);
195 224
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 AstNode* InsertClosureCallNodes(AstNode* condition); 522 AstNode* InsertClosureCallNodes(AstNode* condition);
494 523
495 ConstructorCallNode* CreateConstructorCallNode( 524 ConstructorCallNode* CreateConstructorCallNode(
496 intptr_t token_index, 525 intptr_t token_index,
497 const AbstractTypeArguments& type_arguments, 526 const AbstractTypeArguments& type_arguments,
498 const Function& constructor, 527 const Function& constructor,
499 ArgumentListNode* arguments); 528 ArgumentListNode* arguments);
500 529
501 530
502 const Script& script_; 531 const Script& script_;
503 const TokenStream& tokens_; 532 TokenStreamIterator tokens_iterator_;
504 intptr_t token_index_; 533 Token::Kind token_kind_; // Cached token kind for current token.
505 Token::Kind token_kind_; // Cached token kind for the token_index_.
506 Block* current_block_; 534 Block* current_block_;
507 535
508 // is_top_level_ is true if parsing the "top level" of a compilation unit, 536 // is_top_level_ is true if parsing the "top level" of a compilation unit,
509 // that is interface and class definitions. 537 // that is interface and class definitions.
510 bool is_top_level_; 538 bool is_top_level_;
511 539
512 // The member currently being parsed during "top level" parsing. 540 // The member currently being parsed during "top level" parsing.
513 MemberDesc* current_member_; 541 MemberDesc* current_member_;
514 542
515 // Parser mode to allow/disallow function literals. This is used in 543 // Parser mode to allow/disallow function literals. This is used in
(...skipping 18 matching lines...) Expand all
534 562
535 // Allocate temporary only once per function. 563 // Allocate temporary only once per function.
536 LocalVariable* expression_temp_; 564 LocalVariable* expression_temp_;
537 565
538 DISALLOW_COPY_AND_ASSIGN(Parser); 566 DISALLOW_COPY_AND_ASSIGN(Parser);
539 }; 567 };
540 568
541 } // namespace dart 569 } // namespace dart
542 570
543 #endif // VM_PARSER_H_ 571 #endif // VM_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698