view dmd/InExp.d @ 61:4ae0d790a452

OnScopeStatement.syntaxCopy PtrExp.isLvalue InExp.opId
author korDen
date Mon, 23 Aug 2010 03:01:24 +0400
parents d42cd5917df4
children 6557375aff35
line wrap: on
line source

module dmd.InExp;

import dmd.Expression;
import dmd.Identifier;
import dmd.Loc;
import dmd.Scope;
import dmd.IRState;
import dmd.BinExp;
import dmd.TOK;
import dmd.Type;
import dmd.Id;
import dmd.TY;
import dmd.TypeAArray;

import dmd.expression.util.arrayTypeCompatible;

import dmd.backend.elem;

class InExp : BinExp
{
	this(Loc loc, Expression e1, Expression e2)
	{
		super(loc, TOKin, InExp.sizeof, e1, e2);
	}

	Expression semantic(Scope sc)
	{
		if (type)
			return this;

		super.semanticp(sc);

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

		//type = Type.tboolean;
		Type t2b = e2.type.toBasetype();
		if (t2b.ty != TY.Taarray)
		{
			error("rvalue of in expression must be an associative array, not %s", e2.type.toChars());
			type = Type.terror;
		}
		else
		{
			TypeAArray ta = cast(TypeAArray)t2b;

			// Special handling for array keys
			if (!arrayTypeCompatible(e1.loc, e1.type, ta.index))
			{
				// Convert key to type of key
				e1 = e1.implicitCastTo(sc, ta.index);
			}

			// Return type is pointer to value
			type = ta.nextOf().pointerTo();
		}
		return this;
	}

	int isBit()
	{
		return 0;
	}

	Identifier opId()
	{
		return Id.opIn;
	}

	Identifier opId_r()
	{
		assert(false);
	}

	elem* toElem(IRState* irs)
	{
		assert(false);
	}
}