diff --git a/src/mtype.c b/src/mtype.c index 86de838a3c1c..1b59d457b875 100644 --- a/src/mtype.c +++ b/src/mtype.c @@ -1055,7 +1055,7 @@ StorageClass ModToStc(unsigned mod) * Apply MODxxxx bits to existing type. */ -Type *Type::castMod(unsigned mod) +Type *Type::castMod(MOD mod) { Type *t; switch (mod) @@ -1108,7 +1108,7 @@ Type *Type::castMod(unsigned mod) * a shared type => "shared const" */ -Type *Type::addMod(unsigned mod) +Type *Type::addMod(MOD mod) { /* Add anything to immutable, and it remains immutable */ @@ -1387,10 +1387,10 @@ Type *Type::toBasetype() /*************************** * Return !=0 if modfrom can be implicitly converted to modto */ -int MODimplicitConv(unsigned char modfrom, unsigned char modto) +bool MODimplicitConv(MOD modfrom, MOD modto) { if (modfrom == modto) - return 1; + return true; //printf("MODimplicitConv(from = %x, to = %x)\n", modfrom, modto); #define X(m, n) (((m) << 4) | (n)) @@ -1404,10 +1404,10 @@ int MODimplicitConv(unsigned char modfrom, unsigned char modto) case X(MODimmutable, MODconst): case X(MODimmutable, MODwildconst): - return 1; + return true; default: - return 0; + return false; } #undef X } @@ -1415,10 +1415,10 @@ int MODimplicitConv(unsigned char modfrom, unsigned char modto) /*************************** * Return !=0 if a method of type '() modfrom' can call a method of type '() modto'. */ -int MODmethodConv(unsigned char modfrom, unsigned char modto) +bool MODmethodConv(MOD modfrom, MOD modto) { if (MODimplicitConv(modfrom, modto)) - return 1; + return true; #define X(m, n) (((m) << 4) | (n)) switch (X(modfrom, modto)) @@ -1429,10 +1429,10 @@ int MODmethodConv(unsigned char modfrom, unsigned char modto) case X(MODshared, MODshared|MODwild): case X(MODshared|MODimmutable, MODshared|MODwild): case X(MODshared|MODconst, MODshared|MODwild): - return 1; + return true; default: - return 0; + return false; } #undef X } @@ -1440,13 +1440,13 @@ int MODmethodConv(unsigned char modfrom, unsigned char modto) /*************************** * Merge mod bits to form common mod. */ -unsigned char MODmerge(unsigned char mod1, unsigned char mod2) +MOD MODmerge(MOD mod1, MOD mod2) { if (mod1 == mod2) return mod1; //printf("MODmerge(1 = %x, 2 = %x)\n", mod1, mod2); - unsigned char result = 0; + MOD result = 0; if ((mod1 | mod2) & MODshared) { // If either type is shared, the result will be shared @@ -1474,7 +1474,7 @@ unsigned char MODmerge(unsigned char mod1, unsigned char mod2) /********************************* * Mangling for mod. */ -void MODtoDecoBuffer(OutBuffer *buf, unsigned char mod) +void MODtoDecoBuffer(OutBuffer *buf, MOD mod) { switch (mod) { case 0: @@ -1511,7 +1511,7 @@ void MODtoDecoBuffer(OutBuffer *buf, unsigned char mod) /********************************* * Store modifier name into buf. */ -void MODtoBuffer(OutBuffer *buf, unsigned char mod) +void MODtoBuffer(OutBuffer *buf, MOD mod) { switch (mod) { @@ -1561,7 +1561,7 @@ void MODtoBuffer(OutBuffer *buf, unsigned char mod) /********************************* * Return modifier name. */ -char *MODtoChars(unsigned char mod) +char *MODtoChars(MOD mod) { OutBuffer buf; buf.reserve(16); diff --git a/src/mtype.h b/src/mtype.h index 32b39375492b..163bfdc79c77 100644 --- a/src/mtype.h +++ b/src/mtype.h @@ -115,20 +115,26 @@ extern int Tsize_t; extern int Tptrdiff_t; -/* pick this order of numbers so switch statements work better +/** + * type modifiers + * pick this order of numbers so switch statements work better */ -#define MODconst 1 // type is const -#define MODimmutable 4 // type is immutable -#define MODshared 2 // type is shared -#define MODwild 8 // type is wild -#define MODwildconst (MODwild | MODconst) // type is wild const -#define MODmutable 0x10 // type is mutable (only used in wildcard matching) +enum MODFlags +{ + MODconst = 1, // type is const + MODimmutable = 4, // type is immutable + MODshared = 2, // type is shared + MODwild = 8, // type is wild + MODwildconst = (MODwild | MODconst), // type is wild const + MODmutable = 0x10 // type is mutable (only used in wildcard matching) +}; +typedef unsigned char MOD; class Type : public RootObject { public: TY ty; - unsigned char mod; // modifiers MODxxxx + MOD mod; // modifiers MODxxxx char *deco; /* These are cached values that are lazily evaluated by constOf(), immutableOf(), etc. @@ -296,8 +302,8 @@ class Type : public RootObject void fixTo(Type *t); void check(); Type *addSTC(StorageClass stc); - Type *castMod(unsigned mod); - Type *addMod(unsigned mod); + Type *castMod(MOD mod); + Type *addMod(MOD mod); virtual Type *addStorageClass(StorageClass stc); Type *pointerTo(); Type *referenceTo(); @@ -1014,11 +1020,11 @@ class Parameter : public RootObject int arrayTypeCompatible(Loc loc, Type *t1, Type *t2); int arrayTypeCompatibleWithoutCasting(Loc loc, Type *t1, Type *t2); -void MODtoBuffer(OutBuffer *buf, unsigned char mod); -char *MODtoChars(unsigned char mod); -int MODimplicitConv(unsigned char modfrom, unsigned char modto); -int MODmethodConv(unsigned char modfrom, unsigned char modto); -unsigned char MODmerge(unsigned char mod1, unsigned char mod2); +void MODtoBuffer(OutBuffer *buf, MOD mod); +char *MODtoChars(MOD mod); +bool MODimplicitConv(MOD modfrom, MOD modto); +bool MODmethodConv(MOD modfrom, MOD modto); +MOD MODmerge(MOD mod1, MOD mod2); void identifierToDocBuffer(Identifier* ident, OutBuffer *buf, HdrGenState *hgs); #endif /* DMD_MTYPE_H */ diff --git a/src/opover.c b/src/opover.c index a3a53d1f6cf9..2e2c55a926cd 100644 --- a/src/opover.c +++ b/src/opover.c @@ -1704,7 +1704,7 @@ static Dsymbol *inferApplyArgTypesX(Expression *ethis, FuncDeclaration *fstart, struct ParamOpOver { Parameters *arguments; - unsigned char mod; + MOD mod; MATCH match; FuncDeclaration *fd_best; FuncDeclaration *fd_ambig;