Mercurial > projects > ddmd
diff dmd/expression/Util.d @ 129:010eb8f0e18d
further work on dmd test suite
author | korDen |
---|---|
date | Sun, 05 Sep 2010 15:32:22 +0400 |
parents | 1765f3ef917d |
children | 60bb0fe4563e |
line wrap: on
line diff
--- a/dmd/expression/Util.d Sat Sep 04 01:33:05 2010 +0100 +++ b/dmd/expression/Util.d Sun Sep 05 15:32:22 2010 +0400 @@ -67,6 +67,8 @@ import std.stdio : writef; +import core.stdc.math; +import core.stdc.string; /*********************************** * Utility to build a function call out of this reference and argument. @@ -952,11 +954,11 @@ /* Create the TypeTuple corresponding to the types of args[] */ - auto args = new Arguments; + Arguments args = new Arguments; args.setDim(dim); for (size_t i = 0; i < dim; i++) { - auto arg = new Argument(STCin, exps[i].type, null, null); + Argument arg = new Argument(STCin, exps[i].type, null, null); args[i] = arg; } TypeTuple tup = new TypeTuple(args); @@ -1284,14 +1286,14 @@ if (u == arguments.dim) return; - auto arg = arguments[u]; + Argument arg = arguments[u]; if (!arg.type) break; } AggregateDeclaration ad; - auto arg = arguments[0]; + Argument arg = arguments[0]; Type taggr = aggr.type; if (!taggr) return; @@ -1465,7 +1467,7 @@ for (size_t u = 0; u < nparams; u++) { - auto arg = arguments[u]; + Argument arg = arguments[u]; Argument param = Argument.getNth(tf.parameters, u); if (arg.type) { @@ -1558,4 +1560,64 @@ } } } +} + +void realToMangleBuffer(OutBuffer buf, real value) +{ + /* Rely on %A to get portable mangling. + * Must munge result to get only identifier characters. + * + * Possible values from %A => mangled result + * NAN => NAN + * -INF => NINF + * INF => INF + * -0X1.1BC18BA997B95P+79 => N11BC18BA997B95P79 + * 0X1.9P+2 => 19P2 + */ + + if (isnan(value)) + buf.writestring("NAN"); // no -NAN bugs + else + { + char buffer[32]; + int n = sprintf(buffer.ptr, "%LA", value); + assert(n > 0 && n < buffer.sizeof); + for (int i = 0; i < n; i++) + { char c = buffer[i]; + + switch (c) + { + case '-': + buf.writeByte('N'); + break; + + case '+': + case 'X': + case '.': + break; + + case '0': + if (i < 2) + break; // skip leading 0X + default: + buf.writeByte(c); + break; + } + } + } +} + +/******************************** + * Test to see if two reals are the same. + * Regard NaN's as equivalent. + * Regard +0 and -0 as different. + */ + +int RealEquals(real x1, real x2) +{ + return (isnan(x1) && isnan(x2)) || + /* In some cases, the REALPAD bytes get garbage in them, + * so be sure and ignore them. + */ + memcmp(&x1, &x2, REALSIZE - REALPAD) == 0; } \ No newline at end of file