diff dmd/NewExp.d @ 174:af724d3510d7

lot os toCBuffer methods implemented moved shared Type.* stuff into Global
author korDen
date Sun, 10 Oct 2010 03:47:23 +0400
parents 60bb0fe4563e
children e3afd1303184
line wrap: on
line diff
--- a/dmd/NewExp.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/NewExp.d	Sun Oct 10 03:47:23 2010 +0400
@@ -7,6 +7,7 @@
 import dmd.ClassDeclaration;
 import dmd.Type;
 import dmd.OutBuffer;
+import dmd.PREC;
 import dmd.Loc;
 import dmd.Scope;
 import dmd.IRState;
@@ -92,7 +93,7 @@
 
 	Lagain:
 		if (thisexp)
-		{	
+		{
 			thisexp = thisexp.semantic(sc);
 			cdthis = thisexp.type.isClassHandle();
 			if (cdthis)
@@ -122,7 +123,7 @@
 			error("e.new is only for allocating nested classes, not %s", tb.toChars());
 
 		if (tb.ty == Tclass)
-		{	
+		{
 			TypeFunction tf;
 
 			TypeClass tc = cast(TypeClass)tb;
@@ -130,10 +131,10 @@
 			if (cd.isInterfaceDeclaration())
 				error("cannot create instance of interface %s", cd.toChars());
 			else if (cd.isAbstract())
-			{   
+			{
 				error("cannot create instance of abstract class %s", cd.toChars());
 				for (int j = 0; j < cd.vtbl.dim; j++)
-				{	
+				{
 					FuncDeclaration fd = (cast(Dsymbol)cd.vtbl.data[j]).isFuncDeclaration();
 					if (fd && fd.isAbstract())
 						error("function %s is abstract", fd.toChars());
@@ -156,7 +157,7 @@
 						// Supply an implicit 'this' and try again
 						thisexp = new ThisExp(loc);
 						for (Dsymbol sp = sc.parent; 1; sp = sp.parent)
-						{	
+						{
 							if (!sp)
 							{
 								error("outer class %s 'this' needed to 'new' nested class %s", cdn.toChars(), cd.toChars());
@@ -217,7 +218,7 @@
 				}
 	///} else {
 	///			else if (fdn)
-	///			{	
+	///			{
 	///				/* The nested class cd is nested inside a function,
 	///				 * we'll let getEthis() look for errors.
 	///				 */
@@ -342,7 +343,7 @@
 			for (size_t j = 0; j < arguments.dim; j++)
 			{
 				if (tb.ty != Tarray)
-				{	
+				{
 					error("too many arguments for array");
 					arguments.dim = i;
 					break;
@@ -386,7 +387,7 @@
 		if (newargs)
 		{
 			foreach (ref Expression e; newargs)
-			{   
+			{
 				e = e.optimize(WANTvalue);
 			}
 		}
@@ -394,7 +395,7 @@
 		if (arguments)
 		{
 			foreach (ref Expression e; arguments)
-			{   
+			{
 				e = e.optimize(WANTvalue);
 			}
 		}
@@ -432,7 +433,7 @@
 			elem *ez = null;
 
 			if (allocator || onstack)
-			{   
+			{
 				elem *ei;
 				Symbol *si;
 
@@ -501,7 +502,7 @@
 			}
 
 			if (thisexp)
-			{   
+			{
 				ClassDeclaration cdthis = thisexp.type.isClassHandle();
 				assert(cdthis);
 				//printf("cd = %s\n", cd.toChars());
@@ -515,7 +516,7 @@
 				//printf("cdp = %s\n", cdp.toChars());
 				//printf("cdthis = %s\n", cdthis.toChars());
 				if (cdp != cdthis)
-				{	
+				{
 					int i = cdp.isClassDeclaration().isBaseOf(cdthis, &offset);
 					assert(i);
 				}
@@ -538,7 +539,7 @@
 				//printf("ez: "); elem_print(ez);
 			}
 			else if (cd.isNested())
-			{   
+			{
 				/* Initialize cd.vthis:
 				 *	*(ey + cd.vthis.offset) = this;
 				 */
@@ -572,7 +573,7 @@
 			elem* ez = null;
 
 			if (allocator)
-			{   
+			{
 				elem *ei;
 				Symbol *si;
 
@@ -592,7 +593,7 @@
 					ez = el_same(&ex);
 
 				if (!member)
-				{	
+				{
 					/* Statically intialize with default initializer
 					 */
 					ex = el_una(OPind, TYstruct, ex);
@@ -633,7 +634,7 @@
 			}
 
 			if (cd.isNested())
-			{   
+			{
 				/* Initialize cd.vthis:
 				 *	*(ey + cd.vthis.offset) = this;
 				 */
@@ -641,7 +642,7 @@
 			}
 
 			if (member)
-			{   
+			{
 				// Call constructor
 				ez = callfunc(loc, irs, 1, type, ez, ectype, member, member.type, null, arguments);
 		version (STRUCTTHISREF) {
@@ -661,7 +662,7 @@
 
 			assert(arguments && arguments.dim >= 1);
 			if (arguments.dim == 1)
-			{   
+			{
 				// Single dimension array allocations
 				auto arg = arguments[0];	// gives array length
 				e = arg.toElem(irs);
@@ -673,7 +674,7 @@
 				e = el_bin(OPcall,TYdarray,el_var(rtlsym[rtl]),e);
 			}
 			else
-			{   
+			{
 				// Multidimensional array allocations
 				e = el_long(TYint, arguments.dim);
 				foreach (Expression arg; arguments)
@@ -725,7 +726,27 @@
 
 	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		int i;
+
+		if (thisexp)
+		{
+			expToCBuffer(buf, hgs, thisexp, PREC.PREC_primary);
+			buf.writeByte('.');
+		}
+		buf.writestring("new ");
+		if (newargs && newargs.dim)
+		{
+			buf.writeByte('(');
+			argsToCBuffer(buf, newargs, hgs);
+			buf.writeByte(')');
+		}
+		newtype.toCBuffer(buf, null, hgs);
+		if (arguments && arguments.dim)
+		{
+			buf.writeByte('(');
+			argsToCBuffer(buf, arguments, hgs);
+			buf.writeByte(')');
+		}
 	}
 
 	override void scanForNestedRef(Scope sc)
@@ -744,7 +765,7 @@
 		return 1;
 	}
 }
-	
+
 	//int inlineCost(InlineCostState *ics);
 
 	override Expression doInline(InlineDoState ids)
@@ -758,7 +779,7 @@
 		ne.arguments = arrayExpressiondoInline(ne.arguments, ids);
 		return ne;
 	}
-	
+
 	//Expression inlineScan(InlineScanState *iss);
 }