OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart_backend; | 5 part of dart_backend; |
6 | 6 |
7 // TODO(ahe): This class is simply wrong. This backend should use | 7 // TODO(ahe): This class is simply wrong. This backend should use |
8 // elements when it can, not AST nodes. Perhaps a [Map<Element, | 8 // elements when it can, not AST nodes. Perhaps a [Map<Element, |
9 // TreeElements>] is what is needed. | 9 // TreeElements>] is what is needed. |
10 class ElementAst { | 10 class ElementAst { |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 class DartConstantTask extends ConstantCompilerTask | 417 class DartConstantTask extends ConstantCompilerTask |
418 implements BackendConstantEnvironment { | 418 implements BackendConstantEnvironment { |
419 final DartConstantCompiler constantCompiler; | 419 final DartConstantCompiler constantCompiler; |
420 | 420 |
421 DartConstantTask(Compiler compiler) | 421 DartConstantTask(Compiler compiler) |
422 : this.constantCompiler = new DartConstantCompiler(compiler), | 422 : this.constantCompiler = new DartConstantCompiler(compiler), |
423 super(compiler); | 423 super(compiler); |
424 | 424 |
425 String get name => 'ConstantHandler'; | 425 String get name => 'ConstantHandler'; |
426 | 426 |
| 427 @override |
| 428 ConstantSystem get constantSystem => constantCompiler.constantSystem; |
| 429 |
| 430 @override |
| 431 ConstantValue getConstantValue(ConstantExpression expression) { |
| 432 return constantCompiler.getConstantValue(expression); |
| 433 } |
| 434 |
| 435 @override |
| 436 ConstantValue getConstantValueForVariable(VariableElement element) { |
| 437 return constantCompiler.getConstantValueForVariable(element); |
| 438 } |
| 439 |
| 440 @override |
427 ConstantExpression getConstantForVariable(VariableElement element) { | 441 ConstantExpression getConstantForVariable(VariableElement element) { |
428 return constantCompiler.getConstantForVariable(element); | 442 return constantCompiler.getConstantForVariable(element); |
429 } | 443 } |
430 | 444 |
| 445 @override |
431 ConstantExpression getConstantForNode(Node node, TreeElements elements) { | 446 ConstantExpression getConstantForNode(Node node, TreeElements elements) { |
432 return constantCompiler.getConstantForNode(node, elements); | 447 return constantCompiler.getConstantForNode(node, elements); |
433 } | 448 } |
434 | 449 |
435 ConstantExpression getConstantForMetadata(MetadataAnnotation metadata) { | 450 @override |
436 return metadata.constant; | 451 ConstantValue getConstantValueForNode(Node node, TreeElements elements) { |
| 452 return getConstantValue( |
| 453 constantCompiler.getConstantForNode(node, elements)); |
437 } | 454 } |
438 | 455 |
| 456 @override |
| 457 ConstantValue getConstantValueForMetadata(MetadataAnnotation metadata) { |
| 458 return getConstantValue(metadata.constant); |
| 459 } |
| 460 |
| 461 @override |
439 ConstantExpression compileConstant(VariableElement element) { | 462 ConstantExpression compileConstant(VariableElement element) { |
440 return measure(() { | 463 return measure(() { |
441 return constantCompiler.compileConstant(element); | 464 return constantCompiler.compileConstant(element); |
442 }); | 465 }); |
443 } | 466 } |
444 | 467 |
445 void compileVariable(VariableElement element) { | 468 void compileVariable(VariableElement element) { |
446 measure(() { | 469 measure(() { |
447 constantCompiler.compileVariable(element); | 470 constantCompiler.compileVariable(element); |
448 }); | 471 }); |
449 } | 472 } |
450 | 473 |
451 ConstantExpression compileNode(Node node, TreeElements elements, | 474 @override |
452 {bool enforceConst: true}) { | 475 ConstantExpression compileNode( |
| 476 Node node, |
| 477 TreeElements elements, |
| 478 {bool enforceConst: true}) { |
453 return measure(() { | 479 return measure(() { |
454 return constantCompiler.compileNodeWithDefinitions(node, elements, | 480 return constantCompiler.compileNodeWithDefinitions(node, elements, |
455 isConst: enforceConst); | 481 isConst: enforceConst); |
456 }); | 482 }); |
457 } | 483 } |
458 | 484 |
459 ConstantExpression compileMetadata(MetadataAnnotation metadata, | 485 @override |
460 Node node, | 486 ConstantExpression compileMetadata( |
461 TreeElements elements) { | 487 MetadataAnnotation metadata, |
| 488 Node node, |
| 489 TreeElements elements) { |
462 return measure(() { | 490 return measure(() { |
463 return constantCompiler.compileMetadata(metadata, node, elements); | 491 return constantCompiler.compileMetadata(metadata, node, elements); |
464 }); | 492 }); |
465 } | 493 } |
| 494 |
| 495 // TODO(johnniwinther): Remove this when values are computed from the |
| 496 // expressions. |
| 497 @override |
| 498 void copyConstantValues(DartConstantTask task) { |
| 499 constantCompiler.constantValueMap.addAll( |
| 500 task.constantCompiler.constantValueMap); |
| 501 } |
466 } | 502 } |
467 | 503 |
468 abstract class ElementAstCreationContext { | 504 abstract class ElementAstCreationContext { |
469 DartTypes get dartTypes; | 505 DartTypes get dartTypes; |
470 ConstantSystem get constantSystem; | 506 ConstantSystem get constantSystem; |
471 InternalErrorFunction get internalError; | 507 InternalErrorFunction get internalError; |
472 } | 508 } |
473 | 509 |
474 class _ElementAstCreationContext implements ElementAstCreationContext { | 510 class _ElementAstCreationContext implements ElementAstCreationContext { |
475 final Compiler compiler; | 511 final Compiler compiler; |
476 final ConstantSystem constantSystem; | 512 final ConstantSystem constantSystem; |
477 | 513 |
478 _ElementAstCreationContext(this.compiler, this.constantSystem); | 514 _ElementAstCreationContext(this.compiler, this.constantSystem); |
479 | 515 |
480 DartTypes get dartTypes => compiler.types; | 516 DartTypes get dartTypes => compiler.types; |
481 | 517 |
482 InternalErrorFunction get internalError => compiler.internalError; | 518 InternalErrorFunction get internalError => compiler.internalError; |
483 } | 519 } |
OLD | NEW |