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

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

Issue 975453004: Reformat (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/ast.dart ('k') | pkg/analyzer/lib/src/generated/element.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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';
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 * Initialize a newly created evaluator to evaluate expressions in the given s ource. 212 * Initialize a newly created evaluator to evaluate expressions in the given s ource.
213 * 213 *
214 * @param source the source containing the expression(s) that will be evaluate d 214 * @param source the source containing the expression(s) that will be evaluate d
215 * @param typeProvider the type provider used to access known types 215 * @param typeProvider the type provider used to access known types
216 */ 216 */
217 ConstantEvaluator(this._source, this._typeProvider); 217 ConstantEvaluator(this._source, this._typeProvider);
218 218
219 EvaluationResult evaluate(Expression expression) { 219 EvaluationResult evaluate(Expression expression) {
220 RecordingErrorListener errorListener = new RecordingErrorListener(); 220 RecordingErrorListener errorListener = new RecordingErrorListener();
221 ErrorReporter errorReporter = new ErrorReporter(errorListener, _source); 221 ErrorReporter errorReporter = new ErrorReporter(errorListener, _source);
222 DartObjectImpl result = 222 DartObjectImpl result = expression
223 expression.accept(new ConstantVisitor.con1(_typeProvider, errorReporter) ); 223 .accept(new ConstantVisitor.con1(_typeProvider, errorReporter));
224 if (result != null) { 224 if (result != null) {
225 return EvaluationResult.forValue(result); 225 return EvaluationResult.forValue(result);
226 } 226 }
227 return EvaluationResult.forErrors(errorListener.errors); 227 return EvaluationResult.forErrors(errorListener.errors);
228 } 228 }
229 } 229 }
230 230
231 /** 231 /**
232 * Instances of the class `ConstantFinder` are used to traverse the AST 232 * Instances of the class `ConstantFinder` are used to traverse the AST
233 * structures of all of the compilation units being resolved and build tables 233 * structures of all of the compilation units being resolved and build tables
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 * @param unit the compilation unit defining the constants to be added 397 * @param unit the compilation unit defining the constants to be added
398 */ 398 */
399 void add(CompilationUnit unit) { 399 void add(CompilationUnit unit) {
400 unit.accept(_constantFinder); 400 unit.accept(_constantFinder);
401 } 401 }
402 402
403 /** 403 /**
404 * This method is called just before computing the constant value associated w ith an AST node. 404 * This method is called just before computing the constant value associated w ith an AST node.
405 * Unit tests will override this method to introduce additional error checking . 405 * Unit tests will override this method to introduce additional error checking .
406 */ 406 */
407 void beforeComputeValue(AstNode constNode) { 407 void beforeComputeValue(AstNode constNode) {}
408 }
409 408
410 /** 409 /**
411 * This method is called just before getting the constant initializers associa ted with a 410 * This method is called just before getting the constant initializers associa ted with a
412 * constructor AST node. Unit tests will override this method to introduce add itional error 411 * constructor AST node. Unit tests will override this method to introduce add itional error
413 * checking. 412 * checking.
414 */ 413 */
415 void beforeGetConstantInitializers(ConstructorElement constructor) { 414 void beforeGetConstantInitializers(ConstructorElement constructor) {}
416 }
417 415
418 /** 416 /**
419 * This method is called just before getting a parameter's default value. Unit tests will override 417 * This method is called just before getting a parameter's default value. Unit tests will override
420 * this method to introduce additional error checking. 418 * this method to introduce additional error checking.
421 */ 419 */
422 void beforeGetParameterDefault(ParameterElement parameter) { 420 void beforeGetParameterDefault(ParameterElement parameter) {}
423 }
424 421
425 /** 422 /**
426 * Compute values for all of the constants in the compilation units that were added. 423 * Compute values for all of the constants in the compilation units that were added.
427 */ 424 */
428 void computeValues() { 425 void computeValues() {
429 _variableDeclarationMap = _constantFinder.variableMap; 426 _variableDeclarationMap = _constantFinder.variableMap;
430 constructorDeclarationMap = _constantFinder.constructorMap; 427 constructorDeclarationMap = _constantFinder.constructorMap;
431 _constructorInvocations = _constantFinder.constructorInvocations; 428 _constructorInvocations = _constantFinder.constructorInvocations;
432 _annotations = _constantFinder.annotations; 429 _annotations = _constantFinder.annotations;
433 _variableDeclarationMap.values.forEach((VariableDeclaration declaration) { 430 _variableDeclarationMap.values.forEach((VariableDeclaration declaration) {
434 ReferenceFinder referenceFinder = new ReferenceFinder( 431 ReferenceFinder referenceFinder = new ReferenceFinder(declaration,
435 declaration, 432 referenceGraph, _variableDeclarationMap, constructorDeclarationMap);
436 referenceGraph,
437 _variableDeclarationMap,
438 constructorDeclarationMap);
439 referenceGraph.addNode(declaration); 433 referenceGraph.addNode(declaration);
440 declaration.initializer.accept(referenceFinder); 434 declaration.initializer.accept(referenceFinder);
441 }); 435 });
442 constructorDeclarationMap.forEach( 436 constructorDeclarationMap.forEach(
443 (ConstructorElement element, ConstructorDeclaration declaration) { 437 (ConstructorElement element, ConstructorDeclaration declaration) {
444 ReferenceFinder referenceFinder = new ReferenceFinder( 438 ReferenceFinder referenceFinder = new ReferenceFinder(declaration,
445 declaration, 439 referenceGraph, _variableDeclarationMap, constructorDeclarationMap);
446 referenceGraph,
447 _variableDeclarationMap,
448 constructorDeclarationMap);
449 referenceGraph.addNode(declaration); 440 referenceGraph.addNode(declaration);
450 bool superInvocationFound = false; 441 bool superInvocationFound = false;
451 NodeList<ConstructorInitializer> initializers = declaration.initializers; 442 NodeList<ConstructorInitializer> initializers = declaration.initializers;
452 for (ConstructorInitializer initializer in initializers) { 443 for (ConstructorInitializer initializer in initializers) {
453 if (initializer is SuperConstructorInvocation) { 444 if (initializer is SuperConstructorInvocation) {
454 superInvocationFound = true; 445 superInvocationFound = true;
455 } 446 }
456 initializer.accept(referenceFinder); 447 initializer.accept(referenceFinder);
457 } 448 }
458 if (!superInvocationFound) { 449 if (!superInvocationFound) {
(...skipping 11 matching lines...) Expand all
470 } 461 }
471 } 462 }
472 } 463 }
473 for (FormalParameter parameter in declaration.parameters.parameters) { 464 for (FormalParameter parameter in declaration.parameters.parameters) {
474 referenceGraph.addNode(parameter); 465 referenceGraph.addNode(parameter);
475 referenceGraph.addEdge(declaration, parameter); 466 referenceGraph.addEdge(declaration, parameter);
476 if (parameter is DefaultFormalParameter) { 467 if (parameter is DefaultFormalParameter) {
477 Expression defaultValue = parameter.defaultValue; 468 Expression defaultValue = parameter.defaultValue;
478 if (defaultValue != null) { 469 if (defaultValue != null) {
479 ReferenceFinder parameterReferenceFinder = new ReferenceFinder( 470 ReferenceFinder parameterReferenceFinder = new ReferenceFinder(
480 parameter, 471 parameter, referenceGraph, _variableDeclarationMap,
481 referenceGraph,
482 _variableDeclarationMap,
483 constructorDeclarationMap); 472 constructorDeclarationMap);
484 defaultValue.accept(parameterReferenceFinder); 473 defaultValue.accept(parameterReferenceFinder);
485 } 474 }
486 } 475 }
487 } 476 }
488 }); 477 });
489 for (InstanceCreationExpression expression in _constructorInvocations) { 478 for (InstanceCreationExpression expression in _constructorInvocations) {
490 referenceGraph.addNode(expression); 479 referenceGraph.addNode(expression);
491 ConstructorElement constructor = expression.staticElement; 480 ConstructorElement constructor = expression.staticElement;
492 if (constructor == null) { 481 if (constructor == null) {
493 continue; 482 continue;
494 } 483 }
495 constructor = _followConstantRedirectionChain(constructor); 484 constructor = _followConstantRedirectionChain(constructor);
496 ConstructorDeclaration declaration = 485 ConstructorDeclaration declaration =
497 findConstructorDeclaration(constructor); 486 findConstructorDeclaration(constructor);
498 // An instance creation expression depends both on the constructor and 487 // An instance creation expression depends both on the constructor and
499 // the arguments passed to it. 488 // the arguments passed to it.
500 ReferenceFinder referenceFinder = new ReferenceFinder( 489 ReferenceFinder referenceFinder = new ReferenceFinder(expression,
501 expression, 490 referenceGraph, _variableDeclarationMap, constructorDeclarationMap);
502 referenceGraph,
503 _variableDeclarationMap,
504 constructorDeclarationMap);
505 if (declaration != null) { 491 if (declaration != null) {
506 referenceGraph.addEdge(expression, declaration); 492 referenceGraph.addEdge(expression, declaration);
507 } 493 }
508 expression.argumentList.accept(referenceFinder); 494 expression.argumentList.accept(referenceFinder);
509 } 495 }
510 List<List<AstNode>> topologicalSort = 496 List<List<AstNode>> topologicalSort =
511 referenceGraph.computeTopologicalSort(); 497 referenceGraph.computeTopologicalSort();
512 for (List<AstNode> constantsInCycle in topologicalSort) { 498 for (List<AstNode> constantsInCycle in topologicalSort) {
513 if (constantsInCycle.length == 1) { 499 if (constantsInCycle.length == 1) {
514 _computeValueFor(constantsInCycle[0]); 500 _computeValueFor(constantsInCycle[0]);
(...skipping 11 matching lines...) Expand all
526 } 512 }
527 } 513 }
528 514
529 /** 515 /**
530 * Create the ConstantVisitor used to evaluate constants. Unit tests will over ride this method to 516 * Create the ConstantVisitor used to evaluate constants. Unit tests will over ride this method to
531 * introduce additional error checking. 517 * introduce additional error checking.
532 */ 518 */
533 ConstantVisitor createConstantVisitor(ErrorReporter errorReporter) => 519 ConstantVisitor createConstantVisitor(ErrorReporter errorReporter) =>
534 new ConstantVisitor.con1(typeProvider, errorReporter); 520 new ConstantVisitor.con1(typeProvider, errorReporter);
535 521
536 ConstructorDeclaration 522 ConstructorDeclaration findConstructorDeclaration(
537 findConstructorDeclaration(ConstructorElement constructor) => 523 ConstructorElement constructor) =>
538 constructorDeclarationMap[_getConstructorBase(constructor)]; 524 constructorDeclarationMap[_getConstructorBase(constructor)];
539 525
540 /** 526 /**
541 * Check that the arguments to a call to fromEnvironment() are correct. 527 * Check that the arguments to a call to fromEnvironment() are correct.
542 * 528 *
543 * @param arguments the AST nodes of the arguments. 529 * @param arguments the AST nodes of the arguments.
544 * @param argumentValues the values of the unnamed arguments. 530 * @param argumentValues the values of the unnamed arguments.
545 * @param namedArgumentValues the values of the named arguments. 531 * @param namedArgumentValues the values of the named arguments.
546 * @param expectedDefaultValueType the allowed type of the "defaultValue" para meter (if present). 532 * @param expectedDefaultValueType the allowed type of the "defaultValue" para meter (if present).
547 * Note: "defaultValue" is always allowed to be null. 533 * Note: "defaultValue" is always allowed to be null.
548 * @return true if the arguments are correct, false if there is an error. 534 * @return true if the arguments are correct, false if there is an error.
549 */ 535 */
550 bool _checkFromEnvironmentArguments(NodeList<Expression> arguments, 536 bool _checkFromEnvironmentArguments(NodeList<Expression> arguments,
551 List<DartObjectImpl> argumentValues, HashMap<String, 537 List<DartObjectImpl> argumentValues,
552 DartObjectImpl> namedArgumentValues, InterfaceType expectedDefaultValueTyp e) { 538 HashMap<String, DartObjectImpl> namedArgumentValues,
539 InterfaceType expectedDefaultValueType) {
553 int argumentCount = arguments.length; 540 int argumentCount = arguments.length;
554 if (argumentCount < 1 || argumentCount > 2) { 541 if (argumentCount < 1 || argumentCount > 2) {
555 return false; 542 return false;
556 } 543 }
557 if (arguments[0] is NamedExpression) { 544 if (arguments[0] is NamedExpression) {
558 return false; 545 return false;
559 } 546 }
560 if (!identical(argumentValues[0].type, typeProvider.stringType)) { 547 if (!identical(argumentValues[0].type, typeProvider.stringType)) {
561 return false; 548 return false;
562 } 549 }
(...skipping 17 matching lines...) Expand all
580 567
581 /** 568 /**
582 * Check that the arguments to a call to Symbol() are correct. 569 * Check that the arguments to a call to Symbol() are correct.
583 * 570 *
584 * @param arguments the AST nodes of the arguments. 571 * @param arguments the AST nodes of the arguments.
585 * @param argumentValues the values of the unnamed arguments. 572 * @param argumentValues the values of the unnamed arguments.
586 * @param namedArgumentValues the values of the named arguments. 573 * @param namedArgumentValues the values of the named arguments.
587 * @return true if the arguments are correct, false if there is an error. 574 * @return true if the arguments are correct, false if there is an error.
588 */ 575 */
589 bool _checkSymbolArguments(NodeList<Expression> arguments, 576 bool _checkSymbolArguments(NodeList<Expression> arguments,
590 List<DartObjectImpl> argumentValues, HashMap<String, 577 List<DartObjectImpl> argumentValues,
591 DartObjectImpl> namedArgumentValues) { 578 HashMap<String, DartObjectImpl> namedArgumentValues) {
592 if (arguments.length != 1) { 579 if (arguments.length != 1) {
593 return false; 580 return false;
594 } 581 }
595 if (arguments[0] is NamedExpression) { 582 if (arguments[0] is NamedExpression) {
596 return false; 583 return false;
597 } 584 }
598 if (!identical(argumentValues[0].type, typeProvider.stringType)) { 585 if (!identical(argumentValues[0].type, typeProvider.stringType)) {
599 return false; 586 return false;
600 } 587 }
601 String name = argumentValues[0].stringValue; 588 String name = argumentValues[0].stringValue;
(...skipping 12 matching lines...) Expand all
614 VariableElement element = declaration.element; 601 VariableElement element = declaration.element;
615 RecordingErrorListener errorListener = new RecordingErrorListener(); 602 RecordingErrorListener errorListener = new RecordingErrorListener();
616 ErrorReporter errorReporter = 603 ErrorReporter errorReporter =
617 new ErrorReporter(errorListener, element.source); 604 new ErrorReporter(errorListener, element.source);
618 DartObjectImpl dartObject = 605 DartObjectImpl dartObject =
619 declaration.initializer.accept(createConstantVisitor(errorReporter)); 606 declaration.initializer.accept(createConstantVisitor(errorReporter));
620 if (dartObject != null) { 607 if (dartObject != null) {
621 if (!_runtimeTypeMatch(dartObject, element.type)) { 608 if (!_runtimeTypeMatch(dartObject, element.type)) {
622 errorReporter.reportErrorForNode( 609 errorReporter.reportErrorForNode(
623 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, 610 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH,
624 declaration, 611 declaration, [dartObject.type, element.type]);
625 [dartObject.type, element.type]);
626 } 612 }
627 } 613 }
628 (element as VariableElementImpl).evaluationResult = 614 (element as VariableElementImpl).evaluationResult =
629 new EvaluationResultImpl.con2(dartObject, errorListener.errors); 615 new EvaluationResultImpl.con2(dartObject, errorListener.errors);
630 } else if (constNode is InstanceCreationExpression) { 616 } else if (constNode is InstanceCreationExpression) {
631 InstanceCreationExpression expression = constNode; 617 InstanceCreationExpression expression = constNode;
632 ConstructorElement constructor = expression.staticElement; 618 ConstructorElement constructor = expression.staticElement;
633 if (constructor == null) { 619 if (constructor == null) {
634 // Couldn't resolve the constructor so we can't compute a value. 620 // Couldn't resolve the constructor so we can't compute a value.
635 // No problem - the error has already been reported. 621 // No problem - the error has already been reported.
636 // But we still need to store an evaluation result. 622 // But we still need to store an evaluation result.
637 expression.evaluationResult = new EvaluationResultImpl.con1(null); 623 expression.evaluationResult = new EvaluationResultImpl.con1(null);
638 return; 624 return;
639 } 625 }
640 RecordingErrorListener errorListener = new RecordingErrorListener(); 626 RecordingErrorListener errorListener = new RecordingErrorListener();
641 CompilationUnit sourceCompilationUnit = 627 CompilationUnit sourceCompilationUnit =
642 expression.getAncestor((node) => node is CompilationUnit); 628 expression.getAncestor((node) => node is CompilationUnit);
643 ErrorReporter errorReporter = 629 ErrorReporter errorReporter = new ErrorReporter(
644 new ErrorReporter(errorListener, sourceCompilationUnit.element.source) ; 630 errorListener, sourceCompilationUnit.element.source);
645 ConstantVisitor constantVisitor = createConstantVisitor(errorReporter); 631 ConstantVisitor constantVisitor = createConstantVisitor(errorReporter);
646 DartObjectImpl result = _evaluateConstructorCall( 632 DartObjectImpl result = _evaluateConstructorCall(constNode,
647 constNode, 633 expression.argumentList.arguments, constructor, constantVisitor,
648 expression.argumentList.arguments,
649 constructor,
650 constantVisitor,
651 errorReporter); 634 errorReporter);
652 expression.evaluationResult = 635 expression.evaluationResult =
653 new EvaluationResultImpl.con2(result, errorListener.errors); 636 new EvaluationResultImpl.con2(result, errorListener.errors);
654 } else if (constNode is ConstructorDeclaration) { 637 } else if (constNode is ConstructorDeclaration) {
655 ConstructorDeclaration declaration = constNode; 638 ConstructorDeclaration declaration = constNode;
656 NodeList<ConstructorInitializer> initializers = declaration.initializers; 639 NodeList<ConstructorInitializer> initializers = declaration.initializers;
657 ConstructorElementImpl constructor = 640 ConstructorElementImpl constructor =
658 declaration.element as ConstructorElementImpl; 641 declaration.element as ConstructorElementImpl;
659 constructor.constantInitializers = 642 constructor.constantInitializers =
660 new ConstantValueComputer_InitializerCloner().cloneNodeList(initialize rs); 643 new ConstantValueComputer_InitializerCloner()
644 .cloneNodeList(initializers);
661 } else if (constNode is FormalParameter) { 645 } else if (constNode is FormalParameter) {
662 if (constNode is DefaultFormalParameter) { 646 if (constNode is DefaultFormalParameter) {
663 DefaultFormalParameter parameter = constNode; 647 DefaultFormalParameter parameter = constNode;
664 ParameterElement element = parameter.element; 648 ParameterElement element = parameter.element;
665 Expression defaultValue = parameter.defaultValue; 649 Expression defaultValue = parameter.defaultValue;
666 if (defaultValue != null) { 650 if (defaultValue != null) {
667 RecordingErrorListener errorListener = new RecordingErrorListener(); 651 RecordingErrorListener errorListener = new RecordingErrorListener();
668 ErrorReporter errorReporter = 652 ErrorReporter errorReporter =
669 new ErrorReporter(errorListener, element.source); 653 new ErrorReporter(errorListener, element.source);
670 DartObjectImpl dartObject = 654 DartObjectImpl dartObject =
(...skipping 13 matching lines...) Expand all
684 // The annotation is a reference to a compile-time constant variable. 668 // The annotation is a reference to a compile-time constant variable.
685 // Just copy the evaluation result. 669 // Just copy the evaluation result.
686 VariableElementImpl variableElement = 670 VariableElementImpl variableElement =
687 element.variable as VariableElementImpl; 671 element.variable as VariableElementImpl;
688 elementAnnotation.evaluationResult = variableElement.evaluationResult; 672 elementAnnotation.evaluationResult = variableElement.evaluationResult;
689 } else if (element is ConstructorElementImpl && 673 } else if (element is ConstructorElementImpl &&
690 constNode.arguments != null) { 674 constNode.arguments != null) {
691 RecordingErrorListener errorListener = new RecordingErrorListener(); 675 RecordingErrorListener errorListener = new RecordingErrorListener();
692 CompilationUnit sourceCompilationUnit = 676 CompilationUnit sourceCompilationUnit =
693 constNode.getAncestor((node) => node is CompilationUnit); 677 constNode.getAncestor((node) => node is CompilationUnit);
694 ErrorReporter errorReporter = 678 ErrorReporter errorReporter = new ErrorReporter(
695 new ErrorReporter(errorListener, sourceCompilationUnit.element.sou rce); 679 errorListener, sourceCompilationUnit.element.source);
696 ConstantVisitor constantVisitor = 680 ConstantVisitor constantVisitor =
697 createConstantVisitor(errorReporter); 681 createConstantVisitor(errorReporter);
698 DartObjectImpl result = _evaluateConstructorCall( 682 DartObjectImpl result = _evaluateConstructorCall(constNode,
699 constNode, 683 constNode.arguments.arguments, element, constantVisitor,
700 constNode.arguments.arguments,
701 element,
702 constantVisitor,
703 errorReporter); 684 errorReporter);
704 elementAnnotation.evaluationResult = 685 elementAnnotation.evaluationResult =
705 new EvaluationResultImpl.con2(result, errorListener.errors); 686 new EvaluationResultImpl.con2(result, errorListener.errors);
706 } else { 687 } else {
707 // This may happen for invalid code (e.g. failing to pass arguments 688 // This may happen for invalid code (e.g. failing to pass arguments
708 // to an annotation which references a const constructor). The error 689 // to an annotation which references a const constructor). The error
709 // is detected elsewhere, so just silently ignore it here. 690 // is detected elsewhere, so just silently ignore it here.
710 elementAnnotation.evaluationResult = 691 elementAnnotation.evaluationResult =
711 new EvaluationResultImpl.con1(null); 692 new EvaluationResultImpl.con1(null);
712 } 693 }
713 } 694 }
714 } else { 695 } else {
715 // Should not happen. 696 // Should not happen.
716 AnalysisEngine.instance.logger.logError( 697 AnalysisEngine.instance.logger.logError(
717 "Constant value computer trying to compute the value of a node which i s not a VariableDeclaration, InstanceCreationExpression, FormalParameter, or Con structorDeclaration"); 698 "Constant value computer trying to compute the value of a node which i s not a VariableDeclaration, InstanceCreationExpression, FormalParameter, or Con structorDeclaration");
718 return; 699 return;
719 } 700 }
720 } 701 }
721 702
722 /** 703 /**
723 * Evaluate a call to fromEnvironment() on the bool, int, or String class. 704 * Evaluate a call to fromEnvironment() on the bool, int, or String class.
724 * 705 *
725 * @param environmentValue Value fetched from the environment 706 * @param environmentValue Value fetched from the environment
726 * @param builtInDefaultValue Value that should be used as the default if no " defaultValue" 707 * @param builtInDefaultValue Value that should be used as the default if no " defaultValue"
727 * argument appears in [namedArgumentValues]. 708 * argument appears in [namedArgumentValues].
728 * @param namedArgumentValues Named parameters passed to fromEnvironment() 709 * @param namedArgumentValues Named parameters passed to fromEnvironment()
729 * @return A [DartObjectImpl] object corresponding to the evaluated result 710 * @return A [DartObjectImpl] object corresponding to the evaluated result
730 */ 711 */
731 DartObjectImpl _computeValueFromEnvironment(DartObject environmentValue, 712 DartObjectImpl _computeValueFromEnvironment(DartObject environmentValue,
732 DartObjectImpl builtInDefaultValue, HashMap<String, 713 DartObjectImpl builtInDefaultValue,
733 DartObjectImpl> namedArgumentValues) { 714 HashMap<String, DartObjectImpl> namedArgumentValues) {
734 DartObjectImpl value = environmentValue as DartObjectImpl; 715 DartObjectImpl value = environmentValue as DartObjectImpl;
735 if (value.isUnknown || value.isNull) { 716 if (value.isUnknown || value.isNull) {
736 // The name either doesn't exist in the environment or we couldn't parse 717 // The name either doesn't exist in the environment or we couldn't parse
737 // the corresponding value. 718 // the corresponding value.
738 // If the code supplied an explicit default, use it. 719 // If the code supplied an explicit default, use it.
739 if (namedArgumentValues.containsKey(_DEFAULT_VALUE_PARAM)) { 720 if (namedArgumentValues.containsKey(_DEFAULT_VALUE_PARAM)) {
740 value = namedArgumentValues[_DEFAULT_VALUE_PARAM]; 721 value = namedArgumentValues[_DEFAULT_VALUE_PARAM];
741 } else if (value.isNull) { 722 } else if (value.isNull) {
742 // The code didn't supply an explicit default. 723 // The code didn't supply an explicit default.
743 // The name exists in the environment but we couldn't parse the 724 // The name exists in the environment but we couldn't parse the
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 } 761 }
781 } 762 }
782 constructor = _followConstantRedirectionChain(constructor); 763 constructor = _followConstantRedirectionChain(constructor);
783 InterfaceType definingClass = constructor.returnType as InterfaceType; 764 InterfaceType definingClass = constructor.returnType as InterfaceType;
784 if (constructor.isFactory) { 765 if (constructor.isFactory) {
785 // We couldn't find a non-factory constructor. 766 // We couldn't find a non-factory constructor.
786 // See if it's because we reached an external const factory constructor 767 // See if it's because we reached an external const factory constructor
787 // that we can emulate. 768 // that we can emulate.
788 if (constructor.name == "fromEnvironment") { 769 if (constructor.name == "fromEnvironment") {
789 if (!_checkFromEnvironmentArguments( 770 if (!_checkFromEnvironmentArguments(
790 arguments, 771 arguments, argumentValues, namedArgumentValues, definingClass)) {
791 argumentValues,
792 namedArgumentValues,
793 definingClass)) {
794 errorReporter.reportErrorForNode( 772 errorReporter.reportErrorForNode(
795 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 773 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, node);
796 node);
797 return null; 774 return null;
798 } 775 }
799 String variableName = 776 String variableName =
800 argumentCount < 1 ? null : argumentValues[0].stringValue; 777 argumentCount < 1 ? null : argumentValues[0].stringValue;
801 if (identical(definingClass, typeProvider.boolType)) { 778 if (identical(definingClass, typeProvider.boolType)) {
802 DartObject valueFromEnvironment; 779 DartObject valueFromEnvironment;
803 valueFromEnvironment = 780 valueFromEnvironment =
804 _declaredVariables.getBool(typeProvider, variableName); 781 _declaredVariables.getBool(typeProvider, variableName);
805 return _computeValueFromEnvironment( 782 return _computeValueFromEnvironment(valueFromEnvironment,
806 valueFromEnvironment,
807 new DartObjectImpl(typeProvider.boolType, BoolState.FALSE_STATE), 783 new DartObjectImpl(typeProvider.boolType, BoolState.FALSE_STATE),
808 namedArgumentValues); 784 namedArgumentValues);
809 } else if (identical(definingClass, typeProvider.intType)) { 785 } else if (identical(definingClass, typeProvider.intType)) {
810 DartObject valueFromEnvironment; 786 DartObject valueFromEnvironment;
811 valueFromEnvironment = 787 valueFromEnvironment =
812 _declaredVariables.getInt(typeProvider, variableName); 788 _declaredVariables.getInt(typeProvider, variableName);
813 return _computeValueFromEnvironment( 789 return _computeValueFromEnvironment(valueFromEnvironment,
814 valueFromEnvironment,
815 new DartObjectImpl(typeProvider.nullType, NullState.NULL_STATE), 790 new DartObjectImpl(typeProvider.nullType, NullState.NULL_STATE),
816 namedArgumentValues); 791 namedArgumentValues);
817 } else if (identical(definingClass, typeProvider.stringType)) { 792 } else if (identical(definingClass, typeProvider.stringType)) {
818 DartObject valueFromEnvironment; 793 DartObject valueFromEnvironment;
819 valueFromEnvironment = 794 valueFromEnvironment =
820 _declaredVariables.getString(typeProvider, variableName); 795 _declaredVariables.getString(typeProvider, variableName);
821 return _computeValueFromEnvironment( 796 return _computeValueFromEnvironment(valueFromEnvironment,
822 valueFromEnvironment,
823 new DartObjectImpl(typeProvider.nullType, NullState.NULL_STATE), 797 new DartObjectImpl(typeProvider.nullType, NullState.NULL_STATE),
824 namedArgumentValues); 798 namedArgumentValues);
825 } 799 }
826 } else if (constructor.name == "" && 800 } else if (constructor.name == "" &&
827 identical(definingClass, typeProvider.symbolType) && 801 identical(definingClass, typeProvider.symbolType) &&
828 argumentCount == 1) { 802 argumentCount == 1) {
829 if (!_checkSymbolArguments( 803 if (!_checkSymbolArguments(
830 arguments, 804 arguments, argumentValues, namedArgumentValues)) {
831 argumentValues,
832 namedArgumentValues)) {
833 errorReporter.reportErrorForNode( 805 errorReporter.reportErrorForNode(
834 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 806 CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, node);
835 node);
836 return null; 807 return null;
837 } 808 }
838 String argumentValue = argumentValues[0].stringValue; 809 String argumentValue = argumentValues[0].stringValue;
839 return new DartObjectImpl( 810 return new DartObjectImpl(
840 definingClass, 811 definingClass, new SymbolState(argumentValue));
841 new SymbolState(argumentValue));
842 } 812 }
843 // Either it's an external const factory constructor that we can't 813 // Either it's an external const factory constructor that we can't
844 // emulate, or an error occurred (a cycle, or a const constructor trying 814 // emulate, or an error occurred (a cycle, or a const constructor trying
845 // to delegate to a non-const constructor). 815 // to delegate to a non-const constructor).
846 // In the former case, the best we can do is consider it an unknown value. 816 // In the former case, the best we can do is consider it an unknown value.
847 // In the latter case, the error has already been reported, so considering 817 // In the latter case, the error has already been reported, so considering
848 // it an unknown value will suppress further errors. 818 // it an unknown value will suppress further errors.
849 return constantVisitor._validWithUnknownValue(definingClass); 819 return constantVisitor._validWithUnknownValue(definingClass);
850 } 820 }
851 beforeGetConstantInitializers(constructor); 821 beforeGetConstantInitializers(constructor);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 // No default was provided, so the default value is null. 868 // No default was provided, so the default value is null.
899 argumentValue = constantVisitor.null2; 869 argumentValue = constantVisitor.null2;
900 } else if (evaluationResult.value != null) { 870 } else if (evaluationResult.value != null) {
901 argumentValue = evaluationResult.value; 871 argumentValue = evaluationResult.value;
902 } 872 }
903 } 873 }
904 if (argumentValue != null) { 874 if (argumentValue != null) {
905 if (!_runtimeTypeMatch(argumentValue, parameter.type)) { 875 if (!_runtimeTypeMatch(argumentValue, parameter.type)) {
906 errorReporter.reportErrorForNode( 876 errorReporter.reportErrorForNode(
907 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMA TCH, 877 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMA TCH,
908 errorTarget, 878 errorTarget, [argumentValue.type, parameter.type]);
909 [argumentValue.type, parameter.type]);
910 } 879 }
911 if (baseParameter.isInitializingFormal) { 880 if (baseParameter.isInitializingFormal) {
912 FieldElement field = (parameter as FieldFormalParameterElement).field; 881 FieldElement field = (parameter as FieldFormalParameterElement).field;
913 if (field != null) { 882 if (field != null) {
914 DartType fieldType = field.type; 883 DartType fieldType = field.type;
915 if (fieldType != parameter.type) { 884 if (fieldType != parameter.type) {
916 // We've already checked that the argument can be assigned to the 885 // We've already checked that the argument can be assigned to the
917 // parameter; we also need to check that it can be assigned to 886 // parameter; we also need to check that it can be assigned to
918 // the field. 887 // the field.
919 if (!_runtimeTypeMatch(argumentValue, fieldType)) { 888 if (!_runtimeTypeMatch(argumentValue, fieldType)) {
920 errorReporter.reportErrorForNode( 889 errorReporter.reportErrorForNode(
921 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE _MISMATCH, 890 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE _MISMATCH,
922 errorTarget, 891 errorTarget, [argumentValue.type, fieldType]);
923 [argumentValue.type, fieldType]);
924 } 892 }
925 } 893 }
926 String fieldName = field.name; 894 String fieldName = field.name;
927 fieldMap[fieldName] = argumentValue; 895 fieldMap[fieldName] = argumentValue;
928 } 896 }
929 } else { 897 } else {
930 String name = baseParameter.name; 898 String name = baseParameter.name;
931 parameterMap[name] = argumentValue; 899 parameterMap[name] = argumentValue;
932 } 900 }
933 } 901 }
(...skipping 11 matching lines...) Expand all
945 initializerExpression.accept(initializerVisitor); 913 initializerExpression.accept(initializerVisitor);
946 if (evaluationResult != null) { 914 if (evaluationResult != null) {
947 String fieldName = constructorFieldInitializer.fieldName.name; 915 String fieldName = constructorFieldInitializer.fieldName.name;
948 fieldMap[fieldName] = evaluationResult; 916 fieldMap[fieldName] = evaluationResult;
949 PropertyAccessorElement getter = definingClass.getGetter(fieldName); 917 PropertyAccessorElement getter = definingClass.getGetter(fieldName);
950 if (getter != null) { 918 if (getter != null) {
951 PropertyInducingElement field = getter.variable; 919 PropertyInducingElement field = getter.variable;
952 if (!_runtimeTypeMatch(evaluationResult, field.type)) { 920 if (!_runtimeTypeMatch(evaluationResult, field.type)) {
953 errorReporter.reportErrorForNode( 921 errorReporter.reportErrorForNode(
954 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_M ISMATCH, 922 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_M ISMATCH,
955 node, 923 node, [evaluationResult.type, fieldName, field.type]);
956 [evaluationResult.type, fieldName, field.type]);
957 } 924 }
958 } 925 }
959 } 926 }
960 } else if (initializer is SuperConstructorInvocation) { 927 } else if (initializer is SuperConstructorInvocation) {
961 SuperConstructorInvocation superConstructorInvocation = initializer; 928 SuperConstructorInvocation superConstructorInvocation = initializer;
962 SimpleIdentifier name = superConstructorInvocation.constructorName; 929 SimpleIdentifier name = superConstructorInvocation.constructorName;
963 if (name != null) { 930 if (name != null) {
964 superName = name.name; 931 superName = name.name;
965 } 932 }
966 superArguments = superConstructorInvocation.argumentList.arguments; 933 superArguments = superConstructorInvocation.argumentList.arguments;
967 } else if (initializer is RedirectingConstructorInvocation) { 934 } else if (initializer is RedirectingConstructorInvocation) {
968 // This is a redirecting constructor, so just evaluate the constructor 935 // This is a redirecting constructor, so just evaluate the constructor
969 // it redirects to. 936 // it redirects to.
970 ConstructorElement constructor = initializer.staticElement; 937 ConstructorElement constructor = initializer.staticElement;
971 if (constructor != null && constructor.isConst) { 938 if (constructor != null && constructor.isConst) {
972 return _evaluateConstructorCall( 939 return _evaluateConstructorCall(node,
973 node, 940 initializer.argumentList.arguments, constructor,
974 initializer.argumentList.arguments, 941 initializerVisitor, errorReporter);
975 constructor,
976 initializerVisitor,
977 errorReporter);
978 } 942 }
979 } 943 }
980 } 944 }
981 // Evaluate explicit or implicit call to super(). 945 // Evaluate explicit or implicit call to super().
982 InterfaceType superclass = definingClass.superclass; 946 InterfaceType superclass = definingClass.superclass;
983 if (superclass != null && !superclass.isObject) { 947 if (superclass != null && !superclass.isObject) {
984 ConstructorElement superConstructor = 948 ConstructorElement superConstructor =
985 superclass.lookUpConstructor(superName, constructor.library); 949 superclass.lookUpConstructor(superName, constructor.library);
986 if (superConstructor != null) { 950 if (superConstructor != null) {
987 if (superArguments == null) { 951 if (superArguments == null) {
988 superArguments = new NodeList<Expression>(null); 952 superArguments = new NodeList<Expression>(null);
989 } 953 }
990 _evaluateSuperConstructorCall( 954 _evaluateSuperConstructorCall(node, fieldMap, superConstructor,
991 node, 955 superArguments, initializerVisitor, errorReporter);
992 fieldMap,
993 superConstructor,
994 superArguments,
995 initializerVisitor,
996 errorReporter);
997 } 956 }
998 } 957 }
999 return new DartObjectImpl(definingClass, new GenericState(fieldMap)); 958 return new DartObjectImpl(definingClass, new GenericState(fieldMap));
1000 } 959 }
1001 960
1002 void _evaluateSuperConstructorCall(AstNode node, HashMap<String, 961 void _evaluateSuperConstructorCall(AstNode node,
1003 DartObjectImpl> fieldMap, ConstructorElement superConstructor, 962 HashMap<String, DartObjectImpl> fieldMap,
1004 NodeList<Expression> superArguments, ConstantVisitor initializerVisitor, 963 ConstructorElement superConstructor, NodeList<Expression> superArguments,
1005 ErrorReporter errorReporter) { 964 ConstantVisitor initializerVisitor, ErrorReporter errorReporter) {
1006 if (superConstructor != null && superConstructor.isConst) { 965 if (superConstructor != null && superConstructor.isConst) {
1007 DartObjectImpl evaluationResult = _evaluateConstructorCall( 966 DartObjectImpl evaluationResult = _evaluateConstructorCall(node,
1008 node, 967 superArguments, superConstructor, initializerVisitor, errorReporter);
1009 superArguments,
1010 superConstructor,
1011 initializerVisitor,
1012 errorReporter);
1013 if (evaluationResult != null) { 968 if (evaluationResult != null) {
1014 fieldMap[GenericState.SUPERCLASS_FIELD] = evaluationResult; 969 fieldMap[GenericState.SUPERCLASS_FIELD] = evaluationResult;
1015 } 970 }
1016 } 971 }
1017 } 972 }
1018 973
1019 /** 974 /**
1020 * Attempt to follow the chain of factory redirections until a constructor is reached which is not 975 * Attempt to follow the chain of factory redirections until a constructor is reached which is not
1021 * a const factory constructor. 976 * a const factory constructor.
1022 * 977 *
1023 * @return the constant constructor which terminates the chain of factory redi rections, if the 978 * @return the constant constructor which terminates the chain of factory redi rections, if the
1024 * chain terminates. If there is a problem (e.g. a redirection can't b e found, or a cycle 979 * chain terminates. If there is a problem (e.g. a redirection can't b e found, or a cycle
1025 * is encountered), the chain will be followed as far as possible and then a const factory 980 * is encountered), the chain will be followed as far as possible and then a const factory
1026 * constructor will be returned. 981 * constructor will be returned.
1027 */ 982 */
1028 ConstructorElement 983 ConstructorElement _followConstantRedirectionChain(
1029 _followConstantRedirectionChain(ConstructorElement constructor) { 984 ConstructorElement constructor) {
1030 HashSet<ConstructorElement> constructorsVisited = 985 HashSet<ConstructorElement> constructorsVisited =
1031 new HashSet<ConstructorElement>(); 986 new HashSet<ConstructorElement>();
1032 while (constructor.isFactory) { 987 while (constructor.isFactory) {
1033 if (identical( 988 if (identical(
1034 constructor.enclosingElement.type, 989 constructor.enclosingElement.type, typeProvider.symbolType)) {
1035 typeProvider.symbolType)) {
1036 // The dart:core.Symbol has a const factory constructor that redirects 990 // The dart:core.Symbol has a const factory constructor that redirects
1037 // to dart:_internal.Symbol. That in turn redirects to an external 991 // to dart:_internal.Symbol. That in turn redirects to an external
1038 // const constructor, which we won't be able to evaluate. 992 // const constructor, which we won't be able to evaluate.
1039 // So stop following the chain of redirections at dart:core.Symbol, and 993 // So stop following the chain of redirections at dart:core.Symbol, and
1040 // let [evaluateInstanceCreationExpression] handle it specially. 994 // let [evaluateInstanceCreationExpression] handle it specially.
1041 break; 995 break;
1042 } 996 }
1043 constructorsVisited.add(constructor); 997 constructorsVisited.add(constructor);
1044 ConstructorElement redirectedConstructor = 998 ConstructorElement redirectedConstructor =
1045 constructor.redirectedConstructor; 999 constructor.redirectedConstructor;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 if (type.isUndefined) { 1048 if (type.isUndefined) {
1095 return false; 1049 return false;
1096 } 1050 }
1097 return obj.type.isSubtypeOf(type); 1051 return obj.type.isSubtypeOf(type);
1098 } 1052 }
1099 1053
1100 /** 1054 /**
1101 * Determine whether the given string is a valid name for a public symbol (i.e . whether it is 1055 * Determine whether the given string is a valid name for a public symbol (i.e . whether it is
1102 * allowed for a call to the Symbol constructor). 1056 * allowed for a call to the Symbol constructor).
1103 */ 1057 */
1104 static bool isValidPublicSymbol(String name) => 1058 static bool isValidPublicSymbol(String name) => name.isEmpty ||
1105 name.isEmpty || 1059 name == "void" ||
1106 name == "void" || 1060 new JavaPatternMatcher(_PUBLIC_SYMBOL_PATTERN, name).matches();
1107 new JavaPatternMatcher(_PUBLIC_SYMBOL_PATTERN, name).matches();
1108 } 1061 }
1109 1062
1110 /** 1063 /**
1111 * A `ConstantValueComputer_InitializerCloner` is an [AstCloner] that copies the 1064 * A `ConstantValueComputer_InitializerCloner` is an [AstCloner] that copies the
1112 * necessary information from the AST to allow const constructor initializers to 1065 * necessary information from the AST to allow const constructor initializers to
1113 * be evaluated. 1066 * be evaluated.
1114 */ 1067 */
1115 class ConstantValueComputer_InitializerCloner extends AstCloner { 1068 class ConstantValueComputer_InitializerCloner extends AstCloner {
1116 // TODO(brianwilkerson) Investigate replacing uses of this class with uses of 1069 // TODO(brianwilkerson) Investigate replacing uses of this class with uses of
1117 // AstCloner and ResolutionCopier. 1070 // AstCloner and ResolutionCopier.
1118 1071
1119 ConstantValueComputer_InitializerCloner() : super(true); 1072 ConstantValueComputer_InitializerCloner() : super(true);
1120 1073
1121 @override 1074 @override
1122 InstanceCreationExpression 1075 InstanceCreationExpression visitInstanceCreationExpression(
1123 visitInstanceCreationExpression(InstanceCreationExpression node) { 1076 InstanceCreationExpression node) {
1124 InstanceCreationExpression expression = 1077 InstanceCreationExpression expression =
1125 super.visitInstanceCreationExpression(node); 1078 super.visitInstanceCreationExpression(node);
1126 expression.evaluationResult = node.evaluationResult; 1079 expression.evaluationResult = node.evaluationResult;
1127 return expression; 1080 return expression;
1128 } 1081 }
1129 1082
1130 @override 1083 @override
1131 RedirectingConstructorInvocation 1084 RedirectingConstructorInvocation visitRedirectingConstructorInvocation(
1132 visitRedirectingConstructorInvocation(RedirectingConstructorInvocation nod e) { 1085 RedirectingConstructorInvocation node) {
1133 RedirectingConstructorInvocation invocation = 1086 RedirectingConstructorInvocation invocation =
1134 super.visitRedirectingConstructorInvocation(node); 1087 super.visitRedirectingConstructorInvocation(node);
1135 invocation.staticElement = node.staticElement; 1088 invocation.staticElement = node.staticElement;
1136 return invocation; 1089 return invocation;
1137 } 1090 }
1138 1091
1139 @override 1092 @override
1140 SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) { 1093 SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) {
1141 SimpleIdentifier identifier = super.visitSimpleIdentifier(node); 1094 SimpleIdentifier identifier = super.visitSimpleIdentifier(node);
1142 identifier.staticElement = node.staticElement; 1095 identifier.staticElement = node.staticElement;
1143 return identifier; 1096 return identifier;
1144 } 1097 }
1145 1098
1146 @override 1099 @override
1147 SuperConstructorInvocation 1100 SuperConstructorInvocation visitSuperConstructorInvocation(
1148 visitSuperConstructorInvocation(SuperConstructorInvocation node) { 1101 SuperConstructorInvocation node) {
1149 SuperConstructorInvocation invocation = 1102 SuperConstructorInvocation invocation =
1150 super.visitSuperConstructorInvocation(node); 1103 super.visitSuperConstructorInvocation(node);
1151 invocation.staticElement = node.staticElement; 1104 invocation.staticElement = node.staticElement;
1152 return invocation; 1105 return invocation;
1153 } 1106 }
1154 } 1107 }
1155 1108
1156 /** 1109 /**
1157 * Instances of the class `ConstantVisitor` evaluate constant expressions to pro duce their 1110 * Instances of the class `ConstantVisitor` evaluate constant expressions to pro duce their
1158 * compile-time value. According to the Dart Language Specification: <blockquote > A constant 1111 * compile-time value. According to the Dart Language Specification: <blockquote > A constant
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 new DartObjectComputer(_errorReporter, _typeProvider); 1185 new DartObjectComputer(_errorReporter, _typeProvider);
1233 } 1186 }
1234 1187
1235 /** 1188 /**
1236 * Initialize a newly created constant visitor. 1189 * Initialize a newly created constant visitor.
1237 * 1190 *
1238 * @param typeProvider the type provider used to access known types 1191 * @param typeProvider the type provider used to access known types
1239 * @param lexicalEnvironment values which should override simpleIdentifiers, o r null if no 1192 * @param lexicalEnvironment values which should override simpleIdentifiers, o r null if no
1240 * overriding is necessary. 1193 * overriding is necessary.
1241 */ 1194 */
1242 ConstantVisitor.con2(this._typeProvider, HashMap<String, 1195 ConstantVisitor.con2(this._typeProvider,
1243 DartObjectImpl> lexicalEnvironment, this._errorReporter) { 1196 HashMap<String, DartObjectImpl> lexicalEnvironment, this._errorReporter) {
1244 this._lexicalEnvironment = lexicalEnvironment; 1197 this._lexicalEnvironment = lexicalEnvironment;
1245 this._dartObjectComputer = 1198 this._dartObjectComputer =
1246 new DartObjectComputer(_errorReporter, _typeProvider); 1199 new DartObjectComputer(_errorReporter, _typeProvider);
1247 } 1200 }
1248 1201
1249 /** 1202 /**
1250 * Return an object representing the value 'null'. 1203 * Return an object representing the value 'null'.
1251 * 1204 *
1252 * @return an object representing the value 'null' 1205 * @return an object representing the value 'null'
1253 */ 1206 */
1254 DartObjectImpl get null2 { 1207 DartObjectImpl get null2 {
1255 if (_nullObject == null) { 1208 if (_nullObject == null) {
1256 _nullObject = 1209 _nullObject =
1257 new DartObjectImpl(_typeProvider.nullType, NullState.NULL_STATE); 1210 new DartObjectImpl(_typeProvider.nullType, NullState.NULL_STATE);
1258 } 1211 }
1259 return _nullObject; 1212 return _nullObject;
1260 } 1213 }
1261 1214
1262 /** 1215 /**
1263 * This method is called just before retrieving an evaluation result from an A ST node. Unit tests 1216 * This method is called just before retrieving an evaluation result from an A ST node. Unit tests
1264 * will override it to introduce additional error checking. 1217 * will override it to introduce additional error checking.
1265 */ 1218 */
1266 void beforeGetEvaluationResult(AstNode node) { 1219 void beforeGetEvaluationResult(AstNode node) {}
1267 }
1268 1220
1269 /** 1221 /**
1270 * Return `true` if the given [element] represents the `length` getter in 1222 * Return `true` if the given [element] represents the `length` getter in
1271 * class [String]. 1223 * class [String].
1272 */ 1224 */
1273 bool isStringLength(Element element) { 1225 bool isStringLength(Element element) {
1274 if (element is PropertyAccessorElement) { 1226 if (element is PropertyAccessorElement) {
1275 if (element.isGetter && element.name == 'length') { 1227 if (element.isGetter && element.name == 'length') {
1276 return element.enclosingElement == _typeProvider.stringType.element; 1228 return element.enclosingElement == _typeProvider.stringType.element;
1277 } 1229 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 } else if (operatorType == TokenType.BAR_BAR) { 1271 } else if (operatorType == TokenType.BAR_BAR) {
1320 return _dartObjectComputer.logicalOr(node, leftResult, rightResult); 1272 return _dartObjectComputer.logicalOr(node, leftResult, rightResult);
1321 } else if (operatorType == TokenType.CARET) { 1273 } else if (operatorType == TokenType.CARET) {
1322 return _dartObjectComputer.bitXor(node, leftResult, rightResult); 1274 return _dartObjectComputer.bitXor(node, leftResult, rightResult);
1323 } else if (operatorType == TokenType.EQ_EQ) { 1275 } else if (operatorType == TokenType.EQ_EQ) {
1324 return _dartObjectComputer.equalEqual(node, leftResult, rightResult); 1276 return _dartObjectComputer.equalEqual(node, leftResult, rightResult);
1325 } else if (operatorType == TokenType.GT) { 1277 } else if (operatorType == TokenType.GT) {
1326 return _dartObjectComputer.greaterThan(node, leftResult, rightResult); 1278 return _dartObjectComputer.greaterThan(node, leftResult, rightResult);
1327 } else if (operatorType == TokenType.GT_EQ) { 1279 } else if (operatorType == TokenType.GT_EQ) {
1328 return _dartObjectComputer.greaterThanOrEqual( 1280 return _dartObjectComputer.greaterThanOrEqual(
1329 node, 1281 node, leftResult, rightResult);
1330 leftResult,
1331 rightResult);
1332 } else if (operatorType == TokenType.GT_GT) { 1282 } else if (operatorType == TokenType.GT_GT) {
1333 return _dartObjectComputer.shiftRight(node, leftResult, rightResult); 1283 return _dartObjectComputer.shiftRight(node, leftResult, rightResult);
1334 } else if (operatorType == TokenType.LT) { 1284 } else if (operatorType == TokenType.LT) {
1335 return _dartObjectComputer.lessThan(node, leftResult, rightResult); 1285 return _dartObjectComputer.lessThan(node, leftResult, rightResult);
1336 } else if (operatorType == TokenType.LT_EQ) { 1286 } else if (operatorType == TokenType.LT_EQ) {
1337 return _dartObjectComputer.lessThanOrEqual( 1287 return _dartObjectComputer.lessThanOrEqual(
1338 node, 1288 node, leftResult, rightResult);
1339 leftResult,
1340 rightResult);
1341 } else if (operatorType == TokenType.LT_LT) { 1289 } else if (operatorType == TokenType.LT_LT) {
1342 return _dartObjectComputer.shiftLeft(node, leftResult, rightResult); 1290 return _dartObjectComputer.shiftLeft(node, leftResult, rightResult);
1343 } else if (operatorType == TokenType.MINUS) { 1291 } else if (operatorType == TokenType.MINUS) {
1344 return _dartObjectComputer.minus(node, leftResult, rightResult); 1292 return _dartObjectComputer.minus(node, leftResult, rightResult);
1345 } else if (operatorType == TokenType.PERCENT) { 1293 } else if (operatorType == TokenType.PERCENT) {
1346 return _dartObjectComputer.remainder(node, leftResult, rightResult); 1294 return _dartObjectComputer.remainder(node, leftResult, rightResult);
1347 } else if (operatorType == TokenType.PLUS) { 1295 } else if (operatorType == TokenType.PLUS) {
1348 return _dartObjectComputer.add(node, leftResult, rightResult); 1296 return _dartObjectComputer.add(node, leftResult, rightResult);
1349 } else if (operatorType == TokenType.STAR) { 1297 } else if (operatorType == TokenType.STAR) {
1350 return _dartObjectComputer.times(node, leftResult, rightResult); 1298 return _dartObjectComputer.times(node, leftResult, rightResult);
(...skipping 17 matching lines...) Expand all
1368 @override 1316 @override
1369 DartObjectImpl visitConditionalExpression(ConditionalExpression node) { 1317 DartObjectImpl visitConditionalExpression(ConditionalExpression node) {
1370 Expression condition = node.condition; 1318 Expression condition = node.condition;
1371 DartObjectImpl conditionResult = condition.accept(this); 1319 DartObjectImpl conditionResult = condition.accept(this);
1372 DartObjectImpl thenResult = node.thenExpression.accept(this); 1320 DartObjectImpl thenResult = node.thenExpression.accept(this);
1373 DartObjectImpl elseResult = node.elseExpression.accept(this); 1321 DartObjectImpl elseResult = node.elseExpression.accept(this);
1374 if (conditionResult == null) { 1322 if (conditionResult == null) {
1375 return conditionResult; 1323 return conditionResult;
1376 } else if (!conditionResult.isBool) { 1324 } else if (!conditionResult.isBool) {
1377 _errorReporter.reportErrorForNode( 1325 _errorReporter.reportErrorForNode(
1378 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, 1326 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL, condition);
1379 condition);
1380 return null; 1327 return null;
1381 } else if (thenResult == null) { 1328 } else if (thenResult == null) {
1382 return thenResult; 1329 return thenResult;
1383 } else if (elseResult == null) { 1330 } else if (elseResult == null) {
1384 return elseResult; 1331 return elseResult;
1385 } 1332 }
1386 conditionResult = 1333 conditionResult =
1387 _dartObjectComputer.applyBooleanConversion(condition, conditionResult); 1334 _dartObjectComputer.applyBooleanConversion(condition, conditionResult);
1388 if (conditionResult == null) { 1335 if (conditionResult == null) {
1389 return conditionResult; 1336 return conditionResult;
1390 } 1337 }
1391 if (conditionResult.isTrue) { 1338 if (conditionResult.isTrue) {
1392 return thenResult; 1339 return thenResult;
1393 } else if (conditionResult.isFalse) { 1340 } else if (conditionResult.isFalse) {
1394 return elseResult; 1341 return elseResult;
1395 } 1342 }
1396 ParameterizedType thenType = thenResult.type; 1343 ParameterizedType thenType = thenResult.type;
1397 ParameterizedType elseType = elseResult.type; 1344 ParameterizedType elseType = elseResult.type;
1398 return _validWithUnknownValue( 1345 return _validWithUnknownValue(
1399 thenType.getLeastUpperBound(elseType) as InterfaceType); 1346 thenType.getLeastUpperBound(elseType) as InterfaceType);
1400 } 1347 }
1401 1348
1402 @override 1349 @override
1403 DartObjectImpl visitDoubleLiteral(DoubleLiteral node) => 1350 DartObjectImpl visitDoubleLiteral(DoubleLiteral node) =>
1404 new DartObjectImpl(_typeProvider.doubleType, new DoubleState(node.value)); 1351 new DartObjectImpl(_typeProvider.doubleType, new DoubleState(node.value));
1405 1352
1406 @override 1353 @override
1407 DartObjectImpl 1354 DartObjectImpl visitInstanceCreationExpression(
1408 visitInstanceCreationExpression(InstanceCreationExpression node) { 1355 InstanceCreationExpression node) {
1409 if (!node.isConst) { 1356 if (!node.isConst) {
1410 // TODO(brianwilkerson) Figure out which error to report. 1357 // TODO(brianwilkerson) Figure out which error to report.
1411 _error(node, null); 1358 _error(node, null);
1412 return null; 1359 return null;
1413 } 1360 }
1414 beforeGetEvaluationResult(node); 1361 beforeGetEvaluationResult(node);
1415 EvaluationResultImpl result = node.evaluationResult; 1362 EvaluationResultImpl result = node.evaluationResult;
1416 if (result != null) { 1363 if (result != null) {
1417 return result.value; 1364 return result.value;
1418 } 1365 }
(...skipping 17 matching lines...) Expand all
1436 } 1383 }
1437 1384
1438 @override 1385 @override
1439 DartObjectImpl visitInterpolationString(InterpolationString node) => 1386 DartObjectImpl visitInterpolationString(InterpolationString node) =>
1440 new DartObjectImpl(_typeProvider.stringType, new StringState(node.value)); 1387 new DartObjectImpl(_typeProvider.stringType, new StringState(node.value));
1441 1388
1442 @override 1389 @override
1443 DartObjectImpl visitListLiteral(ListLiteral node) { 1390 DartObjectImpl visitListLiteral(ListLiteral node) {
1444 if (node.constKeyword == null) { 1391 if (node.constKeyword == null) {
1445 _errorReporter.reportErrorForNode( 1392 _errorReporter.reportErrorForNode(
1446 CompileTimeErrorCode.MISSING_CONST_IN_LIST_LITERAL, 1393 CompileTimeErrorCode.MISSING_CONST_IN_LIST_LITERAL, node);
1447 node);
1448 return null; 1394 return null;
1449 } 1395 }
1450 bool errorOccurred = false; 1396 bool errorOccurred = false;
1451 List<DartObjectImpl> elements = new List<DartObjectImpl>(); 1397 List<DartObjectImpl> elements = new List<DartObjectImpl>();
1452 for (Expression element in node.elements) { 1398 for (Expression element in node.elements) {
1453 DartObjectImpl elementResult = element.accept(this); 1399 DartObjectImpl elementResult = element.accept(this);
1454 if (elementResult == null) { 1400 if (elementResult == null) {
1455 errorOccurred = true; 1401 errorOccurred = true;
1456 } else { 1402 } else {
1457 elements.add(elementResult); 1403 elements.add(elementResult);
(...skipping 11 matching lines...) Expand all
1469 } 1415 }
1470 } 1416 }
1471 InterfaceType listType = _typeProvider.listType.substitute4([elementType]); 1417 InterfaceType listType = _typeProvider.listType.substitute4([elementType]);
1472 return new DartObjectImpl(listType, new ListState(elements)); 1418 return new DartObjectImpl(listType, new ListState(elements));
1473 } 1419 }
1474 1420
1475 @override 1421 @override
1476 DartObjectImpl visitMapLiteral(MapLiteral node) { 1422 DartObjectImpl visitMapLiteral(MapLiteral node) {
1477 if (node.constKeyword == null) { 1423 if (node.constKeyword == null) {
1478 _errorReporter.reportErrorForNode( 1424 _errorReporter.reportErrorForNode(
1479 CompileTimeErrorCode.MISSING_CONST_IN_MAP_LITERAL, 1425 CompileTimeErrorCode.MISSING_CONST_IN_MAP_LITERAL, node);
1480 node);
1481 return null; 1426 return null;
1482 } 1427 }
1483 bool errorOccurred = false; 1428 bool errorOccurred = false;
1484 HashMap<DartObjectImpl, DartObjectImpl> map = 1429 HashMap<DartObjectImpl, DartObjectImpl> map =
1485 new HashMap<DartObjectImpl, DartObjectImpl>(); 1430 new HashMap<DartObjectImpl, DartObjectImpl>();
1486 for (MapLiteralEntry entry in node.entries) { 1431 for (MapLiteralEntry entry in node.entries) {
1487 DartObjectImpl keyResult = entry.key.accept(this); 1432 DartObjectImpl keyResult = entry.key.accept(this);
1488 DartObjectImpl valueResult = entry.value.accept(this); 1433 DartObjectImpl valueResult = entry.value.accept(this);
1489 if (keyResult == null || valueResult == null) { 1434 if (keyResult == null || valueResult == null) {
1490 errorOccurred = true; 1435 errorOccurred = true;
(...skipping 30 matching lines...) Expand all
1521 if (function.name == "identical") { 1466 if (function.name == "identical") {
1522 NodeList<Expression> arguments = node.argumentList.arguments; 1467 NodeList<Expression> arguments = node.argumentList.arguments;
1523 if (arguments.length == 2) { 1468 if (arguments.length == 2) {
1524 Element enclosingElement = function.enclosingElement; 1469 Element enclosingElement = function.enclosingElement;
1525 if (enclosingElement is CompilationUnitElement) { 1470 if (enclosingElement is CompilationUnitElement) {
1526 LibraryElement library = enclosingElement.library; 1471 LibraryElement library = enclosingElement.library;
1527 if (library.isDartCore) { 1472 if (library.isDartCore) {
1528 DartObjectImpl leftArgument = arguments[0].accept(this); 1473 DartObjectImpl leftArgument = arguments[0].accept(this);
1529 DartObjectImpl rightArgument = arguments[1].accept(this); 1474 DartObjectImpl rightArgument = arguments[1].accept(this);
1530 return _dartObjectComputer.isIdentical( 1475 return _dartObjectComputer.isIdentical(
1531 node, 1476 node, leftArgument, rightArgument);
1532 leftArgument,
1533 rightArgument);
1534 } 1477 }
1535 } 1478 }
1536 } 1479 }
1537 } 1480 }
1538 } 1481 }
1539 // TODO(brianwilkerson) Figure out which error to report. 1482 // TODO(brianwilkerson) Figure out which error to report.
1540 _error(node, null); 1483 _error(node, null);
1541 return null; 1484 return null;
1542 } 1485 }
1543 1486
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 DartObjectImpl visitSymbolLiteral(SymbolLiteral node) { 1592 DartObjectImpl visitSymbolLiteral(SymbolLiteral node) {
1650 StringBuffer buffer = new StringBuffer(); 1593 StringBuffer buffer = new StringBuffer();
1651 List<Token> components = node.components; 1594 List<Token> components = node.components;
1652 for (int i = 0; i < components.length; i++) { 1595 for (int i = 0; i < components.length; i++) {
1653 if (i > 0) { 1596 if (i > 0) {
1654 buffer.writeCharCode(0x2E); 1597 buffer.writeCharCode(0x2E);
1655 } 1598 }
1656 buffer.write(components[i].lexeme); 1599 buffer.write(components[i].lexeme);
1657 } 1600 }
1658 return new DartObjectImpl( 1601 return new DartObjectImpl(
1659 _typeProvider.symbolType, 1602 _typeProvider.symbolType, new SymbolState(buffer.toString()));
1660 new SymbolState(buffer.toString()));
1661 } 1603 }
1662 1604
1663 /** 1605 /**
1664 * Create an error associated with the given node. 1606 * Create an error associated with the given node.
1665 * 1607 *
1666 * @param node the AST node associated with the error 1608 * @param node the AST node associated with the error
1667 * @param code the error code indicating the nature of the error 1609 * @param code the error code indicating the nature of the error
1668 */ 1610 */
1669 void _error(AstNode node, ErrorCode code) { 1611 void _error(AstNode node, ErrorCode code) {
1670 _errorReporter.reportErrorForNode( 1612 _errorReporter.reportErrorForNode(
1671 code == null ? CompileTimeErrorCode.INVALID_CONSTANT : code, 1613 code == null ? CompileTimeErrorCode.INVALID_CONSTANT : code, node);
1672 node);
1673 } 1614 }
1674 1615
1675 /** 1616 /**
1676 * Return the constant value of the static constant represented by the given e lement. 1617 * Return the constant value of the static constant represented by the given e lement.
1677 * 1618 *
1678 * @param node the node to be used if an error needs to be reported 1619 * @param node the node to be used if an error needs to be reported
1679 * @param element the element whose value is to be returned 1620 * @param element the element whose value is to be returned
1680 * @return the constant value of the static constant 1621 * @return the constant value of the static constant
1681 */ 1622 */
1682 DartObjectImpl _getConstantValue(AstNode node, Element element) { 1623 DartObjectImpl _getConstantValue(AstNode node, Element element) {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1851 } 1792 }
1852 return null; 1793 return null;
1853 } 1794 }
1854 1795
1855 /** 1796 /**
1856 * Return the result of applying boolean conversion to this result. 1797 * Return the result of applying boolean conversion to this result.
1857 * 1798 *
1858 * @param node the node against which errors should be reported 1799 * @param node the node against which errors should be reported
1859 * @return the result of applying boolean conversion to the given value 1800 * @return the result of applying boolean conversion to the given value
1860 */ 1801 */
1861 DartObjectImpl applyBooleanConversion(AstNode node, 1802 DartObjectImpl applyBooleanConversion(
1862 DartObjectImpl evaluationResult) { 1803 AstNode node, DartObjectImpl evaluationResult) {
1863 if (evaluationResult != null) { 1804 if (evaluationResult != null) {
1864 try { 1805 try {
1865 return evaluationResult.convertToBool(_typeProvider); 1806 return evaluationResult.convertToBool(_typeProvider);
1866 } on EvaluationException catch (exception) { 1807 } on EvaluationException catch (exception) {
1867 _errorReporter.reportErrorForNode(exception.errorCode, node); 1808 _errorReporter.reportErrorForNode(exception.errorCode, node);
1868 } 1809 }
1869 } 1810 }
1870 return null; 1811 return null;
1871 } 1812 }
1872 1813
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
2088 if (leftOperand != null && rightOperand != null) { 2029 if (leftOperand != null && rightOperand != null) {
2089 try { 2030 try {
2090 return leftOperand.notEqual(_typeProvider, rightOperand); 2031 return leftOperand.notEqual(_typeProvider, rightOperand);
2091 } on EvaluationException catch (exception) { 2032 } on EvaluationException catch (exception) {
2092 _errorReporter.reportErrorForNode(exception.errorCode, node); 2033 _errorReporter.reportErrorForNode(exception.errorCode, node);
2093 } 2034 }
2094 } 2035 }
2095 return null; 2036 return null;
2096 } 2037 }
2097 2038
2098 DartObjectImpl performToString(AstNode node, 2039 DartObjectImpl performToString(
2099 DartObjectImpl evaluationResult) { 2040 AstNode node, DartObjectImpl evaluationResult) {
2100 if (evaluationResult != null) { 2041 if (evaluationResult != null) {
2101 try { 2042 try {
2102 return evaluationResult.performToString(_typeProvider); 2043 return evaluationResult.performToString(_typeProvider);
2103 } on EvaluationException catch (exception) { 2044 } on EvaluationException catch (exception) {
2104 _errorReporter.reportErrorForNode(exception.errorCode, node); 2045 _errorReporter.reportErrorForNode(exception.errorCode, node);
2105 } 2046 }
2106 } 2047 }
2107 return null; 2048 return null;
2108 } 2049 }
2109 2050
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2142 } 2083 }
2143 return null; 2084 return null;
2144 } 2085 }
2145 2086
2146 /** 2087 /**
2147 * Return the result of invoking the 'length' getter on this result. 2088 * Return the result of invoking the 'length' getter on this result.
2148 * 2089 *
2149 * @param node the node against which errors should be reported 2090 * @param node the node against which errors should be reported
2150 * @return the result of invoking the 'length' getter on this result 2091 * @return the result of invoking the 'length' getter on this result
2151 */ 2092 */
2152 EvaluationResultImpl stringLength(Expression node, 2093 EvaluationResultImpl stringLength(
2153 EvaluationResultImpl evaluationResult) { 2094 Expression node, EvaluationResultImpl evaluationResult) {
2154 if (evaluationResult.value != null) { 2095 if (evaluationResult.value != null) {
2155 try { 2096 try {
2156 return new EvaluationResultImpl.con1( 2097 return new EvaluationResultImpl.con1(
2157 evaluationResult.value.stringLength(_typeProvider)); 2098 evaluationResult.value.stringLength(_typeProvider));
2158 } on EvaluationException catch (exception) { 2099 } on EvaluationException catch (exception) {
2159 _errorReporter.reportErrorForNode(exception.errorCode, node); 2100 _errorReporter.reportErrorForNode(exception.errorCode, node);
2160 } 2101 }
2161 } 2102 }
2162 return new EvaluationResultImpl.con1(null); 2103 return new EvaluationResultImpl.con1(null);
2163 } 2104 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
2316 } 2257 }
2317 2258
2318 /** 2259 /**
2319 * Return the result of invoking the '&' operator on this object with the give n argument. 2260 * Return the result of invoking the '&' operator on this object with the give n argument.
2320 * 2261 *
2321 * @param typeProvider the type provider used to find known types 2262 * @param typeProvider the type provider used to find known types
2322 * @param rightOperand the right-hand operand of the operation 2263 * @param rightOperand the right-hand operand of the operation
2323 * @return the result of invoking the '&' operator on this object with the giv en argument 2264 * @return the result of invoking the '&' operator on this object with the giv en argument
2324 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2265 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2325 */ 2266 */
2326 DartObjectImpl bitAnd(TypeProvider typeProvider, 2267 DartObjectImpl bitAnd(
2327 DartObjectImpl rightOperand) => 2268 TypeProvider typeProvider, DartObjectImpl rightOperand) =>
2328 new DartObjectImpl(typeProvider.intType, _state.bitAnd(rightOperand._state )); 2269 new DartObjectImpl(
2270 typeProvider.intType, _state.bitAnd(rightOperand._state));
2329 2271
2330 /** 2272 /**
2331 * Return the result of invoking the '~' operator on this object. 2273 * Return the result of invoking the '~' operator on this object.
2332 * 2274 *
2333 * @param typeProvider the type provider used to find known types 2275 * @param typeProvider the type provider used to find known types
2334 * @return the result of invoking the '~' operator on this object 2276 * @return the result of invoking the '~' operator on this object
2335 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2277 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2336 */ 2278 */
2337 DartObjectImpl bitNot(TypeProvider typeProvider) => 2279 DartObjectImpl bitNot(TypeProvider typeProvider) =>
2338 new DartObjectImpl(typeProvider.intType, _state.bitNot()); 2280 new DartObjectImpl(typeProvider.intType, _state.bitNot());
2339 2281
2340 /** 2282 /**
2341 * Return the result of invoking the '|' operator on this object with the give n argument. 2283 * Return the result of invoking the '|' operator on this object with the give n argument.
2342 * 2284 *
2343 * @param typeProvider the type provider used to find known types 2285 * @param typeProvider the type provider used to find known types
2344 * @param rightOperand the right-hand operand of the operation 2286 * @param rightOperand the right-hand operand of the operation
2345 * @return the result of invoking the '|' operator on this object with the giv en argument 2287 * @return the result of invoking the '|' operator on this object with the giv en argument
2346 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2288 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2347 */ 2289 */
2348 DartObjectImpl bitOr(TypeProvider typeProvider, 2290 DartObjectImpl bitOr(
2349 DartObjectImpl rightOperand) => 2291 TypeProvider typeProvider, DartObjectImpl rightOperand) =>
2350 new DartObjectImpl(typeProvider.intType, _state.bitOr(rightOperand._state) ); 2292 new DartObjectImpl(
2293 typeProvider.intType, _state.bitOr(rightOperand._state));
2351 2294
2352 /** 2295 /**
2353 * Return the result of invoking the '^' operator on this object with the give n argument. 2296 * Return the result of invoking the '^' operator on this object with the give n argument.
2354 * 2297 *
2355 * @param typeProvider the type provider used to find known types 2298 * @param typeProvider the type provider used to find known types
2356 * @param rightOperand the right-hand operand of the operation 2299 * @param rightOperand the right-hand operand of the operation
2357 * @return the result of invoking the '^' operator on this object with the giv en argument 2300 * @return the result of invoking the '^' operator on this object with the giv en argument
2358 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2301 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2359 */ 2302 */
2360 DartObjectImpl bitXor(TypeProvider typeProvider, 2303 DartObjectImpl bitXor(
2361 DartObjectImpl rightOperand) => 2304 TypeProvider typeProvider, DartObjectImpl rightOperand) =>
2362 new DartObjectImpl(typeProvider.intType, _state.bitXor(rightOperand._state )); 2305 new DartObjectImpl(
2306 typeProvider.intType, _state.bitXor(rightOperand._state));
2363 2307
2364 /** 2308 /**
2365 * Return the result of invoking the ' ' operator on this object with the give n argument. 2309 * Return the result of invoking the ' ' operator on this object with the give n argument.
2366 * 2310 *
2367 * @param typeProvider the type provider used to find known types 2311 * @param typeProvider the type provider used to find known types
2368 * @param rightOperand the right-hand operand of the operation 2312 * @param rightOperand the right-hand operand of the operation
2369 * @return the result of invoking the ' ' operator on this object with the giv en argument 2313 * @return the result of invoking the ' ' operator on this object with the giv en argument
2370 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2314 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2371 */ 2315 */
2372 DartObjectImpl concatenate(TypeProvider typeProvider, 2316 DartObjectImpl concatenate(
2373 DartObjectImpl rightOperand) => 2317 TypeProvider typeProvider, DartObjectImpl rightOperand) =>
2374 new DartObjectImpl( 2318 new DartObjectImpl(
2375 typeProvider.stringType, 2319 typeProvider.stringType, _state.concatenate(rightOperand._state));
2376 _state.concatenate(rightOperand._state));
2377 2320
2378 /** 2321 /**
2379 * Return the result of applying boolean conversion to this object. 2322 * Return the result of applying boolean conversion to this object.
2380 * 2323 *
2381 * @param typeProvider the type provider used to find known types 2324 * @param typeProvider the type provider used to find known types
2382 * @return the result of applying boolean conversion to this object 2325 * @return the result of applying boolean conversion to this object
2383 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2326 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2384 */ 2327 */
2385 DartObjectImpl convertToBool(TypeProvider typeProvider) { 2328 DartObjectImpl convertToBool(TypeProvider typeProvider) {
2386 InterfaceType boolType = typeProvider.boolType; 2329 InterfaceType boolType = typeProvider.boolType;
2387 if (identical(type, boolType)) { 2330 if (identical(type, boolType)) {
2388 return this; 2331 return this;
2389 } 2332 }
2390 return new DartObjectImpl(boolType, _state.convertToBool()); 2333 return new DartObjectImpl(boolType, _state.convertToBool());
2391 } 2334 }
2392 2335
2393 /** 2336 /**
2394 * Return the result of invoking the '/' operator on this object with the give n argument. 2337 * Return the result of invoking the '/' operator on this object with the give n argument.
2395 * 2338 *
2396 * @param typeProvider the type provider used to find known types 2339 * @param typeProvider the type provider used to find known types
2397 * @param rightOperand the right-hand operand of the operation 2340 * @param rightOperand the right-hand operand of the operation
2398 * @return the result of invoking the '/' operator on this object with the giv en argument 2341 * @return the result of invoking the '/' operator on this object with the giv en argument
2399 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2342 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2400 */ 2343 */
2401 DartObjectImpl divide(TypeProvider typeProvider, 2344 DartObjectImpl divide(
2402 DartObjectImpl rightOperand) { 2345 TypeProvider typeProvider, DartObjectImpl rightOperand) {
2403 InstanceState result = _state.divide(rightOperand._state); 2346 InstanceState result = _state.divide(rightOperand._state);
2404 if (result is IntState) { 2347 if (result is IntState) {
2405 return new DartObjectImpl(typeProvider.intType, result); 2348 return new DartObjectImpl(typeProvider.intType, result);
2406 } else if (result is DoubleState) { 2349 } else if (result is DoubleState) {
2407 return new DartObjectImpl(typeProvider.doubleType, result); 2350 return new DartObjectImpl(typeProvider.doubleType, result);
2408 } else if (result is NumState) { 2351 } else if (result is NumState) {
2409 return new DartObjectImpl(typeProvider.numType, result); 2352 return new DartObjectImpl(typeProvider.numType, result);
2410 } 2353 }
2411 // We should never get here. 2354 // We should never get here.
2412 throw new IllegalStateException("divide returned a ${result.runtimeType}"); 2355 throw new IllegalStateException("divide returned a ${result.runtimeType}");
2413 } 2356 }
2414 2357
2415 /** 2358 /**
2416 * Return the result of invoking the '==' operator on this object with the giv en argument. 2359 * Return the result of invoking the '==' operator on this object with the giv en argument.
2417 * 2360 *
2418 * @param typeProvider the type provider used to find known types 2361 * @param typeProvider the type provider used to find known types
2419 * @param rightOperand the right-hand operand of the operation 2362 * @param rightOperand the right-hand operand of the operation
2420 * @return the result of invoking the '==' operator on this object with the gi ven argument 2363 * @return the result of invoking the '==' operator on this object with the gi ven argument
2421 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2364 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2422 */ 2365 */
2423 DartObjectImpl equalEqual(TypeProvider typeProvider, 2366 DartObjectImpl equalEqual(
2424 DartObjectImpl rightOperand) { 2367 TypeProvider typeProvider, DartObjectImpl rightOperand) {
2425 if (type != rightOperand.type) { 2368 if (type != rightOperand.type) {
2426 String typeName = type.name; 2369 String typeName = type.name;
2427 if (!(typeName == "bool" || 2370 if (!(typeName == "bool" ||
2428 typeName == "double" || 2371 typeName == "double" ||
2429 typeName == "int" || 2372 typeName == "int" ||
2430 typeName == "num" || 2373 typeName == "num" ||
2431 typeName == "String" || 2374 typeName == "String" ||
2432 typeName == "Null" || 2375 typeName == "Null" ||
2433 type.isDynamic)) { 2376 type.isDynamic)) {
2434 throw new EvaluationException( 2377 throw new EvaluationException(
2435 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING); 2378 CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING);
2436 } 2379 }
2437 } 2380 }
2438 return new DartObjectImpl( 2381 return new DartObjectImpl(
2439 typeProvider.boolType, 2382 typeProvider.boolType, _state.equalEqual(rightOperand._state));
2440 _state.equalEqual(rightOperand._state));
2441 } 2383 }
2442 2384
2443 /** 2385 /**
2444 * Return the result of invoking the '&gt;' operator on this object with the g iven argument. 2386 * Return the result of invoking the '&gt;' operator on this object with the g iven argument.
2445 * 2387 *
2446 * @param typeProvider the type provider used to find known types 2388 * @param typeProvider the type provider used to find known types
2447 * @param rightOperand the right-hand operand of the operation 2389 * @param rightOperand the right-hand operand of the operation
2448 * @return the result of invoking the '&gt;' operator on this object with the given argument 2390 * @return the result of invoking the '&gt;' operator on this object with the given argument
2449 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2391 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2450 */ 2392 */
2451 DartObjectImpl greaterThan(TypeProvider typeProvider, 2393 DartObjectImpl greaterThan(
2452 DartObjectImpl rightOperand) => 2394 TypeProvider typeProvider, DartObjectImpl rightOperand) =>
2453 new DartObjectImpl( 2395 new DartObjectImpl(
2454 typeProvider.boolType, 2396 typeProvider.boolType, _state.greaterThan(rightOperand._state));
2455 _state.greaterThan(rightOperand._state));
2456 2397
2457 /** 2398 /**
2458 * Return the result of invoking the '&gt;=' operator on this object with the given argument. 2399 * Return the result of invoking the '&gt;=' operator on this object with the given argument.
2459 * 2400 *
2460 * @param typeProvider the type provider used to find known types 2401 * @param typeProvider the type provider used to find known types
2461 * @param rightOperand the right-hand operand of the operation 2402 * @param rightOperand the right-hand operand of the operation
2462 * @return the result of invoking the '&gt;=' operator on this object with the given argument 2403 * @return the result of invoking the '&gt;=' operator on this object with the given argument
2463 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2404 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2464 */ 2405 */
2465 DartObjectImpl greaterThanOrEqual(TypeProvider typeProvider, 2406 DartObjectImpl greaterThanOrEqual(TypeProvider typeProvider,
2466 DartObjectImpl rightOperand) => 2407 DartObjectImpl rightOperand) => new DartObjectImpl(
2467 new DartObjectImpl( 2408 typeProvider.boolType, _state.greaterThanOrEqual(rightOperand._state));
2468 typeProvider.boolType,
2469 _state.greaterThanOrEqual(rightOperand._state));
2470 2409
2471 /** 2410 /**
2472 * Return the result of invoking the '~/' operator on this object with the giv en argument. 2411 * Return the result of invoking the '~/' operator on this object with the giv en argument.
2473 * 2412 *
2474 * @param typeProvider the type provider used to find known types 2413 * @param typeProvider the type provider used to find known types
2475 * @param rightOperand the right-hand operand of the operation 2414 * @param rightOperand the right-hand operand of the operation
2476 * @return the result of invoking the '~/' operator on this object with the gi ven argument 2415 * @return the result of invoking the '~/' operator on this object with the gi ven argument
2477 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2416 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2478 */ 2417 */
2479 DartObjectImpl integerDivide(TypeProvider typeProvider, 2418 DartObjectImpl integerDivide(
2480 DartObjectImpl rightOperand) => 2419 TypeProvider typeProvider, DartObjectImpl rightOperand) =>
2481 new DartObjectImpl( 2420 new DartObjectImpl(
2482 typeProvider.intType, 2421 typeProvider.intType, _state.integerDivide(rightOperand._state));
2483 _state.integerDivide(rightOperand._state));
2484 2422
2485 /** 2423 /**
2486 * Return the result of invoking the identical function on this object with 2424 * Return the result of invoking the identical function on this object with
2487 * the given argument. 2425 * the given argument.
2488 * 2426 *
2489 * @param typeProvider the type provider used to find known types 2427 * @param typeProvider the type provider used to find known types
2490 * @param rightOperand the right-hand operand of the operation 2428 * @param rightOperand the right-hand operand of the operation
2491 * @return the result of invoking the identical function on this object with 2429 * @return the result of invoking the identical function on this object with
2492 * the given argument 2430 * the given argument
2493 */ 2431 */
2494 DartObjectImpl isIdentical(TypeProvider typeProvider, 2432 DartObjectImpl isIdentical(
2495 DartObjectImpl rightOperand) { 2433 TypeProvider typeProvider, DartObjectImpl rightOperand) {
2496 return new DartObjectImpl( 2434 return new DartObjectImpl(
2497 typeProvider.boolType, 2435 typeProvider.boolType, _state.isIdentical(rightOperand._state));
2498 _state.isIdentical(rightOperand._state));
2499 } 2436 }
2500 2437
2501 /** 2438 /**
2502 * Return the result of invoking the '&lt;' operator on this object with the g iven argument. 2439 * Return the result of invoking the '&lt;' operator on this object with the g iven argument.
2503 * 2440 *
2504 * @param typeProvider the type provider used to find known types 2441 * @param typeProvider the type provider used to find known types
2505 * @param rightOperand the right-hand operand of the operation 2442 * @param rightOperand the right-hand operand of the operation
2506 * @return the result of invoking the '&lt;' operator on this object with the given argument 2443 * @return the result of invoking the '&lt;' operator on this object with the given argument
2507 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2444 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2508 */ 2445 */
2509 DartObjectImpl lessThan(TypeProvider typeProvider, 2446 DartObjectImpl lessThan(
2510 DartObjectImpl rightOperand) => 2447 TypeProvider typeProvider, DartObjectImpl rightOperand) =>
2511 new DartObjectImpl(typeProvider.boolType, _state.lessThan(rightOperand._st ate)); 2448 new DartObjectImpl(
2449 typeProvider.boolType, _state.lessThan(rightOperand._state));
2512 2450
2513 /** 2451 /**
2514 * Return the result of invoking the '&lt;=' operator on this object with the given argument. 2452 * Return the result of invoking the '&lt;=' operator on this object with the given argument.
2515 * 2453 *
2516 * @param typeProvider the type provider used to find known types 2454 * @param typeProvider the type provider used to find known types
2517 * @param rightOperand the right-hand operand of the operation 2455 * @param rightOperand the right-hand operand of the operation
2518 * @return the result of invoking the '&lt;=' operator on this object with the given argument 2456 * @return the result of invoking the '&lt;=' operator on this object with the given argument
2519 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2457 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2520 */ 2458 */
2521 DartObjectImpl lessThanOrEqual(TypeProvider typeProvider, 2459 DartObjectImpl lessThanOrEqual(
2522 DartObjectImpl rightOperand) => 2460 TypeProvider typeProvider, DartObjectImpl rightOperand) =>
2523 new DartObjectImpl( 2461 new DartObjectImpl(
2524 typeProvider.boolType, 2462 typeProvider.boolType, _state.lessThanOrEqual(rightOperand._state));
2525 _state.lessThanOrEqual(rightOperand._state));
2526 2463
2527 /** 2464 /**
2528 * Return the result of invoking the '&&' operator on this object with the giv en argument. 2465 * Return the result of invoking the '&&' operator on this object with the giv en argument.
2529 * 2466 *
2530 * @param typeProvider the type provider used to find known types 2467 * @param typeProvider the type provider used to find known types
2531 * @param rightOperand the right-hand operand of the operation 2468 * @param rightOperand the right-hand operand of the operation
2532 * @return the result of invoking the '&&' operator on this object with the gi ven argument 2469 * @return the result of invoking the '&&' operator on this object with the gi ven argument
2533 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2470 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2534 */ 2471 */
2535 DartObjectImpl logicalAnd(TypeProvider typeProvider, 2472 DartObjectImpl logicalAnd(
2536 DartObjectImpl rightOperand) => 2473 TypeProvider typeProvider, DartObjectImpl rightOperand) =>
2537 new DartObjectImpl( 2474 new DartObjectImpl(
2538 typeProvider.boolType, 2475 typeProvider.boolType, _state.logicalAnd(rightOperand._state));
2539 _state.logicalAnd(rightOperand._state));
2540 2476
2541 /** 2477 /**
2542 * Return the result of invoking the '!' operator on this object. 2478 * Return the result of invoking the '!' operator on this object.
2543 * 2479 *
2544 * @param typeProvider the type provider used to find known types 2480 * @param typeProvider the type provider used to find known types
2545 * @return the result of invoking the '!' operator on this object 2481 * @return the result of invoking the '!' operator on this object
2546 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2482 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2547 */ 2483 */
2548 DartObjectImpl logicalNot(TypeProvider typeProvider) => 2484 DartObjectImpl logicalNot(TypeProvider typeProvider) =>
2549 new DartObjectImpl(typeProvider.boolType, _state.logicalNot()); 2485 new DartObjectImpl(typeProvider.boolType, _state.logicalNot());
2550 2486
2551 /** 2487 /**
2552 * Return the result of invoking the '||' operator on this object with the giv en argument. 2488 * Return the result of invoking the '||' operator on this object with the giv en argument.
2553 * 2489 *
2554 * @param typeProvider the type provider used to find known types 2490 * @param typeProvider the type provider used to find known types
2555 * @param rightOperand the right-hand operand of the operation 2491 * @param rightOperand the right-hand operand of the operation
2556 * @return the result of invoking the '||' operator on this object with the gi ven argument 2492 * @return the result of invoking the '||' operator on this object with the gi ven argument
2557 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2493 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2558 */ 2494 */
2559 DartObjectImpl logicalOr(TypeProvider typeProvider, 2495 DartObjectImpl logicalOr(
2560 DartObjectImpl rightOperand) => 2496 TypeProvider typeProvider, DartObjectImpl rightOperand) =>
2561 new DartObjectImpl( 2497 new DartObjectImpl(
2562 typeProvider.boolType, 2498 typeProvider.boolType, _state.logicalOr(rightOperand._state));
2563 _state.logicalOr(rightOperand._state));
2564 2499
2565 /** 2500 /**
2566 * Return the result of invoking the '-' operator on this object with the give n argument. 2501 * Return the result of invoking the '-' operator on this object with the give n argument.
2567 * 2502 *
2568 * @param typeProvider the type provider used to find known types 2503 * @param typeProvider the type provider used to find known types
2569 * @param rightOperand the right-hand operand of the operation 2504 * @param rightOperand the right-hand operand of the operation
2570 * @return the result of invoking the '-' operator on this object with the giv en argument 2505 * @return the result of invoking the '-' operator on this object with the giv en argument
2571 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2506 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2572 */ 2507 */
2573 DartObjectImpl minus(TypeProvider typeProvider, DartObjectImpl rightOperand) { 2508 DartObjectImpl minus(TypeProvider typeProvider, DartObjectImpl rightOperand) {
(...skipping 30 matching lines...) Expand all
2604 } 2539 }
2605 2540
2606 /** 2541 /**
2607 * Return the result of invoking the '!=' operator on this object with the giv en argument. 2542 * Return the result of invoking the '!=' operator on this object with the giv en argument.
2608 * 2543 *
2609 * @param typeProvider the type provider used to find known types 2544 * @param typeProvider the type provider used to find known types
2610 * @param rightOperand the right-hand operand of the operation 2545 * @param rightOperand the right-hand operand of the operation
2611 * @return the result of invoking the '!=' operator on this object with the gi ven argument 2546 * @return the result of invoking the '!=' operator on this object with the gi ven argument
2612 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2547 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2613 */ 2548 */
2614 DartObjectImpl notEqual(TypeProvider typeProvider, 2549 DartObjectImpl notEqual(
2615 DartObjectImpl rightOperand) { 2550 TypeProvider typeProvider, DartObjectImpl rightOperand) {
2616 if (type != rightOperand.type) { 2551 if (type != rightOperand.type) {
2617 String typeName = type.name; 2552 String typeName = type.name;
2618 if (typeName != "bool" && 2553 if (typeName != "bool" &&
2619 typeName != "double" && 2554 typeName != "double" &&
2620 typeName != "int" && 2555 typeName != "int" &&
2621 typeName != "num" && 2556 typeName != "num" &&
2622 typeName != "String") { 2557 typeName != "String") {
2623 return new DartObjectImpl(typeProvider.boolType, BoolState.TRUE_STATE); 2558 return new DartObjectImpl(typeProvider.boolType, BoolState.TRUE_STATE);
2624 } 2559 }
2625 } 2560 }
2626 return new DartObjectImpl( 2561 return new DartObjectImpl(typeProvider.boolType,
2627 typeProvider.boolType,
2628 _state.equalEqual(rightOperand._state).logicalNot()); 2562 _state.equalEqual(rightOperand._state).logicalNot());
2629 } 2563 }
2630 2564
2631 /** 2565 /**
2632 * Return the result of converting this object to a String. 2566 * Return the result of converting this object to a String.
2633 * 2567 *
2634 * @param typeProvider the type provider used to find known types 2568 * @param typeProvider the type provider used to find known types
2635 * @return the result of converting this object to a String 2569 * @return the result of converting this object to a String
2636 * @throws EvaluationException if the object cannot be converted to a String 2570 * @throws EvaluationException if the object cannot be converted to a String
2637 */ 2571 */
2638 DartObjectImpl performToString(TypeProvider typeProvider) { 2572 DartObjectImpl performToString(TypeProvider typeProvider) {
2639 InterfaceType stringType = typeProvider.stringType; 2573 InterfaceType stringType = typeProvider.stringType;
2640 if (identical(type, stringType)) { 2574 if (identical(type, stringType)) {
2641 return this; 2575 return this;
2642 } 2576 }
2643 return new DartObjectImpl(stringType, _state.convertToString()); 2577 return new DartObjectImpl(stringType, _state.convertToString());
2644 } 2578 }
2645 2579
2646 /** 2580 /**
2647 * Return the result of invoking the '%' operator on this object with the give n argument. 2581 * Return the result of invoking the '%' operator on this object with the give n argument.
2648 * 2582 *
2649 * @param typeProvider the type provider used to find known types 2583 * @param typeProvider the type provider used to find known types
2650 * @param rightOperand the right-hand operand of the operation 2584 * @param rightOperand the right-hand operand of the operation
2651 * @return the result of invoking the '%' operator on this object with the giv en argument 2585 * @return the result of invoking the '%' operator on this object with the giv en argument
2652 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2586 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2653 */ 2587 */
2654 DartObjectImpl remainder(TypeProvider typeProvider, 2588 DartObjectImpl remainder(
2655 DartObjectImpl rightOperand) { 2589 TypeProvider typeProvider, DartObjectImpl rightOperand) {
2656 InstanceState result = _state.remainder(rightOperand._state); 2590 InstanceState result = _state.remainder(rightOperand._state);
2657 if (result is IntState) { 2591 if (result is IntState) {
2658 return new DartObjectImpl(typeProvider.intType, result); 2592 return new DartObjectImpl(typeProvider.intType, result);
2659 } else if (result is DoubleState) { 2593 } else if (result is DoubleState) {
2660 return new DartObjectImpl(typeProvider.doubleType, result); 2594 return new DartObjectImpl(typeProvider.doubleType, result);
2661 } else if (result is NumState) { 2595 } else if (result is NumState) {
2662 return new DartObjectImpl(typeProvider.numType, result); 2596 return new DartObjectImpl(typeProvider.numType, result);
2663 } 2597 }
2664 // We should never get here. 2598 // We should never get here.
2665 throw new IllegalStateException( 2599 throw new IllegalStateException(
2666 "remainder returned a ${result.runtimeType}"); 2600 "remainder returned a ${result.runtimeType}");
2667 } 2601 }
2668 2602
2669 /** 2603 /**
2670 * Return the result of invoking the '&lt;&lt;' operator on this object with t he given argument. 2604 * Return the result of invoking the '&lt;&lt;' operator on this object with t he given argument.
2671 * 2605 *
2672 * @param typeProvider the type provider used to find known types 2606 * @param typeProvider the type provider used to find known types
2673 * @param rightOperand the right-hand operand of the operation 2607 * @param rightOperand the right-hand operand of the operation
2674 * @return the result of invoking the '&lt;&lt;' operator on this object with the given argument 2608 * @return the result of invoking the '&lt;&lt;' operator on this object with the given argument
2675 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2609 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2676 */ 2610 */
2677 DartObjectImpl shiftLeft(TypeProvider typeProvider, 2611 DartObjectImpl shiftLeft(
2678 DartObjectImpl rightOperand) => 2612 TypeProvider typeProvider, DartObjectImpl rightOperand) =>
2679 new DartObjectImpl(typeProvider.intType, _state.shiftLeft(rightOperand._st ate)); 2613 new DartObjectImpl(
2614 typeProvider.intType, _state.shiftLeft(rightOperand._state));
2680 2615
2681 /** 2616 /**
2682 * Return the result of invoking the '&gt;&gt;' operator on this object with t he given argument. 2617 * Return the result of invoking the '&gt;&gt;' operator on this object with t he given argument.
2683 * 2618 *
2684 * @param typeProvider the type provider used to find known types 2619 * @param typeProvider the type provider used to find known types
2685 * @param rightOperand the right-hand operand of the operation 2620 * @param rightOperand the right-hand operand of the operation
2686 * @return the result of invoking the '&gt;&gt;' operator on this object with the given argument 2621 * @return the result of invoking the '&gt;&gt;' operator on this object with the given argument
2687 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2622 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2688 */ 2623 */
2689 DartObjectImpl shiftRight(TypeProvider typeProvider, 2624 DartObjectImpl shiftRight(
2690 DartObjectImpl rightOperand) => 2625 TypeProvider typeProvider, DartObjectImpl rightOperand) =>
2691 new DartObjectImpl( 2626 new DartObjectImpl(
2692 typeProvider.intType, 2627 typeProvider.intType, _state.shiftRight(rightOperand._state));
2693 _state.shiftRight(rightOperand._state));
2694 2628
2695 /** 2629 /**
2696 * Return the result of invoking the 'length' getter on this object. 2630 * Return the result of invoking the 'length' getter on this object.
2697 * 2631 *
2698 * @param typeProvider the type provider used to find known types 2632 * @param typeProvider the type provider used to find known types
2699 * @return the result of invoking the 'length' getter on this object 2633 * @return the result of invoking the 'length' getter on this object
2700 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind 2634 * @throws EvaluationException if the operator is not appropriate for an objec t of this kind
2701 */ 2635 */
2702 DartObjectImpl stringLength(TypeProvider typeProvider) => 2636 DartObjectImpl stringLength(TypeProvider typeProvider) =>
2703 new DartObjectImpl(typeProvider.intType, _state.stringLength()); 2637 new DartObjectImpl(typeProvider.intType, _state.stringLength());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2798 * name interpreted as a String value. If the variable is not defined (or [var iableName] is 2732 * name interpreted as a String value. If the variable is not defined (or [var iableName] is
2799 * null), a DartObject representing "unknown" is returned. 2733 * null), a DartObject representing "unknown" is returned.
2800 * 2734 *
2801 * @param typeProvider the type provider used to find the type 'String' 2735 * @param typeProvider the type provider used to find the type 'String'
2802 * @param variableName the name of the variable whose value is to be returned 2736 * @param variableName the name of the variable whose value is to be returned
2803 */ 2737 */
2804 DartObject getString(TypeProvider typeProvider, String variableName) { 2738 DartObject getString(TypeProvider typeProvider, String variableName) {
2805 String value = _declaredVariables[variableName]; 2739 String value = _declaredVariables[variableName];
2806 if (value == null) { 2740 if (value == null) {
2807 return new DartObjectImpl( 2741 return new DartObjectImpl(
2808 typeProvider.stringType, 2742 typeProvider.stringType, StringState.UNKNOWN_VALUE);
2809 StringState.UNKNOWN_VALUE);
2810 } 2743 }
2811 return new DartObjectImpl(typeProvider.stringType, new StringState(value)); 2744 return new DartObjectImpl(typeProvider.stringType, new StringState(value));
2812 } 2745 }
2813 } 2746 }
2814 2747
2815 /** 2748 /**
2816 * Instances of the class `DoubleState` represent the state of an object represe nting a 2749 * Instances of the class `DoubleState` represent the state of an object represe nting a
2817 * double. 2750 * double.
2818 */ 2751 */
2819 class DoubleState extends NumState { 2752 class DoubleState extends NumState {
(...skipping 2127 matching lines...) Expand 10 before | Expand all | Expand 10 after
4947 final DirectedGraph<AstNode> _referenceGraph; 4880 final DirectedGraph<AstNode> _referenceGraph;
4948 4881
4949 /** 4882 /**
4950 * A table mapping constant variables to the declarations of those variables. 4883 * A table mapping constant variables to the declarations of those variables.
4951 */ 4884 */
4952 final HashMap<VariableElement, VariableDeclaration> _variableDeclarationMap; 4885 final HashMap<VariableElement, VariableDeclaration> _variableDeclarationMap;
4953 4886
4954 /** 4887 /**
4955 * A table mapping constant constructors to the declarations of those construc tors. 4888 * A table mapping constant constructors to the declarations of those construc tors.
4956 */ 4889 */
4957 final HashMap<ConstructorElement, ConstructorDeclaration> 4890 final HashMap<ConstructorElement, ConstructorDeclaration> _constructorDeclarat ionMap;
4958 _constructorDeclarationMap;
4959 4891
4960 /** 4892 /**
4961 * Initialize a newly created reference finder to find references from the giv en variable to other 4893 * Initialize a newly created reference finder to find references from the giv en variable to other
4962 * variables and to add those references to the given graph. 4894 * variables and to add those references to the given graph.
4963 * 4895 *
4964 * @param source the element representing the variable whose initializer will be visited 4896 * @param source the element representing the variable whose initializer will be visited
4965 * @param referenceGraph a graph recording which variables (heads) reference w hich other variables 4897 * @param referenceGraph a graph recording which variables (heads) reference w hich other variables
4966 * (tails) in their initializers 4898 * (tails) in their initializers
4967 * @param variableDeclarationMap A table mapping constant variables to the dec larations of those 4899 * @param variableDeclarationMap A table mapping constant variables to the dec larations of those
4968 * variables. 4900 * variables.
4969 * @param constructorDeclarationMap A table mapping constant constructors to t he declarations of 4901 * @param constructorDeclarationMap A table mapping constant constructors to t he declarations of
4970 * those constructors. 4902 * those constructors.
4971 */ 4903 */
4972 ReferenceFinder(this._source, this._referenceGraph, 4904 ReferenceFinder(this._source, this._referenceGraph,
4973 this._variableDeclarationMap, this._constructorDeclarationMap); 4905 this._variableDeclarationMap, this._constructorDeclarationMap);
4974 4906
4975 @override 4907 @override
4976 Object visitInstanceCreationExpression(InstanceCreationExpression node) { 4908 Object visitInstanceCreationExpression(InstanceCreationExpression node) {
4977 if (node.isConst) { 4909 if (node.isConst) {
4978 _referenceGraph.addEdge(_source, node); 4910 _referenceGraph.addEdge(_source, node);
4979 } 4911 }
4980 return null; 4912 return null;
4981 } 4913 }
4982 4914
4983 @override 4915 @override
4984 Object 4916 Object visitRedirectingConstructorInvocation(
4985 visitRedirectingConstructorInvocation(RedirectingConstructorInvocation nod e) { 4917 RedirectingConstructorInvocation node) {
4986 super.visitRedirectingConstructorInvocation(node); 4918 super.visitRedirectingConstructorInvocation(node);
4987 ConstructorElement target = node.staticElement; 4919 ConstructorElement target = node.staticElement;
4988 if (target != null && target.isConst) { 4920 if (target != null && target.isConst) {
4989 ConstructorDeclaration targetDeclaration = 4921 ConstructorDeclaration targetDeclaration =
4990 _constructorDeclarationMap[target]; 4922 _constructorDeclarationMap[target];
4991 if (targetDeclaration != null) { 4923 if (targetDeclaration != null) {
4992 _referenceGraph.addEdge(_source, targetDeclaration); 4924 _referenceGraph.addEdge(_source, targetDeclaration);
4993 } 4925 }
4994 } 4926 }
4995 return null; 4927 return null;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
5253 return BoolState.from(_element == rightElement); 5185 return BoolState.from(_element == rightElement);
5254 } else if (rightOperand is DynamicState) { 5186 } else if (rightOperand is DynamicState) {
5255 return BoolState.UNKNOWN_VALUE; 5187 return BoolState.UNKNOWN_VALUE;
5256 } 5188 }
5257 return BoolState.FALSE_STATE; 5189 return BoolState.FALSE_STATE;
5258 } 5190 }
5259 5191
5260 @override 5192 @override
5261 String toString() => _element == null ? "-unknown-" : _element.name; 5193 String toString() => _element == null ? "-unknown-" : _element.name;
5262 } 5194 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/ast.dart ('k') | pkg/analyzer/lib/src/generated/element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698