Index: pkg/dev_compiler/lib/src/compiler/reify_coercions.dart |
diff --git a/pkg/dev_compiler/lib/src/compiler/reify_coercions.dart b/pkg/dev_compiler/lib/src/compiler/reify_coercions.dart |
index dd87fde4404b53cac8be34f9b97e0a1b13b51eb6..9d0492b1a07ee79a5ed2b3b55431682c0ef2b426 100644 |
--- a/pkg/dev_compiler/lib/src/compiler/reify_coercions.dart |
+++ b/pkg/dev_compiler/lib/src/compiler/reify_coercions.dart |
@@ -31,6 +31,23 @@ class CoercionReifier extends analyzer.GeneralizingAstVisitor<Object> { |
return units.map(cr.visitCompilationUnit).toList(growable: false); |
} |
+ |
+ /// Returns true if the `as` [node] was created by this class. |
+ // TODO(sra): Find a better way to recognize reified coercion, since we |
+ // can't set the isSynthetic attribute. |
+ static bool isImplicitCast(AsExpression node) => node.asOperator.offset == 0; |
+ |
+ /// Creates an implicit cast for expression [e] to [toType]. |
+ static Expression castExpression(Expression e, DartType toType) { |
+ // We use an empty name in the AST, because the JS code generator only cares |
+ // about the target type. It does not look at the AST name. |
+ var typeName = new TypeName(AstBuilder.identifierFromString(''), null); |
+ typeName.type = toType; |
+ var cast = AstBuilder.asExpression(e, typeName); |
+ cast.staticType = toType; |
+ return cast; |
+ } |
+ |
@override |
CompilationUnit visitCompilationUnit(CompilationUnit node) { |
if (ast_properties.hasImplicitCasts(node)) { |
@@ -47,7 +64,7 @@ class CoercionReifier extends analyzer.GeneralizingAstVisitor<Object> { |
var castType = ast_properties.getImplicitCast(node); |
if (castType != null) { |
- _replaceNode(node.parent, node, _castExpression(node, castType)); |
+ _replaceNode(node.parent, node, castExpression(node, castType)); |
} |
} |
@@ -79,7 +96,7 @@ class CoercionReifier extends analyzer.GeneralizingAstVisitor<Object> { |
// Build the cast. We will place this cast in the body, so need to clone |
// the variable's AST node and clear out its static type (otherwise we |
// will optimize away the cast). |
- var cast = _castExpression( |
+ var cast = castExpression( |
_clone(variable)..staticType = DynamicTypeImpl.instance, castType); |
var body = node.body; |
@@ -102,16 +119,6 @@ class CoercionReifier extends analyzer.GeneralizingAstVisitor<Object> { |
} |
} |
- Expression _castExpression(Expression e, DartType toType) { |
- // We use an empty name in the AST, because the JS code generator only cares |
- // about the target type. It does not look at the AST name. |
- var typeName = new TypeName(AstBuilder.identifierFromString(''), null); |
- typeName.type = toType; |
- var cast = AstBuilder.asExpression(e, typeName); |
- cast.staticType = toType; |
- return cast; |
- } |
- |
/*=T*/ _clone/*<T extends AstNode>*/(/*=T*/ node) { |
var copy = node.accept(cloner) as dynamic/*=T*/; |
ResolutionCopier.copyResolutionData(node, copy); |