diff dmd/ArrayExp.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children 1628b221808d
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dmd/ArrayExp.d	Sat Oct 24 08:42:06 2009 +0400
@@ -0,0 +1,132 @@
+module dmd.ArrayExp;
+
+import dmd.Expression;
+import dmd.Identifier;
+import dmd.UnaExp;
+import dmd.OutBuffer;
+import dmd.Loc;
+import dmd.Scope;
+import dmd.InlineCostState;
+import dmd.InlineDoState;
+import dmd.HdrGenState;
+import dmd.InlineScanState;
+import dmd.ArrayTypes;
+import dmd.TOK;
+import dmd.Type;
+import dmd.TY;
+import dmd.Id;
+import dmd.IndexExp;
+
+import dmd.expression.Util;
+
+class ArrayExp : UnaExp
+{
+	Expressions arguments;
+
+	this(Loc loc, Expression e1, Expressions args)
+	{
+		super(loc, TOK.TOKarray, ArrayExp.sizeof, e1);
+		arguments = args;
+	}
+
+	Expression syntaxCopy()
+	{
+		assert(false);
+	}
+
+	Expression semantic(Scope sc)
+	{
+		Expression e;
+		Type t1;
+
+	version (LOGSEMANTIC) {
+		printf("ArrayExp::semantic('%s')\n", toChars());
+	}
+		UnaExp.semantic(sc);
+		e1 = resolveProperties(sc, e1);
+
+		t1 = e1.type.toBasetype();
+		if (t1.ty != Tclass && t1.ty != Tstruct)
+		{	
+			// Convert to IndexExp
+			if (arguments.dim != 1)
+				error("only one index allowed to index %s", t1.toChars());
+			e = new IndexExp(loc, e1, cast(Expression)arguments.data[0]);
+			return e.semantic(sc);
+		}
+
+		// Run semantic() on each argument
+		for (size_t i = 0; i < arguments.dim; i++)
+		{	
+			e = cast(Expression)arguments.data[i];
+
+			e = e.semantic(sc);
+			if (!e.type)
+				error("%s has no value", e.toChars());
+			arguments.data[i] = cast(void*)e;
+		}
+
+		expandTuples(arguments);
+		assert(arguments && arguments.dim);
+
+		e = op_overload(sc);
+		if (!e)
+		{
+			error("no [] operator overload for type %s", e1.type.toChars());
+			e = e1;
+		}
+		return e;
+	}
+
+	int isLvalue()
+	{
+		assert(false);
+	}
+
+	Expression toLvalue(Scope sc, Expression e)
+	{
+		assert(false);
+	}
+
+	void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+	{
+		assert(false);
+	}
+
+	void scanForNestedRef(Scope sc)
+	{
+		assert(false);
+	}
+
+	Identifier opId()
+	{
+		return Id.index;
+	}
+
+	int inlineCost(InlineCostState* ics)
+	{
+		return 1 + e1.inlineCost(ics) + arrayInlineCost(ics, arguments);
+	}
+
+	Expression doInline(InlineDoState ids)
+	{
+		ArrayExp ce;
+
+		ce = cast(ArrayExp)copy();
+		ce.e1 = e1.doInline(ids);
+		ce.arguments = arrayExpressiondoInline(arguments, ids);
+		return ce;
+	}
+
+	Expression inlineScan(InlineScanState* iss)
+	{
+		Expression e = this;
+
+		//printf("ArrayExp.inlineScan()\n");
+		e1 = e1.inlineScan(iss);
+		arrayInlineScan(iss, arguments);
+
+		return e;
+	}
+}
+