Skip to content

Commit

Permalink
Fix build for DMC/Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuclaw committed Nov 4, 2018
1 parent 371fae3 commit 03865b9
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/cppmangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class CppMangleVisitor : public Visitor
{
Objects components; // array of components available for substitution
OutBuffer *buf; // append the mangling to buf[]
public:
Loc loc; // location for use in error messages

public:
// Write <seq-id> to buf
void write_seq_id(size_t i)
{
Expand Down
4 changes: 2 additions & 2 deletions src/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#endif

#include "errors.h"
#include "outbuffer.h"
#include "rmem.h"
#include "root/outbuffer.h"
#include "root/rmem.h"

enum COLOR
{
Expand Down
2 changes: 1 addition & 1 deletion src/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "globals.h"

#include "filename.h"
#include "root/filename.h"

Global global;

Expand Down
3 changes: 2 additions & 1 deletion src/hdrgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2332,7 +2332,8 @@ class PrettyPrintVisitor : public Visitor
(ie, 8 chars more than mantissa). Plus one for trailing \0.
Plus one for rounding. */
const size_t BUFFER_LEN = sizeof(value) * 3 + 8 + 1 + 1;
char buffer[BUFFER_LEN] = {};
char buffer[BUFFER_LEN];
memset(buffer, 0, BUFFER_LEN);
CTFloat::sprint(buffer, 'g', value);
assert(strlen(buffer) < BUFFER_LEN);

Expand Down
5 changes: 3 additions & 2 deletions src/inline.c
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ static void expandInline(Loc callLoc, FuncDeclaration *fd, FuncDeclaration *pare
Expression *eret, Expression *ethis, Expressions *arguments, bool asStatements,
Expression **eresult, Statement **sresult, bool *again)
{
InlineDoState ids = {};
InlineDoState ids;
TypeFunction *tf = (TypeFunction*)fd->type;

#define EXPANDINLINE_LOG 0
Expand Down Expand Up @@ -1925,7 +1925,8 @@ Expression *inlineCopy(Expression *e, Scope *sc)
e->error("cannot inline default argument %s", e->toChars());
return new ErrorExp();
}
InlineDoState ids = {};
InlineDoState ids;
memset(&ids, 0, sizeof(ids));
ids.parent = sc->parent;
return doInline(e, &ids);
}
Expand Down
4 changes: 2 additions & 2 deletions src/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
#define HAS_POSIX_SPAWN 0
#endif

#include "root.h"
#include "root/root.h"

#include "mars.h"

#include "rmem.h"
#include "root/rmem.h"

#include "arraytypes.h"

Expand Down
12 changes: 6 additions & 6 deletions src/mars.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
#include <errno.h>
#endif

#include "rmem.h"
#include "root.h"
#include "async.h"
#include "root/rmem.h"
#include "root/root.h"
#include "root/async.h"
#include "target.h"
#include "file.h"
#include "filename.h"
#include "stringtable.h"
#include "root/file.h"
#include "root/filename.h"
#include "root/stringtable.h"

#include "mars.h"
#include "module.h"
Expand Down
31 changes: 17 additions & 14 deletions src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -9333,20 +9333,23 @@ bool Parameter::isCovariantScope(bool returnByRef, StorageClass from, StorageCla
static unsigned buildSR(bool returnByRef, StorageClass stc)
{
unsigned result;
switch (stc & (STCref | STCscope | STCreturn))
{
case 0: result = SRNone; break;
case STCref: result = SRRef; break;
case STCscope: result = SRScope; break;
case STCreturn | STCref: result = SRReturnRef; break;
case STCreturn | STCscope: result = SRReturnScope; break;
case STCref | STCscope: result = SRRefScope; break;
case STCreturn | STCref | STCscope:
result = returnByRef ? SRReturnRef_Scope : SRRef_ReturnScope;
break;
default:
assert(0);
}
StorageClass stc2 = stc & (STCref | STCscope | STCreturn);
if (stc2 == 0)
result = SRNone;
else if (stc2 == STCref)
result = SRRef;
else if (stc2 == STCscope)
result = SRScope;
else if (stc2 == (STCscope | STCreturn))
result = SRReturnScope;
else if (stc2 == (STCref | STCreturn))
result = SRReturnRef;
else if (stc2 == (STCscope | STCref))
result = SRRefScope;
else if (stc2 == (STCscope | STCref | STCreturn))
result = returnByRef ? SRReturnRef_Scope : SRRef_ReturnScope;
else
assert(0);
return result;
}

Expand Down
8 changes: 0 additions & 8 deletions src/root/checkedint.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@
#include "dsystem.h"
#include "checkedint.h"

#ifdef __DMC__
#undef UINT64_MAX
#define UINT64_MAX 18446744073709551615ULL
#undef UINT32_MAX
#define UINT32_MAX 4294967295U
#endif



/*******************************
* Add two signed integers, checking for overflow.
Expand Down
8 changes: 8 additions & 0 deletions src/root/dsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,11 @@
#elif __MINGW32__
#include <malloc.h>
#endif

// If not present, dmc will error 'number is not representable'.
#ifdef __DMC__
#undef UINT64_MAX
#define UINT64_MAX 18446744073709551615ULL
#undef UINT32_MAX
#define UINT32_MAX 4294967295U
#endif
69 changes: 67 additions & 2 deletions src/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@
* https://github.com/D-Programming-Language/dmd/blob/master/src/target.c
*/

#include <assert.h>
#include "root/dsystem.h"

#if defined(__GNUC__) || defined(__clang__)
#include <limits> // for std::numeric_limits
#else
#include <math.h>
#include <float.h>
#endif

#include "target.h"
#include "aggregate.h"
#include "mars.h"
#include "mtype.h"
#include "outbuffer.h"
#include "root/outbuffer.h"

const char *toCppMangleItanium(Dsymbol *);
const char *cppTypeInfoMangleItanium(Dsymbol *);
Expand Down Expand Up @@ -53,6 +59,7 @@ template <typename T> d_int64 Target::FPTypeProperties<T>::min_10_exp;
template <typename T, typename V>
static void initFloatConstants()
{
#if defined(__GNUC__) || defined(__clang__)
T::max = std::numeric_limits<V>::max();
T::min_normal = std::numeric_limits<V>::min();

Expand All @@ -72,6 +79,64 @@ static void initFloatConstants()
T::min_exp = std::numeric_limits<V>::min_exponent;
T::max_10_exp = std::numeric_limits<V>::max_exponent10;
T::min_10_exp = std::numeric_limits<V>::min_exponent10;
#else
union
{ unsigned int ui[4];
real_t ld;
} snan = {{ 0, 0xA0000000, 0x7FFF, 0 }};

if (sizeof(V) == sizeof(float))
{
T::max = FLT_MAX;
T::min_normal = FLT_MIN;

T::nan = NAN;
T::snan = snan.ld;
T::infinity = INFINITY;

T::epsilon = FLT_EPSILON;
T::dig = FLT_DIG;
T::mant_dig = FLT_MANT_DIG;
T::max_exp = FLT_MAX_EXP;
T::min_exp = FLT_MIN_EXP;
T::max_10_exp = FLT_MAX_10_EXP;
T::min_10_exp = FLT_MIN_10_EXP;
}
else if (sizeof(V) == sizeof(double))
{
T::max = DBL_MAX;
T::min_normal = DBL_MIN;

T::nan = NAN;
T::snan = snan.ld;
T::infinity = INFINITY;

T::epsilon = DBL_EPSILON;
T::dig = DBL_DIG;
T::mant_dig = DBL_MANT_DIG;
T::max_exp = DBL_MAX_EXP;
T::min_exp = DBL_MIN_EXP;
T::max_10_exp = DBL_MAX_10_EXP;
T::min_10_exp = DBL_MIN_10_EXP;
}
else
{
T::max = LDBL_MAX;
T::min_normal = LDBL_MIN;

T::nan = NAN;
T::snan = snan.ld;
T::infinity = INFINITY;

T::epsilon = LDBL_EPSILON;
T::dig = LDBL_DIG;
T::mant_dig = LDBL_MANT_DIG;
T::max_exp = LDBL_MAX_EXP;
T::min_exp = LDBL_MIN_EXP;
T::max_10_exp = LDBL_MAX_10_EXP;
T::min_10_exp = LDBL_MIN_10_EXP;
}
#endif
}

void Target::_init()
Expand Down

0 comments on commit 03865b9

Please sign in to comment.