| OLD | NEW |
| 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/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 2983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2994 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); | 2994 VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i)); |
| 2995 Assignment* assignment = factory()->NewAssignment( | 2995 Assignment* assignment = factory()->NewAssignment( |
| 2996 Token::INIT_LET, proxy, temp_proxy, pos); | 2996 Token::INIT_LET, proxy, temp_proxy, pos); |
| 2997 Statement* assignment_statement = factory()->NewExpressionStatement( | 2997 Statement* assignment_statement = factory()->NewExpressionStatement( |
| 2998 assignment, pos); | 2998 assignment, pos); |
| 2999 proxy->var()->set_initializer_position(pos); | 2999 proxy->var()->set_initializer_position(pos); |
| 3000 inner_block->AddStatement(assignment_statement, zone()); | 3000 inner_block->AddStatement(assignment_statement, zone()); |
| 3001 } | 3001 } |
| 3002 | 3002 |
| 3003 // Make statement: if (flag == 1) { flag = 0; } else { next; }. | 3003 // Make statement: if (flag == 1) { flag = 0; } else { next; }. |
| 3004 { | 3004 if (next) { |
| 3005 Expression* compare = NULL; | 3005 Expression* compare = NULL; |
| 3006 // Make compare expresion: flag == 1. | 3006 // Make compare expresion: flag == 1. |
| 3007 { | 3007 { |
| 3008 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); | 3008 Expression* const1 = factory()->NewSmiLiteral(1, RelocInfo::kNoPosition); |
| 3009 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); | 3009 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); |
| 3010 compare = factory()->NewCompareOperation( | 3010 compare = factory()->NewCompareOperation( |
| 3011 Token::EQ, flag_proxy, const1, pos); | 3011 Token::EQ, flag_proxy, const1, pos); |
| 3012 } | 3012 } |
| 3013 Statement* clear_flag = NULL; | 3013 Statement* clear_flag = NULL; |
| 3014 // Make statement: flag = 0. | 3014 // Make statement: flag = 0. |
| 3015 { | 3015 { |
| 3016 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); | 3016 VariableProxy* flag_proxy = factory()->NewVariableProxy(flag); |
| 3017 Expression* const0 = factory()->NewSmiLiteral(0, RelocInfo::kNoPosition); | 3017 Expression* const0 = factory()->NewSmiLiteral(0, RelocInfo::kNoPosition); |
| 3018 Assignment* assignment = factory()->NewAssignment( | 3018 Assignment* assignment = factory()->NewAssignment( |
| 3019 Token::ASSIGN, flag_proxy, const0, RelocInfo::kNoPosition); | 3019 Token::ASSIGN, flag_proxy, const0, RelocInfo::kNoPosition); |
| 3020 clear_flag = factory()->NewExpressionStatement(assignment, pos); | 3020 clear_flag = factory()->NewExpressionStatement(assignment, pos); |
| 3021 } | 3021 } |
| 3022 Statement* clear_flag_or_next = factory()->NewIfStatement( | 3022 Statement* clear_flag_or_next = factory()->NewIfStatement( |
| 3023 compare, clear_flag, next, RelocInfo::kNoPosition); | 3023 compare, clear_flag, next, RelocInfo::kNoPosition); |
| 3024 inner_block->AddStatement(clear_flag_or_next, zone()); | 3024 inner_block->AddStatement(clear_flag_or_next, zone()); |
| 3025 } | 3025 } |
| 3026 | 3026 |
| 3027 | 3027 |
| 3028 // Make statement: if (cond) { } else { break; }. | 3028 // Make statement: if (cond) { } else { break; }. |
| 3029 { | 3029 if (cond) { |
| 3030 Statement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition); | 3030 Statement* empty = factory()->NewEmptyStatement(RelocInfo::kNoPosition); |
| 3031 BreakableStatement* t = LookupBreakTarget(NULL, CHECK_OK); | 3031 BreakableStatement* t = LookupBreakTarget(NULL, CHECK_OK); |
| 3032 Statement* stop = factory()->NewBreakStatement(t, RelocInfo::kNoPosition); | 3032 Statement* stop = factory()->NewBreakStatement(t, RelocInfo::kNoPosition); |
| 3033 Statement* if_not_cond_break = factory()->NewIfStatement( | 3033 Statement* if_not_cond_break = factory()->NewIfStatement( |
| 3034 cond, empty, stop, cond->position()); | 3034 cond, empty, stop, cond->position()); |
| 3035 inner_block->AddStatement(if_not_cond_break, zone()); | 3035 inner_block->AddStatement(if_not_cond_break, zone()); |
| 3036 } | 3036 } |
| 3037 | 3037 |
| 3038 inner_block->AddStatement(body, zone()); | 3038 inner_block->AddStatement(body, zone()); |
| 3039 | 3039 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3241 Statement* body = ParseStatement(NULL, CHECK_OK); | 3241 Statement* body = ParseStatement(NULL, CHECK_OK); |
| 3242 | 3242 |
| 3243 Statement* result = NULL; | 3243 Statement* result = NULL; |
| 3244 if (let_bindings.length() > 0) { | 3244 if (let_bindings.length() > 0) { |
| 3245 scope_ = for_scope; | 3245 scope_ = for_scope; |
| 3246 result = DesugarLetBindingsInForStatement(inner_scope, &let_bindings, loop, | 3246 result = DesugarLetBindingsInForStatement(inner_scope, &let_bindings, loop, |
| 3247 init, cond, next, body, CHECK_OK); | 3247 init, cond, next, body, CHECK_OK); |
| 3248 scope_ = saved_scope; | 3248 scope_ = saved_scope; |
| 3249 for_scope->set_end_position(scanner()->location().end_pos); | 3249 for_scope->set_end_position(scanner()->location().end_pos); |
| 3250 } else { | 3250 } else { |
| 3251 loop->Initialize(init, cond, next, body); | |
| 3252 result = loop; | |
| 3253 scope_ = saved_scope; | 3251 scope_ = saved_scope; |
| 3254 for_scope->set_end_position(scanner()->location().end_pos); | 3252 for_scope->set_end_position(scanner()->location().end_pos); |
| 3255 for_scope->FinalizeBlockScope(); | 3253 for_scope = for_scope->FinalizeBlockScope(); |
| 3254 if (for_scope) { |
| 3255 // Rewrite a for statement of the form |
| 3256 // for (const x = i; c; n) b |
| 3257 // |
| 3258 // into |
| 3259 // |
| 3260 // { |
| 3261 // const x = i; |
| 3262 // for (; c; n) b |
| 3263 // } |
| 3264 ASSERT(init != NULL); |
| 3265 Block* block = |
| 3266 factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition); |
| 3267 block->AddStatement(init, zone()); |
| 3268 block->AddStatement(loop, zone()); |
| 3269 block->set_scope(for_scope); |
| 3270 loop->Initialize(NULL, cond, next, body); |
| 3271 result = block; |
| 3272 } else { |
| 3273 loop->Initialize(init, cond, next, body); |
| 3274 result = loop; |
| 3275 } |
| 3256 } | 3276 } |
| 3257 return result; | 3277 return result; |
| 3258 } | 3278 } |
| 3259 | 3279 |
| 3260 | 3280 |
| 3261 DebuggerStatement* Parser::ParseDebuggerStatement(bool* ok) { | 3281 DebuggerStatement* Parser::ParseDebuggerStatement(bool* ok) { |
| 3262 // In ECMA-262 'debugger' is defined as a reserved keyword. In some browser | 3282 // In ECMA-262 'debugger' is defined as a reserved keyword. In some browser |
| 3263 // contexts this is used as a statement which invokes the debugger as i a | 3283 // contexts this is used as a statement which invokes the debugger as i a |
| 3264 // break point is present. | 3284 // break point is present. |
| 3265 // DebuggerStatement :: | 3285 // DebuggerStatement :: |
| (...skipping 1600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4866 info()->SetAstValueFactory(ast_value_factory_); | 4886 info()->SetAstValueFactory(ast_value_factory_); |
| 4867 } | 4887 } |
| 4868 ast_value_factory_ = NULL; | 4888 ast_value_factory_ = NULL; |
| 4869 | 4889 |
| 4870 InternalizeUseCounts(); | 4890 InternalizeUseCounts(); |
| 4871 | 4891 |
| 4872 return (result != NULL); | 4892 return (result != NULL); |
| 4873 } | 4893 } |
| 4874 | 4894 |
| 4875 } } // namespace v8::internal | 4895 } } // namespace v8::internal |
| OLD | NEW |