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

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: Make "as" a builtin identifier. 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 7e4662fa024edf27adba4eeb118a72d8f8962ef6..5f7c6597eb8bf0ad3f98f367c7fb4087173b5b8f 100644
--- a/lib/compiler/implementation/ssa/builder.dart
+++ b/lib/compiler/implementation/ssa/builder.dart
@@ -1073,7 +1073,12 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
HInstruction potentiallyCheckType(HInstruction original,
Element sourceElement) {
if (!compiler.enableTypeAssertions) return original;
+ return convertType(original, sourceElement, HTypeConversion.CHECKED);
+ }
+ 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;
@@ -1088,7 +1093,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
}
HInstruction instruction =
- new HTypeConversion(convertedType, original, true);
+ new HTypeConversion(convertedType, original, kind);
add(instruction);
return instruction;
}
@@ -1959,6 +1964,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);
+ stack.add(converted);
} else {
visit(node.receiver);
visit(node.argumentsNode);

Powered by Google App Engine
This is Rietveld 408576698