Showing with 55 additions and 40 deletions.
  1. +3 −3 src/cast.c
  2. +26 −26 src/impcnvgen.c
  3. +15 −0 src/magicport.json
  4. +9 −9 src/mtype.h
  5. +1 −1 src/posix.mak
  6. +1 −1 src/win32.mak
6 changes: 3 additions & 3 deletions src/cast.c
Original file line number Diff line number Diff line change
Expand Up @@ -2655,11 +2655,11 @@ bool typeMerge(Scope *sc, TOK op, Type **pt, Expression **pe1, Expression **pe2)
t1b = t1->toBasetype();
t2b = t2->toBasetype();

TY ty = (TY)Type::impcnvResult[t1b->ty][t2b->ty];
TY ty = (TY)impcnvResult[t1b->ty][t2b->ty];
if (ty != Terror)
{
TY ty1 = (TY)Type::impcnvType1[t1b->ty][t2b->ty];
TY ty2 = (TY)Type::impcnvType2[t1b->ty][t2b->ty];
TY ty1 = (TY)impcnvType1[t1b->ty][t2b->ty];
TY ty2 = (TY)impcnvType2[t1b->ty][t2b->ty];

if (t1b->ty == ty1) // if no promotions
{
Expand Down
52 changes: 26 additions & 26 deletions src/impcnvgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

#include "mtype.h"

TY impcnvResult[TMAX][TMAX];
TY impcnvType1[TMAX][TMAX];
TY impcnvType2[TMAX][TMAX];
int impcnvWarn[TMAX][TMAX];
TY impcnvResultTab[TMAX][TMAX];
TY impcnvType1Tab[TMAX][TMAX];
TY impcnvType2Tab[TMAX][TMAX];
int impcnvWarnTab[TMAX][TMAX];

int integral_promotion(int t)
{
Expand All @@ -41,16 +41,16 @@ void init()
// Set conversion tables
for (i = 0; i < TMAX; i++)
for (j = 0; j < TMAX; j++)
{ impcnvResult[i][j] = Terror;
impcnvType1[i][j] = Terror;
impcnvType2[i][j] = Terror;
impcnvWarn[i][j] = 0;
{ impcnvResultTab[i][j] = Terror;
impcnvType1Tab[i][j] = Terror;
impcnvType2Tab[i][j] = Terror;
impcnvWarnTab[i][j] = 0;
}

#define X(t1,t2, nt1,nt2, rt) \
impcnvResult[t1][t2] = rt; \
impcnvType1[t1][t2] = nt1; \
impcnvType2[t1][t2] = nt2;
impcnvResultTab[t1][t2] = rt; \
impcnvType1Tab[t1][t2] = nt1; \
impcnvType2Tab[t1][t2] = nt2;


/* ======================= */
Expand Down Expand Up @@ -345,7 +345,7 @@ void init()

#undef X

#define Y(t1,t2) impcnvWarn[t1][t2] = 1;
#define Y(t1,t2) impcnvWarnTab[t1][t2] = 1;

Y(Tuns8, Tint8)
Y(Tint16, Tint8)
Expand Down Expand Up @@ -431,28 +431,28 @@ void init()
for (i = 0; i < TMAX; i++)
for (j = 0; j < TMAX; j++)
{
if (impcnvResult[i][j] == Terror)
if (impcnvResultTab[i][j] == Terror)
{
impcnvResult[i][j] = impcnvResult[j][i];
impcnvType1[i][j] = impcnvType2[j][i];
impcnvType2[i][j] = impcnvType1[j][i];
impcnvResultTab[i][j] = impcnvResultTab[j][i];
impcnvType1Tab[i][j] = impcnvType2Tab[j][i];
impcnvType2Tab[i][j] = impcnvType1Tab[j][i];
}
}
}

int main()
{ FILE *fp;
{
int i;
int j;

init();

fp = fopen("impcnvtab.c","w");
FILE *fp = fopen("impcnvtab.c","wb");

fprintf(fp,"// This file is generated by impcnvgen.c\n");
fprintf(fp,"#include \"mtype.h\"\n");

fprintf(fp,"unsigned char Type::impcnvResult[TMAX][TMAX] =\n{\n");
fprintf(fp,"unsigned char impcnvResult[TMAX][TMAX] =\n{\n");
for (i = 0; i < TMAX; i++)
{
if (i)
Expand All @@ -462,13 +462,13 @@ int main()
{
if (j)
fprintf(fp, ",");
fprintf(fp, "%d",impcnvResult[i][j]);
fprintf(fp, "%d",impcnvResultTab[i][j]);
}
fprintf(fp, "}\n");
}
fprintf(fp,"};\n");

fprintf(fp,"unsigned char Type::impcnvType1[TMAX][TMAX] =\n{\n");
fprintf(fp,"unsigned char impcnvType1[TMAX][TMAX] =\n{\n");
for (i = 0; i < TMAX; i++)
{
if (i)
Expand All @@ -478,13 +478,13 @@ int main()
{
if (j)
fprintf(fp, ",");
fprintf(fp, "%d",impcnvType1[i][j]);
fprintf(fp, "%d",impcnvType1Tab[i][j]);
}
fprintf(fp, "}\n");
}
fprintf(fp,"};\n");

fprintf(fp,"unsigned char Type::impcnvType2[TMAX][TMAX] =\n{\n");
fprintf(fp,"unsigned char impcnvType2[TMAX][TMAX] =\n{\n");
for (i = 0; i < TMAX; i++)
{
if (i)
Expand All @@ -494,13 +494,13 @@ int main()
{
if (j)
fprintf(fp, ",");
fprintf(fp, "%d",impcnvType2[i][j]);
fprintf(fp, "%d",impcnvType2Tab[i][j]);
}
fprintf(fp, "}\n");
}
fprintf(fp,"};\n");

fprintf(fp,"unsigned char Type::impcnvWarn[TMAX][TMAX] =\n{\n");
fprintf(fp,"unsigned char impcnvWarn[TMAX][TMAX] =\n{\n");
for (i = 0; i < TMAX; i++)
{
if (i)
Expand All @@ -510,7 +510,7 @@ int main()
{
if (j)
fprintf(fp, ",");
fprintf(fp, "%d",impcnvWarn[i][j]);
fprintf(fp, "%d",impcnvWarnTab[i][j]);
}
fprintf(fp, "}\n");
}
Expand Down
15 changes: 15 additions & 0 deletions src/magicport.json
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,7 @@
"expression",
"func",
"id",
"impcnvtab",
"init",
"intrange",
"tokens",
Expand Down Expand Up @@ -3245,6 +3246,20 @@
[
"function response_expand"
]
},
{
"module" : "impcnvtab",
"package" : "",
"imports" : [
"mtype"
],
"members" :
[
"variable impcnvResult",
"variable impcnvType1",
"variable impcnvType2",
"variable impcnvWarn"
]
}
],
"basicTypes" :
Expand Down
18 changes: 9 additions & 9 deletions src/mtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ enum MODFlags
};
typedef unsigned char MOD;

// These tables are for implicit conversion of binary ops;
// the indices are the type of operand one, followed by operand two.
extern unsigned char impcnvResult[TMAX][TMAX];
extern unsigned char impcnvType1[TMAX][TMAX];
extern unsigned char impcnvType2[TMAX][TMAX];

// If !=0, give warning on implicit conversion
extern unsigned char impcnvWarn[TMAX][TMAX];

class Type : public RootObject
{
public:
Expand Down Expand Up @@ -219,15 +228,6 @@ class Type : public RootObject
static unsigned char sizeTy[TMAX];
static StringTable stringtable;

// These tables are for implicit conversion of binary ops;
// the indices are the type of operand one, followed by operand two.
static unsigned char impcnvResult[TMAX][TMAX];
static unsigned char impcnvType1[TMAX][TMAX];
static unsigned char impcnvType2[TMAX][TMAX];

// If !=0, give warning on implicit conversion
static unsigned char impcnvWarn[TMAX][TMAX];

Type(TY ty);
virtual const char *kind();
Type *copy();
Expand Down
2 changes: 1 addition & 1 deletion src/posix.mak
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ GENSRC=access.d aggregate.d aliasthis.d apply.d \
target.d dtemplate.d traits.d dunittest.d \
utf.d dversion.d visitor.d lib.d \
nogc.d nspace.d errors.d tokens.d \
globals.d escape.d \
globals.d escape.d impcnvtab.d \
$(ROOT)/aav.d $(ROOT)/outbuffer.d $(ROOT)/stringtable.d \
$(ROOT)/file.d $(ROOT)/filename.d $(ROOT)/speller.d \
$(ROOT)/man.d $(ROOT)/response.d
Expand Down
2 changes: 1 addition & 1 deletion src/win32.mak
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ GENSRC=access.d aggregate.d aliasthis.d apply.d \
target.d dtemplate.d traits.d dunittest.d \
utf.d dversion.d visitor.d lib.d \
nogc.d nspace.d errors.d tokens.d \
globals.d escape.d \
globals.d escape.d impcnvtab.d \
$(ROOT)\aav.d $(ROOT)\outbuffer.d $(ROOT)\stringtable.d \
$(ROOT)\file.d $(ROOT)\filename.d $(ROOT)\speller.d \
$(ROOT)\man.d $(ROOT)\response.d
Expand Down