diff --git a/src/cppmangle.c b/src/cppmangle.c index c1f116b2fa60..d2d357667cba 100644 --- a/src/cppmangle.c +++ b/src/cppmangle.c @@ -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 to buf void write_seq_id(size_t i) { diff --git a/src/errors.c b/src/errors.c index 441c4144a213..c1e23de425c3 100644 --- a/src/errors.c +++ b/src/errors.c @@ -23,8 +23,8 @@ #endif #include "errors.h" -#include "outbuffer.h" -#include "rmem.h" +#include "root/outbuffer.h" +#include "root/rmem.h" enum COLOR { diff --git a/src/globals.c b/src/globals.c index ab6c805b0064..ef07ff4220a4 100644 --- a/src/globals.c +++ b/src/globals.c @@ -11,7 +11,7 @@ #include "globals.h" -#include "filename.h" +#include "root/filename.h" Global global; diff --git a/src/hdrgen.c b/src/hdrgen.c index 829711b77f6e..a1f3c12ba728 100644 --- a/src/hdrgen.c +++ b/src/hdrgen.c @@ -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); diff --git a/src/inline.c b/src/inline.c index 65bb96537ea8..ca956b4cf012 100644 --- a/src/inline.c +++ b/src/inline.c @@ -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 @@ -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); } diff --git a/src/link.c b/src/link.c index b22bcbd30424..ffafc85d48cf 100644 --- a/src/link.c +++ b/src/link.c @@ -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" diff --git a/src/mars.c b/src/mars.c index a987777cb74d..0bb27bf2de03 100644 --- a/src/mars.c +++ b/src/mars.c @@ -20,13 +20,13 @@ #include #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" diff --git a/src/mtype.c b/src/mtype.c index e6d5f38b0837..b35b7af3201b 100644 --- a/src/mtype.c +++ b/src/mtype.c @@ -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; } diff --git a/src/root/checkedint.c b/src/root/checkedint.c index 8f05aa98a0f7..392904acf8a3 100644 --- a/src/root/checkedint.c +++ b/src/root/checkedint.c @@ -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. diff --git a/src/root/dsystem.h b/src/root/dsystem.h index 371edf19f928..2abdbb190442 100644 --- a/src/root/dsystem.h +++ b/src/root/dsystem.h @@ -63,3 +63,11 @@ #elif __MINGW32__ #include #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 diff --git a/src/target.c b/src/target.c index 58cfbcb185c6..fd6d3a689466 100644 --- a/src/target.c +++ b/src/target.c @@ -9,14 +9,20 @@ * https://github.com/D-Programming-Language/dmd/blob/master/src/target.c */ -#include +#include "root/dsystem.h" + +#if defined(__GNUC__) || defined(__clang__) #include // for std::numeric_limits +#else +#include +#include +#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 *); @@ -53,6 +59,7 @@ template d_int64 Target::FPTypeProperties::min_10_exp; template static void initFloatConstants() { +#if defined(__GNUC__) || defined(__clang__) T::max = std::numeric_limits::max(); T::min_normal = std::numeric_limits::min(); @@ -72,6 +79,64 @@ static void initFloatConstants() T::min_exp = std::numeric_limits::min_exponent; T::max_10_exp = std::numeric_limits::max_exponent10; T::min_10_exp = std::numeric_limits::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()