Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
| 6 * Represents a meta-value for code generation. | 6 * Represents a meta-value for code generation. |
| 7 */ | 7 */ |
| 8 class Value { | 8 class Value { |
| 9 /** The [Type] of the [Value]. */ | 9 /** The [Type] of the [Value]. */ |
| 10 Type type; | 10 Type type; |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 return new EvaluatedValue._internal(type, actualValue, | 539 return new EvaluatedValue._internal(type, actualValue, |
| 540 canonicalCode, span, codeWithComments(canonicalCode, span)); | 540 canonicalCode, span, codeWithComments(canonicalCode, span)); |
| 541 } | 541 } |
| 542 | 542 |
| 543 EvaluatedValue._internal(Type type, this.actualValue, this.canonicalCode, | 543 EvaluatedValue._internal(Type type, this.actualValue, this.canonicalCode, |
| 544 SourceSpan span, String code) | 544 SourceSpan span, String code) |
| 545 : super(type, code, span, false); | 545 : super(type, code, span, false); |
| 546 | 546 |
| 547 static String codeWithComments(String canonicalCode, SourceSpan span) { | 547 static String codeWithComments(String canonicalCode, SourceSpan span) { |
| 548 return (span != null && span.text != canonicalCode) | 548 return (span != null && span.text != canonicalCode) |
| 549 ? '$canonicalCode/*${span.text}*/' : canonicalCode; | 549 ? '$canonicalCode/*${_escapeForComment(span.text)}*/' : canonicalCode; |
| 550 } | 550 } |
| 551 } | 551 } |
| 552 | 552 |
| 553 /** An evaluated constant list expression. */ | 553 /** An evaluated constant list expression. */ |
| 554 class ConstListValue extends EvaluatedValue { | 554 class ConstListValue extends EvaluatedValue { |
| 555 List<EvaluatedValue> values; | 555 List<EvaluatedValue> values; |
| 556 | 556 |
| 557 factory ConstListValue(Type type, List<EvaluatedValue> values, | 557 factory ConstListValue(Type type, List<EvaluatedValue> values, |
| 558 String actualValue, String canonicalCode, SourceSpan span) { | 558 String actualValue, String canonicalCode, SourceSpan span) { |
| 559 return new ConstListValue._internal(type, values, actualValue, | 559 return new ConstListValue._internal(type, values, actualValue, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 646 factory GlobalValue.fromStatic(field, Value exp, dependencies) { | 646 factory GlobalValue.fromStatic(field, Value exp, dependencies) { |
| 647 var code = (exp.isConst ? exp.canonicalCode : exp.code); | 647 var code = (exp.isConst ? exp.canonicalCode : exp.code); |
| 648 var codeWithComment = '$code/*${field.declaringType.name}.${field.name}*/'; | 648 var codeWithComment = '$code/*${field.declaringType.name}.${field.name}*/'; |
| 649 return new GlobalValue( | 649 return new GlobalValue( |
| 650 exp.type, codeWithComment, field.isFinal, field, null, exp, | 650 exp.type, codeWithComment, field.isFinal, field, null, exp, |
| 651 code, exp.span, dependencies.filter((d) => d is GlobalValue)); | 651 code, exp.span, dependencies.filter((d) => d is GlobalValue)); |
| 652 } | 652 } |
| 653 | 653 |
| 654 factory GlobalValue.fromConst(uniqueId, Value exp, dependencies) { | 654 factory GlobalValue.fromConst(uniqueId, Value exp, dependencies) { |
| 655 var name = "const\$$uniqueId"; | 655 var name = "const\$$uniqueId"; |
| 656 var codeWithComment = "$name/*${exp.span.text}*/"; | 656 var codeWithComment = "$name/*${_escapeForComment(exp.span.text)}*/"; |
| 657 return new GlobalValue( | 657 return new GlobalValue( |
| 658 exp.type, codeWithComment, true, null, name, exp, name, | 658 exp.type, codeWithComment, true, null, name, exp, name, |
| 659 exp.span, | 659 exp.span, |
| 660 dependencies.filter((d) => d is GlobalValue)); | 660 dependencies.filter((d) => d is GlobalValue)); |
| 661 } | 661 } |
| 662 | 662 |
| 663 GlobalValue(Type type, String code, bool isConst, | 663 GlobalValue(Type type, String code, bool isConst, |
| 664 this.field, this.name, this.exp, this.canonicalCode, | 664 this.field, this.name, this.exp, this.canonicalCode, |
| 665 SourceSpan span, List<GlobalValue> _dependencies) | 665 SourceSpan span, List<GlobalValue> _dependencies) |
| 666 : super(type, code, span, !isConst), dependencies = [] { | 666 : super(type, code, span, !isConst), dependencies = [] { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 // Then look for members in my library. | 731 // Then look for members in my library. |
| 732 member = home.library.lookup(name, span); | 732 member = home.library.lookup(name, span); |
| 733 if (member != null) { | 733 if (member != null) { |
| 734 return member; | 734 return member; |
| 735 } | 735 } |
| 736 | 736 |
| 737 _ensureCode(); | 737 _ensureCode(); |
| 738 return null; | 738 return null; |
| 739 } | 739 } |
| 740 } | 740 } |
| 741 | |
| 742 String _escapeForComment(String text) { | |
| 743 return text.replaceAll('/*', '/ *').replaceAll('*/', '* /'); | |
|
jimhug
2011/12/02 00:16:00
I think you need two more spaces to make this bull
Jennifer Messerly
2011/12/02 00:24:23
with the double replace,
| |
| 744 } | |
| OLD | NEW |