Merge the 2.063 frontend.

This commit is contained in:
David Nadlinger
2013-06-12 20:16:37 +02:00
parent 981a6af17e
commit 292caa1438
90 changed files with 10179 additions and 8105 deletions
+19 -2
View File
@@ -51,14 +51,15 @@ bool initFPU()
int old_cw = _control87(_MCW_EM | _PC_64 | _RC_NEAR,
_MCW_EM | _MCW_PC | _MCW_RC);
#endif
_set_output_format(_TWO_DIGIT_EXPONENT);
return true;
}
static bool doInitFPU = initFPU();
#ifndef _WIN64
extern "C"
{
#ifndef _WIN64
double ld_read(const longdouble* pthis)
{
double res;
@@ -70,6 +71,8 @@ double ld_read(const longdouble* pthis)
}
return res;
}
#endif // !_WIN64
long long ld_readll(const longdouble* pthis)
{
#if 1
@@ -126,6 +129,7 @@ unsigned long long ld_readull(const longdouble* pthis)
#endif
}
#ifndef _WIN64
void ld_set(longdouble* pthis, double d)
{
__asm
@@ -157,9 +161,9 @@ void ld_setull(longdouble* pthis, unsigned long long d)
fstp tbyte ptr [eax]
}
}
#endif // !_WIN64
} // extern "C"
#endif // !_WIN64
longdouble ldexpl(longdouble ld, int exp)
{
@@ -519,6 +523,13 @@ size_t ld_sprint(char* str, int fmt, longdouble x)
// fmt is 'a','A','f' or 'g'
if(fmt != 'a' && fmt != 'A')
{
if (ldouble((unsigned long long)x) == x)
{ // ((1.5 -> 1 -> 1.0) == 1.5) is false
// ((1.0 -> 1 -> 1.0) == 1.0) is true
// see http://en.cppreference.com/w/cpp/io/c/fprintf
char format[] = {'%', '#', 'L', fmt, 0};
return sprintf(str, format, ld_read(&x));
}
char format[] = { '%', fmt, 0 };
return sprintf(str, format, ld_read(&x));
}
@@ -580,6 +591,12 @@ static bool unittest()
ld_sprint(buffer, 'a', ld_pi);
assert(strcmp(buffer, "0x1.921fb54442d1846ap+1") == 0);
ld_sprint(buffer, 'g', ldouble(2.0));
assert(strcmp(buffer, "2.00000") == 0);
ld_sprint(buffer, 'g', ldouble(1234567.89));
assert(strcmp(buffer, "1.23457e+06") == 0);
longdouble ldb = ldouble(0.4);
long long b = ldb;
assert(b == 0);
+14 -3
View File
@@ -42,9 +42,20 @@ typedef volatile long double volatile_longdouble;
inline size_t ld_sprint(char* str, int fmt, longdouble x)
{
char sfmt[4] = "%Lg";
sfmt[2] = fmt;
return sprintf(str, sfmt, x);
if (((longdouble)(unsigned long long)x) == x)
{ // ((1.5 -> 1 -> 1.0) == 1.5) is false
// ((1.0 -> 1 -> 1.0) == 1.0) is true
// see http://en.cppreference.com/w/cpp/io/c/fprintf
char sfmt[5] = "%#Lg";
sfmt[3] = fmt;
return sprintf(str, sfmt, x);
}
else
{
char sfmt[4] = "%Lg";
sfmt[2] = fmt;
return sprintf(str, sfmt, x);
}
}
#if __MINGW32__
+12 -33
View File
@@ -987,6 +987,8 @@ void File::mark()
int File::read()
{
if (len)
return 0; // already read the file
#if POSIX
off_t size;
ssize_t numread;
@@ -1064,7 +1066,7 @@ err1:
name = this->name->toChars();
h = CreateFileA(name,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,0);
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,NULL);
if (h == INVALID_HANDLE_VALUE)
goto err1;
@@ -1642,6 +1644,15 @@ void OutBuffer::prependbyte(unsigned b)
offset++;
}
void OutBuffer::writewchar(unsigned w)
{
#if _WIN32
writeword(w);
#else
write4(w);
#endif
}
void OutBuffer::writeword(unsigned w)
{
if (doindent && linehead
@@ -1740,36 +1751,6 @@ void OutBuffer::align(size_t size)
fill0(nbytes);
}
////////////////////////////////////////////////////////////////
// The compiler shipped with Visual Studio 2005 (and possible
// other versions) does not support C99 printf format specfiers
// such as %z and %j
#if 0 && _MSC_VER
using std::string;
using std::wstring;
template<typename S>
inline void
search_and_replace(S& str, const S& what, const S& replacement)
{
assert(!what.empty());
size_t pos = str.find(what);
while (pos != S::npos)
{
str.replace(pos, what.size(), replacement);
pos = str.find(what, pos + replacement.size());
}
}
#define WORKAROUND_C99_SPECIFIERS_BUG(S,tmp,f) \
S tmp = f; \
search_and_replace(fmt, S("%z"), S("%l")); \
search_and_replace(fmt, S("%j"), S("%l")); \
f = tmp.c_str();
#else
#define WORKAROUND_C99_SPECIFIERS_BUG(S,tmp,f)
#endif
void OutBuffer::vprintf(const char *format, va_list args)
{
char buffer[128];
@@ -1777,8 +1758,6 @@ void OutBuffer::vprintf(const char *format, va_list args)
unsigned psize;
int count;
WORKAROUND_C99_SPECIFIERS_BUG(string, fmt, format);
p = buffer;
psize = sizeof(buffer);
for (;;)
+1
View File
@@ -258,6 +258,7 @@ struct OutBuffer : Object
void writebyte(unsigned b) { writeByte(b); }
void writeUTF8(unsigned b);
void prependbyte(unsigned b);
void writewchar(unsigned w);
void writeword(unsigned w);
void writeUTF16(unsigned w);
void write4(unsigned w);
+1 -1
View File
@@ -99,7 +99,7 @@ void StringValue::ctor(const char *p, size_t length)
memcpy(this->lstring, p, length * sizeof(char));
}
void StringTable::init(size_t size)
void StringTable::_init(size_t size)
{
table = (void **)mem.calloc(size, sizeof(void *));
tabledim = size;
+2 -6
View File
@@ -24,11 +24,7 @@ struct StringEntry;
// method because the only thing which should be creating these is StringTable.
struct StringValue
{
union
{
void *ptrvalue;
char *string;
};
void *ptrvalue;
private:
size_t length;
@@ -59,7 +55,7 @@ private:
size_t tabledim;
public:
void init(size_t size = 37);
void _init(size_t size = 37);
~StringTable();
StringValue *lookup(const char *s, size_t len);