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

Unified Diff: pkg/compiler/lib/src/constant_system_dart.dart

Issue 1559233002: WIP: Compute constant expressions in resolution. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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: pkg/compiler/lib/src/constant_system_dart.dart
diff --git a/pkg/compiler/lib/src/constant_system_dart.dart b/pkg/compiler/lib/src/constant_system_dart.dart
index 4a15ac9aff7cba10487fe95cb9a8086619ee39ea..25adefb1f6060d04db817a7aaf8466489132746b 100644
--- a/pkg/compiler/lib/src/constant_system_dart.dart
+++ b/pkg/compiler/lib/src/constant_system_dart.dart
@@ -9,6 +9,9 @@ import 'compiler.dart' show
import 'constants/constant_system.dart';
import 'constants/values.dart';
import 'dart_types.dart';
+import 'elements/elements.dart' show
+ ClassElement,
+ FieldElement;
import 'tree/tree.dart' show
DartString;
@@ -319,6 +322,22 @@ class EqualsOperation implements BinaryOperation {
apply(left, right) => left == right;
}
+class NotEqualsOperation implements BinaryOperation {
+ final String name = '!=';
+ const NotEqualsOperation();
+
+ @override
+ ConstantValue fold(ConstantValue left, ConstantValue right) {
+ BoolConstantValue result = const EqualsOperation().fold(left, right);
+ if (result != null) {
+ result = result.negate();
+ }
+ return result;
+ }
+
+ apply(left, right) => left != right;
+}
+
class IdentityOperation implements BinaryOperation {
final String name = '===';
const IdentityOperation();
@@ -388,6 +407,7 @@ class DartConstantSystem extends ConstantSystem {
final multiply = const MultiplyOperation();
final negate = const NegateOperation();
final not = const NotOperation();
+ final notEqual = const NotEqualsOperation();
final shiftLeft = const ShiftLeftOperation();
final shiftRight = const ShiftRightOperation();
final subtract = const SubtractOperation();
@@ -437,6 +457,20 @@ class DartConstantSystem extends ConstantSystem {
compiler.backend.typeImplementation.computeType(compiler.resolution));
}
+ @override
+ ConstantValue createSymbol(Compiler compiler, String text) {
+ // TODO(johnniwinther): Create a backend agnostic value.
+ InterfaceType type = compiler.symbolClass.rawType;
+ ConstantValue argument = createString(new DartString.literal(text));
+ Map<FieldElement, ConstantValue> fields = <FieldElement, ConstantValue>{};
+ compiler.symbolImplementationClass.forEachInstanceField(
+ (ClassElement enclosingClass, FieldElement field) {
+ fields[field] = argument;
+ });
+ assert(fields.length == 1);
+ return new ConstructedConstantValue(type, fields);
+ }
+
bool isInt(ConstantValue constant) => constant.isInt;
bool isDouble(ConstantValue constant) => constant.isDouble;
bool isString(ConstantValue constant) => constant.isString;
« no previous file with comments | « pkg/compiler/lib/src/compile_time_constants.dart ('k') | pkg/compiler/lib/src/constants/constant_system.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698