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

Side by Side Diff: src/preparser.h

Issue 335293004: New try: Parser: Delay internalizing strings and values (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: efficiency fix: create string constants on demand 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
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 "src/func-name-inferrer.h" 8 #include "src/func-name-inferrer.h"
9 #include "src/hashmap.h" 9 #include "src/hashmap.h"
10 #include "src/scopes.h" 10 #include "src/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* zone = NULL,
153 AstValueFactory* ast_value_factory = 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 NewStringLiteral(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,
757 int literal_index, 760 int literal_index,
758 int pos) { 761 int pos) {
(...skipping 231 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 void ParseLazyFunctionLiteralBody(bool* ok); 1182 void ParseLazyFunctionLiteralBody(bool* ok);
1180 1183
1181 bool CheckInOrOf(bool accept_OF); 1184 bool CheckInOrOf(bool accept_OF);
1182 }; 1185 };
1183 1186
1184 template<class Traits> 1187 template<class Traits>
1185 ParserBase<Traits>::FunctionState::FunctionState( 1188 ParserBase<Traits>::FunctionState::FunctionState(
1186 FunctionState** function_state_stack, 1189 FunctionState** function_state_stack,
1187 typename Traits::Type::Scope** scope_stack, 1190 typename Traits::Type::Scope** scope_stack,
1188 typename Traits::Type::Scope* scope, 1191 typename Traits::Type::Scope* scope,
1189 typename Traits::Type::Zone* extra_param) 1192 typename Traits::Type::Zone* extra_param,
1193 AstValueFactory* ast_value_factory)
1190 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), 1194 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize),
1191 next_handler_index_(0), 1195 next_handler_index_(0),
1192 expected_property_count_(0), 1196 expected_property_count_(0),
1193 is_generator_(false), 1197 is_generator_(false),
1194 generator_object_variable_(NULL), 1198 generator_object_variable_(NULL),
1195 function_state_stack_(function_state_stack), 1199 function_state_stack_(function_state_stack),
1196 outer_function_state_(*function_state_stack), 1200 outer_function_state_(*function_state_stack),
1197 scope_stack_(scope_stack), 1201 scope_stack_(scope_stack),
1198 outer_scope_(*scope_stack), 1202 outer_scope_(*scope_stack),
1199 saved_ast_node_id_(0), 1203 saved_ast_node_id_(0),
1200 extra_param_(extra_param), 1204 extra_param_(extra_param),
1201 factory_(extra_param) { 1205 factory_(extra_param, ast_value_factory) {
1202 *scope_stack_ = scope; 1206 *scope_stack_ = scope;
1203 *function_state_stack = this; 1207 *function_state_stack = this;
1204 Traits::SetUpFunctionState(this, extra_param); 1208 Traits::SetUpFunctionState(this, extra_param);
1205 } 1209 }
1206 1210
1207 1211
1208 template<class Traits> 1212 template<class Traits>
1209 ParserBase<Traits>::FunctionState::~FunctionState() { 1213 ParserBase<Traits>::FunctionState::~FunctionState() {
1210 *scope_stack_ = outer_scope_; 1214 *scope_stack_ = outer_scope_;
1211 *function_state_stack_ = outer_function_state_; 1215 *function_state_stack_ = outer_function_state_;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 int pos = peek_position(); 1321 int pos = peek_position();
1318 if (!scanner()->ScanRegExpPattern(seen_equal)) { 1322 if (!scanner()->ScanRegExpPattern(seen_equal)) {
1319 Next(); 1323 Next();
1320 ReportMessage("unterminated_regexp"); 1324 ReportMessage("unterminated_regexp");
1321 *ok = false; 1325 *ok = false;
1322 return Traits::EmptyExpression(); 1326 return Traits::EmptyExpression();
1323 } 1327 }
1324 1328
1325 int literal_index = function_state_->NextMaterializedLiteralIndex(); 1329 int literal_index = function_state_->NextMaterializedLiteralIndex();
1326 1330
1327 IdentifierT js_pattern = this->NextLiteralString(scanner(), TENURED); 1331 IdentifierT js_pattern = this->GetNextSymbol(scanner());
1328 if (!scanner()->ScanRegExpFlags()) { 1332 if (!scanner()->ScanRegExpFlags()) {
1329 Next(); 1333 Next();
1330 ReportMessage("invalid_regexp_flags"); 1334 ReportMessage("invalid_regexp_flags");
1331 *ok = false; 1335 *ok = false;
1332 return Traits::EmptyExpression(); 1336 return Traits::EmptyExpression();
1333 } 1337 }
1334 IdentifierT js_flags = this->NextLiteralString(scanner(), TENURED); 1338 IdentifierT js_flags = this->GetNextSymbol(scanner());
1335 Next(); 1339 Next();
1336 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos); 1340 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos);
1337 } 1341 }
1338 1342
1339 1343
1340 #define CHECK_OK ok); \ 1344 #define CHECK_OK ok); \
1341 if (!*ok) return this->EmptyExpression(); \ 1345 if (!*ok) return this->EmptyExpression(); \
1342 ((void)0 1346 ((void)0
1343 #define DUMMY ) // to make indentation work 1347 #define DUMMY ) // to make indentation work
1344 #undef DUMMY 1348 #undef DUMMY
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 } 1573 }
1570 1574
1571 if (fni_ != NULL) { 1575 if (fni_ != NULL) {
1572 fni_->Infer(); 1576 fni_->Infer();
1573 fni_->Leave(); 1577 fni_->Leave();
1574 } 1578 }
1575 continue; // restart the while 1579 continue; // restart the while
1576 } 1580 }
1577 // Failed to parse as get/set property, so it's just a normal property 1581 // Failed to parse as get/set property, so it's just a normal property
1578 // (which might be called "get" or "set" or something else). 1582 // (which might be called "get" or "set" or something else).
1579 key = factory()->NewLiteral(id, next_pos); 1583 key = factory()->NewStringLiteral(id, next_pos);
1580 break; 1584 break;
1581 } 1585 }
1582 case Token::STRING: { 1586 case Token::STRING: {
1583 Consume(Token::STRING); 1587 Consume(Token::STRING);
1584 IdentifierT string = this->GetSymbol(scanner_); 1588 IdentifierT string = this->GetSymbol(scanner_);
1585 if (fni_ != NULL) this->PushLiteralName(fni_, string); 1589 if (fni_ != NULL) this->PushLiteralName(fni_, string);
1586 uint32_t index; 1590 uint32_t index;
1587 if (this->IsArrayIndex(string, &index)) { 1591 if (this->IsArrayIndex(string, &index)) {
1588 key = factory()->NewNumberLiteral(index, next_pos); 1592 key = factory()->NewNumberLiteral(index, next_pos);
1589 break; 1593 break;
1590 } 1594 }
1591 key = factory()->NewLiteral(string, next_pos); 1595 key = factory()->NewStringLiteral(string, next_pos);
1592 break; 1596 break;
1593 } 1597 }
1594 case Token::NUMBER: { 1598 case Token::NUMBER: {
1595 Consume(Token::NUMBER); 1599 Consume(Token::NUMBER);
1596 key = this->ExpressionFromLiteral(Token::NUMBER, next_pos, scanner_, 1600 key = this->ExpressionFromLiteral(Token::NUMBER, next_pos, scanner_,
1597 factory()); 1601 factory());
1598 break; 1602 break;
1599 } 1603 }
1600 default: 1604 default:
1601 if (Token::IsKeyword(next)) { 1605 if (Token::IsKeyword(next)) {
1602 Consume(next); 1606 Consume(next);
1603 IdentifierT string = this->GetSymbol(scanner_); 1607 IdentifierT string = this->GetSymbol(scanner_);
1604 key = factory()->NewLiteral(string, next_pos); 1608 key = factory()->NewStringLiteral(string, next_pos);
1605 } else { 1609 } else {
1606 Token::Value next = Next(); 1610 Token::Value next = Next();
1607 ReportUnexpectedToken(next); 1611 ReportUnexpectedToken(next);
1608 *ok = false; 1612 *ok = false;
1609 return this->EmptyLiteral(); 1613 return this->EmptyLiteral();
1610 } 1614 }
1611 } 1615 }
1612 1616
1613 // Validate the property 1617 // Validate the property
1614 checker.CheckProperty(next, kValueProperty, CHECK_OK); 1618 checker.CheckProperty(next, kValueProperty, CHECK_OK);
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1963 result = factory()->NewCall(result, args, pos); 1967 result = factory()->NewCall(result, args, pos);
1964 if (fni_ != NULL) fni_->RemoveLastFunction(); 1968 if (fni_ != NULL) fni_->RemoveLastFunction();
1965 break; 1969 break;
1966 } 1970 }
1967 1971
1968 case Token::PERIOD: { 1972 case Token::PERIOD: {
1969 Consume(Token::PERIOD); 1973 Consume(Token::PERIOD);
1970 int pos = position(); 1974 int pos = position();
1971 IdentifierT name = ParseIdentifierName(CHECK_OK); 1975 IdentifierT name = ParseIdentifierName(CHECK_OK);
1972 result = factory()->NewProperty( 1976 result = factory()->NewProperty(
1973 result, factory()->NewLiteral(name, pos), pos); 1977 result, factory()->NewStringLiteral(name, pos), pos);
1974 if (fni_ != NULL) this->PushLiteralName(fni_, name); 1978 if (fni_ != NULL) this->PushLiteralName(fni_, name);
1975 break; 1979 break;
1976 } 1980 }
1977 1981
1978 default: 1982 default:
1979 return result; 1983 return result;
1980 } 1984 }
1981 } 1985 }
1982 } 1986 }
1983 1987
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2086 this->PushPropertyName(fni_, index); 2090 this->PushPropertyName(fni_, index);
2087 } 2091 }
2088 Expect(Token::RBRACK, CHECK_OK); 2092 Expect(Token::RBRACK, CHECK_OK);
2089 break; 2093 break;
2090 } 2094 }
2091 case Token::PERIOD: { 2095 case Token::PERIOD: {
2092 Consume(Token::PERIOD); 2096 Consume(Token::PERIOD);
2093 int pos = position(); 2097 int pos = position();
2094 IdentifierT name = ParseIdentifierName(CHECK_OK); 2098 IdentifierT name = ParseIdentifierName(CHECK_OK);
2095 expression = factory()->NewProperty( 2099 expression = factory()->NewProperty(
2096 expression, factory()->NewLiteral(name, pos), pos); 2100 expression, factory()->NewStringLiteral(name, pos), pos);
2097 if (fni_ != NULL) { 2101 if (fni_ != NULL) {
2098 this->PushLiteralName(fni_, name); 2102 this->PushLiteralName(fni_, name);
2099 } 2103 }
2100 break; 2104 break;
2101 } 2105 }
2102 default: 2106 default:
2103 return expression; 2107 return expression;
2104 } 2108 }
2105 } 2109 }
2106 ASSERT(false); 2110 ASSERT(false);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2164 parser()->ReportMessage("accessor_get_set"); 2168 parser()->ReportMessage("accessor_get_set");
2165 } 2169 }
2166 *ok = false; 2170 *ok = false;
2167 } 2171 }
2168 } 2172 }
2169 2173
2170 2174
2171 } } // v8::internal 2175 } } // v8::internal
2172 2176
2173 #endif // V8_PREPARSER_H 2177 #endif // V8_PREPARSER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698