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

Side by Side Diff: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/resolver/StaticTypeAnalyzer.java

Issue 913623002: Partial backport of analyzer async/await fixes to Java. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix status files Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, the Dart project authors. 2 * Copyright (c) 2013, the Dart project authors.
3 * 3 *
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except
5 * in compliance with the License. You may obtain a copy of the License at 5 * in compliance with the License. You may obtain a copy of the License at
6 * 6 *
7 * http://www.eclipse.org/legal/epl-v10.html 7 * http://www.eclipse.org/legal/epl-v10.html
8 * 8 *
9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License 9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express
11 * or implied. See the License for the specific language governing permissions a nd limitations under 11 * or implied. See the License for the specific language governing permissions a nd limitations under
12 * the License. 12 * the License.
13 */ 13 */
14 package com.google.dart.engine.internal.resolver; 14 package com.google.dart.engine.internal.resolver;
15 15
16 import com.google.dart.engine.ast.AdjacentStrings; 16 import com.google.dart.engine.ast.AdjacentStrings;
17 import com.google.dart.engine.ast.ArgumentList; 17 import com.google.dart.engine.ast.ArgumentList;
18 import com.google.dart.engine.ast.AsExpression; 18 import com.google.dart.engine.ast.AsExpression;
19 import com.google.dart.engine.ast.AssignmentExpression; 19 import com.google.dart.engine.ast.AssignmentExpression;
20 import com.google.dart.engine.ast.AstNode; 20 import com.google.dart.engine.ast.AstNode;
21 import com.google.dart.engine.ast.AwaitExpression;
21 import com.google.dart.engine.ast.BinaryExpression; 22 import com.google.dart.engine.ast.BinaryExpression;
22 import com.google.dart.engine.ast.BlockFunctionBody; 23 import com.google.dart.engine.ast.BlockFunctionBody;
23 import com.google.dart.engine.ast.BooleanLiteral; 24 import com.google.dart.engine.ast.BooleanLiteral;
24 import com.google.dart.engine.ast.CascadeExpression; 25 import com.google.dart.engine.ast.CascadeExpression;
25 import com.google.dart.engine.ast.ConditionalExpression; 26 import com.google.dart.engine.ast.ConditionalExpression;
26 import com.google.dart.engine.ast.DoubleLiteral; 27 import com.google.dart.engine.ast.DoubleLiteral;
27 import com.google.dart.engine.ast.Expression; 28 import com.google.dart.engine.ast.Expression;
28 import com.google.dart.engine.ast.ExpressionFunctionBody; 29 import com.google.dart.engine.ast.ExpressionFunctionBody;
29 import com.google.dart.engine.ast.FunctionBody; 30 import com.google.dart.engine.ast.FunctionBody;
30 import com.google.dart.engine.ast.FunctionDeclaration; 31 import com.google.dart.engine.ast.FunctionDeclaration;
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 Type propagatedType = computeStaticReturnType(propagatedMethodElement); 325 Type propagatedType = computeStaticReturnType(propagatedMethodElement);
325 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) { 326 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticTy pe)) {
326 recordPropagatedType(node, propagatedType); 327 recordPropagatedType(node, propagatedType);
327 } 328 }
328 } 329 }
329 } 330 }
330 return null; 331 return null;
331 } 332 }
332 333
333 /** 334 /**
335 * The Dart Language Specification, 16.29 (Await Expressions): <blockquote>Let flatten(T) =
336 * flatten(S) if T = Future&lt;S&gt;, and T otherwise. The static type of [the expression await
337 * "e"] is flatten(T) where T is the static type of e.</blockquote>
338 */
339 @Override
340 public Void visitAwaitExpression(AwaitExpression node) {
341 Type staticExpressionType = getStaticType(node.getExpression());
342 if (staticExpressionType == null) {
343 // TODO(brianwilkerson) Determine whether this can still happen.
344 staticExpressionType = dynamicType;
345 }
346 // TODO(paulberry): We should set staticType to flatten(staticExpressionType ). But we can't
347 // implement the flatten function because the Future type isn't available in the type provider.
348 // So to avoid bogus wrnings, set it to dynamic.
349 Type staticType = dynamicType;
350 recordStaticType(node, staticType);
351 Type propagatedExpressionType = node.getExpression().getPropagatedType();
352 if (propagatedExpressionType != null) {
353 // TODO(paulberry): This should be flatten(propagatedExpressionType) for t he same reasons as
354 // documented above next to the declaration of staticType.
355 Type propagatedType = dynamicType;
356 if (propagatedType != null && propagatedType.isMoreSpecificThan(staticType )) {
357 recordPropagatedType(node, propagatedType);
358 }
359 }
360 return null;
361 }
362
363 /**
334 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo gical boolean 364 * The Dart Language Specification, 12.20: <blockquote>The static type of a lo gical boolean
335 * expression is {@code bool}.</blockquote> 365 * expression is {@code bool}.</blockquote>
336 * <p> 366 * <p>
337 * The Dart Language Specification, 12.21:<blockquote>A bitwise expression of the form 367 * The Dart Language Specification, 12.21:<blockquote>A bitwise expression of the form
338 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio n 368 * <i>e<sub>1</sub> op e<sub>2</sub></i> is equivalent to the method invocatio n
339 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A bitwise expression of the form <i >super op 369 * <i>e<sub>1</sub>.op(e<sub>2</sub>)</i>. A bitwise expression of the form <i >super op
340 * e<sub>2</sub></i> is equivalent to the method invocation 370 * e<sub>2</sub></i> is equivalent to the method invocation
341 * <i>super.op(e<sub>2</sub>)</i>.</blockquote> 371 * <i>super.op(e<sub>2</sub>)</i>.</blockquote>
342 * <p> 372 * <p>
343 * The Dart Language Specification, 12.22: <blockquote>The static type of an e quality expression 373 * The Dart Language Specification, 12.22: <blockquote>The static type of an e quality expression
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 /** 1559 /**
1530 * Given a function expression, compute the return type of the function. The r eturn type of 1560 * Given a function expression, compute the return type of the function. The r eturn type of
1531 * functions with a block body is {@code dynamicType}, with an expression body it is the type of 1561 * functions with a block body is {@code dynamicType}, with an expression body it is the type of
1532 * the expression. 1562 * the expression.
1533 * 1563 *
1534 * @param node the function expression whose return type is to be computed 1564 * @param node the function expression whose return type is to be computed
1535 * @return the return type that was computed 1565 * @return the return type that was computed
1536 */ 1566 */
1537 private Type computeStaticReturnTypeOfFunctionExpression(FunctionExpression no de) { 1567 private Type computeStaticReturnTypeOfFunctionExpression(FunctionExpression no de) {
1538 FunctionBody body = node.getBody(); 1568 FunctionBody body = node.getBody();
1569 if (body.isGenerator()) {
1570 if (body.isAsynchronous()) {
1571 // TODO(paulberry): We should return Stream<dynamic>. But we can't beca use the Stream type
1572 // isn't available in the type provider. So to avoid bogus warnings, re turn dynamic.
1573 return typeProvider.getDynamicType();
1574 } else {
1575 return typeProvider.getIterableDynamicType();
1576 }
1577 }
1578 Type type;
1539 if (body instanceof ExpressionFunctionBody) { 1579 if (body instanceof ExpressionFunctionBody) {
1540 return getStaticType(((ExpressionFunctionBody) body).getExpression()); 1580 type = getStaticType(((ExpressionFunctionBody) body).getExpression());
1581 } else {
1582 type = dynamicType;
1541 } 1583 }
1542 return dynamicType; 1584 if (body.isAsynchronous()) {
1585 // TODO(paulberry): we should return Future<flatten(type)>. But we can't because the Future
1586 // type isn't available in the type provider. So to avoid bogus warnings, return dynamic.
1587 return dynamicType;
1588 } else {
1589 return type;
1590 }
1543 } 1591 }
1544 1592
1545 /** 1593 /**
1546 * If the given element name can be mapped to the name of a class defined with in the given 1594 * If the given element name can be mapped to the name of a class defined with in the given
1547 * library, return the type specified by the argument. 1595 * library, return the type specified by the argument.
1548 * 1596 *
1549 * @param library the library in which the specified type would be defined 1597 * @param library the library in which the specified type would be defined
1550 * @param elementName the name of the element for which a type is being sought 1598 * @param elementName the name of the element for which a type is being sought
1551 * @param nameMap an optional map used to map the element name to a type name 1599 * @param nameMap an optional map used to map the element name to a type name
1552 * @return the type specified by the first argument in the argument list 1600 * @return the type specified by the first argument in the argument list
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 || operator == TokenType.TILDE_SLASH) { 1925 || operator == TokenType.TILDE_SLASH) {
1878 if (getStaticType(node.getRightOperand()).equals(intType)) { 1926 if (getStaticType(node.getRightOperand()).equals(intType)) {
1879 staticType = intType; 1927 staticType = intType;
1880 } 1928 }
1881 } 1929 }
1882 } 1930 }
1883 // default 1931 // default
1884 return staticType; 1932 return staticType;
1885 } 1933 }
1886 } 1934 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698