view dmd/DefaultStatement.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children a8b50ff7f201
line wrap: on
line source

module dmd.DefaultStatement;

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

import dmd.backend.Util;
import dmd.backend.OPER;
import dmd.backend.Blockx;
import dmd.backend.block;
import dmd.backend.BC;

class DefaultStatement : Statement
{
    Statement statement;
version (IN_GCC) {
    block* cblock = null;	// back end: label for the block
}

    this(Loc loc, Statement s)
	{
		super(loc);
		this.statement = s;
	}
	
    Statement syntaxCopy()
	{
		assert(false);
	}
	
    Statement semantic(Scope sc)
	{
		//printf("DefaultStatement.semantic()\n");
		if (sc.sw)
		{
			if (sc.sw.sdefault)
			{
				error("switch statement already has a default");
			}
			sc.sw.sdefault = this;

			if (sc.sw.tf !is sc.tf)
				error("switch and default are in different finally blocks");

			if (sc.sw.isFinal)
				error("default statement not allowed in final switch statement");
		}
		else
			error("default not in switch statement");
		statement = statement.semantic(sc);
		return this;
	}
	
    bool usesEH()
	{
		assert(false);
	}
	
    BE blockExit()
	{
		return statement.blockExit();
	}
	
    bool comeFrom()
	{
		return true;
	}
	
    Expression interpret(InterState* istate)
	{
		assert(false);
	}
	
    void toCBuffer(OutBuffer buf, HdrGenState* hgs)
	{
		assert(false);
	}

    Statement inlineScan(InlineScanState* iss)
	{
		if (statement)
			statement = statement.inlineScan(iss);
		return this;
	}

    void toIR(IRState* irs)
	{
		Blockx* blx = irs.blx;
		block* bcase = blx.curblock;
		block* bdefault = irs.getDefaultBlock();
		block_next(blx,BCgoto,bdefault);
		list_append(&bcase.Bsucc,blx.curblock);
		if (blx.tryblock != irs.getSwitchBlock().Btry)
			error("default cannot be in different try block level from switch");
		incUsage(irs, loc);
		if (statement)
			statement.toIR(irs);
	}
}