Skip to content

Commit

Permalink
Merge pull request #3750 from Trass3r/master
Browse files Browse the repository at this point in the history
use enums
  • Loading branch information
9rnsr committed Jul 16, 2014
1 parent b18fb12 commit 190ed25
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
30 changes: 15 additions & 15 deletions src/mtype.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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))
Expand All @@ -1404,21 +1404,21 @@ 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
}

/***************************
* 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))
Expand All @@ -1429,24 +1429,24 @@ 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
}

/***************************
* 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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 21 additions & 15 deletions src/mtype.h
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 */
2 changes: 1 addition & 1 deletion src/opover.c
Expand Up @@ -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;
Expand Down

0 comments on commit 190ed25

Please sign in to comment.