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

Side by Side Diff: lib/src/codegen/reify_coercions.dart

Issue 1649583002: allow JS builtin to be typed as needed (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 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
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 library dev_compiler.src.codegen.reify_coercions; 5 library dev_compiler.src.codegen.reify_coercions;
6 6
7 import 'package:analyzer/analyzer.dart' as analyzer; 7 import 'package:analyzer/analyzer.dart' as analyzer;
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/element.dart'; 9 import 'package:analyzer/src/generated/element.dart';
10 import 'package:analyzer/src/generated/type_system.dart' 10 import 'package:analyzer/src/generated/type_system.dart'
11 show StrongTypeSystemImpl; 11 show StrongTypeSystemImpl;
12 import 'package:logging/logging.dart' as logger; 12 import 'package:logging/logging.dart' as logger;
13 13
14 import '../info.dart'; 14 import '../info.dart';
15 import '../utils.dart' show isInlineJS;
15 16
16 import 'ast_builder.dart'; 17 import 'ast_builder.dart';
17 18
18 final _log = new logger.Logger('dev_compiler.reify_coercions'); 19 final _log = new logger.Logger('dev_compiler.reify_coercions');
19 20
20 // TODO(leafp) Factor this out or use an existing library 21 // TODO(leafp) Factor this out or use an existing library
21 class Tuple2<T0, T1> { 22 class Tuple2<T0, T1> {
22 final T0 e0; 23 final T0 e0;
23 final T1 e1; 24 final T1 e1;
24 Tuple2(this.e0, this.e1); 25 Tuple2(this.e0, this.e1);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 // The main entry point. Coerce e using c, returning a new expression, 162 // The main entry point. Coerce e using c, returning a new expression,
162 // possibly recording additional coercions functions and typedefs to 163 // possibly recording additional coercions functions and typedefs to
163 // be discharged at a higher level. 164 // be discharged at a higher level.
164 Expression coerceExpression(Expression e, Coercion c) { 165 Expression coerceExpression(Expression e, Coercion c) {
165 assert(c != null); 166 assert(c != null);
166 assert(c is! CoercionError); 167 assert(c is! CoercionError);
167 if (e is NamedExpression) { 168 if (e is NamedExpression) {
168 Expression inner = coerceExpression(e.expression, c); 169 Expression inner = coerceExpression(e.expression, c);
169 return new NamedExpression(e.name, inner); 170 return new NamedExpression(e.name, inner);
170 } 171 }
172 if (e is MethodInvocation && isInlineJS(e.methodName.staticElement)) {
173 // Inline JS code should not need casts.
174 return e;
175 }
171 if (c is Cast) return _castExpression(e, c); 176 if (c is Cast) return _castExpression(e, c);
172 assert(c is Identity); 177 assert(c is Identity);
173 return e; 178 return e;
174 } 179 }
175 180
176 ///////////////// Private ////////////////////////////////// 181 ///////////////// Private //////////////////////////////////
177 182
178 Expression _castExpression(Expression e, Cast c) { 183 Expression _castExpression(Expression e, Cast c) {
179 var ttName = _tm.typeNameFromDartType(c.toType); 184 var ttName = _tm.typeNameFromDartType(c.toType);
180 var cast = AstBuilder.asExpression(e, ttName); 185 var cast = AstBuilder.asExpression(e, ttName);
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 var t = _mkNewTypeName(dType, id, args); 460 var t = _mkNewTypeName(dType, id, args);
456 return t; 461 return t;
457 } 462 }
458 463
459 TypeName _mkNewTypeName(DartType type, Identifier id, List<TypeName> args) { 464 TypeName _mkNewTypeName(DartType type, Identifier id, List<TypeName> args) {
460 var t = AstBuilder.typeName(id, args); 465 var t = AstBuilder.typeName(id, args);
461 t.type = type; 466 t.type = type;
462 return t; 467 return t;
463 } 468 }
464 } 469 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698