view dmd/expression/Identity.d @ 191:52188e7e3fb5

Fixed deprecated features, now compiles with DMD2.058 Also changed Array allocation policy: Now doesn't reallocate but malloc's, followed by a memcpy (no free). (this fixes a crash while compiling druntime. Same bug in dmd)
author korDen@korDen-pc
date Sun, 25 Mar 2012 03:11:12 +0400
parents e28b18c23469
children
line wrap: on
line source

module dmd.expression.Identity;

import dmd.common;
import dmd.Expression;
import dmd.Type;
import dmd.TOK;
import dmd.Loc;
import dmd.SymOffExp;
import dmd.IntegerExp;

import dmd.expression.Equal;

Expression Identity(TOK op, Type type, Expression e1, Expression e2)
{   
	Expression e;
    Loc loc = e1.loc;
    int cmp;

    if (e1.op == TOK.TOKnull)
    {
		cmp = (e2.op == TOK.TOKnull);
    }
    else if (e2.op == TOK.TOKnull)
    {
		cmp = 0;
    }
    else if (e1.op == TOK.TOKsymoff && e2.op == TOK.TOKsymoff)
    {
		SymOffExp es1 = cast(SymOffExp)e1;
		SymOffExp es2 = cast(SymOffExp)e2;

		cmp = (es1.var == es2.var && es1.offset == es2.offset);
    }
    else if (e1.isConst() == 1 && e2.isConst() == 1)
		return Equal((op == TOK.TOKidentity) ? TOK.TOKequal : TOK.TOKnotequal, type, e1, e2);
    else
		assert(0);

    if (op == TOK.TOKnotidentity)
		cmp ^= 1;

    return new IntegerExp(loc, cmp, type);
}