view dmd/PostExp.d @ 130:60bb0fe4563e

dmdfe 2.037 first main iteration
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Thu, 09 Sep 2010 22:51:44 +0100
parents e28b18c23469
children af724d3510d7
line wrap: on
line source

module dmd.PostExp;

import dmd.common;
import dmd.Expression;
import dmd.Identifier;
import dmd.backend.elem;
import dmd.InterState;
import dmd.OutBuffer;
import dmd.Loc;
import dmd.Scope;
import dmd.IRState;
import dmd.BinExp;
import dmd.HdrGenState;
import dmd.IntegerExp;
import dmd.TOK;
import dmd.Type;
import dmd.TY;
import dmd.Id;

import dmd.backend.Util;
import dmd.backend.OPER;

class PostExp : BinExp
{
	this(TOK op, Loc loc, Expression e)
	{
		super(loc, op, PostExp.sizeof, e, new IntegerExp(loc, 1, Type.tint32));
	}

	override Expression semantic(Scope sc)
	{
		Expression e = this;

		if (!type)
		{
			BinExp.semantic(sc);
			e2 = resolveProperties(sc, e2);

			e = op_overload(sc);
			if (e)
				return e;

			e = this;
			e1 = e1.modifiableLvalue(sc, e1);
			e1.checkScalar();
			e1.checkNoBool();
			if (e1.type.ty == Tpointer)
				e = scaleFactor(sc);
			else
				e2 = e2.castTo(sc, e1.type);
			e.type = e1.type;
		}
		return e;
	}

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

	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
	{
		assert(false);
	}

	override Identifier opId()
	{
		return (op == TOKplusplus) ? Id.postinc : Id.postdec;
	}

	override elem* toElem(IRState* irs)
	{
		auto e = e1.toElem(irs);
		auto einc = e2.toElem(irs);
		e = el_bin((op == TOKplusplus) ? OPpostinc : OPpostdec,
			e.Ety,e,einc);
		el_setLoc(e,loc);
		return e;
	}
}