Skip to content

Commit

Permalink
Make SC a proper D enum
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel authored and dlang-bot committed Aug 31, 2022
1 parent 1b78c63 commit d610159
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 74 deletions.
9 changes: 1 addition & 8 deletions compiler/src/dmd/backend/cc.d
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ enum IDOHD = 4+1+int.sizeof*3; // max amount of overhead to ID added by
enum STRMAX = 65_000; // max length of string (determined by
// max ph size)

//enum SC;
struct Thunk
{ Symbol *sfunc;
Symbol *sthunk;
Expand Down Expand Up @@ -412,12 +411,6 @@ enum
// done on it, so it is stack and register variables.)
//char symbol_isintab(Symbol *s) { return sytab[s.Sclass] & SCSS; }

//version (Windows)
alias enum_SC = char;
//else
// alias SC enum_SC;


/******************************************
* Basic blocks:
* Basic blocks are a linked list of all the basic blocks
Expand Down Expand Up @@ -1402,7 +1395,7 @@ struct Symbol
targ_size_t Slocalgotoffset;
//#endif

enum_SC Sclass; // storage class (SCxxxx)
SC Sclass; // storage class (SCxxxx)
char Sfl; // flavor (FLxxxx)
SYMFLGS Sflags; // flag bits (SFLxxxx)

Expand Down
137 changes: 90 additions & 47 deletions compiler/src/dmd/backend/cdef.d
Original file line number Diff line number Diff line change
Expand Up @@ -927,55 +927,98 @@ alias SYMFLGS = uint;
/**********************************
* Storage classes
*/

alias SC = int;
enum
enum SC : ubyte
{
SCunde, // undefined
SCauto, // automatic (stack)
SCstatic, // statically allocated
SCthread, // thread local
SCextern, // external
SCregister, // registered variable
SCpseudo, // pseudo register variable
SCglobal, // top level global definition
SCcomdat, // initialized common block
SCparameter, // function parameter
SCregpar, // function register parameter
SCfastpar, // function parameter passed in register
SCshadowreg, // function parameter passed in register, shadowed on stack
SCtypedef, // type definition
SCexplicit, // explicit
SCmutable, // mutable
SClabel, // goto label
SCstruct, // struct/class/union tag name
SCenum, // enum tag name
SCfield, // bit field of struct or union
SCconst, // constant integer
SCmember, // member of struct or union
SCanon, // member of anonymous union
SCinline, // for inline functions
SCsinline, // for static inline functions
SCeinline, // for extern inline functions
SCoverload, // for overloaded function names
SCfriend, // friend of a class
SCvirtual, // virtual function
SClocstat, // static, but local to a function
SCtemplate, // class template
SCfunctempl, // function template
SCftexpspec, // function template explicit specialization
SClinkage, // function linkage symbol
SCpublic, // generate a pubdef for this
SCcomdef, // uninitialized common block
SCbprel, // variable at fixed offset from frame pointer
SCnamespace, // namespace
SCalias, // alias to another symbol
SCfuncalias, // alias to another function symbol
SCmemalias, // alias to base class member
SCstack, // offset from stack pointer (not frame pointer)
SCadl, // list of ADL symbols for overloading
SCMAX
unde, /// undefined
auto_, /// automatic (stack)
static_, /// statically allocated
thread, /// thread local
extern_, /// external
register, /// registered variable
pseudo, /// pseudo register variable
global, /// top level global definition
comdat, /// initialized common block
parameter, /// function parameter
regpar, /// function register parameter
fastpar, /// function parameter passed in register
shadowreg, /// function parameter passed in register, shadowed on stack
typedef_, /// type definition
explicit, /// explicit
mutable, /// mutable
label, /// goto label
struct_, /// struct/class/union tag name
enum_, /// enum tag name
field, /// bit field of struct or union
const_, /// constant integer
member, /// member of struct or union
anon, /// member of anonymous union
inline, /// for inline functions
sinline, /// for static inline functions
einline, /// for extern inline functions
overload, /// for overloaded function names
friend, /// friend of a class
virtual, /// virtual function
locstat, /// static, but local to a function
template_, /// class template
functempl, /// function template
ftexpspec, /// function template explicit specialization
linkage, /// function linkage symbol
public_, /// generate a pubdef for this
comdef, /// uninitialized common block
bprel, /// variable at fixed offset from frame pointer
namespace, /// namespace
alias_, /// alias to another symbol
funcalias, /// alias to another function symbol
memalias, /// alias to base class member
stack, /// offset from stack pointer (not frame pointer)
adl, /// list of ADL symbols for overloading
}

enum SCunde = SC.unde;
enum SCauto = SC.auto_;
enum SCstatic = SC.static_;
enum SCthread = SC.thread;
enum SCextern = SC.extern_;
enum SCregister = SC.register;
enum SCpseudo = SC.pseudo;
enum SCglobal = SC.global;
enum SCcomdat = SC.comdat;
enum SCparameter = SC.parameter;
enum SCregpar = SC.regpar;
enum SCfastpar = SC.fastpar;
enum SCshadowreg = SC.shadowreg;
enum SCtypedef = SC.typedef_;
enum SCexplicit = SC.explicit;
enum SCmutable = SC.mutable;
enum SClabel = SC.label;
enum SCstruct = SC.struct_;
enum SCenum = SC.enum_;
enum SCfield = SC.field;
enum SCconst = SC.const_;
enum SCmember = SC.member;
enum SCanon = SC.anon;
enum SCinline = SC.inline;
enum SCsinline = SC.sinline;
enum SCeinline = SC.einline;
enum SCoverload = SC.overload;
enum SCfriend = SC.friend;
enum SCvirtual = SC.virtual;
enum SClocstat = SC.locstat;
enum SCtemplate = SC.template_;
enum SCfunctempl = SC.functempl;
enum SCftexpspec = SC.ftexpspec;
enum SClinkage = SC.linkage;
enum SCpublic = SC.public_;
enum SCcomdef = SC.comdef;
enum SCbprel = SC.bprel;
enum SCnamespace = SC.namespace;
enum SCalias = SC.alias_;
enum SCfuncalias = SC.funcalias;
enum SCmemalias = SC.memalias;
enum SCstack = SC.stack;
enum SCadl = SC.adl;

enum SCMAX = SC.max + 1;

int ClassInline(int c) { return c == SCinline || c == SCsinline || c == SCeinline; }
int SymInline(Symbol* s) { return ClassInline(s.Sclass); }
2 changes: 1 addition & 1 deletion compiler/src/dmd/backend/cod2.d
Original file line number Diff line number Diff line change
Expand Up @@ -4675,7 +4675,7 @@ void cdrelconst(ref CodeBuilder cdb,elem *e,regm_t *pretregs)
if (s.Sfl == FLdatseg)
{ assert(0);
}
sclass = cast(SC) s.Sclass;
sclass = s.Sclass;
const ety = tybasic(s.ty());
if ((tyfarfunc(ety) || ety == TYifunc) &&
(sclass == SCextern || ClassInline(sclass) || config.wflags & WFthunk)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/backend/elpicpie.d
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ private elem *el_picvar_OSX(Symbol *s)
elem *e;
int x;

//printf("el_picvar(s = '%s') Sclass = %s\n", s.Sident.ptr, class_str(cast(SC) s.Sclass));
//printf("el_picvar(s = '%s') Sclass = %s\n", s.Sident.ptr, class_str(s.Sclass));
//symbol_print(s);
symbol_debug(s);
type_debug(s.Stype);
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dmd/backend/global.d
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ void symbol_term();
const(char)* symbol_ident(const Symbol *s);
Symbol *symbol_calloc(const(char)* id);
Symbol *symbol_calloc(const(char)* id, uint len);
Symbol *symbol_name(const(char)* name, int sclass, type *t);
Symbol *symbol_name(const(char)* name, uint len, int sclass, type *t);
Symbol *symbol_generate(int sclass, type *t);
Symbol *symbol_name(const(char)* name, SC sclass, type *t);
Symbol *symbol_name(const(char)* name, uint len, SC sclass, type *t);
Symbol *symbol_generate(SC sclass, type *t);
Symbol *symbol_genauto(type *t);
Symbol *symbol_genauto(elem *e);
Symbol *symbol_genauto(tym_t ty);
Expand Down Expand Up @@ -524,5 +524,5 @@ void dwarf_CFA_args_size(size_t sz);
elem *exp_isconst();
elem *lnx_builtin_next_arg(elem *efunc,list_t arglist);
char *lnx_redirect_funcname(const(char)*);
void lnx_funcdecl(Symbol *,SC,enum_SC,int);
void lnx_funcdecl(Symbol*, SC, SC, int);
int lnx_attributes(int hinttype,const void *hint, type **ptyp, tym_t *ptym,int *pattrtype);
4 changes: 2 additions & 2 deletions compiler/src/dmd/backend/out.d
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ version (SCPP)

default:
symbol_print(s);
printf("%s\n", class_str(cast(SC) s.Sclass));
printf("%s\n", class_str(s.Sclass));
assert(0);
}
else
Expand Down Expand Up @@ -1164,7 +1164,7 @@ version (SCPP)
{
SC scvtbl;

scvtbl = cast(SC) ((config.flags2 & CFG2comdat) ? SCcomdat : SCglobal);
scvtbl = ((config.flags2 & CFG2comdat) ? SCcomdat : SCglobal);
n2_genvtbl(stag,scvtbl,1);
n2_genvbtbl(stag,scvtbl,1);
if (config.exe & EX_windos)
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dmd/backend/symbol.d
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ version (COMPILE)
{
if (!s) return;
printf("symbol %p '%s'\n ",s,s.Sident.ptr);
printf(" Sclass = %s ", class_str(cast(SC) s.Sclass));
printf(" Sclass = %s ", class_str(s.Sclass));
printf(" Ssymnum = %d",cast(int)s.Ssymnum);
printf(" Sfl = "); WRFL(cast(FL) s.Sfl);
printf(" Sseg = %d\n",s.Sseg);
Expand Down Expand Up @@ -359,16 +359,16 @@ debug
*/

@trusted
Symbol * symbol_name(const(char)* name,int sclass,type *t)
Symbol * symbol_name(const(char)* name, SC sclass,type *t)
{
return symbol_name(name, cast(uint)strlen(name), sclass, t);
}

Symbol * symbol_name(const(char)* name, uint len, int sclass, type *t)
Symbol * symbol_name(const(char)* name, uint len, SC sclass, type *t)
{
type_debug(t);
Symbol *s = symbol_calloc(name, len);
s.Sclass = cast(char) sclass;
s.Sclass = sclass;
s.Stype = t;
s.Stype.Tcount++;

Expand Down Expand Up @@ -404,7 +404,7 @@ version (SCPP_HTOD)
*/

@trusted
Symbol * symbol_generate(int sclass,type *t)
Symbol * symbol_generate(SC sclass,type *t)
{
__gshared int tmpnum;
char[4 + tmpnum.sizeof * 3 + 1] name;
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/objc_glue.d
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ static:
*
* Allows to pass the name of the symbol as a D string.
*/
Symbol* symbolName(const(char)[] name, int sclass, type* t)
Symbol* symbolName(const(char)[] name, SC sclass, type* t)
{
return symbol_name(name.ptr, cast(uint) name.length, sclass, t);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/tocsym.d
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extern (C++):
* Helper
*/

Symbol *toSymbolX(Dsymbol ds, const(char)* prefix, int sclass, type *t, const(char)* suffix)
Symbol *toSymbolX(Dsymbol ds, const(char)* prefix, SC sclass, type *t, const(char)* suffix)
{
//printf("Dsymbol::toSymbolX('%s')\n", prefix);
import dmd.common.string : SmallBuffer;
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dmd/toobj.d
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void toObjFile(Dsymbol ds, bool multiobj)

assert(cd.semanticRun >= PASS.semantic3done); // semantic() should have been run to completion

enum_SC scclass = SCcomdat;
SC scclass = SCcomdat;

// Put out the members
/* There might be static ctors in the members, and they cannot
Expand Down Expand Up @@ -697,7 +697,7 @@ void toObjFile(Dsymbol ds, bool multiobj)
}
else
{
enum_SC scclass = SCglobal;
SC scclass = SCglobal;
if (ed.isInstantiated())
scclass = SCcomdat;

Expand Down Expand Up @@ -1197,7 +1197,7 @@ private size_t emitVtbl(ref DtBuilder dtb, BaseClass *b, ref FuncDeclarations bv
private void genClassInfoForClass(ClassDeclaration cd, Symbol* sinit)
{
// Put out the ClassInfo, which will be the __ClassZ symbol in the object file
enum_SC scclass = SCcomdat;
SC scclass = SCcomdat;
cd.csym.Sclass = scclass;
cd.csym.Sfl = FLdata;

Expand Down Expand Up @@ -1438,7 +1438,7 @@ Louter:
*/
private void genClassInfoForInterface(InterfaceDeclaration id)
{
enum_SC scclass = SCcomdat;
SC scclass = SCcomdat;

// Put out the ClassInfo
id.csym.Sclass = scclass;
Expand Down

0 comments on commit d610159

Please sign in to comment.