All Downloads are FREE. Search and download functionalities are using the official Maven repository.

js.prompto.statement.SwitchStatement.js Maven / Gradle / Ivy

var BaseSwitchStatement = require("./BaseSwitchStatement").BaseSwitchStatement;

function SwitchStatement(expression, switchCases, defaultCase) {
	BaseSwitchStatement.call(this, switchCases, defaultCase);
	this.expression = expression;
}

SwitchStatement.prototype = Object.create(BaseSwitchStatement.prototype);
SwitchStatement.prototype.constructor = SwitchStatement;

SwitchStatement.prototype.checkSwitchType = function(context) {
	return this.expression.check(context);
};

SwitchStatement.prototype.interpret = function(context) {
	var switchValue = this.expression.interpret(context);
	return this.interpretSwitch(context,switchValue,null);
};

SwitchStatement.prototype.toODialect = function(writer) {
    writer.append("switch(");
    this.expression.toDialect(writer);
    writer.append(") {\n");
    this.switchCases.forEach(function(switchCase) {
        switchCase.caseToODialect(writer);
    });
    if(this.defaultCase!=null) {
        writer.append("default:\n");
        writer.indent();
        this.defaultCase.toDialect(writer);
        writer.dedent();
    }
    writer.append("}\n");
}

SwitchStatement.prototype.toEDialect = function(writer) {
    writer.append("switch on ");
    this.expression.toDialect(writer);
    writer.append(":\n");
    writer.indent();
    this.switchCases.forEach(function(switchCase) {
        switchCase.caseToEDialect(writer);
    });
    if(this.defaultCase!=null) {
        writer.append("otherwise:\n");
        writer.indent();
        this.defaultCase.toDialect(writer);
        writer.dedent();
    }
    writer.dedent();
}

SwitchStatement.prototype.toMDialect = function(writer) {
    writer.append("switch on ");
    this.expression.toDialect(writer);
    writer.append(":\n");
    writer.indent();
    this.switchCases.forEach(function(switchCase) {
        switchCase.caseToPDialect(writer);
    });
    if(this.defaultCase!=null) {
        writer.append("otherwise:\n");
        writer.indent();
        this.defaultCase.toDialect(writer);
        writer.dedent();
    }
    writer.dedent();
};

exports.SwitchStatement = SwitchStatement;




© 2015 - 2025 Weber Informatics LLC | Privacy Policy