# HG changeset patch # User Aziz K?ksal # Date 1218569114 -7200 # Node ID e7cb5e38d5671c43eb940c2f3d07ae27d23eaa1d # Parent 451ede0105e01945ba8a8a93cfb1c88c4442def7 Improved ExpressionType template. diff -r 451ede0105e0 -r e7cb5e38d567 src/TypeRulesGenerator.d --- a/src/TypeRulesGenerator.d Tue Aug 12 02:59:11 2008 +0200 +++ b/src/TypeRulesGenerator.d Tue Aug 12 21:25:14 2008 +0200 @@ -7,6 +7,7 @@ import tango.io.File; import tango.io.FilePath; +import common; alias char[] string; @@ -14,20 +15,19 @@ { char[] text = "/// Generated by TypeRulesGenerator.d\n" "module TypeRulesData;\n\n"; - text ~= Format(`const char[] compilerNameVersion = "{} {}.{,:d3}";`\n, __VENDOR__, __VERSION__/1000, __VERSION__%1000); + text ~= Format(`const char[] compilerNameVersion = "{} {}.{,:d3}";`\n\n, + __VENDOR__, __VERSION__/1000, __VERSION__%1000); text ~= "char[][][] unaryExpsResults = [\n"; foreach (results; unaryExpsResults) { text ~= " ["; foreach (result; results) - text ~= '"' ~ result ~ '"' ~ ", "; - text[$-2] = ']'; - text[$-1] = ','; - text ~= \n; + text ~= '"' ~ result ~ `", `; + text.length = text.length - 2; + text ~= "],\n"; } - text[$-2] = '\n'; - text[$-1] = ']'; - text ~= ";\n\n"; + text.length = text.length - 2; + text ~= "\n];\n\n"; text ~= "char[][][][] binaryExpsResults = [\n"; foreach (expResults; binaryExpsResults) @@ -37,30 +37,23 @@ { text ~= " ["; foreach (result; results) - text ~= '"' ~ result ~ '"' ~ ", "; - text[$-2] = ']'; - text[$-1] = ','; - text ~= \n; + text ~= '"' ~ result ~ `", `; + text.length = text.length - 2; + text ~= "],\n"; } - text[$-2] = '\n'; - text[$-1] = ' '; - text ~= " ],\n"; + text.length = text.length - 2; + text ~= "\n ],\n"; } - text[$-2] = '\n'; - text[$-1] = ']'; - text ~= ";\n"; + text.length = text.length - 2; + text ~= "\n];\n"; // Write the text to a D module. auto file = new File("TypeRulesData.d"); file.write(text); } -template ExpressionType(char[] T1, char[] T2, char[] expression) +template ExpressionType(alias x, alias y, char[] expression) { - mixin("alias "~T1~" X;"); - mixin("alias "~T2~" Y;"); - X x; - Y y; static if(is(typeof(mixin(expression)) ResultType)) const char[] result = ResultType.stringof; else @@ -80,6 +73,14 @@ "cfloat", "cdouble", "creal"/+, "void"+/ ]; +char char_; wchar wchar_; dchar dchar_; bool bool_; +byte byte_; ubyte ubyte_; short short_; ushort ushort_; +int int_; uint uint_; long long_; ulong ulong_; +/+cent cent_; ucent ucent_;+/ +float float_; double double_; real real_; +ifloat ifloat_; idouble idouble_; ireal ireal_; +cfloat cfloat_; cdouble cdouble_; creal creal_; + static const string[] unaryExpressions = [ "!x", "&x", @@ -128,7 +129,7 @@ { result ~= "[\n"; foreach (t2; basicTypes) - result ~= `EType!("`~t1~`", "`~t2~`", "`~expression~`").result,`\n; + result ~= `EType!(`~t1~`_, `~t2~`_, "`~expression~`").result,`\n; result[result.length-2] = ']'; // Overwrite last comma. result[result.length-1] = ','; // Overwrite last \n. } @@ -155,7 +156,7 @@ { char[] result = "[\n"; foreach (t1; basicTypes) - result ~= `EType!("`~t1~`", "int", "`~expression~`").result,`\n; + result ~= `EType!(`~t1~`_, int_, "`~expression~`").result,`\n; result[result.length-2] = ']'; // Overwrite last comma. return result; }