Skip to content

Commit

Permalink
Use final switch for LINK
Browse files Browse the repository at this point in the history
  • Loading branch information
wilzbach committed Jan 18, 2018
1 parent 59c08d8 commit 6517be5
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 28 deletions.
5 changes: 2 additions & 3 deletions src/dmd/astbase.d
Expand Up @@ -6278,9 +6278,10 @@ struct ASTBase

extern (C++) static const(char)* linkageToChars(LINK linkage)
{
switch (linkage)
final switch (linkage)
{
case LINK.default_:
case LINK.system:
return null;
case LINK.d:
return "D";
Expand All @@ -6294,8 +6295,6 @@ struct ASTBase
return "Pascal";
case LINK.objc:
return "Objective-C";
default:
assert(0);
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/dmd/cppmanglewin.d
Expand Up @@ -973,7 +973,7 @@ private:
}
else
{
switch (type.linkage)
final switch (type.linkage)
{
case LINK.c:
tmp.buf.writeByte('A');
Expand All @@ -990,7 +990,10 @@ private:
case LINK.pascal:
tmp.buf.writeByte('C');
break;
default:
case LINK.d:
case LINK.default_:
case LINK.system:
case LINK.objc:
tmp.visit(cast(Type)type);
break;
}
Expand Down
12 changes: 5 additions & 7 deletions src/dmd/dmangle.d
Expand Up @@ -351,8 +351,10 @@ public:
if (modMask != t.mod)
MODtoDecoBuffer(buf, t.mod);
ubyte mc;
switch (t.linkage)
final switch (t.linkage)
{
case LINK.default_:
case LINK.system:
case LINK.d:
mc = 'F';
break;
Expand All @@ -371,8 +373,6 @@ public:
case LINK.objc:
mc = 'Y';
break;
default:
assert(0);
}
buf.writeByte(mc);
if (ta.purity || ta.isnothrow || ta.isnogc || ta.isproperty || ta.isref || ta.trust || ta.isreturn || ta.isscope)
Expand Down Expand Up @@ -545,7 +545,7 @@ public:
{
if (!d.parent || d.parent.isModule() || d.linkage == LINK.cpp) // if at global scope
{
switch (d.linkage)
final switch (d.linkage)
{
case LINK.d:
break;
Expand All @@ -557,11 +557,9 @@ public:
case LINK.cpp:
return Target.toCppMangle(d);
case LINK.default_:
case LINK.system:
d.error("forward declaration");
return d.ident.toChars();
default:
fprintf(stderr, "'%s', linkage = %d\n", d.toChars(), d.linkage);
assert(0);
}
}
return null;
Expand Down
5 changes: 3 additions & 2 deletions src/dmd/glue.d
Expand Up @@ -1459,7 +1459,7 @@ uint totym(Type tx)
case Tfunction:
{
TypeFunction tf = cast(TypeFunction)tx;
switch (tf.linkage)
final switch (tf.linkage)
{
case LINK.windows:
if (global.params.is64bit)
Expand Down Expand Up @@ -1487,7 +1487,8 @@ uint totym(Type tx)
t = (tf.varargs == 1) ? TYnfunc : TYjfunc;
break;

default:
case LINK.default_:
case LINK.system:
printf("linkage = %d\n", tf.linkage);
assert(0);
}
Expand Down
4 changes: 1 addition & 3 deletions src/dmd/hdrgen.d
Expand Up @@ -3307,7 +3307,7 @@ private void linkageToBuffer(OutBuffer* buf, LINK linkage)

extern (C++) const(char)* linkageToChars(LINK linkage)
{
switch (linkage)
final switch (linkage)
{
case LINK.default_:
return null;
Expand All @@ -3325,8 +3325,6 @@ extern (C++) const(char)* linkageToChars(LINK linkage)
return "Objective-C";
case LINK.system:
return "System";
default:
assert(0);
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/dmd/json.d
Expand Up @@ -293,7 +293,7 @@ public:

void property(const(char)* name, LINK linkage)
{
switch (linkage)
final switch (linkage)
{
case LINK.default_:
// Should not be printed
Expand All @@ -303,6 +303,10 @@ public:
// Should not be printed
//property(name, "d");
break;
case LINK.system:
// Should not be printed
//property(name, "system");
break;
case LINK.c:
property(name, "c");
break;
Expand All @@ -315,8 +319,9 @@ public:
case LINK.pascal:
property(name, "pascal");
break;
default:
assert(false);
case LINK.objc:
property(name, "objc");
break;
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/dmd/target.d
Expand Up @@ -433,13 +433,19 @@ struct Target
*/
extern (C++) static void prefixName(OutBuffer* buf, LINK linkage)
{
switch (linkage)
final switch (linkage)
{
case LINK.cpp:
if (global.params.isOSX)
buf.prependbyte('_');
break;
default:
case LINK.default_:
case LINK.d:
case LINK.c:
case LINK.windows:
case LINK.pascal:
case LINK.objc:
case LINK.system:
break;
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/dmd/tocsym.d
Expand Up @@ -243,7 +243,7 @@ Symbol *toSymbol(Dsymbol s)
}

mangle_t m = 0;
switch (vd.linkage)
final switch (vd.linkage)
{
case LINK.windows:
m = global.params.is64bit ? mTYman_c : mTYman_std;
Expand All @@ -265,7 +265,8 @@ Symbol *toSymbol(Dsymbol s)
s.Sflags |= SFLpublic;
m = mTYman_d;
break;
default:
case LINK.default_:
case LINK.system:
printf("linkage = %d, vd = %s %s @ [%s]\n",
vd.linkage, vd.kind(), vd.toChars(), vd.loc.toChars());
assert(0);
Expand Down Expand Up @@ -341,7 +342,7 @@ Symbol *toSymbol(Dsymbol s)
}
else
{
switch (fd.linkage)
final switch (fd.linkage)
{
case LINK.windows:
t.Tmangle = global.params.is64bit ? mTYman_c : mTYman_std;
Expand Down Expand Up @@ -375,7 +376,8 @@ Symbol *toSymbol(Dsymbol s)
}
t.Tmangle = mTYman_d;
break;
default:
case LINK.default_:
case LINK.system:
printf("linkage = %d\n", fd.linkage);
assert(0);
}
Expand Down
5 changes: 3 additions & 2 deletions src/dmd/toobj.d
Expand Up @@ -1341,7 +1341,7 @@ void toObjFile(Dsymbol ds, bool multiobj)
*/
static mangle_t mangle(const VarDeclaration vd)
{
switch (vd.linkage)
final switch (vd.linkage)
{
case LINK.windows:
return global.params.is64bit ? mTYman_c : mTYman_std;
Expand All @@ -1359,7 +1359,8 @@ void toObjFile(Dsymbol ds, bool multiobj)
case LINK.cpp:
return mTYman_d;

default:
case LINK.default_:
case LINK.system:
printf("linkage = %d\n", vd.linkage);
assert(0);
}
Expand Down

0 comments on commit 6517be5

Please sign in to comment.