Commits

Vincenzo Ampolo committed e64c79f

other merges

Comments (0)

Files changed (4)

 		goto Lno;
 	    goto Lyes;
 
+#if IN_GCC
+	case Tfloat32:
+	case Tfloat64:
+	case Tfloat80:
+	{
+	    real_t::MyMode mode;
+	    real_t f;
+	    switch (toty)
+	    {
+	    case Tfloat32: mode = real_t::Float; break;
+	    case Tfloat64: mode = real_t::Double; break;
+	    case Tfloat80: mode = real_t::LongDouble; break;
+	    }
+	    if (type->isunsigned())
+	    {
+		f = real_t((d_uns64) value);
+		f = f.convert(mode);
+		if ((d_uns64) f.toInt() != (d_uns64) value)
+		    goto Lno;
+	    }
+	    else
+	    {
+		f = real_t((d_int64) value);
+		f = f.convert(mode);
+		if ((d_int64) f.toInt() != (d_int64) value)
+		    goto Lno;
+	    }
+	    goto Lyes;
+	}
+#else
+
 	case Tfloat32:
 	{
 	    volatile float f;
 		goto Lyes;
 	    }
 	    break;
+#endif
     }
     return Expression::implicitConvTo(t);
 
 	    {
 		f = func->overloadExactMatch(tb->nextOf());
 		if (f)
-		{   int offset;
+		{   target_ptrdiff_t offset;
 		    if (f->tintro && f->tintro->nextOf()->isBaseOf(f->type->nextOf(), &offset) && offset)
 			error("%s", msg);
 		    f->tookAddressOf++;
 	e = Expression::castTo(sc, t);
     }
     else
-    {	int offset;
+    {	target_ptrdiff_t offset;
 
 	func->tookAddressOf++;
 	if (func->tintro && func->tintro->nextOf()->isBaseOf(func->type->nextOf(), &offset) && offset)
 	else if (t1n->ty == Tclass && t2n->ty == Tclass)
 	{   ClassDeclaration *cd1 = t1n->isClassHandle();
 	    ClassDeclaration *cd2 = t2n->isClassHandle();
-	    int offset;
+	    target_ptrdiff_t offset;
 
 	    if (cd1->isBaseOf(cd2, &offset))
 	    {
 // in artistic.txt, or the GNU General Public License in gnu.txt.
 // See the included readme.txt for details.
 
+/* NOTE: This file has been patched from the original DMD distribution to
+   work with the GDC compiler.
+
+   Modified by Vincenzo Ampolo, Sept 2009
+*/
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
 
 void ClassDeclaration::semantic(Scope *sc)
 {   int i;
-    unsigned offset;
 
     //printf("ClassDeclaration::semantic(%s), type = %p, sizeok = %d, this = %p\n", toChars(), type, sizeok, this);
     //printf("\tparent = %p, '%s'\n", sc->parent, sc->parent ? sc->parent->toChars() : "");
 	scx = scope;		// save so we don't make redundant copies
 	scope = NULL;
     }
+    if (attributes)
+    	attributes->append(sc->attributes);
+    else
+    	attributes = sc->attributes;
 #ifdef IN_GCC
     methods.setDim(0);
 #endif
     sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic |
 		 STCabstract | STCdeprecated | STC_TYPECTOR | STCtls | STCgshared);
     sc->stc |= storage_class & STC_TYPECTOR;
+    sc->attributes = NULL;
     sc->parent = this;
     sc->inunion = 0;
 
  * Determine if 'this' is a base class of cd.
  */
 
-int ClassDeclaration::isBaseOf(ClassDeclaration *cd, int *poffset)
+int ClassDeclaration::isBaseOf(ClassDeclaration *cd, target_ptrdiff_t *poffset)
 {
     //printf("ClassDeclaration::isBaseOf(this = '%s', cd = '%s')\n", toChars(), cd->toChars());
     if (poffset)
 	scope = NULL;
     }
 
+    if (attributes)
+    	attributes->append(sc->attributes);
+    else
+    	attributes = sc->attributes;
+
     if (sc->stc & STCdeprecated)
     {
 	isdeprecated = 1;
     sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic |
                  STCabstract | STCdeprecated | STC_TYPECTOR | STCtls | STCgshared);
     sc->stc |= storage_class & STC_TYPECTOR;
+    sc->attributes = NULL;
     sc->parent = this;
     if (isCOMinterface())
 	sc->linkage = LINKwindows;
  *	1	is a base
  */
 
-int InterfaceDeclaration::isBaseOf(ClassDeclaration *cd, int *poffset)
+int InterfaceDeclaration::isBaseOf(ClassDeclaration *cd, target_ptrdiff_t *poffset)
 {
     unsigned j;
 
 }
 
 
-int InterfaceDeclaration::isBaseOf(BaseClass *bc, int *poffset)
+int InterfaceDeclaration::isBaseOf(BaseClass *bc, target_ptrdiff_t *poffset)
 {
     //printf("%s.InterfaceDeclaration::isBaseOf(bc = '%s')\n", toChars(), bc->base->toChars());
     for (unsigned j = 0; j < bc->baseInterfaces_dim; j++)

d/dmd2.032/constfold.c

 // in artistic.txt, or the GNU General Public License in gnu.txt.
 // See the included readme.txt for details.
 
+/* NOTE: This file has been patched from the original DMD distribution to
+   work with the GDC compiler.
+
+   Modified by Vincenzo Ampolo, Sept 2009
+*/
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
 	if (es2->len < len)
 	    len = es2->len;
 
-	int cmp = memcmp(es1->string, es2->string, sz * len);
+	int cmp = 0;
+	if (sz == 1)
+		cmp = memcmp(es1->string, es2->string, sz * len);
+	else if (sz == 2)
+	{
+		const d_uns16 * p1 = (const d_uns16 *) es1->string;
+		const d_uns16 * p2 = (const d_uns16 *) es2->string;
+		for (size_t i = 0; i < len; ++i)
+		if (p1[i] > p2[i])
+			{ cmp = 1; break; }
+		else if (p1[i] < p2[i])
+			{ cmp = -1; break; }
+	}
+	else if (sz == 4)
+	{
+		const d_uns32 * p1 = (const d_uns32 *) es1->string;
+		const d_uns32 * p2 = (const d_uns32 *) es2->string;
+		for (size_t i = 0; i < len; ++i)
+		if (p1[i] > p2[i])
+			{ cmp = 1; break; }
+		else if (p1[i] < p2[i])
+			{ cmp = -1; break; }
+	}
+	else
+		assert(0);
+
 	if (cmp == 0)
 	    cmp = es1->len - es2->len;
 
     {
 	if (e1->type->isfloating())
 	{   dinteger_t result;
+#ifdef IN_GCC
+	    Type * rt = e1->type;
+	    if (rt->iscomplex())
+	    {
+	    	switch (rt->toBasetype()->ty)
+	    	{
+				case Tcomplex32: rt = Type::tfloat32; break;
+				case Tcomplex64: rt = Type::tfloat64; break;
+				case Tcomplex80: rt = Type::tfloat80; break;
+				default: assert(0);
+	    	}
+	    }
+	    d_int64 r = e1->toReal().toInt(rt, type);
+#else
 	    real_t r = e1->toReal();
+#endif
 
 	    switch (typeb->ty)
 	    {
 	uinteger_t i = e2->toInteger();
 
 	if (i >= es1->len)
-	    e1->error("string index %ju is out of bounds [0 .. %zu]", i, es1->len);
+		e1->error("string index %"PRIuMAX" is out of bounds [0 .. %"PRIuSIZE"]", i, es1->len);
 	else
 	{   unsigned value = es1->charAt(i);
 	    e = new IntegerExp(loc, value, type);
 	uinteger_t i = e2->toInteger();
 
 	if (i >= length)
-	{   e2->error("array index %ju is out of bounds %s[0 .. %ju]", i, e1->toChars(), length);
-	}
+	{   e2->error("array index %"PRIuMAX" is out of bounds %s[0 .. %"PRIuMAX"]", i, e1->toChars(), length);	}
 	else if (e1->op == TOKarrayliteral && !e1->checkSideEffect(2))
 	{   ArrayLiteralExp *ale = (ArrayLiteralExp *)e1;
 	    e = (Expression *)ale->elements->data[i];
 	uinteger_t iupr = upr->toInteger();
 
 	if (iupr > es1->len || ilwr > iupr)
-	    e1->error("string slice [%ju .. %ju] is out of bounds", ilwr, iupr);
+		e1->error("string slice [%"PRIuMAX" .. %"PRIuMAX"] is out of bounds", ilwr, iupr);
 	else
 	{   dinteger_t value;
 	    void *s;
 	uinteger_t iupr = upr->toInteger();
 
 	if (iupr > es1->elements->dim || ilwr > iupr)
-	    e1->error("array slice [%ju .. %ju] is out of bounds", ilwr, iupr);
+		e1->error("array slice [%"PRIuMAX" .. %"PRIuMAX"] is out of bounds", ilwr, iupr);
 	else
 	{
 	    Expressions *elements = new Expressions();
 	    dinteger_t v = e->toInteger();
 
 	    s = mem.malloc((len + 1) * sz);
-	    memcpy((unsigned char *)s, &v, sz);
+	    switch (sz)
+	    {
+	    		case 1: *(d_uns8*)s = v; break;
+	    		case 2: *(d_uns16*)s = v; break;
+	    		case 4: *(d_uns32*)s = v; break;
+	    		default: assert(0);
+	    }
 
 	    // Add terminating 0
 	    memset((unsigned char *)s + len * sz, 0, sz);
     {
 	// Concatenate the strings
 	void *s;
+	void *sch;
 	StringExp *es1 = (StringExp *)e1;
 	StringExp *es2 = (StringExp *)e2;
 	StringExp *es;
 	}
 	s = mem.malloc((len + 1) * sz);
 	memcpy(s, es1->string, es1->len * sz);
-	memcpy((unsigned char *)s + es1->len * sz, es2->string, es2->len * sz);
+	sch = (unsigned char *)s + es1->len * sz;
+	switch (sz)
+	{
+		    case 1: *(d_uns8*)sch = es2->string; break;
+		    case 2: *(d_uns16*)sch = es2->string; break;
+		    case 4: *(d_uns32*)sch = es2->string; break;
+		    default: assert(0);
+	}
 
 	// Add terminating 0
 	memset((unsigned char *)s + len * sz, 0, sz);
 	dinteger_t v = e2->toInteger();
 
 	s = mem.malloc((len + 1) * sz);
-	memcpy(s, es1->string, es1->len * sz);
+	switch (sz)
+	{
+		    case 1: *(d_uns8*)s = v; break;
+		    case 2: *(d_uns16*)s = v; break;
+		    case 4: *(d_uns32*)s = v; break;
+		    default: assert(0);
+	}
 	memcpy((unsigned char *)s + es1->len * sz, &v, sz);
 
 	// Add terminating 0

d/dmd2.032/declaration.c

 // in artistic.txt, or the GNU General Public License in gnu.txt.
 // See the included readme.txt for details.
 
+/* NOTE: This file has been patched from the original DMD distribution to
+   work with the GDC compiler.
+
+   Modified by Vincenzo Ampolo, Sept 2009
+*/
+
+
 #include <stdio.h>
 #include <assert.h>
 
     protection = PROTundefined;
     linkage = LINKdefault;
     inuse = 0;
+    attributes = NULL;
 }
 
 void Declaration::semantic(Scope *sc)
     return "declaration";
 }
 
-unsigned Declaration::size(Loc loc)
+target_size_t Declaration::size(Loc loc)
 {
     assert(type);
     return type->size();
 	basetype = basetype->semantic(loc, sc);
 	sem = 2;
 	type = type->semantic(loc, sc);
+	if (attributes)
+		    attributes->append(sc->attributes);
+	else
+		    attributes = sc->attributes;
 	if (sc->parent->isFuncDeclaration() && init)
 	    semantic2(sc);
 	storage_class |= sc->stc & STCdeprecated;
     this->parent = sc->parent;
     //printf("this = %p, parent = %p, '%s'\n", this, parent, parent->toChars());
     protection = sc->protection;
+    if (attributes)
+    	    attributes->append(sc->attributes);
+    else
+    	    attributes = sc->attributes;
     //printf("sc->stc = %x\n", sc->stc);
     //printf("storage_class = x%x\n", storage_class);
 
 	{   Argument *arg = Argument::getNth(tt->arguments, i);
 
 	    OutBuffer buf;
-	    buf.printf("_%s_field_%zu", ident->toChars(), i);
+	    buf.printf("_%s_field_%"PRIuSIZE, ident->toChars(), i);
 	    buf.writeByte(0);
 	    char *name = (char *)buf.extractData();
 	    Identifier *id = new Identifier(name, TOKidentifier);
 		    ei->exp = ei->exp->semantic(sc);
 		    if (!ei->exp->implicitConvTo(type))
 		    {
-			int dim = ((TypeSArray *)t)->dim->toInteger();
+		    sinteger_t dim = ((TypeSArray *)t)->dim->toInteger();
 			// If multidimensional static array, treat as one large array
 			while (1)
 			{