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

Unified 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, 8 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/codegen.dart
diff --git a/lib/compiler/implementation/ssa/codegen.dart b/lib/compiler/implementation/ssa/codegen.dart
index 3081bff5aa8cb81fcadf4e8eb99426ca47a6de94..a283fbaea37302c073b294430b49046af4997119 100644
--- a/lib/compiler/implementation/ssa/codegen.dart
+++ b/lib/compiler/implementation/ssa/codegen.dart
@@ -1727,23 +1727,23 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
}
void visitIs(HIs node) {
- Type type = node.typeName;
+ Type type = node.typeExpression;
Element element = type.element;
if (element.kind === ElementKind.TYPE_VARIABLE) {
compiler.unimplemented("visitIs for type variables");
} else if (element.kind === ElementKind.TYPEDEF) {
compiler.unimplemented("visitIs for typedefs");
}
- compiler.registerIsCheck(element);
+ compiler.registerIsCheck(type.element);
LibraryElement coreLibrary = compiler.coreLibrary;
ClassElement objectClass = compiler.objectClass;
HInstruction input = node.expression;
+
if (node.nullOk) {
beginExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE);
checkNull(input);
buffer.add(' || ');
}
-
if (element === objectClass || element === compiler.dynamicClass) {
// The constant folder also does this optimization, but we make
// it safe by assuming it may have not run.
@@ -1776,7 +1776,20 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
checkType(input, element);
endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE);
}
-
+ if (compiler.universe.rti.hasTypeArguments(type)) {
+ InterfaceType interfaceType = type;
+ ClassElement cls = type.element;
+ Link<Type> arguments = interfaceType.arguments;
+ buffer.add(' && ');
+ checkObject(node.typeInfo, '===');
+ 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
+ buffer.add(' && ');
+ beginExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE);
+ use(node.typeInfo, JSPrecedence.EQUALITY_PRECEDENCE);
+ buffer.add(".${name.slowToString()} === '${arguments.head}'");
+ endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE);
+ });
+ }
if (node.nullOk) {
endExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE);
}

Powered by Google App Engine
This is Rietveld 408576698