diff dmd/TypeReturn.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children 5a2059196104
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dmd/TypeReturn.d	Sat Oct 24 08:42:06 2009 +0400
@@ -0,0 +1,91 @@
+module dmd.TypeReturn;
+
+import dmd.Loc;
+import dmd.MOD;
+import dmd.Type;
+import dmd.TypeQualified;
+import dmd.Scope;
+import dmd.Dsymbol;
+import dmd.OutBuffer;
+import dmd.HdrGenState;
+import dmd.TY;
+
+class TypeReturn : TypeQualified
+{
+    this(Loc loc)
+	{
+		super(TY.Treturn, loc);
+	}
+	
+version (DumbClone) {
+} else {
+	Type clone()
+	{
+		assert(false);
+	}
+}
+	
+    Type syntaxCopy()
+	{
+		TypeReturn t = new TypeReturn(loc);
+		t.syntaxCopyHelper(this);
+		t.mod = mod;
+		return t;
+	}
+
+    Dsymbol toDsymbol(Scope sc)
+	{
+		Type *t = semantic(0, sc);
+		if (t == this)
+			return null;
+		return t.toDsymbol(sc);
+	}
+	
+    Type semantic(Loc loc, Scope sc)
+	{
+		Type t;
+		if (!sc.func)
+		{	
+			error(loc, "typeof(return) must be inside function");
+			goto Lerr;
+		}
+		t = sc.func.type.nextOf();
+		t = t.addMod(mod);
+
+		if (idents.dim)
+		{
+			Dsymbol s = t.toDsymbol(sc);
+			for (size_t i = 0; i < idents.dim; i++)
+			{
+				if (!s)
+					break;
+				Identifier id = cast(Identifier)idents.data[i];
+				s = s.searchX(loc, sc, id);
+			}
+			if (s)
+			{
+				t = s.getType();
+				if (!t)
+				{	
+					error(loc, "%s is not a type", s.toChars());
+					goto Lerr;
+				}
+			}
+			else
+			{   
+				error(loc, "cannot resolve .property for %s", toChars());
+				goto Lerr;
+			}
+		}
+
+		return t;
+
+	Lerr:
+		return terror;
+	}
+	
+    void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
+	{
+		assert(false);
+	}
+}
\ No newline at end of file