| Index: frogsh
|
| ===================================================================
|
| --- frogsh (revision 858)
|
| +++ frogsh (working copy)
|
| @@ -283,6 +283,11 @@
|
| TypeError.prototype.toString = function() {
|
| return ("Failed type check: type " + this.srcType + " is not assignable to type ") + ("" + this.dstType + " of " + this.dstName + " in " + this.url + " at line ") + ("" + this.line + ", column " + this.column + ".");
|
| }
|
| +// ********** Code for FallThroughError **************
|
| +function FallThroughError() {}
|
| +FallThroughError.prototype.toString = function() {
|
| + return ("Switch case fall-through in " + this.url + " at line " + this.line + ".");
|
| +}
|
| // ********** Code for Object **************
|
| Object.prototype.get$dynamic = function() {
|
| return this;
|
| @@ -7272,6 +7277,7 @@
|
| else {
|
| this.writer.writeln(('return ' + this.visitValue(node.value).code + ';'));
|
| }
|
| + return true;
|
| }
|
| MethodGenerator.prototype.visitThrowStatement = function(node) {
|
| if (node.value != null) {
|
| @@ -7288,6 +7294,7 @@
|
| this.writer.writeln(('throw ' + rethrow.code + ';'));
|
| }
|
| }
|
| + return true;
|
| }
|
| MethodGenerator.prototype.visitAssertStatement = function(node) {
|
| var test = this.visitValue(node.test);
|
| @@ -7309,6 +7316,7 @@
|
| else {
|
| this.writer.writeln(('break ' + node.label.name + ';'));
|
| }
|
| + return true;
|
| }
|
| MethodGenerator.prototype.visitContinueStatement = function(node) {
|
| if (node.label == null) {
|
| @@ -7317,15 +7325,18 @@
|
| else {
|
| this.writer.writeln(('continue ' + node.label.name + ';'));
|
| }
|
| + return true;
|
| }
|
| MethodGenerator.prototype.visitIfStatement = function(node) {
|
| var test = this.visitBool(node.test);
|
| + var return1, return2;
|
| this.writer.write(('if (' + test.code + ') '));
|
| - node.trueBranch.visit(this);
|
| + return1 = node.trueBranch.visit(this);
|
| if (node.falseBranch != null) {
|
| this.writer.write('else ');
|
| - node.falseBranch.visit(this);
|
| + return2 = node.falseBranch.visit(this);
|
| }
|
| + return (return1 && return2);
|
| }
|
| MethodGenerator.prototype.visitWhileStatement = function(node) {
|
| var test = this.visitBool(node.test);
|
| @@ -7482,6 +7493,7 @@
|
| MethodGenerator.prototype.visitSwitchStatement = function(node) {
|
| var test = this.visitValue(node.test);
|
| this.writer.enterBlock(('switch (' + test.code + ') {'));
|
| + var allCasesReturn = true;
|
| var $list = node.cases;
|
| for (var $i = 0;$i < $list.length; $i++) {
|
| var case_ = $list.$index($i);
|
| @@ -7493,6 +7505,9 @@
|
| i < case_.cases.length; i++) {
|
| var expr = case_.cases.$index(i);
|
| if (expr == null) {
|
| + if (i < case_.cases.length - 1) {
|
| + world.error('default clause must be the last case', case_.get$span());
|
| + }
|
| this.writer.writeln('default:');
|
| }
|
| else {
|
| @@ -7501,26 +7516,35 @@
|
| }
|
| }
|
| this.writer.enterBlock('');
|
| + var caseReturns;
|
| var $list0 = case_.statements;
|
| for (var $i0 = case_.statements.iterator(); $i0.hasNext(); ) {
|
| var stmt = $i0.next();
|
| - stmt.visit(this);
|
| + caseReturns = stmt.visit(this);
|
| }
|
| + if ($ne(case_, node.cases.$index(node.cases.length - 1)) && !caseReturns) {
|
| + var span = case_.statements.$index(case_.statements.length - 1).get$span();
|
| + this.writer.writeln(('\$throw(new FallThroughError("' + span.file.filename + '",') + (' ' + span.file.getLine(span.start) + '))'));
|
| + allCasesReturn = false;
|
| + }
|
| this.writer.exitBlock('');
|
| this._popBlock();
|
| }
|
| this.writer.exitBlock('}');
|
| + return allCasesReturn;
|
| }
|
| MethodGenerator.prototype.visitBlockStatement = function(node) {
|
| this._pushBlock(false);
|
| this.writer.enterBlock('{');
|
| + var returns;
|
| var $list = node.body;
|
| for (var $i = 0;$i < $list.length; $i++) {
|
| var stmt = $list.$index($i);
|
| - stmt.visit(this);
|
| + returns = stmt.visit(this);
|
| }
|
| this.writer.exitBlock('}');
|
| this._popBlock();
|
| + return returns;
|
| }
|
| MethodGenerator.prototype.visitLabeledStatement = function(node) {
|
| this.writer.writeln(('' + node.name.name + ':'));
|
|
|