# HG changeset patch # User Aziz K?ksal # Date 1204143675 -3600 # Node ID a7320b7cb7dc6f37ae7e8c6a149e92e13993e0ad # Parent b091e8b0ef5c063eb03f2f08624cd94cb311e343 Removed module util/metastrings.d. diff -r b091e8b0ef5c -r a7320b7cb7dc trunk/src/dil/CompilerInfo.d --- a/trunk/src/dil/CompilerInfo.d Wed Feb 27 18:37:13 2008 +0100 +++ b/trunk/src/dil/CompilerInfo.d Wed Feb 27 21:21:15 2008 +0100 @@ -3,50 +3,48 @@ License: GPL3 +/ module dil.CompilerInfo; -import util.metastrings : FormatT = Format, ToString; - -template Pad(char[] str, uint amount) -{ - static if (str.length >= amount) - const char[] Pad = str; - else - const char[] Pad = "0" ~ Pad!(str, amount-1); -} - -template Pad(int num, uint amount) -{ - const char[] Pad = Pad!(ToString!(num), amount); -} version(D2) + /// The major version number of this compiler. + const uint VERSION_MAJOR = 2; +else + /// The major version number of this compiler. + const uint VERSION_MAJOR = 1; + +/// The minor version number of this compiler. +const uint VERSION_MINOR = 0; + +private char[] toString(uint x) { - const VERSION_MAJOR = 2; - const VERSION_MINOR = 0; -} -else -{ - const VERSION_MAJOR = 1; - const VERSION_MINOR = 0; + char[] str; + do + str = cast(char)('0' + (x % 10)) ~ str; + while (x /= 10) + return str; } -const VERSION = FormatT!("%s.%s", VERSION_MAJOR, Pad!(VERSION_MINOR, 3)); -const VENDOR = "dil"; +private char[] toString(uint x, uint pad) +{ + char[] str = toString(x); + if (pad < str.length) + return str; + for (uint i = pad-str.length; i; i--) + str = "0" ~ str; + return str; +} -/// Used in the main help message. -const COMPILED_WITH = __VENDOR__; -/// ditto -const COMPILED_VERSION = FormatT!("%s.%s", __VERSION__/1000, Pad!(__VERSION__%1000, 3)); -/// ditto -const COMPILED_DATE = __TIMESTAMP__; +/// The compiler version formatted as a string. +const char[] VERSION = toString(VERSION_MAJOR)~"."~toString(VERSION_MINOR, 3); +/// The name of the compiler. +const char[] VENDOR = "dil"; /// The global, default alignment size for struct fields. -const DEFAULT_ALIGN_SIZE = 4; +const uint DEFAULT_ALIGN_SIZE = 4; version(DDoc) - const PTR_SIZE = 0; /// The pointer size depending on the platform. + const uint PTR_SIZE = 0; /// The pointer size depending on the platform. else version(X86_64) - const PTR_SIZE = 8; /// Pointer size on 64-bit platforms. + const uint PTR_SIZE = 8; // Pointer size on 64-bit platforms. else - const PTR_SIZE = 4; /// Pointer size on 32-bit platforms. - + const uint PTR_SIZE = 4; // Pointer size on 32-bit platforms. diff -r b091e8b0ef5c -r a7320b7cb7dc trunk/src/main.d --- a/trunk/src/main.d Wed Feb 27 18:37:13 2008 +0100 +++ b/trunk/src/main.d Wed Feb 27 21:21:15 2008 +0100 @@ -404,7 +404,11 @@ char[] helpMain() { - return FormatMsg(MID.HelpMain, VERSION, COMMANDS, COMPILED_WITH, COMPILED_VERSION, COMPILED_DATE); + auto COMPILED_WITH = __VENDOR__; + auto COMPILED_VERSION = Format("{}.{,:d3}", __VERSION__/1000, __VERSION__%1000); + auto COMPILED_DATE = __TIMESTAMP__; + return FormatMsg(MID.HelpMain, VERSION, COMMANDS, COMPILED_WITH, + COMPILED_VERSION, COMPILED_DATE); } void printHelp(char[] command) diff -r b091e8b0ef5c -r a7320b7cb7dc trunk/src/util/metastrings.d --- a/trunk/src/util/metastrings.d Wed Feb 27 18:37:13 2008 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,225 +0,0 @@ - -// Written in the D programming language. - -/** - * Templates with which to do compile time manipulation of strings. - * - * Macros: - * WIKI = Phobos/StdMetastrings - * Copyright: - * Public Domain. - */ - -/** - * Authors: - * Walter Bright, Digital Mars, www.digitalmars.com$(BR) - * Don Clugston - */ - -/* - Note: this is not the original file! - Modified by Aziz Köksal: - Only changed some types from string to char[] -*/ - -module util.metastrings; - -/** - * Formats constants into a string at compile time. - * Analogous to std.string.format(). - * Parameters: - * A = tuple of constants, which can be strings, - * characters, or integral values. - * Formats: - * The formats supported are %s for strings, and %% - * for the % character. - * Example: - * --- -import std.metastrings; -import std.stdio; - -void main() -{ - string s = Format!("Arg %s = %s", "foo", 27); - writefln(s); // "Arg foo = 27" -} - * --- - */ - -template Format(A...) -{ - static if (A.length == 0) - const char[] Format = ""; - else static if (is(typeof(A[0]) : char[])) - const char[] Format = FormatString!(A[0], A[1..$]); - //const char[] Format = FormatString!(A[0]); - else - const char[] Format = ToString!(A[0]) ~ Format!(A[1..$]); -} - -template FormatString(char[] F, A...) -{ - static if (F.length == 0) - const char[] FormatString = Format!(A); - else static if (F.length == 1) - const char[] FormatString = F[0] ~ Format!(A); - else static if (F[0..2] == "%s") - const char[] FormatString = ToString!(A[0]) ~ FormatString!(F[2..$],A[1..$]); - else static if (F[0..2] == "%%") - const char[] FormatString = "%" ~ FormatString!(F[2..$],A); - else static if (F[0] == '%') - static assert(0, "unrecognized format %" ~ F[1]); - else - const char[] FormatString = F[0] ~ FormatString!(F[1..$],A); -} - -/** - * Convert constant argument to a string. - */ - -template ToString(ulong U) -{ - static if (U < 10) - const char[] ToString = "" ~ cast(char)(U + '0'); - else - const char[] ToString = ToString!(U / 10) ~ ToString!(U % 10); -} - -/// ditto -template ToString(long I) -{ - static if (I < 0) - const char[] ToString = "-" ~ ToString!(cast(ulong)(-I)); - else - const char[] ToString = ToString!(cast(ulong)I); -} - -static assert(ToString!(0x100000000) == "4294967296"); - -/// ditto -template ToString(uint U) -{ - const char[] ToString = ToString!(cast(ulong)U); -} - -/// ditto -template ToString(int I) -{ - const char[] ToString = ToString!(cast(long)I); -} - -/// ditto -template ToString(ushort U) -{ - const char[] ToString = ToString!(cast(ulong)U); -} - -/// ditto -template ToString(short I) -{ - const char[] ToString = ToString!(cast(long)I); -} - -/// ditto -template ToString(ubyte U) -{ - const char[] ToString = ToString!(cast(ulong)U); -} - -/// ditto -template ToString(byte I) -{ - const char[] ToString = ToString!(cast(long)I); -} - -/// ditto -template ToString(bool B) -{ - const char[] ToString = B ? "true" : "false"; -} - -/// ditto -template ToString(char[] S) -{ - const char[] ToString = S; -} - -/// ditto -template ToString(char C) -{ - const char[] ToString = "" ~ C; -} - -unittest -{ - char[] s = Format!("hel%slo", "world", -138, 'c', true); - assert(s == "helworldlo-138ctrue"); -} - - -/******** - * Parse unsigned integer literal from the start of string s. - * returns: - * .value = the integer literal as a string, - * .rest = the string following the integer literal - * Otherwise: - * .value = null, - * .rest = s - */ - -template ParseUinteger(char[] s) -{ - static if (s.length == 0) - { const char[] value = ""; - const char[] rest = ""; - } - else static if (s[0] >= '0' && s[0] <= '9') - { const char[] value = s[0] ~ ParseUinteger!(s[1..$]).value; - const char[] rest = ParseUinteger!(s[1..$]).rest; - } - else - { const char[] value = ""; - const char[] rest = s; - } -} - -/******** - * Parse integer literal optionally preceded by '-' - * from the start of string s. - * returns: - * .value = the integer literal as a string, - * .rest = the string following the integer literal - * Otherwise: - * .value = null, - * .rest = s - */ - -template ParseInteger(char[] s) -{ - static if (s.length == 0) - { const char[] value = ""; - const char[] rest = ""; - } - else static if (s[0] >= '0' && s[0] <= '9') - { const char[] value = s[0] ~ ParseUinteger!(s[1..$]).value; - const char[] rest = ParseUinteger!(s[1..$]).rest; - } - else static if (s.length >= 2 && - s[0] == '-' && s[1] >= '0' && s[1] <= '9') - { const char[] value = s[0..2] ~ ParseUinteger!(s[2..$]).value; - const char[] rest = ParseUinteger!(s[2..$]).rest; - } - else - { const char[] value = ""; - const char[] rest = s; - } -} - -unittest -{ - assert(ParseUinteger!("1234abc").value == "1234"); - assert(ParseUinteger!("1234abc").rest == "abc"); - assert(ParseInteger!("-1234abc").value == "-1234"); - assert(ParseInteger!("-1234abc").rest == "abc"); -} -