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

Side by Side Diff: src/preparser.h

Issue 314603004: Parser: Delay internalizing strings and values. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased 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 "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 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 AstValueFactory* ast_value_factory)
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, ast_value_factory) {
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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 int pos = peek_position(); 1319 int pos = peek_position();
1316 if (!scanner()->ScanRegExpPattern(seen_equal)) { 1320 if (!scanner()->ScanRegExpPattern(seen_equal)) {
1317 Next(); 1321 Next();
1318 ReportMessage("unterminated_regexp"); 1322 ReportMessage("unterminated_regexp");
1319 *ok = false; 1323 *ok = false;
1320 return Traits::EmptyExpression(); 1324 return Traits::EmptyExpression();
1321 } 1325 }
1322 1326
1323 int literal_index = function_state_->NextMaterializedLiteralIndex(); 1327 int literal_index = function_state_->NextMaterializedLiteralIndex();
1324 1328
1325 IdentifierT js_pattern = this->NextLiteralString(scanner(), TENURED); 1329 IdentifierT js_pattern = this->GetNextSymbol(scanner());
1326 if (!scanner()->ScanRegExpFlags()) { 1330 if (!scanner()->ScanRegExpFlags()) {
1327 Next(); 1331 Next();
1328 ReportMessage("invalid_regexp_flags"); 1332 ReportMessage("invalid_regexp_flags");
1329 *ok = false; 1333 *ok = false;
1330 return Traits::EmptyExpression(); 1334 return Traits::EmptyExpression();
1331 } 1335 }
1332 IdentifierT js_flags = this->NextLiteralString(scanner(), TENURED); 1336 IdentifierT js_flags = this->GetNextSymbol(scanner());
1333 Next(); 1337 Next();
1334 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos); 1338 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos);
1335 } 1339 }
1336 1340
1337 1341
1338 #define CHECK_OK ok); \ 1342 #define CHECK_OK ok); \
1339 if (!*ok) return this->EmptyExpression(); \ 1343 if (!*ok) return this->EmptyExpression(); \
1340 ((void)0 1344 ((void)0
1341 #define DUMMY ) // to make indentation work 1345 #define DUMMY ) // to make indentation work
1342 #undef DUMMY 1346 #undef DUMMY
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 } 1571 }
1568 1572
1569 if (fni_ != NULL) { 1573 if (fni_ != NULL) {
1570 fni_->Infer(); 1574 fni_->Infer();
1571 fni_->Leave(); 1575 fni_->Leave();
1572 } 1576 }
1573 continue; // restart the while 1577 continue; // restart the while
1574 } 1578 }
1575 // Failed to parse as get/set property, so it's just a normal property 1579 // Failed to parse as get/set property, so it's just a normal property
1576 // (which might be called "get" or "set" or something else). 1580 // (which might be called "get" or "set" or something else).
1577 key = factory()->NewLiteral(id, next_pos); 1581 key = factory()->NewStringLiteral(id, next_pos);
1578 break; 1582 break;
1579 } 1583 }
1580 case Token::STRING: { 1584 case Token::STRING: {
1581 Consume(Token::STRING); 1585 Consume(Token::STRING);
1582 IdentifierT string = this->GetSymbol(scanner_); 1586 IdentifierT string = this->GetSymbol(scanner_);
1583 if (fni_ != NULL) this->PushLiteralName(fni_, string); 1587 if (fni_ != NULL) this->PushLiteralName(fni_, string);
1584 uint32_t index; 1588 uint32_t index;
1585 if (this->IsArrayIndex(string, &index)) { 1589 if (this->IsArrayIndex(string, &index)) {
1586 key = factory()->NewNumberLiteral(index, next_pos); 1590 key = factory()->NewNumberLiteral(index, next_pos);
1587 break; 1591 break;
1588 } 1592 }
1589 key = factory()->NewLiteral(string, next_pos); 1593 key = factory()->NewStringLiteral(string, next_pos);
1590 break; 1594 break;
1591 } 1595 }
1592 case Token::NUMBER: { 1596 case Token::NUMBER: {
1593 Consume(Token::NUMBER); 1597 Consume(Token::NUMBER);
1594 key = this->ExpressionFromLiteral(Token::NUMBER, next_pos, scanner_, 1598 key = this->ExpressionFromLiteral(Token::NUMBER, next_pos, scanner_,
1595 factory()); 1599 factory());
1596 break; 1600 break;
1597 } 1601 }
1598 default: 1602 default:
1599 if (Token::IsKeyword(next)) { 1603 if (Token::IsKeyword(next)) {
1600 Consume(next); 1604 Consume(next);
1601 IdentifierT string = this->GetSymbol(scanner_); 1605 IdentifierT string = this->GetSymbol(scanner_);
1602 key = factory()->NewLiteral(string, next_pos); 1606 key = factory()->NewStringLiteral(string, next_pos);
1603 } else { 1607 } else {
1604 Token::Value next = Next(); 1608 Token::Value next = Next();
1605 ReportUnexpectedToken(next); 1609 ReportUnexpectedToken(next);
1606 *ok = false; 1610 *ok = false;
1607 return this->EmptyLiteral(); 1611 return this->EmptyLiteral();
1608 } 1612 }
1609 } 1613 }
1610 1614
1611 // Validate the property 1615 // Validate the property
1612 checker.CheckProperty(next, kValueProperty, CHECK_OK); 1616 checker.CheckProperty(next, kValueProperty, CHECK_OK);
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1961 result = factory()->NewCall(result, args, pos); 1965 result = factory()->NewCall(result, args, pos);
1962 if (fni_ != NULL) fni_->RemoveLastFunction(); 1966 if (fni_ != NULL) fni_->RemoveLastFunction();
1963 break; 1967 break;
1964 } 1968 }
1965 1969
1966 case Token::PERIOD: { 1970 case Token::PERIOD: {
1967 Consume(Token::PERIOD); 1971 Consume(Token::PERIOD);
1968 int pos = position(); 1972 int pos = position();
1969 IdentifierT name = ParseIdentifierName(CHECK_OK); 1973 IdentifierT name = ParseIdentifierName(CHECK_OK);
1970 result = factory()->NewProperty( 1974 result = factory()->NewProperty(
1971 result, factory()->NewLiteral(name, pos), pos); 1975 result, factory()->NewStringLiteral(name, pos), pos);
1972 if (fni_ != NULL) this->PushLiteralName(fni_, name); 1976 if (fni_ != NULL) this->PushLiteralName(fni_, name);
1973 break; 1977 break;
1974 } 1978 }
1975 1979
1976 default: 1980 default:
1977 return result; 1981 return result;
1978 } 1982 }
1979 } 1983 }
1980 } 1984 }
1981 1985
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2083 this->PushPropertyName(fni_, index); 2087 this->PushPropertyName(fni_, index);
2084 } 2088 }
2085 Expect(Token::RBRACK, CHECK_OK); 2089 Expect(Token::RBRACK, CHECK_OK);
2086 break; 2090 break;
2087 } 2091 }
2088 case Token::PERIOD: { 2092 case Token::PERIOD: {
2089 Consume(Token::PERIOD); 2093 Consume(Token::PERIOD);
2090 int pos = position(); 2094 int pos = position();
2091 IdentifierT name = ParseIdentifierName(CHECK_OK); 2095 IdentifierT name = ParseIdentifierName(CHECK_OK);
2092 expression = factory()->NewProperty( 2096 expression = factory()->NewProperty(
2093 expression, factory()->NewLiteral(name, pos), pos); 2097 expression, factory()->NewStringLiteral(name, pos), pos);
2094 if (fni_ != NULL) { 2098 if (fni_ != NULL) {
2095 this->PushLiteralName(fni_, name); 2099 this->PushLiteralName(fni_, name);
2096 } 2100 }
2097 break; 2101 break;
2098 } 2102 }
2099 default: 2103 default:
2100 return expression; 2104 return expression;
2101 } 2105 }
2102 } 2106 }
2103 ASSERT(false); 2107 ASSERT(false);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2161 parser()->ReportMessage("accessor_get_set"); 2165 parser()->ReportMessage("accessor_get_set");
2162 } 2166 }
2163 *ok = false; 2167 *ok = false;
2164 } 2168 }
2165 } 2169 }
2166 2170
2167 2171
2168 } } // v8::internal 2172 } } // v8::internal
2169 2173
2170 #endif // V8_PREPARSER_H 2174 #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