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

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

Issue 1704223002: Remove strong mode support from Scope and Variable (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove test-parsing test Created 4 years, 10 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/objects.h ('k') | src/parsing/parser-base.h » ('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 "src/api.h" 7 #include "src/api.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/ast-expression-rewriter.h" 9 #include "src/ast/ast-expression-rewriter.h"
10 #include "src/ast/ast-expression-visitor.h" 10 #include "src/ast/ast-expression-visitor.h"
(...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 return 0; 1260 return 0;
1261 } 1261 }
1262 1262
1263 1263
1264 Statement* Parser::ParseStatementListItem(bool* ok) { 1264 Statement* Parser::ParseStatementListItem(bool* ok) {
1265 // (Ecma 262 6th Edition, 13.1): 1265 // (Ecma 262 6th Edition, 13.1):
1266 // StatementListItem: 1266 // StatementListItem:
1267 // Statement 1267 // Statement
1268 // Declaration 1268 // Declaration
1269 1269
1270 if (peek() != Token::CLASS) {
1271 // No more classes follow; reset the start position for the consecutive
1272 // class declaration group.
1273 scope_->set_class_declaration_group_start(-1);
1274 }
1275
1276 switch (peek()) { 1270 switch (peek()) {
1277 case Token::FUNCTION: 1271 case Token::FUNCTION:
1278 return ParseFunctionDeclaration(NULL, ok); 1272 return ParseFunctionDeclaration(NULL, ok);
1279 case Token::CLASS: 1273 case Token::CLASS:
1280 if (scope_->class_declaration_group_start() < 0) {
1281 scope_->set_class_declaration_group_start(
1282 scanner()->peek_location().beg_pos);
1283 }
1284 Consume(Token::CLASS); 1274 Consume(Token::CLASS);
1285 return ParseClassDeclaration(NULL, ok); 1275 return ParseClassDeclaration(NULL, ok);
1286 case Token::CONST: 1276 case Token::CONST:
1287 if (allow_const()) { 1277 if (allow_const()) {
1288 return ParseVariableStatement(kStatementListItem, NULL, ok); 1278 return ParseVariableStatement(kStatementListItem, NULL, ok);
1289 } 1279 }
1290 break; 1280 break;
1291 case Token::VAR: 1281 case Token::VAR:
1292 return ParseVariableStatement(kStatementListItem, NULL, ok); 1282 return ParseVariableStatement(kStatementListItem, NULL, ok);
1293 case Token::LET: 1283 case Token::LET:
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
1951 declaration_scope->is_module_scope() || 1941 declaration_scope->is_module_scope() ||
1952 declaration_scope->is_script_scope() || 1942 declaration_scope->is_script_scope() ||
1953 (declaration_scope->is_eval_scope() && 1943 (declaration_scope->is_eval_scope() &&
1954 (is_strict(declaration_scope->language_mode()) || 1944 (is_strict(declaration_scope->language_mode()) ||
1955 IsLexicalVariableMode(mode)))) { 1945 IsLexicalVariableMode(mode)))) {
1956 // Declare the variable in the declaration scope. 1946 // Declare the variable in the declaration scope.
1957 var = declaration_scope->LookupLocal(name); 1947 var = declaration_scope->LookupLocal(name);
1958 if (var == NULL) { 1948 if (var == NULL) {
1959 // Declare the name. 1949 // Declare the name.
1960 Variable::Kind kind = Variable::NORMAL; 1950 Variable::Kind kind = Variable::NORMAL;
1961 int declaration_group_start = -1;
1962 if (is_function_declaration) { 1951 if (is_function_declaration) {
1963 kind = Variable::FUNCTION; 1952 kind = Variable::FUNCTION;
1964 } else if (declaration->IsVariableDeclaration() &&
1965 declaration->AsVariableDeclaration()->is_class_declaration()) {
1966 kind = Variable::CLASS;
1967 declaration_group_start =
1968 declaration->AsVariableDeclaration()->declaration_group_start();
1969 } 1953 }
1970 var = declaration_scope->DeclareLocal( 1954 var = declaration_scope->DeclareLocal(
1971 name, mode, declaration->initialization(), kind, kNotAssigned, 1955 name, mode, declaration->initialization(), kind, kNotAssigned);
1972 declaration_group_start);
1973 } else if ((mode == CONST_LEGACY || var->mode() == CONST_LEGACY) && 1956 } else if ((mode == CONST_LEGACY || var->mode() == CONST_LEGACY) &&
1974 !declaration_scope->is_script_scope()) { 1957 !declaration_scope->is_script_scope()) {
1975 // Duplicate legacy const definitions throw at runtime. 1958 // Duplicate legacy const definitions throw at runtime.
1976 DCHECK(is_sloppy(language_mode())); 1959 DCHECK(is_sloppy(language_mode()));
1977 Expression* expression = NewThrowSyntaxError( 1960 Expression* expression = NewThrowSyntaxError(
1978 MessageTemplate::kVarRedeclaration, name, declaration->position()); 1961 MessageTemplate::kVarRedeclaration, name, declaration->position());
1979 declaration_scope->SetIllegalRedeclaration(expression); 1962 declaration_scope->SetIllegalRedeclaration(expression);
1980 } else if ((IsLexicalVariableMode(mode) || 1963 } else if ((IsLexicalVariableMode(mode) ||
1981 IsLexicalVariableMode(var->mode())) && 1964 IsLexicalVariableMode(var->mode())) &&
1982 // Lexical bindings may appear for some parameters in sloppy 1965 // Lexical bindings may appear for some parameters in sloppy
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 2205
2223 int pos = position(); 2206 int pos = position();
2224 bool is_strict_reserved = false; 2207 bool is_strict_reserved = false;
2225 const AstRawString* name = 2208 const AstRawString* name =
2226 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 2209 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
2227 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(), 2210 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(),
2228 is_strict_reserved, pos, CHECK_OK); 2211 is_strict_reserved, pos, CHECK_OK);
2229 2212
2230 VariableMode mode = is_strong(language_mode()) ? CONST : LET; 2213 VariableMode mode = is_strong(language_mode()) ? CONST : LET;
2231 VariableProxy* proxy = NewUnresolved(name, mode); 2214 VariableProxy* proxy = NewUnresolved(name, mode);
2232 const bool is_class_declaration = true; 2215 Declaration* declaration =
2233 Declaration* declaration = factory()->NewVariableDeclaration( 2216 factory()->NewVariableDeclaration(proxy, mode, scope_, pos);
2234 proxy, mode, scope_, pos, is_class_declaration, 2217 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
2235 scope_->class_declaration_group_start());
2236 Variable* outer_class_variable =
2237 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
2238 proxy->var()->set_initializer_position(position()); 2218 proxy->var()->set_initializer_position(position());
2239 // This is needed because a class ("class Name { }") creates two bindings (one
2240 // in the outer scope, and one in the class scope). The method is a function
2241 // scope inside the inner scope (class scope). The consecutive class
2242 // declarations are in the outer scope.
2243 if (value->class_variable_proxy() && value->class_variable_proxy()->var() &&
2244 outer_class_variable->is_class()) {
2245 // In some cases, the outer variable is not detected as a class variable;
2246 // this happens e.g., for lazy methods. They are excluded from strong mode
2247 // checks for now. TODO(marja, rossberg): re-create variables with the
2248 // correct Kind and remove this hack.
2249 value->class_variable_proxy()
2250 ->var()
2251 ->AsClassVariable()
2252 ->set_declaration_group_start(
2253 outer_class_variable->AsClassVariable()->declaration_group_start());
2254 }
2255
2256 Assignment* assignment = 2219 Assignment* assignment =
2257 factory()->NewAssignment(Token::INIT, proxy, value, pos); 2220 factory()->NewAssignment(Token::INIT, proxy, value, pos);
2258 Statement* assignment_statement = 2221 Statement* assignment_statement =
2259 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); 2222 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition);
2260 if (names) names->Add(name, zone()); 2223 if (names) names->Add(name, zone());
2261 return assignment_statement; 2224 return assignment_statement;
2262 } 2225 }
2263 2226
2264 2227
2265 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels, 2228 Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels,
(...skipping 2624 matching lines...) Expand 10 before | Expand all | Expand 10 after
4890 } 4853 }
4891 4854
4892 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE); 4855 Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
4893 BlockState block_state(&scope_, block_scope); 4856 BlockState block_state(&scope_, block_scope);
4894 RaiseLanguageMode(STRICT); 4857 RaiseLanguageMode(STRICT);
4895 scope_->SetScopeName(name); 4858 scope_->SetScopeName(name);
4896 4859
4897 VariableProxy* proxy = NULL; 4860 VariableProxy* proxy = NULL;
4898 if (name != NULL) { 4861 if (name != NULL) {
4899 proxy = NewUnresolved(name, CONST); 4862 proxy = NewUnresolved(name, CONST);
4900 const bool is_class_declaration = true; 4863 Declaration* declaration =
4901 Declaration* declaration = factory()->NewVariableDeclaration( 4864 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos);
4902 proxy, CONST, block_scope, pos, is_class_declaration,
4903 scope_->class_declaration_group_start());
4904 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 4865 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
4905 } 4866 }
4906 4867
4907 Expression* extends = NULL; 4868 Expression* extends = NULL;
4908 if (Check(Token::EXTENDS)) { 4869 if (Check(Token::EXTENDS)) {
4909 block_scope->set_start_position(scanner()->location().end_pos); 4870 block_scope->set_start_position(scanner()->location().end_pos);
4910 ExpressionClassifier classifier; 4871 ExpressionClassifier classifier;
4911 extends = ParseLeftHandSideExpression(&classifier, CHECK_OK); 4872 extends = ParseLeftHandSideExpression(&classifier, CHECK_OK);
4912 extends = ParserTraits::RewriteNonPattern(extends, &classifier, CHECK_OK); 4873 extends = ParserTraits::RewriteNonPattern(extends, &classifier, CHECK_OK);
4913 } else { 4874 } else {
(...skipping 1487 matching lines...) Expand 10 before | Expand all | Expand 10 after
6401 6362
6402 statements->Add(get_return, zone); 6363 statements->Add(get_return, zone);
6403 statements->Add(check_return, zone); 6364 statements->Add(check_return, zone);
6404 statements->Add(call_return, zone); 6365 statements->Add(call_return, zone);
6405 statements->Add(validate_output, zone); 6366 statements->Add(validate_output, zone);
6406 } 6367 }
6407 6368
6408 6369
6409 } // namespace internal 6370 } // namespace internal
6410 } // namespace v8 6371 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698