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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/constant_system_dart.dart

Issue 664283004: Revert "Constant fold charCodeAt via constant system" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 dart2js; 5 part of dart2js;
6 6
7 const DART_CONSTANT_SYSTEM = const DartConstantSystem(); 7 const DART_CONSTANT_SYSTEM = const DartConstantSystem();
8 8
9 class BitNotOperation implements UnaryOperation { 9 class BitNotOperation implements UnaryOperation {
10 final String name = '~'; 10 final String name = '~';
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 BoolConstantValue fold(ConstantValue left, ConstantValue right) { 311 BoolConstantValue fold(ConstantValue left, ConstantValue right) {
312 // In order to preserve runtime semantics which says that NaN !== NaN don't 312 // In order to preserve runtime semantics which says that NaN !== NaN don't
313 // constant fold NaN === NaN. Otherwise the output depends on inlined 313 // constant fold NaN === NaN. Otherwise the output depends on inlined
314 // variables and other optimizations. 314 // variables and other optimizations.
315 if (left.isNaN && right.isNaN) return null; 315 if (left.isNaN && right.isNaN) return null;
316 return DART_CONSTANT_SYSTEM.createBool(left == right); 316 return DART_CONSTANT_SYSTEM.createBool(left == right);
317 } 317 }
318 apply(left, right) => identical(left, right); 318 apply(left, right) => identical(left, right);
319 } 319 }
320 320
321 abstract class CodeUnitAtOperation implements BinaryOperation {
322 final String name = 'charCodeAt';
323 const CodeUnitAtOperation();
324 apply(left, right) => left.codeUnitAt(right);
325 }
326
327 class CodeUnitAtConstantOperation extends CodeUnitAtOperation {
328 const CodeUnitAtConstantOperation();
329 ConstantValue fold(ConstantValue left, ConstantValue right) {
330 // 'a'.codeUnitAt(0) is not a constant expression.
331 return null;
332 }
333 }
334
335 class CodeUnitAtRuntimeOperation extends CodeUnitAtOperation {
336 const CodeUnitAtRuntimeOperation();
337 IntConstantValue fold(ConstantValue left, ConstantValue right) {
338 if (left.isString && right.isInt) {
339 DartString dartString = left.primitiveValue;
340 int index = right.primitiveValue;
341 if (index < 0 || index >= dartString.length) return null;
342 String string = dartString.slowToString();
343 int value = string.codeUnitAt(index);
344 return DART_CONSTANT_SYSTEM.createInt(value);
345 }
346 return null;
347 }
348 }
349
350 /** 321 /**
351 * A constant system implementing the Dart semantics. This system relies on 322 * A constant system implementing the Dart semantics. This system relies on
352 * the underlying runtime-system. That is, if dart2js is run in an environment 323 * the underlying runtime-system. That is, if dart2js is run in an environment
353 * that doesn't correctly implement Dart's semantics this constant system will 324 * that doesn't correctly implement Dart's semantics this constant system will
354 * not return the correct values. 325 * not return the correct values.
355 */ 326 */
356 class DartConstantSystem extends ConstantSystem { 327 class DartConstantSystem extends ConstantSystem {
357 final add = const AddOperation(); 328 final add = const AddOperation();
358 final bitAnd = const BitAndOperation(); 329 final bitAnd = const BitAndOperation();
359 final bitNot = const BitNotOperation(); 330 final bitNot = const BitNotOperation();
360 final bitOr = const BitOrOperation(); 331 final bitOr = const BitOrOperation();
361 final bitXor = const BitXorOperation(); 332 final bitXor = const BitXorOperation();
362 final booleanAnd = const BooleanAndOperation(); 333 final booleanAnd = const BooleanAndOperation();
363 final booleanOr = const BooleanOrOperation(); 334 final booleanOr = const BooleanOrOperation();
364 final divide = const DivideOperation(); 335 final divide = const DivideOperation();
365 final equal = const EqualsOperation(); 336 final equal = const EqualsOperation();
366 final greaterEqual = const GreaterEqualOperation(); 337 final greaterEqual = const GreaterEqualOperation();
367 final greater = const GreaterOperation(); 338 final greater = const GreaterOperation();
368 final identity = const IdentityOperation(); 339 final identity = const IdentityOperation();
369 final lessEqual = const LessEqualOperation(); 340 final lessEqual = const LessEqualOperation();
370 final less = const LessOperation(); 341 final less = const LessOperation();
371 final modulo = const ModuloOperation(); 342 final modulo = const ModuloOperation();
372 final multiply = const MultiplyOperation(); 343 final multiply = const MultiplyOperation();
373 final negate = const NegateOperation(); 344 final negate = const NegateOperation();
374 final not = const NotOperation(); 345 final not = const NotOperation();
375 final shiftLeft = const ShiftLeftOperation(); 346 final shiftLeft = const ShiftLeftOperation();
376 final shiftRight = const ShiftRightOperation(); 347 final shiftRight = const ShiftRightOperation();
377 final subtract = const SubtractOperation(); 348 final subtract = const SubtractOperation();
378 final truncatingDivide = const TruncatingDivideOperation(); 349 final truncatingDivide = const TruncatingDivideOperation();
379 final codeUnitAt = const CodeUnitAtConstantOperation();
380 350
381 const DartConstantSystem(); 351 const DartConstantSystem();
382 352
383 IntConstantValue createInt(int i) => new IntConstantValue(i); 353 IntConstantValue createInt(int i) => new IntConstantValue(i);
384 DoubleConstantValue createDouble(double d) => new DoubleConstantValue(d); 354 DoubleConstantValue createDouble(double d) => new DoubleConstantValue(d);
385 StringConstantValue createString(DartString string) { 355 StringConstantValue createString(DartString string) {
386 return new StringConstantValue(string); 356 return new StringConstantValue(string);
387 } 357 }
388 BoolConstantValue createBool(bool value) => new BoolConstantValue(value); 358 BoolConstantValue createBool(bool value) => new BoolConstantValue(value);
389 NullConstantValue createNull() => new NullConstantValue(); 359 NullConstantValue createNull() => new NullConstantValue();
390 MapConstantValue createMap(Compiler compiler, 360 MapConstantValue createMap(Compiler compiler,
391 InterfaceType type, 361 InterfaceType type,
392 List<ConstantValue> keys, 362 List<ConstantValue> keys,
393 List<ConstantValue> values) { 363 List<ConstantValue> values) {
394 return new MapConstantValue(type, keys, values); 364 return new MapConstantValue(type, keys, values);
395 } 365 }
396 366
397 bool isInt(ConstantValue constant) => constant.isInt; 367 bool isInt(ConstantValue constant) => constant.isInt;
398 bool isDouble(ConstantValue constant) => constant.isDouble; 368 bool isDouble(ConstantValue constant) => constant.isDouble;
399 bool isString(ConstantValue constant) => constant.isString; 369 bool isString(ConstantValue constant) => constant.isString;
400 bool isBool(ConstantValue constant) => constant.isBool; 370 bool isBool(ConstantValue constant) => constant.isBool;
401 bool isNull(ConstantValue constant) => constant.isNull; 371 bool isNull(ConstantValue constant) => constant.isNull;
402 372
403 bool isSubtype(Compiler compiler, DartType s, DartType t) { 373 bool isSubtype(Compiler compiler, DartType s, DartType t) {
404 return compiler.types.isSubtype(s, t); 374 return compiler.types.isSubtype(s, t);
405 } 375 }
406 } 376 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698