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

Side by Side Diff: frog/leg/ssa/codegen.dart

Issue 9666006: Support for "a is Function". (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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
« no previous file with comments | « frog/leg/ssa/closure.dart ('k') | frog/tests/leg/src/mock_compiler.dart » ('j') | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 class SsaCodeGeneratorTask extends CompilerTask { 5 class SsaCodeGeneratorTask extends CompilerTask {
6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler); 6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler);
7 String get name() => 'SSA code generator'; 7 String get name() => 'SSA code generator';
8 8
9 String generate(WorkItem work, HGraph graph) { 9 String generate(WorkItem work, HGraph graph) {
10 return measure(() { 10 return measure(() {
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 endExpression(JSPrecedence.EQUALITY_PRECEDENCE); 935 endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
936 } 936 }
937 937
938 void checkNull(HInstruction input) { 938 void checkNull(HInstruction input) {
939 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE); 939 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
940 use(input, JSPrecedence.EQUALITY_PRECEDENCE); 940 use(input, JSPrecedence.EQUALITY_PRECEDENCE);
941 buffer.add(" === (void 0)"); 941 buffer.add(" === (void 0)");
942 endExpression(JSPrecedence.EQUALITY_PRECEDENCE); 942 endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
943 } 943 }
944 944
945 void checkFunction(HInstruction input, Element element) {
946 beginExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE);
947 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
948 buffer.add('typeof ');
949 use(input, JSPrecedence.PREFIX_PRECEDENCE);
950 buffer.add(" === 'function'");
951 endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
952 buffer.add(" || ");
953 beginExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE);
954 checkObject(input, '===');
955 buffer.add(" && ");
956 checkType(input, element);
957 endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE);
958 endExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE);
959 }
960
961 void checkType(HInstruction input, Element element) {
962 buffer.add('!!');
963 use(input, JSPrecedence.MEMBER_PRECEDENCE);
964 buffer.add('.');
965 buffer.add(compiler.namer.operatorIs(element));
966 }
967
945 void visitIs(HIs node) { 968 void visitIs(HIs node) {
946 Element element = node.typeExpression; 969 Element element = node.typeExpression;
947 compiler.registerIsCheck(element); 970 compiler.registerIsCheck(element);
948 LibraryElement coreLibrary = compiler.coreLibrary; 971 LibraryElement coreLibrary = compiler.coreLibrary;
949 ClassElement objectClass = coreLibrary.find(const SourceString('Object')); 972 ClassElement objectClass = coreLibrary.find(const SourceString('Object'));
950 HInstruction input = node.expression; 973 HInstruction input = node.expression;
951 if (node.nullOk) { 974 if (node.nullOk) {
952 beginExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE); 975 beginExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE);
953 checkNull(input); 976 checkNull(input);
954 buffer.add(' || '); 977 buffer.add(' || ');
955 } 978 }
956 if (element == objectClass) { 979 if (element == objectClass) {
957 // TODO(ahe): This probably belongs in the constant folder. 980 // TODO(ahe): This probably belongs in the constant folder.
958 buffer.add('true'); 981 buffer.add('true');
959 } else if (element == coreLibrary.find(const SourceString('String'))) { 982 } else if (element == coreLibrary.find(const SourceString('String'))) {
960 checkString(input, '==='); 983 checkString(input, '===');
961 } else if (element == coreLibrary.find(const SourceString('double'))) { 984 } else if (element == coreLibrary.find(const SourceString('double'))) {
962 checkDouble(input, '==='); 985 checkDouble(input, '===');
963 } else if (element == coreLibrary.find(const SourceString('num'))) { 986 } else if (element == coreLibrary.find(const SourceString('num'))) {
964 checkNum(input, '==='); 987 checkNum(input, '===');
965 } else if (element == coreLibrary.find(const SourceString('bool'))) { 988 } else if (element == coreLibrary.find(const SourceString('bool'))) {
966 checkBool(input, '==='); 989 checkBool(input, '===');
990 } else if (element == coreLibrary.find(const SourceString('Function'))) {
991 checkFunction(input, element);
967 } else if (element == coreLibrary.find(const SourceString('int'))) { 992 } else if (element == coreLibrary.find(const SourceString('int'))) {
968 beginExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); 993 beginExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE);
969 checkNum(input, '==='); 994 checkNum(input, '===');
970 buffer.add(' && '); 995 buffer.add(' && ');
971 checkInt(input, '==='); 996 checkInt(input, '===');
972 endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); 997 endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE);
973 } else { 998 } else {
974 beginExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); 999 beginExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE);
975 if (isStringSupertype(element)) { 1000 if (isStringSupertype(element)) {
976 checkString(input, '==='); 1001 checkString(input, '===');
(...skipping 10 matching lines...) Expand all
987 checkArray(input, '==='); 1012 checkArray(input, '===');
988 buffer.add(' || '); 1013 buffer.add(' || ');
989 precedence = JSPrecedence.LOGICAL_OR_PRECEDENCE; 1014 precedence = JSPrecedence.LOGICAL_OR_PRECEDENCE;
990 } else if (element.isClass() && (element.dynamic.isNative() 1015 } else if (element.isClass() && (element.dynamic.isNative()
991 || isSupertypeOfNativeClass(element))) { 1016 || isSupertypeOfNativeClass(element))) {
992 buffer.add("("); 1017 buffer.add("(");
993 endParen = true; 1018 endParen = true;
994 } else { 1019 } else {
995 beginExpression(precedence); 1020 beginExpression(precedence);
996 } 1021 }
997 buffer.add('!!'); 1022 checkType(input, node.typeExpression);
998 use(input, JSPrecedence.MEMBER_PRECEDENCE);
999 buffer.add('.');
1000 buffer.add(compiler.namer.operatorIs(node.typeExpression));
1001 if (element.isClass() && (element.dynamic.isNative() 1023 if (element.isClass() && (element.dynamic.isNative()
1002 || isSupertypeOfNativeClass(element))) { 1024 || isSupertypeOfNativeClass(element))) {
1003 buffer.add(' || '); 1025 buffer.add(' || ');
1004 beginExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); 1026 beginExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE);
1005 // First check if the object is not a Dart object. If the 1027 // First check if the object is not a Dart object. If the
1006 // object is a Dart object, we know the property check was 1028 // object is a Dart object, we know the property check was
1007 // sufficient. 1029 // sufficient.
1008 compiler.registerIsCheck(objectClass); 1030 compiler.registerIsCheck(objectClass);
1009 buffer.add('!'); 1031 buffer.add('!');
1010 use(input, JSPrecedence.MEMBER_PRECEDENCE); 1032 use(input, JSPrecedence.MEMBER_PRECEDENCE);
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 startBailoutSwitch(); 1427 startBailoutSwitch();
1406 } 1428 }
1407 } 1429 }
1408 1430
1409 void endElse(HIf node) { 1431 void endElse(HIf node) {
1410 if (node.elseBlock.hasBailouts()) { 1432 if (node.elseBlock.hasBailouts()) {
1411 endBailoutSwitch(); 1433 endBailoutSwitch();
1412 } 1434 }
1413 } 1435 }
1414 } 1436 }
OLDNEW
« no previous file with comments | « frog/leg/ssa/closure.dart ('k') | frog/tests/leg/src/mock_compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698