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

Unified Diff: sdk/lib/_internal/compiler/implementation/constants.dart

Issue 574683002: Use ConstExp for storing constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove ConstExpBuilder. Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/constants.dart
diff --git a/sdk/lib/_internal/compiler/implementation/constants.dart b/sdk/lib/_internal/compiler/implementation/constants.dart
index cc7d11dcc84136039425005edd85c8b562194ca7..b16c90033b844ba7ec0ae5287ba94f5e659b8b71 100644
--- a/sdk/lib/_internal/compiler/implementation/constants.dart
+++ b/sdk/lib/_internal/compiler/implementation/constants.dart
@@ -105,10 +105,14 @@ abstract class PrimitiveConstant extends Constant {
int get hashCode => throw new UnsupportedError('PrimitiveConstant.hashCode');
- String toString() => value.toString();
+ String toString() => toSyntax();
// Primitive constants don't have dependencies.
List<Constant> getDependencies() => const <Constant>[];
DartString toDartString();
+
+ /// This value in Dart syntax.
+ // TODO(johnniwinther): Move this to [Constant].
+ String toSyntax() => value.toString();
sigurdm 2014/09/17 10:29:41 maybe call it `unparse` or something similar. `toS
Johnni Winther 2014/09/17 12:20:39 Done.
}
class NullConstant extends PrimitiveConstant {
@@ -341,8 +345,11 @@ class StringConstant extends PrimitiveConstant {
accept(ConstantVisitor visitor) => visitor.visitString(this);
+ // TODO(johnniwinther): Ensure correct escaping.
+ String toSyntax() => '"${value.slowToString()}"';
+
String toString() {
- return 'StringConstant("${value.slowToString()}")';
+ return 'StringConstant(${toSyntax()})';
}
}
@@ -569,17 +576,14 @@ class ConstructedConstant extends ObjectConstant {
final List<Constant> fields;
final int hashCode;
- ConstructedConstant(DartType type, List<Constant> fields,
- {this.isLiteralSymbol: false})
+ ConstructedConstant(DartType type, List<Constant> fields)
: this.fields = fields,
hashCode = computeHash(type, fields),
super(type) {
assert(type != null);
}
- bool get isConstructedObject => true;
- /// True if this constant is constructed as a literal symbol.
- final bool isLiteralSymbol;
+ bool get isConstructedObject => true;
static int computeHash(DartType type, List<Constant> fields) {
// TODO(floitsch): create a better hash.

Powered by Google App Engine
This is Rietveld 408576698