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

Side by Side Diff: pkg/dev_compiler/lib/src/compiler/reify_coercions.dart

Issue 2954523002: fix #27259, implement covariance checking for strong mode and DDC (Closed)
Patch Set: merged and fix an analysis error Created 3 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 import 'package:analyzer/analyzer.dart' as analyzer; 5 import 'package:analyzer/analyzer.dart' as analyzer;
6 import 'package:analyzer/dart/ast/ast.dart'; 6 import 'package:analyzer/dart/ast/ast.dart';
7 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; 7 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
8 import 'package:analyzer/dart/element/type.dart' show DartType; 8 import 'package:analyzer/dart/element/type.dart' show DartType;
9 import 'package:analyzer/src/dart/ast/ast.dart' show FunctionBodyImpl; 9 import 'package:analyzer/src/dart/ast/ast.dart' show FunctionBodyImpl;
10 import 'package:analyzer/src/dart/ast/utilities.dart' show NodeReplacer; 10 import 'package:analyzer/src/dart/ast/utilities.dart' show NodeReplacer;
(...skipping 14 matching lines...) Expand all
25 25
26 CoercionReifier._(); 26 CoercionReifier._();
27 27
28 /// Transforms the given compilation units, and returns a new AST with 28 /// Transforms the given compilation units, and returns a new AST with
29 /// explicit coercion nodes in appropriate places. 29 /// explicit coercion nodes in appropriate places.
30 static List<CompilationUnit> reify(List<CompilationUnit> units) { 30 static List<CompilationUnit> reify(List<CompilationUnit> units) {
31 var cr = new CoercionReifier._(); 31 var cr = new CoercionReifier._();
32 return units.map(cr.visitCompilationUnit).toList(growable: false); 32 return units.map(cr.visitCompilationUnit).toList(growable: false);
33 } 33 }
34 34
35 /// Returns true if the `as` [node] was created by this class. 35 /// True if the `as` [node] is a required runtime check for soundness.
36 // TODO(sra): Find a better way to recognize reified coercion, since we 36 // TODO(sra): Find a better way to recognize reified coercion, since we
37 // can't set the isSynthetic attribute. 37 // can't set the isSynthetic attribute.
38 static bool isImplicitCast(AsExpression node) => node.asOperator.offset == 0; 38 static bool isRequiredForSoundness(AsExpression node) =>
39 node.asOperator.offset == 0;
39 40
40 /// Creates an implicit cast for expression [e] to [toType]. 41 /// Creates an implicit cast for expression [e] to [toType].
41 static Expression castExpression(Expression e, DartType toType) { 42 static Expression castExpression(Expression e, DartType toType) {
42 // We use an empty name in the AST, because the JS code generator only cares 43 // We use an empty name in the AST, because the JS code generator only cares
43 // about the target type. It does not look at the AST name. 44 // about the target type. It does not look at the AST name.
44 var typeName = 45 var typeName =
45 astFactory.typeName(AstBuilder.identifierFromString(''), null); 46 astFactory.typeName(AstBuilder.identifierFromString(''), null);
46 typeName.type = toType; 47 typeName.type = toType;
47 var cast = AstBuilder.asExpression(e, typeName); 48 var cast = AstBuilder.asExpression(e, typeName);
48 cast.staticType = toType; 49 cast.staticType = toType;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 ResolutionCopier.copyResolutionData(node, copy); 126 ResolutionCopier.copyResolutionData(node, copy);
126 return copy; 127 return copy;
127 } 128 }
128 } 129 }
129 130
130 class _TreeCloner extends analyzer.AstCloner { 131 class _TreeCloner extends analyzer.AstCloner {
131 void _cloneProperties(AstNode clone, AstNode node) { 132 void _cloneProperties(AstNode clone, AstNode node) {
132 if (clone is Expression) { 133 if (clone is Expression) {
133 ast_properties.setImplicitCast( 134 ast_properties.setImplicitCast(
134 clone, ast_properties.getImplicitCast(node)); 135 clone, ast_properties.getImplicitCast(node));
136 ast_properties.setImplicitOperationCast(
137 clone, ast_properties.getImplicitOperationCast(node));
135 ast_properties.setIsDynamicInvoke( 138 ast_properties.setIsDynamicInvoke(
136 clone, ast_properties.isDynamicInvoke(node)); 139 clone, ast_properties.isDynamicInvoke(node));
137 } 140 }
141 if (clone is ClassDeclaration) {
142 ast_properties.setClassCovariantParameters(
143 clone, ast_properties.getClassCovariantParameters(node));
144 ast_properties.setSuperclassCovariantParameters(
145 clone, ast_properties.getSuperclassCovariantParameters(node));
146 }
138 } 147 }
139 148
140 @override 149 @override
141 /*=E*/ cloneNode/*<E extends AstNode>*/(/*=E*/ node) { 150 /*=E*/ cloneNode/*<E extends AstNode>*/(/*=E*/ node) {
142 var clone = super.cloneNode(node); 151 var clone = super.cloneNode(node);
143 _cloneProperties(clone, node); 152 _cloneProperties(clone, node);
144 return clone; 153 return clone;
145 } 154 }
146 155
147 @override 156 @override
(...skipping 25 matching lines...) Expand all
173 182
174 // TODO(jmesserly): workaround for 183 // TODO(jmesserly): workaround for
175 // https://github.com/dart-lang/sdk/issues/26368 184 // https://github.com/dart-lang/sdk/issues/26368
176 @override 185 @override
177 TypeName visitTypeName(TypeName node) { 186 TypeName visitTypeName(TypeName node) {
178 var clone = super.visitTypeName(node); 187 var clone = super.visitTypeName(node);
179 clone.type = node.type; 188 clone.type = node.type;
180 return clone; 189 return clone;
181 } 190 }
182 } 191 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/src/compiler/property_model.dart ('k') | pkg/dev_compiler/lib/src/compiler/type_utilities.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698