OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/ast.h" | 5 #include "src/ast.h" |
6 #include "src/parser.h" | 6 #include "src/parser.h" |
7 | 7 |
8 namespace v8 { | 8 namespace v8 { |
9 | 9 |
10 namespace internal { | 10 namespace internal { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 VariableProxy* proxy = initialization_scope->NewUnresolved(factory(), name); | 200 VariableProxy* proxy = initialization_scope->NewUnresolved(factory(), name); |
201 Assignment* assignment = factory()->NewAssignment( | 201 Assignment* assignment = factory()->NewAssignment( |
202 descriptor_->init_op, proxy, value, descriptor_->pos); | 202 descriptor_->init_op, proxy, value, descriptor_->pos); |
203 block_->AddStatement( | 203 block_->AddStatement( |
204 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), | 204 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), |
205 zone()); | 205 zone()); |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 | 209 |
210 Variable* Parser::PatternRewriter::CreateTemp(Expression* value) { | |
arv (Not doing code reviews)
2015/05/18 14:36:20
CreateTempVar maybe?
Dmitry Lomov (no reviews)
2015/05/18 17:31:22
Done.
| |
211 auto temp = TemporaryDeclarationScope()->NewTemporary( | |
212 ast_value_factory()->empty_string()); | |
213 auto assignment = | |
214 factory()->NewAssignment(Token::ASSIGN, factory()->NewVariableProxy(temp), | |
215 value, RelocInfo::kNoPosition); | |
216 | |
217 block_->AddStatement( | |
218 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), | |
219 zone()); | |
220 return temp; | |
221 } | |
222 | |
223 | |
210 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern) { | 224 void Parser::PatternRewriter::VisitObjectLiteral(ObjectLiteral* pattern) { |
211 auto temp = descriptor_->declaration_scope->NewTemporary( | 225 auto temp = CreateTemp(current_value_); |
212 ast_value_factory()->empty_string()); | |
213 auto assignment = | |
214 factory()->NewAssignment(Token::ASSIGN, factory()->NewVariableProxy(temp), | |
215 current_value_, RelocInfo::kNoPosition); | |
216 | |
217 block_->AddStatement( | |
218 factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition), | |
219 zone()); | |
220 block_->AddStatement(descriptor_->parser->BuildAssertIsCoercible(temp), | 226 block_->AddStatement(descriptor_->parser->BuildAssertIsCoercible(temp), |
221 zone()); | 227 zone()); |
222 | 228 |
223 for (ObjectLiteralProperty* property : *pattern->properties()) { | 229 for (ObjectLiteralProperty* property : *pattern->properties()) { |
224 // TODO(dslomov): computed property names. | 230 // TODO(dslomov): computed property names. |
225 RecurseIntoSubpattern( | 231 RecurseIntoSubpattern( |
226 property->value(), | 232 property->value(), |
227 factory()->NewProperty(factory()->NewVariableProxy(temp), | 233 factory()->NewProperty(factory()->NewVariableProxy(temp), |
228 property->key(), RelocInfo::kNoPosition)); | 234 property->key(), RelocInfo::kNoPosition)); |
229 } | 235 } |
230 } | 236 } |
231 | 237 |
232 | 238 |
233 void Parser::PatternRewriter::VisitArrayLiteral(ArrayLiteral* node) { | 239 void Parser::PatternRewriter::VisitArrayLiteral(ArrayLiteral* node) { |
234 // TODO(dslomov): implement. | 240 // TODO(dslomov): implement. |
235 } | 241 } |
236 | 242 |
237 | 243 |
238 void Parser::PatternRewriter::VisitAssignment(Assignment* node) { | 244 void Parser::PatternRewriter::VisitAssignment(Assignment* node) { |
239 // TODO(dslomov): implement. | 245 DCHECK(node->op() == Token::ASSIGN); |
arv (Not doing code reviews)
2015/05/18 14:36:20
Maybe add a comment explaining the desugaring
l
Dmitry Lomov (no reviews)
2015/05/18 17:31:22
Done.
| |
246 auto temp = CreateTemp(current_value_); | |
247 Expression* is_undefined = factory()->NewCompareOperation( | |
248 Token::EQ_STRICT, factory()->NewVariableProxy(temp), | |
249 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition), | |
250 RelocInfo::kNoPosition); | |
251 Expression* value = factory()->NewConditional( | |
252 is_undefined, node->value(), factory()->NewVariableProxy(temp), | |
253 RelocInfo::kNoPosition); | |
254 RecurseIntoSubpattern(node->target(), value); | |
240 } | 255 } |
241 | 256 |
242 | 257 |
243 void Parser::PatternRewriter::VisitSpread(Spread* node) { | 258 void Parser::PatternRewriter::VisitSpread(Spread* node) { |
244 // TODO(dslomov): implement. | 259 // TODO(dslomov): implement. |
245 } | 260 } |
246 | 261 |
247 | 262 |
248 // =============== UNREACHABLE ============================= | 263 // =============== UNREACHABLE ============================= |
249 | 264 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 NOT_A_PATTERN(TryFinallyStatement) | 306 NOT_A_PATTERN(TryFinallyStatement) |
292 NOT_A_PATTERN(UnaryOperation) | 307 NOT_A_PATTERN(UnaryOperation) |
293 NOT_A_PATTERN(VariableDeclaration) | 308 NOT_A_PATTERN(VariableDeclaration) |
294 NOT_A_PATTERN(WhileStatement) | 309 NOT_A_PATTERN(WhileStatement) |
295 NOT_A_PATTERN(WithStatement) | 310 NOT_A_PATTERN(WithStatement) |
296 NOT_A_PATTERN(Yield) | 311 NOT_A_PATTERN(Yield) |
297 | 312 |
298 #undef NOT_A_PATTERN | 313 #undef NOT_A_PATTERN |
299 } | 314 } |
300 } // namespace v8::internal | 315 } // namespace v8::internal |
OLD | NEW |