view dmd/AndExp.d @ 12:832f71e6f96c

*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete) Some unittest-specific functions implemented
author korDen
date Mon, 12 Apr 2010 15:13:00 +0400
parents 10317f0c89a5
children a8b50ff7f201
line wrap: on
line source

module dmd.AndExp;

import dmd.Expression;
import dmd.Identifier;
import dmd.InterState;
import dmd.OutBuffer;
import dmd.Loc;
import dmd.Scope;
import dmd.IntRange;
import dmd.IRState;
import dmd.BinExp;
import dmd.TOK;
import dmd.ArrayTypes;
import dmd.TY;
import dmd.Type;
import dmd.Id;
import dmd.Global;

import dmd.backend.elem;
import dmd.backend.Util;
import dmd.backend.OPER;
import dmd.expression.Util;
import dmd.expression.And;

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

	Expression semantic(Scope sc)
	{
		Expression e;

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

			if (e)
				return e;

			if (e1.type.toBasetype().ty == TY.Tbool && e2.type.toBasetype().ty == TY.Tbool)
			{
				type = e1.type;
				e = this;
			}
			else
			{
				typeCombine(sc);
				if (e1.op != TOK.TOKslice && e2.op != TOK.TOKslice)
				{   
					e1.checkIntegral();
					e2.checkIntegral();
				}
			}
		}
		return this;
	}

	Expression optimize(int result)
	{
		Expression e;

		e1 = e1.optimize(result);
		e2 = e2.optimize(result);
		if (e1.isConst() == 1 && e2.isConst() == 1)
			e = And(type, e1, e2);
		else
			e = this;

		return e;
	}

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

	void buildArrayIdent(OutBuffer buf, Expressions arguments)
	{
		Exp_buildArrayIdent(buf, arguments, "And");
	}

	Expression buildArrayLoop(Arguments fparams)
	{
		/* Evaluate assign expressions left to right		
		 */								
		Expression ex1 = e1.buildArrayLoop(fparams);		
		Expression ex2 = e2.buildArrayLoop(fparams);		
		Expression e = new AndExp(Loc(0), ex1, ex2);			
		return e;							
	}

	IntRange getIntRange()
	{
		assert(false);
	}

	bool isCommutative()
	{
		return true;
	}

	Identifier opId()
	{
		return Id.iand;
	}

	Identifier opId_r()
	{
		return Id.iand_r;
	}

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