view dmd/BoolExp.d @ 187:b0d41ff5e0df

Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author Abscissa
date Tue, 07 Jun 2011 23:37:34 -0400
parents e3afd1303184
children 52188e7e3fb5
line wrap: on
line source

module dmd.BoolExp;

import dmd.common;
import dmd.Expression;
import dmd.backend.elem;
import dmd.UnaExp;
import dmd.InterState;
import dmd.Type;
import dmd.Loc;
import dmd.Scope;
import dmd.IRState;
import dmd.TOK;

import dmd.expression.Bool;
import dmd.backend.OPER;
import dmd.backend.Util;

import dmd.DDMDExtensions;

class BoolExp : UnaExp
{
	mixin insertMemberExtension!(typeof(this));

	this(Loc loc, Expression e, Type t)
	{
		register();

		super(loc, TOKtobool, BoolExp.sizeof, e);
		type = t;
	}

	override Expression semantic(Scope sc)
	{
		super.semantic(sc);
		e1 = resolveProperties(sc, e1);
		e1 = e1.checkToBoolean();
		type = Type.tboolean;
		return this;
	}

	override Expression optimize(int result)
	{
		Expression e;

	    e1 = e1.optimize(result);
	    if (e1.isConst() == 1)
	    {
	        e = Bool(type, e1);
	    }
	    else
	        e = this;
	    return e;
	}

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

	override int isBit()
	{
		return true;
	}

	override elem* toElem(IRState* irs)
	{
		elem* e1 = this.e1.toElem(irs);
		return el_una(OPbool,type.totym(),e1);
	}
}