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

Side by Side Diff: lib/compiler/implementation/ssa/codegen.dart

Issue 10232011: Implement simple dynamic type check. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor edits. Created 8 years, 7 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
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 9
10 String generateMethod(WorkItem work, HGraph graph) { 10 String generateMethod(WorkItem work, HGraph graph) {
(...skipping 1709 matching lines...) Expand 10 before | Expand all | Expand 10 after
1720 beginExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE); 1720 beginExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE);
1721 checkArray(input, '==='); 1721 checkArray(input, '===');
1722 buffer.add(' || '); 1722 buffer.add(' || ');
1723 checkType(input, element); 1723 checkType(input, element);
1724 buffer.add(')'); 1724 buffer.add(')');
1725 endExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE); 1725 endExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE);
1726 endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); 1726 endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE);
1727 } 1727 }
1728 1728
1729 void visitIs(HIs node) { 1729 void visitIs(HIs node) {
1730 Type type = node.typeName; 1730 Type type = node.typeExpression;
1731 Element element = type.element; 1731 Element element = type.element;
1732 if (element.kind === ElementKind.TYPE_VARIABLE) { 1732 if (element.kind === ElementKind.TYPE_VARIABLE) {
1733 compiler.unimplemented("visitIs for type variables"); 1733 compiler.unimplemented("visitIs for type variables");
1734 } else if (element.kind === ElementKind.TYPEDEF) { 1734 } else if (element.kind === ElementKind.TYPEDEF) {
1735 compiler.unimplemented("visitIs for typedefs"); 1735 compiler.unimplemented("visitIs for typedefs");
1736 } 1736 }
1737 compiler.registerIsCheck(element); 1737 compiler.registerIsCheck(type.element);
1738 LibraryElement coreLibrary = compiler.coreLibrary; 1738 LibraryElement coreLibrary = compiler.coreLibrary;
1739 ClassElement objectClass = compiler.objectClass; 1739 ClassElement objectClass = compiler.objectClass;
1740 HInstruction input = node.expression; 1740 HInstruction input = node.expression;
1741
1741 if (node.nullOk) { 1742 if (node.nullOk) {
1742 beginExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE); 1743 beginExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE);
1743 checkNull(input); 1744 checkNull(input);
1744 buffer.add(' || '); 1745 buffer.add(' || ');
1745 } 1746 }
1746
1747 if (element === objectClass || element === compiler.dynamicClass) { 1747 if (element === objectClass || element === compiler.dynamicClass) {
1748 // The constant folder also does this optimization, but we make 1748 // The constant folder also does this optimization, but we make
1749 // it safe by assuming it may have not run. 1749 // it safe by assuming it may have not run.
1750 buffer.add('true'); 1750 buffer.add('true');
1751 } else if (element == compiler.stringClass) { 1751 } else if (element == compiler.stringClass) {
1752 checkString(input, '==='); 1752 checkString(input, '===');
1753 } else if (element == compiler.doubleClass) { 1753 } else if (element == compiler.doubleClass) {
1754 checkDouble(input, '==='); 1754 checkDouble(input, '===');
1755 } else if (element == compiler.numClass) { 1755 } else if (element == compiler.numClass) {
1756 checkNum(input, '==='); 1756 checkNum(input, '===');
(...skipping 12 matching lines...) Expand all
1769 } else if (element === compiler.listClass 1769 } else if (element === compiler.listClass
1770 || Elements.isListSupertype(element, compiler)) { 1770 || Elements.isListSupertype(element, compiler)) {
1771 handleListOrSupertypeCheck(input, element); 1771 handleListOrSupertypeCheck(input, element);
1772 } else { 1772 } else {
1773 beginExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); 1773 beginExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE);
1774 checkObject(input, '==='); 1774 checkObject(input, '===');
1775 buffer.add(' && '); 1775 buffer.add(' && ');
1776 checkType(input, element); 1776 checkType(input, element);
1777 endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); 1777 endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE);
1778 } 1778 }
1779 1779 if (compiler.universe.rti.hasTypeArguments(type)) {
1780 InterfaceType interfaceType = type;
1781 ClassElement cls = type.element;
1782 Link<Type> arguments = interfaceType.arguments;
1783 buffer.add(' && ');
1784 checkObject(node.typeInfo, '===');
1785 cls.typeParameters.forEach((name, _) {
ngeoffray 2012/04/30 08:51:12 name -> Element typeParameter ?
karlklose 2012/05/01 11:20:55 typeParameters is a Map<SourceString, TypeVariable
1786 buffer.add(' && ');
1787 beginExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE);
1788 use(node.typeInfo, JSPrecedence.EQUALITY_PRECEDENCE);
1789 buffer.add(".${name.slowToString()} === '${arguments.head}'");
1790 endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE);
1791 });
1792 }
1780 if (node.nullOk) { 1793 if (node.nullOk) {
1781 endExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE); 1794 endExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE);
1782 } 1795 }
1783 } 1796 }
1784 } 1797 }
1785 1798
1786 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { 1799 class SsaOptimizedCodeGenerator extends SsaCodeGenerator {
1787 SsaOptimizedCodeGenerator(compiler, work, parameters, parameterNames) 1800 SsaOptimizedCodeGenerator(compiler, work, parameters, parameterNames)
1788 : super(compiler, work, parameters, parameterNames); 1801 : super(compiler, work, parameters, parameterNames);
1789 1802
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
2194 startBailoutSwitch(); 2207 startBailoutSwitch();
2195 } 2208 }
2196 } 2209 }
2197 2210
2198 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { 2211 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) {
2199 if (labeledBlockInfo.body.start.hasGuards()) { 2212 if (labeledBlockInfo.body.start.hasGuards()) {
2200 endBailoutSwitch(); 2213 endBailoutSwitch();
2201 } 2214 }
2202 } 2215 }
2203 } 2216 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698