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

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

Issue 10540048: Implement 'as' operator. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: No entries in language.status, vm and dartc already implemented 'as'. Created 8 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 | 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 Interceptors { 5 class Interceptors {
6 Compiler compiler; 6 Compiler compiler;
7 Interceptors(Compiler this.compiler); 7 Interceptors(Compiler this.compiler);
8 8
9 SourceString mapOperatorToMethodName(Operator op) { 9 SourceString mapOperatorToMethodName(Operator op) {
10 String name = op.source.stringValue; 10 String name = op.source.stringValue;
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 params.forEachParameter((Element element) { 1085 params.forEachParameter((Element element) {
1086 HInstruction newParameter = potentiallyCheckType( 1086 HInstruction newParameter = potentiallyCheckType(
1087 localsHandler.directLocals[element], element); 1087 localsHandler.directLocals[element], element);
1088 localsHandler.directLocals[element] = newParameter; 1088 localsHandler.directLocals[element] = newParameter;
1089 }); 1089 });
1090 } 1090 }
1091 1091
1092 HInstruction potentiallyCheckType(HInstruction original, 1092 HInstruction potentiallyCheckType(HInstruction original,
1093 Element sourceElement) { 1093 Element sourceElement) {
1094 if (!compiler.enableTypeAssertions) return original; 1094 if (!compiler.enableTypeAssertions) return original;
1095 return convertType(original, sourceElement,
1096 HTypeConversion.CHECKED_MODE_CHECK);
1097 }
1095 1098
1099 HInstruction convertType(HInstruction original,
1100 Element sourceElement,
1101 int kind) {
1096 Type type = sourceElement.computeType(compiler); 1102 Type type = sourceElement.computeType(compiler);
1097 if (type === null) return original; 1103 if (type === null) return original;
1098 if (type.element === compiler.dynamicClass) return original; 1104 if (type.element === compiler.dynamicClass) return original;
1099 if (type.element === compiler.objectClass) return original; 1105 if (type.element === compiler.objectClass) return original;
1100 1106
1101 HType convertedType = new HType.fromBoundedType(type, compiler, true); 1107 // If the original can't be null, type conversion also can't produce null.
1108 bool canBeNull = original.guaranteedType.canBeNull();
1109 HType convertedType =
1110 new HType.fromBoundedType(type, compiler, canBeNull);
1102 1111
1103 // No need to convert if we know the instruction has 1112 // No need to convert if we know the instruction has
1104 // [convertedType] as a bound. 1113 // [convertedType] as a bound.
1105 if (original.guaranteedType == convertedType) { 1114 if (original.guaranteedType == convertedType) {
1106 return original; 1115 return original;
1107 } 1116 }
1108 1117
1109 HInstruction instruction = 1118 HInstruction instruction =
1110 new HTypeConversion.checkedModeCheck(convertedType, original); 1119 new HTypeConversion(convertedType, original, kind);
1111 add(instruction); 1120 add(instruction);
1112 return instruction; 1121 return instruction;
1113 } 1122 }
1114 1123
1115 HGraph closeFunction() { 1124 HGraph closeFunction() {
1116 // TODO(kasperl): Make this goto an implicit return. 1125 // TODO(kasperl): Make this goto an implicit return.
1117 if (!isAborted()) close(new HGoto()).addSuccessor(graph.exit); 1126 if (!isAborted()) close(new HGoto()).addSuccessor(graph.exit);
1118 graph.finalize(); 1127 graph.finalize();
1119 return graph; 1128 return graph;
1120 } 1129 }
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1971 instruction = new HIs.withTypeInfoCall(type, expression, typeInfo); 1980 instruction = new HIs.withTypeInfoCall(type, expression, typeInfo);
1972 } else { 1981 } else {
1973 instruction = new HIs(type, expression); 1982 instruction = new HIs(type, expression);
1974 } 1983 }
1975 if (isNot) { 1984 if (isNot) {
1976 add(instruction); 1985 add(instruction);
1977 instruction = new HNot(instruction); 1986 instruction = new HNot(instruction);
1978 } 1987 }
1979 push(instruction); 1988 push(instruction);
1980 } 1989 }
1990 } else if (const SourceString("as") == op.source) {
1991 visit(node.receiver);
1992 HInstruction expression = pop();
1993 Node argument = node.arguments.head;
1994 TypeAnnotation typeAnnotation = argument.asTypeAnnotation();
1995 Type type = elements.getType(typeAnnotation);
1996 HInstruction converted = convertType(expression, type.element,
1997 HTypeConversion.CAST_TYPE_CHECK);
1998 stack.add(converted);
1981 } else { 1999 } else {
1982 visit(node.receiver); 2000 visit(node.receiver);
1983 visit(node.argumentsNode); 2001 visit(node.argumentsNode);
1984 var right = pop(); 2002 var right = pop();
1985 var left = pop(); 2003 var left = pop();
1986 visitBinary(left, op, right); 2004 visitBinary(left, op, right);
1987 } 2005 }
1988 } 2006 }
1989 2007
1990 void addDynamicSendArgumentsToList(Send node, List<HInstruction> list) { 2008 void addDynamicSendArgumentsToList(Send node, List<HInstruction> list) {
(...skipping 1473 matching lines...) Expand 10 before | Expand all | Expand 10 after
3464 void visitNodeList(NodeList node) { 3482 void visitNodeList(NodeList node) {
3465 node.visitChildren(this); 3483 node.visitChildren(this);
3466 } 3484 }
3467 3485
3468 HInstruction concat(HInstruction left, HInstruction right) { 3486 HInstruction concat(HInstruction left, HInstruction right) {
3469 HInstruction instruction = new HStringConcat(left, right, diagnosticNode); 3487 HInstruction instruction = new HStringConcat(left, right, diagnosticNode);
3470 builder.add(instruction); 3488 builder.add(instruction);
3471 return instruction; 3489 return instruction;
3472 } 3490 }
3473 } 3491 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698