|
1 | 1 | var Class = require("./Class");
|
2 |
| -eval(Class.$import("./expression.js")); |
3 |
| -eval(Class.$import("./util.js")); |
| 2 | +eval(Class.$import("./expression")); |
| 3 | +eval(Class.$import("./type")); |
| 4 | +eval(Class.$import("./util")); |
4 | 5 |
|
5 | 6 | "use strict";
|
6 | 7 |
|
@@ -491,47 +492,75 @@ var TryStatement = exports.TryStatement = Statement.extend({
|
491 | 492 |
|
492 | 493 | var InformationStatement = exports.InformationStatement = Statement.extend({
|
493 | 494 |
|
494 |
| - initialize: function (exprs) { |
| 495 | + initialize: function (token, exprs) { |
| 496 | + this._token = token; |
495 | 497 | this._exprs = exprs;
|
496 | 498 | },
|
497 | 499 |
|
| 500 | + getToken: function () { |
| 501 | + return this._token; |
| 502 | + }, |
| 503 | + |
498 | 504 | getExprs: function () {
|
499 | 505 | return this._exprs;
|
500 | 506 | },
|
501 | 507 |
|
502 |
| - analyze: function (context) { |
| 508 | + _analyzeExprs: function (context) { |
503 | 509 | for (var i = 0; i < this._exprs.length; ++i)
|
504 |
| - this._exprs[i].analyze(context); |
| 510 | + if (! this._exprs[i].analyze(context)) |
| 511 | + return false; |
| 512 | + return true; |
505 | 513 | }
|
506 | 514 |
|
507 | 515 | });
|
508 | 516 |
|
509 | 517 | var AssertStatement = exports.AssertStatement = InformationStatement.extend({
|
510 | 518 |
|
511 |
| - initialize: function (exprs) { |
512 |
| - InformationStatement.prototype.initialize.call(this, exprs); |
| 519 | + initialize: function (token, exprs) { |
| 520 | + InformationStatement.prototype.initialize.call(this, token, exprs); |
513 | 521 | },
|
514 | 522 |
|
515 | 523 | serialize: function () {
|
516 | 524 | return [
|
517 | 525 | "AssertStatement",
|
518 | 526 | Util.serializeArray(this._exprs)
|
519 | 527 | ];
|
| 528 | + }, |
| 529 | + |
| 530 | + analyze: function (context) { |
| 531 | + if (! this._analyzeExprs(context)) |
| 532 | + return; |
| 533 | + var exprType = this._exprs[this._exprs.length - 1].getType(); |
| 534 | + if (exprType.equals(Type.voidType)) |
| 535 | + context.errors.push(new CompileError(this._token, "cannot assert type void")); |
| 536 | + else if (exprType.equals(Type.nullType)) |
| 537 | + context.errors.push(new CompileError(this._token, "assertion never succeeds")); |
520 | 538 | }
|
521 | 539 |
|
522 | 540 | });
|
523 | 541 |
|
524 | 542 | var LogStatement = exports.LogStatement = InformationStatement.extend({
|
525 | 543 |
|
526 |
| - initialize: function (exprs) { |
527 |
| - InformationStatement.prototype.initialize.call(this, exprs); |
| 544 | + initialize: function (token, exprs) { |
| 545 | + InformationStatement.prototype.initialize.call(this, token, exprs); |
528 | 546 | },
|
529 | 547 |
|
530 | 548 | serialize: function () {
|
531 | 549 | return [
|
532 | 550 | "LogStatement",
|
533 | 551 | Util.serializeArray(this._exprs)
|
534 | 552 | ];
|
| 553 | + }, |
| 554 | + |
| 555 | + analyze: function (context) { |
| 556 | + if (! this._analyzeExprs(context)) |
| 557 | + return; |
| 558 | + for (var i = 0; i < this._exprs.length; ++i) { |
| 559 | + if (this._exprs[i].getType().equals(Type.voidType)) { |
| 560 | + context.errors.push(new CompileError(this._token, "cannot log a void expression")); |
| 561 | + break; |
| 562 | + } |
| 563 | + } |
535 | 564 | }
|
536 | 565 |
|
537 | 566 | });
|
0 commit comments