view dmd/GotoCaseStatement.d @ 64:4290d870944a

More fixes
author korDen
date Mon, 23 Aug 2010 20:29:15 +0400
parents cab4c37afb89
children 2e2a5c3f943a
line wrap: on
line source

module dmd.GotoCaseStatement;

import dmd.Statement;
import dmd.Expression;
import dmd.CaseStatement;
import dmd.IRState;
import dmd.Scope;
import dmd.Loc;
import dmd.InterState;
import dmd.OutBuffer;
import dmd.HdrGenState;
import dmd.BE;
import dmd.WANT;

class GotoCaseStatement : Statement
{
    Expression exp;		// NULL, or which case to goto
    CaseStatement cs;		// case statement it resolves to

    this(Loc loc, Expression exp)
	{
		super(loc);
		cs = null;
		this.exp = exp;
	}
	
    Statement syntaxCopy()
	{
		Expression e = exp ? exp.syntaxCopy() : null;
		GotoCaseStatement s = new GotoCaseStatement(loc, e);
		return s;
	}
	
    Statement semantic(Scope sc)
	{
		if (exp)
			exp = exp.semantic(sc);

		if (!sc.sw)
			error("goto case not in switch statement");
		else
		{
			sc.sw.gotoCases.push(cast(void*)this);
			if (exp)
			{
				exp = exp.implicitCastTo(sc, sc.sw.condition.type);
				exp = exp.optimize(WANTvalue);
			}
		}
		return this;
	}
	
    Expression interpret(InterState istate)
	{
		assert(false);
	}
	
    BE blockExit()
	{
		return BEgoto;
	}
	
    void toCBuffer(OutBuffer buf, HdrGenState* hgs)
	{
		buf.writestring("goto case");
		if (exp)
		{   
			buf.writebyte(' ');
			exp.toCBuffer(buf, hgs);
		}
		buf.writebyte(';');
		buf.writenl();
	}

    void toIR(IRState* irs)
	{
		assert(false);
	}
}