Mercurial > projects > dil
comparison src/TypeRulesGenerator.d @ 836:e7cb5e38d567
Improved ExpressionType template.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Tue, 12 Aug 2008 21:25:14 +0200 |
parents | 451ede0105e0 |
children |
comparison
equal
deleted
inserted
replaced
835:451ede0105e0 | 836:e7cb5e38d567 |
---|---|
5 +/ | 5 +/ |
6 module TypeRulesGenerator; | 6 module TypeRulesGenerator; |
7 | 7 |
8 import tango.io.File; | 8 import tango.io.File; |
9 import tango.io.FilePath; | 9 import tango.io.FilePath; |
10 import common; | |
10 | 11 |
11 alias char[] string; | 12 alias char[] string; |
12 | 13 |
13 void main(char[][] args) | 14 void main(char[][] args) |
14 { | 15 { |
15 char[] text = "/// Generated by TypeRulesGenerator.d\n" | 16 char[] text = "/// Generated by TypeRulesGenerator.d\n" |
16 "module TypeRulesData;\n\n"; | 17 "module TypeRulesData;\n\n"; |
17 text ~= Format(`const char[] compilerNameVersion = "{} {}.{,:d3}";`\n, __VENDOR__, __VERSION__/1000, __VERSION__%1000); | 18 text ~= Format(`const char[] compilerNameVersion = "{} {}.{,:d3}";`\n\n, |
19 __VENDOR__, __VERSION__/1000, __VERSION__%1000); | |
18 text ~= "char[][][] unaryExpsResults = [\n"; | 20 text ~= "char[][][] unaryExpsResults = [\n"; |
19 foreach (results; unaryExpsResults) | 21 foreach (results; unaryExpsResults) |
20 { | 22 { |
21 text ~= " ["; | 23 text ~= " ["; |
22 foreach (result; results) | 24 foreach (result; results) |
23 text ~= '"' ~ result ~ '"' ~ ", "; | 25 text ~= '"' ~ result ~ `", `; |
24 text[$-2] = ']'; | 26 text.length = text.length - 2; |
25 text[$-1] = ','; | 27 text ~= "],\n"; |
26 text ~= \n; | |
27 } | 28 } |
28 text[$-2] = '\n'; | 29 text.length = text.length - 2; |
29 text[$-1] = ']'; | 30 text ~= "\n];\n\n"; |
30 text ~= ";\n\n"; | |
31 | 31 |
32 text ~= "char[][][][] binaryExpsResults = [\n"; | 32 text ~= "char[][][][] binaryExpsResults = [\n"; |
33 foreach (expResults; binaryExpsResults) | 33 foreach (expResults; binaryExpsResults) |
34 { | 34 { |
35 text ~= " [\n"; | 35 text ~= " [\n"; |
36 foreach (results; expResults) | 36 foreach (results; expResults) |
37 { | 37 { |
38 text ~= " ["; | 38 text ~= " ["; |
39 foreach (result; results) | 39 foreach (result; results) |
40 text ~= '"' ~ result ~ '"' ~ ", "; | 40 text ~= '"' ~ result ~ `", `; |
41 text[$-2] = ']'; | 41 text.length = text.length - 2; |
42 text[$-1] = ','; | 42 text ~= "],\n"; |
43 text ~= \n; | |
44 } | 43 } |
45 text[$-2] = '\n'; | 44 text.length = text.length - 2; |
46 text[$-1] = ' '; | 45 text ~= "\n ],\n"; |
47 text ~= " ],\n"; | |
48 } | 46 } |
49 text[$-2] = '\n'; | 47 text.length = text.length - 2; |
50 text[$-1] = ']'; | 48 text ~= "\n];\n"; |
51 text ~= ";\n"; | |
52 | 49 |
53 // Write the text to a D module. | 50 // Write the text to a D module. |
54 auto file = new File("TypeRulesData.d"); | 51 auto file = new File("TypeRulesData.d"); |
55 file.write(text); | 52 file.write(text); |
56 } | 53 } |
57 | 54 |
58 template ExpressionType(char[] T1, char[] T2, char[] expression) | 55 template ExpressionType(alias x, alias y, char[] expression) |
59 { | 56 { |
60 mixin("alias "~T1~" X;"); | |
61 mixin("alias "~T2~" Y;"); | |
62 X x; | |
63 Y y; | |
64 static if(is(typeof(mixin(expression)) ResultType)) | 57 static if(is(typeof(mixin(expression)) ResultType)) |
65 const char[] result = ResultType.stringof; | 58 const char[] result = ResultType.stringof; |
66 else | 59 else |
67 const char[] result = "Error"; | 60 const char[] result = "Error"; |
68 } | 61 } |
77 /+"cent", "ucent",+/ | 70 /+"cent", "ucent",+/ |
78 "float", "double", "real", | 71 "float", "double", "real", |
79 "ifloat", "idouble", "ireal", | 72 "ifloat", "idouble", "ireal", |
80 "cfloat", "cdouble", "creal"/+, "void"+/ | 73 "cfloat", "cdouble", "creal"/+, "void"+/ |
81 ]; | 74 ]; |
75 | |
76 char char_; wchar wchar_; dchar dchar_; bool bool_; | |
77 byte byte_; ubyte ubyte_; short short_; ushort ushort_; | |
78 int int_; uint uint_; long long_; ulong ulong_; | |
79 /+cent cent_; ucent ucent_;+/ | |
80 float float_; double double_; real real_; | |
81 ifloat ifloat_; idouble idouble_; ireal ireal_; | |
82 cfloat cfloat_; cdouble cdouble_; creal creal_; | |
82 | 83 |
83 static const string[] unaryExpressions = [ | 84 static const string[] unaryExpressions = [ |
84 "!x", | 85 "!x", |
85 "&x", | 86 "&x", |
86 "~x", | 87 "~x", |
126 char[] result = "[\n"; | 127 char[] result = "[\n"; |
127 foreach (t1; basicTypes) | 128 foreach (t1; basicTypes) |
128 { | 129 { |
129 result ~= "[\n"; | 130 result ~= "[\n"; |
130 foreach (t2; basicTypes) | 131 foreach (t2; basicTypes) |
131 result ~= `EType!("`~t1~`", "`~t2~`", "`~expression~`").result,`\n; | 132 result ~= `EType!(`~t1~`_, `~t2~`_, "`~expression~`").result,`\n; |
132 result[result.length-2] = ']'; // Overwrite last comma. | 133 result[result.length-2] = ']'; // Overwrite last comma. |
133 result[result.length-1] = ','; // Overwrite last \n. | 134 result[result.length-1] = ','; // Overwrite last \n. |
134 } | 135 } |
135 result[result.length-1] = ']'; // Overwrite last comma. | 136 result[result.length-1] = ']'; // Overwrite last comma. |
136 return result; | 137 return result; |
153 | 154 |
154 char[] genUnaryExpArray(char[] expression) | 155 char[] genUnaryExpArray(char[] expression) |
155 { | 156 { |
156 char[] result = "[\n"; | 157 char[] result = "[\n"; |
157 foreach (t1; basicTypes) | 158 foreach (t1; basicTypes) |
158 result ~= `EType!("`~t1~`", "int", "`~expression~`").result,`\n; | 159 result ~= `EType!(`~t1~`_, int_, "`~expression~`").result,`\n; |
159 result[result.length-2] = ']'; // Overwrite last comma. | 160 result[result.length-2] = ']'; // Overwrite last comma. |
160 return result; | 161 return result; |
161 } | 162 } |
162 | 163 |
163 char[] genUnaryExpsArray() | 164 char[] genUnaryExpsArray() |