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

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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 function AssertError() {} 295 function AssertError() {}
296 AssertError.prototype.toString = function() { 296 AssertError.prototype.toString = function() {
297 return ("Failed assertion: '" + this.failedAssertion + "' is not true ") + ("i n " + this.url + " at line " + this.line + ", column " + this.column + "."); 297 return ("Failed assertion: '" + this.failedAssertion + "' is not true ") + ("i n " + this.url + " at line " + this.line + ", column " + this.column + ".");
298 } 298 }
299 // ********** Code for TypeError ************** 299 // ********** Code for TypeError **************
300 function TypeError() {} 300 function TypeError() {}
301 $inherits(TypeError, AssertError); 301 $inherits(TypeError, AssertError);
302 TypeError.prototype.toString = function() { 302 TypeError.prototype.toString = function() {
303 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 + "."); 303 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 + ".");
304 } 304 }
305 // ********** Code for FallThroughError **************
306 function FallThroughError() {}
307 FallThroughError.prototype.toString = function() {
308 return ("Switch case fall-through in " + this.url + " at line " + this.line + ".");
309 }
305 // ********** Code for Object ************** 310 // ********** Code for Object **************
306 Object.prototype.get$dynamic = function() { 311 Object.prototype.get$dynamic = function() {
307 return this; 312 return this;
308 } 313 }
309 Object.prototype.noSuchMethod = function(name, args) { 314 Object.prototype.noSuchMethod = function(name, args) {
310 $throw(new NoSuchMethodException(this, name, args)); 315 $throw(new NoSuchMethodException(this, name, args));
311 } 316 }
312 $defineMethod(Object, "forEach$1", function($0) { 317 $defineMethod(Object, "forEach$1", function($0) {
313 return this.noSuchMethod("forEach$1", [$0]); 318 return this.noSuchMethod("forEach$1", [$0]);
314 } 319 }
(...skipping 2237 matching lines...) Expand 10 before | Expand all | Expand 10 after
2552 case 62/*null.$GT*/: 2557 case 62/*null.$GT*/:
2553 2558
2554 return this.select(61/*null.$EQ*/, ">>>=", ">>>"); 2559 return this.select(61/*null.$EQ*/, ">>>=", ">>>");
2555 2560
2556 default: 2561 default:
2557 2562
2558 this.appendStringToken(62/*null.$GT*/, ">>"); 2563 this.appendStringToken(62/*null.$GT*/, ">>");
2559 return next; 2564 return next;
2560 2565
2561 } 2566 }
2567 $throw(new FallThroughError("./leg/scanner/scanner.dart", 389))
jimhug 2011/10/28 20:02:44 Please send Peter Ahe and email pointing this chan
2562 2568
2563 default: 2569 default:
2564 2570
2565 this.appendStringToken(62/*null.$GT*/, ">"); 2571 this.appendStringToken(62/*null.$GT*/, ">");
2566 return next; 2572 return next;
2567 2573
2568 } 2574 }
2569 } 2575 }
2570 ArrayBasedScanner$String.prototype.tokenizeLessThan = function(next) { 2576 ArrayBasedScanner$String.prototype.tokenizeLessThan = function(next) {
2571 next = this.advance(); 2577 next = this.advance();
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
3459 case 62/*null.$GT*/: 3465 case 62/*null.$GT*/:
3460 3466
3461 return this.select(61/*null.$EQ*/, ">>>=", ">>>"); 3467 return this.select(61/*null.$EQ*/, ">>>=", ">>>");
3462 3468
3463 default: 3469 default:
3464 3470
3465 this.appendStringToken(62/*null.$GT*/, ">>"); 3471 this.appendStringToken(62/*null.$GT*/, ">>");
3466 return next; 3472 return next;
3467 3473
3468 } 3474 }
3475 $throw(new FallThroughError("./leg/scanner/scanner.dart", 389))
3469 3476
3470 default: 3477 default:
3471 3478
3472 this.appendStringToken(62/*null.$GT*/, ">"); 3479 this.appendStringToken(62/*null.$GT*/, ">");
3473 return next; 3480 return next;
3474 3481
3475 } 3482 }
3476 } 3483 }
3477 AbstractScanner.prototype.tokenizeLessThan = function(next) { 3484 AbstractScanner.prototype.tokenizeLessThan = function(next) {
3478 next = this.advance(); 3485 next = this.advance();
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
4261 case 62/*null.$GT*/: 4268 case 62/*null.$GT*/:
4262 4269
4263 return this.select(61/*null.$EQ*/, ">>>=", ">>>"); 4270 return this.select(61/*null.$EQ*/, ">>>=", ">>>");
4264 4271
4265 default: 4272 default:
4266 4273
4267 this.appendStringToken(62/*null.$GT*/, ">>"); 4274 this.appendStringToken(62/*null.$GT*/, ">>");
4268 return next; 4275 return next;
4269 4276
4270 } 4277 }
4278 $throw(new FallThroughError("./leg/scanner/scanner.dart", 389))
4271 4279
4272 default: 4280 default:
4273 4281
4274 this.appendStringToken(62/*null.$GT*/, ">"); 4282 this.appendStringToken(62/*null.$GT*/, ">");
4275 return next; 4283 return next;
4276 4284
4277 } 4285 }
4278 } 4286 }
4279 AbstractScanner$S.prototype.tokenizeLessThan = function(next) { 4287 AbstractScanner$S.prototype.tokenizeLessThan = function(next) {
4280 next = this.advance(); 4288 next = this.advance();
(...skipping 2962 matching lines...) Expand 10 before | Expand all | Expand 10 after
7243 if ((body instanceof BlockStatement)) { 7251 if ((body instanceof BlockStatement)) {
7244 var $list = body.body; 7252 var $list = body.body;
7245 for (var $i = body.body.iterator(); $i.hasNext(); ) { 7253 for (var $i = body.body.iterator(); $i.hasNext(); ) {
7246 var stmt = $i.next(); 7254 var stmt = $i.next();
7247 stmt.visit(this); 7255 stmt.visit(this);
7248 } 7256 }
7249 } 7257 }
7250 else { 7258 else {
7251 if (body != null) body.visit(this); 7259 if (body != null) body.visit(this);
7252 } 7260 }
7261 return false;
7253 } 7262 }
7254 MethodGenerator.prototype._pushBlock = function(reentrant) { 7263 MethodGenerator.prototype._pushBlock = function(reentrant) {
7255 this._scope = new BlockScope(this, this._scope, reentrant); 7264 this._scope = new BlockScope(this, this._scope, reentrant);
7256 } 7265 }
7257 MethodGenerator.prototype._popBlock = function() { 7266 MethodGenerator.prototype._popBlock = function() {
7258 this._scope = this._scope.parent; 7267 this._scope = this._scope.parent;
7259 } 7268 }
7260 MethodGenerator.prototype._makeLambdaMethod = function(name, func) { 7269 MethodGenerator.prototype._makeLambdaMethod = function(name, func) {
7261 var meth = new MethodMember(name, this.method.declaringType, func); 7270 var meth = new MethodMember(name, this.method.declaringType, func);
7262 meth.isLambda = true; 7271 meth.isLambda = true;
(...skipping 19 matching lines...) Expand all
7282 if ((node instanceof PostfixExpression)) { 7291 if ((node instanceof PostfixExpression)) {
7283 var value = this.visitPostfixExpression(node, true); 7292 var value = this.visitPostfixExpression(node, true);
7284 value.checkFirstClass(node.span); 7293 value.checkFirstClass(node.span);
7285 return value; 7294 return value;
7286 } 7295 }
7287 return this.visitValue(node); 7296 return this.visitValue(node);
7288 } 7297 }
7289 MethodGenerator.prototype.visitDietStatement = function(node) { 7298 MethodGenerator.prototype.visitDietStatement = function(node) {
7290 var parser = new lang_Parser(node.span.file, false, node.span.start); 7299 var parser = new lang_Parser(node.span.file, false, node.span.start);
7291 this.visitStatementsInBlock(parser.block()); 7300 this.visitStatementsInBlock(parser.block());
7301 return false;
7292 } 7302 }
7293 MethodGenerator.prototype.visitVariableDefinition = function(node) { 7303 MethodGenerator.prototype.visitVariableDefinition = function(node) {
7294 var isFinal = false; 7304 var isFinal = false;
7295 if (node.modifiers != null && node.modifiers.$index(0).kind == 96/*TokenKind.F INAL*/) { 7305 if (node.modifiers != null && node.modifiers.$index(0).kind == 96/*TokenKind.F INAL*/) {
7296 isFinal = true; 7306 isFinal = true;
7297 } 7307 }
7298 this.writer.write('var '); 7308 this.writer.write('var ');
7299 var type = this.method.resolveType(node.type); 7309 var type = this.method.resolveType(node.type);
7300 for (var i = 0; 7310 for (var i = 0;
7301 i < node.names.length; i++) { 7311 i < node.names.length; i++) {
(...skipping 13 matching lines...) Expand all
7315 } 7325 }
7316 var val = this._scope.create(name, thisType, node.names.$index(i)); 7326 var val = this._scope.create(name, thisType, node.names.$index(i));
7317 if (value == null) { 7327 if (value == null) {
7318 this.writer.write(('' + val.code + '')); 7328 this.writer.write(('' + val.code + ''));
7319 } 7329 }
7320 else { 7330 else {
7321 this.writer.write(('' + val.code + ' = ' + value.code + '')); 7331 this.writer.write(('' + val.code + ' = ' + value.code + ''));
7322 } 7332 }
7323 } 7333 }
7324 this.writer.writeln(';'); 7334 this.writer.writeln(';');
7335 return false;
7325 } 7336 }
7326 MethodGenerator.prototype.visitFunctionDefinition = function(node) { 7337 MethodGenerator.prototype.visitFunctionDefinition = function(node) {
7327 var name = world.toJsIdentifier(node.name.name); 7338 var name = world.toJsIdentifier(node.name.name);
7328 var meth = this._makeLambdaMethod(name, node); 7339 var meth = this._makeLambdaMethod(name, node);
7329 var funcValue = this._scope.create(name, meth.get$functionType(), this.method. get$definition()); 7340 var funcValue = this._scope.create(name, meth.get$functionType(), this.method. get$definition());
7330 meth.generator.writeDefinition(this.writer, null); 7341 meth.generator.writeDefinition(this.writer, null);
7342 return false;
7331 } 7343 }
7332 MethodGenerator.prototype.visitReturnStatement = function(node) { 7344 MethodGenerator.prototype.visitReturnStatement = function(node) {
7333 if (node.value == null) { 7345 if (node.value == null) {
7334 this.writer.writeln('return;'); 7346 this.writer.writeln('return;');
7335 } 7347 }
7336 else { 7348 else {
7337 if (this.method.get$isConstructor()) { 7349 if (this.method.get$isConstructor()) {
7338 world.error('return of value not allowed from constructor', node.span); 7350 world.error('return of value not allowed from constructor', node.span);
7339 } 7351 }
7340 this.writer.writeln(('return ' + this.visitValue(node.value).code + ';')); 7352 this.writer.writeln(('return ' + this.visitValue(node.value).code + ';'));
7341 } 7353 }
7354 return true;
7342 } 7355 }
7343 MethodGenerator.prototype.visitThrowStatement = function(node) { 7356 MethodGenerator.prototype.visitThrowStatement = function(node) {
7344 if (node.value != null) { 7357 if (node.value != null) {
7345 var value = this.visitValue(node.value); 7358 var value = this.visitValue(node.value);
7346 value.invoke(this.parent, 'toString', node, Arguments.get$EMPTY()); 7359 value.invoke(this.parent, 'toString', node, Arguments.get$EMPTY());
7347 this.writer.writeln(('\$throw(' + value.code + ');')); 7360 this.writer.writeln(('\$throw(' + value.code + ');'));
7348 } 7361 }
7349 else { 7362 else {
7350 var rethrow = this._scope.getRethrow(); 7363 var rethrow = this._scope.getRethrow();
7351 if (rethrow == null) { 7364 if (rethrow == null) {
7352 world.error('rethrow outside of catch', node.span); 7365 world.error('rethrow outside of catch', node.span);
7353 } 7366 }
7354 else { 7367 else {
7355 this.writer.writeln(('throw ' + rethrow.code + ';')); 7368 this.writer.writeln(('throw ' + rethrow.code + ';'));
7356 } 7369 }
7357 } 7370 }
7371 return true;
7358 } 7372 }
7359 MethodGenerator.prototype.visitAssertStatement = function(node) { 7373 MethodGenerator.prototype.visitAssertStatement = function(node) {
7360 var test = this.visitValue(node.test); 7374 var test = this.visitValue(node.test);
7361 if (options.enableAsserts) { 7375 if (options.enableAsserts) {
7362 var err = world.corelib.types.$index('AssertError'); 7376 var err = world.corelib.types.$index('AssertError');
7363 err.markUsed(); 7377 err.markUsed();
7364 this.parent.genMethod(err.getConstructor('')); 7378 this.parent.genMethod(err.getConstructor(''));
7365 this.parent.genMethod(err.members.$index('toString')); 7379 this.parent.genMethod(err.members.$index('toString'));
7366 var span = node.test.span; 7380 var span = node.test.span;
7367 var line = span.file.getLine(span.start); 7381 var line = span.file.getLine(span.start);
7368 var column = span.file.getColumn(line, span.start); 7382 var column = span.file.getColumn(line, span.start);
7369 this.writer.writeln(('\$assert(' + test.code + ', "' + MethodGenerator._esca peString(span.get$text()) + '",') + (' "' + span.file.filename + '", ' + (line + 1) + ', ' + (column + 1) + ');')); 7383 this.writer.writeln(('\$assert(' + test.code + ', "' + MethodGenerator._esca peString(span.get$text()) + '",') + (' "' + span.file.filename + '", ' + (line + 1) + ', ' + (column + 1) + ');'));
7370 } 7384 }
7385 return false;
7371 } 7386 }
7372 MethodGenerator.prototype.visitBreakStatement = function(node) { 7387 MethodGenerator.prototype.visitBreakStatement = function(node) {
7373 if (node.label == null) { 7388 if (node.label == null) {
7374 this.writer.writeln('break;'); 7389 this.writer.writeln('break;');
7375 } 7390 }
7376 else { 7391 else {
7377 this.writer.writeln(('break ' + node.label.name + ';')); 7392 this.writer.writeln(('break ' + node.label.name + ';'));
7378 } 7393 }
7394 return true;
7379 } 7395 }
7380 MethodGenerator.prototype.visitContinueStatement = function(node) { 7396 MethodGenerator.prototype.visitContinueStatement = function(node) {
7381 if (node.label == null) { 7397 if (node.label == null) {
7382 this.writer.writeln('continue;'); 7398 this.writer.writeln('continue;');
7383 } 7399 }
7384 else { 7400 else {
7385 this.writer.writeln(('continue ' + node.label.name + ';')); 7401 this.writer.writeln(('continue ' + node.label.name + ';'));
7386 } 7402 }
7403 return true;
7387 } 7404 }
7388 MethodGenerator.prototype.visitIfStatement = function(node) { 7405 MethodGenerator.prototype.visitIfStatement = function(node) {
7389 var test = this.visitBool(node.test); 7406 var test = this.visitBool(node.test);
7407 var exit1;
7390 this.writer.write(('if (' + test.code + ') ')); 7408 this.writer.write(('if (' + test.code + ') '));
7391 node.trueBranch.visit(this); 7409 exit1 = node.trueBranch.visit(this);
7392 if (node.falseBranch != null) { 7410 if (node.falseBranch != null) {
7393 this.writer.write('else '); 7411 this.writer.write('else ');
7394 node.falseBranch.visit(this); 7412 if (node.falseBranch.visit(this) && exit1) {
7413 return true;
7414 }
7395 } 7415 }
7416 return false;
7396 } 7417 }
7397 MethodGenerator.prototype.visitWhileStatement = function(node) { 7418 MethodGenerator.prototype.visitWhileStatement = function(node) {
7398 var test = this.visitBool(node.test); 7419 var test = this.visitBool(node.test);
7399 this.writer.write(('while (' + test.code + ') ')); 7420 this.writer.write(('while (' + test.code + ') '));
7400 this._pushBlock(true); 7421 this._pushBlock(true);
7401 node.body.visit(this); 7422 node.body.visit(this);
7402 this._popBlock(); 7423 this._popBlock();
7424 return false;
7403 } 7425 }
7404 MethodGenerator.prototype.visitDoStatement = function(node) { 7426 MethodGenerator.prototype.visitDoStatement = function(node) {
7405 this.writer.write('do '); 7427 this.writer.write('do ');
7406 this._pushBlock(true); 7428 this._pushBlock(true);
7407 node.body.visit(this); 7429 node.body.visit(this);
7408 this._popBlock(); 7430 this._popBlock();
7409 var test = this.visitBool(node.test); 7431 var test = this.visitBool(node.test);
7410 this.writer.writeln(('while (' + test.code + ')')); 7432 this.writer.writeln(('while (' + test.code + ')'));
7433 return false;
7411 } 7434 }
7412 MethodGenerator.prototype.visitForStatement = function(node) { 7435 MethodGenerator.prototype.visitForStatement = function(node) {
7413 this._pushBlock(false); 7436 this._pushBlock(false);
7414 this.writer.write('for ('); 7437 this.writer.write('for (');
7415 if (node.init != null) node.init.visit(this); 7438 if (node.init != null) node.init.visit(this);
7416 else this.writer.write(';'); 7439 else this.writer.write(';');
7417 if (node.test != null) { 7440 if (node.test != null) {
7418 var test = this.visitBool(node.test); 7441 var test = this.visitBool(node.test);
7419 this.writer.write((' ' + test.code + '; ')); 7442 this.writer.write((' ' + test.code + '; '));
7420 } 7443 }
7421 else { 7444 else {
7422 this.writer.write('; '); 7445 this.writer.write('; ');
7423 } 7446 }
7424 var needsComma = false; 7447 var needsComma = false;
7425 var $list = node.step; 7448 var $list = node.step;
7426 for (var $i = 0;$i < $list.length; $i++) { 7449 for (var $i = 0;$i < $list.length; $i++) {
7427 var s = $list.$index($i); 7450 var s = $list.$index($i);
7428 if (needsComma) this.writer.write(', '); 7451 if (needsComma) this.writer.write(', ');
7429 var sv = this.visitVoid(s); 7452 var sv = this.visitVoid(s);
7430 this.writer.write(sv.code); 7453 this.writer.write(sv.code);
7431 needsComma = true; 7454 needsComma = true;
7432 } 7455 }
7433 this.writer.write(') '); 7456 this.writer.write(') ');
7434 this._pushBlock(true); 7457 this._pushBlock(true);
7435 node.body.visit(this); 7458 node.body.visit(this);
7436 this._popBlock(); 7459 this._popBlock();
7437 this._popBlock(); 7460 this._popBlock();
7461 return false;
7438 } 7462 }
7439 MethodGenerator.prototype.visitForInStatement = function(node) { 7463 MethodGenerator.prototype.visitForInStatement = function(node) {
7440 var itemType = this.method.resolveType(node.item.type); 7464 var itemType = this.method.resolveType(node.item.type);
7441 var itemName = node.item.name.name; 7465 var itemName = node.item.name.name;
7442 var list = node.list.visit(this); 7466 var list = node.list.visit(this);
7443 this._pushBlock(true); 7467 this._pushBlock(true);
7444 var item = this._scope.create(itemName, itemType, node.item.name); 7468 var item = this._scope.create(itemName, itemType, node.item.name);
7445 var listVar = list; 7469 var listVar = list;
7446 if (list.needsTemp) { 7470 if (list.needsTemp) {
7447 listVar = this._scope.create('\$list', list.type, null); 7471 listVar = this._scope.create('\$list', list.type, null);
(...skipping 12 matching lines...) Expand all
7460 var iterator = list.invoke(this.parent, 'iterator', node.list, Arguments.get $EMPTY()); 7484 var iterator = list.invoke(this.parent, 'iterator', node.list, Arguments.get $EMPTY());
7461 var tmpi = this._scope.create('\$i', iterator.type, null); 7485 var tmpi = this._scope.create('\$i', iterator.type, null);
7462 var hasNext = tmpi.invoke(this.parent, 'hasNext', node.list, Arguments.get$E MPTY()); 7486 var hasNext = tmpi.invoke(this.parent, 'hasNext', node.list, Arguments.get$E MPTY());
7463 var next = tmpi.invoke(this.parent, 'next', node.list, Arguments.get$EMPTY() ); 7487 var next = tmpi.invoke(this.parent, 'next', node.list, Arguments.get$EMPTY() );
7464 this.writer.enterBlock(('for (var ' + tmpi.code + ' = ' + iterator.code + '; ' + hasNext.code + '; ) {')); 7488 this.writer.enterBlock(('for (var ' + tmpi.code + ' = ' + iterator.code + '; ' + hasNext.code + '; ) {'));
7465 this.writer.writeln(('var ' + item.code + ' = ' + next.code + ';')); 7489 this.writer.writeln(('var ' + item.code + ' = ' + next.code + ';'));
7466 } 7490 }
7467 this.visitStatementsInBlock(node.body); 7491 this.visitStatementsInBlock(node.body);
7468 this.writer.exitBlock('}'); 7492 this.writer.exitBlock('}');
7469 this._popBlock(); 7493 this._popBlock();
7494 return false;
7470 } 7495 }
7471 MethodGenerator.prototype.visitTryStatement = function(node) { 7496 MethodGenerator.prototype.visitTryStatement = function(node) {
7472 this.writer.enterBlock('try {'); 7497 this.writer.enterBlock('try {');
7473 this._pushBlock(false); 7498 this._pushBlock(false);
7474 this.visitStatementsInBlock(node.body); 7499 this.visitStatementsInBlock(node.body);
7475 this._popBlock(); 7500 this._popBlock();
7476 if (node.catches.length == 1) { 7501 if (node.catches.length == 1) {
7477 var catch_ = node.catches.$index(0); 7502 var catch_ = node.catches.$index(0);
7478 this._pushBlock(false); 7503 this._pushBlock(false);
7479 var ex = this._scope.declare(catch_.exception); 7504 var ex = this._scope.declare(catch_.exception);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
7538 } 7563 }
7539 this._popBlock(); 7564 this._popBlock();
7540 } 7565 }
7541 if (node.finallyBlock != null) { 7566 if (node.finallyBlock != null) {
7542 this.writer.nextBlock('} finally {'); 7567 this.writer.nextBlock('} finally {');
7543 this._pushBlock(false); 7568 this._pushBlock(false);
7544 this.visitStatementsInBlock(node.finallyBlock); 7569 this.visitStatementsInBlock(node.finallyBlock);
7545 this._popBlock(); 7570 this._popBlock();
7546 } 7571 }
7547 this.writer.exitBlock('}'); 7572 this.writer.exitBlock('}');
7573 return false;
7548 } 7574 }
7549 MethodGenerator.prototype.visitSwitchStatement = function(node) { 7575 MethodGenerator.prototype.visitSwitchStatement = function(node) {
7550 var test = this.visitValue(node.test); 7576 var test = this.visitValue(node.test);
7551 this.writer.enterBlock(('switch (' + test.code + ') {')); 7577 this.writer.enterBlock(('switch (' + test.code + ') {'));
7552 var $list = node.cases; 7578 var $list = node.cases;
7553 for (var $i = 0;$i < $list.length; $i++) { 7579 for (var $i = 0;$i < $list.length; $i++) {
7554 var case_ = $list.$index($i); 7580 var case_ = $list.$index($i);
7555 if (case_.label != null) { 7581 if (case_.label != null) {
7556 world.error('unimplemented: labeled case statement', case_.get$span()); 7582 world.error('unimplemented: labeled case statement', case_.get$span());
7557 } 7583 }
7558 this._pushBlock(false); 7584 this._pushBlock(false);
7559 for (var i = 0; 7585 for (var i = 0;
7560 i < case_.cases.length; i++) { 7586 i < case_.cases.length; i++) {
7561 var expr = case_.cases.$index(i); 7587 var expr = case_.cases.$index(i);
7562 if (expr == null) { 7588 if (expr == null) {
7563 if (i < case_.cases.length - 1) { 7589 if (i < case_.cases.length - 1) {
7564 world.error('default clause must be the last case', case_.get$span()); 7590 world.error('default clause must be the last case', case_.get$span());
7565 } 7591 }
7566 this.writer.writeln('default:'); 7592 this.writer.writeln('default:');
7567 } 7593 }
7568 else { 7594 else {
7569 var value = this.visitValue(expr); 7595 var value = this.visitValue(expr);
7570 this.writer.writeln(('case ' + value.code + ':')); 7596 this.writer.writeln(('case ' + value.code + ':'));
7571 } 7597 }
7572 } 7598 }
7573 this.writer.enterBlock(''); 7599 this.writer.enterBlock('');
7574 var $list0 = case_.statements; 7600 var caseExits = false;
7575 for (var $i0 = case_.statements.iterator(); $i0.hasNext(); ) { 7601 for (var i = 0;
7576 var stmt = $i0.next(); 7602 i < case_.statements.length; i++) {
7577 stmt.visit(this); 7603 var stmt = case_.statements.$index(i);
7604 caseExits = stmt.visit(this);
7605 if ($ne(stmt, case_.statements.$index(case_.statements.length - 1)) && cas eExits) {
7606 world.warning('unreachable code', case_.statements.$index(i + 1).get$spa n());
7607 }
7578 } 7608 }
7579 if ($ne(case_, node.cases.$index(node.cases.length - 1))) { 7609 if ($ne(case_, node.cases.$index(node.cases.length - 1)) && !caseExits) {
7580 var span = case_.statements.$index(case_.statements.length - 1).get$span() ; 7610 var span = case_.statements.$index(case_.statements.length - 1).get$span() ;
7611 this.writer.writeln(('\$throw(new FallThroughError("' + span.file.filename + '",') + (' ' + span.file.getLine(span.start) + '))'));
7581 } 7612 }
7582 this.writer.exitBlock(''); 7613 this.writer.exitBlock('');
7583 this._popBlock(); 7614 this._popBlock();
7584 } 7615 }
7585 this.writer.exitBlock('}'); 7616 this.writer.exitBlock('}');
7617 return false;
7586 } 7618 }
7587 MethodGenerator.prototype.visitBlockStatement = function(node) { 7619 MethodGenerator.prototype.visitBlockStatement = function(node) {
7588 this._pushBlock(false); 7620 this._pushBlock(false);
7589 this.writer.enterBlock('{'); 7621 this.writer.enterBlock('{');
7590 var $list = node.body; 7622 var exits = false;
7591 for (var $i = 0;$i < $list.length; $i++) { 7623 for (var i = 0;
7592 var stmt = $list.$index($i); 7624 i < node.body.length; i++) {
7593 stmt.visit(this); 7625 var stmt = node.body.$index(i);
7626 exits = stmt.visit(this);
7627 if (exits && $ne(stmt, node.body.$index(node.body.length - 1))) {
7628 world.warning('unreachable code', node.body.$index(i + 1).get$span());
7629 }
7594 } 7630 }
7595 this.writer.exitBlock('}'); 7631 this.writer.exitBlock('}');
7596 this._popBlock(); 7632 this._popBlock();
7633 return exits;
7597 } 7634 }
7598 MethodGenerator.prototype.visitLabeledStatement = function(node) { 7635 MethodGenerator.prototype.visitLabeledStatement = function(node) {
7599 this.writer.writeln(('' + node.name.name + ':')); 7636 this.writer.writeln(('' + node.name.name + ':'));
7600 node.body.visit(this); 7637 node.body.visit(this);
7638 return false;
7601 } 7639 }
7602 MethodGenerator.prototype.visitExpressionStatement = function(node) { 7640 MethodGenerator.prototype.visitExpressionStatement = function(node) {
7603 if ((node.body instanceof VarExpression) || (node.body instanceof ThisExpressi on)) { 7641 if ((node.body instanceof VarExpression) || (node.body instanceof ThisExpressi on)) {
7604 world.warning('variable used as statement', node.span); 7642 world.warning('variable used as statement', node.span);
7605 } 7643 }
7606 var value = this.visitVoid(node.body); 7644 var value = this.visitVoid(node.body);
7607 this.writer.writeln(('' + value.code + ';')); 7645 this.writer.writeln(('' + value.code + ';'));
7646 return false;
7608 } 7647 }
7609 MethodGenerator.prototype.visitEmptyStatement = function(node) { 7648 MethodGenerator.prototype.visitEmptyStatement = function(node) {
7610 this.writer.writeln(';'); 7649 this.writer.writeln(';');
7650 return false;
7611 } 7651 }
7612 MethodGenerator.prototype._checkNonStatic = function(node) { 7652 MethodGenerator.prototype._checkNonStatic = function(node) {
7613 if (this.method.get$isStatic()) { 7653 if (this.method.get$isStatic()) {
7614 world.warning('not allowed in static method', node.span); 7654 world.warning('not allowed in static method', node.span);
7615 } 7655 }
7616 } 7656 }
7617 MethodGenerator.prototype._makeSuperValue = function(node) { 7657 MethodGenerator.prototype._makeSuperValue = function(node) {
7618 var parentType = this.method.declaringType.get$parent(); 7658 var parentType = this.method.declaringType.get$parent();
7619 this._checkNonStatic(node); 7659 this._checkNonStatic(node);
7620 if (parentType == null) { 7660 if (parentType == null) {
(...skipping 4461 matching lines...) Expand 10 before | Expand all | Expand 10 after
12082 return new SwitchStatement(test, cases, this._makeSpan(start)); 12122 return new SwitchStatement(test, cases, this._makeSpan(start));
12083 } 12123 }
12084 lang_Parser.prototype._peekCaseEnd = function() { 12124 lang_Parser.prototype._peekCaseEnd = function() {
12085 var kind = this._peek(); 12125 var kind = this._peek();
12086 return $eq(kind, 7/*TokenKind.RBRACE*/) || $eq(kind, 88/*TokenKind.CASE*/) || $eq(kind, 92/*TokenKind.DEFAULT*/); 12126 return $eq(kind, 7/*TokenKind.RBRACE*/) || $eq(kind, 88/*TokenKind.CASE*/) || $eq(kind, 92/*TokenKind.DEFAULT*/);
12087 } 12127 }
12088 lang_Parser.prototype.caseNode = function() { 12128 lang_Parser.prototype.caseNode = function() {
12089 var start = this._peekToken.start; 12129 var start = this._peekToken.start;
12090 var label = null; 12130 var label = null;
12091 if (this._peekIdentifier()) { 12131 if (this._peekIdentifier()) {
12132 label = this.identifier();
12092 this._eat(8/*TokenKind.COLON*/); 12133 this._eat(8/*TokenKind.COLON*/);
12093 label = this.identifier();
12094 } 12134 }
12095 var cases = []; 12135 var cases = [];
12096 while (true) { 12136 while (true) {
12097 if (this._maybeEat(88/*TokenKind.CASE*/)) { 12137 if (this._maybeEat(88/*TokenKind.CASE*/)) {
12098 cases.add(this.expression()); 12138 cases.add(this.expression());
12099 this._eat(8/*TokenKind.COLON*/); 12139 this._eat(8/*TokenKind.COLON*/);
12100 } 12140 }
12101 else if (this._maybeEat(92/*TokenKind.DEFAULT*/)) { 12141 else if (this._maybeEat(92/*TokenKind.DEFAULT*/)) {
12102 cases.add(null); 12142 cases.add(null);
12103 this._eat(8/*TokenKind.COLON*/); 12143 this._eat(8/*TokenKind.COLON*/);
(...skipping 4108 matching lines...) Expand 10 before | Expand all | Expand 10 after
16212 INTERFACE, 16252 INTERFACE,
16213 LIBRARY, 16253 LIBRARY,
16214 NATIVE, 16254 NATIVE,
16215 NEGATE, 16255 NEGATE,
16216 OPERATOR, 16256 OPERATOR,
16217 SET, 16257 SET,
16218 SOURCE, 16258 SOURCE,
16219 STATIC, 16259 STATIC,
16220 TYPEDEF ]*/; 16260 TYPEDEF ]*/;
16221 main(); 16261 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