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/parser.cc

Issue 1309303006: Propagate switch statement value for 'eval' (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix AST tests Created 5 years, 3 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 | « no previous file | test/cctest/test-ast-expression-visitor.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/parser.h" 5 #include "src/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/ast-literal-reindexer.h" 9 #include "src/ast-literal-reindexer.h"
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 2972 matching lines...) Expand 10 before | Expand all | Expand 10 after
2983 // but without requiring downstream code to have special scope handling 2983 // but without requiring downstream code to have special scope handling
2984 // code for switch statements, desugar into blocks as follows: 2984 // code for switch statements, desugar into blocks as follows:
2985 // { // To group the statements--harmless to evaluate Expression in scope 2985 // { // To group the statements--harmless to evaluate Expression in scope
2986 // .tag_variable = Expression; 2986 // .tag_variable = Expression;
2987 // { // To give CaseClauses a scope 2987 // { // To give CaseClauses a scope
2988 // switch (.tag_variable) { CaseClause* } 2988 // switch (.tag_variable) { CaseClause* }
2989 // } 2989 // }
2990 // } 2990 // }
2991 2991
2992 Block* switch_block = 2992 Block* switch_block =
2993 factory()->NewBlock(NULL, 2, true, RelocInfo::kNoPosition); 2993 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition);
2994 int switch_pos = peek_position(); 2994 int switch_pos = peek_position();
2995 2995
2996 Expect(Token::SWITCH, CHECK_OK); 2996 Expect(Token::SWITCH, CHECK_OK);
2997 Expect(Token::LPAREN, CHECK_OK); 2997 Expect(Token::LPAREN, CHECK_OK);
2998 Expression* tag = ParseExpression(true, CHECK_OK); 2998 Expression* tag = ParseExpression(true, CHECK_OK);
2999 Expect(Token::RPAREN, CHECK_OK); 2999 Expect(Token::RPAREN, CHECK_OK);
3000 3000
3001 Variable* tag_variable = 3001 Variable* tag_variable =
3002 scope_->NewTemporary(ast_value_factory()->dot_switch_tag_string()); 3002 scope_->NewTemporary(ast_value_factory()->dot_switch_tag_string());
3003 Assignment* tag_assign = factory()->NewAssignment( 3003 Assignment* tag_assign = factory()->NewAssignment(
3004 Token::ASSIGN, factory()->NewVariableProxy(tag_variable), tag, 3004 Token::ASSIGN, factory()->NewVariableProxy(tag_variable), tag,
3005 tag->position()); 3005 tag->position());
3006 Statement* tag_statement = 3006 Statement* tag_statement =
3007 factory()->NewExpressionStatement(tag_assign, RelocInfo::kNoPosition); 3007 factory()->NewExpressionStatement(tag_assign, RelocInfo::kNoPosition);
3008 switch_block->AddStatement(tag_statement, zone()); 3008 switch_block->AddStatement(tag_statement, zone());
3009 3009
3010 // make statement: undefined;
3011 // This is needed so the tag isn't returned as the value, in case the switch
3012 // statements don't have a value.
3013 switch_block->AddStatement(
3014 factory()->NewExpressionStatement(
3015 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition),
3016 RelocInfo::kNoPosition),
3017 zone());
3018
3010 Block* cases_block = 3019 Block* cases_block =
3011 factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition); 3020 factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition);
3012 Scope* cases_scope = NewScope(scope_, BLOCK_SCOPE); 3021 Scope* cases_scope = NewScope(scope_, BLOCK_SCOPE);
3013 3022
3014 SwitchStatement* switch_statement = 3023 SwitchStatement* switch_statement =
3015 factory()->NewSwitchStatement(labels, switch_pos); 3024 factory()->NewSwitchStatement(labels, switch_pos);
3016 3025
3017 cases_scope->set_start_position(scanner()->location().beg_pos); 3026 cases_scope->set_start_position(scanner()->location().beg_pos);
3018 { 3027 {
3019 BlockState cases_block_state(&scope_, cases_scope); 3028 BlockState cases_block_state(&scope_, cases_scope);
3020 Target target(&this->target_stack_, switch_statement); 3029 Target target(&this->target_stack_, switch_statement);
3021 3030
(...skipping 3084 matching lines...) Expand 10 before | Expand all | Expand 10 after
6106 6115
6107 Expression* Parser::SpreadCallNew(Expression* function, 6116 Expression* Parser::SpreadCallNew(Expression* function,
6108 ZoneList<v8::internal::Expression*>* args, 6117 ZoneList<v8::internal::Expression*>* args,
6109 int pos) { 6118 int pos) {
6110 args->InsertAt(0, function, zone()); 6119 args->InsertAt(0, function, zone());
6111 6120
6112 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); 6121 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos);
6113 } 6122 }
6114 } // namespace internal 6123 } // namespace internal
6115 } // namespace v8 6124 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-ast-expression-visitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698