Commit 82e43bfe authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[parser] Skipping inner funcs: produce the same scopes / variables for parameters (part 1).

This CL covers only the very simple cases.

BUG=v8:5516
R=vogelheim@chromium.org

Change-Id: Ib6ddc90cbcf1c923a7b72493cfd029cfa835462b
Reviewed-on: https://chromium-review.googlesource.com/440246Reviewed-by: 's avatarDaniel Vogelheim <vogelheim@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43086}
parent b8c7870c
......@@ -938,6 +938,7 @@ Variable* DeclarationScope::DeclareParameter(
if (mode == TEMPORARY) {
var = NewTemporary(name);
} else {
DCHECK_EQ(mode, VAR);
var = Declare(zone(), name, mode);
// TODO(wingo): Avoid O(n^2) check.
*is_duplicate = IsDeclaredParameter(name);
......@@ -950,6 +951,26 @@ Variable* DeclarationScope::DeclareParameter(
return var;
}
Variable* DeclarationScope::DeclareParameterName(
const AstRawString* name, bool is_rest,
AstValueFactory* ast_value_factory) {
DCHECK(!already_resolved_);
DCHECK(is_function_scope() || is_module_scope());
DCHECK(!has_rest_);
DCHECK(is_being_lazily_parsed_);
has_rest_ = is_rest;
if (name == ast_value_factory->arguments_string()) {
has_arguments_parameter_ = true;
}
if (FLAG_preparser_scope_analysis) {
Variable* var = Declare(zone(), name, VAR);
params_.Add(var, zone());
return var;
}
DeclareVariableName(name, VAR);
return nullptr;
}
Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode,
InitializationFlag init_flag, VariableKind kind,
MaybeAssignedFlag maybe_assigned_flag) {
......
......@@ -687,6 +687,11 @@ class DeclarationScope : public Scope {
bool is_optional, bool is_rest, bool* is_duplicate,
AstValueFactory* ast_value_factory);
// Declares that a parameter with the name exists. Creates a Variable and
// returns it if FLAG_preparser_scope_analysis is on.
Variable* DeclareParameterName(const AstRawString* name, bool is_rest,
AstValueFactory* ast_value_factory);
// Declare an implicit global variable in this scope which must be a
// script scope. The variable was introduced (possibly from an inner
// scope) by a reference to an unresolved variable with no intervening
......
......@@ -783,11 +783,13 @@ class PreParserFactory {
struct PreParserFormalParameters : FormalParametersBase {
struct Parameter : public ZoneObject {
explicit Parameter(PreParserExpression pattern) : pattern(pattern) {}
Parameter(PreParserExpression pattern, bool is_rest)
: pattern(pattern), is_rest(is_rest) {}
Parameter** next() { return &next_parameter; }
Parameter* const* next() const { return &next_parameter; }
PreParserExpression pattern;
Parameter* next_parameter = nullptr;
bool is_rest;
};
explicit PreParserFormalParameters(DeclarationScope* scope)
: FormalParametersBase(scope) {}
......@@ -1584,8 +1586,8 @@ class PreParser : public ParserBase<PreParser> {
bool is_rest) {
if (track_unresolved_variables_) {
DCHECK(FLAG_lazy_inner_functions);
parameters->params.Add(new (zone())
PreParserFormalParameters::Parameter(pattern));
parameters->params.Add(
new (zone()) PreParserFormalParameters::Parameter(pattern, is_rest));
}
parameters->UpdateArityAndFunctionLength(!initializer.IsEmpty(), is_rest);
}
......@@ -1601,7 +1603,8 @@ class PreParser : public ParserBase<PreParser> {
for (auto parameter : parameters) {
if (parameter->pattern.variables_ != nullptr) {
for (auto variable : *parameter->pattern.variables_) {
scope->DeclareVariableName(variable->raw_name(), VAR);
scope->DeclareParameterName(
variable->raw_name(), parameter->is_rest, ast_value_factory());
}
}
}
......
......@@ -284,6 +284,24 @@ TEST(PreParserScopeAnalysis) {
{"var f1 = 1; if (true) { function f1() {} }"},
{"var f1 = 1; if (true) { function f1() {} } function foo() { f1; }"},
// Simple parameters.
{"var1", ""},
{"var1", "var1;"},
{"var1", "var1 = 9;"},
{"var1", "function f1() { var1; }"},
{"var1", "function f1() { var1 = 9; }"},
// Duplicate parameters.
{"var1, var1", ""},
{"var1, var1", "var1;"},
{"var1, var1", "var1 = 9;"},
{"var1, var1", "function f1() { var1; }"},
{"var1, var1", "function f1() { var1 = 9; }"},
// FIXME(marja): destructuring parameters, rest parameter, default
// parameters, shadowing parameters, default parameters referring to other
// parameters, arguments parameter, eval in default parameter.
};
for (unsigned i = 0; i < arraysize(inners); ++i) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment