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

Side by Side Diff: pkg/compiler/lib/src/constant_system_dart.dart

Issue 2864363002: Remove DartString from constants. (Closed)
Patch Set: Remove toDartString Created 3 years, 7 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 unified diff | Download patch
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 library dart2js.constant_system.dart; 5 library dart2js.constant_system.dart;
6 6
7 import 'constants/constant_system.dart'; 7 import 'constants/constant_system.dart';
8 import 'constants/values.dart'; 8 import 'constants/values.dart';
9 import 'common_elements.dart' show CommonElements; 9 import 'common_elements.dart' show CommonElements;
10 import 'elements/types.dart'; 10 import 'elements/types.dart';
11 import 'tree/dartstring.dart' show DartString;
12 11
13 const DART_CONSTANT_SYSTEM = const DartConstantSystem(); 12 const DART_CONSTANT_SYSTEM = const DartConstantSystem();
14 13
15 class BitNotOperation implements UnaryOperation { 14 class BitNotOperation implements UnaryOperation {
16 final String name = '~'; 15 final String name = '~';
17 const BitNotOperation(); 16 const BitNotOperation();
18 ConstantValue fold(ConstantValue constant) { 17 ConstantValue fold(ConstantValue constant) {
19 if (constant.isInt) { 18 if (constant.isInt) {
20 IntConstantValue intConstant = constant; 19 IntConstantValue intConstant = constant;
21 return DART_CONSTANT_SYSTEM.createInt(~intConstant.primitiveValue); 20 return DART_CONSTANT_SYSTEM.createInt(~intConstant.primitiveValue);
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 int result = leftInt.primitiveValue + rightInt.primitiveValue; 246 int result = leftInt.primitiveValue + rightInt.primitiveValue;
248 return DART_CONSTANT_SYSTEM.createInt(result); 247 return DART_CONSTANT_SYSTEM.createInt(result);
249 } else if (left.isNum && right.isNum) { 248 } else if (left.isNum && right.isNum) {
250 NumConstantValue leftNum = left; 249 NumConstantValue leftNum = left;
251 NumConstantValue rightNum = right; 250 NumConstantValue rightNum = right;
252 double result = leftNum.primitiveValue + rightNum.primitiveValue; 251 double result = leftNum.primitiveValue + rightNum.primitiveValue;
253 return DART_CONSTANT_SYSTEM.createDouble(result); 252 return DART_CONSTANT_SYSTEM.createDouble(result);
254 } else if (left.isString && right.isString) { 253 } else if (left.isString && right.isString) {
255 StringConstantValue leftString = left; 254 StringConstantValue leftString = left;
256 StringConstantValue rightString = right; 255 StringConstantValue rightString = right;
257 DartString result = new DartString.concat( 256 String result = leftString.primitiveValue + rightString.primitiveValue;
258 leftString.primitiveValue, rightString.primitiveValue);
259 return DART_CONSTANT_SYSTEM.createString(result); 257 return DART_CONSTANT_SYSTEM.createString(result);
260 } else { 258 } else {
261 return null; 259 return null;
262 } 260 }
263 } 261 }
264 262
265 apply(left, right) => left + right; 263 apply(left, right) => left + right;
266 } 264 }
267 265
268 abstract class RelationalNumOperation implements BinaryOperation { 266 abstract class RelationalNumOperation implements BinaryOperation {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 ConstantValue fold(ConstantValue left, ConstantValue right) => null; 360 ConstantValue fold(ConstantValue left, ConstantValue right) => null;
363 apply(left, right) => left.codeUnitAt(right); 361 apply(left, right) => left.codeUnitAt(right);
364 } 362 }
365 363
366 class CodeUnitAtRuntimeOperation extends CodeUnitAtOperation { 364 class CodeUnitAtRuntimeOperation extends CodeUnitAtOperation {
367 const CodeUnitAtRuntimeOperation(); 365 const CodeUnitAtRuntimeOperation();
368 IntConstantValue fold(ConstantValue left, ConstantValue right) { 366 IntConstantValue fold(ConstantValue left, ConstantValue right) {
369 if (left.isString && right.isInt) { 367 if (left.isString && right.isInt) {
370 StringConstantValue stringConstant = left; 368 StringConstantValue stringConstant = left;
371 IntConstantValue indexConstant = right; 369 IntConstantValue indexConstant = right;
372 DartString dartString = stringConstant.primitiveValue; 370 String string = stringConstant.primitiveValue;
373 int index = indexConstant.primitiveValue; 371 int index = indexConstant.primitiveValue;
374 if (index < 0 || index >= dartString.length) return null; 372 if (index < 0 || index >= string.length) return null;
375 String string = dartString.slowToString();
376 int value = string.codeUnitAt(index); 373 int value = string.codeUnitAt(index);
377 return DART_CONSTANT_SYSTEM.createInt(value); 374 return DART_CONSTANT_SYSTEM.createInt(value);
378 } 375 }
379 return null; 376 return null;
380 } 377 }
381 } 378 }
382 379
383 class UnfoldedUnaryOperation implements UnaryOperation { 380 class UnfoldedUnaryOperation implements UnaryOperation {
384 final String name; 381 final String name;
385 const UnfoldedUnaryOperation(this.name); 382 const UnfoldedUnaryOperation(this.name);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 421
425 const DartConstantSystem(); 422 const DartConstantSystem();
426 423
427 @override 424 @override
428 IntConstantValue createInt(int i) => new IntConstantValue(i); 425 IntConstantValue createInt(int i) => new IntConstantValue(i);
429 426
430 @override 427 @override
431 DoubleConstantValue createDouble(double d) => new DoubleConstantValue(d); 428 DoubleConstantValue createDouble(double d) => new DoubleConstantValue(d);
432 429
433 @override 430 @override
434 StringConstantValue createString(DartString string) { 431 StringConstantValue createString(String string) {
435 return new StringConstantValue(string); 432 return new StringConstantValue(string);
436 } 433 }
437 434
438 @override 435 @override
439 BoolConstantValue createBool(bool value) => new BoolConstantValue(value); 436 BoolConstantValue createBool(bool value) => new BoolConstantValue(value);
440 437
441 @override 438 @override
442 NullConstantValue createNull() => new NullConstantValue(); 439 NullConstantValue createNull() => new NullConstantValue();
443 440
444 @override 441 @override
(...skipping 21 matching lines...) Expand all
466 bool isInt(ConstantValue constant) => constant.isInt; 463 bool isInt(ConstantValue constant) => constant.isInt;
467 bool isDouble(ConstantValue constant) => constant.isDouble; 464 bool isDouble(ConstantValue constant) => constant.isDouble;
468 bool isString(ConstantValue constant) => constant.isString; 465 bool isString(ConstantValue constant) => constant.isString;
469 bool isBool(ConstantValue constant) => constant.isBool; 466 bool isBool(ConstantValue constant) => constant.isBool;
470 bool isNull(ConstantValue constant) => constant.isNull; 467 bool isNull(ConstantValue constant) => constant.isNull;
471 468
472 bool isSubtype(DartTypes types, DartType s, DartType t) { 469 bool isSubtype(DartTypes types, DartType s, DartType t) {
473 return types.isSubtype(s, t); 470 return types.isSubtype(s, t);
474 } 471 }
475 } 472 }
OLDNEW
« 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