view dmd/ShrExp.d @ 32:81796b717a39

A few bad cast fixed. TODO: either get rid of dyncast(), or derive all objects from intermediate supertype.
author korDen
date Tue, 18 May 2010 17:51:46 +0400
parents 10317f0c89a5
children cab4c37afb89
line wrap: on
line source

module dmd.ShrExp;

import dmd.Expression;
import dmd.Identifier;
import dmd.InterState;
import dmd.Loc;
import dmd.Scope;
import dmd.IntRange;
import dmd.IRState;
import dmd.BinExp;
import dmd.TOK;
import dmd.Type;
import dmd.Id;

import dmd.backend.elem;
import dmd.backend.OPER;

import dmd.expression.shift_optimize;
import dmd.expression.Shr;

class ShrExp : BinExp
{
	this(Loc loc, Expression e1, Expression e2)
	{
		super(loc, TOK.TOKshr, ShrExp.sizeof, e1, e2);
	}

	Expression semantic(Scope sc)
	{
		Expression e;

		if (!type)
		{	
			BinExp.semanticp(sc);
			e = op_overload(sc);
			
			if (e)
				return e;

			e1 = e1.checkIntegral();
			e2 = e2.checkIntegral();
			e1 = e1.integralPromotions(sc);
			e2 = e2.castTo(sc, Type.tshiftcnt);
			type = e1.type;
		}
		return this;
	}

	Expression optimize(int result)
	{
		//printf("ShrExp::optimize(result = %d) %s\n", result, toChars());
		return shift_optimize(result, this, &Shr);
	}

	Expression interpret(InterState* istate)
	{
		assert(false);
	}

	IntRange getIntRange()
	{
		assert(false);
	}

	Identifier opId()
	{
		return Id.shr;
	}

	Identifier opId_r()
	{
		return Id.shr_r;
	}

	elem* toElem(IRState* irs)
	{
		return toElemBin(irs, OPER.OPshr);
	}
}