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

Side by Side Diff: src/parser.cc

Issue 1032653002: Do not assign positions to parser-generated desugarings. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased for landing Created 5 years, 9 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/hydrogen.h ('k') | test/mjsunit/es6/regress/regress-468661.js » ('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/v8.h" 5 #include "src/v8.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/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 3183 matching lines...) Expand 10 before | Expand all | Expand 10 after
3194 // in this function that looks up break targets. 3194 // in this function that looks up break targets.
3195 ForStatement* outer_loop = 3195 ForStatement* outer_loop =
3196 factory()->NewForStatement(NULL, RelocInfo::kNoPosition); 3196 factory()->NewForStatement(NULL, RelocInfo::kNoPosition);
3197 outer_block->AddStatement(outer_loop, zone()); 3197 outer_block->AddStatement(outer_loop, zone());
3198 3198
3199 outer_block->set_scope(for_scope); 3199 outer_block->set_scope(for_scope);
3200 scope_ = inner_scope; 3200 scope_ = inner_scope;
3201 3201
3202 Block* inner_block = factory()->NewBlock(NULL, names->length() + 4, false, 3202 Block* inner_block = factory()->NewBlock(NULL, names->length() + 4, false,
3203 RelocInfo::kNoPosition); 3203 RelocInfo::kNoPosition);
3204 int pos = scanner()->location().beg_pos;
3205 ZoneList<Variable*> inner_vars(names->length(), zone()); 3204 ZoneList<Variable*> inner_vars(names->length(), zone());
3206 3205
3207 // For each let variable x: 3206 // For each let variable x:
3208 // make statement: let/const x = temp_x. 3207 // make statement: let/const x = temp_x.
3209 VariableMode mode = is_const ? CONST : LET; 3208 VariableMode mode = is_const ? CONST : LET;
3210 for (int i = 0; i < names->length(); i++) { 3209 for (int i = 0; i < names->length(); i++) {
3211 VariableProxy* proxy = NewUnresolved(names->at(i), mode); 3210 VariableProxy* proxy = NewUnresolved(names->at(i), mode);
3212 Declaration* declaration = factory()->NewVariableDeclaration( 3211 Declaration* declaration = factory()->NewVariableDeclaration(
3213 proxy, mode, scope_, RelocInfo::kNoPosition); 3212 proxy, mode, scope_, RelocInfo::kNoPosition);
3214 Declare(declaration, true, CHECK_OK); 3213 Declare(declaration, true, CHECK_OK);
3215 inner_vars.Add(declaration->proxy()->var(), zone()); 3214 inner_vars.Add(declaration->proxy()->var(), zone());
3216 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); 3215 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i));
3217 Assignment* assignment = factory()->NewAssignment( 3216 Assignment* assignment =
3218 is_const ? Token::INIT_CONST : Token::INIT_LET, proxy, temp_proxy, pos); 3217 factory()->NewAssignment(is_const ? Token::INIT_CONST : Token::INIT_LET,
3218 proxy, temp_proxy, RelocInfo::kNoPosition);
3219 Statement* assignment_statement = 3219 Statement* assignment_statement =
3220 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); 3220 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition);
3221 proxy->var()->set_initializer_position(init->position()); 3221 proxy->var()->set_initializer_position(init->position());
3222 inner_block->AddStatement(assignment_statement, zone()); 3222 inner_block->AddStatement(assignment_statement, zone());
3223 } 3223 }
3224 3224
3225 // Make statement: if (first == 1) { first = 0; } else { next; } 3225 // Make statement: if (first == 1) { first = 0; } else { next; }
3226 if (next) { 3226 if (next) {
3227 DCHECK(first); 3227 DCHECK(first);
3228 Expression* compare = NULL; 3228 Expression* compare = NULL;
3229 // Make compare expression: first == 1. 3229 // Make compare expression: first == 1.
3230 { 3230 {
3231 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); 3231 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition);
3232 VariableProxy* first_proxy = factory()->NewVariableProxy(first); 3232 VariableProxy* first_proxy = factory()->NewVariableProxy(first);
3233 compare = 3233 compare = factory()->NewCompareOperation(Token::EQ, first_proxy, const1,
3234 factory()->NewCompareOperation(Token::EQ, first_proxy, const1, pos); 3234 RelocInfo::kNoPosition);
3235 } 3235 }
3236 Statement* clear_first = NULL; 3236 Statement* clear_first = NULL;
3237 // Make statement: first = 0. 3237 // Make statement: first = 0.
3238 { 3238 {
3239 VariableProxy* first_proxy = factory()->NewVariableProxy(first); 3239 VariableProxy* first_proxy = factory()->NewVariableProxy(first);
3240 Expression* const0 = factory()->NewSmiLiteral(0, RelocInfo::kNoPosition); 3240 Expression* const0 = factory()->NewSmiLiteral(0, RelocInfo::kNoPosition);
3241 Assignment* assignment = factory()->NewAssignment( 3241 Assignment* assignment = factory()->NewAssignment(
3242 Token::ASSIGN, first_proxy, const0, RelocInfo::kNoPosition); 3242 Token::ASSIGN, first_proxy, const0, RelocInfo::kNoPosition);
3243 clear_first = 3243 clear_first =
3244 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); 3244 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition);
3245 } 3245 }
3246 Statement* clear_first_or_next = factory()->NewIfStatement( 3246 Statement* clear_first_or_next =
3247 compare, clear_first, next, RelocInfo::kNoPosition); 3247 factory()->NewIfStatement(compare, clear_first, next, next->position());
3248 inner_block->AddStatement(clear_first_or_next, zone()); 3248 inner_block->AddStatement(clear_first_or_next, zone());
3249 } 3249 }
3250 3250
3251 Variable* flag = scope_->DeclarationScope()->NewTemporary(temp_name); 3251 Variable* flag = scope_->DeclarationScope()->NewTemporary(temp_name);
3252 // Make statement: flag = 1. 3252 // Make statement: flag = 1.
3253 { 3253 {
3254 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); 3254 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
3255 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); 3255 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition);
3256 Assignment* assignment = factory()->NewAssignment( 3256 Assignment* assignment = factory()->NewAssignment(
3257 Token::ASSIGN, flag_proxy, const1, RelocInfo::kNoPosition); 3257 Token::ASSIGN, flag_proxy, const1, RelocInfo::kNoPosition);
3258 Statement* assignment_statement = 3258 Statement* assignment_statement =
3259 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition); 3259 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition);
3260 inner_block->AddStatement(assignment_statement, zone()); 3260 inner_block->AddStatement(assignment_statement, zone());
3261 } 3261 }
3262 3262
3263 // Make cond expression for main loop: flag == 1. 3263 // Make cond expression for main loop: flag == 1.
3264 Expression* flag_cond = NULL; 3264 Expression* flag_cond = NULL;
3265 { 3265 {
3266 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); 3266 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition);
3267 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); 3267 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
3268 flag_cond = 3268 flag_cond = factory()->NewCompareOperation(Token::EQ, flag_proxy, const1,
3269 factory()->NewCompareOperation(Token::EQ, flag_proxy, const1, pos); 3269 RelocInfo::kNoPosition);
3270 } 3270 }
3271 3271
3272 // Create chain of expressions "flag = 0, temp_x = x, ..." 3272 // Create chain of expressions "flag = 0, temp_x = x, ..."
3273 Statement* compound_next_statement = NULL; 3273 Statement* compound_next_statement = NULL;
3274 { 3274 {
3275 Expression* compound_next = NULL; 3275 Expression* compound_next = NULL;
3276 // Make expression: flag = 0. 3276 // Make expression: flag = 0.
3277 { 3277 {
3278 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); 3278 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
3279 Expression* const0 = factory()->NewSmiLiteral(0, RelocInfo::kNoPosition); 3279 Expression* const0 = factory()->NewSmiLiteral(0, RelocInfo::kNoPosition);
3280 compound_next = factory()->NewAssignment(Token::ASSIGN, flag_proxy, 3280 compound_next = factory()->NewAssignment(Token::ASSIGN, flag_proxy,
3281 const0, RelocInfo::kNoPosition); 3281 const0, RelocInfo::kNoPosition);
3282 } 3282 }
3283 3283
3284 // Make the comma-separated list of temp_x = x assignments. 3284 // Make the comma-separated list of temp_x = x assignments.
3285 int inner_var_proxy_pos = scanner()->location().beg_pos;
3285 for (int i = 0; i < names->length(); i++) { 3286 for (int i = 0; i < names->length(); i++) {
3286 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); 3287 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i));
3287 VariableProxy* proxy = factory()->NewVariableProxy(inner_vars.at(i), pos); 3288 VariableProxy* proxy =
3289 factory()->NewVariableProxy(inner_vars.at(i), inner_var_proxy_pos);
3288 Assignment* assignment = factory()->NewAssignment( 3290 Assignment* assignment = factory()->NewAssignment(
3289 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition); 3291 Token::ASSIGN, temp_proxy, proxy, RelocInfo::kNoPosition);
3290 compound_next = factory()->NewBinaryOperation( 3292 compound_next = factory()->NewBinaryOperation(
3291 Token::COMMA, compound_next, assignment, RelocInfo::kNoPosition); 3293 Token::COMMA, compound_next, assignment, RelocInfo::kNoPosition);
3292 } 3294 }
3293 3295
3294 compound_next_statement = factory()->NewExpressionStatement( 3296 compound_next_statement = factory()->NewExpressionStatement(
3295 compound_next, RelocInfo::kNoPosition); 3297 compound_next, RelocInfo::kNoPosition);
3296 } 3298 }
3297 3299
(...skipping 13 matching lines...) Expand all
3311 loop->Initialize(NULL, flag_cond, compound_next_statement, body_or_stop); 3313 loop->Initialize(NULL, flag_cond, compound_next_statement, body_or_stop);
3312 inner_block->AddStatement(loop, zone()); 3314 inner_block->AddStatement(loop, zone());
3313 3315
3314 // Make statement: if (flag == 1) { break; } 3316 // Make statement: if (flag == 1) { break; }
3315 { 3317 {
3316 Expression* compare = NULL; 3318 Expression* compare = NULL;
3317 // Make compare expresion: flag == 1. 3319 // Make compare expresion: flag == 1.
3318 { 3320 {
3319 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); 3321 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition);
3320 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); 3322 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
3321 compare = 3323 compare = factory()->NewCompareOperation(Token::EQ, flag_proxy, const1,
3322 factory()->NewCompareOperation(Token::EQ, flag_proxy, const1, pos); 3324 RelocInfo::kNoPosition);
3323 } 3325 }
3324 Statement* stop = 3326 Statement* stop =
3325 factory()->NewBreakStatement(outer_loop, RelocInfo::kNoPosition); 3327 factory()->NewBreakStatement(outer_loop, RelocInfo::kNoPosition);
3326 Statement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition); 3328 Statement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition);
3327 Statement* if_flag_break = 3329 Statement* if_flag_break =
3328 factory()->NewIfStatement(compare, stop, empty, RelocInfo::kNoPosition); 3330 factory()->NewIfStatement(compare, stop, empty, RelocInfo::kNoPosition);
3329 inner_block->AddStatement(if_flag_break, zone()); 3331 inner_block->AddStatement(if_flag_break, zone());
3330 } 3332 }
3331 3333
3332 inner_scope->set_end_position(scanner()->location().end_pos); 3334 inner_scope->set_end_position(scanner()->location().end_pos);
(...skipping 2224 matching lines...) Expand 10 before | Expand all | Expand 10 after
5557 } else { 5559 } else {
5558 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); 5560 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data());
5559 running_hash = StringHasher::ComputeRunningHash(running_hash, data, 5561 running_hash = StringHasher::ComputeRunningHash(running_hash, data,
5560 raw_string->length()); 5562 raw_string->length());
5561 } 5563 }
5562 } 5564 }
5563 5565
5564 return running_hash; 5566 return running_hash;
5565 } 5567 }
5566 } } // namespace v8::internal 5568 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | test/mjsunit/es6/regress/regress-468661.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698