OLD | NEW |
1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
3 library engine.constant; | 3 library engine.constant; |
4 import 'java_core.dart'; | 4 import 'java_core.dart'; |
5 import 'source.dart' show Source; | 5 import 'source.dart' show Source; |
6 import 'error.dart' show AnalysisError, ErrorCode, CompileTimeErrorCode; | 6 import 'error.dart' show AnalysisError, ErrorCode, CompileTimeErrorCode; |
7 import 'scanner.dart' show TokenType; | 7 import 'scanner.dart' show TokenType; |
8 import 'ast.dart'; | 8 import 'ast.dart'; |
9 import 'element.dart'; | 9 import 'element.dart'; |
10 import 'engine.dart' show AnalysisEngine; | 10 import 'engine.dart' show AnalysisEngine; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 ConstantEvaluator(Source source) { | 53 ConstantEvaluator(Source source) { |
54 this._source = source; | 54 this._source = source; |
55 } | 55 } |
56 EvaluationResult evaluate(Expression expression) { | 56 EvaluationResult evaluate(Expression expression) { |
57 EvaluationResultImpl result = expression.accept(new ConstantVisitor()); | 57 EvaluationResultImpl result = expression.accept(new ConstantVisitor()); |
58 if (result is ValidResult) { | 58 if (result is ValidResult) { |
59 return EvaluationResult.forValue(((result as ValidResult)).value); | 59 return EvaluationResult.forValue(((result as ValidResult)).value); |
60 } | 60 } |
61 List<AnalysisError> errors = new List<AnalysisError>(); | 61 List<AnalysisError> errors = new List<AnalysisError>(); |
62 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { | 62 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { |
63 ASTNode node2 = data.node; | 63 ASTNode node = data.node; |
64 errors.add(new AnalysisError.con2(_source, node2.offset, node2.length, dat
a.errorCode, [])); | 64 errors.add(new AnalysisError.con2(_source, node.offset, node.length, data.
errorCode, [])); |
65 } | 65 } |
66 return EvaluationResult.forErrors(new List.from(errors)); | 66 return EvaluationResult.forErrors(new List.from(errors)); |
67 } | 67 } |
68 } | 68 } |
69 /** | 69 /** |
70 * Instances of the class {@code EvaluationResult} represent the result of attem
pting to evaluate an | 70 * Instances of the class {@code EvaluationResult} represent the result of attem
pting to evaluate an |
71 * expression. | 71 * expression. |
72 */ | 72 */ |
73 class EvaluationResult { | 73 class EvaluationResult { |
74 | 74 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 */ | 143 */ |
144 Map<VariableElement, VariableDeclaration> _variableMap = new Map<VariableEleme
nt, VariableDeclaration>(); | 144 Map<VariableElement, VariableDeclaration> _variableMap = new Map<VariableEleme
nt, VariableDeclaration>(); |
145 | 145 |
146 /** | 146 /** |
147 * Return a table mapping constant variable elements to the declarations of th
ose variables. | 147 * Return a table mapping constant variable elements to the declarations of th
ose variables. |
148 * @return a table mapping constant variable elements to the declarations of t
hose variables | 148 * @return a table mapping constant variable elements to the declarations of t
hose variables |
149 */ | 149 */ |
150 Map<VariableElement, VariableDeclaration> get variableMap => _variableMap; | 150 Map<VariableElement, VariableDeclaration> get variableMap => _variableMap; |
151 Object visitVariableDeclaration(VariableDeclaration node) { | 151 Object visitVariableDeclaration(VariableDeclaration node) { |
152 super.visitVariableDeclaration(node); | 152 super.visitVariableDeclaration(node); |
153 Expression initializer2 = node.initializer; | 153 Expression initializer = node.initializer; |
154 if (initializer2 != null && node.isConst()) { | 154 if (initializer != null && node.isConst()) { |
155 VariableElement element2 = node.element; | 155 VariableElement element = node.element; |
156 if (element2 != null) { | 156 if (element != null) { |
157 _variableMap[element2] = node; | 157 _variableMap[element] = node; |
158 } | 158 } |
159 } | 159 } |
160 return null; | 160 return null; |
161 } | 161 } |
162 } | 162 } |
163 /** | 163 /** |
164 * Instances of the class {@code ConstantValueComputer} compute the values of co
nstant variables in | 164 * Instances of the class {@code ConstantValueComputer} compute the values of co
nstant variables in |
165 * one or more compilation units. The expected usage pattern is for the compilat
ion units to be | 165 * one or more compilation units. The expected usage pattern is for the compilat
ion units to be |
166 * added to this computer using the method {@link #add(CompilationUnit)} and the
n for the method{@link #computeValues()} to invoked exactly once. Any use of an
instance after invoking the | 166 * added to this computer using the method {@link #add(CompilationUnit)} and the
n for the method{@link #computeValues()} to invoked exactly once. Any use of an
instance after invoking the |
167 * method {@link #computeValues()} will result in unpredictable behavior. | 167 * method {@link #computeValues()} will result in unpredictable behavior. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 void computeValueFor(VariableElement variable) { | 231 void computeValueFor(VariableElement variable) { |
232 VariableDeclaration declaration = _declarationMap[variable]; | 232 VariableDeclaration declaration = _declarationMap[variable]; |
233 if (declaration == null) { | 233 if (declaration == null) { |
234 return; | 234 return; |
235 } | 235 } |
236 EvaluationResultImpl result = declaration.initializer.accept(new ConstantVis
itor()); | 236 EvaluationResultImpl result = declaration.initializer.accept(new ConstantVis
itor()); |
237 ((variable as VariableElementImpl)).evaluationResult = result; | 237 ((variable as VariableElementImpl)).evaluationResult = result; |
238 if (result is ErrorResult) { | 238 if (result is ErrorResult) { |
239 List<AnalysisError> errors = new List<AnalysisError>(); | 239 List<AnalysisError> errors = new List<AnalysisError>(); |
240 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { | 240 for (ErrorResult_ErrorData data in ((result as ErrorResult)).errorData) { |
241 ASTNode node2 = data.node; | 241 ASTNode node = data.node; |
242 Source source2 = variable.getAncestor(CompilationUnitElement).source; | 242 Source source = variable.getAncestor(CompilationUnitElement).source; |
243 errors.add(new AnalysisError.con2(source2, node2.offset, node2.length, d
ata.errorCode, [])); | 243 errors.add(new AnalysisError.con2(source, node.offset, node.length, data
.errorCode, [])); |
244 } | 244 } |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 /** | 248 /** |
249 * Generate an error indicating that the given variable is not a valid compile
-time constant | 249 * Generate an error indicating that the given variable is not a valid compile
-time constant |
250 * because it references at least one of the variables in the given cycle, eac
h of which directly | 250 * because it references at least one of the variables in the given cycle, eac
h of which directly |
251 * or indirectly references the variable. | 251 * or indirectly references the variable. |
252 * @param variablesInCycle the variables in the cycle that includes the given
variable | 252 * @param variablesInCycle the variables in the cycle that includes the given
variable |
253 * @param variable the variable that is not a valid compile-time constant | 253 * @param variable the variable that is not a valid compile-time constant |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 for (MapLiteralEntry entry in node.entries) { | 383 for (MapLiteralEntry entry in node.entries) { |
384 result = union(result, entry.key.accept(this)); | 384 result = union(result, entry.key.accept(this)); |
385 result = union(result, entry.value.accept(this)); | 385 result = union(result, entry.value.accept(this)); |
386 } | 386 } |
387 if (result != null) { | 387 if (result != null) { |
388 return result; | 388 return result; |
389 } | 389 } |
390 return ValidResult.RESULT_OBJECT; | 390 return ValidResult.RESULT_OBJECT; |
391 } | 391 } |
392 EvaluationResultImpl visitMethodInvocation(MethodInvocation node) { | 392 EvaluationResultImpl visitMethodInvocation(MethodInvocation node) { |
393 Element element2 = node.methodName.element; | 393 Element element = node.methodName.element; |
394 if (element2 is FunctionElement) { | 394 if (element is FunctionElement) { |
395 FunctionElement function = element2 as FunctionElement; | 395 FunctionElement function = element as FunctionElement; |
396 if (function.name == "identical") { | 396 if (function.name == "identical") { |
397 NodeList<Expression> arguments2 = node.argumentList.arguments; | 397 NodeList<Expression> arguments = node.argumentList.arguments; |
398 if (arguments2.length == 2) { | 398 if (arguments.length == 2) { |
399 Element enclosingElement2 = function.enclosingElement; | 399 Element enclosingElement = function.enclosingElement; |
400 if (enclosingElement2 is CompilationUnitElement) { | 400 if (enclosingElement is CompilationUnitElement) { |
401 LibraryElement library2 = ((enclosingElement2 as CompilationUnitElem
ent)).library; | 401 LibraryElement library = ((enclosingElement as CompilationUnitElemen
t)).library; |
402 if (library2.isDartCore()) { | 402 if (library.isDartCore()) { |
403 EvaluationResultImpl leftArgument = arguments2[0].accept(this); | 403 EvaluationResultImpl leftArgument = arguments[0].accept(this); |
404 EvaluationResultImpl rightArgument = arguments2[1].accept(this); | 404 EvaluationResultImpl rightArgument = arguments[1].accept(this); |
405 return leftArgument.equalEqual(node, rightArgument); | 405 return leftArgument.equalEqual(node, rightArgument); |
406 } | 406 } |
407 } | 407 } |
408 } | 408 } |
409 } | 409 } |
410 } | 410 } |
411 return error(node, null); | 411 return error(node, null); |
412 } | 412 } |
413 EvaluationResultImpl visitNode(ASTNode node) => error(node, null); | 413 EvaluationResultImpl visitNode(ASTNode node) => error(node, null); |
414 EvaluationResultImpl visitNullLiteral(NullLiteral node) => ValidResult.RESULT_
NULL; | 414 EvaluationResultImpl visitNullLiteral(NullLiteral node) => ValidResult.RESULT_
NULL; |
415 EvaluationResultImpl visitParenthesizedExpression(ParenthesizedExpression node
) => node.expression.accept(this); | 415 EvaluationResultImpl visitParenthesizedExpression(ParenthesizedExpression node
) => node.expression.accept(this); |
416 EvaluationResultImpl visitPrefixedIdentifier(PrefixedIdentifier node) => getCo
nstantValue(node, node.element); | 416 EvaluationResultImpl visitPrefixedIdentifier(PrefixedIdentifier node) => getCo
nstantValue(node, node.element); |
417 EvaluationResultImpl visitPrefixExpression(PrefixExpression node) { | 417 EvaluationResultImpl visitPrefixExpression(PrefixExpression node) { |
418 EvaluationResultImpl operand2 = node.operand.accept(this); | 418 EvaluationResultImpl operand = node.operand.accept(this); |
419 if (operand2 is ValidResult && ((operand2 as ValidResult)).isNull()) { | 419 if (operand is ValidResult && ((operand as ValidResult)).isNull()) { |
420 return error(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION); | 420 return error(node, CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION); |
421 } | 421 } |
422 while (true) { | 422 while (true) { |
423 if (node.operator.type == TokenType.BANG) { | 423 if (node.operator.type == TokenType.BANG) { |
424 return operand2.logicalNot(node); | 424 return operand.logicalNot(node); |
425 } else if (node.operator.type == TokenType.TILDE) { | 425 } else if (node.operator.type == TokenType.TILDE) { |
426 return operand2.bitNot(node); | 426 return operand.bitNot(node); |
427 } else if (node.operator.type == TokenType.MINUS) { | 427 } else if (node.operator.type == TokenType.MINUS) { |
428 return operand2.negated(node); | 428 return operand.negated(node); |
429 } | 429 } |
430 break; | 430 break; |
431 } | 431 } |
432 return error(node, null); | 432 return error(node, null); |
433 } | 433 } |
434 EvaluationResultImpl visitPropertyAccess(PropertyAccess node) => getConstantVa
lue(node, node.propertyName.element); | 434 EvaluationResultImpl visitPropertyAccess(PropertyAccess node) => getConstantVa
lue(node, node.propertyName.element); |
435 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) => getConsta
ntValue(node, node.element); | 435 EvaluationResultImpl visitSimpleIdentifier(SimpleIdentifier node) => getConsta
ntValue(node, node.element); |
436 EvaluationResultImpl visitSimpleStringLiteral(SimpleStringLiteral node) => new
ValidResult(node.value); | 436 EvaluationResultImpl visitSimpleStringLiteral(SimpleStringLiteral node) => new
ValidResult(node.value); |
437 EvaluationResultImpl visitStringInterpolation(StringInterpolation node) { | 437 EvaluationResultImpl visitStringInterpolation(StringInterpolation node) { |
438 EvaluationResultImpl result = null; | 438 EvaluationResultImpl result = null; |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 * variables and to add those references to the given graph. | 872 * variables and to add those references to the given graph. |
873 * @param source the element representing the variable whose initializer will
be visited | 873 * @param source the element representing the variable whose initializer will
be visited |
874 * @param referenceGraph a graph recording which variables (heads) reference w
hich other variables | 874 * @param referenceGraph a graph recording which variables (heads) reference w
hich other variables |
875 * (tails) in their initializers | 875 * (tails) in their initializers |
876 */ | 876 */ |
877 ReferenceFinder(VariableElement source, DirectedGraph<VariableElement> referen
ceGraph) { | 877 ReferenceFinder(VariableElement source, DirectedGraph<VariableElement> referen
ceGraph) { |
878 this._source = source; | 878 this._source = source; |
879 this._referenceGraph = referenceGraph; | 879 this._referenceGraph = referenceGraph; |
880 } | 880 } |
881 Object visitSimpleIdentifier(SimpleIdentifier node) { | 881 Object visitSimpleIdentifier(SimpleIdentifier node) { |
882 Element element2 = node.element; | 882 Element element = node.element; |
883 if (element2 is PropertyAccessorElement) { | 883 if (element is PropertyAccessorElement) { |
884 element2 = ((element2 as PropertyAccessorElement)).variable; | 884 element = ((element as PropertyAccessorElement)).variable; |
885 } | 885 } |
886 if (element2 is VariableElement) { | 886 if (element is VariableElement) { |
887 VariableElement variable = element2 as VariableElement; | 887 VariableElement variable = element as VariableElement; |
888 if (variable.isConst()) { | 888 if (variable.isConst()) { |
889 _referenceGraph.addEdge(_source, variable); | 889 _referenceGraph.addEdge(_source, variable); |
890 } | 890 } |
891 } | 891 } |
892 return null; | 892 return null; |
893 } | 893 } |
894 } | 894 } |
895 /** | 895 /** |
896 * Instances of the class {@code ValidResult} represent the result of attempting
to evaluate a valid | 896 * Instances of the class {@code ValidResult} represent the result of attempting
to evaluate a valid |
897 * compile time constant expression. | 897 * compile time constant expression. |
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1657 */ | 1657 */ |
1658 ValidResult valueOf3(double value) => new ValidResult(value); | 1658 ValidResult valueOf3(double value) => new ValidResult(value); |
1659 | 1659 |
1660 /** | 1660 /** |
1661 * Return a result object representing the given value. | 1661 * Return a result object representing the given value. |
1662 * @param value the value to be represented as a result object | 1662 * @param value the value to be represented as a result object |
1663 * @return a result object representing the given value | 1663 * @return a result object representing the given value |
1664 */ | 1664 */ |
1665 ValidResult valueOf4(String value) => new ValidResult(value); | 1665 ValidResult valueOf4(String value) => new ValidResult(value); |
1666 } | 1666 } |
OLD | NEW |