diff dmd2/mtype.c @ 1577:e4f7b5d9c68a

DMD 2.032 Merge.
author Robert Clipsham <robert@octarineparrot.com>
date Tue, 08 Sep 2009 10:07:56 +0100
parents 54b3c1394d62
children
line wrap: on
line diff
--- a/dmd2/mtype.c	Tue Aug 25 21:35:43 2009 +0200
+++ b/dmd2/mtype.c	Tue Sep 08 10:07:56 2009 +0100
@@ -198,6 +198,7 @@
 	sizeTy[i] = sizeof(TypeBasic);
     sizeTy[Tsarray] = sizeof(TypeSArray);
     sizeTy[Tarray] = sizeof(TypeDArray);
+    //sizeTy[Tnarray] = sizeof(TypeNArray);
     sizeTy[Taarray] = sizeof(TypeAArray);
     sizeTy[Tpointer] = sizeof(TypePointer);
     sizeTy[Treference] = sizeof(TypeReference);
@@ -216,6 +217,7 @@
 
     mangleChar[Tarray] = 'A';
     mangleChar[Tsarray] = 'G';
+    mangleChar[Tnarray] = '@';
     mangleChar[Taarray] = 'H';
     mangleChar[Tpointer] = 'P';
     mangleChar[Treference] = 'R';
@@ -1151,6 +1153,16 @@
     }
 }
 
+void Type::modToBuffer(OutBuffer *buf)
+{
+    if (mod & MODshared)
+        buf->writestring(" shared");
+    if (mod & MODconst)
+        buf->writestring(" const");
+    if (mod & MODinvariant)
+        buf->writestring(" immutable");
+}
+
 /************************************
  */
 
@@ -1651,6 +1663,12 @@
     return next->reliesOnTident();
 }
 
+/*******************************
+ * For TypeFunction, nextOf() can return NULL if the function return
+ * type is meant to be inferred, and semantic() hasn't yet ben run
+ * on the function. After semantic(), it must no longer be NULL.
+ */
+
 Type *TypeNext::nextOf()
 {
     return next;
@@ -3251,6 +3269,88 @@
     return TRUE;
 }
 
+
+/***************************** TypeNewArray *****************************/
+
+#if 0
+
+TypeNewArray::TypeNewArray(Type *telement)
+	: TypeArray(Tnewarray, telement)
+{
+    sym = NULL;
+}
+
+Type *TypeNewArray::syntaxCopy()
+{
+    Type *t = next->syntaxCopy();
+    if (t == next)
+	t = this;
+    else
+    {	t = new TypeNewArray(t);
+	t->mod = mod;
+    }
+    return t;
+}
+
+d_uns64 TypeNewArray::size(Loc loc)
+{
+    //printf("TypeNewArray::size()\n");
+    return PTRSIZE;
+}
+
+unsigned TypeNewArray::alignsize()
+{
+    return PTRSIZE;
+}
+
+Type *TypeNewArray::semantic(Loc loc, Scope *sc)
+{   Type *tn = next;
+
+    tn = next->semantic(loc,sc);
+    Type *tbn = tn->toBasetype();
+    switch (tbn->ty)
+    {
+	case Tfunction:
+	case Tnone:
+	case Ttuple:
+	    error(loc, "can't have array of %s", tbn->toChars());
+	    tn = next = tint32;
+	    break;
+	case Tstruct:
+	{   TypeStruct *ts = (TypeStruct *)tbn;
+	    if (ts->sym->isnested)
+		error(loc, "cannot have array of inner structs %s", ts->toChars());
+	    break;
+	}
+    }
+    if (tn->isauto())
+	error(loc, "cannot have array of auto %s", tn->toChars());
+
+    next = tn;
+    transitive();
+    return merge();
+}
+
+void TypeNewArray::toDecoBuffer(OutBuffer *buf, int flag)
+{
+    Type::toDecoBuffer(buf, flag);
+    buf->writeByte('e');
+    if (next)
+	next->toDecoBuffer(buf, (flag & 0x100) ? 0 : mod);
+}
+
+void TypeNewArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod)
+{
+    if (mod != this->mod)
+    {	toCBuffer3(buf, hgs, mod);
+	return;
+    }
+    next->toCBuffer2(buf, hgs, this->mod);
+    buf->writestring("[new]");
+}
+
+#endif
+
 /***************************** TypeAArray *****************************/
 
 TypeAArray::TypeAArray(Type *t, Type *index)
@@ -3774,6 +3874,7 @@
     this->inuse = 0;
     this->isnothrow = false;
     this->ispure = false;
+    this->isproperty = false;
     this->isref = false;
 
 #if IN_LLVM
@@ -3789,6 +3890,7 @@
     t->mod = mod;
     t->isnothrow = isnothrow;
     t->ispure = ispure;
+    t->isproperty = isproperty;
     t->isref = isref;
     return t;
 }
@@ -3958,8 +4060,7 @@
 	    assert(0);
     }
     buf->writeByte(mc);
-
-    if (ispure || isnothrow || isref)
+    if (ispure || isnothrow || isproperty || isref)
     {
 	if (ispure)
 	    buf->writestring("Na");
@@ -3967,6 +4068,8 @@
 	    buf->writestring("Nb");
 	if (isref)
 	    buf->writestring("Nc");
+	if (isproperty)
+	    buf->writestring("Nd");
     }
 
     // LDC: if we're not producing a mangle string, add the this
@@ -4026,6 +4129,8 @@
 	buf->writestring("pure ");
     if (isnothrow)
 	buf->writestring("nothrow ");
+    if (isproperty)
+	buf->writestring("@property ");
     if (isref)
 	buf->writestring("ref ");
 
@@ -4098,17 +4203,14 @@
      */
     if (mod != this->mod)
     {
-	if (mod & MODconst)
-	    buf->writestring(" const");
-	if (mod & MODinvariant)
-	    buf->writestring(" immutable");
-	if (mod & MODshared)
-	    buf->writestring(" shared");
+	modToBuffer(buf);
     }
     if (ispure)
 	buf->writestring(" pure");
     if (isnothrow)
 	buf->writestring(" nothrow");
+    if (isproperty)
+	buf->writestring(" @property");
     if (isref)
 	buf->writestring(" ref");
 
@@ -6170,7 +6272,7 @@
 {
     if (mod)
 	return Type::toChars();
-    return sym->toPrettyChars();
+    return (char *)sym->toPrettyChars();
 }
 
 Type *TypeClass::syntaxCopy()