diff dmd/TypeidExp.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 206db751bd4c
line wrap: on
line diff
--- a/dmd/TypeidExp.d	Sun Sep 05 15:32:22 2010 +0400
+++ b/dmd/TypeidExp.d	Thu Sep 09 22:51:44 2010 +0100
@@ -11,12 +11,12 @@
 
 class TypeidExp : Expression
 {
-	Type typeidType;
+	Object *obj;
 
-	this(Loc loc, Type typeidType)
+	this(Loc loc, Object o)
 	{
 		super(loc, TOK.TOKtypeid, TypeidExp.sizeof);
-		this.typeidType = typeidType;
+		this.obj = o;
 	}
 
 version (DumbClone) {
@@ -28,7 +28,7 @@
 }
 	override Expression syntaxCopy()
 	{
-		return new TypeidExp(loc, typeidType.syntaxCopy());
+		return new TypeidExp(loc, objectSyntaxCopy(obj));
 	}
 
 	override Expression semantic(Scope sc)
@@ -38,10 +38,46 @@
 	version (LOGSEMANTIC) {
 		printf("TypeidExp.semantic()\n");
 	}
-		typeidType = typeidType.semantic(loc, sc);
-		e = typeidType.getTypeInfo(sc);
-		if (e.loc.linnum == 0)
-			e.loc = loc;		// so there's at least some line number info
+		Type ta = isType(obj);
+		Expression ea = isExpression(obj);
+		Dsymbol sa = isDsymbol(obj);
+
+		if (ta)
+		{
+			ta.resolve(loc, sc, &ea, &ta, &sa);
+		}
+		if (ea)
+		{
+			ea = ea.semantic(sc);
+			ea = resolveProperties(sc, ea);
+			ta = ea.type;
+			if (ea.op == TOKtype)
+				ea = null;
+		}
+
+		if (!ta)
+		{	error("no type for typeid(%s)", ea ? ea.toChars() : (sa ? sa.toChars() : ""));
+			return new ErrorExp();
+		}
+
+		if (ea && ta.toBasetype().ty == Tclass)
+		{   /* Get the dynamic type, which is .classinfo
+		 */
+			e = new DotIdExp(ea.loc, ea, Id.classinfo);
+			e = e.semantic(sc);
+		}
+		else
+		{	/* Get the static type
+		 */
+			e = ta.getTypeInfo(sc);
+			if (e.loc.linnum == 0)
+				e.loc = loc;		// so there's at least some line number info
+			if (ea)
+			{
+				e = new CommaExp(loc, ea, e);	// execute ea
+				e = e.semantic(sc);
+			}
+		}
 		return e;
 	}