| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.constants.expressions; | 5 library dart2js.constants.expressions; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../constants/constant_system.dart'; | 8 import '../constants/constant_system.dart'; |
| 9 import '../common_elements.dart'; | 9 import '../common_elements.dart'; |
| 10 import '../elements/types.dart'; | 10 import '../elements/types.dart'; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 int get precedence => 16; | 65 int get precedence => 16; |
| 66 | 66 |
| 67 accept(ConstantExpressionVisitor visitor, [context]); | 67 accept(ConstantExpressionVisitor visitor, [context]); |
| 68 | 68 |
| 69 /// Substitute free variables using arguments. | 69 /// Substitute free variables using arguments. |
| 70 ConstantExpression apply(NormalizedArguments arguments) => this; | 70 ConstantExpression apply(NormalizedArguments arguments) => this; |
| 71 | 71 |
| 72 /// Compute the [ConstantValue] for this expression using the [environment] | 72 /// Compute the [ConstantValue] for this expression using the [environment] |
| 73 /// and the [constantSystem]. | 73 /// and the [constantSystem]. |
| 74 ConstantValue evaluate( | 74 ConstantValue evaluate( |
| 75 Environment environment, ConstantSystem constantSystem); | 75 EvaluationEnvironment environment, ConstantSystem constantSystem); |
| 76 | 76 |
| 77 /// Returns the type of this constant expression, if it is independent of the | 77 /// Returns the type of this constant expression, if it is independent of the |
| 78 /// environment values. | 78 /// environment values. |
| 79 DartType getKnownType(CommonElements commonElements) => null; | 79 DartType getKnownType(CommonElements commonElements) => null; |
| 80 | 80 |
| 81 /// Returns a text string resembling the Dart code creating this constant. | 81 /// Returns a text string resembling the Dart code creating this constant. |
| 82 String toDartText() { | 82 String toDartText() { |
| 83 ConstExpPrinter printer = new ConstExpPrinter(); | 83 ConstExpPrinter printer = new ConstExpPrinter(); |
| 84 accept(printer); | 84 accept(printer); |
| 85 return printer.toString(); | 85 return printer.toString(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 /// A synthetic constant used to recover from errors. | 135 /// A synthetic constant used to recover from errors. |
| 136 class ErroneousConstantExpression extends ConstantExpression { | 136 class ErroneousConstantExpression extends ConstantExpression { |
| 137 ConstantExpressionKind get kind => ConstantExpressionKind.ERRONEOUS; | 137 ConstantExpressionKind get kind => ConstantExpressionKind.ERRONEOUS; |
| 138 | 138 |
| 139 accept(ConstantExpressionVisitor visitor, [context]) { | 139 accept(ConstantExpressionVisitor visitor, [context]) { |
| 140 // Do nothing. This is an error. | 140 // Do nothing. This is an error. |
| 141 } | 141 } |
| 142 | 142 |
| 143 @override | 143 @override |
| 144 ConstantValue evaluate( | 144 ConstantValue evaluate( |
| 145 Environment environment, ConstantSystem constantSystem) { | 145 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 146 // TODO(johnniwinther): Use non-constant values for errors. | 146 // TODO(johnniwinther): Use non-constant values for errors. |
| 147 return new NonConstantValue(); | 147 return new NonConstantValue(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 @override | 150 @override |
| 151 void _createStructuredText(StringBuffer sb) { | 151 void _createStructuredText(StringBuffer sb) { |
| 152 sb.write('Erroneous()'); | 152 sb.write('Erroneous()'); |
| 153 } | 153 } |
| 154 | 154 |
| 155 @override | 155 @override |
| 156 int _computeHashCode() => 13; | 156 int _computeHashCode() => 13; |
| 157 | 157 |
| 158 @override | 158 @override |
| 159 bool _equals(ErroneousConstantExpression other) => true; | 159 bool _equals(ErroneousConstantExpression other) => true; |
| 160 } | 160 } |
| 161 | 161 |
| 162 // TODO(johnniwinther): Avoid the need for this class. | 162 // TODO(johnniwinther): Avoid the need for this class. |
| 163 class SyntheticConstantExpression extends ConstantExpression { | 163 class SyntheticConstantExpression extends ConstantExpression { |
| 164 final SyntheticConstantValue value; | 164 final SyntheticConstantValue value; |
| 165 | 165 |
| 166 SyntheticConstantExpression(this.value); | 166 SyntheticConstantExpression(this.value); |
| 167 | 167 |
| 168 @override | 168 @override |
| 169 ConstantValue evaluate( | 169 ConstantValue evaluate( |
| 170 Environment environment, ConstantSystem constantSystem) { | 170 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 171 return value; | 171 return value; |
| 172 } | 172 } |
| 173 | 173 |
| 174 @override | 174 @override |
| 175 void _createStructuredText(StringBuffer sb) { | 175 void _createStructuredText(StringBuffer sb) { |
| 176 sb.write('Synthetic(value=${value.toStructuredText()})'); | 176 sb.write('Synthetic(value=${value.toStructuredText()})'); |
| 177 } | 177 } |
| 178 | 178 |
| 179 @override | 179 @override |
| 180 int _computeHashCode() => 13 * value.hashCode; | 180 int _computeHashCode() => 13 * value.hashCode; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 return visitor.visitBool(this, context); | 212 return visitor.visitBool(this, context); |
| 213 } | 213 } |
| 214 | 214 |
| 215 @override | 215 @override |
| 216 void _createStructuredText(StringBuffer sb) { | 216 void _createStructuredText(StringBuffer sb) { |
| 217 sb.write('Bool(value=${primitiveValue})'); | 217 sb.write('Bool(value=${primitiveValue})'); |
| 218 } | 218 } |
| 219 | 219 |
| 220 @override | 220 @override |
| 221 ConstantValue evaluate( | 221 ConstantValue evaluate( |
| 222 Environment environment, ConstantSystem constantSystem) { | 222 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 223 return constantSystem.createBool(primitiveValue); | 223 return constantSystem.createBool(primitiveValue); |
| 224 } | 224 } |
| 225 | 225 |
| 226 @override | 226 @override |
| 227 int _computeHashCode() => 13 * primitiveValue.hashCode; | 227 int _computeHashCode() => 13 * primitiveValue.hashCode; |
| 228 | 228 |
| 229 @override | 229 @override |
| 230 bool _equals(BoolConstantExpression other) { | 230 bool _equals(BoolConstantExpression other) { |
| 231 return primitiveValue == other.primitiveValue; | 231 return primitiveValue == other.primitiveValue; |
| 232 } | 232 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 248 return visitor.visitInt(this, context); | 248 return visitor.visitInt(this, context); |
| 249 } | 249 } |
| 250 | 250 |
| 251 @override | 251 @override |
| 252 void _createStructuredText(StringBuffer sb) { | 252 void _createStructuredText(StringBuffer sb) { |
| 253 sb.write('Int(value=${primitiveValue})'); | 253 sb.write('Int(value=${primitiveValue})'); |
| 254 } | 254 } |
| 255 | 255 |
| 256 @override | 256 @override |
| 257 ConstantValue evaluate( | 257 ConstantValue evaluate( |
| 258 Environment environment, ConstantSystem constantSystem) { | 258 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 259 return constantSystem.createInt(primitiveValue); | 259 return constantSystem.createInt(primitiveValue); |
| 260 } | 260 } |
| 261 | 261 |
| 262 @override | 262 @override |
| 263 int _computeHashCode() => 17 * primitiveValue.hashCode; | 263 int _computeHashCode() => 17 * primitiveValue.hashCode; |
| 264 | 264 |
| 265 @override | 265 @override |
| 266 bool _equals(IntConstantExpression other) { | 266 bool _equals(IntConstantExpression other) { |
| 267 return primitiveValue == other.primitiveValue; | 267 return primitiveValue == other.primitiveValue; |
| 268 } | 268 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 284 return visitor.visitDouble(this, context); | 284 return visitor.visitDouble(this, context); |
| 285 } | 285 } |
| 286 | 286 |
| 287 @override | 287 @override |
| 288 void _createStructuredText(StringBuffer sb) { | 288 void _createStructuredText(StringBuffer sb) { |
| 289 sb.write('Double(value=${primitiveValue})'); | 289 sb.write('Double(value=${primitiveValue})'); |
| 290 } | 290 } |
| 291 | 291 |
| 292 @override | 292 @override |
| 293 ConstantValue evaluate( | 293 ConstantValue evaluate( |
| 294 Environment environment, ConstantSystem constantSystem) { | 294 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 295 return constantSystem.createDouble(primitiveValue); | 295 return constantSystem.createDouble(primitiveValue); |
| 296 } | 296 } |
| 297 | 297 |
| 298 @override | 298 @override |
| 299 int _computeHashCode() => 19 * primitiveValue.hashCode; | 299 int _computeHashCode() => 19 * primitiveValue.hashCode; |
| 300 | 300 |
| 301 @override | 301 @override |
| 302 bool _equals(DoubleConstantExpression other) { | 302 bool _equals(DoubleConstantExpression other) { |
| 303 return primitiveValue == other.primitiveValue; | 303 return primitiveValue == other.primitiveValue; |
| 304 } | 304 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 320 return visitor.visitString(this, context); | 320 return visitor.visitString(this, context); |
| 321 } | 321 } |
| 322 | 322 |
| 323 @override | 323 @override |
| 324 void _createStructuredText(StringBuffer sb) { | 324 void _createStructuredText(StringBuffer sb) { |
| 325 sb.write('String(value=${primitiveValue})'); | 325 sb.write('String(value=${primitiveValue})'); |
| 326 } | 326 } |
| 327 | 327 |
| 328 @override | 328 @override |
| 329 ConstantValue evaluate( | 329 ConstantValue evaluate( |
| 330 Environment environment, ConstantSystem constantSystem) { | 330 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 331 return constantSystem.createString(new DartString.literal(primitiveValue)); | 331 return constantSystem.createString(new DartString.literal(primitiveValue)); |
| 332 } | 332 } |
| 333 | 333 |
| 334 @override | 334 @override |
| 335 int _computeHashCode() => 23 * primitiveValue.hashCode; | 335 int _computeHashCode() => 23 * primitiveValue.hashCode; |
| 336 | 336 |
| 337 @override | 337 @override |
| 338 bool _equals(StringConstantExpression other) { | 338 bool _equals(StringConstantExpression other) { |
| 339 return primitiveValue == other.primitiveValue; | 339 return primitiveValue == other.primitiveValue; |
| 340 } | 340 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 354 return visitor.visitNull(this, context); | 354 return visitor.visitNull(this, context); |
| 355 } | 355 } |
| 356 | 356 |
| 357 @override | 357 @override |
| 358 void _createStructuredText(StringBuffer sb) { | 358 void _createStructuredText(StringBuffer sb) { |
| 359 sb.write('Null()'); | 359 sb.write('Null()'); |
| 360 } | 360 } |
| 361 | 361 |
| 362 @override | 362 @override |
| 363 ConstantValue evaluate( | 363 ConstantValue evaluate( |
| 364 Environment environment, ConstantSystem constantSystem) { | 364 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 365 return constantSystem.createNull(); | 365 return constantSystem.createNull(); |
| 366 } | 366 } |
| 367 | 367 |
| 368 get primitiveValue => null; | 368 get primitiveValue => null; |
| 369 | 369 |
| 370 @override | 370 @override |
| 371 int _computeHashCode() => 29; | 371 int _computeHashCode() => 29; |
| 372 | 372 |
| 373 @override | 373 @override |
| 374 bool _equals(NullConstantExpression other) => true; | 374 bool _equals(NullConstantExpression other) => true; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 398 for (ConstantExpression value in values) { | 398 for (ConstantExpression value in values) { |
| 399 sb.write(delimiter); | 399 sb.write(delimiter); |
| 400 value._createStructuredText(sb); | 400 value._createStructuredText(sb); |
| 401 delimiter = ','; | 401 delimiter = ','; |
| 402 } | 402 } |
| 403 sb.write('])'); | 403 sb.write('])'); |
| 404 } | 404 } |
| 405 | 405 |
| 406 @override | 406 @override |
| 407 ConstantValue evaluate( | 407 ConstantValue evaluate( |
| 408 Environment environment, ConstantSystem constantSystem) { | 408 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 409 return constantSystem.createList(type, | 409 return constantSystem.createList(type, |
| 410 values.map((v) => v.evaluate(environment, constantSystem)).toList()); | 410 values.map((v) => v.evaluate(environment, constantSystem)).toList()); |
| 411 } | 411 } |
| 412 | 412 |
| 413 ConstantExpression apply(NormalizedArguments arguments) { | 413 ConstantExpression apply(NormalizedArguments arguments) { |
| 414 return new ListConstantExpression( | 414 return new ListConstantExpression( |
| 415 type, values.map((v) => v.apply(arguments)).toList()); | 415 type, values.map((v) => v.apply(arguments)).toList()); |
| 416 } | 416 } |
| 417 | 417 |
| 418 @override | 418 @override |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 } | 467 } |
| 468 keys[index]._createStructuredText(sb); | 468 keys[index]._createStructuredText(sb); |
| 469 sb.write('->'); | 469 sb.write('->'); |
| 470 values[index]._createStructuredText(sb); | 470 values[index]._createStructuredText(sb); |
| 471 } | 471 } |
| 472 sb.write('])'); | 472 sb.write('])'); |
| 473 } | 473 } |
| 474 | 474 |
| 475 @override | 475 @override |
| 476 ConstantValue evaluate( | 476 ConstantValue evaluate( |
| 477 Environment environment, ConstantSystem constantSystem) { | 477 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 478 Map<ConstantValue, ConstantValue> valueMap = | 478 Map<ConstantValue, ConstantValue> valueMap = |
| 479 <ConstantValue, ConstantValue>{}; | 479 <ConstantValue, ConstantValue>{}; |
| 480 for (int index = 0; index < keys.length; index++) { | 480 for (int index = 0; index < keys.length; index++) { |
| 481 ConstantValue key = keys[index].evaluate(environment, constantSystem); | 481 ConstantValue key = keys[index].evaluate(environment, constantSystem); |
| 482 ConstantValue value = values[index].evaluate(environment, constantSystem); | 482 ConstantValue value = values[index].evaluate(environment, constantSystem); |
| 483 valueMap[key] = value; | 483 valueMap[key] = value; |
| 484 } | 484 } |
| 485 return constantSystem.createMap(environment.commonElements, type, | 485 return constantSystem.createMap(environment.commonElements, type, |
| 486 valueMap.keys.toList(), valueMap.values.toList()); | 486 valueMap.keys.toList(), valueMap.values.toList()); |
| 487 } | 487 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 String delimiter = ''; | 551 String delimiter = ''; |
| 552 for (ConstantExpression value in arguments) { | 552 for (ConstantExpression value in arguments) { |
| 553 sb.write(delimiter); | 553 sb.write(delimiter); |
| 554 value._createStructuredText(sb); | 554 value._createStructuredText(sb); |
| 555 delimiter = ','; | 555 delimiter = ','; |
| 556 } | 556 } |
| 557 sb.write('])'); | 557 sb.write('])'); |
| 558 } | 558 } |
| 559 | 559 |
| 560 Map<FieldEntity, ConstantExpression> computeInstanceFields( | 560 Map<FieldEntity, ConstantExpression> computeInstanceFields( |
| 561 Environment environment) { | 561 EvaluationEnvironment environment) { |
| 562 ConstantConstructor constantConstructor = | 562 ConstantConstructor constantConstructor = |
| 563 environment.getConstructorConstant(target); | 563 environment.getConstructorConstant(target); |
| 564 assert(invariant(target, constantConstructor != null, | 564 assert(invariant(target, constantConstructor != null, |
| 565 message: "No constant constructor computed for $target.")); | 565 message: "No constant constructor computed for $target.")); |
| 566 return constantConstructor.computeInstanceFields( | 566 return constantConstructor.computeInstanceFields( |
| 567 environment, arguments, callStructure); | 567 environment, arguments, callStructure); |
| 568 } | 568 } |
| 569 | 569 |
| 570 InterfaceType computeInstanceType(Environment environment) { | 570 InterfaceType computeInstanceType(EvaluationEnvironment environment) { |
| 571 return environment | 571 return environment |
| 572 .getConstructorConstant(target) | 572 .getConstructorConstant(target) |
| 573 .computeInstanceType(environment, type); | 573 .computeInstanceType(environment, type); |
| 574 } | 574 } |
| 575 | 575 |
| 576 ConstructedConstantExpression apply(NormalizedArguments arguments) { | 576 ConstructedConstantExpression apply(NormalizedArguments arguments) { |
| 577 return new ConstructedConstantExpression(type, target, callStructure, | 577 return new ConstructedConstantExpression(type, target, callStructure, |
| 578 this.arguments.map((a) => a.apply(arguments)).toList()); | 578 this.arguments.map((a) => a.apply(arguments)).toList()); |
| 579 } | 579 } |
| 580 | 580 |
| 581 @override | 581 @override |
| 582 ConstantValue evaluate( | 582 ConstantValue evaluate( |
| 583 Environment environment, ConstantSystem constantSystem) { | 583 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 584 Map<FieldEntity, ConstantValue> fieldValues = | 584 Map<FieldEntity, ConstantValue> fieldValues = |
| 585 <FieldEntity, ConstantValue>{}; | 585 <FieldEntity, ConstantValue>{}; |
| 586 computeInstanceFields(environment) | 586 computeInstanceFields(environment) |
| 587 .forEach((FieldEntity field, ConstantExpression constant) { | 587 .forEach((FieldEntity field, ConstantExpression constant) { |
| 588 fieldValues[field] = constant.evaluate(environment, constantSystem); | 588 fieldValues[field] = constant.evaluate(environment, constantSystem); |
| 589 }); | 589 }); |
| 590 return new ConstructedConstantValue( | 590 return new ConstructedConstantValue( |
| 591 computeInstanceType(environment), fieldValues); | 591 computeInstanceType(environment), fieldValues); |
| 592 } | 592 } |
| 593 | 593 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 sb.write('])'); | 645 sb.write('])'); |
| 646 } | 646 } |
| 647 | 647 |
| 648 ConstantExpression apply(NormalizedArguments arguments) { | 648 ConstantExpression apply(NormalizedArguments arguments) { |
| 649 return new ConcatenateConstantExpression( | 649 return new ConcatenateConstantExpression( |
| 650 expressions.map((a) => a.apply(arguments)).toList()); | 650 expressions.map((a) => a.apply(arguments)).toList()); |
| 651 } | 651 } |
| 652 | 652 |
| 653 @override | 653 @override |
| 654 ConstantValue evaluate( | 654 ConstantValue evaluate( |
| 655 Environment environment, ConstantSystem constantSystem) { | 655 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 656 DartString accumulator; | 656 DartString accumulator; |
| 657 for (ConstantExpression expression in expressions) { | 657 for (ConstantExpression expression in expressions) { |
| 658 ConstantValue value = expression.evaluate(environment, constantSystem); | 658 ConstantValue value = expression.evaluate(environment, constantSystem); |
| 659 DartString valueString; | 659 DartString valueString; |
| 660 if (value.isNum || value.isBool || value.isNull) { | 660 if (value.isNum || value.isBool || value.isNull) { |
| 661 PrimitiveConstantValue primitive = value; | 661 PrimitiveConstantValue primitive = value; |
| 662 valueString = | 662 valueString = |
| 663 new DartString.literal(primitive.primitiveValue.toString()); | 663 new DartString.literal(primitive.primitiveValue.toString()); |
| 664 } else if (value.isString) { | 664 } else if (value.isString) { |
| 665 PrimitiveConstantValue primitive = value; | 665 PrimitiveConstantValue primitive = value; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 @override | 726 @override |
| 727 int _computeHashCode() => 13 * name.hashCode; | 727 int _computeHashCode() => 13 * name.hashCode; |
| 728 | 728 |
| 729 @override | 729 @override |
| 730 bool _equals(SymbolConstantExpression other) { | 730 bool _equals(SymbolConstantExpression other) { |
| 731 return name == other.name; | 731 return name == other.name; |
| 732 } | 732 } |
| 733 | 733 |
| 734 @override | 734 @override |
| 735 ConstantValue evaluate( | 735 ConstantValue evaluate( |
| 736 Environment environment, ConstantSystem constantSystem) { | 736 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 737 return constantSystem.createSymbol(environment.commonElements, name); | 737 return constantSystem.createSymbol(environment.commonElements, name); |
| 738 } | 738 } |
| 739 | 739 |
| 740 @override | 740 @override |
| 741 InterfaceType getKnownType(CommonElements commonElements) => | 741 InterfaceType getKnownType(CommonElements commonElements) => |
| 742 commonElements.symbolType; | 742 commonElements.symbolType; |
| 743 } | 743 } |
| 744 | 744 |
| 745 /// Type literal. | 745 /// Type literal. |
| 746 class TypeConstantExpression extends ConstantExpression { | 746 class TypeConstantExpression extends ConstantExpression { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 761 return visitor.visitType(this, context); | 761 return visitor.visitType(this, context); |
| 762 } | 762 } |
| 763 | 763 |
| 764 @override | 764 @override |
| 765 void _createStructuredText(StringBuffer sb) { | 765 void _createStructuredText(StringBuffer sb) { |
| 766 sb.write('Type(type=$type)'); | 766 sb.write('Type(type=$type)'); |
| 767 } | 767 } |
| 768 | 768 |
| 769 @override | 769 @override |
| 770 ConstantValue evaluate( | 770 ConstantValue evaluate( |
| 771 Environment environment, ConstantSystem constantSystem) { | 771 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 772 return constantSystem.createType(environment.commonElements, type); | 772 return constantSystem.createType(environment.commonElements, type); |
| 773 } | 773 } |
| 774 | 774 |
| 775 @override | 775 @override |
| 776 int _computeHashCode() => 13 * type.hashCode; | 776 int _computeHashCode() => 13 * type.hashCode; |
| 777 | 777 |
| 778 @override | 778 @override |
| 779 bool _equals(TypeConstantExpression other) { | 779 bool _equals(TypeConstantExpression other) { |
| 780 return type == other.type; | 780 return type == other.type; |
| 781 } | 781 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 797 return visitor.visitField(this, context); | 797 return visitor.visitField(this, context); |
| 798 } | 798 } |
| 799 | 799 |
| 800 @override | 800 @override |
| 801 void _createStructuredText(StringBuffer sb) { | 801 void _createStructuredText(StringBuffer sb) { |
| 802 sb.write('Field(element=$element)'); | 802 sb.write('Field(element=$element)'); |
| 803 } | 803 } |
| 804 | 804 |
| 805 @override | 805 @override |
| 806 ConstantValue evaluate( | 806 ConstantValue evaluate( |
| 807 Environment environment, ConstantSystem constantSystem) { | 807 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 808 ConstantExpression constant = environment.getFieldConstant(element); | 808 ConstantExpression constant = environment.getFieldConstant(element); |
| 809 return constant.evaluate(environment, constantSystem); | 809 return constant.evaluate(environment, constantSystem); |
| 810 } | 810 } |
| 811 | 811 |
| 812 @override | 812 @override |
| 813 int _computeHashCode() => 13 * element.hashCode; | 813 int _computeHashCode() => 13 * element.hashCode; |
| 814 | 814 |
| 815 @override | 815 @override |
| 816 bool _equals(FieldConstantExpression other) { | 816 bool _equals(FieldConstantExpression other) { |
| 817 return element == other.element; | 817 return element == other.element; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 830 return visitor.visitLocalVariable(this, context); | 830 return visitor.visitLocalVariable(this, context); |
| 831 } | 831 } |
| 832 | 832 |
| 833 @override | 833 @override |
| 834 void _createStructuredText(StringBuffer sb) { | 834 void _createStructuredText(StringBuffer sb) { |
| 835 sb.write('LocalVariable(element=$element)'); | 835 sb.write('LocalVariable(element=$element)'); |
| 836 } | 836 } |
| 837 | 837 |
| 838 @override | 838 @override |
| 839 ConstantValue evaluate( | 839 ConstantValue evaluate( |
| 840 Environment environment, ConstantSystem constantSystem) { | 840 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 841 ConstantExpression constant = environment.getLocalConstant(element); | 841 ConstantExpression constant = environment.getLocalConstant(element); |
| 842 return constant.evaluate(environment, constantSystem); | 842 return constant.evaluate(environment, constantSystem); |
| 843 } | 843 } |
| 844 | 844 |
| 845 @override | 845 @override |
| 846 int _computeHashCode() => 13 * element.hashCode; | 846 int _computeHashCode() => 13 * element.hashCode; |
| 847 | 847 |
| 848 @override | 848 @override |
| 849 bool _equals(LocalVariableConstantExpression other) { | 849 bool _equals(LocalVariableConstantExpression other) { |
| 850 return element == other.element; | 850 return element == other.element; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 864 return visitor.visitFunction(this, context); | 864 return visitor.visitFunction(this, context); |
| 865 } | 865 } |
| 866 | 866 |
| 867 @override | 867 @override |
| 868 void _createStructuredText(StringBuffer sb) { | 868 void _createStructuredText(StringBuffer sb) { |
| 869 sb.write('Function(element=$element)'); | 869 sb.write('Function(element=$element)'); |
| 870 } | 870 } |
| 871 | 871 |
| 872 @override | 872 @override |
| 873 ConstantValue evaluate( | 873 ConstantValue evaluate( |
| 874 Environment environment, ConstantSystem constantSystem) { | 874 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 875 return new FunctionConstantValue(element, type); | 875 return new FunctionConstantValue(element, type); |
| 876 } | 876 } |
| 877 | 877 |
| 878 @override | 878 @override |
| 879 int _computeHashCode() => 13 * element.hashCode; | 879 int _computeHashCode() => 13 * element.hashCode; |
| 880 | 880 |
| 881 @override | 881 @override |
| 882 bool _equals(FunctionConstantExpression other) { | 882 bool _equals(FunctionConstantExpression other) { |
| 883 return element == other.element; | 883 return element == other.element; |
| 884 } | 884 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 908 void _createStructuredText(StringBuffer sb) { | 908 void _createStructuredText(StringBuffer sb) { |
| 909 sb.write('Binary(left='); | 909 sb.write('Binary(left='); |
| 910 left._createStructuredText(sb); | 910 left._createStructuredText(sb); |
| 911 sb.write(',op=$operator,right='); | 911 sb.write(',op=$operator,right='); |
| 912 right._createStructuredText(sb); | 912 right._createStructuredText(sb); |
| 913 sb.write(')'); | 913 sb.write(')'); |
| 914 } | 914 } |
| 915 | 915 |
| 916 @override | 916 @override |
| 917 ConstantValue evaluate( | 917 ConstantValue evaluate( |
| 918 Environment environment, ConstantSystem constantSystem) { | 918 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 919 ConstantValue leftValue = left.evaluate(environment, constantSystem); | 919 ConstantValue leftValue = left.evaluate(environment, constantSystem); |
| 920 ConstantValue rightValue = right.evaluate(environment, constantSystem); | 920 ConstantValue rightValue = right.evaluate(environment, constantSystem); |
| 921 switch (operator.kind) { | 921 switch (operator.kind) { |
| 922 case BinaryOperatorKind.NOT_EQ: | 922 case BinaryOperatorKind.NOT_EQ: |
| 923 BoolConstantValue equals = | 923 BoolConstantValue equals = |
| 924 constantSystem.equal.fold(leftValue, rightValue); | 924 constantSystem.equal.fold(leftValue, rightValue); |
| 925 return equals.negate(); | 925 return equals.negate(); |
| 926 default: | 926 default: |
| 927 return constantSystem | 927 return constantSystem |
| 928 .lookupBinary(operator) | 928 .lookupBinary(operator) |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 void _createStructuredText(StringBuffer sb) { | 1047 void _createStructuredText(StringBuffer sb) { |
| 1048 sb.write('Identical(left='); | 1048 sb.write('Identical(left='); |
| 1049 left._createStructuredText(sb); | 1049 left._createStructuredText(sb); |
| 1050 sb.write(',right='); | 1050 sb.write(',right='); |
| 1051 right._createStructuredText(sb); | 1051 right._createStructuredText(sb); |
| 1052 sb.write(')'); | 1052 sb.write(')'); |
| 1053 } | 1053 } |
| 1054 | 1054 |
| 1055 @override | 1055 @override |
| 1056 ConstantValue evaluate( | 1056 ConstantValue evaluate( |
| 1057 Environment environment, ConstantSystem constantSystem) { | 1057 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 1058 return constantSystem.identity.fold( | 1058 return constantSystem.identity.fold( |
| 1059 left.evaluate(environment, constantSystem), | 1059 left.evaluate(environment, constantSystem), |
| 1060 right.evaluate(environment, constantSystem)); | 1060 right.evaluate(environment, constantSystem)); |
| 1061 } | 1061 } |
| 1062 | 1062 |
| 1063 ConstantExpression apply(NormalizedArguments arguments) { | 1063 ConstantExpression apply(NormalizedArguments arguments) { |
| 1064 return new IdenticalConstantExpression( | 1064 return new IdenticalConstantExpression( |
| 1065 left.apply(arguments), right.apply(arguments)); | 1065 left.apply(arguments), right.apply(arguments)); |
| 1066 } | 1066 } |
| 1067 | 1067 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 | 1104 |
| 1105 @override | 1105 @override |
| 1106 void _createStructuredText(StringBuffer sb) { | 1106 void _createStructuredText(StringBuffer sb) { |
| 1107 sb.write('Unary(op=$operator,expression='); | 1107 sb.write('Unary(op=$operator,expression='); |
| 1108 expression._createStructuredText(sb); | 1108 expression._createStructuredText(sb); |
| 1109 sb.write(')'); | 1109 sb.write(')'); |
| 1110 } | 1110 } |
| 1111 | 1111 |
| 1112 @override | 1112 @override |
| 1113 ConstantValue evaluate( | 1113 ConstantValue evaluate( |
| 1114 Environment environment, ConstantSystem constantSystem) { | 1114 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 1115 return constantSystem | 1115 return constantSystem |
| 1116 .lookupUnary(operator) | 1116 .lookupUnary(operator) |
| 1117 .fold(expression.evaluate(environment, constantSystem)); | 1117 .fold(expression.evaluate(environment, constantSystem)); |
| 1118 } | 1118 } |
| 1119 | 1119 |
| 1120 ConstantExpression apply(NormalizedArguments arguments) { | 1120 ConstantExpression apply(NormalizedArguments arguments) { |
| 1121 return new UnaryConstantExpression(operator, expression.apply(arguments)); | 1121 return new UnaryConstantExpression(operator, expression.apply(arguments)); |
| 1122 } | 1122 } |
| 1123 | 1123 |
| 1124 int get precedence => PRECEDENCE_MAP[operator.kind]; | 1124 int get precedence => PRECEDENCE_MAP[operator.kind]; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 | 1164 |
| 1165 @override | 1165 @override |
| 1166 void _createStructuredText(StringBuffer sb) { | 1166 void _createStructuredText(StringBuffer sb) { |
| 1167 sb.write('StringLength(expression='); | 1167 sb.write('StringLength(expression='); |
| 1168 expression._createStructuredText(sb); | 1168 expression._createStructuredText(sb); |
| 1169 sb.write(')'); | 1169 sb.write(')'); |
| 1170 } | 1170 } |
| 1171 | 1171 |
| 1172 @override | 1172 @override |
| 1173 ConstantValue evaluate( | 1173 ConstantValue evaluate( |
| 1174 Environment environment, ConstantSystem constantSystem) { | 1174 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 1175 ConstantValue value = expression.evaluate(environment, constantSystem); | 1175 ConstantValue value = expression.evaluate(environment, constantSystem); |
| 1176 if (value.isString) { | 1176 if (value.isString) { |
| 1177 StringConstantValue stringValue = value; | 1177 StringConstantValue stringValue = value; |
| 1178 return constantSystem.createInt(stringValue.primitiveValue.length); | 1178 return constantSystem.createInt(stringValue.primitiveValue.length); |
| 1179 } | 1179 } |
| 1180 return new NonConstantValue(); | 1180 return new NonConstantValue(); |
| 1181 } | 1181 } |
| 1182 | 1182 |
| 1183 ConstantExpression apply(NormalizedArguments arguments) { | 1183 ConstantExpression apply(NormalizedArguments arguments) { |
| 1184 return new StringLengthConstantExpression(expression.apply(arguments)); | 1184 return new StringLengthConstantExpression(expression.apply(arguments)); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1247 | 1247 |
| 1248 @override | 1248 @override |
| 1249 bool _equals(ConditionalConstantExpression other) { | 1249 bool _equals(ConditionalConstantExpression other) { |
| 1250 return condition == other.condition && | 1250 return condition == other.condition && |
| 1251 trueExp == other.trueExp && | 1251 trueExp == other.trueExp && |
| 1252 falseExp == other.falseExp; | 1252 falseExp == other.falseExp; |
| 1253 } | 1253 } |
| 1254 | 1254 |
| 1255 @override | 1255 @override |
| 1256 ConstantValue evaluate( | 1256 ConstantValue evaluate( |
| 1257 Environment environment, ConstantSystem constantSystem) { | 1257 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 1258 ConstantValue conditionValue = | 1258 ConstantValue conditionValue = |
| 1259 condition.evaluate(environment, constantSystem); | 1259 condition.evaluate(environment, constantSystem); |
| 1260 ConstantValue trueValue = trueExp.evaluate(environment, constantSystem); | 1260 ConstantValue trueValue = trueExp.evaluate(environment, constantSystem); |
| 1261 ConstantValue falseValue = falseExp.evaluate(environment, constantSystem); | 1261 ConstantValue falseValue = falseExp.evaluate(environment, constantSystem); |
| 1262 if (conditionValue.isTrue) { | 1262 if (conditionValue.isTrue) { |
| 1263 return trueValue; | 1263 return trueValue; |
| 1264 } else if (conditionValue.isFalse) { | 1264 } else if (conditionValue.isFalse) { |
| 1265 return falseValue; | 1265 return falseValue; |
| 1266 } else { | 1266 } else { |
| 1267 return new NonConstantValue(); | 1267 return new NonConstantValue(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1308 } | 1308 } |
| 1309 | 1309 |
| 1310 @override | 1310 @override |
| 1311 int _computeHashCode() => 13 * index.hashCode; | 1311 int _computeHashCode() => 13 * index.hashCode; |
| 1312 | 1312 |
| 1313 @override | 1313 @override |
| 1314 bool _equals(PositionalArgumentReference other) => index == other.index; | 1314 bool _equals(PositionalArgumentReference other) => index == other.index; |
| 1315 | 1315 |
| 1316 @override | 1316 @override |
| 1317 ConstantValue evaluate( | 1317 ConstantValue evaluate( |
| 1318 Environment environment, ConstantSystem constantSystem) { | 1318 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 1319 throw new UnsupportedError('PositionalArgumentReference.evaluate'); | 1319 throw new UnsupportedError('PositionalArgumentReference.evaluate'); |
| 1320 } | 1320 } |
| 1321 | 1321 |
| 1322 @override | 1322 @override |
| 1323 bool get isPotential => true; | 1323 bool get isPotential => true; |
| 1324 } | 1324 } |
| 1325 | 1325 |
| 1326 /// A reference to a named parameter. | 1326 /// A reference to a named parameter. |
| 1327 class NamedArgumentReference extends ConstantExpression { | 1327 class NamedArgumentReference extends ConstantExpression { |
| 1328 final String name; | 1328 final String name; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1347 } | 1347 } |
| 1348 | 1348 |
| 1349 @override | 1349 @override |
| 1350 int _computeHashCode() => 13 * name.hashCode; | 1350 int _computeHashCode() => 13 * name.hashCode; |
| 1351 | 1351 |
| 1352 @override | 1352 @override |
| 1353 bool _equals(NamedArgumentReference other) => name == other.name; | 1353 bool _equals(NamedArgumentReference other) => name == other.name; |
| 1354 | 1354 |
| 1355 @override | 1355 @override |
| 1356 ConstantValue evaluate( | 1356 ConstantValue evaluate( |
| 1357 Environment environment, ConstantSystem constantSystem) { | 1357 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 1358 throw new UnsupportedError('NamedArgumentReference.evaluate'); | 1358 throw new UnsupportedError('NamedArgumentReference.evaluate'); |
| 1359 } | 1359 } |
| 1360 | 1360 |
| 1361 @override | 1361 @override |
| 1362 bool get isPotential => true; | 1362 bool get isPotential => true; |
| 1363 } | 1363 } |
| 1364 | 1364 |
| 1365 abstract class FromEnvironmentConstantExpression extends ConstantExpression { | 1365 abstract class FromEnvironmentConstantExpression extends ConstantExpression { |
| 1366 final ConstantExpression name; | 1366 final ConstantExpression name; |
| 1367 final ConstantExpression defaultValue; | 1367 final ConstantExpression defaultValue; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 if (defaultValue != null) { | 1413 if (defaultValue != null) { |
| 1414 defaultValue._createStructuredText(sb); | 1414 defaultValue._createStructuredText(sb); |
| 1415 } else { | 1415 } else { |
| 1416 sb.write('null'); | 1416 sb.write('null'); |
| 1417 } | 1417 } |
| 1418 sb.write(')'); | 1418 sb.write(')'); |
| 1419 } | 1419 } |
| 1420 | 1420 |
| 1421 @override | 1421 @override |
| 1422 ConstantValue evaluate( | 1422 ConstantValue evaluate( |
| 1423 Environment environment, ConstantSystem constantSystem) { | 1423 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 1424 ConstantValue nameConstantValue = | 1424 ConstantValue nameConstantValue = |
| 1425 name.evaluate(environment, constantSystem); | 1425 name.evaluate(environment, constantSystem); |
| 1426 ConstantValue defaultConstantValue; | 1426 ConstantValue defaultConstantValue; |
| 1427 if (defaultValue != null) { | 1427 if (defaultValue != null) { |
| 1428 defaultConstantValue = defaultValue.evaluate(environment, constantSystem); | 1428 defaultConstantValue = defaultValue.evaluate(environment, constantSystem); |
| 1429 } else { | 1429 } else { |
| 1430 defaultConstantValue = constantSystem.createBool(false); | 1430 defaultConstantValue = constantSystem.createBool(false); |
| 1431 } | 1431 } |
| 1432 if (!nameConstantValue.isString) { | 1432 if (!nameConstantValue.isString) { |
| 1433 return new NonConstantValue(); | 1433 return new NonConstantValue(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1477 if (defaultValue != null) { | 1477 if (defaultValue != null) { |
| 1478 defaultValue._createStructuredText(sb); | 1478 defaultValue._createStructuredText(sb); |
| 1479 } else { | 1479 } else { |
| 1480 sb.write('null'); | 1480 sb.write('null'); |
| 1481 } | 1481 } |
| 1482 sb.write(')'); | 1482 sb.write(')'); |
| 1483 } | 1483 } |
| 1484 | 1484 |
| 1485 @override | 1485 @override |
| 1486 ConstantValue evaluate( | 1486 ConstantValue evaluate( |
| 1487 Environment environment, ConstantSystem constantSystem) { | 1487 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 1488 ConstantValue nameConstantValue = | 1488 ConstantValue nameConstantValue = |
| 1489 name.evaluate(environment, constantSystem); | 1489 name.evaluate(environment, constantSystem); |
| 1490 ConstantValue defaultConstantValue; | 1490 ConstantValue defaultConstantValue; |
| 1491 if (defaultValue != null) { | 1491 if (defaultValue != null) { |
| 1492 defaultConstantValue = defaultValue.evaluate(environment, constantSystem); | 1492 defaultConstantValue = defaultValue.evaluate(environment, constantSystem); |
| 1493 } else { | 1493 } else { |
| 1494 defaultConstantValue = constantSystem.createNull(); | 1494 defaultConstantValue = constantSystem.createNull(); |
| 1495 } | 1495 } |
| 1496 if (!nameConstantValue.isString) { | 1496 if (!nameConstantValue.isString) { |
| 1497 return new NonConstantValue(); | 1497 return new NonConstantValue(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1543 if (defaultValue != null) { | 1543 if (defaultValue != null) { |
| 1544 defaultValue._createStructuredText(sb); | 1544 defaultValue._createStructuredText(sb); |
| 1545 } else { | 1545 } else { |
| 1546 sb.write('null'); | 1546 sb.write('null'); |
| 1547 } | 1547 } |
| 1548 sb.write(')'); | 1548 sb.write(')'); |
| 1549 } | 1549 } |
| 1550 | 1550 |
| 1551 @override | 1551 @override |
| 1552 ConstantValue evaluate( | 1552 ConstantValue evaluate( |
| 1553 Environment environment, ConstantSystem constantSystem) { | 1553 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 1554 ConstantValue nameConstantValue = | 1554 ConstantValue nameConstantValue = |
| 1555 name.evaluate(environment, constantSystem); | 1555 name.evaluate(environment, constantSystem); |
| 1556 ConstantValue defaultConstantValue; | 1556 ConstantValue defaultConstantValue; |
| 1557 if (defaultValue != null) { | 1557 if (defaultValue != null) { |
| 1558 defaultConstantValue = defaultValue.evaluate(environment, constantSystem); | 1558 defaultConstantValue = defaultValue.evaluate(environment, constantSystem); |
| 1559 } else { | 1559 } else { |
| 1560 defaultConstantValue = constantSystem.createNull(); | 1560 defaultConstantValue = constantSystem.createNull(); |
| 1561 } | 1561 } |
| 1562 if (!nameConstantValue.isString) { | 1562 if (!nameConstantValue.isString) { |
| 1563 return new NonConstantValue(); | 1563 return new NonConstantValue(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1594 | 1594 |
| 1595 @override | 1595 @override |
| 1596 void _createStructuredText(StringBuffer sb) { | 1596 void _createStructuredText(StringBuffer sb) { |
| 1597 sb.write('Deferred(prefix=$prefix,expression='); | 1597 sb.write('Deferred(prefix=$prefix,expression='); |
| 1598 expression._createStructuredText(sb); | 1598 expression._createStructuredText(sb); |
| 1599 sb.write(')'); | 1599 sb.write(')'); |
| 1600 } | 1600 } |
| 1601 | 1601 |
| 1602 @override | 1602 @override |
| 1603 ConstantValue evaluate( | 1603 ConstantValue evaluate( |
| 1604 Environment environment, ConstantSystem constantSystem) { | 1604 EvaluationEnvironment environment, ConstantSystem constantSystem) { |
| 1605 return new DeferredConstantValue( | 1605 return new DeferredConstantValue( |
| 1606 expression.evaluate(environment, constantSystem), prefix); | 1606 expression.evaluate(environment, constantSystem), prefix); |
| 1607 } | 1607 } |
| 1608 | 1608 |
| 1609 @override | 1609 @override |
| 1610 int _computeHashCode() { | 1610 int _computeHashCode() { |
| 1611 return 13 * expression.hashCode; | 1611 return 13 * expression.hashCode; |
| 1612 } | 1612 } |
| 1613 | 1613 |
| 1614 ConstantExpression apply(NormalizedArguments arguments) { | 1614 ConstantExpression apply(NormalizedArguments arguments) { |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1936 visit(exp.name); | 1936 visit(exp.name); |
| 1937 if (exp.defaultValue != null) { | 1937 if (exp.defaultValue != null) { |
| 1938 sb.write(', defaultValue: '); | 1938 sb.write(', defaultValue: '); |
| 1939 visit(exp.defaultValue); | 1939 visit(exp.defaultValue); |
| 1940 } | 1940 } |
| 1941 sb.write(')'); | 1941 sb.write(')'); |
| 1942 } | 1942 } |
| 1943 | 1943 |
| 1944 String toString() => sb.toString(); | 1944 String toString() => sb.toString(); |
| 1945 } | 1945 } |
| OLD | NEW |