| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 <cmath> | 5 #include <cmath> |
| 6 | 6 |
| 7 #include "src/allocation.h" | 7 #include "src/allocation.h" |
| 8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
| 9 #include "src/conversions-inl.h" | 9 #include "src/conversions-inl.h" |
| 10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 if (track_unresolved_variables_) { | 78 if (track_unresolved_variables_) { |
| 79 const AstRawString* result = scanner()->CurrentSymbol(ast_value_factory()); | 79 const AstRawString* result = scanner()->CurrentSymbol(ast_value_factory()); |
| 80 DCHECK_NOT_NULL(result); | 80 DCHECK_NOT_NULL(result); |
| 81 symbol.string_ = result; | 81 symbol.string_ = result; |
| 82 } | 82 } |
| 83 return symbol; | 83 return symbol; |
| 84 } | 84 } |
| 85 | 85 |
| 86 PreParser::PreParseResult PreParser::PreParseFunction( | 86 PreParser::PreParseResult PreParser::PreParseFunction( |
| 87 FunctionKind kind, DeclarationScope* function_scope, bool parsing_module, | 87 FunctionKind kind, DeclarationScope* function_scope, bool parsing_module, |
| 88 SingletonLogger* log, bool is_inner_function, bool may_abort, | 88 bool is_inner_function, bool may_abort, int* use_counts) { |
| 89 int* use_counts) { | |
| 90 DCHECK_EQ(FUNCTION_SCOPE, function_scope->scope_type()); | 89 DCHECK_EQ(FUNCTION_SCOPE, function_scope->scope_type()); |
| 91 parsing_module_ = parsing_module; | 90 parsing_module_ = parsing_module; |
| 92 log_ = log; | |
| 93 use_counts_ = use_counts; | 91 use_counts_ = use_counts; |
| 94 DCHECK(!track_unresolved_variables_); | 92 DCHECK(!track_unresolved_variables_); |
| 95 track_unresolved_variables_ = is_inner_function; | 93 track_unresolved_variables_ = is_inner_function; |
| 96 | 94 |
| 97 // The caller passes the function_scope which is not yet inserted into the | 95 // The caller passes the function_scope which is not yet inserted into the |
| 98 // scope_state_. All scopes above the function_scope are ignored by the | 96 // scope_state_. All scopes above the function_scope are ignored by the |
| 99 // PreParser. | 97 // PreParser. |
| 100 DCHECK_NULL(scope_state_); | 98 DCHECK_NULL(scope_state_); |
| 101 FunctionState function_state(&function_state_, &scope_state_, function_scope); | 99 FunctionState function_state(&function_state_, &scope_state_, function_scope); |
| 102 // This indirection is needed so that we can use the CHECK_OK macros. | 100 // This indirection is needed so that we can use the CHECK_OK macros. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 120 | 118 |
| 121 CheckArityRestrictions( | 119 CheckArityRestrictions( |
| 122 formals.arity, kind, formals.has_rest, function_scope->start_position(), | 120 formals.arity, kind, formals.has_rest, function_scope->start_position(), |
| 123 formals_end_position, CHECK_OK_VALUE(kPreParseSuccess)); | 121 formals_end_position, CHECK_OK_VALUE(kPreParseSuccess)); |
| 124 has_duplicate_parameters = | 122 has_duplicate_parameters = |
| 125 !classifier()->is_valid_formal_parameter_list_without_duplicates(); | 123 !classifier()->is_valid_formal_parameter_list_without_duplicates(); |
| 126 } | 124 } |
| 127 | 125 |
| 128 Expect(Token::LBRACE, CHECK_OK_VALUE(kPreParseSuccess)); | 126 Expect(Token::LBRACE, CHECK_OK_VALUE(kPreParseSuccess)); |
| 129 LazyParsingResult result = ParseStatementListAndLogFunction( | 127 LazyParsingResult result = ParseStatementListAndLogFunction( |
| 130 function_scope->start_position(), &formals, has_duplicate_parameters, | 128 &formals, has_duplicate_parameters, may_abort, ok); |
| 131 may_abort, ok); | |
| 132 use_counts_ = nullptr; | 129 use_counts_ = nullptr; |
| 133 track_unresolved_variables_ = false; | 130 track_unresolved_variables_ = false; |
| 134 if (result == kLazyParsingAborted) { | 131 if (result == kLazyParsingAborted) { |
| 135 return kPreParseAbort; | 132 return kPreParseAbort; |
| 136 } else if (stack_overflow()) { | 133 } else if (stack_overflow()) { |
| 137 return kPreParseStackOverflow; | 134 return kPreParseStackOverflow; |
| 138 } else if (!*ok) { | 135 } else if (!*ok) { |
| 139 DCHECK(log->has_error()); | 136 DCHECK(log_.has_error()); |
| 140 } else { | 137 } else { |
| 141 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 138 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
| 142 | 139 |
| 143 if (!IsArrowFunction(kind)) { | 140 if (!IsArrowFunction(kind)) { |
| 144 // Validate parameter names. We can do this only after parsing the | 141 // Validate parameter names. We can do this only after parsing the |
| 145 // function, since the function can declare itself strict. | 142 // function, since the function can declare itself strict. |
| 146 const bool allow_duplicate_parameters = | 143 const bool allow_duplicate_parameters = |
| 147 is_sloppy(function_scope->language_mode()) && formals.is_simple && | 144 is_sloppy(function_scope->language_mode()) && formals.is_simple && |
| 148 !IsConciseMethod(kind); | 145 !IsConciseMethod(kind); |
| 149 ValidateFormalParameters(function_scope->language_mode(), | 146 ValidateFormalParameters(function_scope->language_mode(), |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 PrintF(" [%s]: %i-%i\n", | 225 PrintF(" [%s]: %i-%i\n", |
| 229 track_unresolved_variables_ ? "Preparse resolution" | 226 track_unresolved_variables_ ? "Preparse resolution" |
| 230 : "Preparse no-resolution", | 227 : "Preparse no-resolution", |
| 231 function_scope->start_position(), function_scope->end_position()); | 228 function_scope->start_position(), function_scope->end_position()); |
| 232 } | 229 } |
| 233 | 230 |
| 234 return Expression::Default(); | 231 return Expression::Default(); |
| 235 } | 232 } |
| 236 | 233 |
| 237 PreParser::LazyParsingResult PreParser::ParseStatementListAndLogFunction( | 234 PreParser::LazyParsingResult PreParser::ParseStatementListAndLogFunction( |
| 238 int start_position, PreParserFormalParameters* formals, | 235 PreParserFormalParameters* formals, bool has_duplicate_parameters, |
| 239 bool has_duplicate_parameters, bool may_abort, bool* ok) { | 236 bool may_abort, bool* ok) { |
| 240 PreParserStatementList body; | 237 PreParserStatementList body; |
| 241 LazyParsingResult result = ParseStatementList( | 238 LazyParsingResult result = ParseStatementList( |
| 242 body, Token::RBRACE, may_abort, CHECK_OK_VALUE(kLazyParsingComplete)); | 239 body, Token::RBRACE, may_abort, CHECK_OK_VALUE(kLazyParsingComplete)); |
| 243 if (result == kLazyParsingAborted) return result; | 240 if (result == kLazyParsingAborted) return result; |
| 244 | 241 |
| 245 // Position right after terminal '}'. | 242 // Position right after terminal '}'. |
| 246 DCHECK_EQ(Token::RBRACE, scanner()->peek()); | 243 DCHECK_EQ(Token::RBRACE, scanner()->peek()); |
| 247 int body_end = scanner()->peek_location().end_pos; | 244 int body_end = scanner()->peek_location().end_pos; |
| 248 DeclarationScope* scope = this->scope()->AsDeclarationScope(); | 245 DCHECK(this->scope()->is_function_scope()); |
| 249 DCHECK(scope->is_function_scope()); | 246 log_.LogFunction(body_end, formals->num_parameters(), |
| 250 log_->LogFunction(start_position, body_end, formals->num_parameters(), | 247 formals->function_length, has_duplicate_parameters, |
| 251 formals->function_length, has_duplicate_parameters, | 248 function_state_->materialized_literal_count(), |
| 252 function_state_->materialized_literal_count(), | 249 function_state_->expected_property_count()); |
| 253 function_state_->expected_property_count(), language_mode(), | |
| 254 scope->uses_super_property(), scope->calls_eval()); | |
| 255 return kLazyParsingComplete; | 250 return kLazyParsingComplete; |
| 256 } | 251 } |
| 257 | 252 |
| 258 PreParserExpression PreParser::ExpressionFromIdentifier( | 253 PreParserExpression PreParser::ExpressionFromIdentifier( |
| 259 PreParserIdentifier name, int start_position, InferName infer) { | 254 PreParserIdentifier name, int start_position, InferName infer) { |
| 260 if (track_unresolved_variables_) { | 255 if (track_unresolved_variables_) { |
| 261 AstNodeFactory factory(ast_value_factory()); | 256 AstNodeFactory factory(ast_value_factory()); |
| 262 // Setting the Zone is necessary because zone_ might be the temp Zone, and | 257 // Setting the Zone is necessary because zone_ might be the temp Zone, and |
| 263 // AstValueFactory doesn't know about it. | 258 // AstValueFactory doesn't know about it. |
| 264 factory.set_zone(zone()); | 259 factory.set_zone(zone()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 294 } | 289 } |
| 295 } | 290 } |
| 296 } | 291 } |
| 297 | 292 |
| 298 #undef CHECK_OK | 293 #undef CHECK_OK |
| 299 #undef CHECK_OK_CUSTOM | 294 #undef CHECK_OK_CUSTOM |
| 300 | 295 |
| 301 | 296 |
| 302 } // namespace internal | 297 } // namespace internal |
| 303 } // namespace v8 | 298 } // namespace v8 |
| OLD | NEW |