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

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