Skip to content

Commit

Permalink
begin transition to @safe code
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Apr 3, 2021
1 parent b0a5059 commit 5ff59a9
Show file tree
Hide file tree
Showing 43 changed files with 670 additions and 81 deletions.
24 changes: 22 additions & 2 deletions dm/src/dmc/aarray.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Compiler implementation of the
* $(LINK2 http://www.dlang.org, D programming language).
*
* Copyright: Copyright (C) 2000-2020 by The D Language Foundation, All Rights Reserved
* Copyright: Copyright (C) 2000-2021 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 http://www.digitalmars.com, Walter Bright), Dave Fladebo
* License: Distributed under the Boost Software License, Version 1.0.
* http://www.boost.org/LICENSE_1_0.txt
Expand All @@ -21,6 +21,7 @@ version (MARS)
import dmd.root.hash;

nothrow:
@safe:

/*********************
* This is the "bucket" used by the AArray.
Expand Down Expand Up @@ -53,6 +54,7 @@ nothrow:
/****
* Frees all the data used by AArray
*/
@trusted
void destroy()
{
if (buckets)
Expand Down Expand Up @@ -89,7 +91,7 @@ nothrow:
* Returns:
* pointer to Value
*/

@trusted
Value* get(Key* pkey)
{
//printf("AArray::get()\n");
Expand Down Expand Up @@ -150,6 +152,7 @@ nothrow:
* !=null in aa, return pointer to value
*/

@trusted
Value* isIn(Key* pkey)
{
//printf("AArray.isIn(), .length = %d, .ptr = %p\n", nodes, buckets.ptr);
Expand Down Expand Up @@ -183,6 +186,7 @@ nothrow:
* pKey = pointer to key
*/

@trusted
void del(Key *pkey)
{
if (!nodes)
Expand Down Expand Up @@ -214,6 +218,7 @@ nothrow:
* malloc'd array of keys
*/

@trusted
Key[] keys()
{
if (!nodes)
Expand All @@ -240,6 +245,7 @@ nothrow:
* malloc'd array of values
*/

@trusted
Value[] values()
{
if (!nodes)
Expand All @@ -265,6 +271,7 @@ nothrow:
* Rehash an array.
*/

@trusted
void rehash()
{
//printf("Rehash\n");
Expand Down Expand Up @@ -313,6 +320,7 @@ nothrow:
* 0 : no entries in aa, or all dg() calls returned 0
*/

@trusted
int apply(applyDg dg)
{
if (!nodes)
Expand Down Expand Up @@ -421,6 +429,7 @@ nothrow:
}
}

@trusted
static bool equals(Key* pk1, Key* pk2)
{
auto buf1 = *pk1;
Expand All @@ -437,19 +446,22 @@ nothrow:
alias AA = AArray!(TinfoChars, uint);
AA aa;

@trusted
static AAchars* create()
{
auto a = cast(AAchars*)calloc(1, AAchars.sizeof);
assert(a);
return a;
}

@trusted
static void destroy(AAchars* aac)
{
aac.aa.destroy();
free(aac);
}

@trusted
uint* get(const(char)* s, uint len)
{
auto buf = s[0 .. len];
Expand All @@ -475,6 +487,7 @@ nothrow:

ubyte** pbase;

@trusted
hash_t getHash(Key* pk)
{
version (MARS)
Expand All @@ -492,6 +505,7 @@ nothrow:
}
}

@trusted
bool equals(Key* pk1, Key* pk2)
{
const len1 = pk1.end - pk1.start;
Expand All @@ -511,6 +525,7 @@ nothrow:
alias AA = AArray!(TinfoPair, uint);
AA aa;

@trusted
static AApair* create(ubyte** pbase)
{
auto a = cast(AApair*)calloc(1, AApair.sizeof);
Expand All @@ -519,12 +534,14 @@ nothrow:
return a;
}

@trusted
static void destroy(AApair* aap)
{
aap.aa.destroy();
free(aap);
}

@trusted
uint* get(uint start, uint end)
{
auto p = Pair(start, end);
Expand All @@ -544,6 +561,7 @@ nothrow:
alias AA = AArray!(TinfoPair, Pair);
AA aa;

@trusted
static AApair* create(ubyte** pbase)
{
auto a = cast(AApair*)calloc(1, AApair.sizeof);
Expand All @@ -552,12 +570,14 @@ nothrow:
return a;
}

@trusted
static void destroy(AApair* aap)
{
aap.aa.destroy();
free(aap);
}

@trusted
Pair* get(uint start, uint end)
{
auto p = Pair(start, end);
Expand Down
8 changes: 8 additions & 0 deletions dm/src/dmc/barray.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import core.stdc.stdlib;
import core.stdc.string;

nothrow:
@safe:

extern (C++): private void err_nomem();

Expand All @@ -24,11 +25,14 @@ extern (C++): private void err_nomem();
*/
struct Barray(T)
{
@safe:

/**********************
* Set useable length of array.
* Params:
* length = minimum number of elements in array
*/
@trusted
void setLength(size_t length)
{
static void enlarge(ref Barray barray, size_t length)
Expand Down Expand Up @@ -80,6 +84,7 @@ struct Barray(T)
* Returns:
* pointer to appended element
*/
@trusted
T* push()
{
const i = length;
Expand Down Expand Up @@ -108,6 +113,7 @@ struct Barray(T)
/******************
* Release all memory used.
*/
@trusted
void dtor()
{
free(array.ptr);
Expand Down Expand Up @@ -150,6 +156,8 @@ unittest

struct Rarray(T)
{
@safe:

/*******************
* Append an uninitialized element of T to array.
* This leaves allocations used by T intact.
Expand Down
26 changes: 25 additions & 1 deletion dm/src/dmc/cc.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* $(LINK2 http://www.dlang.org, D programming language).
*
* Copyright: Copyright (C) 1985-1998 by Symantec
* Copyright (C) 2000-2020 by The D Language Foundation, All Rights Reserved
* Copyright (C) 2000-2021 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 http://www.digitalmars.com, Walter Bright)
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 /~https://github.com/dlang/dmd/blob/master/src/dmd/backend/cc.d, backend/_cc.d)
Expand All @@ -25,6 +25,7 @@ import dmd.backend.type;
extern (C++):
@nogc:
nothrow:
@safe:

enum GENOBJ = 1; // generating .obj file

Expand Down Expand Up @@ -74,7 +75,10 @@ static if (MEMMODELS == 1)
}
else
{
@trusted
bool LARGEDATA() { return (config.memmodel & 6) != 0; }

@trusted
bool LARGECODE() { return (config.memmodel & 5) != 0; }
}

Expand Down Expand Up @@ -167,6 +171,7 @@ alias enum_TK = ubyte;

__gshared Config config;

@trusted
uint CPP() { return config.flags3 & CFG3cpp; }


Expand Down Expand Up @@ -362,10 +367,16 @@ struct Pstate
// than STmaxsequence
}

@trusted
void funcsym_p(Funcsym* fp) { pstate.STfuncsym_p = fp; }

@trusted
Funcsym* funcsym_p() { return pstate.STfuncsym_p; }

@trusted
stflags_t preprocessor() { return pstate.STflags & PFLpreprocessor; }

@trusted
stflags_t inline_asm() { return pstate.STflags & (PFLmasm | PFLbasm); }

extern __gshared Pstate pstate;
Expand Down Expand Up @@ -610,10 +621,15 @@ nothrow:
void appendSucc(block* b) { list_append(&this.Bsucc, b); }
void prependSucc(block* b) { list_prepend(&this.Bsucc, b); }
int numSucc() { return list_nitems(this.Bsucc); }

@trusted
block* nthSucc(int n) { return cast(block*)list_ptr(list_nth(Bsucc, n)); }

@trusted
void setNthSucc(int n, block *b) { list_nth(Bsucc, n).ptr = b; }
}

@trusted
inout(block)* list_block(inout list_t lst) { return cast(inout(block)*)list_ptr(lst); }

/** Basic block control flow operators. **/
Expand Down Expand Up @@ -882,6 +898,7 @@ struct mptr_t
mptr_flags_t MPflags;
}

@trusted
inout(mptr_t)* list_mptr(inout(list_t) lst) { return cast(inout(mptr_t)*) list_ptr(lst); }


Expand Down Expand Up @@ -1143,8 +1160,13 @@ struct struct_t
* Symbol Table
*/

@trusted
inout(Symbol)* list_symbol(inout list_t lst) { return cast(inout(Symbol)*) list_ptr(lst); }

@trusted
void list_setsymbol(list_t lst, Symbol* s) { lst.ptr = s; }

@trusted
inout(Classsym)* list_Classsym(inout list_t lst) { return cast(inout(Classsym)*) list_ptr(lst); }

enum
Expand Down Expand Up @@ -1517,6 +1539,7 @@ enum
* Returns:
* exception method for f
*/
@trusted
EHmethod ehmethod(Symbol *f)
{
return f.Sfunc.Fflags3 & Feh_none ? EHmethod.EH_NONE : config.ehmethod;
Expand Down Expand Up @@ -1696,6 +1719,7 @@ struct Srcfiles
uint idx; // # used in array
}

@trusted
Sfile* sfile(uint fi)
{
import dmd.backend.global : srcfiles;
Expand Down
6 changes: 4 additions & 2 deletions dm/src/dmc/cgcod.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Top level code for the code generator.
*
* Copyright: Copyright (C) 1985-1998 by Symantec
* Copyright (C) 2000-2020 by The D Language Foundation, All Rights Reserved
* Copyright (C) 2000-2021 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 http://www.digitalmars.com, Walter Bright)
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 /~https://github.com/dlang/dmd/blob/master/src/dmd/backend/cgcod.d, backend/cgcod.d)
Expand Down Expand Up @@ -1826,11 +1826,13 @@ int numbitsset(regm_t regm)
* of the first register that fits.
*/

@trusted
reg_t findreg(regm_t regm)
{
return findreg(regm, __LINE__, __FILE__);
}

@trusted
reg_t findreg(regm_t regm, int line, const(char)* file)
{
debug
Expand Down Expand Up @@ -1861,7 +1863,7 @@ reg_t findreg(regm_t regm, int line, const(char)* file)
}

/***************
* Free element (but not it's leaves! (assume they are already freed))
* Free element (but not its leaves! (assume they are already freed))
* Don't decrement Ecount! This is so we can detect if the common subexp
* has already been evaluated.
* If common subexpression is not required anymore, eliminate
Expand Down
Loading

0 comments on commit 5ff59a9

Please sign in to comment.