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

Unified Diff: lib/compiler/implementation/ssa/codegen.dart

Issue 10353014: Start implementing checked mode and tools support for using it. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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
===================================================================
--- lib/compiler/implementation/ssa/codegen.dart (revision 7269)
+++ lib/compiler/implementation/ssa/codegen.dart (working copy)
@@ -959,8 +959,10 @@
visit(instruction, JSPrecedence.STATEMENT_PRECEDENCE);
return;
} else if (!isGenerateAtUseSite(instruction)) {
- if (instruction is !HIf && instruction is !HTypeGuard &&
- instruction is !HLoopBranch && !isGeneratingExpression()) {
+ if (instruction is !HIf
+ && instruction is !HTypeGuard
+ && instruction is !HLoopBranch
+ && !isGeneratingExpression()) {
addIndentation();
}
if (isGeneratingExpression()) {
@@ -975,8 +977,9 @@
}
// Control flow instructions, and some other instructions,
// know how to handle ';'.
- if (instruction is !HControlFlow && instruction is !HTypeGuard &&
- !isGeneratingExpression()) {
+ if (instruction is !HControlFlow
+ && instruction is !HTypeGuard
+ && !isGeneratingExpression()) {
buffer.add(';\n');
}
} else if (instruction is HIf) {
@@ -1750,7 +1753,11 @@
}
void checkExtendableArray(HInstruction input) {
- compiler.unimplemented("check extendable array");
+ beginExpression(JSPrecedence.PREFIX_PRECEDENCE);
+ buffer.add('!!');
+ use(input, JSPrecedence.MEMBER_PRECEDENCE);
+ buffer.add('.fixed\$length');
+ endExpression(JSPrecedence.PREFIX_PRECEDENCE);
}
void checkNull(HInstruction input) {
@@ -1892,8 +1899,56 @@
}
void visitTypeConversion(HTypeConversion node) {
- assert(isGenerateAtUseSite(node));
- use(node.inputs[0], JSPrecedence.EXPRESSION_PRECEDENCE);
+ if (node.checked) {
floitsch 2012/05/07 11:06:56 not sure I like that all of this is in the codegen
ngeoffray 2012/05/07 13:15:42 As discussed, I will live it here, but we can revi
+ Element element = node.type.computeType(compiler).element;
+ compiler.registerIsCheck(element);
+ SourceString helper;
+ String additionalArgument;
+ bool nativeCheck =
+ compiler.emitter.nativeEmitter.requiresNativeIsCheck(element);
+ beginExpression(JSPrecedence.CALL_PRECEDENCE);
+
+ if (element == compiler.stringClass) {
+ helper = const SourceString('stringTypeCheck');
+ } else if (element == compiler.doubleClass) {
+ helper = const SourceString('doubleTypeCheck');
+ } else if (element == compiler.numClass) {
+ helper = const SourceString('numTypeCheck');
+ } else if (element == compiler.boolClass) {
+ helper = const SourceString('boolTypeCheck');
+ } else if (element == compiler.functionClass || element.isTypedef()) {
+ helper = const SourceString('functionTypeCheck');
+ } else if (element == compiler.intClass) {
+ helper = const SourceString('intTypeCheck');
+ } else if (Elements.isStringSupertype(element, compiler)) {
+ helper = const SourceString('stringSuperTypeCheck');
+ } else if (element === compiler.listClass) {
+ helper = const SourceString('listTypeCheck');
+ } else {
+ additionalArgument = compiler.namer.operatorIs(element);
+ if (Elements.isListSupertype(element, compiler)) {
+ if (nativeCheck) {
+ helper = const SourceString('listSuperNativeTypeCheck');
+ } else {
+ helper = const SourceString('listSuperTypeCheck');
+ }
+ } else if (nativeCheck) {
+ helper = const SourceString('callTypeCheck');
+ } else {
+ helper = const SourceString('propertyTypeCheck');
+ }
+ }
+ Element helperElement = compiler.findHelper(helper);
+ compiler.registerStaticUse(helperElement);
+ buffer.add(compiler.namer.isolateAccess(helperElement));
+ buffer.add('(');
+ use(node.inputs[0], JSPrecedence.EXPRESSION_PRECEDENCE);
+ if (additionalArgument !== null) buffer.add(", '$additionalArgument'");
+ buffer.add(')');
+ endExpression(JSPrecedence.CALL_PRECEDENCE);
+ } else {
+ use(node.inputs[0], expectedPrecedence);
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698