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

Side by Side Diff: pkg/analyzer/lib/src/generated/constant.dart

Issue 622743002: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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 | Annotate | Revision Log
OLDNEW
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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.constant; 8 library engine.constant;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
11 import 'java_core.dart'; 11 import 'java_core.dart';
12 import 'java_engine.dart' show ObjectUtilities; 12 import 'java_engine.dart' show ObjectUtilities;
13 import 'source.dart' show Source; 13 import 'source.dart' show Source;
14 import 'error.dart' show AnalysisError, ErrorCode, CompileTimeErrorCode; 14 import 'error.dart';
15 import 'scanner.dart' show Token, TokenType; 15 import 'scanner.dart' show Token, TokenType;
16 import 'ast.dart'; 16 import 'ast.dart';
17 import 'element.dart'; 17 import 'element.dart';
18 import 'resolver.dart' show TypeProvider; 18 import 'resolver.dart' show TypeProvider;
19 import 'engine.dart' show AnalysisEngine; 19 import 'engine.dart' show AnalysisEngine, RecordingErrorListener;
20 import 'utilities_dart.dart' show ParameterKind; 20 import 'utilities_dart.dart' show ParameterKind;
21 import 'utilities_collection.dart'; 21 import 'utilities_collection.dart';
22 22
23 /** 23 /**
24 * Instances of the class `BoolState` represent the state of an object represent ing a boolean 24 * Instances of the class `BoolState` represent the state of an object represent ing a boolean
25 * value. 25 * value.
26 */ 26 */
27 class BoolState extends InstanceState { 27 class BoolState extends InstanceState {
28 /** 28 /**
29 * The value of this instance. 29 * The value of this instance.
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 201
202 /** 202 /**
203 * Initialize a newly created evaluator to evaluate expressions in the given s ource. 203 * Initialize a newly created evaluator to evaluate expressions in the given s ource.
204 * 204 *
205 * @param source the source containing the expression(s) that will be evaluate d 205 * @param source the source containing the expression(s) that will be evaluate d
206 * @param typeProvider the type provider used to access known types 206 * @param typeProvider the type provider used to access known types
207 */ 207 */
208 ConstantEvaluator(this._source, this._typeProvider); 208 ConstantEvaluator(this._source, this._typeProvider);
209 209
210 EvaluationResult evaluate(Expression expression) { 210 EvaluationResult evaluate(Expression expression) {
211 EvaluationResultImpl result = expression.accept(new ConstantVisitor.con1(_ty peProvider)); 211 RecordingErrorListener errorListener = new RecordingErrorListener();
212 if (result is ValidResult) { 212 ErrorReporter errorReporter = new ErrorReporter(errorListener, _source);
213 return EvaluationResult.forValue(result.value); 213 DartObjectImpl result = expression.accept(new ConstantVisitor.con1(_typeProv ider, errorReporter));
214 if (result != null) {
215 return EvaluationResult.forValue(result);
214 } 216 }
215 List<AnalysisError> errors = new List<AnalysisError>(); 217 return EvaluationResult.forErrors(errorListener.errors);
216 for (ErrorResult_ErrorData data in (result as ErrorResult).errorData) {
217 AstNode node = data.node;
218 errors.add(new AnalysisError.con2(_source, node.offset, node.length, data. errorCode, []));
219 }
220 return EvaluationResult.forErrors(new List.from(errors));
221 } 218 }
222 } 219 }
223 220
224 /** 221 /**
225 * Instances of the class `ConstantFinder` are used to traverse the AST structur es of all of 222 * Instances of the class `ConstantFinder` are used to traverse the AST structur es of all of
226 * the compilation units being resolved and build a table mapping constant varia ble elements to the 223 * the compilation units being resolved and build a table mapping constant varia ble elements to the
227 * declarations of those variables. 224 * declarations of those variables.
228 */ 225 */
229 class ConstantFinder extends RecursiveAstVisitor<Object> { 226 class ConstantFinder extends RecursiveAstVisitor<Object> {
230 /** 227 /**
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 ReferenceFinder parameterReferenceFinder = new ReferenceFinder(param eter, referenceGraph, _variableDeclarationMap, constructorDeclarationMap); 417 ReferenceFinder parameterReferenceFinder = new ReferenceFinder(param eter, referenceGraph, _variableDeclarationMap, constructorDeclarationMap);
421 defaultValue.accept(parameterReferenceFinder); 418 defaultValue.accept(parameterReferenceFinder);
422 } 419 }
423 } 420 }
424 } 421 }
425 } 422 }
426 for (InstanceCreationExpression expression in _constructorInvocations) { 423 for (InstanceCreationExpression expression in _constructorInvocations) {
427 referenceGraph.addNode(expression); 424 referenceGraph.addNode(expression);
428 ConstructorElement constructor = expression.staticElement; 425 ConstructorElement constructor = expression.staticElement;
429 if (constructor == null) { 426 if (constructor == null) {
430 break; 427 continue;
431 } 428 }
432 constructor = _followConstantRedirectionChain(constructor); 429 constructor = _followConstantRedirectionChain(constructor);
433 ConstructorDeclaration declaration = findConstructorDeclaration(constructo r); 430 ConstructorDeclaration declaration = findConstructorDeclaration(constructo r);
434 // An instance creation expression depends both on the constructor and the arguments passed 431 // An instance creation expression depends both on the constructor and the arguments passed
435 // to it. 432 // to it.
436 ReferenceFinder referenceFinder = new ReferenceFinder(expression, referenc eGraph, _variableDeclarationMap, constructorDeclarationMap); 433 ReferenceFinder referenceFinder = new ReferenceFinder(expression, referenc eGraph, _variableDeclarationMap, constructorDeclarationMap);
437 if (declaration != null) { 434 if (declaration != null) {
438 referenceGraph.addEdge(expression, declaration); 435 referenceGraph.addEdge(expression, declaration);
439 } 436 }
440 expression.argumentList.accept(referenceFinder); 437 expression.argumentList.accept(referenceFinder);
(...skipping 29 matching lines...) Expand all
470 * This method is called just before getting a parameter's default value. Unit tests will override 467 * This method is called just before getting a parameter's default value. Unit tests will override
471 * this method to introduce additional error checking. 468 * this method to introduce additional error checking.
472 */ 469 */
473 void beforeGetParameterDefault(ParameterElement parameter) { 470 void beforeGetParameterDefault(ParameterElement parameter) {
474 } 471 }
475 472
476 /** 473 /**
477 * Create the ConstantVisitor used to evaluate constants. Unit tests will over ride this method to 474 * Create the ConstantVisitor used to evaluate constants. Unit tests will over ride this method to
478 * introduce additional error checking. 475 * introduce additional error checking.
479 */ 476 */
480 ConstantVisitor createConstantVisitor() => new ConstantVisitor.con1(typeProvid er); 477 ConstantVisitor createConstantVisitor(ErrorReporter errorReporter) => new Cons tantVisitor.con1(typeProvider, errorReporter);
481 478
482 ConstructorDeclaration findConstructorDeclaration(ConstructorElement construct or) => constructorDeclarationMap[_getConstructorBase(constructor)]; 479 ConstructorDeclaration findConstructorDeclaration(ConstructorElement construct or) => constructorDeclarationMap[_getConstructorBase(constructor)];
483 480
484 /** 481 /**
485 * Check that the arguments to a call to fromEnvironment() are correct. 482 * Check that the arguments to a call to fromEnvironment() are correct.
486 * 483 *
487 * @param arguments the AST nodes of the arguments. 484 * @param arguments the AST nodes of the arguments.
488 * @param argumentValues the values of the unnamed arguments. 485 * @param argumentValues the values of the unnamed arguments.
489 * @param namedArgumentValues the values of the named arguments. 486 * @param namedArgumentValues the values of the named arguments.
490 * @param expectedDefaultValueType the allowed type of the "defaultValue" para meter (if present). 487 * @param expectedDefaultValueType the allowed type of the "defaultValue" para meter (if present).
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 /** 539 /**
543 * Compute a value for the given constant. 540 * Compute a value for the given constant.
544 * 541 *
545 * @param constNode the constant for which a value is to be computed 542 * @param constNode the constant for which a value is to be computed
546 */ 543 */
547 void _computeValueFor(AstNode constNode) { 544 void _computeValueFor(AstNode constNode) {
548 beforeComputeValue(constNode); 545 beforeComputeValue(constNode);
549 if (constNode is VariableDeclaration) { 546 if (constNode is VariableDeclaration) {
550 VariableDeclaration declaration = constNode; 547 VariableDeclaration declaration = constNode;
551 Element element = declaration.element; 548 Element element = declaration.element;
552 EvaluationResultImpl result = declaration.initializer.accept(createConstan tVisitor()); 549 RecordingErrorListener errorListener = new RecordingErrorListener();
553 (element as VariableElementImpl).evaluationResult = result; 550 ErrorReporter errorReporter = new ErrorReporter(errorListener, element.sou rce);
551 DartObjectImpl dartObject = declaration.initializer.accept(createConstantV isitor(errorReporter));
552 (element as VariableElementImpl).evaluationResult = new EvaluationResultIm pl.con2(dartObject, errorListener.errors);
554 } else if (constNode is InstanceCreationExpression) { 553 } else if (constNode is InstanceCreationExpression) {
555 InstanceCreationExpression expression = constNode; 554 InstanceCreationExpression expression = constNode;
556 ConstructorElement constructor = expression.staticElement; 555 ConstructorElement constructor = expression.staticElement;
557 if (constructor == null) { 556 if (constructor == null) {
558 // Couldn't resolve the constructor so we can't compute a value. No pro blem--the error 557 // Couldn't resolve the constructor so we can't compute a value. No pro blem--the error
559 // has already been reported. 558 // has already been reported. But we still need to store an evaluation result.
559 expression.evaluationResult = new EvaluationResultImpl.con1(null);
560 return; 560 return;
561 } 561 }
562 ConstantVisitor constantVisitor = createConstantVisitor(); 562 RecordingErrorListener errorListener = new RecordingErrorListener();
563 EvaluationResultImpl result = _evaluateConstructorCall(constNode, expressi on.argumentList.arguments, constructor, constantVisitor); 563 CompilationUnit sourceCompilationUnit = expression.getAncestor((node) => n ode is CompilationUnit);
564 expression.evaluationResult = result; 564 ErrorReporter errorReporter = new ErrorReporter(errorListener, sourceCompi lationUnit.element.source);
565 ConstantVisitor constantVisitor = createConstantVisitor(errorReporter);
566 DartObjectImpl result = _evaluateConstructorCall(constNode, expression.arg umentList.arguments, constructor, constantVisitor, errorReporter);
567 expression.evaluationResult = new EvaluationResultImpl.con2(result, errorL istener.errors);
565 } else if (constNode is ConstructorDeclaration) { 568 } else if (constNode is ConstructorDeclaration) {
566 ConstructorDeclaration declaration = constNode; 569 ConstructorDeclaration declaration = constNode;
567 NodeList<ConstructorInitializer> initializers = declaration.initializers; 570 NodeList<ConstructorInitializer> initializers = declaration.initializers;
568 ConstructorElementImpl constructor = declaration.element as ConstructorEle mentImpl; 571 ConstructorElementImpl constructor = declaration.element as ConstructorEle mentImpl;
569 constructor.constantInitializers = new ConstantValueComputer_InitializerCl oner().cloneNodeList(initializers); 572 constructor.constantInitializers = new ConstantValueComputer_InitializerCl oner().cloneNodeList(initializers);
570 } else if (constNode is FormalParameter) { 573 } else if (constNode is FormalParameter) {
571 if (constNode is DefaultFormalParameter) { 574 if (constNode is DefaultFormalParameter) {
572 DefaultFormalParameter parameter = constNode; 575 DefaultFormalParameter parameter = constNode;
573 ParameterElement element = parameter.element; 576 ParameterElement element = parameter.element;
574 Expression defaultValue = parameter.defaultValue; 577 Expression defaultValue = parameter.defaultValue;
575 if (defaultValue != null) { 578 if (defaultValue != null) {
576 EvaluationResultImpl result = defaultValue.accept(createConstantVisito r()); 579 RecordingErrorListener errorListener = new RecordingErrorListener();
577 (element as ParameterElementImpl).evaluationResult = result; 580 ErrorReporter errorReporter = new ErrorReporter(errorListener, element .source);
581 DartObjectImpl dartObject = defaultValue.accept(createConstantVisitor( errorReporter));
582 (element as ParameterElementImpl).evaluationResult = new EvaluationRes ultImpl.con2(dartObject, errorListener.errors);
578 } 583 }
579 } 584 }
580 } else { 585 } else {
581 // Should not happen. 586 // Should not happen.
582 AnalysisEngine.instance.logger.logError("Constant value computer trying to compute the value of a node which is not a VariableDeclaration, InstanceCreatio nExpression, FormalParameter, or ConstructorDeclaration"); 587 AnalysisEngine.instance.logger.logError("Constant value computer trying to compute the value of a node which is not a VariableDeclaration, InstanceCreatio nExpression, FormalParameter, or ConstructorDeclaration");
583 return; 588 return;
584 } 589 }
585 } 590 }
586 591
587 /** 592 /**
588 * Evaluate a call to fromEnvironment() on the bool, int, or String class. 593 * Evaluate a call to fromEnvironment() on the bool, int, or String class.
589 * 594 *
590 * @param environmentValue Value fetched from the environment 595 * @param environmentValue Value fetched from the environment
591 * @param builtInDefaultValue Value that should be used as the default if no " defaultValue" 596 * @param builtInDefaultValue Value that should be used as the default if no " defaultValue"
592 * argument appears in [namedArgumentValues]. 597 * argument appears in [namedArgumentValues].
593 * @param namedArgumentValues Named parameters passed to fromEnvironment() 598 * @param namedArgumentValues Named parameters passed to fromEnvironment()
594 * @return A [ValidResult] object corresponding to the evaluated result 599 * @return A [DartObjectImpl] object corresponding to the evaluated result
595 */ 600 */
596 ValidResult _computeValueFromEnvironment(DartObject environmentValue, DartObje ctImpl builtInDefaultValue, HashMap<String, DartObjectImpl> namedArgumentValues) { 601 DartObjectImpl _computeValueFromEnvironment(DartObject environmentValue, DartO bjectImpl builtInDefaultValue, HashMap<String, DartObjectImpl> namedArgumentValu es) {
597 DartObjectImpl value = environmentValue as DartObjectImpl; 602 DartObjectImpl value = environmentValue as DartObjectImpl;
598 if (value.isUnknown || value.isNull) { 603 if (value.isUnknown || value.isNull) {
599 // The name either doesn't exist in the environment or we couldn't parse t he corresponding 604 // The name either doesn't exist in the environment or we couldn't parse t he corresponding
600 // value. If the code supplied an explicit default, use it. 605 // value. If the code supplied an explicit default, use it.
601 if (namedArgumentValues.containsKey(_DEFAULT_VALUE_PARAM)) { 606 if (namedArgumentValues.containsKey(_DEFAULT_VALUE_PARAM)) {
602 value = namedArgumentValues[_DEFAULT_VALUE_PARAM]; 607 value = namedArgumentValues[_DEFAULT_VALUE_PARAM];
603 } else if (value.isNull) { 608 } else if (value.isNull) {
604 // The code didn't supply an explicit default. The name exists in the e nvironment but 609 // The code didn't supply an explicit default. The name exists in the e nvironment but
605 // we couldn't parse the corresponding value. So use the built-in defau lt value, because 610 // we couldn't parse the corresponding value. So use the built-in defau lt value, because
606 // this is what the VM does. 611 // this is what the VM does.
607 value = builtInDefaultValue; 612 value = builtInDefaultValue;
608 } else { 613 } else {
609 } 614 }
610 } 615 }
611 return new ValidResult(value); 616 return value;
612 } 617 }
613 618
614 EvaluationResultImpl _evaluateConstructorCall(AstNode node, NodeList<Expressio n> arguments, ConstructorElement constructor, ConstantVisitor constantVisitor) { 619 DartObjectImpl _evaluateConstructorCall(AstNode node, NodeList<Expression> arg uments, ConstructorElement constructor, ConstantVisitor constantVisitor, ErrorRe porter errorReporter) {
615 int argumentCount = arguments.length; 620 int argumentCount = arguments.length;
616 List<DartObjectImpl> argumentValues = new List<DartObjectImpl>(argumentCount ); 621 List<DartObjectImpl> argumentValues = new List<DartObjectImpl>(argumentCount );
617 HashMap<String, DartObjectImpl> namedArgumentValues = new HashMap<String, Da rtObjectImpl>(); 622 HashMap<String, DartObjectImpl> namedArgumentValues = new HashMap<String, Da rtObjectImpl>();
618 for (int i = 0; i < argumentCount; i++) { 623 for (int i = 0; i < argumentCount; i++) {
619 Expression argument = arguments[i]; 624 Expression argument = arguments[i];
620 if (argument is NamedExpression) { 625 if (argument is NamedExpression) {
621 NamedExpression namedExpression = argument; 626 NamedExpression namedExpression = argument;
622 String name = namedExpression.name.label.name; 627 String name = namedExpression.name.label.name;
623 namedArgumentValues[name] = constantVisitor._valueOf(namedExpression.exp ression); 628 namedArgumentValues[name] = constantVisitor._valueOf(namedExpression.exp ression);
624 argumentValues[i] = constantVisitor.null2; 629 argumentValues[i] = constantVisitor.null2;
625 } else { 630 } else {
626 argumentValues[i] = constantVisitor._valueOf(argument); 631 argumentValues[i] = constantVisitor._valueOf(argument);
627 } 632 }
628 } 633 }
629 constructor = _followConstantRedirectionChain(constructor); 634 constructor = _followConstantRedirectionChain(constructor);
630 InterfaceType definingClass = constructor.returnType as InterfaceType; 635 InterfaceType definingClass = constructor.returnType as InterfaceType;
631 if (constructor.isFactory) { 636 if (constructor.isFactory) {
632 // We couldn't find a non-factory constructor. See if it's because we rea ched an external 637 // We couldn't find a non-factory constructor. See if it's because we rea ched an external
633 // const factory constructor that we can emulate. 638 // const factory constructor that we can emulate.
634 if (constructor.name == "fromEnvironment") { 639 if (constructor.name == "fromEnvironment") {
635 if (!_checkFromEnvironmentArguments(arguments, argumentValues, namedArgu mentValues, definingClass)) { 640 if (!_checkFromEnvironmentArguments(arguments, argumentValues, namedArgu mentValues, definingClass)) {
636 return new ErrorResult.con1(node, CompileTimeErrorCode.CONST_EVAL_THRO WS_EXCEPTION); 641 errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_EVAL_THROW S_EXCEPTION, node, []);
642 return null;
637 } 643 }
638 String variableName = argumentCount < 1 ? null : argumentValues[0].strin gValue; 644 String variableName = argumentCount < 1 ? null : argumentValues[0].strin gValue;
639 if (identical(definingClass, typeProvider.boolType)) { 645 if (identical(definingClass, typeProvider.boolType)) {
640 DartObject valueFromEnvironment; 646 DartObject valueFromEnvironment;
641 valueFromEnvironment = _declaredVariables.getBool(typeProvider, variab leName); 647 valueFromEnvironment = _declaredVariables.getBool(typeProvider, variab leName);
642 return _computeValueFromEnvironment(valueFromEnvironment, new DartObje ctImpl(typeProvider.boolType, BoolState.FALSE_STATE), namedArgumentValues); 648 return _computeValueFromEnvironment(valueFromEnvironment, new DartObje ctImpl(typeProvider.boolType, BoolState.FALSE_STATE), namedArgumentValues);
643 } else if (identical(definingClass, typeProvider.intType)) { 649 } else if (identical(definingClass, typeProvider.intType)) {
644 DartObject valueFromEnvironment; 650 DartObject valueFromEnvironment;
645 valueFromEnvironment = _declaredVariables.getInt(typeProvider, variabl eName); 651 valueFromEnvironment = _declaredVariables.getInt(typeProvider, variabl eName);
646 return _computeValueFromEnvironment(valueFromEnvironment, new DartObje ctImpl(typeProvider.nullType, NullState.NULL_STATE), namedArgumentValues); 652 return _computeValueFromEnvironment(valueFromEnvironment, new DartObje ctImpl(typeProvider.nullType, NullState.NULL_STATE), namedArgumentValues);
647 } else if (identical(definingClass, typeProvider.stringType)) { 653 } else if (identical(definingClass, typeProvider.stringType)) {
648 DartObject valueFromEnvironment; 654 DartObject valueFromEnvironment;
649 valueFromEnvironment = _declaredVariables.getString(typeProvider, vari ableName); 655 valueFromEnvironment = _declaredVariables.getString(typeProvider, vari ableName);
650 return _computeValueFromEnvironment(valueFromEnvironment, new DartObje ctImpl(typeProvider.nullType, NullState.NULL_STATE), namedArgumentValues); 656 return _computeValueFromEnvironment(valueFromEnvironment, new DartObje ctImpl(typeProvider.nullType, NullState.NULL_STATE), namedArgumentValues);
651 } 657 }
652 } else if (constructor.name == "" && identical(definingClass, typeProvider .symbolType) && argumentCount == 1) { 658 } else if (constructor.name == "" && identical(definingClass, typeProvider .symbolType) && argumentCount == 1) {
653 if (!_checkSymbolArguments(arguments, argumentValues, namedArgumentValue s)) { 659 if (!_checkSymbolArguments(arguments, argumentValues, namedArgumentValue s)) {
654 return new ErrorResult.con1(node, CompileTimeErrorCode.CONST_EVAL_THRO WS_EXCEPTION); 660 errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_EVAL_THROW S_EXCEPTION, node, []);
661 return null;
655 } 662 }
656 String argumentValue = argumentValues[0].stringValue; 663 String argumentValue = argumentValues[0].stringValue;
657 return constantVisitor._valid(definingClass, new SymbolState(argumentVal ue)); 664 return new DartObjectImpl(definingClass, new SymbolState(argumentValue)) ;
658 } 665 }
659 // Either it's an external const factory constructor that we can't emulate , or an error 666 // Either it's an external const factory constructor that we can't emulate , or an error
660 // occurred (a cycle, or a const constructor trying to delegate to a non-c onst constructor). 667 // occurred (a cycle, or a const constructor trying to delegate to a non-c onst constructor).
661 // In the former case, the best we can do is consider it an unknown value. In the latter 668 // In the former case, the best we can do is consider it an unknown value. In the latter
662 // case, the error has already been reported, so considering it an unknown value will 669 // case, the error has already been reported, so considering it an unknown value will
663 // suppress further errors. 670 // suppress further errors.
664 return constantVisitor._validWithUnknownValue(definingClass); 671 return constantVisitor._validWithUnknownValue(definingClass);
665 } 672 }
666 beforeGetConstantInitializers(constructor); 673 beforeGetConstantInitializers(constructor);
667 ConstructorElementImpl constructorBase = _getConstructorBase(constructor) as ConstructorElementImpl; 674 ConstructorElementImpl constructorBase = _getConstructorBase(constructor) as ConstructorElementImpl;
(...skipping 18 matching lines...) Expand all
686 if (parameter.parameterKind == ParameterKind.NAMED) { 693 if (parameter.parameterKind == ParameterKind.NAMED) {
687 argumentValue = namedArgumentValues[parameter.name]; 694 argumentValue = namedArgumentValues[parameter.name];
688 } else if (i < argumentCount) { 695 } else if (i < argumentCount) {
689 argumentValue = argumentValues[i]; 696 argumentValue = argumentValues[i];
690 } 697 }
691 if (argumentValue == null && parameter is ParameterElementImpl) { 698 if (argumentValue == null && parameter is ParameterElementImpl) {
692 // The parameter is an optional positional parameter for which no value was provided, so 699 // The parameter is an optional positional parameter for which no value was provided, so
693 // use the default value. 700 // use the default value.
694 beforeGetParameterDefault(parameter); 701 beforeGetParameterDefault(parameter);
695 EvaluationResultImpl evaluationResult = (parameter as ParameterElementIm pl).evaluationResult; 702 EvaluationResultImpl evaluationResult = (parameter as ParameterElementIm pl).evaluationResult;
696 if (evaluationResult is ValidResult) { 703 if (evaluationResult == null) {
697 argumentValue = evaluationResult.value;
698 } else if (evaluationResult == null) {
699 // No default was provided, so the default value is null. 704 // No default was provided, so the default value is null.
700 argumentValue = constantVisitor.null2; 705 argumentValue = constantVisitor.null2;
706 } else if (evaluationResult.value != null) {
707 argumentValue = evaluationResult.value;
701 } 708 }
702 } 709 }
703 if (argumentValue != null) { 710 if (argumentValue != null) {
704 if (parameter.isInitializingFormal) { 711 if (parameter.isInitializingFormal) {
705 FieldElement field = (parameter as FieldFormalParameterElement).field; 712 FieldElement field = (parameter as FieldFormalParameterElement).field;
706 if (field != null) { 713 if (field != null) {
707 String fieldName = field.name; 714 String fieldName = field.name;
708 fieldMap[fieldName] = argumentValue; 715 fieldMap[fieldName] = argumentValue;
709 } 716 }
710 } else { 717 } else {
711 String name = parameter.name; 718 String name = parameter.name;
712 parameterMap[name] = argumentValue; 719 parameterMap[name] = argumentValue;
713 } 720 }
714 } 721 }
715 } 722 }
716 ConstantVisitor initializerVisitor = new ConstantVisitor.con2(typeProvider, parameterMap); 723 ConstantVisitor initializerVisitor = new ConstantVisitor.con2(typeProvider, parameterMap, errorReporter);
717 String superName = null; 724 String superName = null;
718 NodeList<Expression> superArguments = null; 725 NodeList<Expression> superArguments = null;
719 for (ConstructorInitializer initializer in initializers) { 726 for (ConstructorInitializer initializer in initializers) {
720 if (initializer is ConstructorFieldInitializer) { 727 if (initializer is ConstructorFieldInitializer) {
721 ConstructorFieldInitializer constructorFieldInitializer = initializer; 728 ConstructorFieldInitializer constructorFieldInitializer = initializer;
722 Expression initializerExpression = constructorFieldInitializer.expressio n; 729 Expression initializerExpression = constructorFieldInitializer.expressio n;
723 EvaluationResultImpl evaluationResult = initializerExpression.accept(ini tializerVisitor); 730 DartObjectImpl evaluationResult = initializerExpression.accept(initializ erVisitor);
724 if (evaluationResult is ValidResult) { 731 if (evaluationResult != null) {
725 DartObjectImpl value = evaluationResult.value;
726 String fieldName = constructorFieldInitializer.fieldName.name; 732 String fieldName = constructorFieldInitializer.fieldName.name;
727 fieldMap[fieldName] = value; 733 fieldMap[fieldName] = evaluationResult;
728 } 734 }
729 } else if (initializer is SuperConstructorInvocation) { 735 } else if (initializer is SuperConstructorInvocation) {
730 SuperConstructorInvocation superConstructorInvocation = initializer; 736 SuperConstructorInvocation superConstructorInvocation = initializer;
731 SimpleIdentifier name = superConstructorInvocation.constructorName; 737 SimpleIdentifier name = superConstructorInvocation.constructorName;
732 if (name != null) { 738 if (name != null) {
733 superName = name.name; 739 superName = name.name;
734 } 740 }
735 superArguments = superConstructorInvocation.argumentList.arguments; 741 superArguments = superConstructorInvocation.argumentList.arguments;
736 } 742 }
737 } 743 }
738 // Evaluate explicit or implicit call to super(). 744 // Evaluate explicit or implicit call to super().
739 InterfaceType superclass = definingClass.superclass; 745 InterfaceType superclass = definingClass.superclass;
740 if (superclass != null && !superclass.isObject) { 746 if (superclass != null && !superclass.isObject) {
741 ConstructorElement superConstructor = superclass.lookUpConstructor(superNa me, constructor.library); 747 ConstructorElement superConstructor = superclass.lookUpConstructor(superNa me, constructor.library);
742 if (superConstructor != null) { 748 if (superConstructor != null) {
743 if (superArguments == null) { 749 if (superArguments == null) {
744 superArguments = new NodeList<Expression>(null); 750 superArguments = new NodeList<Expression>(null);
745 } 751 }
746 _evaluateSuperConstructorCall(node, fieldMap, superConstructor, superArg uments, initializerVisitor); 752 _evaluateSuperConstructorCall(node, fieldMap, superConstructor, superArg uments, initializerVisitor, errorReporter);
747 } 753 }
748 } 754 }
749 return constantVisitor._valid(definingClass, new GenericState(fieldMap)); 755 return new DartObjectImpl(definingClass, new GenericState(fieldMap));
750 } 756 }
751 757
752 void _evaluateSuperConstructorCall(AstNode node, HashMap<String, DartObjectImp l> fieldMap, ConstructorElement superConstructor, NodeList<Expression> superArgu ments, ConstantVisitor initializerVisitor) { 758 void _evaluateSuperConstructorCall(AstNode node, HashMap<String, DartObjectImp l> fieldMap, ConstructorElement superConstructor, NodeList<Expression> superArgu ments, ConstantVisitor initializerVisitor, ErrorReporter errorReporter) {
753 if (superConstructor != null && superConstructor.isConst) { 759 if (superConstructor != null && superConstructor.isConst) {
754 EvaluationResultImpl evaluationResult = _evaluateConstructorCall(node, sup erArguments, superConstructor, initializerVisitor); 760 DartObjectImpl evaluationResult = _evaluateConstructorCall(node, superArgu ments, superConstructor, initializerVisitor, errorReporter);
755 if (evaluationResult is ValidResult) { 761 if (evaluationResult != null) {
756 ValidResult validResult = evaluationResult; 762 fieldMap[GenericState.SUPERCLASS_FIELD] = evaluationResult;
757 fieldMap[GenericState.SUPERCLASS_FIELD] = validResult.value;
758 } 763 }
759 } 764 }
760 } 765 }
761 766
762 /** 767 /**
763 * Attempt to follow the chain of factory redirections until a constructor is reached which is not 768 * Attempt to follow the chain of factory redirections until a constructor is reached which is not
764 * a const factory constructor. 769 * a const factory constructor.
765 * 770 *
766 * @return the constant constructor which terminates the chain of factory redi rections, if the 771 * @return the constant constructor which terminates the chain of factory redi rections, if the
767 * chain terminates. If there is a problem (e.g. a redirection can't b e found, or a cycle 772 * chain terminates. If there is a problem (e.g. a redirection can't b e found, or a cycle
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 } 823 }
819 } 824 }
820 825
821 /** 826 /**
822 * [AstCloner] that copies the necessary information from the AST to allow const constructor 827 * [AstCloner] that copies the necessary information from the AST to allow const constructor
823 * initializers to be evaluated. 828 * initializers to be evaluated.
824 */ 829 */
825 class ConstantValueComputer_InitializerCloner extends AstCloner { 830 class ConstantValueComputer_InitializerCloner extends AstCloner {
826 @override 831 @override
827 InstanceCreationExpression visitInstanceCreationExpression(InstanceCreationExp ression node) { 832 InstanceCreationExpression visitInstanceCreationExpression(InstanceCreationExp ression node) {
828 // All we need is the evaluation result, and the keyword so that we know whe ther it's const. 833 InstanceCreationExpression expression = super.visitInstanceCreationExpressio n(node);
829 InstanceCreationExpression expression = new InstanceCreationExpression(node. keyword, null, null);
830 expression.evaluationResult = node.evaluationResult; 834 expression.evaluationResult = node.evaluationResult;
831 return expression; 835 return expression;
832 } 836 }
833 837
834 @override 838 @override
835 SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) { 839 SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) {
836 SimpleIdentifier identifier = super.visitSimpleIdentifier(node); 840 SimpleIdentifier identifier = super.visitSimpleIdentifier(node);
837 identifier.staticElement = node.staticElement; 841 identifier.staticElement = node.staticElement;
838 return identifier; 842 return identifier;
839 } 843 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 * e<sub>2</sub></i>, <i>e<sub>1</sub> ~/ e<sub>2</sub></i>, <i>e<sub>1</sub> &g t; 886 * e<sub>2</sub></i>, <i>e<sub>1</sub> ~/ e<sub>2</sub></i>, <i>e<sub>1</sub> &g t;
883 * e<sub>2</sub></i>, <i>e<sub>1</sub> &lt; e<sub>2</sub></i>, <i>e<sub>1</sub> &gt;= 887 * e<sub>2</sub></i>, <i>e<sub>1</sub> &lt; e<sub>2</sub></i>, <i>e<sub>1</sub> &gt;=
884 * e<sub>2</sub></i>, <i>e<sub>1</sub> &lt;= e<sub>2</sub></i> or <i>e<sub>1</su b> % 888 * e<sub>2</sub></i>, <i>e<sub>1</sub> &lt;= e<sub>2</sub></i> or <i>e<sub>1</su b> %
885 * e<sub>2</sub></i>, where <i>e</i>, <i>e<sub>1</sub></i> and <i>e<sub>2</sub>< /i> are constant 889 * e<sub>2</sub></i>, where <i>e</i>, <i>e<sub>1</sub></i> and <i>e<sub>2</sub>< /i> are constant
886 * expressions that evaluate to a numeric value or to <b>null</b>. 890 * expressions that evaluate to a numeric value or to <b>null</b>.
887 * * An expression of the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub>< /i> where 891 * * An expression of the form <i>e<sub>1</sub> ? e<sub>2</sub> : e<sub>3</sub>< /i> where
888 * <i>e<sub>1</sub></i>, <i>e<sub>2</sub></i> and <i>e<sub>3</sub></i> are const ant expressions, and 892 * <i>e<sub>1</sub></i>, <i>e<sub>2</sub></i> and <i>e<sub>3</sub></i> are const ant expressions, and
889 * <i>e<sub>1</sub></i> evaluates to a boolean value. 893 * <i>e<sub>1</sub></i> evaluates to a boolean value.
890 * </blockquote> 894 * </blockquote>
891 */ 895 */
892 class ConstantVisitor extends UnifyingAstVisitor<EvaluationResultImpl> { 896 class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
893 /** 897 /**
894 * The type provider used to access the known types. 898 * The type provider used to access the known types.
895 */ 899 */
896 final TypeProvider _typeProvider; 900 final TypeProvider _typeProvider;
897 901
898 /** 902 /**
899 * An shared object representing the value 'null'. 903 * An shared object representing the value 'null'.
900 */ 904 */
901 DartObjectImpl _nullObject; 905 DartObjectImpl _nullObject;
902 906
903 HashMap<String, DartObjectImpl> _lexicalEnvironment; 907 HashMap<String, DartObjectImpl> _lexicalEnvironment;
904 908
905 /** 909 /**
910 * Error reporter that we use to report errors accumulated while computing the constant.
911 */
912 final ErrorReporter _errorReporter;
913
914 /**
915 * Helper class used to compute constant values.
916 */
917 DartObjectComputer _dartObjectComputer;
918
919 /**
906 * Initialize a newly created constant visitor. 920 * Initialize a newly created constant visitor.
907 * 921 *
908 * @param typeProvider the type provider used to access known types 922 * @param typeProvider the type provider used to access known types
909 * @param lexicalEnvironment values which should override simpleIdentifiers, o r null if no 923 * @param lexicalEnvironment values which should override simpleIdentifiers, o r null if no
910 * overriding is necessary. 924 * overriding is necessary.
911 */ 925 */
912 ConstantVisitor.con1(this._typeProvider) { 926 ConstantVisitor.con1(this._typeProvider, this._errorReporter) {
913 this._lexicalEnvironment = null; 927 this._lexicalEnvironment = null;
928 this._dartObjectComputer = new DartObjectComputer(_errorReporter, _typeProvi der);
914 } 929 }
915 930
916 /** 931 /**
917 * Initialize a newly created constant visitor. 932 * Initialize a newly created constant visitor.
918 * 933 *
919 * @param typeProvider the type provider used to access known types 934 * @param typeProvider the type provider used to access known types
920 * @param lexicalEnvironment values which should override simpleIdentifiers, o r null if no 935 * @param lexicalEnvironment values which should override simpleIdentifiers, o r null if no
921 * overriding is necessary. 936 * overriding is necessary.
922 */ 937 */
923 ConstantVisitor.con2(this._typeProvider, HashMap<String, DartObjectImpl> lexic alEnvironment) { 938 ConstantVisitor.con2(this._typeProvider, HashMap<String, DartObjectImpl> lexic alEnvironment, this._errorReporter) {
924 this._lexicalEnvironment = lexicalEnvironment; 939 this._lexicalEnvironment = lexicalEnvironment;
925 } 940 this._dartObjectComputer = new DartObjectComputer(_errorReporter, _typeProvi der);
926 941 }
927 @override 942
928 EvaluationResultImpl visitAdjacentStrings(AdjacentStrings node) { 943 @override
929 EvaluationResultImpl result = null; 944 DartObjectImpl visitAdjacentStrings(AdjacentStrings node) {
945 DartObjectImpl result = null;
930 for (StringLiteral string in node.strings) { 946 for (StringLiteral string in node.strings) {
931 if (result == null) { 947 if (result == null) {
932 result = string.accept(this); 948 result = string.accept(this);
933 } else { 949 } else {
934 result = result.concatenate(_typeProvider, node, string.accept(this)); 950 result = _dartObjectComputer.concatenate(node, result, string.accept(thi s));
935 } 951 }
936 } 952 }
937 return result; 953 return result;
938 } 954 }
939 955
940 @override 956 @override
941 EvaluationResultImpl visitBinaryExpression(BinaryExpression node) { 957 DartObjectImpl visitBinaryExpression(BinaryExpression node) {
942 EvaluationResultImpl leftResult = node.leftOperand.accept(this); 958 DartObjectImpl leftResult = node.leftOperand.accept(this);
943 EvaluationResultImpl rightResult = node.rightOperand.accept(this); 959 DartObjectImpl rightResult = node.rightOperand.accept(this);
944 TokenType operatorType = node.operator.type; 960 TokenType operatorType = node.operator.type;
945 // 'null' is almost never good operand 961 // 'null' is almost never good operand
946 if (operatorType != TokenType.BANG_EQ && operatorType != TokenType.EQ_EQ) { 962 if (operatorType != TokenType.BANG_EQ && operatorType != TokenType.EQ_EQ) {
947 if (leftResult is ValidResult && leftResult.isNull || rightResult is Valid Result && rightResult.isNull) { 963 if (leftResult != null && leftResult.isNull || rightResult != null && righ tResult.isNull) {
948 return _error(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION); 964 _error(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION);
965 return null;
949 } 966 }
950 } 967 }
951 // evaluate operator 968 // evaluate operator
952 while (true) { 969 while (true) {
953 if (operatorType == TokenType.AMPERSAND) { 970 if (operatorType == TokenType.AMPERSAND) {
954 return leftResult.bitAnd(_typeProvider, node, rightResult); 971 return _dartObjectComputer.bitAnd(node, leftResult, rightResult);
955 } else if (operatorType == TokenType.AMPERSAND_AMPERSAND) { 972 } else if (operatorType == TokenType.AMPERSAND_AMPERSAND) {
956 return leftResult.logicalAnd(_typeProvider, node, rightResult); 973 return _dartObjectComputer.logicalAnd(node, leftResult, rightResult);
957 } else if (operatorType == TokenType.BANG_EQ) { 974 } else if (operatorType == TokenType.BANG_EQ) {
958 return leftResult.notEqual(_typeProvider, node, rightResult); 975 return _dartObjectComputer.notEqual(node, leftResult, rightResult);
959 } else if (operatorType == TokenType.BAR) { 976 } else if (operatorType == TokenType.BAR) {
960 return leftResult.bitOr(_typeProvider, node, rightResult); 977 return _dartObjectComputer.bitOr(node, leftResult, rightResult);
961 } else if (operatorType == TokenType.BAR_BAR) { 978 } else if (operatorType == TokenType.BAR_BAR) {
962 return leftResult.logicalOr(_typeProvider, node, rightResult); 979 return _dartObjectComputer.logicalOr(node, leftResult, rightResult);
963 } else if (operatorType == TokenType.CARET) { 980 } else if (operatorType == TokenType.CARET) {
964 return leftResult.bitXor(_typeProvider, node, rightResult); 981 return _dartObjectComputer.bitXor(node, leftResult, rightResult);
965 } else if (operatorType == TokenType.EQ_EQ) { 982 } else if (operatorType == TokenType.EQ_EQ) {
966 return leftResult.equalEqual(_typeProvider, node, rightResult); 983 return _dartObjectComputer.equalEqual(node, leftResult, rightResult);
967 } else if (operatorType == TokenType.GT) { 984 } else if (operatorType == TokenType.GT) {
968 return leftResult.greaterThan(_typeProvider, node, rightResult); 985 return _dartObjectComputer.greaterThan(node, leftResult, rightResult);
969 } else if (operatorType == TokenType.GT_EQ) { 986 } else if (operatorType == TokenType.GT_EQ) {
970 return leftResult.greaterThanOrEqual(_typeProvider, node, rightResult); 987 return _dartObjectComputer.greaterThanOrEqual(node, leftResult, rightRes ult);
971 } else if (operatorType == TokenType.GT_GT) { 988 } else if (operatorType == TokenType.GT_GT) {
972 return leftResult.shiftRight(_typeProvider, node, rightResult); 989 return _dartObjectComputer.shiftRight(node, leftResult, rightResult);
973 } else if (operatorType == TokenType.LT) { 990 } else if (operatorType == TokenType.LT) {
974 return leftResult.lessThan(_typeProvider, node, rightResult); 991 return _dartObjectComputer.lessThan(node, leftResult, rightResult);
975 } else if (operatorType == TokenType.LT_EQ) { 992 } else if (operatorType == TokenType.LT_EQ) {
976 return leftResult.lessThanOrEqual(_typeProvider, node, rightResult); 993 return _dartObjectComputer.lessThanOrEqual(node, leftResult, rightResult );
977 } else if (operatorType == TokenType.LT_LT) { 994 } else if (operatorType == TokenType.LT_LT) {
978 return leftResult.shiftLeft(_typeProvider, node, rightResult); 995 return _dartObjectComputer.shiftLeft(node, leftResult, rightResult);
979 } else if (operatorType == TokenType.MINUS) { 996 } else if (operatorType == TokenType.MINUS) {
980 return leftResult.minus(_typeProvider, node, rightResult); 997 return _dartObjectComputer.minus(node, leftResult, rightResult);
981 } else if (operatorType == TokenType.PERCENT) { 998 } else if (operatorType == TokenType.PERCENT) {
982 return leftResult.remainder(_typeProvider, node, rightResult); 999 return _dartObjectComputer.remainder(node, leftResult, rightResult);
983 } else if (operatorType == TokenType.PLUS) { 1000 } else if (operatorType == TokenType.PLUS) {
984 return leftResult.add(_typeProvider, node, rightResult); 1001 return _dartObjectComputer.add(node, leftResult, rightResult);
985 } else if (operatorType == TokenType.STAR) { 1002 } else if (operatorType == TokenType.STAR) {
986 return leftResult.times(_typeProvider, node, rightResult); 1003 return _dartObjectComputer.times(node, leftResult, rightResult);
987 } else if (operatorType == TokenType.SLASH) { 1004 } else if (operatorType == TokenType.SLASH) {
988 return leftResult.divide(_typeProvider, node, rightResult); 1005 return _dartObjectComputer.divide(node, leftResult, rightResult);
989 } else if (operatorType == TokenType.TILDE_SLASH) { 1006 } else if (operatorType == TokenType.TILDE_SLASH) {
990 return leftResult.integerDivide(_typeProvider, node, rightResult); 1007 return _dartObjectComputer.integerDivide(node, leftResult, rightResult);
991 } else { 1008 } else {
992 // TODO(brianwilkerson) Figure out which error to report. 1009 // TODO(brianwilkerson) Figure out which error to report.
993 return _error(node, null); 1010 _error(node, null);
1011 return null;
994 } 1012 }
995 break; 1013 break;
996 } 1014 }
997 } 1015 }
998 1016
999 @override 1017 @override
1000 EvaluationResultImpl visitBooleanLiteral(BooleanLiteral node) => _valid(_typeP rovider.boolType, BoolState.from(node.value)); 1018 DartObjectImpl visitBooleanLiteral(BooleanLiteral node) => new DartObjectImpl( _typeProvider.boolType, BoolState.from(node.value));
1001 1019
1002 @override 1020 @override
1003 EvaluationResultImpl visitConditionalExpression(ConditionalExpression node) { 1021 DartObjectImpl visitConditionalExpression(ConditionalExpression node) {
1004 Expression condition = node.condition; 1022 Expression condition = node.condition;
1005 EvaluationResultImpl conditionResult = condition.accept(this); 1023 DartObjectImpl conditionResult = condition.accept(this);
1006 EvaluationResultImpl thenResult = node.thenExpression.accept(this); 1024 DartObjectImpl thenResult = node.thenExpression.accept(this);
1007 EvaluationResultImpl elseResult = node.elseExpression.accept(this); 1025 DartObjectImpl elseResult = node.elseExpression.accept(this);
1008 if (conditionResult is ErrorResult) { 1026 if (conditionResult == null) {
1009 return _union(_union(conditionResult as ErrorResult, thenResult), elseResu lt); 1027 return conditionResult;
1010 } else if (!(conditionResult as ValidResult).isBool) { 1028 } else if (!conditionResult.isBool) {
1011 return new ErrorResult.con1(condition, CompileTimeErrorCode.CONST_EVAL_TYP E_BOOL); 1029 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_EVAL_TYPE_BOO L, condition, []);
1012 } else if (thenResult is ErrorResult) { 1030 return null;
1013 return _union(thenResult, elseResult); 1031 } else if (thenResult == null) {
1014 } else if (elseResult is ErrorResult) { 1032 return thenResult;
1033 } else if (elseResult == null) {
1015 return elseResult; 1034 return elseResult;
1016 } 1035 }
1017 conditionResult = conditionResult.applyBooleanConversion(_typeProvider, cond ition); 1036 conditionResult = _dartObjectComputer.applyBooleanConversion(condition, cond itionResult);
1018 if (conditionResult is ErrorResult) { 1037 if (conditionResult == null) {
1019 return conditionResult; 1038 return conditionResult;
1020 } 1039 }
1021 ValidResult validResult = conditionResult as ValidResult; 1040 if (conditionResult.isTrue) {
1022 if (validResult.isTrue) {
1023 return thenResult; 1041 return thenResult;
1024 } else if (validResult.isFalse) { 1042 } else if (conditionResult.isFalse) {
1025 return elseResult; 1043 return elseResult;
1026 } 1044 }
1027 InterfaceType thenType = (thenResult as ValidResult).value.type; 1045 InterfaceType thenType = thenResult.type;
1028 InterfaceType elseType = (elseResult as ValidResult).value.type; 1046 InterfaceType elseType = elseResult.type;
1029 return _validWithUnknownValue(thenType.getLeastUpperBound(elseType) as Inter faceType); 1047 return _validWithUnknownValue(thenType.getLeastUpperBound(elseType) as Inter faceType);
1030 } 1048 }
1031 1049
1032 @override 1050 @override
1033 EvaluationResultImpl visitDoubleLiteral(DoubleLiteral node) => _valid(_typePro vider.doubleType, new DoubleState(node.value)); 1051 DartObjectImpl visitDoubleLiteral(DoubleLiteral node) => new DartObjectImpl(_t ypeProvider.doubleType, new DoubleState(node.value));
1034 1052
1035 @override 1053 @override
1036 EvaluationResultImpl visitInstanceCreationExpression(InstanceCreationExpressio n node) { 1054 DartObjectImpl visitInstanceCreationExpression(InstanceCreationExpression node ) {
1037 if (!node.isConst) { 1055 if (!node.isConst) {
1038 // TODO(brianwilkerson) Figure out which error to report. 1056 // TODO(brianwilkerson) Figure out which error to report.
1039 return _error(node, null); 1057 _error(node, null);
1058 return null;
1040 } 1059 }
1041 beforeGetEvaluationResult(node); 1060 beforeGetEvaluationResult(node);
1042 EvaluationResultImpl result = node.evaluationResult; 1061 EvaluationResultImpl result = node.evaluationResult;
1043 if (result != null) { 1062 if (result != null) {
1044 return result; 1063 return result.value;
1045 } 1064 }
1046 // TODO(brianwilkerson) Figure out which error to report. 1065 // TODO(brianwilkerson) Figure out which error to report.
1047 return _error(node, null); 1066 _error(node, null);
1048 } 1067 return null;
1049 1068 }
1050 @override 1069
1051 EvaluationResultImpl visitIntegerLiteral(IntegerLiteral node) => _valid(_typeP rovider.intType, new IntState(node.value)); 1070 @override
1052 1071 DartObjectImpl visitIntegerLiteral(IntegerLiteral node) => new DartObjectImpl( _typeProvider.intType, new IntState(node.value));
1053 @override 1072
1054 EvaluationResultImpl visitInterpolationExpression(InterpolationExpression node ) { 1073 @override
1055 EvaluationResultImpl result = node.expression.accept(this); 1074 DartObjectImpl visitInterpolationExpression(InterpolationExpression node) {
1056 if (result is ValidResult && !result.isBoolNumStringOrNull) { 1075 DartObjectImpl result = node.expression.accept(this);
1057 return _error(node, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING); 1076 if (result != null && !result.isBoolNumStringOrNull) {
1058 } 1077 _error(node, CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING);
1059 return result.performToString(_typeProvider, node); 1078 return null;
1060 } 1079 }
1061 1080 return _dartObjectComputer.performToString(node, result);
1062 @override 1081 }
1063 EvaluationResultImpl visitInterpolationString(InterpolationString node) => _va lid(_typeProvider.stringType, new StringState(node.value)); 1082
1064 1083 @override
1065 @override 1084 DartObjectImpl visitInterpolationString(InterpolationString node) => new DartO bjectImpl(_typeProvider.stringType, new StringState(node.value));
1066 EvaluationResultImpl visitListLiteral(ListLiteral node) { 1085
1086 @override
1087 DartObjectImpl visitListLiteral(ListLiteral node) {
1067 if (node.constKeyword == null) { 1088 if (node.constKeyword == null) {
1068 return new ErrorResult.con1(node, CompileTimeErrorCode.MISSING_CONST_IN_LI ST_LITERAL); 1089 _errorReporter.reportErrorForNode(CompileTimeErrorCode.MISSING_CONST_IN_LI ST_LITERAL, node, []);
1069 } 1090 return null;
1070 ErrorResult result = null; 1091 }
1092 bool errorOccurred = false;
1071 List<DartObjectImpl> elements = new List<DartObjectImpl>(); 1093 List<DartObjectImpl> elements = new List<DartObjectImpl>();
1072 for (Expression element in node.elements) { 1094 for (Expression element in node.elements) {
1073 EvaluationResultImpl elementResult = element.accept(this); 1095 DartObjectImpl elementResult = element.accept(this);
1074 result = _union(result, elementResult); 1096 if (elementResult == null) {
1075 if (elementResult is ValidResult) { 1097 errorOccurred = true;
1076 elements.add(elementResult.value); 1098 } else {
1077 } 1099 elements.add(elementResult);
1078 } 1100 }
1079 if (result != null) { 1101 }
1080 return result; 1102 if (errorOccurred) {
1081 } 1103 return null;
1082 return _valid(_typeProvider.listType, new ListState(new List.from(elements)) ); 1104 }
1083 } 1105 return new DartObjectImpl(_typeProvider.listType, new ListState(new List.fro m(elements)));
1084 1106 }
1085 @override 1107
1086 EvaluationResultImpl visitMapLiteral(MapLiteral node) { 1108 @override
1109 DartObjectImpl visitMapLiteral(MapLiteral node) {
1087 if (node.constKeyword == null) { 1110 if (node.constKeyword == null) {
1088 return new ErrorResult.con1(node, CompileTimeErrorCode.MISSING_CONST_IN_MA P_LITERAL); 1111 _errorReporter.reportErrorForNode(CompileTimeErrorCode.MISSING_CONST_IN_MA P_LITERAL, node, []);
1089 } 1112 return null;
1090 ErrorResult result = null; 1113 }
1114 bool errorOccurred = false;
1091 HashMap<DartObjectImpl, DartObjectImpl> map = new HashMap<DartObjectImpl, Da rtObjectImpl>(); 1115 HashMap<DartObjectImpl, DartObjectImpl> map = new HashMap<DartObjectImpl, Da rtObjectImpl>();
1092 for (MapLiteralEntry entry in node.entries) { 1116 for (MapLiteralEntry entry in node.entries) {
1093 EvaluationResultImpl keyResult = entry.key.accept(this); 1117 DartObjectImpl keyResult = entry.key.accept(this);
1094 EvaluationResultImpl valueResult = entry.value.accept(this); 1118 DartObjectImpl valueResult = entry.value.accept(this);
1095 result = _union(result, keyResult); 1119 if (keyResult == null || valueResult == null) {
1096 result = _union(result, valueResult); 1120 errorOccurred = true;
1097 if (keyResult is ValidResult && valueResult is ValidResult) { 1121 } else {
1098 map[keyResult.value] = valueResult.value; 1122 map[keyResult] = valueResult;
1099 } 1123 }
1100 } 1124 }
1101 if (result != null) { 1125 if (errorOccurred) {
1102 return result; 1126 return null;
1103 } 1127 }
1104 return _valid(_typeProvider.mapType, new MapState(map)); 1128 return new DartObjectImpl(_typeProvider.mapType, new MapState(map));
1105 } 1129 }
1106 1130
1107 @override 1131 @override
1108 EvaluationResultImpl visitMethodInvocation(MethodInvocation node) { 1132 DartObjectImpl visitMethodInvocation(MethodInvocation node) {
1109 Element element = node.methodName.staticElement; 1133 Element element = node.methodName.staticElement;
1110 if (element is FunctionElement) { 1134 if (element is FunctionElement) {
1111 FunctionElement function = element; 1135 FunctionElement function = element;
1112 if (function.name == "identical") { 1136 if (function.name == "identical") {
1113 NodeList<Expression> arguments = node.argumentList.arguments; 1137 NodeList<Expression> arguments = node.argumentList.arguments;
1114 if (arguments.length == 2) { 1138 if (arguments.length == 2) {
1115 Element enclosingElement = function.enclosingElement; 1139 Element enclosingElement = function.enclosingElement;
1116 if (enclosingElement is CompilationUnitElement) { 1140 if (enclosingElement is CompilationUnitElement) {
1117 LibraryElement library = enclosingElement.library; 1141 LibraryElement library = enclosingElement.library;
1118 if (library.isDartCore) { 1142 if (library.isDartCore) {
1119 EvaluationResultImpl leftArgument = arguments[0].accept(this); 1143 DartObjectImpl leftArgument = arguments[0].accept(this);
1120 EvaluationResultImpl rightArgument = arguments[1].accept(this); 1144 DartObjectImpl rightArgument = arguments[1].accept(this);
1121 return leftArgument.equalEqual(_typeProvider, node, rightArgument) ; 1145 return _dartObjectComputer.equalEqual(node, leftArgument, rightArg ument);
1122 } 1146 }
1123 } 1147 }
1124 } 1148 }
1125 } 1149 }
1126 } 1150 }
1127 // TODO(brianwilkerson) Figure out which error to report. 1151 // TODO(brianwilkerson) Figure out which error to report.
1128 return _error(node, null); 1152 _error(node, null);
1153 return null;
1129 } 1154 }
1130 1155
1131 @override 1156 @override
1132 EvaluationResultImpl visitNamedExpression(NamedExpression node) => node.expres sion.accept(this); 1157 DartObjectImpl visitNamedExpression(NamedExpression node) => node.expression.a ccept(this);
1133 1158
1134 @override 1159 @override
1135 EvaluationResultImpl visitNode(AstNode node) => _error(node, null); 1160 DartObjectImpl visitNode(AstNode node) {
1161 // TODO(brianwilkerson) Figure out which error to report.
1162 _error(node, null);
1163 return null;
1164 }
1136 1165
1137 @override 1166 @override
1138 EvaluationResultImpl visitNullLiteral(NullLiteral node) => new ValidResult(nul l2); 1167 DartObjectImpl visitNullLiteral(NullLiteral node) => null2;
1139 1168
1140 @override 1169 @override
1141 EvaluationResultImpl visitParenthesizedExpression(ParenthesizedExpression node ) => node.expression.accept(this); 1170 DartObjectImpl visitParenthesizedExpression(ParenthesizedExpression node) => n ode.expression.accept(this);
1142 1171
1143 @override 1172 @override
1144 EvaluationResultImpl visitPrefixedIdentifier(PrefixedIdentifier node) { 1173 DartObjectImpl visitPrefixedIdentifier(PrefixedIdentifier node) {
1145 // validate prefix 1174 // TODO(brianwilkerson) Uncomment the lines below when the new constant supp ort can be added.
1175 // Element element = node.getStaticElement();
1176 // if (isStringLength(element)) {
1177 // EvaluationResultImpl target = node.getPrefix().accept(this);
1178 // return target.stringLength(typeProvider, node);
1179 // }
1146 SimpleIdentifier prefixNode = node.prefix; 1180 SimpleIdentifier prefixNode = node.prefix;
1147 Element prefixElement = prefixNode.staticElement; 1181 Element prefixElement = prefixNode.staticElement;
1148 if (prefixElement is! PrefixElement) { 1182 if (prefixElement is! PrefixElement) {
1149 EvaluationResultImpl prefixResult = prefixNode.accept(this); 1183 DartObjectImpl prefixResult = prefixNode.accept(this);
1150 if (prefixResult is! ValidResult) { 1184 if (prefixResult == null) {
1151 return _error(node, null); 1185 // The error has already been reported.
1186 return null;
1152 } 1187 }
1153 } 1188 }
1154 // validate prefixed identifier 1189 // validate prefixed identifier
1155 return _getConstantValue(node, node.staticElement); 1190 return _getConstantValue(node, node.staticElement);
1156 } 1191 }
1157 1192
1158 @override 1193 @override
1159 EvaluationResultImpl visitPrefixExpression(PrefixExpression node) { 1194 DartObjectImpl visitPrefixExpression(PrefixExpression node) {
1160 EvaluationResultImpl operand = node.operand.accept(this); 1195 DartObjectImpl operand = node.operand.accept(this);
1161 if (operand is ValidResult && operand.isNull) { 1196 if (operand != null && operand.isNull) {
1162 return _error(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION); 1197 _error(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION);
1198 return null;
1163 } 1199 }
1164 while (true) { 1200 while (true) {
1165 if (node.operator.type == TokenType.BANG) { 1201 if (node.operator.type == TokenType.BANG) {
1166 return operand.logicalNot(_typeProvider, node); 1202 return _dartObjectComputer.logicalNot(node, operand);
1167 } else if (node.operator.type == TokenType.TILDE) { 1203 } else if (node.operator.type == TokenType.TILDE) {
1168 return operand.bitNot(_typeProvider, node); 1204 return _dartObjectComputer.bitNot(node, operand);
1169 } else if (node.operator.type == TokenType.MINUS) { 1205 } else if (node.operator.type == TokenType.MINUS) {
1170 return operand.negated(_typeProvider, node); 1206 return _dartObjectComputer.negated(node, operand);
1171 } else { 1207 } else {
1172 // TODO(brianwilkerson) Figure out which error to report. 1208 // TODO(brianwilkerson) Figure out which error to report.
1173 return _error(node, null); 1209 _error(node, null);
1210 return null;
1174 } 1211 }
1175 break; 1212 break;
1176 } 1213 }
1177 } 1214 }
1178 1215
1179 @override 1216 @override
1180 EvaluationResultImpl visitPropertyAccess(PropertyAccess node) => _getConstantV alue(node, node.propertyName.staticElement); 1217 DartObjectImpl visitPropertyAccess(PropertyAccess node) {
1218 Element element = node.propertyName.staticElement;
1219 // TODO(brianwilkerson) Uncomment the lines below when the new constant supp ort can be added.
1220 // if (isStringLength(element)) {
1221 // EvaluationResultImpl target = node.getRealTarget().accept(this);
1222 // return target.stringLength(typeProvider, node);
1223 // }
1224 return _getConstantValue(node, element);
1225 }
1181 1226
1182 @override 1227 @override
1183 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) { 1228 DartObjectImpl visitSimpleIdentifier(SimpleIdentifier node) {
1184 if (_lexicalEnvironment != null && _lexicalEnvironment.containsKey(node.name )) { 1229 if (_lexicalEnvironment != null && _lexicalEnvironment.containsKey(node.name )) {
1185 return new ValidResult(_lexicalEnvironment[node.name]); 1230 return _lexicalEnvironment[node.name];
1186 } 1231 }
1187 return _getConstantValue(node, node.staticElement); 1232 return _getConstantValue(node, node.staticElement);
1188 } 1233 }
1189 1234
1190 @override 1235 @override
1191 EvaluationResultImpl visitSimpleStringLiteral(SimpleStringLiteral node) => _va lid(_typeProvider.stringType, new StringState(node.value)); 1236 DartObjectImpl visitSimpleStringLiteral(SimpleStringLiteral node) => new DartO bjectImpl(_typeProvider.stringType, new StringState(node.value));
1192 1237
1193 @override 1238 @override
1194 EvaluationResultImpl visitStringInterpolation(StringInterpolation node) { 1239 DartObjectImpl visitStringInterpolation(StringInterpolation node) {
1195 EvaluationResultImpl result = null; 1240 DartObjectImpl result = null;
1241 bool first = true;
1196 for (InterpolationElement element in node.elements) { 1242 for (InterpolationElement element in node.elements) {
1197 if (result == null) { 1243 if (first) {
1198 result = element.accept(this); 1244 result = element.accept(this);
1245 first = false;
1199 } else { 1246 } else {
1200 result = result.concatenate(_typeProvider, node, element.accept(this)); 1247 result = _dartObjectComputer.concatenate(node, result, element.accept(th is));
1201 } 1248 }
1202 } 1249 }
1203 return result; 1250 return result;
1204 } 1251 }
1205 1252
1206 @override 1253 @override
1207 EvaluationResultImpl visitSymbolLiteral(SymbolLiteral node) { 1254 DartObjectImpl visitSymbolLiteral(SymbolLiteral node) {
1208 JavaStringBuilder builder = new JavaStringBuilder(); 1255 JavaStringBuilder builder = new JavaStringBuilder();
1209 List<Token> components = node.components; 1256 List<Token> components = node.components;
1210 for (int i = 0; i < components.length; i++) { 1257 for (int i = 0; i < components.length; i++) {
1211 if (i > 0) { 1258 if (i > 0) {
1212 builder.appendChar(0x2E); 1259 builder.appendChar(0x2E);
1213 } 1260 }
1214 builder.append(components[i].lexeme); 1261 builder.append(components[i].lexeme);
1215 } 1262 }
1216 return _valid(_typeProvider.symbolType, new SymbolState(builder.toString())) ; 1263 return new DartObjectImpl(_typeProvider.symbolType, new SymbolState(builder. toString()));
1217 } 1264 }
1218 1265
1219 /** 1266 /**
1220 * This method is called just before retrieving an evaluation result from an A ST node. Unit tests 1267 * This method is called just before retrieving an evaluation result from an A ST node. Unit tests
1221 * will override it to introduce additional error checking. 1268 * will override it to introduce additional error checking.
1222 */ 1269 */
1223 void beforeGetEvaluationResult(AstNode node) { 1270 void beforeGetEvaluationResult(AstNode node) {
1224 } 1271 }
1225 1272
1226 /** 1273 /**
1227 * Return an object representing the value 'null'. 1274 * Return an object representing the value 'null'.
1228 * 1275 *
1229 * @return an object representing the value 'null' 1276 * @return an object representing the value 'null'
1230 */ 1277 */
1231 DartObjectImpl get null2 { 1278 DartObjectImpl get null2 {
1232 if (_nullObject == null) { 1279 if (_nullObject == null) {
1233 _nullObject = new DartObjectImpl(_typeProvider.nullType, NullState.NULL_ST ATE); 1280 _nullObject = new DartObjectImpl(_typeProvider.nullType, NullState.NULL_ST ATE);
1234 } 1281 }
1235 return _nullObject; 1282 return _nullObject;
1236 } 1283 }
1237 1284
1238 ValidResult _valid(InterfaceType type, InstanceState state) => new ValidResult (new DartObjectImpl(type, state)); 1285 DartObjectImpl _validWithUnknownValue(InterfaceType type) {
1239
1240 ValidResult _validWithUnknownValue(InterfaceType type) {
1241 if (type.element.library.isDartCore) { 1286 if (type.element.library.isDartCore) {
1242 String typeName = type.name; 1287 String typeName = type.name;
1243 if (typeName == "bool") { 1288 if (typeName == "bool") {
1244 return _valid(type, BoolState.UNKNOWN_VALUE); 1289 return new DartObjectImpl(type, BoolState.UNKNOWN_VALUE);
1245 } else if (typeName == "double") { 1290 } else if (typeName == "double") {
1246 return _valid(type, DoubleState.UNKNOWN_VALUE); 1291 return new DartObjectImpl(type, DoubleState.UNKNOWN_VALUE);
1247 } else if (typeName == "int") { 1292 } else if (typeName == "int") {
1248 return _valid(type, IntState.UNKNOWN_VALUE); 1293 return new DartObjectImpl(type, IntState.UNKNOWN_VALUE);
1249 } else if (typeName == "String") { 1294 } else if (typeName == "String") {
1250 return _valid(type, StringState.UNKNOWN_VALUE); 1295 return new DartObjectImpl(type, StringState.UNKNOWN_VALUE);
1251 } 1296 }
1252 } 1297 }
1253 return _valid(type, GenericState.UNKNOWN_VALUE); 1298 return new DartObjectImpl(type, GenericState.UNKNOWN_VALUE);
1254 } 1299 }
1255 1300
1256 /** 1301 /**
1257 * Return the value of the given expression, or a representation of 'null' if the expression 1302 * Return the value of the given expression, or a representation of 'null' if the expression
1258 * cannot be evaluated. 1303 * cannot be evaluated.
1259 * 1304 *
1260 * @param expression the expression whose value is to be returned 1305 * @param expression the expression whose value is to be returned
1261 * @return the value of the given expression 1306 * @return the value of the given expression
1262 */ 1307 */
1263 DartObjectImpl _valueOf(Expression expression) { 1308 DartObjectImpl _valueOf(Expression expression) {
1264 EvaluationResultImpl expressionValue = expression.accept(this); 1309 DartObjectImpl expressionValue = expression.accept(this);
1265 if (expressionValue is ValidResult) { 1310 if (expressionValue != null) {
1266 return expressionValue.value; 1311 return expressionValue;
1267 } 1312 }
1268 return null2; 1313 return null2;
1269 } 1314 }
1270 1315
1271 /** 1316 /**
1272 * Return a result object representing an error associated with the given node . 1317 * Create an error associated with the given node.
1273 * 1318 *
1274 * @param node the AST node associated with the error 1319 * @param node the AST node associated with the error
1275 * @param code the error code indicating the nature of the error 1320 * @param code the error code indicating the nature of the error
1276 * @return a result object representing an error associated with the given nod e
1277 */ 1321 */
1278 ErrorResult _error(AstNode node, ErrorCode code) => new ErrorResult.con1(node, code == null ? CompileTimeErrorCode.INVALID_CONSTANT : code); 1322 void _error(AstNode node, ErrorCode code) {
1323 _errorReporter.reportErrorForNode(code == null ? CompileTimeErrorCode.INVALI D_CONSTANT : code, node, []);
1324 }
1279 1325
1280 /** 1326 /**
1281 * Return the constant value of the static constant represented by the given e lement. 1327 * Return the constant value of the static constant represented by the given e lement.
1282 * 1328 *
1283 * @param node the node to be used if an error needs to be reported 1329 * @param node the node to be used if an error needs to be reported
1284 * @param element the element whose value is to be returned 1330 * @param element the element whose value is to be returned
1285 * @return the constant value of the static constant 1331 * @return the constant value of the static constant
1286 */ 1332 */
1287 EvaluationResultImpl _getConstantValue(AstNode node, Element element) { 1333 DartObjectImpl _getConstantValue(AstNode node, Element element) {
1288 if (element is PropertyAccessorElement) { 1334 if (element is PropertyAccessorElement) {
1289 element = (element as PropertyAccessorElement).variable; 1335 element = (element as PropertyAccessorElement).variable;
1290 } 1336 }
1291 if (element is VariableElementImpl) { 1337 if (element is VariableElementImpl) {
1292 VariableElementImpl variableElementImpl = element; 1338 VariableElementImpl variableElementImpl = element;
1293 beforeGetEvaluationResult(node); 1339 beforeGetEvaluationResult(node);
1294 EvaluationResultImpl value = variableElementImpl.evaluationResult; 1340 EvaluationResultImpl value = variableElementImpl.evaluationResult;
1295 if (variableElementImpl.isConst && value != null) { 1341 if (variableElementImpl.isConst && value != null) {
1296 return value; 1342 return value.value;
1297 } 1343 }
1298 } else if (element is ExecutableElement) { 1344 } else if (element is ExecutableElement) {
1299 ExecutableElement function = element; 1345 ExecutableElement function = element;
1300 if (function.isStatic) { 1346 if (function.isStatic) {
1301 return _valid(_typeProvider.functionType, new FunctionState(function)); 1347 return new DartObjectImpl(_typeProvider.functionType, new FunctionState( function));
1302 } 1348 }
1303 } else if (element is ClassElement || element is FunctionTypeAliasElement) { 1349 } else if (element is ClassElement || element is FunctionTypeAliasElement) {
1304 return _valid(_typeProvider.typeType, new TypeState(element)); 1350 return new DartObjectImpl(_typeProvider.typeType, new TypeState(element));
1305 } 1351 }
1306 // TODO(brianwilkerson) Figure out which error to report. 1352 // TODO(brianwilkerson) Figure out which error to report.
1307 return _error(node, null); 1353 _error(node, null);
1354 return null;
1308 } 1355 }
1309 1356
1310 /** 1357 /**
1311 * Return the union of the errors encoded in the given results. 1358 * Return `true` if the given element represents the 'length' getter in class 'String'.
1312 * 1359 *
1313 * @param leftResult the first set of errors, or `null` if there was no previo us collection 1360 * @param element the element being tested.
1314 * of errors 1361 * @return
1315 * @param rightResult the errors to be added to the collection, or a valid res ult if there are no
1316 * errors to be added
1317 * @return the union of the errors encoded in the given results
1318 */ 1362 */
1319 ErrorResult _union(ErrorResult leftResult, EvaluationResultImpl rightResult) { 1363 bool _isStringLength(Element element) {
1320 if (rightResult is ErrorResult) { 1364 if (element is! PropertyAccessorElement) {
1321 if (leftResult != null) { 1365 return false;
1322 return new ErrorResult.con2(leftResult, rightResult);
1323 } else {
1324 return rightResult;
1325 }
1326 } 1366 }
1327 return leftResult; 1367 PropertyAccessorElement accessor = element as PropertyAccessorElement;
1368 if (!accessor.isGetter || accessor.name != "length") {
1369 return false;
1370 }
1371 Element parent = accessor.enclosingElement;
1372 return parent == _typeProvider.stringType.element;
1328 } 1373 }
1329 } 1374 }
1330 1375
1331 /** 1376 /**
1332 * The interface `DartObject` defines the behavior of objects that represent the state of a 1377 * The interface `DartObject` defines the behavior of objects that represent the state of a
1333 * Dart object. 1378 * Dart object.
1334 */ 1379 */
1335 abstract class DartObject { 1380 abstract class DartObject {
1336 /** 1381 /**
1337 * Return the boolean value of this object, or `null` if either the value of t his object is 1382 * Return the boolean value of this object, or `null` if either the value of t his object is
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 1449
1405 /** 1450 /**
1406 * Return `true` if this object represents the value 'true'. 1451 * Return `true` if this object represents the value 'true'.
1407 * 1452 *
1408 * @return `true` if this object represents the value 'true' 1453 * @return `true` if this object represents the value 'true'
1409 */ 1454 */
1410 bool get isTrue; 1455 bool get isTrue;
1411 } 1456 }
1412 1457
1413 /** 1458 /**
1459 * Instances of the class `DartObjectComputer` contain methods for manipulating instances of a
1460 * Dart class and for collecting errors during evaluation.
1461 */
1462 class DartObjectComputer {
1463 /**
1464 * The error reporter that we are using to collect errors.
1465 */
1466 final ErrorReporter _errorReporter;
1467
1468 /**
1469 * The type provider. Used to create objects of the appropriate types, and to identify when an
1470 * object is of a built-in type.
1471 */
1472 final TypeProvider _typeProvider;
1473
1474 DartObjectComputer(this._errorReporter, this._typeProvider);
1475
1476 DartObjectImpl add(BinaryExpression node, DartObjectImpl leftOperand, DartObje ctImpl rightOperand) {
1477 if (leftOperand != null && rightOperand != null) {
1478 try {
1479 return leftOperand.add(_typeProvider, rightOperand);
1480 } on EvaluationException catch (exception) {
1481 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1482 return null;
1483 }
1484 }
1485 return null;
1486 }
1487
1488 /**
1489 * Return the result of applying boolean conversion to this result.
1490 *
1491 * @param node the node against which errors should be reported
1492 * @return the result of applying boolean conversion to the given value
1493 */
1494 DartObjectImpl applyBooleanConversion(AstNode node, DartObjectImpl evaluationR esult) {
1495 if (evaluationResult != null) {
1496 try {
1497 return evaluationResult.convertToBool(_typeProvider);
1498 } on EvaluationException catch (exception) {
1499 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1500 }
1501 }
1502 return null;
1503 }
1504
1505 DartObjectImpl bitAnd(BinaryExpression node, DartObjectImpl leftOperand, DartO bjectImpl rightOperand) {
1506 if (leftOperand != null && rightOperand != null) {
1507 try {
1508 return leftOperand.bitAnd(_typeProvider, rightOperand);
1509 } on EvaluationException catch (exception) {
1510 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1511 }
1512 }
1513 return null;
1514 }
1515
1516 DartObjectImpl bitNot(Expression node, DartObjectImpl evaluationResult) {
1517 if (evaluationResult != null) {
1518 try {
1519 return evaluationResult.bitNot(_typeProvider);
1520 } on EvaluationException catch (exception) {
1521 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1522 }
1523 }
1524 return null;
1525 }
1526
1527 DartObjectImpl bitOr(BinaryExpression node, DartObjectImpl leftOperand, DartOb jectImpl rightOperand) {
1528 if (leftOperand != null && rightOperand != null) {
1529 try {
1530 return leftOperand.bitOr(_typeProvider, rightOperand);
1531 } on EvaluationException catch (exception) {
1532 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1533 }
1534 }
1535 return null;
1536 }
1537
1538 DartObjectImpl bitXor(BinaryExpression node, DartObjectImpl leftOperand, DartO bjectImpl rightOperand) {
1539 if (leftOperand != null && rightOperand != null) {
1540 try {
1541 return leftOperand.bitXor(_typeProvider, rightOperand);
1542 } on EvaluationException catch (exception) {
1543 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1544 }
1545 }
1546 return null;
1547 }
1548
1549 DartObjectImpl concatenate(Expression node, DartObjectImpl leftOperand, DartOb jectImpl rightOperand) {
1550 if (leftOperand != null && rightOperand != null) {
1551 try {
1552 return leftOperand.concatenate(_typeProvider, rightOperand);
1553 } on EvaluationException catch (exception) {
1554 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1555 }
1556 }
1557 return null;
1558 }
1559
1560 DartObjectImpl divide(BinaryExpression node, DartObjectImpl leftOperand, DartO bjectImpl rightOperand) {
1561 if (leftOperand != null && rightOperand != null) {
1562 try {
1563 return leftOperand.divide(_typeProvider, rightOperand);
1564 } on EvaluationException catch (exception) {
1565 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1566 }
1567 }
1568 return null;
1569 }
1570
1571 DartObjectImpl equalEqual(Expression node, DartObjectImpl leftOperand, DartObj ectImpl rightOperand) {
1572 if (leftOperand != null && rightOperand != null) {
1573 try {
1574 return leftOperand.equalEqual(_typeProvider, rightOperand);
1575 } on EvaluationException catch (exception) {
1576 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1577 }
1578 }
1579 return null;
1580 }
1581
1582 DartObjectImpl greaterThan(BinaryExpression node, DartObjectImpl leftOperand, DartObjectImpl rightOperand) {
1583 if (leftOperand != null && rightOperand != null) {
1584 try {
1585 return leftOperand.greaterThan(_typeProvider, rightOperand);
1586 } on EvaluationException catch (exception) {
1587 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1588 }
1589 }
1590 return null;
1591 }
1592
1593 DartObjectImpl greaterThanOrEqual(BinaryExpression node, DartObjectImpl leftOp erand, DartObjectImpl rightOperand) {
1594 if (leftOperand != null && rightOperand != null) {
1595 try {
1596 return leftOperand.greaterThanOrEqual(_typeProvider, rightOperand);
1597 } on EvaluationException catch (exception) {
1598 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1599 }
1600 }
1601 return null;
1602 }
1603
1604 DartObjectImpl integerDivide(BinaryExpression node, DartObjectImpl leftOperand , DartObjectImpl rightOperand) {
1605 if (leftOperand != null && rightOperand != null) {
1606 try {
1607 return leftOperand.integerDivide(_typeProvider, rightOperand);
1608 } on EvaluationException catch (exception) {
1609 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1610 }
1611 }
1612 return null;
1613 }
1614
1615 DartObjectImpl lessThan(BinaryExpression node, DartObjectImpl leftOperand, Dar tObjectImpl rightOperand) {
1616 if (leftOperand != null && rightOperand != null) {
1617 try {
1618 return leftOperand.lessThan(_typeProvider, rightOperand);
1619 } on EvaluationException catch (exception) {
1620 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1621 }
1622 }
1623 return null;
1624 }
1625
1626 DartObjectImpl lessThanOrEqual(BinaryExpression node, DartObjectImpl leftOpera nd, DartObjectImpl rightOperand) {
1627 if (leftOperand != null && rightOperand != null) {
1628 try {
1629 return leftOperand.lessThanOrEqual(_typeProvider, rightOperand);
1630 } on EvaluationException catch (exception) {
1631 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1632 }
1633 }
1634 return null;
1635 }
1636
1637 DartObjectImpl logicalAnd(BinaryExpression node, DartObjectImpl leftOperand, D artObjectImpl rightOperand) {
1638 if (leftOperand != null && rightOperand != null) {
1639 try {
1640 return leftOperand.logicalAnd(_typeProvider, rightOperand);
1641 } on EvaluationException catch (exception) {
1642 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1643 }
1644 }
1645 return null;
1646 }
1647
1648 DartObjectImpl logicalNot(Expression node, DartObjectImpl evaluationResult) {
1649 if (evaluationResult != null) {
1650 try {
1651 return evaluationResult.logicalNot(_typeProvider);
1652 } on EvaluationException catch (exception) {
1653 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1654 }
1655 }
1656 return null;
1657 }
1658
1659 DartObjectImpl logicalOr(BinaryExpression node, DartObjectImpl leftOperand, Da rtObjectImpl rightOperand) {
1660 if (leftOperand != null && rightOperand != null) {
1661 try {
1662 return leftOperand.logicalOr(_typeProvider, rightOperand);
1663 } on EvaluationException catch (exception) {
1664 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1665 }
1666 }
1667 return null;
1668 }
1669
1670 DartObjectImpl minus(BinaryExpression node, DartObjectImpl leftOperand, DartOb jectImpl rightOperand) {
1671 if (leftOperand != null && rightOperand != null) {
1672 try {
1673 return leftOperand.minus(_typeProvider, rightOperand);
1674 } on EvaluationException catch (exception) {
1675 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1676 }
1677 }
1678 return null;
1679 }
1680
1681 DartObjectImpl negated(Expression node, DartObjectImpl evaluationResult) {
1682 if (evaluationResult != null) {
1683 try {
1684 return evaluationResult.negated(_typeProvider);
1685 } on EvaluationException catch (exception) {
1686 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1687 }
1688 }
1689 return null;
1690 }
1691
1692 DartObjectImpl notEqual(BinaryExpression node, DartObjectImpl leftOperand, Dar tObjectImpl rightOperand) {
1693 if (leftOperand != null && rightOperand != null) {
1694 try {
1695 return leftOperand.notEqual(_typeProvider, rightOperand);
1696 } on EvaluationException catch (exception) {
1697 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1698 }
1699 }
1700 return null;
1701 }
1702
1703 DartObjectImpl performToString(AstNode node, DartObjectImpl evaluationResult) {
1704 if (evaluationResult != null) {
1705 try {
1706 return evaluationResult.performToString(_typeProvider);
1707 } on EvaluationException catch (exception) {
1708 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1709 }
1710 }
1711 return null;
1712 }
1713
1714 DartObjectImpl remainder(BinaryExpression node, DartObjectImpl leftOperand, Da rtObjectImpl rightOperand) {
1715 if (leftOperand != null && rightOperand != null) {
1716 try {
1717 return leftOperand.remainder(_typeProvider, rightOperand);
1718 } on EvaluationException catch (exception) {
1719 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1720 }
1721 }
1722 return null;
1723 }
1724
1725 DartObjectImpl shiftLeft(BinaryExpression node, DartObjectImpl leftOperand, Da rtObjectImpl rightOperand) {
1726 if (leftOperand != null && rightOperand != null) {
1727 try {
1728 return leftOperand.shiftLeft(_typeProvider, rightOperand);
1729 } on EvaluationException catch (exception) {
1730 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1731 }
1732 }
1733 return null;
1734 }
1735
1736 DartObjectImpl shiftRight(BinaryExpression node, DartObjectImpl leftOperand, D artObjectImpl rightOperand) {
1737 if (leftOperand != null && rightOperand != null) {
1738 try {
1739 return leftOperand.shiftRight(_typeProvider, rightOperand);
1740 } on EvaluationException catch (exception) {
1741 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1742 }
1743 }
1744 return null;
1745 }
1746
1747 /**
1748 * Return the result of invoking the 'length' getter on this result.
1749 *
1750 * @param node the node against which errors should be reported
1751 * @return the result of invoking the 'length' getter on this result
1752 */
1753 EvaluationResultImpl stringLength(Expression node, EvaluationResultImpl evalua tionResult) {
1754 if (evaluationResult.value != null) {
1755 try {
1756 return new EvaluationResultImpl.con1(evaluationResult.value.stringLength (_typeProvider));
1757 } on EvaluationException catch (exception) {
1758 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1759 }
1760 }
1761 return new EvaluationResultImpl.con1(null);
1762 }
1763
1764 DartObjectImpl times(BinaryExpression node, DartObjectImpl leftOperand, DartOb jectImpl rightOperand) {
1765 if (leftOperand != null && rightOperand != null) {
1766 try {
1767 return leftOperand.times(_typeProvider, rightOperand);
1768 } on EvaluationException catch (exception) {
1769 _errorReporter.reportErrorForNode(exception.errorCode, node, []);
1770 }
1771 }
1772 return null;
1773 }
1774 }
1775
1776 /**
1414 * Instances of the class `DartObjectImpl` represent an instance of a Dart class . 1777 * Instances of the class `DartObjectImpl` represent an instance of a Dart class .
1415 */ 1778 */
1416 class DartObjectImpl implements DartObject { 1779 class DartObjectImpl implements DartObject {
1417 /** 1780 /**
1418 * The run-time type of this object. 1781 * The run-time type of this object.
1419 */ 1782 */
1420 final InterfaceType type; 1783 final InterfaceType type;
1421 1784
1422 /** 1785 /**
1423 * The state of the object. 1786 * The state of the object.
(...skipping 17 matching lines...) Expand all
1441 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 1804 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
1442 */ 1805 */
1443 DartObjectImpl add(TypeProvider typeProvider, DartObjectImpl rightOperand) { 1806 DartObjectImpl add(TypeProvider typeProvider, DartObjectImpl rightOperand) {
1444 InstanceState result = _state.add(rightOperand._state); 1807 InstanceState result = _state.add(rightOperand._state);
1445 if (result is IntState) { 1808 if (result is IntState) {
1446 return new DartObjectImpl(typeProvider.intType, result); 1809 return new DartObjectImpl(typeProvider.intType, result);
1447 } else if (result is DoubleState) { 1810 } else if (result is DoubleState) {
1448 return new DartObjectImpl(typeProvider.doubleType, result); 1811 return new DartObjectImpl(typeProvider.doubleType, result);
1449 } else if (result is NumState) { 1812 } else if (result is NumState) {
1450 return new DartObjectImpl(typeProvider.numType, result); 1813 return new DartObjectImpl(typeProvider.numType, result);
1814 } else if (result is StringState) {
1815 return new DartObjectImpl(typeProvider.stringType, result);
1451 } 1816 }
1452 // We should never get here. 1817 // We should never get here.
1453 throw new IllegalStateException("add returned a ${result.runtimeType.toStrin g()}"); 1818 throw new IllegalStateException("add returned a ${result.runtimeType.toStrin g()}");
1454 } 1819 }
1455 1820
1456 /** 1821 /**
1457 * Return the result of invoking the '&' operator on this object with the give n argument. 1822 * Return the result of invoking the '&' operator on this object with the give n argument.
1458 * 1823 *
1459 * @param typeProvider the type provider used to find known types 1824 * @param typeProvider the type provider used to find known types
1460 * @param rightOperand the right-hand operand of the operation 1825 * @param rightOperand the right-hand operand of the operation
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1832 * Return the result of invoking the '&gt;&gt;' operator on this object with t he given argument. 2197 * Return the result of invoking the '&gt;&gt;' operator on this object with t he given argument.
1833 * 2198 *
1834 * @param typeProvider the type provider used to find known types 2199 * @param typeProvider the type provider used to find known types
1835 * @param rightOperand the right-hand operand of the operation 2200 * @param rightOperand the right-hand operand of the operation
1836 * @return the result of invoking the '&gt;&gt;' operator on this object with the given argument 2201 * @return the result of invoking the '&gt;&gt;' operator on this object with the given argument
1837 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2202 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
1838 */ 2203 */
1839 DartObjectImpl shiftRight(TypeProvider typeProvider, DartObjectImpl rightOpera nd) => new DartObjectImpl(typeProvider.intType, _state.shiftRight(rightOperand._ state)); 2204 DartObjectImpl shiftRight(TypeProvider typeProvider, DartObjectImpl rightOpera nd) => new DartObjectImpl(typeProvider.intType, _state.shiftRight(rightOperand._ state));
1840 2205
1841 /** 2206 /**
2207 * Return the result of invoking the 'length' getter on this object.
2208 *
2209 * @param typeProvider the type provider used to find known types
2210 * @return the result of invoking the 'length' getter on this object
2211 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2212 */
2213 DartObjectImpl stringLength(TypeProvider typeProvider) => new DartObjectImpl(t ypeProvider.intType, _state.stringLength());
2214
2215 /**
1842 * Return the result of invoking the '*' operator on this object with the give n argument. 2216 * Return the result of invoking the '*' operator on this object with the give n argument.
1843 * 2217 *
1844 * @param typeProvider the type provider used to find known types 2218 * @param typeProvider the type provider used to find known types
1845 * @param rightOperand the right-hand operand of the operation 2219 * @param rightOperand the right-hand operand of the operation
1846 * @return the result of invoking the '*' operator on this object with the giv en argument 2220 * @return the result of invoking the '*' operator on this object with the giv en argument
1847 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2221 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
1848 */ 2222 */
1849 DartObjectImpl times(TypeProvider typeProvider, DartObjectImpl rightOperand) { 2223 DartObjectImpl times(TypeProvider typeProvider, DartObjectImpl rightOperand) {
1850 InstanceState result = _state.times(rightOperand._state); 2224 InstanceState result = _state.times(rightOperand._state);
1851 if (result is IntState) { 2225 if (result is IntState) {
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
2431 if (rightOperand is IntState) { 2805 if (rightOperand is IntState) {
2432 return IntState.UNKNOWN_VALUE; 2806 return IntState.UNKNOWN_VALUE;
2433 } else if (rightOperand is DoubleState) { 2807 } else if (rightOperand is DoubleState) {
2434 return DoubleState.UNKNOWN_VALUE; 2808 return DoubleState.UNKNOWN_VALUE;
2435 } 2809 }
2436 return NumState.UNKNOWN_VALUE; 2810 return NumState.UNKNOWN_VALUE;
2437 } 2811 }
2438 } 2812 }
2439 2813
2440 /** 2814 /**
2441 * Instances of the class `ErrorResult` represent the result of evaluating an ex pression that
2442 * is not a valid compile time constant.
2443 */
2444 class ErrorResult extends EvaluationResultImpl {
2445 /**
2446 * The errors that prevent the expression from being a valid compile time cons tant.
2447 */
2448 List<ErrorResult_ErrorData> _errors = new List<ErrorResult_ErrorData>();
2449
2450 /**
2451 * Initialize a newly created result representing the error with the given cod e reported against
2452 * the given node.
2453 *
2454 * @param node the node against which the error should be reported
2455 * @param errorCode the error code for the error to be generated
2456 */
2457 ErrorResult.con1(AstNode node, ErrorCode errorCode) {
2458 _errors.add(new ErrorResult_ErrorData(node, errorCode));
2459 }
2460
2461 /**
2462 * Initialize a newly created result to represent the union of the errors in t he given result
2463 * objects.
2464 *
2465 * @param firstResult the first set of results being merged
2466 * @param secondResult the second set of results being merged
2467 */
2468 ErrorResult.con2(ErrorResult firstResult, ErrorResult secondResult) {
2469 _errors.addAll(firstResult._errors);
2470 _errors.addAll(secondResult._errors);
2471 }
2472
2473 @override
2474 EvaluationResultImpl add(TypeProvider typeProvider, BinaryExpression node, Eva luationResultImpl rightOperand) => rightOperand.addToError(node, this);
2475
2476 @override
2477 EvaluationResultImpl applyBooleanConversion(TypeProvider typeProvider, AstNode node) => this;
2478
2479 @override
2480 EvaluationResultImpl bitAnd(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.bitAndError(node, this);
2481
2482 @override
2483 EvaluationResultImpl bitNot(TypeProvider typeProvider, Expression node) => thi s;
2484
2485 @override
2486 EvaluationResultImpl bitOr(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.bitOrError(node, this);
2487
2488 @override
2489 EvaluationResultImpl bitXor(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.bitXorError(node, this);
2490
2491 @override
2492 EvaluationResultImpl concatenate(TypeProvider typeProvider, Expression node, E valuationResultImpl rightOperand) => rightOperand.concatenateError(node, this);
2493
2494 @override
2495 EvaluationResultImpl divide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.divideError(node, this);
2496
2497 @override
2498 EvaluationResultImpl equalEqual(TypeProvider typeProvider, Expression node, Ev aluationResultImpl rightOperand) => rightOperand.equalEqualError(node, this);
2499
2500 @override
2501 bool equalValues(TypeProvider typeProvider, EvaluationResultImpl result) => fa lse;
2502
2503 List<ErrorResult_ErrorData> get errorData => _errors;
2504
2505 @override
2506 EvaluationResultImpl greaterThan(TypeProvider typeProvider, BinaryExpression n ode, EvaluationResultImpl rightOperand) => rightOperand.greaterThanError(node, t his);
2507
2508 @override
2509 EvaluationResultImpl greaterThanOrEqual(TypeProvider typeProvider, BinaryExpre ssion node, EvaluationResultImpl rightOperand) => rightOperand.greaterThanOrEqua lError(node, this);
2510
2511 @override
2512 EvaluationResultImpl integerDivide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.integerDivideError(nod e, this);
2513
2514 @override
2515 EvaluationResultImpl integerDivideValid(TypeProvider typeProvider, BinaryExpre ssion node, ValidResult leftOperand) => this;
2516
2517 @override
2518 EvaluationResultImpl lessThan(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand) => rightOperand.lessThanError(node, this);
2519
2520 @override
2521 EvaluationResultImpl lessThanOrEqual(TypeProvider typeProvider, BinaryExpressi on node, EvaluationResultImpl rightOperand) => rightOperand.lessThanOrEqualError (node, this);
2522
2523 @override
2524 EvaluationResultImpl logicalAnd(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand) => rightOperand.logicalAndError(node, thi s);
2525
2526 @override
2527 EvaluationResultImpl logicalNot(TypeProvider typeProvider, Expression node) => this;
2528
2529 @override
2530 EvaluationResultImpl logicalOr(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.logicalOrError(node, this) ;
2531
2532 @override
2533 EvaluationResultImpl minus(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.minusError(node, this);
2534
2535 @override
2536 EvaluationResultImpl negated(TypeProvider typeProvider, Expression node) => th is;
2537
2538 @override
2539 EvaluationResultImpl notEqual(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand) => rightOperand.notEqualError(node, this);
2540
2541 @override
2542 EvaluationResultImpl performToString(TypeProvider typeProvider, AstNode node) => this;
2543
2544 @override
2545 EvaluationResultImpl remainder(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.remainderError(node, this) ;
2546
2547 @override
2548 EvaluationResultImpl shiftLeft(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.shiftLeftError(node, this) ;
2549
2550 @override
2551 EvaluationResultImpl shiftRight(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand) => rightOperand.shiftRightError(node, thi s);
2552
2553 @override
2554 EvaluationResultImpl times(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.timesError(node, this);
2555
2556 @override
2557 EvaluationResultImpl addToError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
2558
2559 @override
2560 EvaluationResultImpl addToValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) => this;
2561
2562 @override
2563 EvaluationResultImpl bitAndError(BinaryExpression node, ErrorResult leftOperan d) => new ErrorResult.con2(this, leftOperand);
2564
2565 @override
2566 EvaluationResultImpl bitAndValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) => this;
2567
2568 @override
2569 EvaluationResultImpl bitOrError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
2570
2571 @override
2572 EvaluationResultImpl bitOrValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) => this;
2573
2574 @override
2575 EvaluationResultImpl bitXorError(BinaryExpression node, ErrorResult leftOperan d) => new ErrorResult.con2(this, leftOperand);
2576
2577 @override
2578 EvaluationResultImpl bitXorValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) => this;
2579
2580 @override
2581 EvaluationResultImpl concatenateError(Expression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
2582
2583 @override
2584 EvaluationResultImpl concatenateValid(TypeProvider typeProvider, Expression no de, ValidResult leftOperand) => this;
2585
2586 @override
2587 EvaluationResultImpl divideError(BinaryExpression node, ErrorResult leftOperan d) => new ErrorResult.con2(this, leftOperand);
2588
2589 @override
2590 EvaluationResultImpl divideValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) => this;
2591
2592 @override
2593 EvaluationResultImpl equalEqualError(Expression node, ErrorResult leftOperand) => new ErrorResult.con2(this, leftOperand);
2594
2595 @override
2596 EvaluationResultImpl equalEqualValid(TypeProvider typeProvider, Expression nod e, ValidResult leftOperand) => this;
2597
2598 @override
2599 EvaluationResultImpl greaterThanError(BinaryExpression node, ErrorResult leftO perand) => new ErrorResult.con2(this, leftOperand);
2600
2601 @override
2602 EvaluationResultImpl greaterThanOrEqualError(BinaryExpression node, ErrorResul t leftOperand) => new ErrorResult.con2(this, leftOperand);
2603
2604 @override
2605 EvaluationResultImpl greaterThanOrEqualValid(TypeProvider typeProvider, Binary Expression node, ValidResult leftOperand) => this;
2606
2607 @override
2608 EvaluationResultImpl greaterThanValid(TypeProvider typeProvider, BinaryExpress ion node, ValidResult leftOperand) => this;
2609
2610 @override
2611 EvaluationResultImpl integerDivideError(BinaryExpression node, ErrorResult lef tOperand) => new ErrorResult.con2(this, leftOperand);
2612
2613 @override
2614 EvaluationResultImpl lessThanError(BinaryExpression node, ErrorResult leftOper and) => new ErrorResult.con2(this, leftOperand);
2615
2616 @override
2617 EvaluationResultImpl lessThanOrEqualError(BinaryExpression node, ErrorResult l eftOperand) => new ErrorResult.con2(this, leftOperand);
2618
2619 @override
2620 EvaluationResultImpl lessThanOrEqualValid(TypeProvider typeProvider, BinaryExp ression node, ValidResult leftOperand) => this;
2621
2622 @override
2623 EvaluationResultImpl lessThanValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand) => this;
2624
2625 @override
2626 EvaluationResultImpl logicalAndError(BinaryExpression node, ErrorResult leftOp erand) => new ErrorResult.con2(this, leftOperand);
2627
2628 @override
2629 EvaluationResultImpl logicalAndValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand) => this;
2630
2631 @override
2632 EvaluationResultImpl logicalOrError(BinaryExpression node, ErrorResult leftOpe rand) => new ErrorResult.con2(this, leftOperand);
2633
2634 @override
2635 EvaluationResultImpl logicalOrValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) => this;
2636
2637 @override
2638 EvaluationResultImpl minusError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
2639
2640 @override
2641 EvaluationResultImpl minusValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) => this;
2642
2643 @override
2644 EvaluationResultImpl notEqualError(BinaryExpression node, ErrorResult leftOper and) => new ErrorResult.con2(this, leftOperand);
2645
2646 @override
2647 EvaluationResultImpl notEqualValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand) => this;
2648
2649 @override
2650 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe rand) => new ErrorResult.con2(this, leftOperand);
2651
2652 @override
2653 EvaluationResultImpl remainderValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) => this;
2654
2655 @override
2656 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe rand) => new ErrorResult.con2(this, leftOperand);
2657
2658 @override
2659 EvaluationResultImpl shiftLeftValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) => this;
2660
2661 @override
2662 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp erand) => new ErrorResult.con2(this, leftOperand);
2663
2664 @override
2665 EvaluationResultImpl shiftRightValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand) => this;
2666
2667 @override
2668 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand ) => new ErrorResult.con2(this, leftOperand);
2669
2670 @override
2671 EvaluationResultImpl timesValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) => this;
2672 }
2673
2674 class ErrorResult_ErrorData {
2675 /**
2676 * The node against which the error should be reported.
2677 */
2678 final AstNode node;
2679
2680 /**
2681 * The error code for the error to be generated.
2682 */
2683 final ErrorCode errorCode;
2684
2685 /**
2686 * Initialize a newly created data holder to represent the error with the give n code reported
2687 * against the given node.
2688 *
2689 * @param node the node against which the error should be reported
2690 * @param errorCode the error code for the error to be generated
2691 */
2692 ErrorResult_ErrorData(this.node, this.errorCode);
2693 }
2694
2695 /**
2696 * Instances of the class `EvaluationException` represent a run-time exception t hat would be 2815 * Instances of the class `EvaluationException` represent a run-time exception t hat would be
2697 * thrown during the evaluation of Dart code. 2816 * thrown during the evaluation of Dart code.
2698 */ 2817 */
2699 class EvaluationException extends JavaException { 2818 class EvaluationException extends JavaException {
2700 /** 2819 /**
2701 * The error code associated with the exception. 2820 * The error code associated with the exception.
2702 */ 2821 */
2703 final ErrorCode errorCode; 2822 final ErrorCode errorCode;
2704 2823
2705 /** 2824 /**
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2766 * 2885 *
2767 * @return `true` if the expression is a valid compile-time constant expressio n 2886 * @return `true` if the expression is a valid compile-time constant expressio n
2768 */ 2887 */
2769 bool get isValid => _errors == null; 2888 bool get isValid => _errors == null;
2770 } 2889 }
2771 2890
2772 /** 2891 /**
2773 * Instances of the class `InternalResult` represent the result of attempting to evaluate a 2892 * Instances of the class `InternalResult` represent the result of attempting to evaluate a
2774 * expression. 2893 * expression.
2775 */ 2894 */
2776 abstract class EvaluationResultImpl { 2895 class EvaluationResultImpl {
2777 EvaluationResultImpl add(TypeProvider typeProvider, BinaryExpression node, Eva luationResultImpl rightOperand); 2896 /**
2778 2897 * The errors encountered while trying to evaluate the compile time constant. These errors may or
2779 /** 2898 * may not have prevented the expression from being a valid compile time const ant.
2780 * Return the result of applying boolean conversion to this result. 2899 */
2781 * 2900 List<AnalysisError> _errors;
2782 * @param typeProvider the type provider used to access known types 2901
2783 * @param node the node against which errors should be reported 2902 /**
2784 * @return the result of applying boolean conversion to the given value 2903 * The value of the expression, or null if the value couldn't be computed due to errors.
2785 */ 2904 */
2786 EvaluationResultImpl applyBooleanConversion(TypeProvider typeProvider, AstNode node); 2905 final DartObjectImpl value;
2787 2906
2788 EvaluationResultImpl bitAnd(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand); 2907 EvaluationResultImpl.con1(this.value) {
2789 2908 this._errors = new List<AnalysisError>(0);
2790 EvaluationResultImpl bitNot(TypeProvider typeProvider, Expression node); 2909 }
2791 2910
2792 EvaluationResultImpl bitOr(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand); 2911 EvaluationResultImpl.con2(this.value, List<AnalysisError> errors) {
2793 2912 this._errors = errors;
2794 EvaluationResultImpl bitXor(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand); 2913 }
2795 2914
2796 EvaluationResultImpl concatenate(TypeProvider typeProvider, Expression node, E valuationResultImpl rightOperand); 2915 bool equalValues(TypeProvider typeProvider, EvaluationResultImpl result) {
2797 2916 if (this.value != null) {
2798 EvaluationResultImpl divide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand); 2917 if (result.value == null) {
2799 2918 return false;
2800 EvaluationResultImpl equalEqual(TypeProvider typeProvider, Expression node, Ev aluationResultImpl rightOperand); 2919 }
2801 2920 return value == result.value;
2802 bool equalValues(TypeProvider typeProvider, EvaluationResultImpl result); 2921 } else {
2803 2922 return false;
2804 EvaluationResultImpl greaterThan(TypeProvider typeProvider, BinaryExpression n ode, EvaluationResultImpl rightOperand); 2923 }
2805 2924 }
2806 EvaluationResultImpl greaterThanOrEqual(TypeProvider typeProvider, BinaryExpre ssion node, EvaluationResultImpl rightOperand); 2925
2807 2926 List<AnalysisError> get errors => _errors;
2808 EvaluationResultImpl integerDivide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand); 2927
2809 2928 @override
2810 EvaluationResultImpl lessThan(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand); 2929 String toString() {
2811 2930 if (value == null) {
2812 EvaluationResultImpl lessThanOrEqual(TypeProvider typeProvider, BinaryExpressi on node, EvaluationResultImpl rightOperand); 2931 return "error";
2813 2932 }
2814 EvaluationResultImpl logicalAnd(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand); 2933 return value.toString();
2815 2934 }
2816 EvaluationResultImpl logicalNot(TypeProvider typeProvider, Expression node);
2817
2818 EvaluationResultImpl logicalOr(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand);
2819
2820 EvaluationResultImpl minus(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand);
2821
2822 EvaluationResultImpl negated(TypeProvider typeProvider, Expression node);
2823
2824 EvaluationResultImpl notEqual(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand);
2825
2826 EvaluationResultImpl performToString(TypeProvider typeProvider, AstNode node);
2827
2828 EvaluationResultImpl remainder(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand);
2829
2830 EvaluationResultImpl shiftLeft(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand);
2831
2832 EvaluationResultImpl shiftRight(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand);
2833
2834 EvaluationResultImpl times(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand);
2835
2836 EvaluationResultImpl addToError(BinaryExpression node, ErrorResult leftOperand );
2837
2838 EvaluationResultImpl addToValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand);
2839
2840 EvaluationResultImpl bitAndError(BinaryExpression node, ErrorResult leftOperan d);
2841
2842 EvaluationResultImpl bitAndValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand);
2843
2844 EvaluationResultImpl bitOrError(BinaryExpression node, ErrorResult leftOperand );
2845
2846 EvaluationResultImpl bitOrValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand);
2847
2848 EvaluationResultImpl bitXorError(BinaryExpression node, ErrorResult leftOperan d);
2849
2850 EvaluationResultImpl bitXorValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand);
2851
2852 EvaluationResultImpl concatenateError(Expression node, ErrorResult leftOperand );
2853
2854 EvaluationResultImpl concatenateValid(TypeProvider typeProvider, Expression no de, ValidResult leftOperand);
2855
2856 EvaluationResultImpl divideError(BinaryExpression node, ErrorResult leftOperan d);
2857
2858 EvaluationResultImpl divideValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand);
2859
2860 EvaluationResultImpl equalEqualError(Expression node, ErrorResult leftOperand) ;
2861
2862 EvaluationResultImpl equalEqualValid(TypeProvider typeProvider, Expression nod e, ValidResult leftOperand);
2863
2864 EvaluationResultImpl greaterThanError(BinaryExpression node, ErrorResult leftO perand);
2865
2866 EvaluationResultImpl greaterThanOrEqualError(BinaryExpression node, ErrorResul t leftOperand);
2867
2868 EvaluationResultImpl greaterThanOrEqualValid(TypeProvider typeProvider, Binary Expression node, ValidResult leftOperand);
2869
2870 EvaluationResultImpl greaterThanValid(TypeProvider typeProvider, BinaryExpress ion node, ValidResult leftOperand);
2871
2872 EvaluationResultImpl integerDivideError(BinaryExpression node, ErrorResult lef tOperand);
2873
2874 EvaluationResultImpl integerDivideValid(TypeProvider typeProvider, BinaryExpre ssion node, ValidResult leftOperand);
2875
2876 EvaluationResultImpl lessThanError(BinaryExpression node, ErrorResult leftOper and);
2877
2878 EvaluationResultImpl lessThanOrEqualError(BinaryExpression node, ErrorResult l eftOperand);
2879
2880 EvaluationResultImpl lessThanOrEqualValid(TypeProvider typeProvider, BinaryExp ression node, ValidResult leftOperand);
2881
2882 EvaluationResultImpl lessThanValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand);
2883
2884 EvaluationResultImpl logicalAndError(BinaryExpression node, ErrorResult leftOp erand);
2885
2886 EvaluationResultImpl logicalAndValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand);
2887
2888 EvaluationResultImpl logicalOrError(BinaryExpression node, ErrorResult leftOpe rand);
2889
2890 EvaluationResultImpl logicalOrValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand);
2891
2892 EvaluationResultImpl minusError(BinaryExpression node, ErrorResult leftOperand );
2893
2894 EvaluationResultImpl minusValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand);
2895
2896 EvaluationResultImpl notEqualError(BinaryExpression node, ErrorResult leftOper and);
2897
2898 EvaluationResultImpl notEqualValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand);
2899
2900 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe rand);
2901
2902 EvaluationResultImpl remainderValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand);
2903
2904 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe rand);
2905
2906 EvaluationResultImpl shiftLeftValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand);
2907
2908 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp erand);
2909
2910 EvaluationResultImpl shiftRightValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand);
2911
2912 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand );
2913
2914 EvaluationResultImpl timesValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand);
2915 } 2935 }
2916 2936
2917 /** 2937 /**
2918 * Instances of the class `FunctionState` represent the state of an object repre senting a 2938 * Instances of the class `FunctionState` represent the state of an object repre senting a
2919 * function. 2939 * function.
2920 */ 2940 */
2921 class FunctionState extends InstanceState { 2941 class FunctionState extends InstanceState {
2922 /** 2942 /**
2923 * The element representing the function being modeled. 2943 * The element representing the function being modeled.
2924 */ 2944 */
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
3053 * object. 3073 * object.
3054 */ 3074 */
3055 abstract class InstanceState { 3075 abstract class InstanceState {
3056 /** 3076 /**
3057 * Return the result of invoking the '+' operator on this object with the give n argument. 3077 * Return the result of invoking the '+' operator on this object with the give n argument.
3058 * 3078 *
3059 * @param rightOperand the right-hand operand of the operation 3079 * @param rightOperand the right-hand operand of the operation
3060 * @return the result of invoking the '+' operator on this object with the giv en argument 3080 * @return the result of invoking the '+' operator on this object with the giv en argument
3061 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 3081 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
3062 */ 3082 */
3063 NumState add(InstanceState rightOperand) { 3083 InstanceState add(InstanceState rightOperand) {
3084 // TODO(brianwilkerson) Uncomment the code below when the new constant suppo rt can be added.
3085 // if (this instanceof StringState || rightOperand instanceof StringState ) {
3086 // return concatenate(rightOperand);
3087 // }
3064 assertNumOrNull(this); 3088 assertNumOrNull(this);
3065 assertNumOrNull(rightOperand); 3089 assertNumOrNull(rightOperand);
3066 throw new EvaluationException(CompileTimeErrorCode.INVALID_CONSTANT); 3090 throw new EvaluationException(CompileTimeErrorCode.INVALID_CONSTANT);
3067 } 3091 }
3068 3092
3069 /** 3093 /**
3070 * Return the result of invoking the '&' operator on this object with the give n argument. 3094 * Return the result of invoking the '&' operator on this object with the give n argument.
3071 * 3095 *
3072 * @param rightOperand the right-hand operand of the operation 3096 * @param rightOperand the right-hand operand of the operation
3073 * @return the result of invoking the '&' operator on this object with the giv en argument 3097 * @return the result of invoking the '&' operator on this object with the giv en argument
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
3117 } 3141 }
3118 3142
3119 /** 3143 /**
3120 * Return the result of invoking the ' ' operator on this object with the give n argument. 3144 * Return the result of invoking the ' ' operator on this object with the give n argument.
3121 * 3145 *
3122 * @param rightOperand the right-hand operand of the operation 3146 * @param rightOperand the right-hand operand of the operation
3123 * @return the result of invoking the ' ' operator on this object with the giv en argument 3147 * @return the result of invoking the ' ' operator on this object with the giv en argument
3124 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 3148 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
3125 */ 3149 */
3126 StringState concatenate(InstanceState rightOperand) { 3150 StringState concatenate(InstanceState rightOperand) {
3151 assertString(rightOperand);
3127 throw new EvaluationException(CompileTimeErrorCode.INVALID_CONSTANT); 3152 throw new EvaluationException(CompileTimeErrorCode.INVALID_CONSTANT);
3128 } 3153 }
3129 3154
3130 /** 3155 /**
3131 * Return the result of applying boolean conversion to this object. 3156 * Return the result of applying boolean conversion to this object.
3132 * 3157 *
3133 * @param typeProvider the type provider used to find known types 3158 * @param typeProvider the type provider used to find known types
3134 * @return the result of applying boolean conversion to this object 3159 * @return the result of applying boolean conversion to this object
3135 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 3160 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
3136 */ 3161 */
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
3374 * @return the result of invoking the '&gt;&gt;' operator on this object with the given argument 3399 * @return the result of invoking the '&gt;&gt;' operator on this object with the given argument
3375 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 3400 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
3376 */ 3401 */
3377 IntState shiftRight(InstanceState rightOperand) { 3402 IntState shiftRight(InstanceState rightOperand) {
3378 assertIntOrNull(this); 3403 assertIntOrNull(this);
3379 assertIntOrNull(rightOperand); 3404 assertIntOrNull(rightOperand);
3380 throw new EvaluationException(CompileTimeErrorCode.INVALID_CONSTANT); 3405 throw new EvaluationException(CompileTimeErrorCode.INVALID_CONSTANT);
3381 } 3406 }
3382 3407
3383 /** 3408 /**
3409 * Return the result of invoking the 'length' getter on this object.
3410 *
3411 * @return the result of invoking the 'length' getter on this object
3412 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
3413 */
3414 IntState stringLength() {
3415 assertString(this);
3416 throw new EvaluationException(CompileTimeErrorCode.INVALID_CONSTANT);
3417 }
3418
3419 /**
3384 * Return the result of invoking the '*' operator on this object with the give n argument. 3420 * Return the result of invoking the '*' operator on this object with the give n argument.
3385 * 3421 *
3386 * @param rightOperand the right-hand operand of the operation 3422 * @param rightOperand the right-hand operand of the operation
3387 * @return the result of invoking the '*' operator on this object with the giv en argument 3423 * @return the result of invoking the '*' operator on this object with the giv en argument
3388 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 3424 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
3389 */ 3425 */
3390 NumState times(InstanceState rightOperand) { 3426 NumState times(InstanceState rightOperand) {
3391 assertNumOrNull(this); 3427 assertNumOrNull(this);
3392 assertNumOrNull(rightOperand); 3428 assertNumOrNull(rightOperand);
3393 throw new EvaluationException(CompileTimeErrorCode.INVALID_CONSTANT); 3429 throw new EvaluationException(CompileTimeErrorCode.INVALID_CONSTANT);
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after
4403 @override 4439 @override
4404 int get hashCode => value == null ? 0 : value.hashCode; 4440 int get hashCode => value == null ? 0 : value.hashCode;
4405 4441
4406 @override 4442 @override
4407 bool get isBoolNumStringOrNull => true; 4443 bool get isBoolNumStringOrNull => true;
4408 4444
4409 @override 4445 @override
4410 bool get isUnknown => value == null; 4446 bool get isUnknown => value == null;
4411 4447
4412 @override 4448 @override
4449 IntState stringLength() {
4450 if (value == null) {
4451 return IntState.UNKNOWN_VALUE;
4452 }
4453 return new IntState(value.length);
4454 }
4455
4456 @override
4413 String toString() => value == null ? "-unknown-" : "'${value}'"; 4457 String toString() => value == null ? "-unknown-" : "'${value}'";
4414 } 4458 }
4415 4459
4416 /** 4460 /**
4417 * Instances of the class `StringState` represent the state of an object represe nting a 4461 * Instances of the class `StringState` represent the state of an object represe nting a
4418 * symbol. 4462 * symbol.
4419 */ 4463 */
4420 class SymbolState extends InstanceState { 4464 class SymbolState extends InstanceState {
4421 /** 4465 /**
4422 * The value of this instance. 4466 * The value of this instance.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
4518 } 4562 }
4519 4563
4520 @override 4564 @override
4521 String get typeName => "Type"; 4565 String get typeName => "Type";
4522 4566
4523 @override 4567 @override
4524 int get hashCode => _element == null ? 0 : _element.hashCode; 4568 int get hashCode => _element == null ? 0 : _element.hashCode;
4525 4569
4526 @override 4570 @override
4527 String toString() => _element == null ? "-unknown-" : _element.name; 4571 String toString() => _element == null ? "-unknown-" : _element.name;
4528 }
4529
4530 /**
4531 * Instances of the class `ValidResult` represent the result of attempting to ev aluate a valid
4532 * compile time constant expression.
4533 */
4534 class ValidResult extends EvaluationResultImpl {
4535 /**
4536 * The value of the expression.
4537 */
4538 final DartObjectImpl value;
4539
4540 /**
4541 * Initialize a newly created result to represent the given value.
4542 *
4543 * @param value the value of the expression
4544 */
4545 ValidResult(this.value);
4546
4547 @override
4548 EvaluationResultImpl add(TypeProvider typeProvider, BinaryExpression node, Eva luationResultImpl rightOperand) => rightOperand.addToValid(typeProvider, node, t his);
4549
4550 /**
4551 * Return the result of applying boolean conversion to this result.
4552 *
4553 * @param node the node against which errors should be reported
4554 * @return the result of applying boolean conversion to the given value
4555 */
4556 @override
4557 EvaluationResultImpl applyBooleanConversion(TypeProvider typeProvider, AstNode node) {
4558 try {
4559 return _valueOf(value.convertToBool(typeProvider));
4560 } on EvaluationException catch (exception) {
4561 return _error(node, exception.errorCode);
4562 }
4563 }
4564
4565 @override
4566 EvaluationResultImpl bitAnd(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.bitAndValid(typeProvider, nod e, this);
4567
4568 @override
4569 EvaluationResultImpl bitNot(TypeProvider typeProvider, Expression node) {
4570 try {
4571 return _valueOf(value.bitNot(typeProvider));
4572 } on EvaluationException catch (exception) {
4573 return _error(node, exception.errorCode);
4574 }
4575 }
4576
4577 @override
4578 EvaluationResultImpl bitOr(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.bitOrValid(typeProvider, node, this);
4579
4580 @override
4581 EvaluationResultImpl bitXor(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.bitXorValid(typeProvider, nod e, this);
4582
4583 @override
4584 EvaluationResultImpl concatenate(TypeProvider typeProvider, Expression node, E valuationResultImpl rightOperand) => rightOperand.concatenateValid(typeProvider, node, this);
4585
4586 @override
4587 EvaluationResultImpl divide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.divideValid(typeProvider, nod e, this);
4588
4589 @override
4590 EvaluationResultImpl equalEqual(TypeProvider typeProvider, Expression node, Ev aluationResultImpl rightOperand) => rightOperand.equalEqualValid(typeProvider, n ode, this);
4591
4592 @override
4593 bool equalValues(TypeProvider typeProvider, EvaluationResultImpl result) {
4594 if (result is! ValidResult) {
4595 return false;
4596 }
4597 return value == (result as ValidResult).value;
4598 }
4599
4600 @override
4601 EvaluationResultImpl greaterThan(TypeProvider typeProvider, BinaryExpression n ode, EvaluationResultImpl rightOperand) => rightOperand.greaterThanValid(typePro vider, node, this);
4602
4603 @override
4604 EvaluationResultImpl greaterThanOrEqual(TypeProvider typeProvider, BinaryExpre ssion node, EvaluationResultImpl rightOperand) => rightOperand.greaterThanOrEqua lValid(typeProvider, node, this);
4605
4606 @override
4607 EvaluationResultImpl integerDivide(TypeProvider typeProvider, BinaryExpression node, EvaluationResultImpl rightOperand) => rightOperand.integerDivideValid(typ eProvider, node, this);
4608
4609 /**
4610 * Return `true` if this object represents an object whose type is 'bool'.
4611 *
4612 * @return `true` if this object represents a boolean value
4613 */
4614 bool get isBool => value.isBool;
4615
4616 /**
4617 * Return `true` if this object represents an object whose type is either 'boo l', 'num',
4618 * 'String', or 'Null'.
4619 *
4620 * @return `true` if this object represents either a boolean, numeric, string or null value
4621 */
4622 bool get isBoolNumStringOrNull => value.isBoolNumStringOrNull;
4623
4624 /**
4625 * Return `true` if this result represents the value 'false'.
4626 *
4627 * @return `true` if this result represents the value 'false'
4628 */
4629 bool get isFalse => value.isFalse;
4630
4631 /**
4632 * Return `true` if this result represents the value 'null'.
4633 *
4634 * @return `true` if this result represents the value 'null'
4635 */
4636 bool get isNull => value.isNull;
4637
4638 /**
4639 * Return `true` if this result represents the value 'true'.
4640 *
4641 * @return `true` if this result represents the value 'true'
4642 */
4643 bool get isTrue => value.isTrue;
4644
4645 /**
4646 * Return `true` if this object represents an instance of a user-defined class .
4647 *
4648 * @return `true` if this object represents an instance of a user-defined clas s
4649 */
4650 bool get isUserDefinedObject => value.isUserDefinedObject;
4651
4652 @override
4653 EvaluationResultImpl lessThan(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand) => rightOperand.lessThanValid(typeProvider, node, this);
4654
4655 @override
4656 EvaluationResultImpl lessThanOrEqual(TypeProvider typeProvider, BinaryExpressi on node, EvaluationResultImpl rightOperand) => rightOperand.lessThanOrEqualValid (typeProvider, node, this);
4657
4658 @override
4659 EvaluationResultImpl logicalAnd(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand) => rightOperand.logicalAndValid(typeProvi der, node, this);
4660
4661 @override
4662 EvaluationResultImpl logicalNot(TypeProvider typeProvider, Expression node) {
4663 try {
4664 return _valueOf(value.logicalNot(typeProvider));
4665 } on EvaluationException catch (exception) {
4666 return _error(node, exception.errorCode);
4667 }
4668 }
4669
4670 @override
4671 EvaluationResultImpl logicalOr(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.logicalOrValid(typeProvide r, node, this);
4672
4673 @override
4674 EvaluationResultImpl minus(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.minusValid(typeProvider, node, this);
4675
4676 @override
4677 EvaluationResultImpl negated(TypeProvider typeProvider, Expression node) {
4678 try {
4679 return _valueOf(value.negated(typeProvider));
4680 } on EvaluationException catch (exception) {
4681 return _error(node, exception.errorCode);
4682 }
4683 }
4684
4685 @override
4686 EvaluationResultImpl notEqual(TypeProvider typeProvider, BinaryExpression node , EvaluationResultImpl rightOperand) => rightOperand.notEqualValid(typeProvider, node, this);
4687
4688 @override
4689 EvaluationResultImpl performToString(TypeProvider typeProvider, AstNode node) {
4690 try {
4691 return _valueOf(value.performToString(typeProvider));
4692 } on EvaluationException catch (exception) {
4693 return _error(node, exception.errorCode);
4694 }
4695 }
4696
4697 @override
4698 EvaluationResultImpl remainder(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.remainderValid(typeProvide r, node, this);
4699
4700 @override
4701 EvaluationResultImpl shiftLeft(TypeProvider typeProvider, BinaryExpression nod e, EvaluationResultImpl rightOperand) => rightOperand.shiftLeftValid(typeProvide r, node, this);
4702
4703 @override
4704 EvaluationResultImpl shiftRight(TypeProvider typeProvider, BinaryExpression no de, EvaluationResultImpl rightOperand) => rightOperand.shiftRightValid(typeProvi der, node, this);
4705
4706 @override
4707 EvaluationResultImpl times(TypeProvider typeProvider, BinaryExpression node, E valuationResultImpl rightOperand) => rightOperand.timesValid(typeProvider, node, this);
4708
4709 @override
4710 String toString() {
4711 if (value == null) {
4712 return "null";
4713 }
4714 return value.toString();
4715 }
4716
4717 @override
4718 EvaluationResultImpl addToError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand;
4719
4720 @override
4721 EvaluationResultImpl addToValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) {
4722 try {
4723 return _valueOf(leftOperand.value.add(typeProvider, value));
4724 } on EvaluationException catch (exception) {
4725 return _error(node, exception.errorCode);
4726 }
4727 }
4728
4729 @override
4730 EvaluationResultImpl bitAndError(BinaryExpression node, ErrorResult leftOperan d) => leftOperand;
4731
4732 @override
4733 EvaluationResultImpl bitAndValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) {
4734 try {
4735 return _valueOf(leftOperand.value.bitAnd(typeProvider, value));
4736 } on EvaluationException catch (exception) {
4737 return _error(node, exception.errorCode);
4738 }
4739 }
4740
4741 @override
4742 EvaluationResultImpl bitOrError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand;
4743
4744 @override
4745 EvaluationResultImpl bitOrValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) {
4746 try {
4747 return _valueOf(leftOperand.value.bitOr(typeProvider, value));
4748 } on EvaluationException catch (exception) {
4749 return _error(node, exception.errorCode);
4750 }
4751 }
4752
4753 @override
4754 EvaluationResultImpl bitXorError(BinaryExpression node, ErrorResult leftOperan d) => leftOperand;
4755
4756 @override
4757 EvaluationResultImpl bitXorValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) {
4758 try {
4759 return _valueOf(leftOperand.value.bitXor(typeProvider, value));
4760 } on EvaluationException catch (exception) {
4761 return _error(node, exception.errorCode);
4762 }
4763 }
4764
4765 @override
4766 EvaluationResultImpl concatenateError(Expression node, ErrorResult leftOperand ) => leftOperand;
4767
4768 @override
4769 EvaluationResultImpl concatenateValid(TypeProvider typeProvider, Expression no de, ValidResult leftOperand) {
4770 try {
4771 return _valueOf(leftOperand.value.concatenate(typeProvider, value));
4772 } on EvaluationException catch (exception) {
4773 return _error(node, exception.errorCode);
4774 }
4775 }
4776
4777 @override
4778 EvaluationResultImpl divideError(BinaryExpression node, ErrorResult leftOperan d) => leftOperand;
4779
4780 @override
4781 EvaluationResultImpl divideValid(TypeProvider typeProvider, BinaryExpression n ode, ValidResult leftOperand) {
4782 try {
4783 return _valueOf(leftOperand.value.divide(typeProvider, value));
4784 } on EvaluationException catch (exception) {
4785 return _error(node, exception.errorCode);
4786 }
4787 }
4788
4789 @override
4790 EvaluationResultImpl equalEqualError(Expression node, ErrorResult leftOperand) => leftOperand;
4791
4792 @override
4793 EvaluationResultImpl equalEqualValid(TypeProvider typeProvider, Expression nod e, ValidResult leftOperand) {
4794 try {
4795 return _valueOf(leftOperand.value.equalEqual(typeProvider, value));
4796 } on EvaluationException catch (exception) {
4797 return _error(node, exception.errorCode);
4798 }
4799 }
4800
4801 @override
4802 EvaluationResultImpl greaterThanError(BinaryExpression node, ErrorResult leftO perand) => leftOperand;
4803
4804 @override
4805 EvaluationResultImpl greaterThanOrEqualError(BinaryExpression node, ErrorResul t leftOperand) => leftOperand;
4806
4807 @override
4808 EvaluationResultImpl greaterThanOrEqualValid(TypeProvider typeProvider, Binary Expression node, ValidResult leftOperand) {
4809 try {
4810 return _valueOf(leftOperand.value.greaterThanOrEqual(typeProvider, value)) ;
4811 } on EvaluationException catch (exception) {
4812 return _error(node, exception.errorCode);
4813 }
4814 }
4815
4816 @override
4817 EvaluationResultImpl greaterThanValid(TypeProvider typeProvider, BinaryExpress ion node, ValidResult leftOperand) {
4818 try {
4819 return _valueOf(leftOperand.value.greaterThan(typeProvider, value));
4820 } on EvaluationException catch (exception) {
4821 return _error(node, exception.errorCode);
4822 }
4823 }
4824
4825 @override
4826 EvaluationResultImpl integerDivideError(BinaryExpression node, ErrorResult lef tOperand) => leftOperand;
4827
4828 @override
4829 EvaluationResultImpl integerDivideValid(TypeProvider typeProvider, BinaryExpre ssion node, ValidResult leftOperand) {
4830 try {
4831 return _valueOf(leftOperand.value.integerDivide(typeProvider, value));
4832 } on EvaluationException catch (exception) {
4833 return _error(node, exception.errorCode);
4834 }
4835 }
4836
4837 @override
4838 EvaluationResultImpl lessThanError(BinaryExpression node, ErrorResult leftOper and) => leftOperand;
4839
4840 @override
4841 EvaluationResultImpl lessThanOrEqualError(BinaryExpression node, ErrorResult l eftOperand) => leftOperand;
4842
4843 @override
4844 EvaluationResultImpl lessThanOrEqualValid(TypeProvider typeProvider, BinaryExp ression node, ValidResult leftOperand) {
4845 try {
4846 return _valueOf(leftOperand.value.lessThanOrEqual(typeProvider, value));
4847 } on EvaluationException catch (exception) {
4848 return _error(node, exception.errorCode);
4849 }
4850 }
4851
4852 @override
4853 EvaluationResultImpl lessThanValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand) {
4854 try {
4855 return _valueOf(leftOperand.value.lessThan(typeProvider, value));
4856 } on EvaluationException catch (exception) {
4857 return _error(node, exception.errorCode);
4858 }
4859 }
4860
4861 @override
4862 EvaluationResultImpl logicalAndError(BinaryExpression node, ErrorResult leftOp erand) => leftOperand;
4863
4864 @override
4865 EvaluationResultImpl logicalAndValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand) {
4866 try {
4867 return _valueOf(leftOperand.value.logicalAnd(typeProvider, value));
4868 } on EvaluationException catch (exception) {
4869 return _error(node, exception.errorCode);
4870 }
4871 }
4872
4873 @override
4874 EvaluationResultImpl logicalOrError(BinaryExpression node, ErrorResult leftOpe rand) => leftOperand;
4875
4876 @override
4877 EvaluationResultImpl logicalOrValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) {
4878 try {
4879 return _valueOf(leftOperand.value.logicalOr(typeProvider, value));
4880 } on EvaluationException catch (exception) {
4881 return _error(node, exception.errorCode);
4882 }
4883 }
4884
4885 @override
4886 EvaluationResultImpl minusError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand;
4887
4888 @override
4889 EvaluationResultImpl minusValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) {
4890 try {
4891 return _valueOf(leftOperand.value.minus(typeProvider, value));
4892 } on EvaluationException catch (exception) {
4893 return _error(node, exception.errorCode);
4894 }
4895 }
4896
4897 @override
4898 EvaluationResultImpl notEqualError(BinaryExpression node, ErrorResult leftOper and) => leftOperand;
4899
4900 @override
4901 EvaluationResultImpl notEqualValid(TypeProvider typeProvider, BinaryExpression node, ValidResult leftOperand) {
4902 try {
4903 return _valueOf(leftOperand.value.notEqual(typeProvider, value));
4904 } on EvaluationException catch (exception) {
4905 return _error(node, exception.errorCode);
4906 }
4907 }
4908
4909 @override
4910 EvaluationResultImpl remainderError(BinaryExpression node, ErrorResult leftOpe rand) => leftOperand;
4911
4912 @override
4913 EvaluationResultImpl remainderValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) {
4914 try {
4915 return _valueOf(leftOperand.value.remainder(typeProvider, value));
4916 } on EvaluationException catch (exception) {
4917 return _error(node, exception.errorCode);
4918 }
4919 }
4920
4921 @override
4922 EvaluationResultImpl shiftLeftError(BinaryExpression node, ErrorResult leftOpe rand) => leftOperand;
4923
4924 @override
4925 EvaluationResultImpl shiftLeftValid(TypeProvider typeProvider, BinaryExpressio n node, ValidResult leftOperand) {
4926 try {
4927 return _valueOf(leftOperand.value.shiftLeft(typeProvider, value));
4928 } on EvaluationException catch (exception) {
4929 return _error(node, exception.errorCode);
4930 }
4931 }
4932
4933 @override
4934 EvaluationResultImpl shiftRightError(BinaryExpression node, ErrorResult leftOp erand) => leftOperand;
4935
4936 @override
4937 EvaluationResultImpl shiftRightValid(TypeProvider typeProvider, BinaryExpressi on node, ValidResult leftOperand) {
4938 try {
4939 return _valueOf(leftOperand.value.shiftRight(typeProvider, value));
4940 } on EvaluationException catch (exception) {
4941 return _error(node, exception.errorCode);
4942 }
4943 }
4944
4945 @override
4946 EvaluationResultImpl timesError(BinaryExpression node, ErrorResult leftOperand ) => leftOperand;
4947
4948 @override
4949 EvaluationResultImpl timesValid(TypeProvider typeProvider, BinaryExpression no de, ValidResult leftOperand) {
4950 try {
4951 return _valueOf(leftOperand.value.times(typeProvider, value));
4952 } on EvaluationException catch (exception) {
4953 return _error(node, exception.errorCode);
4954 }
4955 }
4956
4957 /**
4958 * Return a result object representing an error associated with the given node .
4959 *
4960 * @param node the AST node associated with the error
4961 * @param code the error code indicating the nature of the error
4962 * @return a result object representing an error associated with the given nod e
4963 */
4964 ErrorResult _error(AstNode node, ErrorCode code) => new ErrorResult.con1(node, code);
4965
4966 /**
4967 * Return a result object representing the given value.
4968 *
4969 * @param value the value to be represented as a result object
4970 * @return a result object representing the given value
4971 */
4972 ValidResult _valueOf(DartObjectImpl value) => new ValidResult(value);
4973 } 4572 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698