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

Side by Side Diff: src/parser.cc

Issue 1157213004: Drop computed handler count and index from AST. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments. Created 5 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
« no previous file with comments | « src/mips64/full-codegen-mips64.cc ('k') | src/ppc/full-codegen-ppc.cc » ('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 #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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 cached_parse_data_ = ParseData::FromCachedData(*info->cached_data()); 329 cached_parse_data_ = ParseData::FromCachedData(*info->cached_data());
330 } 330 }
331 } 331 }
332 } 332 }
333 333
334 334
335 FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope, 335 FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope,
336 int pos, int end_pos) { 336 int pos, int end_pos) {
337 int materialized_literal_count = -1; 337 int materialized_literal_count = -1;
338 int expected_property_count = -1; 338 int expected_property_count = -1;
339 int handler_count = 0;
340 int parameter_count = 0; 339 int parameter_count = 0;
341 const AstRawString* name = ast_value_factory()->empty_string(); 340 const AstRawString* name = ast_value_factory()->empty_string();
342 341
343 342
344 FunctionKind kind = call_super ? FunctionKind::kDefaultSubclassConstructor 343 FunctionKind kind = call_super ? FunctionKind::kDefaultSubclassConstructor
345 : FunctionKind::kDefaultBaseConstructor; 344 : FunctionKind::kDefaultBaseConstructor;
346 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE, kind); 345 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE, kind);
347 function_scope->SetLanguageMode( 346 function_scope->SetLanguageMode(
348 static_cast<LanguageMode>(scope->language_mode() | STRICT_BIT)); 347 static_cast<LanguageMode>(scope->language_mode() | STRICT_BIT));
349 // Set start and end position to the same value 348 // Set start and end position to the same value
(...skipping 22 matching lines...) Expand all
372 args->Add(this_function_proxy, zone()); 371 args->Add(this_function_proxy, zone());
373 CallRuntime* call = factory()->NewCallRuntime( 372 CallRuntime* call = factory()->NewCallRuntime(
374 ast_value_factory()->empty_string(), 373 ast_value_factory()->empty_string(),
375 Runtime::FunctionForId(Runtime::kInlineDefaultConstructorCallSuper), 374 Runtime::FunctionForId(Runtime::kInlineDefaultConstructorCallSuper),
376 args, pos); 375 args, pos);
377 body->Add(factory()->NewReturnStatement(call, pos), zone()); 376 body->Add(factory()->NewReturnStatement(call, pos), zone());
378 } 377 }
379 378
380 materialized_literal_count = function_state.materialized_literal_count(); 379 materialized_literal_count = function_state.materialized_literal_count();
381 expected_property_count = function_state.expected_property_count(); 380 expected_property_count = function_state.expected_property_count();
382 handler_count = function_state.handler_count();
383 } 381 }
384 382
385 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( 383 FunctionLiteral* function_literal = factory()->NewFunctionLiteral(
386 name, ast_value_factory(), function_scope, body, 384 name, ast_value_factory(), function_scope, body,
387 materialized_literal_count, expected_property_count, handler_count, 385 materialized_literal_count, expected_property_count, parameter_count,
388 parameter_count, FunctionLiteral::kNoDuplicateParameters, 386 FunctionLiteral::kNoDuplicateParameters,
389 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, 387 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction,
390 FunctionLiteral::kShouldLazyCompile, kind, pos); 388 FunctionLiteral::kShouldLazyCompile, kind, pos);
391 389
392 return function_literal; 390 return function_literal;
393 } 391 }
394 392
395 393
396 // ---------------------------------------------------------------------------- 394 // ----------------------------------------------------------------------------
397 // Target is a support class to facilitate manipulation of the 395 // Target is a support class to facilitate manipulation of the
398 // Parser's target_stack_ (the stack of potential 'break' and 396 // Parser's target_stack_ (the stack of potential 'break' and
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 expression()->IsFunctionLiteral()) { 1061 expression()->IsFunctionLiteral()) {
1064 ReportMessage(MessageTemplate::kSingleFunctionLiteral); 1062 ReportMessage(MessageTemplate::kSingleFunctionLiteral);
1065 ok = false; 1063 ok = false;
1066 } 1064 }
1067 } 1065 }
1068 1066
1069 if (ok) { 1067 if (ok) {
1070 result = factory()->NewFunctionLiteral( 1068 result = factory()->NewFunctionLiteral(
1071 ast_value_factory()->empty_string(), ast_value_factory(), scope_, 1069 ast_value_factory()->empty_string(), ast_value_factory(), scope_,
1072 body, function_state.materialized_literal_count(), 1070 body, function_state.materialized_literal_count(),
1073 function_state.expected_property_count(), 1071 function_state.expected_property_count(), 0,
1074 function_state.handler_count(), 0,
1075 FunctionLiteral::kNoDuplicateParameters, 1072 FunctionLiteral::kNoDuplicateParameters,
1076 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kGlobalOrEval, 1073 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kGlobalOrEval,
1077 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 1074 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction,
1078 0); 1075 0);
1079 } 1076 }
1080 } 1077 }
1081 1078
1082 // Make sure the target stack is empty. 1079 // Make sure the target stack is empty.
1083 DCHECK(target_stack_ == NULL); 1080 DCHECK(target_stack_ == NULL);
1084 1081
(...skipping 1928 matching lines...) Expand 10 before | Expand all | Expand 10 after
3013 } 3010 }
3014 3011
3015 // Simplify the AST nodes by converting: 3012 // Simplify the AST nodes by converting:
3016 // 'try B0 catch B1 finally B2' 3013 // 'try B0 catch B1 finally B2'
3017 // to: 3014 // to:
3018 // 'try { try B0 catch B1 } finally B2' 3015 // 'try { try B0 catch B1 } finally B2'
3019 3016
3020 if (catch_block != NULL && finally_block != NULL) { 3017 if (catch_block != NULL && finally_block != NULL) {
3021 // If we have both, create an inner try/catch. 3018 // If we have both, create an inner try/catch.
3022 DCHECK(catch_scope != NULL && catch_variable != NULL); 3019 DCHECK(catch_scope != NULL && catch_variable != NULL);
3023 int index = function_state_->NextHandlerIndex(); 3020 TryCatchStatement* statement =
3024 TryCatchStatement* statement = factory()->NewTryCatchStatement( 3021 factory()->NewTryCatchStatement(try_block, catch_scope, catch_variable,
3025 index, try_block, catch_scope, catch_variable, catch_block, 3022 catch_block, RelocInfo::kNoPosition);
3026 RelocInfo::kNoPosition);
3027 try_block = factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition); 3023 try_block = factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition);
3028 try_block->AddStatement(statement, zone()); 3024 try_block->AddStatement(statement, zone());
3029 catch_block = NULL; // Clear to indicate it's been handled. 3025 catch_block = NULL; // Clear to indicate it's been handled.
3030 } 3026 }
3031 3027
3032 TryStatement* result = NULL; 3028 TryStatement* result = NULL;
3033 if (catch_block != NULL) { 3029 if (catch_block != NULL) {
3034 DCHECK(finally_block == NULL); 3030 DCHECK(finally_block == NULL);
3035 DCHECK(catch_scope != NULL && catch_variable != NULL); 3031 DCHECK(catch_scope != NULL && catch_variable != NULL);
3036 int index = function_state_->NextHandlerIndex(); 3032 result = factory()->NewTryCatchStatement(try_block, catch_scope,
3037 result = factory()->NewTryCatchStatement( 3033 catch_variable, catch_block, pos);
3038 index, try_block, catch_scope, catch_variable, catch_block, pos);
3039 } else { 3034 } else {
3040 DCHECK(finally_block != NULL); 3035 DCHECK(finally_block != NULL);
3041 int index = function_state_->NextHandlerIndex(); 3036 result = factory()->NewTryFinallyStatement(try_block, finally_block, pos);
3042 result = factory()->NewTryFinallyStatement(
3043 index, try_block, finally_block, pos);
3044 } 3037 }
3045 3038
3046 return result; 3039 return result;
3047 } 3040 }
3048 3041
3049 3042
3050 DoWhileStatement* Parser::ParseDoWhileStatement( 3043 DoWhileStatement* Parser::ParseDoWhileStatement(
3051 ZoneList<const AstRawString*>* labels, bool* ok) { 3044 ZoneList<const AstRawString*>* labels, bool* ok) {
3052 // DoStatement :: 3045 // DoStatement ::
3053 // 'do' Statement 'while' '(' Expression ')' ';' 3046 // 'do' Statement 'while' '(' Expression ')' ';'
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
3876 Scope* original_declaration_scope = original_scope_->DeclarationScope(); 3869 Scope* original_declaration_scope = original_scope_->DeclarationScope();
3877 Scope* scope = function_type == FunctionLiteral::DECLARATION && 3870 Scope* scope = function_type == FunctionLiteral::DECLARATION &&
3878 is_sloppy(language_mode()) && 3871 is_sloppy(language_mode()) &&
3879 (original_scope_ == original_declaration_scope || 3872 (original_scope_ == original_declaration_scope ||
3880 declaration_scope != original_declaration_scope) 3873 declaration_scope != original_declaration_scope)
3881 ? NewScope(declaration_scope, FUNCTION_SCOPE, kind) 3874 ? NewScope(declaration_scope, FUNCTION_SCOPE, kind)
3882 : NewScope(scope_, FUNCTION_SCOPE, kind); 3875 : NewScope(scope_, FUNCTION_SCOPE, kind);
3883 ZoneList<Statement*>* body = NULL; 3876 ZoneList<Statement*>* body = NULL;
3884 int materialized_literal_count = -1; 3877 int materialized_literal_count = -1;
3885 int expected_property_count = -1; 3878 int expected_property_count = -1;
3886 int handler_count = 0;
3887 ExpressionClassifier formals_classifier; 3879 ExpressionClassifier formals_classifier;
3888 FunctionLiteral::EagerCompileHint eager_compile_hint = 3880 FunctionLiteral::EagerCompileHint eager_compile_hint =
3889 parenthesized_function_ ? FunctionLiteral::kShouldEagerCompile 3881 parenthesized_function_ ? FunctionLiteral::kShouldEagerCompile
3890 : FunctionLiteral::kShouldLazyCompile; 3882 : FunctionLiteral::kShouldLazyCompile;
3891 bool should_be_used_once_hint = false; 3883 bool should_be_used_once_hint = false;
3892 // Parse function body. 3884 // Parse function body.
3893 { 3885 {
3894 AstNodeFactory function_factory(ast_value_factory()); 3886 AstNodeFactory function_factory(ast_value_factory());
3895 FunctionState function_state(&function_state_, &scope_, scope, kind, 3887 FunctionState function_state(&function_state_, &scope_, scope, kind,
3896 &function_factory); 3888 &function_factory);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
4013 // used once. 4005 // used once.
4014 eager_compile_hint = FunctionLiteral::kShouldEagerCompile; 4006 eager_compile_hint = FunctionLiteral::kShouldEagerCompile;
4015 should_be_used_once_hint = true; 4007 should_be_used_once_hint = true;
4016 } 4008 }
4017 } 4009 }
4018 if (!is_lazily_parsed) { 4010 if (!is_lazily_parsed) {
4019 body = ParseEagerFunctionBody(function_name, pos, fvar, fvar_init_op, 4011 body = ParseEagerFunctionBody(function_name, pos, fvar, fvar_init_op,
4020 kind, CHECK_OK); 4012 kind, CHECK_OK);
4021 materialized_literal_count = function_state.materialized_literal_count(); 4013 materialized_literal_count = function_state.materialized_literal_count();
4022 expected_property_count = function_state.expected_property_count(); 4014 expected_property_count = function_state.expected_property_count();
4023 handler_count = function_state.handler_count();
4024 4015
4025 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) { 4016 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) {
4026 if (!function_state.super_location().IsValid()) { 4017 if (!function_state.super_location().IsValid()) {
4027 ReportMessageAt(function_name_location, 4018 ReportMessageAt(function_name_location,
4028 MessageTemplate::kStrongSuperCallMissing, 4019 MessageTemplate::kStrongSuperCallMissing,
4029 kReferenceError); 4020 kReferenceError);
4030 *ok = false; 4021 *ok = false;
4031 return nullptr; 4022 return nullptr;
4032 } 4023 }
4033 } 4024 }
(...skipping 18 matching lines...) Expand all
4052 } 4043 }
4053 4044
4054 bool has_duplicate_parameters = 4045 bool has_duplicate_parameters =
4055 !formals_classifier.is_valid_formal_parameter_list_without_duplicates(); 4046 !formals_classifier.is_valid_formal_parameter_list_without_duplicates();
4056 FunctionLiteral::ParameterFlag duplicate_parameters = 4047 FunctionLiteral::ParameterFlag duplicate_parameters =
4057 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters 4048 has_duplicate_parameters ? FunctionLiteral::kHasDuplicateParameters
4058 : FunctionLiteral::kNoDuplicateParameters; 4049 : FunctionLiteral::kNoDuplicateParameters;
4059 4050
4060 FunctionLiteral* function_literal = factory()->NewFunctionLiteral( 4051 FunctionLiteral* function_literal = factory()->NewFunctionLiteral(
4061 function_name, ast_value_factory(), scope, body, 4052 function_name, ast_value_factory(), scope, body,
4062 materialized_literal_count, expected_property_count, handler_count, 4053 materialized_literal_count, expected_property_count, num_parameters,
4063 num_parameters, duplicate_parameters, function_type, 4054 duplicate_parameters, function_type, FunctionLiteral::kIsFunction,
4064 FunctionLiteral::kIsFunction, eager_compile_hint, kind, pos); 4055 eager_compile_hint, kind, pos);
4065 function_literal->set_function_token_position(function_token_pos); 4056 function_literal->set_function_token_position(function_token_pos);
4066 if (should_be_used_once_hint) 4057 if (should_be_used_once_hint)
4067 function_literal->set_should_be_used_once_hint(); 4058 function_literal->set_should_be_used_once_hint();
4068 4059
4069 if (scope->has_rest_parameter()) { 4060 if (scope->has_rest_parameter()) {
4070 // TODO(caitp): enable optimization of functions with rest params 4061 // TODO(caitp): enable optimization of functions with rest params
4071 function_literal->set_dont_optimize_reason(kRestParameter); 4062 function_literal->set_dont_optimize_reason(kRestParameter);
4072 } 4063 }
4073 4064
4074 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); 4065 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal);
(...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after
5822 Expression* Parser::SpreadCallNew(Expression* function, 5813 Expression* Parser::SpreadCallNew(Expression* function,
5823 ZoneList<v8::internal::Expression*>* args, 5814 ZoneList<v8::internal::Expression*>* args,
5824 int pos) { 5815 int pos) {
5825 args->InsertAt(0, function, zone()); 5816 args->InsertAt(0, function, zone());
5826 5817
5827 return factory()->NewCallRuntime( 5818 return factory()->NewCallRuntime(
5828 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 5819 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5829 } 5820 }
5830 } // namespace internal 5821 } // namespace internal
5831 } // namespace v8 5822 } // namespace v8
OLDNEW
« no previous file with comments | « src/mips64/full-codegen-mips64.cc ('k') | src/ppc/full-codegen-ppc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698