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 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 268 |
269 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) { | 269 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) { |
270 DCHECK(ast_value_factory()); | 270 DCHECK(ast_value_factory()); |
271 Scope* result = | 271 Scope* result = |
272 new (zone()) Scope(parent, scope_type, ast_value_factory(), zone()); | 272 new (zone()) Scope(parent, scope_type, ast_value_factory(), zone()); |
273 result->Initialize(); | 273 result->Initialize(); |
274 return result; | 274 return result; |
275 } | 275 } |
276 | 276 |
277 | 277 |
| 278 FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope, |
| 279 int pos, int end_pos) { |
| 280 int materialized_literal_count = -1; |
| 281 int expected_property_count = -1; |
| 282 int handler_count = 0; |
| 283 int parameter_count = 0; |
| 284 AstProperties ast_properties; |
| 285 BailoutReason dont_optimize_reason = kNoReason; |
| 286 const AstRawString* name = ast_value_factory()->empty_string(); |
| 287 FunctionKind kind = call_super ? FunctionKind::kDefaultConstructorCallSuper |
| 288 : FunctionKind::kDefaultConstructor; |
| 289 |
| 290 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE); |
| 291 function_scope->SetStrictMode(STRICT); |
| 292 // Set start and end position to the same value |
| 293 function_scope->set_start_position(pos); |
| 294 function_scope->set_end_position(pos); |
| 295 ZoneList<Statement*>* body = NULL; |
| 296 |
| 297 { |
| 298 AstNodeFactory<AstConstructionVisitor> function_factory( |
| 299 ast_value_factory()); |
| 300 FunctionState function_state(&function_state_, &scope_, function_scope, |
| 301 &function_factory); |
| 302 |
| 303 body = new (zone()) ZoneList<Statement*>(1, zone()); |
| 304 if (call_super) { |
| 305 Expression* prop = SuperReference(function_scope, factory(), pos); |
| 306 ZoneList<Expression*>* args = |
| 307 new (zone()) ZoneList<Expression*>(0, zone()); |
| 308 Call* call = factory()->NewCall(prop, args, pos); |
| 309 body->Add(factory()->NewExpressionStatement(call, pos), zone()); |
| 310 } |
| 311 |
| 312 materialized_literal_count = function_state.materialized_literal_count(); |
| 313 expected_property_count = function_state.expected_property_count(); |
| 314 handler_count = function_state.handler_count(); |
| 315 |
| 316 ast_properties = *factory()->visitor()->ast_properties(); |
| 317 dont_optimize_reason = factory()->visitor()->dont_optimize_reason(); |
| 318 } |
| 319 |
| 320 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( |
| 321 name, ast_value_factory(), function_scope, body, |
| 322 materialized_literal_count, expected_property_count, handler_count, |
| 323 parameter_count, FunctionLiteral::kNoDuplicateParameters, |
| 324 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, |
| 325 FunctionLiteral::kNotParenthesized, kind, pos); |
| 326 |
| 327 function_literal->set_ast_properties(&ast_properties); |
| 328 function_literal->set_dont_optimize_reason(dont_optimize_reason); |
| 329 |
| 330 return function_literal; |
| 331 } |
| 332 |
| 333 |
278 // ---------------------------------------------------------------------------- | 334 // ---------------------------------------------------------------------------- |
279 // Target is a support class to facilitate manipulation of the | 335 // Target is a support class to facilitate manipulation of the |
280 // Parser's target_stack_ (the stack of potential 'break' and | 336 // Parser's target_stack_ (the stack of potential 'break' and |
281 // 'continue' statement targets). Upon construction, a new target is | 337 // 'continue' statement targets). Upon construction, a new target is |
282 // added; it is removed upon destruction. | 338 // added; it is removed upon destruction. |
283 | 339 |
284 class Target BASE_EMBEDDED { | 340 class Target BASE_EMBEDDED { |
285 public: | 341 public: |
286 Target(Target** variable, AstNode* node) | 342 Target(Target** variable, AstNode* node) |
287 : variable_(variable), node_(node), previous_(*variable) { | 343 : variable_(variable), node_(node), previous_(*variable) { |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 } | 697 } |
642 | 698 |
643 Expression* ParserTraits::ClassExpression( | 699 Expression* ParserTraits::ClassExpression( |
644 const AstRawString* name, Expression* extends, Expression* constructor, | 700 const AstRawString* name, Expression* extends, Expression* constructor, |
645 ZoneList<ObjectLiteral::Property*>* properties, int start_position, | 701 ZoneList<ObjectLiteral::Property*>* properties, int start_position, |
646 int end_position, AstNodeFactory<AstConstructionVisitor>* factory) { | 702 int end_position, AstNodeFactory<AstConstructionVisitor>* factory) { |
647 return factory->NewClassLiteral(name, extends, constructor, properties, | 703 return factory->NewClassLiteral(name, extends, constructor, properties, |
648 start_position, end_position); | 704 start_position, end_position); |
649 } | 705 } |
650 | 706 |
| 707 |
| 708 Expression* ParserTraits::DefaultConstructor(bool call_super, Scope* scope, |
| 709 int pos, int end_pos) { |
| 710 return parser_->DefaultConstructor(call_super, scope, pos, end_pos); |
| 711 } |
| 712 |
| 713 |
651 Literal* ParserTraits::ExpressionFromLiteral( | 714 Literal* ParserTraits::ExpressionFromLiteral( |
652 Token::Value token, int pos, | 715 Token::Value token, int pos, |
653 Scanner* scanner, | 716 Scanner* scanner, |
654 AstNodeFactory<AstConstructionVisitor>* factory) { | 717 AstNodeFactory<AstConstructionVisitor>* factory) { |
655 switch (token) { | 718 switch (token) { |
656 case Token::NULL_LITERAL: | 719 case Token::NULL_LITERAL: |
657 return factory->NewNullLiteral(pos); | 720 return factory->NewNullLiteral(pos); |
658 case Token::TRUE_LITERAL: | 721 case Token::TRUE_LITERAL: |
659 return factory->NewBooleanLiteral(true, pos); | 722 return factory->NewBooleanLiteral(true, pos); |
660 case Token::FALSE_LITERAL: | 723 case Token::FALSE_LITERAL: |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 ? (shared_info->is_anonymous() | 1060 ? (shared_info->is_anonymous() |
998 ? FunctionLiteral::ANONYMOUS_EXPRESSION | 1061 ? FunctionLiteral::ANONYMOUS_EXPRESSION |
999 : FunctionLiteral::NAMED_EXPRESSION) | 1062 : FunctionLiteral::NAMED_EXPRESSION) |
1000 : FunctionLiteral::DECLARATION; | 1063 : FunctionLiteral::DECLARATION; |
1001 bool ok = true; | 1064 bool ok = true; |
1002 | 1065 |
1003 if (shared_info->is_arrow()) { | 1066 if (shared_info->is_arrow()) { |
1004 Expression* expression = ParseExpression(false, &ok); | 1067 Expression* expression = ParseExpression(false, &ok); |
1005 DCHECK(expression->IsFunctionLiteral()); | 1068 DCHECK(expression->IsFunctionLiteral()); |
1006 result = expression->AsFunctionLiteral(); | 1069 result = expression->AsFunctionLiteral(); |
| 1070 } else if (shared_info->is_default_constructor() || |
| 1071 shared_info->is_default_constructor_call_super()) { |
| 1072 result = DefaultConstructor( |
| 1073 shared_info->is_default_constructor_call_super(), scope, |
| 1074 shared_info->start_position(), shared_info->end_position()); |
1007 } else { | 1075 } else { |
1008 result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(), | 1076 result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(), |
1009 false, // Strict mode name already checked. | 1077 false, // Strict mode name already checked. |
1010 shared_info->kind(), RelocInfo::kNoPosition, | 1078 shared_info->kind(), RelocInfo::kNoPosition, |
1011 function_type, | 1079 function_type, |
1012 FunctionLiteral::NORMAL_ARITY, &ok); | 1080 FunctionLiteral::NORMAL_ARITY, &ok); |
1013 } | 1081 } |
1014 // Make sure the results agree. | 1082 // Make sure the results agree. |
1015 DCHECK(ok == (result != NULL)); | 1083 DCHECK(ok == (result != NULL)); |
1016 } | 1084 } |
(...skipping 3938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4955 | 5023 |
4956 // We cannot internalize on a background thread; a foreground task will take | 5024 // We cannot internalize on a background thread; a foreground task will take |
4957 // care of calling Parser::Internalize just before compilation. | 5025 // care of calling Parser::Internalize just before compilation. |
4958 | 5026 |
4959 if (compile_options() == ScriptCompiler::kProduceParserCache) { | 5027 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
4960 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); | 5028 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); |
4961 log_ = NULL; | 5029 log_ = NULL; |
4962 } | 5030 } |
4963 } | 5031 } |
4964 } } // namespace v8::internal | 5032 } } // namespace v8::internal |
OLD | NEW |