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

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

Issue 9358055: Fix 'is' for null. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | dart/tests/language/src/NullIsTest.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 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 use(input); 807 use(input);
808 buffer.add(" $cmp 'string'"); 808 buffer.add(" $cmp 'string'");
809 } 809 }
810 810
811 void checkBool(HInstruction input, String cmp) { 811 void checkBool(HInstruction input, String cmp) {
812 buffer.add('typeof '); 812 buffer.add('typeof ');
813 use(input); 813 use(input);
814 buffer.add(" $cmp 'boolean'"); 814 buffer.add(" $cmp 'boolean'");
815 } 815 }
816 816
817 void checkObject(HInstruction input, String cmp) {
818 buffer.add('typeof ');
819 use(input);
820 buffer.add(" $cmp 'object'");
821 }
822
817 void checkArray(HInstruction input, String cmp) { 823 void checkArray(HInstruction input, String cmp) {
818 use(input); 824 use(input);
819 buffer.add('.constructor $cmp Array'); 825 buffer.add('.constructor $cmp Array');
820 } 826 }
821 827
822 void visitIs(HIs node) { 828 void visitIs(HIs node) {
823 ClassElement element = node.typeExpression; 829 ClassElement element = node.typeExpression;
824 LibraryElement coreLibrary = compiler.coreLibrary; 830 LibraryElement coreLibrary = compiler.coreLibrary;
825 HInstruction input = node.expression; 831 HInstruction input = node.expression;
826 buffer.add('('); 832 buffer.add('(');
827 if (element == coreLibrary.find(const SourceString('Object'))) { 833 if (element == coreLibrary.find(const SourceString('Object'))) {
828 // TODO(ahe): This probably belongs in the constant folder. 834 // TODO(ahe): This probably belongs in the constant folder.
829 buffer.add('true'); 835 buffer.add('true');
830 } else if (element == coreLibrary.find(const SourceString('String'))) { 836 } else if (element == coreLibrary.find(const SourceString('String'))) {
831 checkString(input, '==='); 837 checkString(input, '===');
832 } else if (element == coreLibrary.find(const SourceString('double'))) { 838 } else if (element == coreLibrary.find(const SourceString('double'))) {
833 checkDouble(input, '==='); 839 checkDouble(input, '===');
834 } else if (element == coreLibrary.find(const SourceString('num'))) { 840 } else if (element == coreLibrary.find(const SourceString('num'))) {
835 checkNum(input, '==='); 841 checkNum(input, '===');
836 } else if (element == coreLibrary.find(const SourceString('bool'))) { 842 } else if (element == coreLibrary.find(const SourceString('bool'))) {
837 checkBool(input, '==='); 843 checkBool(input, '===');
838 } else if (element == coreLibrary.find(const SourceString('int'))) { 844 } else if (element == coreLibrary.find(const SourceString('int'))) {
839 checkNum(input, '==='); 845 checkNum(input, '===');
840 buffer.add(' && '); 846 buffer.add(' && ');
841 checkInt(input, '==='); 847 checkInt(input, '===');
842 } else { 848 } else {
849 checkObject(input, '===');
850 buffer.add(' && (');
843 if (element == coreLibrary.find(const SourceString('List'))) { 851 if (element == coreLibrary.find(const SourceString('List'))) {
844 checkArray(input, '==='); 852 checkArray(input, '===');
845 buffer.add(' || '); 853 buffer.add(' || ');
846 } 854 }
847 buffer.add('!!('); 855 buffer.add('!!(');
848 use(input); 856 use(input);
849 buffer.add('.'); 857 buffer.add('.');
850 buffer.add(compiler.namer.operatorIs(node.typeExpression)); 858 buffer.add(compiler.namer.operatorIs(node.typeExpression));
851 buffer.add(')'); 859 buffer.add('))');
852 } 860 }
853 buffer.add(')'); 861 buffer.add(')');
854 } 862 }
855 } 863 }
856 864
857 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { 865 class SsaOptimizedCodeGenerator extends SsaCodeGenerator {
858 final List<HTypeGuard> guards; 866 final List<HTypeGuard> guards;
859 int state = 0; 867 int state = 0;
860 868
861 SsaOptimizedCodeGenerator(compiler, work, buffer, parameters, parameterNames) 869 SsaOptimizedCodeGenerator(compiler, work, buffer, parameters, parameterNames)
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 startBailoutSwitch(); 1200 startBailoutSwitch();
1193 } 1201 }
1194 } 1202 }
1195 1203
1196 void endElse(HIf node) { 1204 void endElse(HIf node) {
1197 if (node.elseBlock.hasBailouts()) { 1205 if (node.elseBlock.hasBailouts()) {
1198 endBailoutSwitch(); 1206 endBailoutSwitch();
1199 } 1207 }
1200 } 1208 }
1201 } 1209 }
OLDNEW
« no previous file with comments | « no previous file | dart/tests/language/src/NullIsTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698