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

Side by Side Diff: src/parsing/parser.cc

Issue 2217973003: Clean up and simplify Parser::Declare (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix bad merge Created 4 years, 4 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/parsing/parser.h ('k') | src/parsing/pattern-rewriter.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/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/ast/ast.h" 10 #include "src/ast/ast.h"
(...skipping 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 1683
1684 const AstRawString* local_name = 1684 const AstRawString* local_name =
1685 ast_value_factory()->star_default_star_string(); 1685 ast_value_factory()->star_default_star_string();
1686 local_names.Add(local_name, zone()); 1686 local_names.Add(local_name, zone());
1687 1687
1688 // It's fine to declare this as CONST because the user has no way of 1688 // It's fine to declare this as CONST because the user has no way of
1689 // writing to it. 1689 // writing to it.
1690 VariableProxy* proxy = NewUnresolved(local_name, CONST); 1690 VariableProxy* proxy = NewUnresolved(local_name, CONST);
1691 Declaration* declaration = 1691 Declaration* declaration =
1692 factory()->NewVariableDeclaration(proxy, CONST, scope(), pos); 1692 factory()->NewVariableDeclaration(proxy, CONST, scope(), pos);
1693 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 1693 Declare(declaration, DeclarationDescriptor::NORMAL, CHECK_OK);
1694 proxy->var()->set_initializer_position(position()); 1694 proxy->var()->set_initializer_position(position());
1695 1695
1696 Assignment* assignment = factory()->NewAssignment( 1696 Assignment* assignment = factory()->NewAssignment(
1697 Token::INIT, proxy, value, kNoSourcePosition); 1697 Token::INIT, proxy, value, kNoSourcePosition);
1698 result = factory()->NewExpressionStatement(assignment, kNoSourcePosition); 1698 result = factory()->NewExpressionStatement(assignment, kNoSourcePosition);
1699 1699
1700 ExpectSemicolon(CHECK_OK); 1700 ExpectSemicolon(CHECK_OK);
1701 break; 1701 break;
1702 } 1702 }
1703 } 1703 }
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 scanner()->location().beg_pos, 1973 scanner()->location().beg_pos,
1974 scanner()->location().end_pos); 1974 scanner()->location().end_pos);
1975 } 1975 }
1976 1976
1977 void Parser::DeclareConstVariable(const AstRawString* name, 1977 void Parser::DeclareConstVariable(const AstRawString* name,
1978 InitializationFlag init, int pos, bool* ok) { 1978 InitializationFlag init, int pos, bool* ok) {
1979 DCHECK_NOT_NULL(name); 1979 DCHECK_NOT_NULL(name);
1980 VariableProxy* proxy = NewUnresolved(name, CONST); 1980 VariableProxy* proxy = NewUnresolved(name, CONST);
1981 Declaration* declaration = 1981 Declaration* declaration =
1982 factory()->NewVariableDeclaration(proxy, CONST, scope(), init, pos); 1982 factory()->NewVariableDeclaration(proxy, CONST, scope(), init, pos);
1983 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK_VOID); 1983 Declare(declaration, DeclarationDescriptor::NORMAL, CHECK_OK_VOID);
1984 } 1984 }
1985 1985
1986
1987 Variable* Parser::Declare(Declaration* declaration, 1986 Variable* Parser::Declare(Declaration* declaration,
1988 DeclarationDescriptor::Kind declaration_kind, 1987 DeclarationDescriptor::Kind declaration_kind,
1989 bool resolve, bool* ok, Scope* scope) { 1988 bool* ok, Scope* scope) {
1990 VariableProxy* proxy = declaration->proxy(); 1989 VariableProxy* proxy = declaration->proxy();
1991 DCHECK(proxy->raw_name() != NULL); 1990 DCHECK(proxy->raw_name() != NULL);
1992 const AstRawString* name = proxy->raw_name(); 1991 const AstRawString* name = proxy->raw_name();
1993 VariableMode mode = declaration->mode(); 1992 VariableMode mode = declaration->mode();
1994 DCHECK(IsDeclaredVariableMode(mode) && mode != CONST_LEGACY); 1993 DCHECK(IsDeclaredVariableMode(mode) && mode != CONST_LEGACY);
1995 bool is_function_declaration = declaration->IsFunctionDeclaration(); 1994 bool is_function_declaration = declaration->IsFunctionDeclaration();
1996 if (scope == nullptr) scope = this->scope(); 1995 if (scope == nullptr) scope = this->scope();
1997 Scope* declaration_scope = 1996 if (mode == VAR) scope = scope->GetDeclarationScope();
1998 IsLexicalVariableMode(mode) ? scope : scope->GetDeclarationScope(); 1997
1998 DCHECK(!scope->is_catch_scope());
1999 DCHECK(!scope->is_with_scope());
2000 DCHECK(scope->is_declaration_scope() ||
2001 (IsLexicalVariableMode(mode) && scope->is_block_scope()));
2002
1999 Variable* var = NULL; 2003 Variable* var = NULL;
2000 2004 if (scope->is_eval_scope() && is_sloppy(scope->language_mode()) &&
2001 // If a suitable scope exists, then we can statically declare this 2005 mode == VAR) {
2002 // variable and also set its mode. In any case, a Declaration node 2006 // In a var binding in a sloppy direct eval, pollute the enclosing scope
2003 // will be added to the scope so that the declaration can be added 2007 // with this new binding by doing the following:
2004 // to the corresponding activation frame at runtime if necessary. 2008 // The proxy is bound to a lookup variable to force a dynamic declaration
2005 // For instance, var declarations inside a sloppy eval scope need 2009 // using the DeclareEvalVar or DeclareEvalFunction runtime functions.
2006 // to be added to the calling function context. Similarly, strict 2010 Variable::Kind kind = Variable::NORMAL;
2007 // mode eval scope and lexical eval bindings do not leak variable 2011 // TODO(sigurds) figure out if kNotAssigned is OK here
2008 // declarations to the caller's scope so we declare all locals, too. 2012 var = new (zone()) Variable(scope, name, mode, kind,
2009 if (declaration_scope->is_function_scope() || 2013 declaration->initialization(), kNotAssigned);
2010 declaration_scope->is_block_scope() || 2014 var->AllocateTo(VariableLocation::LOOKUP, -1);
2011 declaration_scope->is_module_scope() || 2015 } else {
2012 declaration_scope->is_script_scope() ||
2013 (declaration_scope->is_eval_scope() &&
2014 (is_strict(declaration_scope->language_mode()) ||
2015 IsLexicalVariableMode(mode)))) {
2016 // Declare the variable in the declaration scope. 2016 // Declare the variable in the declaration scope.
2017 var = declaration_scope->LookupLocal(name); 2017 var = scope->LookupLocal(name);
2018 if (var == NULL) { 2018 if (var == NULL) {
2019 // Declare the name. 2019 // Declare the name.
2020 Variable::Kind kind = Variable::NORMAL; 2020 Variable::Kind kind = Variable::NORMAL;
2021 if (is_function_declaration) { 2021 if (is_function_declaration) {
2022 kind = Variable::FUNCTION; 2022 kind = Variable::FUNCTION;
2023 } 2023 }
2024 var = declaration_scope->DeclareLocal( 2024 var = scope->DeclareLocal(name, mode, declaration->initialization(), kind,
2025 name, mode, declaration->initialization(), kind, kNotAssigned); 2025 kNotAssigned);
2026 } else if (IsLexicalVariableMode(mode) || 2026 } else if (IsLexicalVariableMode(mode) ||
2027 IsLexicalVariableMode(var->mode())) { 2027 IsLexicalVariableMode(var->mode())) {
2028 // Allow duplicate function decls for web compat, see bug 4693. 2028 // Allow duplicate function decls for web compat, see bug 4693.
2029 bool duplicate_allowed = false; 2029 bool duplicate_allowed = false;
2030 if (is_sloppy(language_mode()) && is_function_declaration && 2030 if (is_sloppy(scope->language_mode()) && is_function_declaration &&
2031 var->is_function()) { 2031 var->is_function()) {
2032 DCHECK(IsLexicalVariableMode(mode) && 2032 DCHECK(IsLexicalVariableMode(mode) &&
2033 IsLexicalVariableMode(var->mode())); 2033 IsLexicalVariableMode(var->mode()));
2034 // If the duplication is allowed, then the var will show up 2034 // If the duplication is allowed, then the var will show up
2035 // in the SloppyBlockFunctionMap and the new FunctionKind 2035 // in the SloppyBlockFunctionMap and the new FunctionKind
2036 // will be a permitted duplicate. 2036 // will be a permitted duplicate.
2037 FunctionKind function_kind = 2037 FunctionKind function_kind =
2038 declaration->AsFunctionDeclaration()->fun()->kind(); 2038 declaration->AsFunctionDeclaration()->fun()->kind();
2039 duplicate_allowed = 2039 duplicate_allowed =
2040 scope->GetDeclarationScope()->sloppy_block_function_map()->Lookup( 2040 scope->GetDeclarationScope()->sloppy_block_function_map()->Lookup(
(...skipping 25 matching lines...) Expand all
2066 ParserTraits::ReportMessage(MessageTemplate::kVarRedeclaration, name); 2066 ParserTraits::ReportMessage(MessageTemplate::kVarRedeclaration, name);
2067 } else { 2067 } else {
2068 ParserTraits::ReportMessage(MessageTemplate::kParamDupe); 2068 ParserTraits::ReportMessage(MessageTemplate::kParamDupe);
2069 } 2069 }
2070 *ok = false; 2070 *ok = false;
2071 return nullptr; 2071 return nullptr;
2072 } 2072 }
2073 } else if (mode == VAR) { 2073 } else if (mode == VAR) {
2074 var->set_maybe_assigned(); 2074 var->set_maybe_assigned();
2075 } 2075 }
2076 } else if (declaration_scope->is_eval_scope() &&
2077 is_sloppy(declaration_scope->language_mode()) &&
2078 !IsLexicalVariableMode(mode)) {
2079 // In a var binding in a sloppy direct eval, pollute the enclosing scope
2080 // with this new binding by doing the following:
2081 // The proxy is bound to a lookup variable to force a dynamic declaration
2082 // using the DeclareEvalVar or DeclareEvalFunction runtime functions.
2083 Variable::Kind kind = Variable::NORMAL;
2084 // TODO(sigurds) figure out if kNotAssigned is OK here
2085 var = new (zone()) Variable(declaration_scope, name, mode, kind,
2086 declaration->initialization(), kNotAssigned);
2087 var->AllocateTo(VariableLocation::LOOKUP, -1);
2088 resolve = true;
2089 } 2076 }
2090 2077 DCHECK_NOT_NULL(var);
2091 2078
2092 // We add a declaration node for every declaration. The compiler 2079 // We add a declaration node for every declaration. The compiler
2093 // will only generate code if necessary. In particular, declarations 2080 // will only generate code if necessary. In particular, declarations
2094 // for inner local variables that do not represent functions won't 2081 // for inner local variables that do not represent functions won't
2095 // result in any generated code. 2082 // result in any generated code.
2096 // 2083 //
2097 // Note that we always add an unresolved proxy even if it's not 2084 // This will lead to multiple declaration nodes for the
2098 // used, simply because we don't know in this method (w/o extra
2099 // parameters) if the proxy is needed or not. The proxy will be
2100 // bound during variable resolution time unless it was pre-bound
2101 // below.
2102 //
2103 // WARNING: This will lead to multiple declaration nodes for the
2104 // same variable if it is declared several times. This is not a 2085 // same variable if it is declared several times. This is not a
2105 // semantic issue as long as we keep the source order, but it may be 2086 // semantic issue, but it may be a performance issue since it may
2106 // a performance issue since it may lead to repeated 2087 // lead to repeated DeclareEvalVar or DeclareEvalFunction calls.
2107 // DeclareEvalVar or DeclareEvalFunction calls. 2088 scope->AddDeclaration(declaration);
2108 declaration_scope->AddDeclaration(declaration); 2089 proxy->BindTo(var);
2109
2110 // If requested and we have a local variable, bind the proxy to the variable
2111 // at parse-time. This is used for functions (and consts) declared inside
2112 // statements: the corresponding function (or const) variable must be in the
2113 // function scope and not a statement-local scope, e.g. as provided with a
2114 // 'with' statement:
2115 //
2116 // with (obj) {
2117 // function f() {}
2118 // }
2119 //
2120 // which is translated into:
2121 //
2122 // with (obj) {
2123 // // in this case this is not: 'var f; f = function () {};'
2124 // var f = function () {};
2125 // }
2126 //
2127 // Note that if 'f' is accessed from inside the 'with' statement, it
2128 // will be allocated in the context (because we must be able to look
2129 // it up dynamically) but it will also be accessed statically, i.e.,
2130 // with a context slot index and a context chain length for this
2131 // initialization code. Thus, inside the 'with' statement, we need
2132 // both access to the static and the dynamic context chain; the
2133 // runtime needs to provide both.
2134 if (resolve && var != NULL) {
2135 proxy->BindTo(var);
2136 }
2137 return var; 2090 return var;
2138 } 2091 }
2139 2092
2140 2093
2141 // Language extension which is only enabled for source files loaded 2094 // Language extension which is only enabled for source files loaded
2142 // through the API's extension mechanism. A native function 2095 // through the API's extension mechanism. A native function
2143 // declaration is resolved by looking up the function through a 2096 // declaration is resolved by looking up the function through a
2144 // callback provided by the extension. 2097 // callback provided by the extension.
2145 Statement* Parser::ParseNativeDeclaration(bool* ok) { 2098 Statement* Parser::ParseNativeDeclaration(bool* ok) {
2146 int pos = peek_position(); 2099 int pos = peek_position();
(...skipping 19 matching lines...) Expand all
2166 // because of lazy compilation. 2119 // because of lazy compilation.
2167 // TODO(adamk): Should this be GetClosureScope()? 2120 // TODO(adamk): Should this be GetClosureScope()?
2168 scope()->GetDeclarationScope()->ForceEagerCompilation(); 2121 scope()->GetDeclarationScope()->ForceEagerCompilation();
2169 2122
2170 // TODO(1240846): It's weird that native function declarations are 2123 // TODO(1240846): It's weird that native function declarations are
2171 // introduced dynamically when we meet their declarations, whereas 2124 // introduced dynamically when we meet their declarations, whereas
2172 // other functions are set up when entering the surrounding scope. 2125 // other functions are set up when entering the surrounding scope.
2173 VariableProxy* proxy = NewUnresolved(name, VAR); 2126 VariableProxy* proxy = NewUnresolved(name, VAR);
2174 Declaration* declaration = 2127 Declaration* declaration =
2175 factory()->NewVariableDeclaration(proxy, VAR, scope(), pos); 2128 factory()->NewVariableDeclaration(proxy, VAR, scope(), pos);
2176 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 2129 Declare(declaration, DeclarationDescriptor::NORMAL, CHECK_OK);
2177 NativeFunctionLiteral* lit = 2130 NativeFunctionLiteral* lit =
2178 factory()->NewNativeFunctionLiteral(name, extension_, kNoSourcePosition); 2131 factory()->NewNativeFunctionLiteral(name, extension_, kNoSourcePosition);
2179 return factory()->NewExpressionStatement( 2132 return factory()->NewExpressionStatement(
2180 factory()->NewAssignment(Token::INIT, proxy, lit, kNoSourcePosition), 2133 factory()->NewAssignment(Token::INIT, proxy, lit, kNoSourcePosition),
2181 pos); 2134 pos);
2182 } 2135 }
2183 2136
2184 Statement* Parser::ParseHoistableDeclaration( 2137 Statement* Parser::ParseHoistableDeclaration(
2185 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) { 2138 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
2186 Expect(Token::FUNCTION, CHECK_OK); 2139 Expect(Token::FUNCTION, CHECK_OK);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2256 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); 2209 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK);
2257 2210
2258 // In ES6, a function behaves as a lexical binding, except in 2211 // In ES6, a function behaves as a lexical binding, except in
2259 // a script scope, or the initial scope of eval or another function. 2212 // a script scope, or the initial scope of eval or another function.
2260 VariableMode mode = 2213 VariableMode mode =
2261 (!scope()->is_declaration_scope() || scope()->is_module_scope()) ? LET 2214 (!scope()->is_declaration_scope() || scope()->is_module_scope()) ? LET
2262 : VAR; 2215 : VAR;
2263 VariableProxy* proxy = NewUnresolved(variable_name, mode); 2216 VariableProxy* proxy = NewUnresolved(variable_name, mode);
2264 Declaration* declaration = 2217 Declaration* declaration =
2265 factory()->NewFunctionDeclaration(proxy, mode, fun, scope(), pos); 2218 factory()->NewFunctionDeclaration(proxy, mode, fun, scope(), pos);
2266 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 2219 Declare(declaration, DeclarationDescriptor::NORMAL, CHECK_OK);
2267 if (names) names->Add(variable_name, zone()); 2220 if (names) names->Add(variable_name, zone());
2268 EmptyStatement* empty = factory()->NewEmptyStatement(kNoSourcePosition); 2221 EmptyStatement* empty = factory()->NewEmptyStatement(kNoSourcePosition);
2269 // Async functions don't undergo sloppy mode block scoped hoisting, and don't 2222 // Async functions don't undergo sloppy mode block scoped hoisting, and don't
2270 // allow duplicates in a block. Both are represented by the 2223 // allow duplicates in a block. Both are represented by the
2271 // sloppy_block_function_map. Don't add them to the map for async functions. 2224 // sloppy_block_function_map. Don't add them to the map for async functions.
2272 // Generators are also supposed to be prohibited; currently doing this behind 2225 // Generators are also supposed to be prohibited; currently doing this behind
2273 // a flag and UseCounting violations to assess web compatibility. 2226 // a flag and UseCounting violations to assess web compatibility.
2274 if (is_sloppy(language_mode()) && !scope()->is_declaration_scope() && 2227 if (is_sloppy(language_mode()) && !scope()->is_declaration_scope() &&
2275 !is_async && !(allow_harmony_restrictive_generators() && is_generator)) { 2228 !is_async && !(allow_harmony_restrictive_generators() && is_generator)) {
2276 SloppyBlockFunctionStatement* delegate = 2229 SloppyBlockFunctionStatement* delegate =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2315 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 2268 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
2316 variable_name = name; 2269 variable_name = name;
2317 } 2270 }
2318 2271
2319 Expression* value = ParseClassLiteral(nullptr, name, scanner()->location(), 2272 Expression* value = ParseClassLiteral(nullptr, name, scanner()->location(),
2320 is_strict_reserved, pos, CHECK_OK); 2273 is_strict_reserved, pos, CHECK_OK);
2321 2274
2322 VariableProxy* proxy = NewUnresolved(variable_name, LET); 2275 VariableProxy* proxy = NewUnresolved(variable_name, LET);
2323 Declaration* declaration = 2276 Declaration* declaration =
2324 factory()->NewVariableDeclaration(proxy, LET, scope(), pos); 2277 factory()->NewVariableDeclaration(proxy, LET, scope(), pos);
2325 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 2278 Declare(declaration, DeclarationDescriptor::NORMAL, CHECK_OK);
2326 proxy->var()->set_initializer_position(position()); 2279 proxy->var()->set_initializer_position(position());
2327 Assignment* assignment = 2280 Assignment* assignment =
2328 factory()->NewAssignment(Token::INIT, proxy, value, pos); 2281 factory()->NewAssignment(Token::INIT, proxy, value, pos);
2329 Statement* assignment_statement = 2282 Statement* assignment_statement =
2330 factory()->NewExpressionStatement(assignment, kNoSourcePosition); 2283 factory()->NewExpressionStatement(assignment, kNoSourcePosition);
2331 if (names) names->Add(variable_name, zone()); 2284 if (names) names->Add(variable_name, zone());
2332 return assignment_statement; 2285 return assignment_statement;
2333 } 2286 }
2334 2287
2335 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) { 2288 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok) {
(...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after
3548 3501
3549 Block* ignore_completion_block = 3502 Block* ignore_completion_block =
3550 factory()->NewBlock(NULL, names->length() + 3, true, kNoSourcePosition); 3503 factory()->NewBlock(NULL, names->length() + 3, true, kNoSourcePosition);
3551 ZoneList<Variable*> inner_vars(names->length(), zone()); 3504 ZoneList<Variable*> inner_vars(names->length(), zone());
3552 // For each let variable x: 3505 // For each let variable x:
3553 // make statement: let/const x = temp_x. 3506 // make statement: let/const x = temp_x.
3554 for (int i = 0; i < names->length(); i++) { 3507 for (int i = 0; i < names->length(); i++) {
3555 VariableProxy* proxy = NewUnresolved(names->at(i), mode); 3508 VariableProxy* proxy = NewUnresolved(names->at(i), mode);
3556 Declaration* declaration = factory()->NewVariableDeclaration( 3509 Declaration* declaration = factory()->NewVariableDeclaration(
3557 proxy, mode, scope(), kNoSourcePosition); 3510 proxy, mode, scope(), kNoSourcePosition);
3558 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 3511 Declare(declaration, DeclarationDescriptor::NORMAL, CHECK_OK);
3559 inner_vars.Add(declaration->proxy()->var(), zone()); 3512 inner_vars.Add(declaration->proxy()->var(), zone());
3560 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); 3513 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i));
3561 Assignment* assignment = factory()->NewAssignment( 3514 Assignment* assignment = factory()->NewAssignment(
3562 Token::INIT, proxy, temp_proxy, kNoSourcePosition); 3515 Token::INIT, proxy, temp_proxy, kNoSourcePosition);
3563 Statement* assignment_statement = 3516 Statement* assignment_statement =
3564 factory()->NewExpressionStatement(assignment, kNoSourcePosition); 3517 factory()->NewExpressionStatement(assignment, kNoSourcePosition);
3565 DCHECK(init->position() != kNoSourcePosition); 3518 DCHECK(init->position() != kNoSourcePosition);
3566 proxy->var()->set_initializer_position(init->position()); 3519 proxy->var()->set_initializer_position(init->position());
3567 ignore_completion_block->statements()->Add(assignment_statement, zone()); 3520 ignore_completion_block->statements()->Add(assignment_statement, zone());
3568 } 3521 }
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
3899 init_block = 3852 init_block =
3900 factory()->NewBlock(nullptr, 1, false, kNoSourcePosition); 3853 factory()->NewBlock(nullptr, 1, false, kNoSourcePosition);
3901 3854
3902 for (int i = 0; i < bound_names.length(); ++i) { 3855 for (int i = 0; i < bound_names.length(); ++i) {
3903 // TODO(adamk): This needs to be some sort of special 3856 // TODO(adamk): This needs to be some sort of special
3904 // INTERNAL variable that's invisible to the debugger 3857 // INTERNAL variable that's invisible to the debugger
3905 // but visible to everything else. 3858 // but visible to everything else.
3906 VariableProxy* tdz_proxy = NewUnresolved(bound_names[i], LET); 3859 VariableProxy* tdz_proxy = NewUnresolved(bound_names[i], LET);
3907 Declaration* tdz_decl = factory()->NewVariableDeclaration( 3860 Declaration* tdz_decl = factory()->NewVariableDeclaration(
3908 tdz_proxy, LET, scope(), kNoSourcePosition); 3861 tdz_proxy, LET, scope(), kNoSourcePosition);
3909 Variable* tdz_var = Declare( 3862 Variable* tdz_var =
3910 tdz_decl, DeclarationDescriptor::NORMAL, true, CHECK_OK); 3863 Declare(tdz_decl, DeclarationDescriptor::NORMAL, CHECK_OK);
3911 tdz_var->set_initializer_position(position()); 3864 tdz_var->set_initializer_position(position());
3912 } 3865 }
3913 } 3866 }
3914 3867
3915 for_state.set_end_position(scanner()->location().end_pos); 3868 for_state.set_end_position(scanner()->location().end_pos);
3916 Scope* for_scope = for_state.FinalizedBlockScope(); 3869 Scope* for_scope = for_state.FinalizedBlockScope();
3917 // Parsed for-in loop w/ variable declarations. 3870 // Parsed for-in loop w/ variable declarations.
3918 if (init_block != nullptr) { 3871 if (init_block != nullptr) {
3919 init_block->statements()->Add(final_loop, zone()); 3872 init_block->statements()->Add(final_loop, zone());
3920 init_block->set_scope(for_scope); 3873 init_block->set_scope(for_scope);
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
5081 #ifdef DEBUG 5034 #ifdef DEBUG
5082 scope()->SetScopeName(name); 5035 scope()->SetScopeName(name);
5083 #endif 5036 #endif
5084 5037
5085 VariableProxy* proxy = nullptr; 5038 VariableProxy* proxy = nullptr;
5086 if (name != nullptr) { 5039 if (name != nullptr) {
5087 proxy = NewUnresolved(name, CONST); 5040 proxy = NewUnresolved(name, CONST);
5088 // TODO(verwaest): declare via block_state. 5041 // TODO(verwaest): declare via block_state.
5089 Declaration* declaration = factory()->NewVariableDeclaration( 5042 Declaration* declaration = factory()->NewVariableDeclaration(
5090 proxy, CONST, block_state.scope(), pos); 5043 proxy, CONST, block_state.scope(), pos);
5091 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 5044 Declare(declaration, DeclarationDescriptor::NORMAL, CHECK_OK);
5092 } 5045 }
5093 5046
5094 Expression* extends = nullptr; 5047 Expression* extends = nullptr;
5095 if (Check(Token::EXTENDS)) { 5048 if (Check(Token::EXTENDS)) {
5096 block_state.set_start_position(scanner()->location().end_pos); 5049 block_state.set_start_position(scanner()->location().end_pos);
5097 ExpressionClassifier extends_classifier(this); 5050 ExpressionClassifier extends_classifier(this);
5098 extends = ParseLeftHandSideExpression(&extends_classifier, CHECK_OK); 5051 extends = ParseLeftHandSideExpression(&extends_classifier, CHECK_OK);
5099 CheckNoTailCallExpressions(&extends_classifier, CHECK_OK); 5052 CheckNoTailCallExpressions(&extends_classifier, CHECK_OK);
5100 RewriteNonPattern(&extends_classifier, CHECK_OK); 5053 RewriteNonPattern(&extends_classifier, CHECK_OK);
5101 if (classifier != nullptr) { 5054 if (classifier != nullptr) {
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
5359 } while (query_scope != outer_scope); 5312 } while (query_scope != outer_scope);
5360 5313
5361 if (!should_hoist) continue; 5314 if (!should_hoist) continue;
5362 5315
5363 // Declare a var-style binding for the function in the outer scope 5316 // Declare a var-style binding for the function in the outer scope
5364 if (!var_created) { 5317 if (!var_created) {
5365 var_created = true; 5318 var_created = true;
5366 VariableProxy* proxy = scope->NewUnresolved(factory(), name); 5319 VariableProxy* proxy = scope->NewUnresolved(factory(), name);
5367 Declaration* declaration = factory()->NewVariableDeclaration( 5320 Declaration* declaration = factory()->NewVariableDeclaration(
5368 proxy, VAR, scope, kNoSourcePosition); 5321 proxy, VAR, scope, kNoSourcePosition);
5369 Declare(declaration, DeclarationDescriptor::NORMAL, true, ok, scope); 5322 Declare(declaration, DeclarationDescriptor::NORMAL, ok, scope);
5370 DCHECK(ok); // Based on the preceding check, this should not fail 5323 DCHECK(ok); // Based on the preceding check, this should not fail
5371 if (!ok) return; 5324 if (!ok) return;
5372 } 5325 }
5373 5326
5374 // Read from the local lexical scope and write to the function scope 5327 // Read from the local lexical scope and write to the function scope
5375 VariableProxy* to = scope->NewUnresolved(factory(), name); 5328 VariableProxy* to = scope->NewUnresolved(factory(), name);
5376 VariableProxy* from = delegate->scope()->NewUnresolved(factory(), name); 5329 VariableProxy* from = delegate->scope()->NewUnresolved(factory(), name);
5377 Expression* assignment = 5330 Expression* assignment =
5378 factory()->NewAssignment(Token::ASSIGN, to, from, kNoSourcePosition); 5331 factory()->NewAssignment(Token::ASSIGN, to, from, kNoSourcePosition);
5379 Statement* statement = 5332 Statement* statement =
(...skipping 1785 matching lines...) Expand 10 before | Expand all | Expand 10 after
7165 node->Print(Isolate::Current()); 7118 node->Print(Isolate::Current());
7166 } 7119 }
7167 #endif // DEBUG 7120 #endif // DEBUG
7168 7121
7169 #undef CHECK_OK 7122 #undef CHECK_OK
7170 #undef CHECK_OK_VOID 7123 #undef CHECK_OK_VOID
7171 #undef CHECK_FAILED 7124 #undef CHECK_FAILED
7172 7125
7173 } // namespace internal 7126 } // namespace internal
7174 } // namespace v8 7127 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/pattern-rewriter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698