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

Side by Side Diff: lib/src/compiler/code_generator.dart

Issue 2037473002: Check for extension methods when using whitelist (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 'dart:collection' show HashMap, HashSet; 5 import 'dart:collection' show HashMap, HashSet;
6 import 'dart:math' show min, max; 6 import 'dart:math' show min, max;
7 7
8 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 8 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; 10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType;
(...skipping 2514 matching lines...) Expand 10 before | Expand all | Expand 10 after
2525 2525
2526 target = _getTarget(lhs); 2526 target = _getTarget(lhs);
2527 id = lhs.propertyName; 2527 id = lhs.propertyName;
2528 } else if (lhs is PrefixedIdentifier) { 2528 } else if (lhs is PrefixedIdentifier) {
2529 target = lhs.prefix; 2529 target = lhs.prefix;
2530 id = lhs.identifier; 2530 id = lhs.identifier;
2531 } 2531 }
2532 2532
2533 if (target != null && DynamicInvoke.get(target)) { 2533 if (target != null && DynamicInvoke.get(target)) {
2534 if (_inWhitelistCode(lhs)) { 2534 if (_inWhitelistCode(lhs)) {
2535 return _visit(rhs).toAssignExpression(_visit(lhs)); 2535 var vars = <JS.MetaLetVariable, JS.Expression>{};
2536 var l = _visit(_bindValue(vars, 'l', target));
2537 var name = _emitMemberName(id.name);
2538 return new JS.MetaLet(vars, [
2539 js.call('(#[(#[dart._extensionType]) ? dartx[#] : #] = #)',
2540 [l, l, name, name, _visit(rhs)])
2541 ]);
2536 } 2542 }
2537 return js.call('dart.dput(#, #, #)', 2543 return js.call('dart.dput(#, #, #)',
2538 [_visit(target), _emitMemberName(id.name), _visit(rhs)]); 2544 [_visit(target), _emitMemberName(id.name), _visit(rhs)]);
2539 } 2545 }
2540 2546
2541 return _visit(rhs).toAssignExpression(_visit(lhs)); 2547 return _visit(rhs).toAssignExpression(_visit(lhs));
2542 } 2548 }
2543 2549
2544 JS.Expression _emitNullSafeSet(PropertyAccess node, Expression right) { 2550 JS.Expression _emitNullSafeSet(PropertyAccess node, Expression right) {
2545 // Emit `obj?.prop = expr` as: 2551 // Emit `obj?.prop = expr` as:
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
2658 List<JS.Expression> typeArgs) { 2664 List<JS.Expression> typeArgs) {
2659 var type = getStaticType(target); 2665 var type = getStaticType(target);
2660 var name = node.methodName.name; 2666 var name = node.methodName.name;
2661 var element = node.methodName.staticElement; 2667 var element = node.methodName.staticElement;
2662 bool isStatic = element is ExecutableElement && element.isStatic; 2668 bool isStatic = element is ExecutableElement && element.isStatic;
2663 var memberName = _emitMemberName(name, type: type, isStatic: isStatic); 2669 var memberName = _emitMemberName(name, type: type, isStatic: isStatic);
2664 2670
2665 JS.Expression jsTarget = _visit(target); 2671 JS.Expression jsTarget = _visit(target);
2666 if (DynamicInvoke.get(target) || DynamicInvoke.get(node.methodName)) { 2672 if (DynamicInvoke.get(target) || DynamicInvoke.get(node.methodName)) {
2667 if (_inWhitelistCode(target)) { 2673 if (_inWhitelistCode(target)) {
2668 jsTarget = new JS.PropertyAccess(jsTarget, memberName); 2674 var vars = <JS.MetaLetVariable, JS.Expression>{};
2675 var l = _visit(_bindValue(vars, 'l', target));
2676 jsTarget =
2677 new JS.MetaLet(vars, [
2678 js.call('(#[(#[dart._extensionType]) ? dartx[#] : #])',
2679 [l, l, memberName, memberName,])
2680 ]);
2669 if (typeArgs != null) jsTarget = new JS.Call(jsTarget, typeArgs); 2681 if (typeArgs != null) jsTarget = new JS.Call(jsTarget, typeArgs);
2670 return new JS.Call(jsTarget, args); 2682 return new JS.Call(jsTarget, args);
2671 } 2683 }
2672 if (typeArgs != null) { 2684 if (typeArgs != null) {
2673 return js.call('dart.dgsend(#, #, #, #)', 2685 return js.call('dart.dgsend(#, #, #, #)',
2674 [jsTarget, new JS.ArrayInitializer(typeArgs), memberName, args]); 2686 [jsTarget, new JS.ArrayInitializer(typeArgs), memberName, args]);
2675 } else { 2687 } else {
2676 return js.call('dart.dsend(#, #, #)', [jsTarget, memberName, args]); 2688 return js.call('dart.dsend(#, #, #)', [jsTarget, memberName, args]);
2677 } 2689 }
2678 } 2690 }
(...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after
3873 return _emitFunctionTypeArguments(type, instantiated); 3885 return _emitFunctionTypeArguments(type, instantiated);
3874 } 3886 }
3875 3887
3876 JS.Expression _emitAccessInternal(Expression target, Element member, 3888 JS.Expression _emitAccessInternal(Expression target, Element member,
3877 String memberName, List<JS.Expression> typeArgs) { 3889 String memberName, List<JS.Expression> typeArgs) {
3878 bool isStatic = member is ClassMemberElement && member.isStatic; 3890 bool isStatic = member is ClassMemberElement && member.isStatic;
3879 var name = _emitMemberName(memberName, 3891 var name = _emitMemberName(memberName,
3880 type: getStaticType(target), isStatic: isStatic); 3892 type: getStaticType(target), isStatic: isStatic);
3881 if (DynamicInvoke.get(target)) { 3893 if (DynamicInvoke.get(target)) {
3882 if (_inWhitelistCode(target)) { 3894 if (_inWhitelistCode(target)) {
3883 return js.call('#.#', [_visit(target), name]); 3895 var vars = <JS.MetaLetVariable, JS.Expression>{};
3896 var l = _visit(_bindValue(vars, 'l', target));
3897 return new JS.MetaLet(vars, [
3898 js.call('(#[dart._extensionType]) ? #[dartx[#]] : #.#', [l, l, name, l , name])
Jacob 2016/06/02 03:07:51 long line. Also I believe there is a way to specif
3899 ]);
3884 } 3900 }
3885 return js.call('dart.dload(#, #)', [_visit(target), name]); 3901 return js.call('dart.dload(#, #)', [_visit(target), name]);
3886 } 3902 }
3887 3903
3888 var jsTarget = _visit(target); 3904 var jsTarget = _visit(target);
3889 bool isSuper = jsTarget is JS.Super; 3905 bool isSuper = jsTarget is JS.Super;
3890 3906
3891 if (isSuper && member is FieldElement && !member.isSynthetic) { 3907 if (isSuper && member is FieldElement && !member.isSynthetic) {
3892 // If super.x is actually a field, then x is an instance property since 3908 // If super.x is actually a field, then x is an instance property since
3893 // subclasses cannot override x. 3909 // subclasses cannot override x.
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after
4692 } 4708 }
4693 4709
4694 bool isLibraryPrefix(Expression node) => 4710 bool isLibraryPrefix(Expression node) =>
4695 node is SimpleIdentifier && node.staticElement is PrefixElement; 4711 node is SimpleIdentifier && node.staticElement is PrefixElement;
4696 4712
4697 LibraryElement _getLibrary(AnalysisContext c, String uri) => 4713 LibraryElement _getLibrary(AnalysisContext c, String uri) =>
4698 c.computeLibraryElement(c.sourceFactory.forUri(uri)); 4714 c.computeLibraryElement(c.sourceFactory.forUri(uri));
4699 4715
4700 bool _isDartRuntime(LibraryElement l) => 4716 bool _isDartRuntime(LibraryElement l) =>
4701 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; 4717 l.isInSdk && l.source.uri.toString() == 'dart:_runtime';
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698