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

Side by Side Diff: src/preparser.h

Issue 231073002: WIP: Parser: delay string internalization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: more cleanup Created 6 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
« no previous file with comments | « src/parser.cc ('k') | src/prettyprinter.h » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_PREPARSER_H 5 #ifndef V8_PREPARSER_H
6 #define V8_PREPARSER_H 6 #define V8_PREPARSER_H
7 7
8 #include "func-name-inferrer.h" 8 #include "func-name-inferrer.h"
9 #include "hashmap.h" 9 #include "hashmap.h"
10 #include "scopes.h" 10 #include "scopes.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 typename Traits::Type::Scope* outer_scope_; 142 typename Traits::Type::Scope* outer_scope_;
143 typename Traits::Type::Scope* scope_; 143 typename Traits::Type::Scope* scope_;
144 }; 144 };
145 145
146 class FunctionState BASE_EMBEDDED { 146 class FunctionState BASE_EMBEDDED {
147 public: 147 public:
148 FunctionState( 148 FunctionState(
149 FunctionState** function_state_stack, 149 FunctionState** function_state_stack,
150 typename Traits::Type::Scope** scope_stack, 150 typename Traits::Type::Scope** scope_stack,
151 typename Traits::Type::Scope* scope, 151 typename Traits::Type::Scope* scope,
152 typename Traits::Type::Zone* zone = NULL); 152 typename Traits::Type::Zone* extra_param = NULL,
153 AstStringTable* string_table = NULL);
153 ~FunctionState(); 154 ~FunctionState();
154 155
155 int NextMaterializedLiteralIndex() { 156 int NextMaterializedLiteralIndex() {
156 return next_materialized_literal_index_++; 157 return next_materialized_literal_index_++;
157 } 158 }
158 int materialized_literal_count() { 159 int materialized_literal_count() {
159 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; 160 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize;
160 } 161 }
161 162
162 int NextHandlerIndex() { return next_handler_index_++; } 163 int NextHandlerIndex() { return next_handler_index_++; }
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 350
350 // Report syntax errors. 351 // Report syntax errors.
351 void ReportMessage(const char* message, const char* arg = NULL, 352 void ReportMessage(const char* message, const char* arg = NULL,
352 bool is_reference_error = false) { 353 bool is_reference_error = false) {
353 Scanner::Location source_location = scanner()->location(); 354 Scanner::Location source_location = scanner()->location();
354 Traits::ReportMessageAt(source_location, message, arg, is_reference_error); 355 Traits::ReportMessageAt(source_location, message, arg, is_reference_error);
355 } 356 }
356 357
357 void ReportMessageAt(Scanner::Location location, const char* message, 358 void ReportMessageAt(Scanner::Location location, const char* message,
358 bool is_reference_error = false) { 359 bool is_reference_error = false) {
359 Traits::ReportMessageAt(location, message, NULL, is_reference_error); 360 Traits::ReportMessageAt(location, message,
361 reinterpret_cast<const char*>(NULL),
362 is_reference_error);
360 } 363 }
361 364
362 void ReportUnexpectedToken(Token::Value token); 365 void ReportUnexpectedToken(Token::Value token);
363 366
364 // Recursive descent functions: 367 // Recursive descent functions:
365 368
366 // Parses an identifier that is valid for the current scope, in particular it 369 // Parses an identifier that is valid for the current scope, in particular it
367 // fails on strict mode future reserved keywords in a strict scope. If 370 // fails on strict mode future reserved keywords in a strict scope. If
368 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or 371 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or
369 // "arguments" as identifier even in strict mode (this is needed in cases like 372 // "arguments" as identifier even in strict mode (this is needed in cases like
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 void SetStrictMode(StrictMode strict_mode) { strict_mode_ = strict_mode; } 739 void SetStrictMode(StrictMode strict_mode) { strict_mode_ = strict_mode; }
737 740
738 private: 741 private:
739 ScopeType scope_type_; 742 ScopeType scope_type_;
740 StrictMode strict_mode_; 743 StrictMode strict_mode_;
741 }; 744 };
742 745
743 746
744 class PreParserFactory { 747 class PreParserFactory {
745 public: 748 public:
746 explicit PreParserFactory(void* extra_param) {} 749 explicit PreParserFactory(void* extra_param1, void* extra_param2) {}
747 PreParserExpression NewLiteral(PreParserIdentifier identifier, 750 PreParserExpression NewLiteral(PreParserIdentifier identifier,
748 int pos) { 751 int pos) {
749 return PreParserExpression::Default(); 752 return PreParserExpression::Default();
750 } 753 }
751 PreParserExpression NewNumberLiteral(double number, 754 PreParserExpression NewNumberLiteral(double number,
752 int pos) { 755 int pos) {
753 return PreParserExpression::Default(); 756 return PreParserExpression::Default();
754 } 757 }
755 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, 758 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern,
756 PreParserIdentifier js_flags, 759 PreParserIdentifier js_flags,
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 } 993 }
991 994
992 // Odd-ball literal creators. 995 // Odd-ball literal creators.
993 static PreParserExpression GetLiteralTheHole(int position, 996 static PreParserExpression GetLiteralTheHole(int position,
994 PreParserFactory* factory) { 997 PreParserFactory* factory) {
995 return PreParserExpression::Default(); 998 return PreParserExpression::Default();
996 } 999 }
997 1000
998 // Producing data during the recursive descent. 1001 // Producing data during the recursive descent.
999 PreParserIdentifier GetSymbol(Scanner* scanner); 1002 PreParserIdentifier GetSymbol(Scanner* scanner);
1000 static PreParserIdentifier NextLiteralString(Scanner* scanner, 1003
1001 PretenureFlag tenured) { 1004 static PreParserIdentifier GetNextSymbol(Scanner* scanner) {
1002 return PreParserIdentifier::Default(); 1005 return PreParserIdentifier::Default();
1003 } 1006 }
1004 1007
1005 static PreParserExpression ThisExpression(PreParserScope* scope, 1008 static PreParserExpression ThisExpression(PreParserScope* scope,
1006 PreParserFactory* factory) { 1009 PreParserFactory* factory) {
1007 return PreParserExpression::This(); 1010 return PreParserExpression::This();
1008 } 1011 }
1009 1012
1010 static PreParserExpression ExpressionFromLiteral( 1013 static PreParserExpression ExpressionFromLiteral(
1011 Token::Value token, int pos, Scanner* scanner, 1014 Token::Value token, int pos, Scanner* scanner,
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 void ParseLazyFunctionLiteralBody(bool* ok); 1180 void ParseLazyFunctionLiteralBody(bool* ok);
1178 1181
1179 bool CheckInOrOf(bool accept_OF); 1182 bool CheckInOrOf(bool accept_OF);
1180 }; 1183 };
1181 1184
1182 template<class Traits> 1185 template<class Traits>
1183 ParserBase<Traits>::FunctionState::FunctionState( 1186 ParserBase<Traits>::FunctionState::FunctionState(
1184 FunctionState** function_state_stack, 1187 FunctionState** function_state_stack,
1185 typename Traits::Type::Scope** scope_stack, 1188 typename Traits::Type::Scope** scope_stack,
1186 typename Traits::Type::Scope* scope, 1189 typename Traits::Type::Scope* scope,
1187 typename Traits::Type::Zone* extra_param) 1190 typename Traits::Type::Zone* extra_param,
1191 AstStringTable* string_table)
1188 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), 1192 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize),
1189 next_handler_index_(0), 1193 next_handler_index_(0),
1190 expected_property_count_(0), 1194 expected_property_count_(0),
1191 is_generator_(false), 1195 is_generator_(false),
1192 generator_object_variable_(NULL), 1196 generator_object_variable_(NULL),
1193 function_state_stack_(function_state_stack), 1197 function_state_stack_(function_state_stack),
1194 outer_function_state_(*function_state_stack), 1198 outer_function_state_(*function_state_stack),
1195 scope_stack_(scope_stack), 1199 scope_stack_(scope_stack),
1196 outer_scope_(*scope_stack), 1200 outer_scope_(*scope_stack),
1197 saved_ast_node_id_(0), 1201 saved_ast_node_id_(0),
1198 extra_param_(extra_param), 1202 extra_param_(extra_param),
1199 factory_(extra_param) { 1203 factory_(extra_param, string_table) {
1200 *scope_stack_ = scope; 1204 *scope_stack_ = scope;
1201 *function_state_stack = this; 1205 *function_state_stack = this;
1202 Traits::SetUpFunctionState(this, extra_param); 1206 Traits::SetUpFunctionState(this, extra_param);
1203 } 1207 }
1204 1208
1205 1209
1206 template<class Traits> 1210 template<class Traits>
1207 ParserBase<Traits>::FunctionState::~FunctionState() { 1211 ParserBase<Traits>::FunctionState::~FunctionState() {
1208 *scope_stack_ = outer_scope_; 1212 *scope_stack_ = outer_scope_;
1209 *function_state_stack_ = outer_function_state_; 1213 *function_state_stack_ = outer_function_state_;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 int pos = peek_position(); 1320 int pos = peek_position();
1317 if (!scanner()->ScanRegExpPattern(seen_equal)) { 1321 if (!scanner()->ScanRegExpPattern(seen_equal)) {
1318 Next(); 1322 Next();
1319 ReportMessage("unterminated_regexp"); 1323 ReportMessage("unterminated_regexp");
1320 *ok = false; 1324 *ok = false;
1321 return Traits::EmptyExpression(); 1325 return Traits::EmptyExpression();
1322 } 1326 }
1323 1327
1324 int literal_index = function_state_->NextMaterializedLiteralIndex(); 1328 int literal_index = function_state_->NextMaterializedLiteralIndex();
1325 1329
1326 IdentifierT js_pattern = this->NextLiteralString(scanner(), TENURED); 1330 IdentifierT js_pattern = this->GetNextSymbol(scanner());
1327 if (!scanner()->ScanRegExpFlags()) { 1331 if (!scanner()->ScanRegExpFlags()) {
1328 Next(); 1332 Next();
1329 ReportMessageAt(scanner()->location(), "invalid_regexp_flags"); 1333 ReportMessageAt(scanner()->location(), "invalid_regexp_flags");
1330 *ok = false; 1334 *ok = false;
1331 return Traits::EmptyExpression(); 1335 return Traits::EmptyExpression();
1332 } 1336 }
1333 IdentifierT js_flags = this->NextLiteralString(scanner(), TENURED); 1337 IdentifierT js_flags = this->GetNextSymbol(scanner());
1334 Next(); 1338 Next();
1335 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos); 1339 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos);
1336 } 1340 }
1337 1341
1338 1342
1339 #define CHECK_OK ok); \ 1343 #define CHECK_OK ok); \
1340 if (!*ok) return this->EmptyExpression(); \ 1344 if (!*ok) return this->EmptyExpression(); \
1341 ((void)0 1345 ((void)0
1342 #define DUMMY ) // to make indentation work 1346 #define DUMMY ) // to make indentation work
1343 #undef DUMMY 1347 #undef DUMMY
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
2165 "accessor_get_set"); 2169 "accessor_get_set");
2166 } 2170 }
2167 *ok = false; 2171 *ok = false;
2168 } 2172 }
2169 } 2173 }
2170 2174
2171 2175
2172 } } // v8::internal 2176 } } // v8::internal
2173 2177
2174 #endif // V8_PREPARSER_H 2178 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/prettyprinter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698