diff dmd/TemplateInstance.d @ 20:1628b221808d

Fleshed out more unimplemented methods.
author Robert Clipsham <robert@octarineparrot.com>
date Wed, 07 Apr 2010 00:29:13 +0100
parents 10317f0c89a5
children 460959608115
line wrap: on
line diff
--- a/dmd/TemplateInstance.d	Tue Apr 06 02:21:04 2010 +0100
+++ b/dmd/TemplateInstance.d	Wed Apr 07 00:29:13 2010 +0100
@@ -36,6 +36,7 @@
 import dmd.FuncExp;
 import dmd.Declaration;
 import dmd.MATCH;
+import dmd.templates.Util;
 
 import dmd.backend.glue;
 
@@ -229,12 +230,31 @@
 
     static Objects arraySyntaxCopy(Objects objs)
 	{
-		assert(false);
+	    Objects a = null;
+	    if (objs)
+	    {	a = new Objects();
+		a.setDim(objs.dim);
+		for (size_t i = 0; i < objs.dim; i++)
+		{
+		    a.data[i] = cast(void*)objectSyntaxCopy(cast(Object)objs.data[i]);
+		}
+	    }
+	    return a;
 	}
 
-    Dsymbol syntaxCopy(Dsymbol)
+    Dsymbol syntaxCopy(Dsymbol s)
 	{
-		assert(false);
+	    TemplateInstance ti;
+
+	    if (s)
+		ti = cast(TemplateInstance)s;
+	    else
+		ti = new TemplateInstance(loc, name);
+
+	    ti.tiargs = arraySyntaxCopy(tiargs);
+
+	    ScopeDsymbol.syntaxCopy(ti);
+	    return ti;
 	}
 
     void semantic(Scope sc)
@@ -527,7 +547,7 @@
 			}
 			--nest;
 		}
-		catch
+		catch (Exception e)
 		{
 			global.gag = 0;			// ensure error message gets printed
 			error("recursive expansion");
@@ -596,7 +616,7 @@
 
 		semanticRun = 2;
 	version (LOG) {
-		printf("+TemplateInstance::semantic2('%s')\n", toChars());
+		printf("+TemplateInstance.semantic2('%s')\n", toChars());
 	}
 
 		if (!errors && members)
@@ -621,7 +641,7 @@
 		}
 
 	version (LOG) {
-		printf("-TemplateInstance::semantic2('%s')\n", toChars());
+		printf("-TemplateInstance.semantic2('%s')\n", toChars());
 	}
 	}
 
@@ -693,7 +713,7 @@
     Dsymbol toAlias()			// resolve real symbol
 	{
 	version (LOG) {
-		printf("TemplateInstance::toAlias()\n");
+		printf("TemplateInstance.toAlias()\n");
 	}
 		if (!inst)
 		{	
@@ -714,12 +734,13 @@
 	
     string kind()
 	{
-		assert(false);
+	    return "template instance";
 	}
 	
     bool oneMember(Dsymbol* ps)
 	{
-		assert(false);
+	    *ps = null;
+	    return true;
 	}
 	
     string toChars()
@@ -733,12 +754,36 @@
 	
     string mangle()
 	{
-		assert(false);
+	    OutBuffer buf = new OutBuffer();
+	    string id;
+
+	static if (0) {
+	    printf("TemplateInstance.mangle() %s", toChars());
+	    if (parent)
+		printf("  parent = %s %s", parent.kind(), parent.toChars());
+	    printf("\n");
+	}
+	    id = ident ? ident.toChars() : toChars();
+	    if (!tempdecl)
+		error("is not defined");
+	    else if (tempdecl.parent)
+	    {
+		string p = tempdecl.parent.mangle();
+		if (p[0] == '_' && p[1] == 'D')
+		    p = p[2..$];
+		buf.writestring(p);
+	    }
+	    buf.printf("%d%s", id.length, id);
+	    id = buf.toChars();
+	    buf.data = null;
+	    //printf("TemplateInstance.mangle() %s = %s\n", toChars(), id);
+	    return id;
 	}
 	
     void printInstantiationTrace()
 	{
-		assert(false);
+	    if (global.gag)
+		return;
 	}
 
     void toObjFile(int multiobj)			// compile to .obj file
@@ -1159,7 +1204,7 @@
 	 */
     void declareParameters(Scope sc)
 	{
-		//printf("TemplateInstance::declareParameters()\n");
+		//printf("TemplateInstance.declareParameters()\n");
 		for (int i = 0; i < tdtypes.dim; i++)
 		{
 			TemplateParameter tp = cast(TemplateParameter)tempdecl.parameters.data[i];
@@ -1178,7 +1223,7 @@
     bool hasNestedArgs(Objects args)
 	{
 		bool nested = false;
-		//printf("TemplateInstance::hasNestedArgs('%s')\n", tempdecl.ident.toChars());
+		//printf("TemplateInstance.hasNestedArgs('%s')\n", tempdecl.ident.toChars());
 
 		/* A nested instance happens when an argument references a local
 		 * symbol that is on the stack.
@@ -1274,7 +1319,7 @@
 		string id;
 		Objects args;
 
-		//printf("TemplateInstance::genIdent('%s')\n", tempdecl.ident.toChars());
+		//printf("TemplateInstance.genIdent('%s')\n", tempdecl.ident.toChars());
 		id = tempdecl.ident.toChars();
 		buf.printf("__T%d%s", id.length, id);	///!
 		args = tiargs;
@@ -1383,4 +1428,4 @@
 	{
 		assert(false);
 	}
-}
\ No newline at end of file
+}