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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: lib/compiler/implementation/ssa/builder.dart
diff --git a/lib/compiler/implementation/ssa/builder.dart b/lib/compiler/implementation/ssa/builder.dart
index 8ab033fc10cb23c49bc68ebf8257f078254a80a0..dbd2824b0a56c106ba8971af35b7ab261987a618 100644
--- a/lib/compiler/implementation/ssa/builder.dart
+++ b/lib/compiler/implementation/ssa/builder.dart
@@ -1092,13 +1092,22 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
HInstruction potentiallyCheckType(HInstruction original,
Element sourceElement) {
if (!compiler.enableTypeAssertions) return original;
+ return convertType(original, sourceElement,
+ HTypeConversion.CHECKED_MODE_CHECK);
+ }
+ HInstruction convertType(HInstruction original,
+ Element sourceElement,
+ int kind) {
Type type = sourceElement.computeType(compiler);
if (type === null) return original;
if (type.element === compiler.dynamicClass) return original;
if (type.element === compiler.objectClass) return original;
- HType convertedType = new HType.fromBoundedType(type, compiler, true);
+ // If the original can't be null, type conversion also can't produce null.
+ bool canBeNull = original.guaranteedType.canBeNull();
+ HType convertedType =
+ new HType.fromBoundedType(type, compiler, canBeNull);
// No need to convert if we know the instruction has
// [convertedType] as a bound.
@@ -1107,7 +1116,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
}
HInstruction instruction =
- new HTypeConversion.checkedModeCheck(convertedType, original);
+ new HTypeConversion(convertedType, original, kind);
add(instruction);
return instruction;
}
@@ -1978,6 +1987,15 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
}
push(instruction);
}
+ } else if (const SourceString("as") == op.source) {
+ visit(node.receiver);
+ HInstruction expression = pop();
+ Node argument = node.arguments.head;
+ TypeAnnotation typeAnnotation = argument.asTypeAnnotation();
+ Type type = elements.getType(typeAnnotation);
+ HInstruction converted = convertType(expression, type.element,
+ HTypeConversion.CAST_TYPE_CHECK);
+ stack.add(converted);
} else {
visit(node.receiver);
visit(node.argumentsNode);

Powered by Google App Engine
This is Rietveld 408576698