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

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

Issue 382953002: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 /** 280 /**
281 * Instances of the class `ConstantValueComputer` compute the values of constant variables and 281 * Instances of the class `ConstantValueComputer` compute the values of constant variables and
282 * constant constructor invocations in one or more compilation units. The expect ed usage pattern is 282 * constant constructor invocations in one or more compilation units. The expect ed usage pattern is
283 * for the compilation units to be added to this computer using the method 283 * for the compilation units to be added to this computer using the method
284 * [add] and then for the method [computeValues] to be invoked 284 * [add] and then for the method [computeValues] to be invoked
285 * exactly once. Any use of an instance after invoking the method [computeValues ] will 285 * exactly once. Any use of an instance after invoking the method [computeValues ] will
286 * result in unpredictable behavior. 286 * result in unpredictable behavior.
287 */ 287 */
288 class ConstantValueComputer { 288 class ConstantValueComputer {
289 /** 289 /**
290 * Parameter to "fromEnvironment" methods that denotes the default value.
291 */
292 static String _DEFAULT_VALUE_PARAM = "defaultValue";
293
294 /**
290 * The type provider used to access the known types. 295 * The type provider used to access the known types.
291 */ 296 */
292 TypeProvider typeProvider; 297 TypeProvider typeProvider;
293 298
294 /** 299 /**
295 * The object used to find constant variables and constant constructor invocat ions in the 300 * The object used to find constant variables and constant constructor invocat ions in the
296 * compilation units that were added. 301 * compilation units that were added.
297 */ 302 */
298 ConstantFinder _constantFinder = new ConstantFinder(); 303 ConstantFinder _constantFinder = new ConstantFinder();
299 304
(...skipping 12 matching lines...) Expand all
312 * A table mapping constant constructors to the declarations of those construc tors. 317 * A table mapping constant constructors to the declarations of those construc tors.
313 */ 318 */
314 HashMap<ConstructorElement, ConstructorDeclaration> constructorDeclarationMap; 319 HashMap<ConstructorElement, ConstructorDeclaration> constructorDeclarationMap;
315 320
316 /** 321 /**
317 * A collection of constant constructor invocations. 322 * A collection of constant constructor invocations.
318 */ 323 */
319 List<InstanceCreationExpression> _constructorInvocations; 324 List<InstanceCreationExpression> _constructorInvocations;
320 325
321 /** 326 /**
327 * The set of variables declared on the command line using '-D'.
328 */
329 final DeclaredVariables _declaredVariables;
330
331 /**
322 * Initialize a newly created constant value computer. 332 * Initialize a newly created constant value computer.
323 * 333 *
324 * @param typeProvider the type provider used to access known types 334 * @param typeProvider the type provider used to access known types
335 * @param declaredVariables the set of variables declared on the command line using '-D'
325 */ 336 */
326 ConstantValueComputer(TypeProvider typeProvider) { 337 ConstantValueComputer(TypeProvider typeProvider, this._declaredVariables) {
327 this.typeProvider = typeProvider; 338 this.typeProvider = typeProvider;
328 } 339 }
329 340
330 /** 341 /**
331 * Add the constants in the given compilation unit to the list of constants wh ose value needs to 342 * Add the constants in the given compilation unit to the list of constants wh ose value needs to
332 * be computed. 343 * be computed.
333 * 344 *
334 * @param unit the compilation unit defining the constants to be added 345 * @param unit the compilation unit defining the constants to be added
335 */ 346 */
336 void add(CompilationUnit unit) { 347 void add(CompilationUnit unit) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 449
439 /** 450 /**
440 * Create the ConstantVisitor used to evaluate constants. Unit tests will over ride this method to 451 * Create the ConstantVisitor used to evaluate constants. Unit tests will over ride this method to
441 * introduce additional error checking. 452 * introduce additional error checking.
442 */ 453 */
443 ConstantVisitor createConstantVisitor() => new ConstantVisitor.con1(typeProvid er); 454 ConstantVisitor createConstantVisitor() => new ConstantVisitor.con1(typeProvid er);
444 455
445 ConstructorDeclaration findConstructorDeclaration(ConstructorElement construct or) => constructorDeclarationMap[_getConstructorBase(constructor)]; 456 ConstructorDeclaration findConstructorDeclaration(ConstructorElement construct or) => constructorDeclarationMap[_getConstructorBase(constructor)];
446 457
447 /** 458 /**
459 * Check that the arguments to a call to fromEnvironment() are correct.
460 *
461 * @param arguments the AST nodes of the arguments.
462 * @param argumentValues the values of the unnamed arguments.
463 * @param namedArgumentValues the values of the named arguments.
464 * @param expectedDefaultValueType the allowed type of the "defaultValue" para meter (if present).
465 * Note: "defaultValue" is always allowed to be null.
466 * @return true if the arguments are correct, false if there is an error.
467 */
468 bool _checkFromEnvironmentArguments(NodeList<Expression> arguments, List<DartO bjectImpl> argumentValues, HashMap<String, DartObjectImpl> namedArgumentValues, InterfaceType expectedDefaultValueType) {
469 int argumentCount = arguments.length;
470 if (argumentCount < 1 || argumentCount > 2) {
471 return false;
472 }
473 if (arguments[0] is NamedExpression) {
474 return false;
475 }
476 if (!identical(argumentValues[0].type, typeProvider.stringType)) {
477 return false;
478 }
479 if (argumentCount == 2) {
480 if (arguments[1] is! NamedExpression) {
481 return false;
482 }
483 if (!((arguments[1] as NamedExpression).name.label.name == _DEFAULT_VALUE_ PARAM)) {
484 return false;
485 }
486 InterfaceType defaultValueType = namedArgumentValues[_DEFAULT_VALUE_PARAM] .type;
487 if (!(identical(defaultValueType, expectedDefaultValueType) || identical(d efaultValueType, typeProvider.nullType))) {
488 return false;
489 }
490 }
491 return true;
492 }
493
494 /**
448 * Compute a value for the given constant. 495 * Compute a value for the given constant.
449 * 496 *
450 * @param constNode the constant for which a value is to be computed 497 * @param constNode the constant for which a value is to be computed
451 */ 498 */
452 void _computeValueFor(AstNode constNode) { 499 void _computeValueFor(AstNode constNode) {
453 beforeComputeValue(constNode); 500 beforeComputeValue(constNode);
454 if (constNode is VariableDeclaration) { 501 if (constNode is VariableDeclaration) {
455 VariableDeclaration declaration = constNode; 502 VariableDeclaration declaration = constNode;
456 Element element = declaration.element; 503 Element element = declaration.element;
457 EvaluationResultImpl result = declaration.initializer.accept(createConstan tVisitor()); 504 EvaluationResultImpl result = declaration.initializer.accept(createConstan tVisitor());
458 (element as VariableElementImpl).evaluationResult = result; 505 (element as VariableElementImpl).evaluationResult = result;
459 } else if (constNode is InstanceCreationExpression) { 506 } else if (constNode is InstanceCreationExpression) {
460 InstanceCreationExpression expression = constNode; 507 InstanceCreationExpression expression = constNode;
461 ConstructorElement constructor = expression.staticElement; 508 ConstructorElement constructor = expression.staticElement;
462 if (constructor == null) { 509 if (constructor == null) {
463 // Couldn't resolve the constructor so we can't compute a value. No pro blem--the error 510 // Couldn't resolve the constructor so we can't compute a value. No pro blem--the error
464 // has already been reported. 511 // has already been reported.
465 return; 512 return;
466 } 513 }
467 ConstantVisitor constantVisitor = createConstantVisitor(); 514 ConstantVisitor constantVisitor = createConstantVisitor();
468 ValidResult result = _evaluateConstructorCall(expression.argumentList.argu ments, constructor, constantVisitor); 515 EvaluationResultImpl result = _evaluateConstructorCall(constNode, expressi on.argumentList.arguments, constructor, constantVisitor);
469 expression.evaluationResult = result; 516 expression.evaluationResult = result;
470 } else if (constNode is ConstructorDeclaration) { 517 } else if (constNode is ConstructorDeclaration) {
471 ConstructorDeclaration declaration = constNode; 518 ConstructorDeclaration declaration = constNode;
472 NodeList<ConstructorInitializer> initializers = declaration.initializers; 519 NodeList<ConstructorInitializer> initializers = declaration.initializers;
473 ConstructorElementImpl constructor = declaration.element as ConstructorEle mentImpl; 520 ConstructorElementImpl constructor = declaration.element as ConstructorEle mentImpl;
474 constructor.constantInitializers = new ConstantValueComputer_InitializerCl oner().cloneNodeList(initializers); 521 constructor.constantInitializers = new ConstantValueComputer_InitializerCl oner().cloneNodeList(initializers);
475 } else if (constNode is FormalParameter) { 522 } else if (constNode is FormalParameter) {
476 if (constNode is DefaultFormalParameter) { 523 if (constNode is DefaultFormalParameter) {
477 DefaultFormalParameter parameter = constNode; 524 DefaultFormalParameter parameter = constNode;
478 ParameterElement element = parameter.element; 525 ParameterElement element = parameter.element;
479 Expression defaultValue = parameter.defaultValue; 526 Expression defaultValue = parameter.defaultValue;
480 if (defaultValue != null) { 527 if (defaultValue != null) {
481 EvaluationResultImpl result = defaultValue.accept(createConstantVisito r()); 528 EvaluationResultImpl result = defaultValue.accept(createConstantVisito r());
482 (element as ParameterElementImpl).evaluationResult = result; 529 (element as ParameterElementImpl).evaluationResult = result;
483 } 530 }
484 } 531 }
485 } else { 532 } else {
486 // Should not happen. 533 // Should not happen.
487 AnalysisEngine.instance.logger.logError("Constant value computer trying to compute the value of a node which is not a VariableDeclaration, InstanceCreatio nExpression, FormalParameter, or ConstructorDeclaration"); 534 AnalysisEngine.instance.logger.logError("Constant value computer trying to compute the value of a node which is not a VariableDeclaration, InstanceCreatio nExpression, FormalParameter, or ConstructorDeclaration");
488 return; 535 return;
489 } 536 }
490 } 537 }
491 538
492 ValidResult _evaluateConstructorCall(NodeList<Expression> arguments, Construct orElement constructor, ConstantVisitor constantVisitor) { 539 /**
540 * Evaluate a call to fromEnvironment() on the bool, int, or String class.
541 *
542 * @param environmentValue Value fetched from the environment
543 * @param builtInDefaultValue Value that should be used as the default if no " defaultValue"
544 * argument appears in [namedArgumentValues].
545 * @param namedArgumentValues Named parameters passed to fromEnvironment()
546 * @return A [ValidResult] object corresponding to the evaluated result
547 */
548 ValidResult _computeValueFromEnvironment(DartObject environmentValue, DartObje ctImpl builtInDefaultValue, HashMap<String, DartObjectImpl> namedArgumentValues) {
549 DartObjectImpl value = environmentValue as DartObjectImpl;
550 if (value.isUnknown || value.isNull) {
551 // The name either doesn't exist in the environment or we couldn't parse t he corresponding
552 // value. If the code supplied an explicit default, use it.
553 if (namedArgumentValues.containsKey(_DEFAULT_VALUE_PARAM)) {
554 value = namedArgumentValues[_DEFAULT_VALUE_PARAM];
555 } else if (value.isNull) {
556 // The code didn't supply an explicit default. The name exists in the e nvironment but
557 // we couldn't parse the corresponding value. So use the built-in defau lt value, because
558 // this is what the VM does.
559 value = builtInDefaultValue;
560 } else {
561 }
562 }
563 return new ValidResult(value);
564 }
565
566 EvaluationResultImpl _evaluateConstructorCall(AstNode node, NodeList<Expressio n> arguments, ConstructorElement constructor, ConstantVisitor constantVisitor) {
493 int argumentCount = arguments.length; 567 int argumentCount = arguments.length;
494 List<DartObjectImpl> argumentValues = new List<DartObjectImpl>(argumentCount ); 568 List<DartObjectImpl> argumentValues = new List<DartObjectImpl>(argumentCount );
495 HashMap<String, DartObjectImpl> namedArgumentValues = new HashMap<String, Da rtObjectImpl>(); 569 HashMap<String, DartObjectImpl> namedArgumentValues = new HashMap<String, Da rtObjectImpl>();
496 for (int i = 0; i < argumentCount; i++) { 570 for (int i = 0; i < argumentCount; i++) {
497 Expression argument = arguments[i]; 571 Expression argument = arguments[i];
498 if (argument is NamedExpression) { 572 if (argument is NamedExpression) {
499 NamedExpression namedExpression = argument; 573 NamedExpression namedExpression = argument;
500 String name = namedExpression.name.label.name; 574 String name = namedExpression.name.label.name;
501 namedArgumentValues[name] = constantVisitor._valueOf(namedExpression.exp ression); 575 namedArgumentValues[name] = constantVisitor._valueOf(namedExpression.exp ression);
502 argumentValues[i] = constantVisitor.null2; 576 argumentValues[i] = constantVisitor.null2;
503 } else { 577 } else {
504 argumentValues[i] = constantVisitor._valueOf(argument); 578 argumentValues[i] = constantVisitor._valueOf(argument);
505 } 579 }
506 } 580 }
507 constructor = _followConstantRedirectionChain(constructor); 581 constructor = _followConstantRedirectionChain(constructor);
508 InterfaceType definingClass = constructor.returnType as InterfaceType; 582 InterfaceType definingClass = constructor.returnType as InterfaceType;
509 if (constructor.isFactory) { 583 if (constructor.isFactory) {
510 // We couldn't find a non-factory constructor. See if it's because we rea ched an external 584 // We couldn't find a non-factory constructor. See if it's because we rea ched an external
511 // const factory constructor that we can emulate. 585 // const factory constructor that we can emulate.
512 // TODO(paulberry): if the constructor is one of {bool,int,String}.fromEnv ironment(), 586 if (constructor.name == "fromEnvironment") {
513 // we may be able to infer the value based on -D flags provided to the ana lyzer (see 587 if (!_checkFromEnvironmentArguments(arguments, argumentValues, namedArgu mentValues, definingClass)) {
514 // dartbug.com/17234). 588 return new ErrorResult.con1(node, CompileTimeErrorCode.CONST_EVAL_THRO WS_EXCEPTION);
515 if (identical(definingClass, typeProvider.symbolType) && argumentCount == 1) { 589 }
590 String variableName = argumentCount < 1 ? null : argumentValues[0].strin gValue;
591 if (identical(definingClass, typeProvider.boolType)) {
592 DartObject valueFromEnvironment;
593 valueFromEnvironment = _declaredVariables.getBool(typeProvider, variab leName);
594 return _computeValueFromEnvironment(valueFromEnvironment, new DartObje ctImpl(typeProvider.boolType, BoolState.FALSE_STATE), namedArgumentValues);
595 } else if (identical(definingClass, typeProvider.intType)) {
596 DartObject valueFromEnvironment;
597 valueFromEnvironment = _declaredVariables.getInt(typeProvider, variabl eName);
598 return _computeValueFromEnvironment(valueFromEnvironment, new DartObje ctImpl(typeProvider.nullType, NullState.NULL_STATE), namedArgumentValues);
599 } else if (identical(definingClass, typeProvider.stringType)) {
600 DartObject valueFromEnvironment;
601 valueFromEnvironment = _declaredVariables.getString(typeProvider, vari ableName);
602 return _computeValueFromEnvironment(valueFromEnvironment, new DartObje ctImpl(typeProvider.nullType, NullState.NULL_STATE), namedArgumentValues);
603 }
604 } else if (constructor.name == "" && identical(definingClass, typeProvider .symbolType) && argumentCount == 1) {
516 String argumentValue = argumentValues[0].stringValue; 605 String argumentValue = argumentValues[0].stringValue;
517 if (argumentValue != null) { 606 if (argumentValue != null) {
518 return constantVisitor._valid(definingClass, new SymbolState(argumentV alue)); 607 return constantVisitor._valid(definingClass, new SymbolState(argumentV alue));
519 } 608 }
520 } 609 }
521 // Either it's an external const factory constructor that we can't emulate , or an error 610 // Either it's an external const factory constructor that we can't emulate , or an error
522 // occurred (a cycle, or a const constructor trying to delegate to a non-c onst constructor). 611 // occurred (a cycle, or a const constructor trying to delegate to a non-c onst constructor).
523 // In the former case, the best we can do is consider it an unknown value. In the latter 612 // In the former case, the best we can do is consider it an unknown value. In the latter
524 // case, the error has already been reported, so considering it an unknown value will 613 // case, the error has already been reported, so considering it an unknown value will
525 // suppress further errors. 614 // suppress further errors.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 } 687 }
599 } 688 }
600 // Evaluate explicit or implicit call to super(). 689 // Evaluate explicit or implicit call to super().
601 InterfaceType superclass = definingClass.superclass; 690 InterfaceType superclass = definingClass.superclass;
602 if (superclass != null && !superclass.isObject) { 691 if (superclass != null && !superclass.isObject) {
603 ConstructorElement superConstructor = superclass.lookUpConstructor(superNa me, constructor.library); 692 ConstructorElement superConstructor = superclass.lookUpConstructor(superNa me, constructor.library);
604 if (superConstructor != null) { 693 if (superConstructor != null) {
605 if (superArguments == null) { 694 if (superArguments == null) {
606 superArguments = new NodeList<Expression>(null); 695 superArguments = new NodeList<Expression>(null);
607 } 696 }
608 _evaluateSuperConstructorCall(fieldMap, superConstructor, superArguments , initializerVisitor); 697 _evaluateSuperConstructorCall(node, fieldMap, superConstructor, superArg uments, initializerVisitor);
609 } 698 }
610 } 699 }
611 return constantVisitor._valid(definingClass, new GenericState(fieldMap)); 700 return constantVisitor._valid(definingClass, new GenericState(fieldMap));
612 } 701 }
613 702
614 void _evaluateSuperConstructorCall(HashMap<String, DartObjectImpl> fieldMap, C onstructorElement superConstructor, NodeList<Expression> superArguments, Constan tVisitor initializerVisitor) { 703 void _evaluateSuperConstructorCall(AstNode node, HashMap<String, DartObjectImp l> fieldMap, ConstructorElement superConstructor, NodeList<Expression> superArgu ments, ConstantVisitor initializerVisitor) {
615 if (superConstructor != null && superConstructor.isConst) { 704 if (superConstructor != null && superConstructor.isConst) {
616 ValidResult evaluationResult = _evaluateConstructorCall(superArguments, su perConstructor, initializerVisitor); 705 EvaluationResultImpl evaluationResult = _evaluateConstructorCall(node, sup erArguments, superConstructor, initializerVisitor);
617 fieldMap[GenericState.SUPERCLASS_FIELD] = evaluationResult.value; 706 if (evaluationResult is ValidResult) {
707 ValidResult validResult = evaluationResult;
708 fieldMap[GenericState.SUPERCLASS_FIELD] = validResult.value;
709 }
618 } 710 }
619 } 711 }
620 712
621 /** 713 /**
622 * Attempt to follow the chain of factory redirections until a constructor is reached which is not 714 * Attempt to follow the chain of factory redirections until a constructor is reached which is not
623 * a const factory constructor. 715 * a const factory constructor.
624 * 716 *
625 * @return the constant constructor which terminates the chain of factory redi rections, if the 717 * @return the constant constructor which terminates the chain of factory redi rections, if the
626 * chain terminates. If there is a problem (e.g. a redirection can't b e found, or a cycle 718 * chain terminates. If there is a problem (e.g. a redirection can't b e found, or a cycle
627 * is encountered), the chain will be followed as far as possible and then a const factory 719 * is encountered), the chain will be followed as far as possible and then a const factory
(...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1736 * Define a variable with the given name to have the given value. 1828 * Define a variable with the given name to have the given value.
1737 * 1829 *
1738 * @param variableName the name of the variable being defined 1830 * @param variableName the name of the variable being defined
1739 * @param value the value of the variable 1831 * @param value the value of the variable
1740 */ 1832 */
1741 void define(String variableName, String value) { 1833 void define(String variableName, String value) {
1742 _declaredVariables[variableName] = value; 1834 _declaredVariables[variableName] = value;
1743 } 1835 }
1744 1836
1745 /** 1837 /**
1746 * Return the value of the variable with the given name interpreted as a boole an value, or 1838 * Return the value of the variable with the given name interpreted as a boole an value. If the
1747 * `null` if the variable is not defined. 1839 * variable is not defined (or [variableName] is null), a DartObject represent ing "unknown"
1840 * is returned. If the value can't be parsed as a boolean, a DartObject repres enting null is
1841 * returned.
1748 * 1842 *
1749 * @param typeProvider the type provider used to find the type 'bool' 1843 * @param typeProvider the type provider used to find the type 'bool'
1750 * @param variableName the name of the variable whose value is to be returned 1844 * @param variableName the name of the variable whose value is to be returned
1751 */ 1845 */
1752 DartObject getBool(TypeProvider typeProvider, String variableName) { 1846 DartObject getBool(TypeProvider typeProvider, String variableName) {
1753 String value = _declaredVariables[variableName]; 1847 String value = _declaredVariables[variableName];
1754 if (value == null) { 1848 if (value == null) {
1755 return null; 1849 return new DartObjectImpl(typeProvider.boolType, BoolState.UNKNOWN_VALUE);
1756 } 1850 }
1757 if (value == "true") { 1851 if (value == "true") {
1758 return new DartObjectImpl(typeProvider.boolType, BoolState.from(true)); 1852 return new DartObjectImpl(typeProvider.boolType, BoolState.TRUE_STATE);
1759 } else if (value == "false") { 1853 } else if (value == "false") {
1760 return new DartObjectImpl(typeProvider.boolType, BoolState.from(false)); 1854 return new DartObjectImpl(typeProvider.boolType, BoolState.FALSE_STATE);
1761 } 1855 }
1762 return null; 1856 return new DartObjectImpl(typeProvider.nullType, NullState.NULL_STATE);
1763 } 1857 }
1764 1858
1765 /** 1859 /**
1766 * Return the value of the variable with the given name interpreted as an inte ger value, or 1860 * Return the value of the variable with the given name interpreted as an inte ger value. If the
1767 * `null` if the variable is not defined. 1861 * variable is not defined (or [variableName] is null), a DartObject represent ing "unknown"
1862 * is returned. If the value can't be parsed as an integer, a DartObject repre senting null is
1863 * returned.
1768 * 1864 *
1769 * @param typeProvider the type provider used to find the type 'int' 1865 * @param typeProvider the type provider used to find the type 'int'
1770 * @param variableName the name of the variable whose value is to be returned 1866 * @param variableName the name of the variable whose value is to be returned
1771 * @throws NumberFormatException if the value of the variable is not a valid i nteger value
1772 */ 1867 */
1773 DartObject getInt(TypeProvider typeProvider, String variableName) { 1868 DartObject getInt(TypeProvider typeProvider, String variableName) {
1774 String value = _declaredVariables[variableName]; 1869 String value = _declaredVariables[variableName];
1775 if (value == null) { 1870 if (value == null) {
1776 return null; 1871 return new DartObjectImpl(typeProvider.intType, IntState.UNKNOWN_VALUE);
1777 } 1872 }
1778 return new DartObjectImpl(typeProvider.intType, new IntState(int.parse(value ))); 1873 int bigInteger;
1874 try {
1875 bigInteger = int.parse(value);
1876 } on FormatException catch (exception) {
1877 return new DartObjectImpl(typeProvider.nullType, NullState.NULL_STATE);
1878 }
1879 return new DartObjectImpl(typeProvider.intType, new IntState(bigInteger));
1779 } 1880 }
1780 1881
1781 /** 1882 /**
1782 * Return the value of the variable with the given name interpreted as a Strin g value, or 1883 * Return the value of the variable with the given name interpreted as a Strin g value, or
1783 * `null` if the variable is not defined. 1884 * `null` if the variable is not defined. Return the value of the variable wit h the given
1885 * name interpreted as a String value. If the variable is not defined (or [var iableName] is
1886 * null), a DartObject representing "unknown" is returned.
1784 * 1887 *
1785 * @param typeProvider the type provider used to find the type 'String' 1888 * @param typeProvider the type provider used to find the type 'String'
1786 * @param variableName the name of the variable whose value is to be returned 1889 * @param variableName the name of the variable whose value is to be returned
1787 */ 1890 */
1788 DartObject getString(TypeProvider typeProvider, String variableName) { 1891 DartObject getString(TypeProvider typeProvider, String variableName) {
1789 String value = _declaredVariables[variableName]; 1892 String value = _declaredVariables[variableName];
1790 if (value == null) { 1893 if (value == null) {
1791 return null; 1894 return new DartObjectImpl(typeProvider.intType, IntState.UNKNOWN_VALUE);
1792 } 1895 }
1793 return new DartObjectImpl(typeProvider.stringType, new StringState(value)); 1896 return new DartObjectImpl(typeProvider.stringType, new StringState(value));
1794 } 1897 }
1795 } 1898 }
1796 1899
1797 /** 1900 /**
1798 * Instances of the class `DoubleState` represent the state of an object represe nting a 1901 * Instances of the class `DoubleState` represent the state of an object represe nting a
1799 * double. 1902 * double.
1800 */ 1903 */
1801 class DoubleState extends NumState { 1904 class DoubleState extends NumState {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1979 } else if (rightOperand is DynamicState || rightOperand is NumState) { 2082 } else if (rightOperand is DynamicState || rightOperand is NumState) {
1980 return IntState.UNKNOWN_VALUE; 2083 return IntState.UNKNOWN_VALUE;
1981 } 2084 }
1982 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON); 2085 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
1983 } 2086 }
1984 2087
1985 @override 2088 @override
1986 bool get isBoolNumStringOrNull => true; 2089 bool get isBoolNumStringOrNull => true;
1987 2090
1988 @override 2091 @override
2092 bool get isUnknown => value == null;
2093
2094 @override
1989 BoolState lessThan(InstanceState rightOperand) { 2095 BoolState lessThan(InstanceState rightOperand) {
1990 assertNumOrNull(rightOperand); 2096 assertNumOrNull(rightOperand);
1991 if (value == null) { 2097 if (value == null) {
1992 return BoolState.UNKNOWN_VALUE; 2098 return BoolState.UNKNOWN_VALUE;
1993 } 2099 }
1994 if (rightOperand is IntState) { 2100 if (rightOperand is IntState) {
1995 int rightValue = rightOperand.value; 2101 int rightValue = rightOperand.value;
1996 if (rightValue == null) { 2102 if (rightValue == null) {
1997 return BoolState.UNKNOWN_VALUE; 2103 return BoolState.UNKNOWN_VALUE;
1998 } 2104 }
(...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after
3558 } else if (rightOperand is DynamicState || rightOperand is NumState) { 3664 } else if (rightOperand is DynamicState || rightOperand is NumState) {
3559 return UNKNOWN_VALUE; 3665 return UNKNOWN_VALUE;
3560 } 3666 }
3561 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON); 3667 throw new EvaluationException(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTI ON);
3562 } 3668 }
3563 3669
3564 @override 3670 @override
3565 bool get isBoolNumStringOrNull => true; 3671 bool get isBoolNumStringOrNull => true;
3566 3672
3567 @override 3673 @override
3674 bool get isUnknown => value == null;
3675
3676 @override
3568 BoolState lessThan(InstanceState rightOperand) { 3677 BoolState lessThan(InstanceState rightOperand) {
3569 assertNumOrNull(rightOperand); 3678 assertNumOrNull(rightOperand);
3570 if (value == null) { 3679 if (value == null) {
3571 return BoolState.UNKNOWN_VALUE; 3680 return BoolState.UNKNOWN_VALUE;
3572 } 3681 }
3573 if (rightOperand is IntState) { 3682 if (rightOperand is IntState) {
3574 int rightValue = rightOperand.value; 3683 int rightValue = rightOperand.value;
3575 if (rightValue == null) { 3684 if (rightValue == null) {
3576 return BoolState.UNKNOWN_VALUE; 3685 return BoolState.UNKNOWN_VALUE;
3577 } 3686 }
(...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after
4806 ErrorResult _error(AstNode node, ErrorCode code) => new ErrorResult.con1(node, code); 4915 ErrorResult _error(AstNode node, ErrorCode code) => new ErrorResult.con1(node, code);
4807 4916
4808 /** 4917 /**
4809 * Return a result object representing the given value. 4918 * Return a result object representing the given value.
4810 * 4919 *
4811 * @param value the value to be represented as a result object 4920 * @param value the value to be represented as a result object
4812 * @return a result object representing the given value 4921 * @return a result object representing the given value
4813 */ 4922 */
4814 ValidResult _valueOf(DartObjectImpl value) => new ValidResult(value); 4923 ValidResult _valueOf(DartObjectImpl value) => new ValidResult(value);
4815 } 4924 }
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