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

Side by Side Diff: frogsh

Issue 8343037: Throw FallThroughError when we fall through a case in a switch statement. Fixes (Closed) Base URL: http://dart.googlecode.com/svn/experimental/frog/
Patch Set: '' Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | gen.dart » ('j') | gen.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env node 1 #!/usr/bin/env node
2 // ********** Library dart:core ************** 2 // ********** Library dart:core **************
3 // ********** Natives core.js ************** 3 // ********** Natives core.js **************
4 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 4 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
5 // for details. All rights reserved. Use of this source code is governed by a 5 // for details. All rights reserved. Use of this source code is governed by a
6 // BSD-style license that can be found in the LICENSE file. 6 // BSD-style license that can be found in the LICENSE file.
7 7
8 // TODO(jimhug): Completeness - see tests/corelib 8 // TODO(jimhug): Completeness - see tests/corelib
9 9
10 /** Implements extends for dart classes on javascript prototypes. */ 10 /** Implements extends for dart classes on javascript prototypes. */
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 function AssertError() {} 276 function AssertError() {}
277 AssertError.prototype.toString = function() { 277 AssertError.prototype.toString = function() {
278 return ("Failed assertion: '" + this.failedAssertion + "' is not true ") + ("i n " + this.url + " at line " + this.line + ", column " + this.column + "."); 278 return ("Failed assertion: '" + this.failedAssertion + "' is not true ") + ("i n " + this.url + " at line " + this.line + ", column " + this.column + ".");
279 } 279 }
280 // ********** Code for TypeError ************** 280 // ********** Code for TypeError **************
281 function TypeError() {} 281 function TypeError() {}
282 $inherits(TypeError, AssertError); 282 $inherits(TypeError, AssertError);
283 TypeError.prototype.toString = function() { 283 TypeError.prototype.toString = function() {
284 return ("Failed type check: type " + this.srcType + " is not assignable to typ e ") + ("" + this.dstType + " of " + this.dstName + " in " + this.url + " at lin e ") + ("" + this.line + ", column " + this.column + "."); 284 return ("Failed type check: type " + this.srcType + " is not assignable to typ e ") + ("" + this.dstType + " of " + this.dstName + " in " + this.url + " at lin e ") + ("" + this.line + ", column " + this.column + ".");
285 } 285 }
286 // ********** Code for FallThroughError **************
287 function FallThroughError() {}
288 FallThroughError.prototype.toString = function() {
289 return ("Switch case fall-through in " + this.url + " at line " + this.line + ".");
290 }
286 // ********** Code for Object ************** 291 // ********** Code for Object **************
287 Object.prototype.get$dynamic = function() { 292 Object.prototype.get$dynamic = function() {
288 return this; 293 return this;
289 } 294 }
290 Object.prototype.forEach$1 = function(f) { 295 Object.prototype.forEach$1 = function(f) {
291 return this.forEach(to$call$1(f)); 296 return this.forEach(to$call$1(f));
292 } 297 }
293 function Duration() {} 298 function Duration() {}
294 // ********** Code for IndexOutOfRangeException ************** 299 // ********** Code for IndexOutOfRangeException **************
295 function IndexOutOfRangeException() {} 300 function IndexOutOfRangeException() {}
(...skipping 6969 matching lines...) Expand 10 before | Expand all | Expand 10 after
7265 var funcValue = this._scope.create(name, meth.get$functionType(), this.method. get$definition()); 7270 var funcValue = this._scope.create(name, meth.get$functionType(), this.method. get$definition());
7266 meth.generator.writeDefinition(this.writer, null); 7271 meth.generator.writeDefinition(this.writer, null);
7267 } 7272 }
7268 MethodGenerator.prototype.visitReturnStatement = function(node) { 7273 MethodGenerator.prototype.visitReturnStatement = function(node) {
7269 if (node.value == null) { 7274 if (node.value == null) {
7270 this.writer.writeln('return;'); 7275 this.writer.writeln('return;');
7271 } 7276 }
7272 else { 7277 else {
7273 this.writer.writeln(('return ' + this.visitValue(node.value).code + ';')); 7278 this.writer.writeln(('return ' + this.visitValue(node.value).code + ';'));
7274 } 7279 }
7280 return true;
7275 } 7281 }
7276 MethodGenerator.prototype.visitThrowStatement = function(node) { 7282 MethodGenerator.prototype.visitThrowStatement = function(node) {
7277 if (node.value != null) { 7283 if (node.value != null) {
7278 var value = this.visitValue(node.value); 7284 var value = this.visitValue(node.value);
7279 value.invoke(this.parent, 'toString', node, Arguments.get$EMPTY()); 7285 value.invoke(this.parent, 'toString', node, Arguments.get$EMPTY());
7280 this.writer.writeln(('\$throw(' + value.code + ');')); 7286 this.writer.writeln(('\$throw(' + value.code + ');'));
7281 } 7287 }
7282 else { 7288 else {
7283 var rethrow = this._scope.getRethrow(); 7289 var rethrow = this._scope.getRethrow();
7284 if (rethrow == null) { 7290 if (rethrow == null) {
7285 world.error('rethrow outside of catch', node.span); 7291 world.error('rethrow outside of catch', node.span);
7286 } 7292 }
7287 else { 7293 else {
7288 this.writer.writeln(('throw ' + rethrow.code + ';')); 7294 this.writer.writeln(('throw ' + rethrow.code + ';'));
7289 } 7295 }
7290 } 7296 }
7297 return true;
7291 } 7298 }
7292 MethodGenerator.prototype.visitAssertStatement = function(node) { 7299 MethodGenerator.prototype.visitAssertStatement = function(node) {
7293 var test = this.visitValue(node.test); 7300 var test = this.visitValue(node.test);
7294 if (options.enableAsserts) { 7301 if (options.enableAsserts) {
7295 var err = world.corelib.types.$index('AssertError'); 7302 var err = world.corelib.types.$index('AssertError');
7296 err.markUsed(); 7303 err.markUsed();
7297 this.parent.genMethod(err.getConstructor('')); 7304 this.parent.genMethod(err.getConstructor(''));
7298 this.parent.genMethod(err.members.$index('toString')); 7305 this.parent.genMethod(err.members.$index('toString'));
7299 var span = node.test.span; 7306 var span = node.test.span;
7300 var line = span.file.getLine(span.start); 7307 var line = span.file.getLine(span.start);
7301 var column = span.file.getColumn(line, span.start); 7308 var column = span.file.getColumn(line, span.start);
7302 this.writer.writeln(('\$assert(' + test.code + ', "' + MethodGenerator._esca peString(span.get$text()) + '",') + (' "' + span.file.filename + '", ' + (line + 1) + ', ' + (column + 1) + ');')); 7309 this.writer.writeln(('\$assert(' + test.code + ', "' + MethodGenerator._esca peString(span.get$text()) + '",') + (' "' + span.file.filename + '", ' + (line + 1) + ', ' + (column + 1) + ');'));
7303 } 7310 }
7304 } 7311 }
7305 MethodGenerator.prototype.visitBreakStatement = function(node) { 7312 MethodGenerator.prototype.visitBreakStatement = function(node) {
7306 if (node.label == null) { 7313 if (node.label == null) {
7307 this.writer.writeln('break;'); 7314 this.writer.writeln('break;');
7308 } 7315 }
7309 else { 7316 else {
7310 this.writer.writeln(('break ' + node.label.name + ';')); 7317 this.writer.writeln(('break ' + node.label.name + ';'));
7311 } 7318 }
7319 return true;
7312 } 7320 }
7313 MethodGenerator.prototype.visitContinueStatement = function(node) { 7321 MethodGenerator.prototype.visitContinueStatement = function(node) {
7314 if (node.label == null) { 7322 if (node.label == null) {
7315 this.writer.writeln('continue;'); 7323 this.writer.writeln('continue;');
7316 } 7324 }
7317 else { 7325 else {
7318 this.writer.writeln(('continue ' + node.label.name + ';')); 7326 this.writer.writeln(('continue ' + node.label.name + ';'));
7319 } 7327 }
7328 return true;
7320 } 7329 }
7321 MethodGenerator.prototype.visitIfStatement = function(node) { 7330 MethodGenerator.prototype.visitIfStatement = function(node) {
7322 var test = this.visitBool(node.test); 7331 var test = this.visitBool(node.test);
7332 var return1, return2;
7323 this.writer.write(('if (' + test.code + ') ')); 7333 this.writer.write(('if (' + test.code + ') '));
7324 node.trueBranch.visit(this); 7334 return1 = node.trueBranch.visit(this);
7325 if (node.falseBranch != null) { 7335 if (node.falseBranch != null) {
7326 this.writer.write('else '); 7336 this.writer.write('else ');
7327 node.falseBranch.visit(this); 7337 return2 = node.falseBranch.visit(this);
7328 } 7338 }
7339 return (return1 && return2);
7329 } 7340 }
7330 MethodGenerator.prototype.visitWhileStatement = function(node) { 7341 MethodGenerator.prototype.visitWhileStatement = function(node) {
7331 var test = this.visitBool(node.test); 7342 var test = this.visitBool(node.test);
7332 this.writer.write(('while (' + test.code + ') ')); 7343 this.writer.write(('while (' + test.code + ') '));
7333 this._pushBlock(true); 7344 this._pushBlock(true);
7334 node.body.visit(this); 7345 node.body.visit(this);
7335 this._popBlock(); 7346 this._popBlock();
7336 } 7347 }
7337 MethodGenerator.prototype.visitDoStatement = function(node) { 7348 MethodGenerator.prototype.visitDoStatement = function(node) {
7338 this.writer.write('do '); 7349 this.writer.write('do ');
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
7475 this.writer.nextBlock('} finally {'); 7486 this.writer.nextBlock('} finally {');
7476 this._pushBlock(false); 7487 this._pushBlock(false);
7477 this.visitStatementsInBlock(node.finallyBlock); 7488 this.visitStatementsInBlock(node.finallyBlock);
7478 this._popBlock(); 7489 this._popBlock();
7479 } 7490 }
7480 this.writer.exitBlock('}'); 7491 this.writer.exitBlock('}');
7481 } 7492 }
7482 MethodGenerator.prototype.visitSwitchStatement = function(node) { 7493 MethodGenerator.prototype.visitSwitchStatement = function(node) {
7483 var test = this.visitValue(node.test); 7494 var test = this.visitValue(node.test);
7484 this.writer.enterBlock(('switch (' + test.code + ') {')); 7495 this.writer.enterBlock(('switch (' + test.code + ') {'));
7496 var allCasesReturn = true;
7485 var $list = node.cases; 7497 var $list = node.cases;
7486 for (var $i = 0;$i < $list.length; $i++) { 7498 for (var $i = 0;$i < $list.length; $i++) {
7487 var case_ = $list.$index($i); 7499 var case_ = $list.$index($i);
7488 if (case_.label != null) { 7500 if (case_.label != null) {
7489 world.error('unimplemented: labeled case statement', case_.get$span()); 7501 world.error('unimplemented: labeled case statement', case_.get$span());
7490 } 7502 }
7491 this._pushBlock(false); 7503 this._pushBlock(false);
7492 for (var i = 0; 7504 for (var i = 0;
7493 i < case_.cases.length; i++) { 7505 i < case_.cases.length; i++) {
7494 var expr = case_.cases.$index(i); 7506 var expr = case_.cases.$index(i);
7495 if (expr == null) { 7507 if (expr == null) {
7508 if (i < case_.cases.length - 1) {
7509 world.error('default clause must be the last case', case_.get$span());
7510 }
7496 this.writer.writeln('default:'); 7511 this.writer.writeln('default:');
7497 } 7512 }
7498 else { 7513 else {
7499 var value = this.visitValue(expr); 7514 var value = this.visitValue(expr);
7500 this.writer.writeln(('case ' + value.code + ':')); 7515 this.writer.writeln(('case ' + value.code + ':'));
7501 } 7516 }
7502 } 7517 }
7503 this.writer.enterBlock(''); 7518 this.writer.enterBlock('');
7519 var caseReturns;
7504 var $list0 = case_.statements; 7520 var $list0 = case_.statements;
7505 for (var $i0 = case_.statements.iterator(); $i0.hasNext(); ) { 7521 for (var $i0 = case_.statements.iterator(); $i0.hasNext(); ) {
7506 var stmt = $i0.next(); 7522 var stmt = $i0.next();
7507 stmt.visit(this); 7523 caseReturns = stmt.visit(this);
7524 }
7525 if ($ne(case_, node.cases.$index(node.cases.length - 1)) && !caseReturns) {
7526 var span = case_.statements.$index(case_.statements.length - 1).get$span() ;
7527 this.writer.writeln(('\$throw(new FallThroughError("' + span.file.filename + '",') + (' ' + span.file.getLine(span.start) + '))'));
7528 allCasesReturn = false;
7508 } 7529 }
7509 this.writer.exitBlock(''); 7530 this.writer.exitBlock('');
7510 this._popBlock(); 7531 this._popBlock();
7511 } 7532 }
7512 this.writer.exitBlock('}'); 7533 this.writer.exitBlock('}');
7534 return allCasesReturn;
7513 } 7535 }
7514 MethodGenerator.prototype.visitBlockStatement = function(node) { 7536 MethodGenerator.prototype.visitBlockStatement = function(node) {
7515 this._pushBlock(false); 7537 this._pushBlock(false);
7516 this.writer.enterBlock('{'); 7538 this.writer.enterBlock('{');
7539 var returns;
7517 var $list = node.body; 7540 var $list = node.body;
7518 for (var $i = 0;$i < $list.length; $i++) { 7541 for (var $i = 0;$i < $list.length; $i++) {
7519 var stmt = $list.$index($i); 7542 var stmt = $list.$index($i);
7520 stmt.visit(this); 7543 returns = stmt.visit(this);
7521 } 7544 }
7522 this.writer.exitBlock('}'); 7545 this.writer.exitBlock('}');
7523 this._popBlock(); 7546 this._popBlock();
7547 return returns;
7524 } 7548 }
7525 MethodGenerator.prototype.visitLabeledStatement = function(node) { 7549 MethodGenerator.prototype.visitLabeledStatement = function(node) {
7526 this.writer.writeln(('' + node.name.name + ':')); 7550 this.writer.writeln(('' + node.name.name + ':'));
7527 node.body.visit(this); 7551 node.body.visit(this);
7528 } 7552 }
7529 MethodGenerator.prototype.visitExpressionStatement = function(node) { 7553 MethodGenerator.prototype.visitExpressionStatement = function(node) {
7530 if ((node.body instanceof VarExpression) || (node.body instanceof ThisExpressi on)) { 7554 if ((node.body instanceof VarExpression) || (node.body instanceof ThisExpressi on)) {
7531 world.warning('variable used as statement', node.span); 7555 world.warning('variable used as statement', node.span);
7532 } 7556 }
7533 var value = this.visitVoid(node.body); 7557 var value = this.visitVoid(node.body);
(...skipping 8489 matching lines...) Expand 10 before | Expand all | Expand 10 after
16023 INTERFACE, 16047 INTERFACE,
16024 LIBRARY, 16048 LIBRARY,
16025 NATIVE, 16049 NATIVE,
16026 NEGATE, 16050 NEGATE,
16027 OPERATOR, 16051 OPERATOR,
16028 SET, 16052 SET,
16029 SOURCE, 16053 SOURCE,
16030 STATIC, 16054 STATIC,
16031 TYPEDEF ]*/; 16055 TYPEDEF ]*/;
16032 main(); 16056 main();
OLDNEW
« no previous file with comments | « no previous file | gen.dart » ('j') | gen.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698