OLD | NEW |
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/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 class Checkpoint; | 175 class Checkpoint; |
176 class ObjectLiteralCheckerBase; | 176 class ObjectLiteralCheckerBase; |
177 | 177 |
178 // --------------------------------------------------------------------------- | 178 // --------------------------------------------------------------------------- |
179 // FunctionState and BlockState together implement the parser's scope stack. | 179 // FunctionState and BlockState together implement the parser's scope stack. |
180 // The parser's current scope is in scope_. BlockState and FunctionState | 180 // The parser's current scope is in scope_. BlockState and FunctionState |
181 // constructors push on the scope stack and the destructors pop. They are also | 181 // constructors push on the scope stack and the destructors pop. They are also |
182 // used to hold the parser's per-function and per-block state. | 182 // used to hold the parser's per-function and per-block state. |
183 class BlockState BASE_EMBEDDED { | 183 class BlockState BASE_EMBEDDED { |
184 public: | 184 public: |
185 BlockState(typename Traits::Type::Scope** scope_stack, | 185 BlockState(Scope** scope_stack, Scope* scope) |
186 typename Traits::Type::Scope* scope) | 186 : scope_stack_(scope_stack), outer_scope_(*scope_stack), scope_(scope) { |
187 : scope_stack_(scope_stack), | |
188 outer_scope_(*scope_stack), | |
189 scope_(scope) { | |
190 *scope_stack_ = scope_; | 187 *scope_stack_ = scope_; |
191 } | 188 } |
192 ~BlockState() { *scope_stack_ = outer_scope_; } | 189 ~BlockState() { *scope_stack_ = outer_scope_; } |
193 | 190 |
194 private: | 191 private: |
195 typename Traits::Type::Scope** scope_stack_; | 192 Scope** scope_stack_; |
196 typename Traits::Type::Scope* outer_scope_; | 193 Scope* outer_scope_; |
197 typename Traits::Type::Scope* scope_; | 194 Scope* scope_; |
198 }; | 195 }; |
199 | 196 |
200 class FunctionState BASE_EMBEDDED { | 197 class FunctionState BASE_EMBEDDED { |
201 public: | 198 public: |
202 FunctionState(FunctionState** function_state_stack, | 199 FunctionState(FunctionState** function_state_stack, Scope** scope_stack, |
203 typename Traits::Type::Scope** scope_stack, | 200 Scope* scope, FunctionKind kind, |
204 typename Traits::Type::Scope* scope, FunctionKind kind, | |
205 typename Traits::Type::Factory* factory); | 201 typename Traits::Type::Factory* factory); |
206 ~FunctionState(); | 202 ~FunctionState(); |
207 | 203 |
208 int NextMaterializedLiteralIndex() { | 204 int NextMaterializedLiteralIndex() { |
209 return next_materialized_literal_index_++; | 205 return next_materialized_literal_index_++; |
210 } | 206 } |
211 int materialized_literal_count() { | 207 int materialized_literal_count() { |
212 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; | 208 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; |
213 } | 209 } |
214 | 210 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 245 |
250 FunctionKind kind_; | 246 FunctionKind kind_; |
251 // For generators, this variable may hold the generator object. It variable | 247 // For generators, this variable may hold the generator object. It variable |
252 // is used by yield expressions and return statements. It is not necessary | 248 // is used by yield expressions and return statements. It is not necessary |
253 // for generator functions to have this variable set. | 249 // for generator functions to have this variable set. |
254 Variable* generator_object_variable_; | 250 Variable* generator_object_variable_; |
255 | 251 |
256 | 252 |
257 FunctionState** function_state_stack_; | 253 FunctionState** function_state_stack_; |
258 FunctionState* outer_function_state_; | 254 FunctionState* outer_function_state_; |
259 typename Traits::Type::Scope** scope_stack_; | 255 Scope** scope_stack_; |
260 typename Traits::Type::Scope* outer_scope_; | 256 Scope* outer_scope_; |
261 typename Traits::Type::Factory* factory_; | 257 typename Traits::Type::Factory* factory_; |
262 | 258 |
263 friend class ParserTraits; | 259 friend class ParserTraits; |
264 friend class Checkpoint; | 260 friend class Checkpoint; |
265 }; | 261 }; |
266 | 262 |
267 // Annoyingly, arrow functions first parse as comma expressions, then when we | 263 // Annoyingly, arrow functions first parse as comma expressions, then when we |
268 // see the => we have to go back and reinterpret the arguments as being formal | 264 // see the => we have to go back and reinterpret the arguments as being formal |
269 // parameters. To do so we need to reset some of the parser state back to | 265 // parameters. To do so we need to reset some of the parser state back to |
270 // what it was before the arguments were first seen. | 266 // what it was before the arguments were first seen. |
(...skipping 30 matching lines...) Expand all Loading... |
301 } | 297 } |
302 ~ParsingModeScope() { | 298 ~ParsingModeScope() { |
303 parser_->mode_ = old_mode_; | 299 parser_->mode_ = old_mode_; |
304 } | 300 } |
305 | 301 |
306 private: | 302 private: |
307 ParserBase* parser_; | 303 ParserBase* parser_; |
308 Mode old_mode_; | 304 Mode old_mode_; |
309 }; | 305 }; |
310 | 306 |
| 307 Scope* NewScope(Scope* parent, ScopeType scope_type, |
| 308 FunctionKind kind = kNormalFunction) { |
| 309 DCHECK(ast_value_factory()); |
| 310 DCHECK(scope_type != MODULE_SCOPE || allow_harmony_modules()); |
| 311 DCHECK((scope_type == FUNCTION_SCOPE && IsValidFunctionKind(kind)) || |
| 312 kind == kNormalFunction); |
| 313 Scope* result = new (zone()) |
| 314 Scope(isolate(), zone(), parent, scope_type, ast_value_factory()); |
| 315 bool uninitialized_this = |
| 316 FLAG_experimental_classes && IsSubclassConstructor(kind); |
| 317 result->Initialize(uninitialized_this); |
| 318 return result; |
| 319 } |
| 320 |
311 Isolate* isolate() const { return isolate_; } | 321 Isolate* isolate() const { return isolate_; } |
312 Scanner* scanner() const { return scanner_; } | 322 Scanner* scanner() const { return scanner_; } |
313 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } | 323 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } |
314 int position() { return scanner_->location().beg_pos; } | 324 int position() { return scanner_->location().beg_pos; } |
315 int peek_position() { return scanner_->peek_location().beg_pos; } | 325 int peek_position() { return scanner_->peek_location().beg_pos; } |
316 bool stack_overflow() const { return stack_overflow_; } | 326 bool stack_overflow() const { return stack_overflow_; } |
317 void set_stack_overflow() { stack_overflow_ = true; } | 327 void set_stack_overflow() { stack_overflow_ = true; } |
318 Mode mode() const { return mode_; } | 328 Mode mode() const { return mode_; } |
319 Zone* zone() const { return zone_; } | 329 Zone* zone() const { return zone_; } |
320 | 330 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 | 620 |
611 bool has_seen_constructor_; | 621 bool has_seen_constructor_; |
612 }; | 622 }; |
613 | 623 |
614 // If true, the next (and immediately following) function literal is | 624 // If true, the next (and immediately following) function literal is |
615 // preceded by a parenthesis. | 625 // preceded by a parenthesis. |
616 // Heuristically that means that the function will be called immediately, | 626 // Heuristically that means that the function will be called immediately, |
617 // so never lazily compile it. | 627 // so never lazily compile it. |
618 bool parenthesized_function_; | 628 bool parenthesized_function_; |
619 | 629 |
620 typename Traits::Type::Scope* scope_; // Scope stack. | 630 Scope* scope_; // Scope stack. |
621 FunctionState* function_state_; // Function state stack. | 631 FunctionState* function_state_; // Function state stack. |
622 v8::Extension* extension_; | 632 v8::Extension* extension_; |
623 FuncNameInferrer* fni_; | 633 FuncNameInferrer* fni_; |
624 AstValueFactory* ast_value_factory_; // Not owned. | 634 AstValueFactory* ast_value_factory_; // Not owned. |
625 ParserRecorder* log_; | 635 ParserRecorder* log_; |
626 Mode mode_; | 636 Mode mode_; |
627 uintptr_t stack_limit_; | 637 uintptr_t stack_limit_; |
628 | 638 |
629 private: | 639 private: |
630 Isolate* isolate_; | 640 Isolate* isolate_; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 kYieldIdentifier, | 730 kYieldIdentifier, |
721 kEvalIdentifier, | 731 kEvalIdentifier, |
722 kArgumentsIdentifier, | 732 kArgumentsIdentifier, |
723 kPrototypeIdentifier, | 733 kPrototypeIdentifier, |
724 kConstructorIdentifier | 734 kConstructorIdentifier |
725 }; | 735 }; |
726 explicit PreParserIdentifier(Type type) : type_(type) {} | 736 explicit PreParserIdentifier(Type type) : type_(type) {} |
727 Type type_; | 737 Type type_; |
728 | 738 |
729 friend class PreParserExpression; | 739 friend class PreParserExpression; |
730 friend class PreParserScope; | |
731 }; | 740 }; |
732 | 741 |
733 | 742 |
734 class PreParserExpression { | 743 class PreParserExpression { |
735 public: | 744 public: |
736 static PreParserExpression Default() { | 745 static PreParserExpression Default() { |
737 return PreParserExpression(TypeField::encode(kExpression)); | 746 return PreParserExpression(TypeField::encode(kExpression)); |
738 } | 747 } |
739 | 748 |
740 static PreParserExpression FromIdentifier(PreParserIdentifier id) { | 749 static PreParserExpression FromIdentifier(PreParserIdentifier id) { |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 // the PreParser does not need them. | 1031 // the PreParser does not need them. |
1023 class PreParserStatementList { | 1032 class PreParserStatementList { |
1024 public: | 1033 public: |
1025 // These functions make list->Add(some_expression) work as no-ops. | 1034 // These functions make list->Add(some_expression) work as no-ops. |
1026 PreParserStatementList() {} | 1035 PreParserStatementList() {} |
1027 PreParserStatementList* operator->() { return this; } | 1036 PreParserStatementList* operator->() { return this; } |
1028 void Add(PreParserStatement, void*) {} | 1037 void Add(PreParserStatement, void*) {} |
1029 }; | 1038 }; |
1030 | 1039 |
1031 | 1040 |
1032 class PreParserScope { | |
1033 public: | |
1034 explicit PreParserScope(PreParserScope* outer_scope, ScopeType scope_type, | |
1035 void* = NULL) | |
1036 : scope_type_(scope_type) { | |
1037 language_mode_ = outer_scope ? outer_scope->language_mode() : SLOPPY; | |
1038 } | |
1039 | |
1040 ScopeType type() { return scope_type_; } | |
1041 LanguageMode language_mode() const { return language_mode_; } | |
1042 void SetLanguageMode(LanguageMode language_mode) { | |
1043 language_mode_ = language_mode; | |
1044 } | |
1045 void SetScopeName(PreParserIdentifier name) {} | |
1046 | |
1047 // When PreParser is in use, lazy compilation is already being done, | |
1048 // things cannot get lazier than that. | |
1049 bool AllowsLazyCompilation() const { return false; } | |
1050 | |
1051 void set_start_position(int position) {} | |
1052 void set_end_position(int position) {} | |
1053 | |
1054 bool IsDeclared(const PreParserIdentifier& identifier) const { return false; } | |
1055 void DeclareParameter(const PreParserIdentifier& identifier, VariableMode) {} | |
1056 void RecordArgumentsUsage() {} | |
1057 void RecordSuperPropertyUsage() {} | |
1058 void RecordSuperConstructorCallUsage() {} | |
1059 void RecordThisUsage() {} | |
1060 | |
1061 // Allow scope->Foo() to work. | |
1062 PreParserScope* operator->() { return this; } | |
1063 | |
1064 private: | |
1065 ScopeType scope_type_; | |
1066 LanguageMode language_mode_; | |
1067 }; | |
1068 | |
1069 | |
1070 class PreParserFactory { | 1041 class PreParserFactory { |
1071 public: | 1042 public: |
1072 explicit PreParserFactory(void* unused_value_factory) {} | 1043 explicit PreParserFactory(void* unused_value_factory) {} |
1073 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, | 1044 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, |
1074 int pos) { | 1045 int pos) { |
1075 return PreParserExpression::Default(); | 1046 return PreParserExpression::Default(); |
1076 } | 1047 } |
1077 PreParserExpression NewNumberLiteral(double number, | 1048 PreParserExpression NewNumberLiteral(double number, |
1078 int pos) { | 1049 int pos) { |
1079 return PreParserExpression::Default(); | 1050 return PreParserExpression::Default(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 PreParserExpressionList arguments, | 1139 PreParserExpressionList arguments, |
1169 int pos) { | 1140 int pos) { |
1170 return PreParserExpression::Default(); | 1141 return PreParserExpression::Default(); |
1171 } | 1142 } |
1172 PreParserStatement NewReturnStatement(PreParserExpression expression, | 1143 PreParserStatement NewReturnStatement(PreParserExpression expression, |
1173 int pos) { | 1144 int pos) { |
1174 return PreParserStatement::Default(); | 1145 return PreParserStatement::Default(); |
1175 } | 1146 } |
1176 PreParserExpression NewFunctionLiteral( | 1147 PreParserExpression NewFunctionLiteral( |
1177 PreParserIdentifier name, AstValueFactory* ast_value_factory, | 1148 PreParserIdentifier name, AstValueFactory* ast_value_factory, |
1178 const PreParserScope& scope, PreParserStatementList body, | 1149 Scope* scope, PreParserStatementList body, int materialized_literal_count, |
1179 int materialized_literal_count, int expected_property_count, | 1150 int expected_property_count, int handler_count, int parameter_count, |
1180 int handler_count, int parameter_count, | |
1181 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 1151 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
1182 FunctionLiteral::FunctionType function_type, | 1152 FunctionLiteral::FunctionType function_type, |
1183 FunctionLiteral::IsFunctionFlag is_function, | 1153 FunctionLiteral::IsFunctionFlag is_function, |
1184 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, | 1154 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, |
1185 int position) { | 1155 int position) { |
1186 return PreParserExpression::Default(); | 1156 return PreParserExpression::Default(); |
1187 } | 1157 } |
1188 | 1158 |
1189 // Return the object itself as AstVisitor and implement the needed | 1159 // Return the object itself as AstVisitor and implement the needed |
1190 // dummy method right in this class. | 1160 // dummy method right in this class. |
1191 PreParserFactory* visitor() { return this; } | 1161 PreParserFactory* visitor() { return this; } |
1192 int* ast_properties() { | 1162 int* ast_properties() { |
1193 static int dummy = 42; | 1163 static int dummy = 42; |
1194 return &dummy; | 1164 return &dummy; |
1195 } | 1165 } |
1196 }; | 1166 }; |
1197 | 1167 |
1198 | 1168 |
1199 class PreParser; | 1169 class PreParser; |
1200 | 1170 |
1201 class PreParserTraits { | 1171 class PreParserTraits { |
1202 public: | 1172 public: |
1203 struct Type { | 1173 struct Type { |
1204 // TODO(marja): To be removed. The Traits object should contain all the data | 1174 // TODO(marja): To be removed. The Traits object should contain all the data |
1205 // it needs. | 1175 // it needs. |
1206 typedef PreParser* Parser; | 1176 typedef PreParser* Parser; |
1207 | 1177 |
1208 // Used by FunctionState and BlockState. | |
1209 typedef PreParserScope Scope; | |
1210 typedef PreParserScope ScopePtr; | |
1211 inline static Scope* ptr_to_scope(ScopePtr& scope) { return &scope; } | |
1212 | |
1213 // PreParser doesn't need to store generator variables. | 1178 // PreParser doesn't need to store generator variables. |
1214 typedef void GeneratorVariable; | 1179 typedef void GeneratorVariable; |
1215 | 1180 |
1216 typedef int AstProperties; | 1181 typedef int AstProperties; |
1217 typedef Vector<PreParserIdentifier> ParameterIdentifierVector; | 1182 typedef Vector<PreParserIdentifier> ParameterIdentifierVector; |
1218 | 1183 |
1219 // Return types for traversing functions. | 1184 // Return types for traversing functions. |
1220 typedef PreParserIdentifier Identifier; | 1185 typedef PreParserIdentifier Identifier; |
1221 typedef PreParserExpression Expression; | 1186 typedef PreParserExpression Expression; |
1222 typedef PreParserExpression YieldExpression; | 1187 typedef PreParserExpression YieldExpression; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1290 UNREACHABLE(); | 1255 UNREACHABLE(); |
1291 } | 1256 } |
1292 | 1257 |
1293 static void InferFunctionName(FuncNameInferrer* fni, | 1258 static void InferFunctionName(FuncNameInferrer* fni, |
1294 PreParserExpression expression) { | 1259 PreParserExpression expression) { |
1295 // PreParser should not use FuncNameInferrer. | 1260 // PreParser should not use FuncNameInferrer. |
1296 UNREACHABLE(); | 1261 UNREACHABLE(); |
1297 } | 1262 } |
1298 | 1263 |
1299 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( | 1264 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( |
1300 PreParserScope* scope, PreParserExpression property, bool* has_function) { | 1265 Scope* scope, PreParserExpression property, bool* has_function) {} |
1301 } | |
1302 | 1266 |
1303 static void CheckAssigningFunctionLiteralToProperty( | 1267 static void CheckAssigningFunctionLiteralToProperty( |
1304 PreParserExpression left, PreParserExpression right) {} | 1268 PreParserExpression left, PreParserExpression right) {} |
1305 | 1269 |
1306 // PreParser doesn't need to keep track of eval calls. | 1270 // PreParser doesn't need to keep track of eval calls. |
1307 static void CheckPossibleEvalCall(PreParserExpression expression, | 1271 static void CheckPossibleEvalCall(PreParserExpression expression, |
1308 PreParserScope* scope) {} | 1272 Scope* scope) {} |
1309 | 1273 |
1310 static PreParserExpression MarkExpressionAsAssigned( | 1274 static PreParserExpression MarkExpressionAsAssigned( |
1311 PreParserExpression expression) { | 1275 PreParserExpression expression) { |
1312 // TODO(marja): To be able to produce the same errors, the preparser needs | 1276 // TODO(marja): To be able to produce the same errors, the preparser needs |
1313 // to start tracking which expressions are variables and which are assigned. | 1277 // to start tracking which expressions are variables and which are assigned. |
1314 return expression; | 1278 return expression; |
1315 } | 1279 } |
1316 | 1280 |
1317 bool ShortcutNumericLiteralBinaryExpression(PreParserExpression* x, | 1281 bool ShortcutNumericLiteralBinaryExpression(PreParserExpression* x, |
1318 PreParserExpression y, | 1282 PreParserExpression y, |
(...skipping 13 matching lines...) Expand all Loading... |
1332 return PreParserExpression::Default(); | 1296 return PreParserExpression::Default(); |
1333 } | 1297 } |
1334 PreParserExpression NewThrowSyntaxError( | 1298 PreParserExpression NewThrowSyntaxError( |
1335 const char* type, Handle<Object> arg, int pos) { | 1299 const char* type, Handle<Object> arg, int pos) { |
1336 return PreParserExpression::Default(); | 1300 return PreParserExpression::Default(); |
1337 } | 1301 } |
1338 PreParserExpression NewThrowTypeError( | 1302 PreParserExpression NewThrowTypeError( |
1339 const char* type, Handle<Object> arg, int pos) { | 1303 const char* type, Handle<Object> arg, int pos) { |
1340 return PreParserExpression::Default(); | 1304 return PreParserExpression::Default(); |
1341 } | 1305 } |
1342 PreParserScope NewScope(PreParserScope* outer_scope, ScopeType scope_type, | |
1343 FunctionKind kind = kNormalFunction) { | |
1344 return PreParserScope(outer_scope, scope_type); | |
1345 } | |
1346 | 1306 |
1347 // Reporting errors. | 1307 // Reporting errors. |
1348 void ReportMessageAt(Scanner::Location location, | 1308 void ReportMessageAt(Scanner::Location location, |
1349 const char* message, | 1309 const char* message, |
1350 const char* arg = NULL, | 1310 const char* arg = NULL, |
1351 bool is_reference_error = false); | 1311 bool is_reference_error = false); |
1352 void ReportMessageAt(int start_pos, | 1312 void ReportMessageAt(int start_pos, |
1353 int end_pos, | 1313 int end_pos, |
1354 const char* message, | 1314 const char* message, |
1355 const char* arg = NULL, | 1315 const char* arg = NULL, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 } | 1348 } |
1389 | 1349 |
1390 // Producing data during the recursive descent. | 1350 // Producing data during the recursive descent. |
1391 PreParserIdentifier GetSymbol(Scanner* scanner); | 1351 PreParserIdentifier GetSymbol(Scanner* scanner); |
1392 PreParserIdentifier GetNumberAsSymbol(Scanner* scanner); | 1352 PreParserIdentifier GetNumberAsSymbol(Scanner* scanner); |
1393 | 1353 |
1394 static PreParserIdentifier GetNextSymbol(Scanner* scanner) { | 1354 static PreParserIdentifier GetNextSymbol(Scanner* scanner) { |
1395 return PreParserIdentifier::Default(); | 1355 return PreParserIdentifier::Default(); |
1396 } | 1356 } |
1397 | 1357 |
1398 static PreParserExpression ThisExpression(PreParserScope* scope, | 1358 static PreParserExpression ThisExpression(Scope* scope, |
1399 PreParserFactory* factory) { | 1359 PreParserFactory* factory) { |
1400 return PreParserExpression::This(); | 1360 return PreParserExpression::This(); |
1401 } | 1361 } |
1402 | 1362 |
1403 static PreParserExpression SuperReference(PreParserScope* scope, | 1363 static PreParserExpression SuperReference(Scope* scope, |
1404 PreParserFactory* factory) { | 1364 PreParserFactory* factory) { |
1405 return PreParserExpression::Super(); | 1365 return PreParserExpression::Super(); |
1406 } | 1366 } |
1407 | 1367 |
1408 static PreParserExpression DefaultConstructor(bool call_super, | 1368 static PreParserExpression DefaultConstructor(bool call_super, Scope* scope, |
1409 PreParserScope* scope, int pos, | 1369 int pos, int end_pos) { |
1410 int end_pos) { | |
1411 return PreParserExpression::Default(); | 1370 return PreParserExpression::Default(); |
1412 } | 1371 } |
1413 | 1372 |
1414 static PreParserExpression ExpressionFromLiteral( | 1373 static PreParserExpression ExpressionFromLiteral( |
1415 Token::Value token, int pos, Scanner* scanner, | 1374 Token::Value token, int pos, Scanner* scanner, |
1416 PreParserFactory* factory) { | 1375 PreParserFactory* factory) { |
1417 return PreParserExpression::Default(); | 1376 return PreParserExpression::Default(); |
1418 } | 1377 } |
1419 | 1378 |
1420 static PreParserExpression ExpressionFromIdentifier( | 1379 static PreParserExpression ExpressionFromIdentifier( |
1421 PreParserIdentifier name, int pos, PreParserScope* scope, | 1380 PreParserIdentifier name, int pos, Scope* scope, |
1422 PreParserFactory* factory) { | 1381 PreParserFactory* factory) { |
1423 return PreParserExpression::FromIdentifier(name); | 1382 return PreParserExpression::FromIdentifier(name); |
1424 } | 1383 } |
1425 | 1384 |
1426 PreParserExpression ExpressionFromString(int pos, | 1385 PreParserExpression ExpressionFromString(int pos, |
1427 Scanner* scanner, | 1386 Scanner* scanner, |
1428 PreParserFactory* factory = NULL); | 1387 PreParserFactory* factory = NULL); |
1429 | 1388 |
1430 PreParserExpression GetIterator(PreParserExpression iterable, | 1389 PreParserExpression GetIterator(PreParserExpression iterable, |
1431 PreParserFactory* factory) { | 1390 PreParserFactory* factory) { |
(...skipping 18 matching lines...) Expand all Loading... |
1450 UNREACHABLE(); | 1409 UNREACHABLE(); |
1451 } | 1410 } |
1452 | 1411 |
1453 V8_INLINE PreParserStatementList | 1412 V8_INLINE PreParserStatementList |
1454 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos, | 1413 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos, |
1455 Variable* fvar, Token::Value fvar_init_op, | 1414 Variable* fvar, Token::Value fvar_init_op, |
1456 FunctionKind kind, bool* ok); | 1415 FunctionKind kind, bool* ok); |
1457 | 1416 |
1458 // Utility functions | 1417 // Utility functions |
1459 int DeclareArrowParametersFromExpression(PreParserExpression expression, | 1418 int DeclareArrowParametersFromExpression(PreParserExpression expression, |
1460 PreParserScope* scope, | 1419 Scope* scope, |
1461 Scanner::Location* dupe_loc, | 1420 Scanner::Location* dupe_loc, |
1462 bool* ok) { | 1421 bool* ok) { |
1463 // TODO(aperez): Detect duplicated identifiers in paramlists. | 1422 // TODO(aperez): Detect duplicated identifiers in paramlists. |
1464 *ok = expression.IsValidArrowParamList(); | 1423 *ok = expression.IsValidArrowParamList(); |
1465 return 0; | 1424 return 0; |
1466 } | 1425 } |
1467 | 1426 |
1468 struct TemplateLiteralState {}; | 1427 struct TemplateLiteralState {}; |
1469 | 1428 |
1470 TemplateLiteralState OpenTemplateLiteral(int pos) { | 1429 TemplateLiteralState OpenTemplateLiteral(int pos) { |
(...skipping 11 matching lines...) Expand all Loading... |
1482 return EmptyExpression(); | 1441 return EmptyExpression(); |
1483 } | 1442 } |
1484 inline void MaterializeTemplateCallsiteLiterals(); | 1443 inline void MaterializeTemplateCallsiteLiterals(); |
1485 PreParserExpression NoTemplateTag() { | 1444 PreParserExpression NoTemplateTag() { |
1486 return PreParserExpression::NoTemplateTag(); | 1445 return PreParserExpression::NoTemplateTag(); |
1487 } | 1446 } |
1488 static bool IsTaggedTemplate(const PreParserExpression tag) { | 1447 static bool IsTaggedTemplate(const PreParserExpression tag) { |
1489 return !tag.IsNoTemplateTag(); | 1448 return !tag.IsNoTemplateTag(); |
1490 } | 1449 } |
1491 | 1450 |
1492 void CheckConflictingVarDeclarations(PreParserScope scope, bool* ok) {} | 1451 void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {} |
1493 | 1452 |
1494 // Temporary glue; these functions will move to ParserBase. | 1453 // Temporary glue; these functions will move to ParserBase. |
1495 PreParserExpression ParseV8Intrinsic(bool* ok); | 1454 PreParserExpression ParseV8Intrinsic(bool* ok); |
1496 PreParserExpression ParseFunctionLiteral( | 1455 PreParserExpression ParseFunctionLiteral( |
1497 PreParserIdentifier name, Scanner::Location function_name_location, | 1456 PreParserIdentifier name, Scanner::Location function_name_location, |
1498 bool name_is_strict_reserved, FunctionKind kind, | 1457 bool name_is_strict_reserved, FunctionKind kind, |
1499 int function_token_position, FunctionLiteral::FunctionType type, | 1458 int function_token_position, FunctionLiteral::FunctionType type, |
1500 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); | 1459 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); |
1501 | 1460 |
1502 PreParserExpression ParseClassLiteral(PreParserIdentifier name, | 1461 PreParserExpression ParseClassLiteral(PreParserIdentifier name, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1536 AstValueFactory* ast_value_factory, ParserRecorder* log, | 1495 AstValueFactory* ast_value_factory, ParserRecorder* log, |
1537 uintptr_t stack_limit) | 1496 uintptr_t stack_limit) |
1538 : ParserBase<PreParserTraits>(isolate, zone, scanner, stack_limit, NULL, | 1497 : ParserBase<PreParserTraits>(isolate, zone, scanner, stack_limit, NULL, |
1539 ast_value_factory, log, this) {} | 1498 ast_value_factory, log, this) {} |
1540 | 1499 |
1541 // Pre-parse the program from the character stream; returns true on | 1500 // Pre-parse the program from the character stream; returns true on |
1542 // success (even if parsing failed, the pre-parse data successfully | 1501 // success (even if parsing failed, the pre-parse data successfully |
1543 // captured the syntax error), and false if a stack-overflow happened | 1502 // captured the syntax error), and false if a stack-overflow happened |
1544 // during parsing. | 1503 // during parsing. |
1545 PreParseResult PreParseProgram(int* materialized_literals = 0) { | 1504 PreParseResult PreParseProgram(int* materialized_literals = 0) { |
1546 PreParserScope scope(scope_, SCRIPT_SCOPE); | 1505 Scope* scope = NewScope(scope_, SCRIPT_SCOPE); |
1547 PreParserFactory factory(NULL); | 1506 PreParserFactory factory(NULL); |
1548 FunctionState top_scope(&function_state_, &scope_, &scope, kNormalFunction, | 1507 FunctionState top_scope(&function_state_, &scope_, scope, kNormalFunction, |
1549 &factory); | 1508 &factory); |
1550 bool ok = true; | 1509 bool ok = true; |
1551 int start_position = scanner()->peek_location().beg_pos; | 1510 int start_position = scanner()->peek_location().beg_pos; |
1552 ParseSourceElements(Token::EOS, &ok); | 1511 ParseSourceElements(Token::EOS, &ok); |
1553 if (stack_overflow()) return kPreParseStackOverflow; | 1512 if (stack_overflow()) return kPreParseStackOverflow; |
1554 if (!ok) { | 1513 if (!ok) { |
1555 ReportUnexpectedToken(scanner()->current_token()); | 1514 ReportUnexpectedToken(scanner()->current_token()); |
1556 } else if (is_strict(scope_->language_mode())) { | 1515 } else if (is_strict(scope_->language_mode())) { |
1557 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, | 1516 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, |
1558 &ok); | 1517 &ok); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1678 PreParserStatementList PreParserTraits::ParseEagerFunctionBody( | 1637 PreParserStatementList PreParserTraits::ParseEagerFunctionBody( |
1679 PreParserIdentifier function_name, int pos, Variable* fvar, | 1638 PreParserIdentifier function_name, int pos, Variable* fvar, |
1680 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { | 1639 Token::Value fvar_init_op, FunctionKind kind, bool* ok) { |
1681 return pre_parser_->ParseEagerFunctionBody(function_name, pos, fvar, | 1640 return pre_parser_->ParseEagerFunctionBody(function_name, pos, fvar, |
1682 fvar_init_op, kind, ok); | 1641 fvar_init_op, kind, ok); |
1683 } | 1642 } |
1684 | 1643 |
1685 | 1644 |
1686 template <class Traits> | 1645 template <class Traits> |
1687 ParserBase<Traits>::FunctionState::FunctionState( | 1646 ParserBase<Traits>::FunctionState::FunctionState( |
1688 FunctionState** function_state_stack, | 1647 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, |
1689 typename Traits::Type::Scope** scope_stack, | 1648 FunctionKind kind, typename Traits::Type::Factory* factory) |
1690 typename Traits::Type::Scope* scope, FunctionKind kind, | |
1691 typename Traits::Type::Factory* factory) | |
1692 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), | 1649 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), |
1693 next_handler_index_(0), | 1650 next_handler_index_(0), |
1694 expected_property_count_(0), | 1651 expected_property_count_(0), |
1695 kind_(kind), | 1652 kind_(kind), |
1696 generator_object_variable_(NULL), | 1653 generator_object_variable_(NULL), |
1697 function_state_stack_(function_state_stack), | 1654 function_state_stack_(function_state_stack), |
1698 outer_function_state_(*function_state_stack), | 1655 outer_function_state_(*function_state_stack), |
1699 scope_stack_(scope_stack), | 1656 scope_stack_(scope_stack), |
1700 outer_scope_(*scope_stack), | 1657 outer_scope_(*scope_stack), |
1701 factory_(factory) { | 1658 factory_(factory) { |
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2818 DCHECK(false); | 2775 DCHECK(false); |
2819 return this->EmptyExpression(); | 2776 return this->EmptyExpression(); |
2820 } | 2777 } |
2821 | 2778 |
2822 | 2779 |
2823 template <class Traits> | 2780 template <class Traits> |
2824 typename ParserBase<Traits>::ExpressionT | 2781 typename ParserBase<Traits>::ExpressionT |
2825 ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos, | 2782 ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos, |
2826 ExpressionT params_ast, | 2783 ExpressionT params_ast, |
2827 bool* ok) { | 2784 bool* ok) { |
2828 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, ARROW_SCOPE); | 2785 Scope* scope = this->NewScope(scope_, ARROW_SCOPE); |
2829 typename Traits::Type::StatementList body; | 2786 typename Traits::Type::StatementList body; |
2830 int num_parameters = -1; | 2787 int num_parameters = -1; |
2831 int materialized_literal_count = -1; | 2788 int materialized_literal_count = -1; |
2832 int expected_property_count = -1; | 2789 int expected_property_count = -1; |
2833 int handler_count = 0; | 2790 int handler_count = 0; |
2834 | 2791 |
2835 { | 2792 { |
2836 typename Traits::Type::Factory function_factory(ast_value_factory()); | 2793 typename Traits::Type::Factory function_factory(ast_value_factory()); |
2837 FunctionState function_state(&function_state_, &scope_, | 2794 FunctionState function_state(&function_state_, &scope_, scope, |
2838 Traits::Type::ptr_to_scope(scope), | |
2839 kArrowFunction, &function_factory); | 2795 kArrowFunction, &function_factory); |
2840 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); | 2796 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); |
2841 num_parameters = Traits::DeclareArrowParametersFromExpression( | 2797 num_parameters = Traits::DeclareArrowParametersFromExpression( |
2842 params_ast, scope_, &dupe_error_loc, ok); | 2798 params_ast, scope_, &dupe_error_loc, ok); |
2843 if (!*ok) { | 2799 if (!*ok) { |
2844 ReportMessageAt( | 2800 ReportMessageAt( |
2845 Scanner::Location(start_pos, scanner()->location().beg_pos), | 2801 Scanner::Location(start_pos, scanner()->location().beg_pos), |
2846 "malformed_arrow_function_parameter_list"); | 2802 "malformed_arrow_function_parameter_list"); |
2847 return this->EmptyExpression(); | 2803 return this->EmptyExpression(); |
2848 } | 2804 } |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3094 *ok = false; | 3050 *ok = false; |
3095 return; | 3051 return; |
3096 } | 3052 } |
3097 has_seen_constructor_ = true; | 3053 has_seen_constructor_ = true; |
3098 return; | 3054 return; |
3099 } | 3055 } |
3100 } | 3056 } |
3101 } } // v8::internal | 3057 } } // v8::internal |
3102 | 3058 |
3103 #endif // V8_PREPARSER_H | 3059 #endif // V8_PREPARSER_H |
OLD | NEW |